采集策略_NEW.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using UAS_LabelMachine.Entity;
  7. using UAS_LabelMachine.PublicMethod;
  8. namespace UAS_LabelMachine
  9. {
  10. public partial class 采集策略_NEW : Form
  11. {
  12. AutoSizeFormClass asc = new AutoSizeFormClass();
  13. DataHelper dh;
  14. StringBuilder sql = new StringBuilder();
  15. DataTable dt;
  16. public 采集策略_NEW()
  17. {
  18. InitializeComponent();
  19. }
  20. private void 采集策略_Load(object sender, EventArgs e)
  21. {
  22. asc.controllInitializeSize(this);
  23. dh = SystemInf.dh;
  24. dt = (DataTable)dh.ExecuteSql("select pb_name from productbrand", "select");
  25. for (int i = 0; i < dt.Rows.Count; i++)
  26. {
  27. CustomerTreeView.Nodes.Add(dt.Rows[i]["pb_name"].ToString());
  28. }
  29. }
  30. private void 采集策略_SizeChanged(object sender, EventArgs e)
  31. {
  32. asc.controlAutoSize(this);
  33. }
  34. string SGID = "0";
  35. string SGBrand = "";
  36. private void CustomerTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  37. {
  38. //点中根节点的时候查询品牌下的采集方案
  39. if (e.Node.Level == 0)
  40. {
  41. e.Node.Nodes.Clear();
  42. dt = (DataTable)dh.ExecuteSql("select sg_id,sg_name,nvl(sg_autolabel,0)sg_autolabel from scangroup where sg_brand='" + e.Node.Text + "'", "select");
  43. for (int i = 0; i < dt.Rows.Count; i++)
  44. {
  45. TreeNode tn = new TreeNode(dt.Rows[i]["sg_name"].ToString());
  46. if (dt.Rows[i]["sg_autolabel"].ToString() != "0")
  47. {
  48. tn.BackColor = Color.Green;
  49. tn.ForeColor = Color.White;
  50. }
  51. tn.Tag = dt.Rows[i]["sg_id"].ToString();
  52. e.Node.Nodes.Add(tn);
  53. }
  54. SGBrand = e.Node.Text;
  55. CleanFormData();
  56. }
  57. //节点为子节点的时候查询界面的值
  58. if (e.Node.Level == 1)
  59. {
  60. SGID = e.Node.Tag.ToString();
  61. dt = (DataTable)dh.ExecuteSql("select sg_name,sg_script,sg_step,nvl(sg_autolabel,0)sg_autolabel from scangroup where sg_id=" + SGID, "select");
  62. if (dt.Rows.Count > 0)
  63. {
  64. sg_name.Text = dt.Rows[0]["sg_name"].ToString();
  65. sg_script.Text = dt.Rows[0]["sg_script"].ToString();
  66. sg_step.Text = dt.Rows[0]["sg_step"].ToString();
  67. sg_autolabel.Checked = dt.Rows[0]["sg_autolabel"].ToString() == "0" ? false : true;
  68. }
  69. dt = (DataTable)dh.ExecuteSql("select si_item,si_expression,si_remark,si_name,si_enable from scanitem where si_sgid=" + SGID + "order by si_id", "select");
  70. if (dt.Rows.Count > 0)
  71. {
  72. for (int i = 0; i < 6; i++)
  73. {
  74. for (int j = 0; j < dt.Rows.Count; j++)
  75. {
  76. if (Controls["si_name" + (i + 1)].Tag.ToString() == dt.Rows[j]["si_item"].ToString())
  77. {
  78. (Controls["si_item" + (i + 1)] as CheckBox).Checked = dt.Rows[j]["si_enable"].ToString() == "-1" ? true : false;
  79. Controls["si_name" + (i + 1)].Text = dt.Rows[j]["si_name"].ToString();
  80. Controls["si_remark" + (i + 1)].Text = dt.Rows[j]["si_remark"].ToString();
  81. if (Controls["si_expression" + (i + 1)] != null)
  82. Controls["si_expression" + (i + 1)].Text = dt.Rows[j]["si_expression"].ToString();
  83. continue;
  84. }
  85. }
  86. }
  87. }
  88. }
  89. }
  90. private void ButtonSaveScanGroup_Click(object sender, EventArgs e)
  91. {
  92. string[] si_item = new string[6];
  93. string[] si_name = new string[6];
  94. string[] si_remark = new string[6];
  95. string[] si_expression = new string[6];
  96. string[] si_enable = new string[6];
  97. //用数组的方式记录批量插入
  98. string sgname = "";
  99. for (int i = 0; i < 6; i++)
  100. {
  101. si_enable[i] = (Controls["si_item" + (i + 1)] as CheckBox).Checked ? "-1" : "0";
  102. //如果是-1则拼接名称
  103. if (si_enable[i] == "-1")
  104. {
  105. sgname += Controls["si_name" + (i + 1)].Text.ToString() + "+";
  106. }
  107. si_item[i] = Controls["si_item" + (i + 1)].Tag.ToString();
  108. si_name[i] = Controls["si_name" + (i + 1)].Text;
  109. si_remark[i] = Controls["si_remark" + (i + 1)].Text;
  110. if (Controls["si_expression" + (i + 1)] != null)
  111. si_expression[i] = Controls["si_expression" + (i + 1)].Text;
  112. else
  113. si_expression[i] = "";
  114. }
  115. try
  116. {
  117. sgname = sgname.Substring(0, sgname.LastIndexOf("+"));
  118. }
  119. catch (Exception)
  120. {
  121. }
  122. if (SGID == "0")
  123. {
  124. SGID = dh.GetSEQ("scangroup_seq");
  125. dh.ExecuteSql("insert into scangroup(sg_id,sg_brand)values(" + SGID + ",'" + SGBrand + "')", "insert");
  126. }
  127. //更新主表数据
  128. sql.Clear();
  129. sql.Append("update scangroup set sg_name=:sg_name,sg_script=:sg_script,sg_step=:sg_step,sg_autolabel=:sg_autolabel where sg_id=" + SGID);
  130. dh.ExecuteSql(sql.ToString(), "update", sgname, sg_script.Text, sg_step.Value, sg_autolabel.Checked ? "-1" : "0");
  131. dh.ExecuteSql("delete from scanitem where si_sgid=" + SGID, "delete");
  132. sql.Clear();
  133. sql.Append("insert into scanitem(si_id,si_sgid,si_item,si_expression,si_remark,si_name,");
  134. sql.Append("si_enable) values(scanitem_seq.nextval,'" + SGID + "',:si_item,:si_expression,:si_remark,:si_name,:si_enable)");
  135. dh.BatchInsert(sql.ToString(), new string[] { "si_item", "si_expression", "si_remark", "si_name", "si_enable" }, si_item, si_expression, si_remark, si_name, si_enable);
  136. MessageBox.Show("保存成功!", "提示");
  137. }
  138. private void CheckChange(object sender, EventArgs e)
  139. {
  140. CheckBox cb = (CheckBox)sender;
  141. int index = 0;
  142. switch (cb.Tag.ToString())
  143. {
  144. case "Order":
  145. index = 1;
  146. break;
  147. case "PN":
  148. index = 2;
  149. break;
  150. case "QTY":
  151. index = 3;
  152. break;
  153. case "DateCode":
  154. index = 4;
  155. break;
  156. case "LotNo":
  157. index = 5;
  158. break;
  159. case "OutBox":
  160. index = 6;
  161. break;
  162. default:
  163. break;
  164. }
  165. if (cb.Checked)
  166. {
  167. Controls["si_name" + index].Enabled = true;
  168. Controls["si_remark" + index].Enabled = true;
  169. if (Controls["si_expression" + index] != null)
  170. Controls["si_expression" + index].Enabled = true;
  171. }
  172. else
  173. {
  174. Controls["si_name" + index].Enabled = false;
  175. Controls["si_remark" + index].Enabled = false;
  176. if (Controls["si_expression" + index] != null)
  177. Controls["si_expression" + index].Enabled = false;
  178. }
  179. }
  180. private void CleanFormData()
  181. {
  182. sg_name.Text = "";
  183. sg_script.Text = "";
  184. sg_step.Value = 0;
  185. SGID = "0";
  186. sg_autolabel.Checked = false;
  187. for (int i = 0; i < 6; i++)
  188. {
  189. (Controls["si_item" + (i + 1)] as CheckBox).Checked = false;
  190. Controls["si_name" + (i + 1)].Text = "";
  191. Controls["si_remark" + (i + 1)].Text = "";
  192. if (Controls["si_expression" + (i + 1)] != null)
  193. Controls["si_expression" + (i + 1)].Text = "";
  194. }
  195. }
  196. /// <summary>
  197. /// 模糊搜索功能
  198. /// </summary>
  199. /// <param name="sender"></param>
  200. /// <param name="e"></param>
  201. private void Brand_KeyDown(object sender, KeyEventArgs e)
  202. {
  203. if (e.KeyCode == Keys.Enter)
  204. {
  205. dt = (DataTable)dh.ExecuteSql("select pb_name from productbrand where pb_name like '%" + Brand.Text + "%'", "select");
  206. CustomerTreeView.Nodes.Clear();
  207. for (int i = 0; i < dt.Rows.Count; i++)
  208. {
  209. CustomerTreeView.Nodes.Add(dt.Rows[i]["pb_name"].ToString());
  210. }
  211. }
  212. }
  213. private void AddNew_Click(object sender, EventArgs e)
  214. {
  215. CleanFormData();
  216. }
  217. }
  218. }