123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- using System;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using UAS_LabelMachine.Entity;
- using UAS_LabelMachine.PublicMethod;
- namespace UAS_LabelMachine
- {
- public partial class 采集策略_NEW : Form
- {
- AutoSizeFormClass asc = new AutoSizeFormClass();
- DataHelper dh;
- StringBuilder sql = new StringBuilder();
- DataTable dt;
- public 采集策略_NEW()
- {
- InitializeComponent();
- }
- private void 采集策略_Load(object sender, EventArgs e)
- {
- asc.controllInitializeSize(this);
- dh = SystemInf.dh;
- dt = (DataTable)dh.ExecuteSql("select pb_name from productbrand", "select");
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- CustomerTreeView.Nodes.Add(dt.Rows[i]["pb_name"].ToString());
- }
- }
- private void 采集策略_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- string SGID = "0";
- string SGBrand = "";
- private void CustomerTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
- {
- //点中根节点的时候查询品牌下的采集方案
- if (e.Node.Level == 0)
- {
- e.Node.Nodes.Clear();
- dt = (DataTable)dh.ExecuteSql("select sg_id,sg_name,nvl(sg_autolabel,0)sg_autolabel from scangroup where sg_brand='" + e.Node.Text + "'", "select");
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- TreeNode tn = new TreeNode(dt.Rows[i]["sg_name"].ToString());
- if (dt.Rows[i]["sg_autolabel"].ToString() != "0")
- {
- tn.BackColor = Color.Green;
- tn.ForeColor = Color.White;
- }
- tn.Tag = dt.Rows[i]["sg_id"].ToString();
- e.Node.Nodes.Add(tn);
- }
- SGBrand = e.Node.Text;
- CleanFormData();
- }
- //节点为子节点的时候查询界面的值
- if (e.Node.Level == 1)
- {
- SGID = e.Node.Tag.ToString();
- dt = (DataTable)dh.ExecuteSql("select sg_name,sg_script,sg_step,nvl(sg_autolabel,0)sg_autolabel from scangroup where sg_id=" + SGID, "select");
- if (dt.Rows.Count > 0)
- {
- sg_name.Text = dt.Rows[0]["sg_name"].ToString();
- sg_script.Text = dt.Rows[0]["sg_script"].ToString();
- sg_step.Text = dt.Rows[0]["sg_step"].ToString();
- sg_autolabel.Checked = dt.Rows[0]["sg_autolabel"].ToString() == "0" ? false : true;
- }
- 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");
- if (dt.Rows.Count > 0)
- {
- for (int i = 0; i < 6; i++)
- {
- for (int j = 0; j < dt.Rows.Count; j++)
- {
- if (Controls["si_name" + (i + 1)].Tag.ToString() == dt.Rows[j]["si_item"].ToString())
- {
- (Controls["si_item" + (i + 1)] as CheckBox).Checked = dt.Rows[j]["si_enable"].ToString() == "-1" ? true : false;
- Controls["si_name" + (i + 1)].Text = dt.Rows[j]["si_name"].ToString();
- Controls["si_remark" + (i + 1)].Text = dt.Rows[j]["si_remark"].ToString();
- if (Controls["si_expression" + (i + 1)] != null)
- Controls["si_expression" + (i + 1)].Text = dt.Rows[j]["si_expression"].ToString();
- continue;
- }
- }
- }
- }
- }
- }
- private void ButtonSaveScanGroup_Click(object sender, EventArgs e)
- {
- string[] si_item = new string[6];
- string[] si_name = new string[6];
- string[] si_remark = new string[6];
- string[] si_expression = new string[6];
- string[] si_enable = new string[6];
- //用数组的方式记录批量插入
- string sgname = "";
- for (int i = 0; i < 6; i++)
- {
- si_enable[i] = (Controls["si_item" + (i + 1)] as CheckBox).Checked ? "-1" : "0";
- //如果是-1则拼接名称
- if (si_enable[i] == "-1")
- {
- sgname += Controls["si_name" + (i + 1)].Text.ToString() + "+";
- }
- si_item[i] = Controls["si_item" + (i + 1)].Tag.ToString();
- si_name[i] = Controls["si_name" + (i + 1)].Text;
- si_remark[i] = Controls["si_remark" + (i + 1)].Text;
- if (Controls["si_expression" + (i + 1)] != null)
- si_expression[i] = Controls["si_expression" + (i + 1)].Text;
- else
- si_expression[i] = "";
- }
- try
- {
- sgname = sgname.Substring(0, sgname.LastIndexOf("+"));
- }
- catch (Exception)
- {
- }
- if (SGID == "0")
- {
- SGID = dh.GetSEQ("scangroup_seq");
- dh.ExecuteSql("insert into scangroup(sg_id,sg_brand)values(" + SGID + ",'" + SGBrand + "')", "insert");
- }
- //更新主表数据
- sql.Clear();
- 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);
- dh.ExecuteSql(sql.ToString(), "update", sgname, sg_script.Text, sg_step.Value, sg_autolabel.Checked ? "-1" : "0");
- dh.ExecuteSql("delete from scanitem where si_sgid=" + SGID, "delete");
- sql.Clear();
- sql.Append("insert into scanitem(si_id,si_sgid,si_item,si_expression,si_remark,si_name,");
- sql.Append("si_enable) values(scanitem_seq.nextval,'" + SGID + "',:si_item,:si_expression,:si_remark,:si_name,:si_enable)");
- 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);
- MessageBox.Show("保存成功!", "提示");
- }
- private void CheckChange(object sender, EventArgs e)
- {
- CheckBox cb = (CheckBox)sender;
- int index = 0;
- switch (cb.Tag.ToString())
- {
- case "Order":
- index = 1;
- break;
- case "PN":
- index = 2;
- break;
- case "QTY":
- index = 3;
- break;
- case "DateCode":
- index = 4;
- break;
- case "LotNo":
- index = 5;
- break;
- case "OutBox":
- index = 6;
- break;
- default:
- break;
- }
- if (cb.Checked)
- {
- Controls["si_name" + index].Enabled = true;
- Controls["si_remark" + index].Enabled = true;
- if (Controls["si_expression" + index] != null)
- Controls["si_expression" + index].Enabled = true;
- }
- else
- {
- Controls["si_name" + index].Enabled = false;
- Controls["si_remark" + index].Enabled = false;
- if (Controls["si_expression" + index] != null)
- Controls["si_expression" + index].Enabled = false;
- }
- }
- private void CleanFormData()
- {
- sg_name.Text = "";
- sg_script.Text = "";
- sg_step.Value = 0;
- SGID = "0";
- sg_autolabel.Checked = false;
- for (int i = 0; i < 6; i++)
- {
- (Controls["si_item" + (i + 1)] as CheckBox).Checked = false;
- Controls["si_name" + (i + 1)].Text = "";
- Controls["si_remark" + (i + 1)].Text = "";
- if (Controls["si_expression" + (i + 1)] != null)
- Controls["si_expression" + (i + 1)].Text = "";
- }
- }
- /// <summary>
- /// 模糊搜索功能
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Brand_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- dt = (DataTable)dh.ExecuteSql("select pb_name from productbrand where pb_name like '%" + Brand.Text + "%'", "select");
- CustomerTreeView.Nodes.Clear();
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- CustomerTreeView.Nodes.Add(dt.Rows[i]["pb_name"].ToString());
- }
- }
- }
- private void AddNew_Click(object sender, EventArgs e)
- {
- CleanFormData();
- }
- }
- }
|