123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722 |
- using System;
- using System.Data;
- using System.Text;
- using System.Windows.Forms;
- using UAS_MES_NEW.CustomControl.TextBoxWithIcon;
- using UAS_MES_NEW.DataOperate;
- using UAS_MES_NEW.Entity;
- using UAS_MES_NEW.PublicMethod;
- using System.Drawing;
- using System.Text.RegularExpressions;
- using System.Collections.Generic;
- using System.Threading;
- using UAS_MES_NEW.PublicForm;
- namespace UAS_MES_NEW.Make
- {
- public partial class Make_SMTBind : Form
- {
- string ErrorMessage = "";
- List<string> TSN = new List<string>();
- Dictionary<string, string> CheckBarcode = new Dictionary<string, string>();
- DataHelper dh;
- LogStringBuilder sql = new LogStringBuilder();
- DataTable DBFind;
- //保存ListB中的数据
- DataTable dt1;
- DataTable dt = new DataTable();
- DataTable dbfind;
- ExcelHandler eh;
- Thread thread;
- AutoSizeFormClass asc = new AutoSizeFormClass();
- List<string> CollectData = new List<string>();
- List<string> CollectDataSonCode = new List<string>();
- List<string> SPID = new List<string>();
- public Make_SMTBind()
- {
- InitializeComponent();
- }
- private void Make_FeedingCollection_Load(object sender, EventArgs e)
- {
- asc.controllInitializeSize(this);
- LockMakeCode.GetMakeCodeCtl(ma_code);
- ma_code.SetLockCheckBox(LockMakeCode);
- //工单号放大镜配置
- eh = new ExcelHandler();
- ma_code.TableName = "make left join product on ma_prodcode=pr_code";
- ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,ma_craftcode # 途程编号,pr_spec # 产品名称,ma_bomversion # Bom版本,ma_softversion # 软件版本,ma_ecncode # ECN号,pr_pcbacount # 拼版数";
- ma_code.FormName = Name;
- ma_code.DBTitle = "工单查询";
- ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_spec", "ma_craftcode", "ma_bomversion", "ma_softversion", "ma_ecncode", "pr_pcbacount" };
- ma_code.Condition = "ma_statuscode='STARTED'";
- ma_code.DbChange += Ma_code_DBChange;
- code.GotFocus+= text_getfocus;
- code.Focus();
- dh = SystemInf.dh;
- StepCount.StepCode = User.CurrentStepCode;
- StepCount.Source = User.UserSourceCode;
- StepCount.LineCode = User.UserLineCode;
- StepCount.Dh = dh;
- StepCount.Start();
- }
- private void text_getfocus(object sender, EventArgs e)
- {
- code.ImeMode = ImeMode.Close;
- }
- private void Ma_code_DBChange(object sender, EventArgs e)
- {
- DBFind = ma_code.ReturnData;
- BaseUtil.SetFormValue(this.Controls, DBFind);
- }
- private void Make_FeedingCollection_SizeChanged(object sender, EventArgs e)
- {
- asc.controlAutoSize(this);
- }
- private void Clean_Click(object sender, EventArgs e)
- {
- OperateResult.Clear();
- }
- private void Confirm_Click(object sender, EventArgs e)
- {
- KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
- code_KeyDown(sender, e2);
- }
- private void code_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
- {
- if (Loading.Checked)
- {
- if (code.Text.Replace(" ", "") == ""||pr_pcbacount.Value == 0 )
- {
- OperateResult.AppendText(">>采集数据与拼版数不可为空\n", Color.Red);
- return;
- }
- else
- {
- if (sn_code.Text == "")
- {
- if (ma_code.Text != "" && !LogicHandler.CheckSnRule(ma_code.Text, ma_prodcode.Text, code.Text, out ErrorMessage))
- {
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
- return;
- }
- int maqty = int.Parse(dh.getFieldDataByCondition("make", "ma_qty", "ma_code = '" + ma_code.Text + "'").ToString());
- int nowqty = int.Parse(dh.getFieldDataByCondition("smtbind", "count(1) cn ", "sb_makecode = '" + ma_code.Text + "'").ToString());
- if (nowqty+ pr_pcbacount.Value > maqty)
- {
- OperateResult.AppendText(">>已绑定数"+ nowqty + "+拼版数"+ pr_pcbacount.Value + "大于工单数"+ maqty + "不允许操作\n", Color.Red);
- return;
- }
- sql.Clear();
- sql.Append("select rownum,sb_maincode,sb_makecode,sb_barcode,sb_prodcode,sb_indate from SMTBIND where sb_maincode=(select sb_maincode from SMTBIND ");
- sql.Append("where sb_barcode='" + code.Text + "')");
- dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt1.Rows.Count > 0)
- {
- string sb_makecode = dt1.Rows[0]["sb_makecode"].ToString();
- if (ma_code.Text != "" && ma_code.Text != sb_makecode)
- {
- OperateResult.AppendText(">>条码已绑定至工单" + sb_makecode + "\n", Color.Red, code);
- return;
- }
- ma_code.Text = dt1.Rows[0]["sb_makecode"].ToString();
- LockMakeCode.Checked = true;
- ma_code_UserControlTextChanged(sender, e);
- BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
- if (dt1.Rows.Count < pr_pcbacount.Value)
- {
- sn_code.Text = dt1.Rows[0]["sb_maincode"].ToString();
- }
- code.Text = "";
- }
- else
- {
- if (ma_code.Text == "")
- {
- OperateResult.AppendText(">>请先选择工单号\n", Color.Red, code);
- return;
- }
- if (!LogicHandler.CheckSnRule(ma_code.Text, ma_prodcode.Text, code.Text, out ErrorMessage))
- {
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
- return;
- }
- sn_code.Text = code.Text;
- sql.Clear();
- sql.Append("insert into smtbind(sb_id,sb_maincode,sb_barcode,sb_makecode,sb_prodcode,sb_inman,sb_indate,sb_status)");
- sql.Append("values(smtbind_seq.nextval,'" + sn_code.Text + "','" + code.Text + "','" + ma_code.Text + "','" + ma_prodcode.Text + "',");
- sql.Append("'" + User.UserCode + "',sysdate,0)");
- dh.ExecuteSql(sql.GetString(), "insert");
- RefreshData();
- sql.Clear();
- sql.Append("select rownum,sb_maincode,sb_barcode,sb_prodcode,sb_indate from SMTBIND where sb_maincode=(select sb_maincode from SMTBIND ");
- sql.Append("where sb_barcode='" + code.Text + "')");
- dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
- if (LabelDataGridView.Rows.Count == pr_pcbacount.Value)
- {
- OperateResult.AppendText(">>拼版主码" + sn_code.Text + "绑定完成\n", Color.Green);
- sn_code.Text = "";
- }
- code.Text = "";
- }
- }
- else
- {
- if (ma_code.Text == "")
- {
- OperateResult.AppendText(">>请先选择工单号\n", Color.Red, code);
- return;
- }
- if (!LogicHandler.CheckSnRule(ma_code.Text, ma_prodcode.Text, code.Text, out ErrorMessage))
- {
- OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
- return;
- }
- if (dh.CheckExist("smtbind", "sb_barcode='" + code.Text + "'"))
- {
- OperateResult.AppendText(">>条码" + code.Text + "已绑定\n", Color.Red, code);
- return;
- }
- sql.Clear();
- sql.Append("insert into smtbind(sb_id,sb_maincode,sb_barcode,sb_makecode,sb_prodcode,sb_inman,sb_indate,sb_status)");
- sql.Append("values(smtbind_seq.nextval,'" + sn_code.Text + "','" + code.Text + "','" + ma_code.Text + "','" + ma_prodcode.Text + "',");
- sql.Append("'" + User.UserCode + "',sysdate,0)");
- dh.ExecuteSql(sql.GetString(), "insert");
- RefreshData();
- sql.Clear();
- sql.Append("select rownum,sb_maincode,sb_barcode,sb_prodcode,sb_indate from SMTBIND where sb_maincode=(select sb_maincode from SMTBIND ");
- sql.Append("where sb_barcode='" + code.Text + "')");
- dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
- if (LabelDataGridView.Rows.Count == pr_pcbacount.Value)
- {
- OperateResult.AppendText(">>拼版主码" + sn_code.Text + "绑定完成\n", Color.Green);
- sn_code.Text = "";
- }
- code.Text = "";
- }
- }
- }
- //勾选了下料的时候
- else if (UnLoading.Checked)
- {
- sql.Clear();
- sql.Append("select rownum,sb_maincode,sb_makecode,sb_barcode,sb_prodcode,sb_indate from SMTBIND where sb_maincode=(select sb_maincode from SMTBIND ");
- sql.Append("where sb_barcode='" + code.Text + "')");
- dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt1.Rows.Count > 0)
- {
- string sb_makecode = dt1.Rows[0]["sb_makecode"].ToString();
- if (ma_code.Text != "" && ma_code.Text != sb_makecode)
- {
- OperateResult.AppendText(">>条码已绑定至工单" + sb_makecode + "\n", Color.Red, code);
- return;
- }
- ma_code.Text = dt1.Rows[0]["sb_makecode"].ToString();
- LockMakeCode.Checked = true;
- ma_code_UserControlTextChanged(sender, e);
- BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
- string sb_maincode = dt1.Rows[0]["sb_maincode"].ToString();
- //如果采集的是主条码则拆分所有的条码
- if (sb_maincode == code.Text)
- {
- string closetab_confirm = MessageBox.Show(this.ParentForm, "确认拆解所有条码", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- if (closetab_confirm == "Yes")
- {
- dh.ExecuteSql("delete from smtbind where sb_maincode='" + code.Text + "'", "delete");
- }
- }
- else
- {
- dh.ExecuteSql("delete from smtbind where sb_barcode='" + code.Text + "'", "delete");
- }
- sql.Clear();
- sql.Append("select rownum,sb_maincode,sb_barcode,sb_prodcode,sb_indate from SMTBIND where sb_maincode='" + sb_maincode + "'");
- dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
- sn_code.Text = "";
- code.Text = "";
- RefreshData();
- }
- }
- }
- else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, code);
- }
- }
- private void ClearSn_code_Click(object sender, EventArgs e)
- {
- sn_code.Clear();
- SPID.Clear();
- TSN.Clear();
- CheckBarcode.Clear();
- CollectData.Clear();
- CollectDataSonCode.Clear();
- if (dt1 != null)
- BaseUtil.CleanDataTableData(dt1);
- BaseUtil.CleanDGVData(LabelDataGridView);
- OperateResult.AppendText(">>请采集序列号\n", Color.Black);
- }
- private void ma_code_UserControlTextChanged(object sender, EventArgs e)
- {
- if (ma_code.Text.Length > 5)
- {
- string ErrMessage = "";
- if (LogicHandler.CheckMakeStatus(ma_code.Text, out ErrMessage))
- {
- mcd_inqty.Text = "";
- mcd_remainqty.Text = "";
- sql.Clear();
- sql.Append("select ma_qty,ma_prodcode,pr_detail,pr_pcbacount ");
- sql.Append("from make left join makecraftdetail on mcd_macode=ma_code left join product on ma_prodcode=pr_code where ");
- sql.Append("ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
- DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- BaseUtil.SetFormValue(Controls, dt);
- RefreshData();
- sql.Clear();
- sql.Append("select rownum,sb_maincode,sb_barcode,sb_prodcode,sb_makecode,sb_indate from SMTBIND where sb_maincode=(select sb_maincode from SMTBIND ");
- sql.Append("where sb_barcode='" + code.Text + "')");
- dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt1);
- }
- }
- }
- /// <summary>
- /// 刷新采集数据
- /// </summary>
- private void RefreshData()
- {
- sql.Clear();
- sql.Append("select count(1) mcd_inqty,max(ma_qty)-count(1) mcd_remainqty from smtbind left join make on ma_code= sb_makecode where sb_makecode='" + ma_code.Text + "' ");
- DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
- if (dt.Rows.Count > 0)
- BaseUtil.SetFormValue(Controls, dt);
- }
- string mincode;
- int sncount;
- int startsn;
- string firstsn;
- string lastsn;
- private void Crbut_Click(object sender, EventArgs e)
- {
- if(ma_code.Text==""|| Prefix.Text == "" || Num.Text == "" || Rn.Text == "" || pr_pcbacount.Value == 0 || Rnle.Value == 0)
- {
- OperateResult.AppendText(">>有关信息未录入或拼版数,流水长度未维护\n", Color.Red);
- return;
- }
- try
- {
- sncount = int.Parse(Num.Text);
- int maqty = int.Parse(dh.getFieldDataByCondition("make", "ma_qty", "ma_code = '" + ma_code.Text + "'").ToString());
- int nowqty = int.Parse(dh.getFieldDataByCondition("smtbind", "count(1) cn ", "sb_makecode = '" + ma_code.Text + "'").ToString());
- if (nowqty + sncount > maqty)
- {
- OperateResult.AppendText(">>已绑定数" + nowqty + "+待绑定数" + sncount + "大于工单数" + maqty + "不允许操作\n", Color.Red);
- return;
- }
- if (DSCIN.Checked)
- {
- startsn = int.Parse(Rn.Text);
- }
- else {
- startsn = int.Parse(Hex2Ten(Rn.Text));
- }
- if (sncount % pr_pcbacount.Value != 0)
- {
- OperateResult.AppendText(">>数量不是拼版数倍数\n", Color.Red);
- return;
- }
- if (DSCIN.Checked)
- {
- if ((startsn + (sncount - 1)*(sqit.Value)).ToString().Length > Rnle.Value)
- {
- OperateResult.AppendText(">>流水号长度超过设置长度\n", Color.Red);
- return;
- }
- }
- else {
- if (ConvertNumToHex((startsn + (sncount - 1) * (sqit.Value )).ToString()).Length > Rnle.Value)
- {
- OperateResult.AppendText(">>流水号长度超过设置长度\n", Color.Red);
- return;
- }
- }
- if (DSCIN.Checked)
- {
- firstsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), startsn.ToString());
- lastsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), (startsn + (sncount - 1) * (sqit.Value)).ToString());
- }
- else {
- firstsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), ConvertNumToHex(startsn.ToString()));
- lastsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), ConvertNumToHex((startsn + (sncount - 1) * (sqit.Value )).ToString()));
- }
- if (dh.CheckExist("SMTBIND", "sb_barcode between '"+ firstsn + "' and '"+ lastsn + "' "))
- {
- OperateResult.AppendText(">>SN导入重复\n", Color.Red);
- return;
- }
- thread = new Thread(NewPrint);
- SetLoadingWindow stw = new SetLoadingWindow(thread, "请稍候...");
- BaseUtil.SetFormCenter(stw);
- stw.ShowDialog();
- RefreshData();
- }
- catch (Exception ex)
- {
- OperateResult.AppendText(">>"+ex.Message+"\n", Color.Red);
- }
- }
- private void NewPrint()
- {
- List<string> maincodelist = new List<string>();
- List<string> nowcodelist = new List<string>();
- if (DSCIN.Checked)
- {
- for (int i = 0; i < sncount; i++)
- {
- string nowsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), (startsn + i*(sqit.Value)).ToString());
- if (i % pr_pcbacount.Value == 0)
- mincode = nowsn;
- maincodelist.Add(mincode);
- nowcodelist.Add(nowsn);
- }
- }
- else {
- for (int i = 0; i < sncount; i++)
- {
- string nowsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), ConvertNumToHex((startsn + i * (sqit.Value )).ToString()));
- if (i % pr_pcbacount.Value == 0)
- mincode = nowsn;
- maincodelist.Add(mincode);
- nowcodelist.Add(nowsn);
- }
- }
- sql.Clear();
- sql.Append("insert into smtbind(sb_id,sb_maincode,sb_barcode,sb_makecode,sb_prodcode,sb_inman,sb_indate,sb_status)");
- sql.Append("values(smtbind_seq.nextval,:maincode,:nowcode,'" + ma_code.Text + "','" + ma_prodcode.Text + "',");
- sql.Append("'" + User.UserCode + "',sysdate,0)");
- dh.BatchInsert(sql.GetString(), new string[] { "maincode", "nowcode" }, maincodelist.ToArray(), nowcodelist.ToArray());
- MessageBox.Show("导入成功!");
- OperateResult.AppendText(">>生成完毕\n", Color.Black);
- OperateResult.AppendText(">>起始号:" + firstsn + "\n", Color.Black);
- OperateResult.AppendText(">>截止号:" + lastsn + "\n", Color.Black);
- LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "SMT拼版绑定", firstsn+"到"+lastsn+"绑定成功,数量"+ sncount+",间隔"+ sqit.Value, "","");
- }
- private static string lpad(int length, string number)
- {
- while (number.Length < length)
- {
- number = "0" + number;
- }
- number = number.Substring(number.Length - length, length);
- return number;
- }
- private void Debut_Click(object sender, EventArgs e)
- {
- //if (!(ma_code.Text == ""))
- //{
- // string logout_confirm = MessageBox.Show(this.ParentForm, "是否删除此工单拼版绑定记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- // if (logout_confirm == "Yes")
- // {
- // dh.ExecuteSql("delete SMTBIND where sb_makecode ='"+ma_code.Text+"'", "delete");
- // OperateResult.AppendText(">>工单"+ma_code.Text+ "拼版绑定记录清除成功\n", Color.Green);
- // }
- //}
- //else {
- // OperateResult.AppendText(">>工单号不能为空\n", Color.Red);
- //}
- try
- {
- sncount = int.Parse(Num.Text);
- if (DSCIN.Checked)
- {
- startsn = int.Parse(Rn.Text);
- }
- else
- {
- startsn = int.Parse(Hex2Ten(Rn.Text));
- }
- if (sncount % pr_pcbacount.Value != 0)
- {
- OperateResult.AppendText(">>数量不是拼版数倍数\n", Color.Red);
- return;
- }
- if (DSCIN.Checked)
- {
- if ((startsn + (sncount - 1) * (sqit.Value)).ToString().Length > Rnle.Value)
- {
- OperateResult.AppendText(">>流水号长度超过设置长度\n", Color.Red);
- return;
- }
- }
- else
- {
- if (ConvertNumToHex((startsn + (sncount - 1) * (sqit.Value)).ToString()).Length > Rnle.Value)
- {
- OperateResult.AppendText(">>流水号长度超过设置长度\n", Color.Red);
- return;
- }
- }
- if (DSCIN.Checked)
- {
- firstsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), startsn.ToString());
- lastsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), (startsn + (sncount - 1) * (sqit.Value)).ToString());
- }
- else
- {
- firstsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), ConvertNumToHex(startsn.ToString()));
- lastsn = Prefix.Text + lpad(int.Parse(Rnle.Value.ToString()), ConvertNumToHex((startsn + (sncount - 1) * (sqit.Value)).ToString()));
- }
- string logout_confirm = MessageBox.Show(this.ParentForm, "是否删除SN: "+ firstsn + " 到 "+ lastsn + " 拼版绑定记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
- if (logout_confirm == "Yes")
- {
- dh.ExecuteSql("delete SMTBIND where sb_barcode between '" + firstsn + "' and '" + lastsn + "'", "delete");
- OperateResult.AppendText(">>SN: " + firstsn + " 到 " + lastsn + " 拼版绑定记录清除成功\n", Color.Green);
- }
- }
- catch (Exception ex)
- {
- OperateResult.AppendText(">>" + ex.Message + "\n", Color.Red);
- }
- }
- /// <summary>
- /// 从十进制转换到十六进制
- /// </summary>
- /// <param name="ten"></param>
- /// <returns></returns>
- public static string ConvertNumToHex(string ten)
- {
- ulong Numb = Convert.ToUInt64(ten);
- ulong divValue, resValue;
- string hex = "";
- do
- {
- divValue = (ulong)Math.Floor((decimal)(Numb / 16));
- resValue = Numb % 16;
- hex = GetNumb(resValue) + hex;
- Numb = divValue;
- }
- while (Numb >= 16);
- if (Numb != 0)
- hex = GetNumb(Numb) + hex;
- return hex;
- }
- public static string GetNumb(ulong Numb)
- {
- switch (Numb)
- {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- case 8:
- case 9:
- return Numb.ToString();
- case 10:
- return "A";
- case 11:
- return "B";
- case 12:
- return "C";
- case 13:
- return "D";
- case 14:
- return "E";
- case 15:
- return "F";
- default:
- return "";
- }
- }
- public static string Hex2Ten(string hex)
- {
- int ten = 0;
- for (int i = 0, j = hex.Length - 1; i < hex.Length; i++)
- {
- ten += HexChar2Value(hex.Substring(i, 1)) * ((int)Math.Pow(16, j));
- j--;
- }
- return ten.ToString();
- }
- public static int HexChar2Value(string hexChar)
- {
- switch (hexChar)
- {
- case "0":
- case "1":
- case "2":
- case "3":
- case "4":
- case "5":
- case "6":
- case "7":
- case "8":
- case "9":
- return Convert.ToInt32(hexChar);
- case "a":
- case "A":
- return 10;
- case "b":
- case "B":
- return 11;
- case "c":
- case "C":
- return 12;
- case "d":
- case "D":
- return 13;
- case "e":
- case "E":
- return 14;
- case "f":
- case "F":
- return 15;
- default:
- return 0;
- }
- }
- private void normalButton2_Click(object sender, EventArgs e)
- {
- DialogResult result = openFileDialog1.ShowDialog();
- if (result == DialogResult.OK)
- {
- textBox1.Text = openFileDialog1.FileName;
- }
- }
- private void normalButton3_Click(object sender, EventArgs e)
- {
- if (ma_code.Text == "" || textBox1.Text == "" || ma_prodcode.Text == "")
- {
- MessageBox.Show("工单号,产品编号与文件地址不可为空");
- return;
- }
- dt = eh.ImportExcel(textBox1.Text, "test");
- int number = 0;
- //for (int i = 0; i < dt.Rows.Count; i++)
- //{
- // MessageBox.Show(dt.Rows[i]["RefDes"].ToString()+":"+ dt.Rows[i]["Layer"].ToString());
- //}
- //BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt);
- List<string> maincodelist = new List<string>();
- List<string> nowcodelist = new List<string>();
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- if (dt.Rows[i]["工单"].ToString().Trim()==ma_code.Text&&dt.Rows[i]["拼板号"].ToString().Trim().Length >2 && dt.Rows[i]["打码内容"].ToString().Trim().Length > 7 && dt.Rows[i]["拼板号"].ToString().Trim().Substring(0, 2)
- == dt.Rows[i]["打码内容"].ToString().Trim().Substring(0, 2))
- {
- maincodelist.Add(dt.Rows[i]["拼板号"].ToString().Trim());
- nowcodelist.Add(dt.Rows[i]["打码内容"].ToString().Trim());
- //number++;
- }
- }
-
- sql.Clear();
- sql.Append("insert into smtbind_temp(MAINCODE,BARCODE)");
- sql.Append("values(:maincode,:nowcode)");
- dh.BatchInsert(sql.GetString(), new string[] { "maincode", "nowcode" }, maincodelist.ToArray(), nowcodelist.ToArray());
- number = int.Parse(dh.getFieldDataByCondition("smtbind_temp", "count(1) cn ", "BARCODE not in (select sb_barcode from smtbind )").ToString());
- int maqty = int.Parse(dh.getFieldDataByCondition("make", "ma_qty", "ma_code = '" + ma_code.Text + "'").ToString());
- int nowqty = int.Parse(dh.getFieldDataByCondition("smtbind", "count(1) cn ", "sb_makecode = '" + ma_code.Text + "'").ToString());
- if (nowqty + number > maqty)
- {
- OperateResult.AppendText(">>已绑定数" + nowqty + "+待绑定数" + number + "大于工单数" + maqty + "不允许操作\n", Color.Red);
- dh.ExecuteSql("delete SMTBIND_TEMP", "delete");
- return;
- }
- sql.Clear();
- sql.Append("merge into smtbind using SMTBIND_TEMP on (sb_barcode = barcode) when not MATCHED then insert (sb_id,sb_maincode,sb_barcode,sb_makecode,sb_prodcode,sb_inman,sb_indate,sb_status)");
- sql.Append(" values (SMTBIND_seq.nextval ,maincode,barcode,'" + ma_code.Text + "','"+ma_prodcode.Text+"','"+User.UserCode+"',sysdate,0)");
- dh.ExecuteSql(sql.GetString(), "insert");
- dh.ExecuteSql("delete SMTBIND_TEMP", "delete");
- MessageBox.Show("导入成功"+ number + "条!");
- OperateResult.AppendText(">>导入成功" + number + "条!\n", Color.Green);
- RefreshData();
- }
- }
- }
|