ExportColumns.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Windows.Forms;
  10. using UAS_LabelMachine.Entity;
  11. using UAS_LabelMachine.PublicMethod;
  12. namespace UAS_LabelMachine
  13. {
  14. public partial class ExportColumns : Form
  15. {
  16. DataHelper dh = SystemInf.dh;
  17. string inoutno = "";
  18. string custcode = "";
  19. public ExportColumns()
  20. {
  21. InitializeComponent();
  22. Activate();
  23. }
  24. public ExportColumns(string IInoutno)
  25. {
  26. InitializeComponent();
  27. inoutno = IInoutno;
  28. }
  29. private void ExportColumns_Load(object sender, EventArgs e)
  30. {
  31. Activate();
  32. LogicHandler.CustInit("0");
  33. LoadData();
  34. }
  35. private void SaveColumns_Click(object sender, EventArgs e)
  36. {
  37. //先删除之前此客户的记录
  38. dh.ExecuteSql("delete from CS_EXPORTSETTING where es_custcode='" + custcode + "'", "delete");
  39. StringBuilder sql = new StringBuilder();
  40. List<string> es_filed = new List<string>();
  41. List<string> es_caption = new List<string>();
  42. List<string> es_enable = new List<string>();
  43. List<string> es_detno = new List<string>();
  44. List<string> es_istitle = new List<string>();
  45. List<string> es_datatype = new List<string>();
  46. for (int i = 0; i < FirstPage.Rows.Count; i++)
  47. {
  48. es_filed.Add(FirstPage.Rows[i].Cells["es_filed"].Value.ToString());
  49. es_caption.Add(FirstPage.Rows[i].Cells["es_caption"].Value.ToString());
  50. es_enable.Add(FirstPage.Rows[i].Cells["es_enable"].Value.ToString());
  51. es_detno.Add(FirstPage.Rows[i].Cells["es_detno"].Value.ToString());
  52. es_istitle.Add(FirstPage.Rows[i].Cells["es_istitle"].Value.ToString());
  53. es_datatype.Add(FirstPage.Rows[i].Cells["es_datatype"].Value.ToString());
  54. }
  55. sql.Clear();
  56. sql.Append("insert into CS_EXPORTSETTING(es_type,es_filed,es_caption,es_enable,es_detno,es_custcode,es_istitle,es_datatype)");
  57. sql.Append("values('First',:es_filed,:es_caption,:es_enable,:es_detno,'" + custcode + "',:es_istitle,:es_datatype)");
  58. dh.BatchInsert(sql.ToString(), new string[] { "es_filed", "es_caption", "es_enable", "es_detno", "es_istitle", "es_datatype" }, es_filed.ToArray(), es_caption.ToArray(), es_enable.ToArray(), es_detno.ToArray(), es_istitle.ToArray(), es_datatype.ToArray());
  59. //清除首页赋的值
  60. es_filed.Clear(); es_caption.Clear(); es_enable.Clear(); ; es_detno.Clear(); es_filed.Clear(); es_istitle.Clear();
  61. for (int i = 0; i < DataPage.Rows.Count; i++)
  62. {
  63. es_filed.Add(DataPage.Rows[i].Cells["es_filed"].Value.ToString());
  64. es_caption.Add(DataPage.Rows[i].Cells["es_caption"].Value.ToString());
  65. es_enable.Add(DataPage.Rows[i].Cells["es_enable"].Value.ToString());
  66. es_detno.Add(DataPage.Rows[i].Cells["es_detno"].Value.ToString());
  67. es_istitle.Add(DataPage.Rows[i].Cells["es_istitle"].Value.ToString());
  68. es_datatype.Add(DataPage.Rows[i].Cells["es_datatype"].Value.ToString());
  69. }
  70. sql.Clear();
  71. sql.Append("insert into CS_EXPORTSETTING(es_type,es_filed,es_caption,es_enable,es_detno,es_custcode,es_istitle,es_datatype)");
  72. sql.Append("values('DataPage',:es_filed,:es_caption,:es_enable,:es_detno,'" + custcode + "',:es_istitle,:es_datatype)");
  73. dh.BatchInsert(sql.ToString(), new string[] { "es_filed", "es_caption", "es_enable", "es_detno", "es_istitle", "es_datatype" }, es_filed.ToArray(), es_caption.ToArray(), es_enable.ToArray(), es_detno.ToArray(), es_istitle.ToArray(), es_datatype.ToArray());
  74. MessageBox.Show("保存成功!");
  75. LoadData();
  76. }
  77. private void ResetColumns_Click(object sender, EventArgs e)
  78. {
  79. string close = MessageBox.Show(this.ParentForm, "是否重置列", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  80. if (close == "Yes")
  81. {
  82. dh.ExecuteSql("delete from CS_EXPORTSETTING where es_custcode='" + custcode + "'", "delete");
  83. LoadData();
  84. }
  85. }
  86. private void DeleteColumns_Click(object sender, EventArgs e)
  87. {
  88. DataGridViewSelectedCellCollection cl = FirstPage.SelectedCells;
  89. List<int> deleteIndex = new List<int>();
  90. for (int i = 0; i < cl.Count; i++)
  91. {
  92. if (!deleteIndex.Contains(cl[i].ColumnIndex))
  93. {
  94. deleteIndex.Add(cl[i].ColumnIndex);
  95. }
  96. }
  97. for (int i = FirstPage.Columns.Count - 1; i >= 0; i--)
  98. {
  99. for (int j = 0; j < deleteIndex.ToArray().Length; j++)
  100. {
  101. if (deleteIndex.ToArray()[j] == i)
  102. FirstPage.Columns.RemoveAt(i);
  103. }
  104. }
  105. }
  106. private void DeleteDataColumns_Click(object sender, EventArgs e)
  107. {
  108. DataGridViewSelectedCellCollection cl = DataPage.SelectedCells;
  109. List<int> deleteIndex = new List<int>();
  110. for (int i = 0; i < cl.Count; i++)
  111. {
  112. if (!deleteIndex.Contains(cl[i].ColumnIndex))
  113. {
  114. deleteIndex.Add(cl[i].ColumnIndex);
  115. }
  116. }
  117. for (int i = DataPage.Columns.Count - 1; i >= 0; i--)
  118. {
  119. for (int j = 0; j < deleteIndex.ToArray().Length; j++)
  120. {
  121. if (deleteIndex.ToArray()[j] == i)
  122. DataPage.Columns.RemoveAt(i);
  123. }
  124. }
  125. }
  126. private void LoadData()
  127. {
  128. StringBuilder sql = new StringBuilder();
  129. custcode = dh.getFieldDataByCondition("prodinout", "pi_cardcode", "pi_inoutno='" + inoutno + "'").ToString();
  130. DataTable SQL1_ = (DataTable)dh.ExecuteSql("select es_type,es_filed,es_engcaption,es_detno,es_caption,es_enable,es_istitle,es_datatype from CS_EXPORTSETTING where es_type='DataPage' and es_enable=-1 and es_custcode='" + custcode + "' order by es_detno", "select");
  131. //没有置顶客户的取空的
  132. if (SQL1_.Rows.Count == 0)
  133. {
  134. SQL1_ = (DataTable)dh.ExecuteSql("select es_type,es_filed,es_engcaption,es_detno,es_caption,es_enable,es_istitle,es_datatype from CS_EXPORTSETTING where es_type='DataPage' and es_enable=-1 and es_custcode is null order by es_detno", "select");
  135. }
  136. //获取首页需要展示的字段
  137. DataTable SQL_ = (DataTable)dh.ExecuteSql("select es_type,es_filed,es_engcaption,es_detno,es_caption,es_enable,es_istitle,es_datatype from CS_EXPORTSETTING where es_type='First' and es_enable=-1 and es_custcode='" + custcode + "' order by es_detno", "select");
  138. if (SQL_.Rows.Count == 0)
  139. {
  140. SQL_ = (DataTable)dh.ExecuteSql("select es_type,es_filed,es_engcaption,es_detno,es_caption,es_enable,es_istitle,es_datatype from CS_EXPORTSETTING where es_type='First' and es_enable=-1 and es_custcode is null order by es_detno", "select");
  141. }
  142. if (FirstPage.DataSource != null)
  143. FirstPage.DataSource = null;
  144. if (DataPage.DataSource != null)
  145. DataPage.DataSource = null;
  146. FirstPage.DataSource = SQL_;
  147. DataPage.DataSource = SQL1_;
  148. FirstPage.ReadOnly = false;
  149. DataPage.ReadOnly = false;
  150. }
  151. }
  152. }