入库条码规则解析.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. using LabelManager2;
  2. using Seagull.BarTender.Print;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Drawing.Printing;
  8. using System.Linq;
  9. using System.Media;
  10. using System.Threading;
  11. using System.Windows.Forms;
  12. using static System.Runtime.CompilerServices.RuntimeHelpers;
  13. namespace UAS_BARCODEIO
  14. {
  15. public partial class 入库条码规则解析 : Form
  16. {
  17. ApplicationClass lbl;
  18. DataHelper dh = new DataHelper();
  19. Document SingleDoc;
  20. Document OutDoc;
  21. DataTable Dbfind;
  22. //自适应屏幕
  23. AutoSizeFormClass asc = new AutoSizeFormClass();
  24. public 入库条码规则解析()
  25. {
  26. InitializeComponent();
  27. }
  28. delegate void BindDataSource(DataGridView dgv, DataTable dt);//定义委托
  29. void bindingsource(DataGridView dgv, DataTable dt)
  30. {
  31. //dgv.AutoGenerateColumns = false;
  32. //dgv.DataSource = null;
  33. //dgv.DataSource = dt;
  34. if (dgv.InvokeRequired)
  35. {
  36. dgv.Invoke(new BindDataSource(bindingsource), new object[] { dgv, dt });
  37. }
  38. else
  39. {
  40. dgv.AutoGenerateColumns = false;
  41. dgv.DataSource = dt;
  42. }
  43. }
  44. private void Form1_Load(object sender, EventArgs e)
  45. {
  46. es_custcode.TableName = "CS_EXPORTSETTING ";
  47. es_custcode.SelectField = "es_custcode # 品牌";
  48. es_custcode.FormName = Name;
  49. es_custcode.DBTitle = "解析规则查询";
  50. es_custcode.SetValueField = new string[] { "es_custcode" };
  51. es_custcode.Condition = "";
  52. es_custcode.DbChange += nr_rule_DBChange;
  53. SystemInf.dh = dh;
  54. try
  55. {
  56. lbl = new ApplicationClass();
  57. }
  58. catch (Exception ex)
  59. {
  60. Console.WriteLine(ex.Message);
  61. throw;
  62. }
  63. SingleDoc = lbl.Documents.Open(System.Windows.Forms.Application.StartupPath + @"\BARCODE.lab");
  64. OutDoc = lbl.Documents.Open(System.Windows.Forms.Application.StartupPath + @"\BOXCODE.lab");
  65. asc.controllInitializeSize(this);
  66. asc.controlAutoSize(this);
  67. PrintDocument print = new PrintDocument();
  68. string sDefault = print.PrinterSettings.PrinterName;//默认打印机名
  69. foreach (string sPrint in PrinterSettings.InstalledPrinters)//获取所有打印机名称
  70. {
  71. PrinterList.Items.Add(sPrint);
  72. if (sPrint == sDefault)
  73. PrinterList.SelectedIndex = PrinterList.Items.IndexOf(sPrint);
  74. }
  75. }
  76. private void nr_rule_DBChange(object sender, EventArgs e)
  77. {
  78. Dbfind = es_custcode.ReturnData;
  79. BaseUtil.SetFormValue(this.Controls, Dbfind);
  80. }
  81. private void pi_inoutnokeydown(object sender, KeyEventArgs e)
  82. {
  83. if (e.KeyCode == Keys.Enter)
  84. {
  85. LoadGridData();
  86. }
  87. }
  88. private void LoadGridData()
  89. {
  90. string sql = "select pd_inqty,pd_prodcode,pr_detail,pr_orispeccode,pr_spec,bi_inqty,pr_brand from " +
  91. "(select max(pd_prodcode)pd_prodcode,sum(pd_inqty)pd_inqty from prodiodetail left join product on pd_prodcode=pr_code where pd_inoutno='" + pi_inoutno.Text + "' group by pr_orispeccode,pr_brand)" +
  92. " left join (select max(bi_prodcode)bi_prodcode,nvl(sum(bi_inqty),0)bi_inqty from barcodeio left join product on pr_code=bi_prodcode " +
  93. "where bi_inoutno='" + pi_inoutno.Text + "' group by pr_orispeccode,pr_brand) on pd_prodcode=bi_prodcode left join product on pr_code=pd_prodcode order by pr_code";
  94. DataTable dt = (DataTable)dh.ExecuteSql(sql, "select");
  95. BaseUtil.FillDgvWithDataTable(Prodiodetail, dt);
  96. if (Prodiodetail.Rows.Count > SelectIndex)
  97. {
  98. Prodiodetail.Rows[SelectIndex].Selected = true;
  99. }
  100. }
  101. private void Barcode_KeyDown(object sender, KeyEventArgs e)
  102. {
  103. if (e.KeyCode == Keys.Enter)
  104. {
  105. DataTable dt = (DataTable)dh.ExecuteSql("select esd_caption,esd_enable,el_type from cs_exportsettingdetail left join CS_EXPORTSETTING" +
  106. " on es_id=esd_esid where es_custcode='" + es_custcode.Text + "'", "select");
  107. if (dt.Rows.Count == 0)
  108. {
  109. Play("NG");
  110. MessageBox.Show("无条码解析规则");
  111. return;
  112. }
  113. string split = dt.Rows[0]["el_type"].ToString();
  114. string[] str = Barcode.Text.Split(split.ToCharArray()[0]);
  115. //分割后的字符串数组需要大于设置的参数解析
  116. if (str.Length < dt.Rows.Count)
  117. {
  118. Play("NG");
  119. MessageBox.Show("解析参数与解析规则不匹配");
  120. return;
  121. }
  122. for (int i = 0; i < dt.Rows.Count; i++)
  123. {
  124. string name = dt.Rows[i]["esd_caption"].ToString();
  125. string index = dt.Rows[i]["esd_enable"].ToString();
  126. switch (name)
  127. {
  128. case "LOTNO":
  129. LOTNO.Text = str[int.Parse(index) - 1];
  130. break;
  131. case "DC":
  132. DC.Text = str[int.Parse(index) - 1];
  133. break;
  134. case "PROD":
  135. pr_orispeccode3.Text = str[int.Parse(index) - 1];
  136. break;
  137. case "QTY":
  138. INQTY.Text = str[int.Parse(index) - 1];
  139. break;
  140. case "SCCODE":
  141. SCCODE.Text = str[int.Parse(index) - 1];
  142. break;
  143. default:
  144. break;
  145. }
  146. }
  147. string madedate;
  148. string outqty;
  149. string lotno;
  150. string spec;
  151. DC1.Text = DC.Text;
  152. LogicHandler.GetWeekData(DC.Text, INQTY.Text, es_custcode.Text.ToUpper(), pr_orispeccode3.Text, LOTNO.Text, out madedate, out outqty, out lotno, out spec);
  153. DC.Text = madedate;
  154. INQTY.Text = outqty;
  155. LOTNO.Text = lotno;
  156. pr_orispeccode3.Text = spec;
  157. Barcode.Clear();
  158. GenBarCode.PerformClick();
  159. Play("OK");
  160. }
  161. }
  162. bool AutoSized = false;
  163. private void 入库条码规则解析_AutoSizeChanged(object sender, EventArgs e)
  164. {
  165. if (!AutoSized)
  166. {
  167. asc.controlAutoSize(this);
  168. AutoSized = true;
  169. }
  170. }
  171. private void Prodiodetail_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  172. {
  173. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  174. if (e.ColumnIndex > 0 && e.RowIndex >= 0)
  175. {
  176. if (Prodiodetail.Columns[e.ColumnIndex].Name == "pd_prodcode")
  177. {
  178. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  179. if (Prodiodetail.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString() != Prodiodetail.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString())
  180. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.Yellow, e.CellBounds);
  181. else
  182. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.White, e.CellBounds);
  183. Rectangle border = e.CellBounds;
  184. border.Width -= 1;
  185. e.Graphics.DrawRectangle(Pens.White, border);
  186. e.PaintContent(e.CellBounds);
  187. e.Handled = true;
  188. }
  189. }
  190. }
  191. private void Prodiodetail_SelectionChanged(object sender, EventArgs e)
  192. {
  193. if (Prodiodetail.SelectedRows.Count > 0)
  194. {
  195. DataGridViewSelectedRowCollection dsc = Prodiodetail.SelectedRows;
  196. Prodiodetail.Rows[dsc[0].Index].Selected = true;
  197. if (dsc[0].Index - 2 >= 0)
  198. Prodiodetail.FirstDisplayedScrollingRowIndex = dsc[0].Index - 2;
  199. else
  200. Prodiodetail.FirstDisplayedScrollingRowIndex = dsc[0].Index;
  201. }
  202. }
  203. private void GenBarCode_Click(object sender, EventArgs e)
  204. {
  205. string sql = "select pr_zxbzs,pd_piid,pd_piclass,pd_inqty,pd_prodcode,pr_detail,pr_spec,nvl(bi_inqty,0)bi_inqty from " +
  206. "(select max(pd_piid)pd_piid,max(pd_piclass)pd_piclass,max(pd_prodcode)pd_prodcode,sum(pd_inqty)pd_inqty from prodiodetail left join product on pr_code=pd_prodcode where pd_inoutno='" + pi_inoutno.Text + "' group by pr_orispeccode,pr_brand)" +
  207. " left join (select max(bi_prodcode)bi_prodcode,nvl(sum(bi_inqty),0)bi_inqty from barcodeio left join product on pr_code=bi_prodcode " +
  208. "where bi_inoutno='" + pi_inoutno.Text + "' group by pr_orispeccode,pr_brand) on pd_prodcode=bi_prodcode left join product on pr_code=pd_prodcode " +
  209. "where pr_code='" + PR_CODE.Text + "'";
  210. DataTable dt = (DataTable)dh.ExecuteSql(sql, "select");
  211. if (dt.Rows.Count == 0)
  212. {
  213. Play("NG");
  214. MessageBox.Show("物料不在对应入库单中" + pi_inoutno.Text);
  215. return;
  216. }
  217. if (pr_orispeccode2.Text != pr_orispeccode3.Text)
  218. {
  219. Play("NG");
  220. MessageBox.Show("解析型号和单据型号不对应");
  221. return;
  222. }
  223. ZXBZ.Text = dt.Rows[0]["pr_zxbzs"].ToString();
  224. int pdinqty = int.Parse(dt.Rows[0]["pd_inqty"].ToString());
  225. int barqty = int.Parse(dt.Rows[0]["bi_inqty"].ToString());
  226. int Minpackage = 0;
  227. string pi_id = dt.Rows[0]["pd_piid"].ToString();
  228. string pd_piclass = dt.Rows[0]["pd_piclass"].ToString();
  229. //本次入库数
  230. int NowInqty = int.Parse(INQTY.Text);
  231. if (!int.TryParse(ZXBZ.Text, out Minpackage))
  232. {
  233. Play("NG");
  234. MessageBox.Show("最小包装数错误,料号" + PR_CODE.Text);
  235. return;
  236. }
  237. if (int.Parse(INQTY.Text) > pdinqty - barqty)
  238. {
  239. Play("NG");
  240. MessageBox.Show("物料采集后超出入库单数量" + PR_CODE.Text);
  241. return;
  242. }
  243. string outboxcode = "";
  244. if (GenBoxCode.Checked)
  245. {
  246. string[] param = new string[] { PR_CODE.Text, "", outboxcode };
  247. dh.CallProcedure("SP_GETBOX", ref param);
  248. outboxcode = param[2].Replace("BOX:", "");
  249. }
  250. //生成条码数量
  251. int barcount = NowInqty % Minpackage == 0 ? NowInqty / Minpackage : (NowInqty / Minpackage) + 1;
  252. List<string> bi_inqty = new List<string>();
  253. List<string> bi_barcode = new List<string>();
  254. List<string> bi_vendbarcode = new List<string>();
  255. List<string> bi_madedate = new List<string>();
  256. List<string> bi_sccode = new List<string>();
  257. for (int i = 0; i < barcount; i++)
  258. {
  259. string barcode = "";
  260. int OneUnit = 0;
  261. string[] param = new string[] { PR_CODE.Text, "", barcode };
  262. dh.CallProcedure("SP_GETBARCODE", ref param);
  263. barcode = param[2].Replace("BARCODE:", "");
  264. //如果最后有尾数的话
  265. if (i == barcount - 1)
  266. {
  267. if (NowInqty % Minpackage == 0)
  268. {
  269. OneUnit = Minpackage;
  270. }
  271. else
  272. {
  273. OneUnit = NowInqty % Minpackage;
  274. }
  275. }
  276. else
  277. {
  278. OneUnit = Minpackage;
  279. }
  280. bi_inqty.Add(OneUnit.ToString());
  281. bi_barcode.Add(barcode);
  282. bi_vendbarcode.Add(LOTNO.Text);
  283. bi_madedate.Add(DC.Text);
  284. bi_sccode.Add(SCCODE.Text);
  285. }
  286. sql = "insert into barcodeio(BI_ID,bi_made, BI_BARCODE, BI_PIID, BI_PICLASS, BI_INOUTNO, BI_PDNO, BI_PDID, BI_PRODCODE, BI_INQTY,bi_vendbarcode, " +
  287. "BI_MADEDATE, BI_PRODID, BI_STATUS, BI_ORDERCODE, BI_INMAN, BI_INDATE,BI_OUTBOXCODE,bi_sccode)select barcodeio_seq.nextval,'"+ DC1.Text + "',:bi_barcode,'" + pi_id + "'," +
  288. "'" + pd_piclass + "','" + pi_inoutno.Text + "',0,0,'" + PR_CODE.Text + "',:bi_inqty,:bi_vendbarcode,to_date(:bi_madedate,'yyyy-mm-dd'),pr_id,0,'','管理员',sysdate,'" + outboxcode + "',:bi_sccode " +
  289. " from product where pr_code='" + PR_CODE.Text + "'";
  290. dh.BatchInsert(sql, new string[] { "bi_inqty", "bi_barcode", "bi_vendbarcode", "bi_madedate" , "bi_sccode" }, bi_barcode.ToArray(), bi_inqty.ToArray(), bi_vendbarcode.ToArray(), bi_madedate.ToArray(),bi_sccode.ToArray());
  291. LoadGridData();
  292. LoadBarcodeioData(PR_CODE.Text);
  293. }
  294. private void LoadBarcodeioData(string pr_code)
  295. {
  296. string sql = "select 0 CheckBox,bi_sccode,bi_barcode,bi_inqty,bi_datecode,bi_outboxcode,bi_vendbarcode,to_char(bi_madedate,'yyyy-mm-dd')bi_madedate,to_char(bi_madedate,'yyiw')dc_week,pr_detail,pr_spec,bi_prodcode,pr_orispeccode from barcodeio left join product on bi_prodcode=pr_code where bi_inoutno='" + pi_inoutno.Text + "' and bi_prodcode='" + pr_code + "'";
  297. DataTable dt = (DataTable)dh.ExecuteSql(sql, "select");
  298. BaseUtil.FillDgvWithDataTable(BarcodeIO, dt);
  299. }
  300. private void PrintBarCode_Click(object sender, EventArgs e)
  301. {
  302. for (int i = 0; i < BarcodeIO.Rows.Count; i++)
  303. {
  304. if (BarcodeIO.Rows[i].Cells["CheckBox"].FormattedValue != null && BarcodeIO.Rows[i].Cells["CheckBox"].FormattedValue.ToString() == "True")
  305. {
  306. for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++)
  307. {
  308. if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "BARCODE")
  309. {
  310. if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null)
  311. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["bi_barcode"].Value.ToString();
  312. }
  313. if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "DC")
  314. {
  315. if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null)
  316. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["bi_madedate"].Value.ToString();
  317. }
  318. if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "LOTNO")
  319. {
  320. if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null)
  321. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["bi_vendbarcode"].Value.ToString();
  322. }
  323. if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "QTY")
  324. {
  325. if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null)
  326. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["bi_inqty1"].Value.ToString();
  327. }
  328. if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "PRCODE")
  329. {
  330. if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null)
  331. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["bi_prodcode"].Value.ToString();
  332. }
  333. if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "PRSPEC")
  334. {
  335. if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null)
  336. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["pr_spec1"].Value.ToString();
  337. }
  338. if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "PRDETAIL")
  339. {
  340. if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null)
  341. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["pr_detail1"].Value.ToString();
  342. }
  343. if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "ORISPEC")
  344. {
  345. if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null)
  346. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["pr_orispeccode"].Value.ToString();
  347. }
  348. if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "DC_WEEK")
  349. {
  350. if (BarcodeIO.Rows[i].Cells["dc_week"].Value != null)
  351. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = BarcodeIO.Rows[i].Cells["dc_week"].Value.ToString();
  352. }
  353. }
  354. SingleDoc.Printer.SwitchTo(PrinterList.Text);
  355. SingleDoc.PrintDocument();
  356. }
  357. }
  358. }
  359. private void Prodiodetail_CellContentClick(object sender, DataGridViewCellEventArgs e)
  360. {
  361. if (Prodiodetail.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString() != "")
  362. {
  363. }
  364. }
  365. int SelectIndex = 0;
  366. private void Prodiodetail_CellClick(object sender, DataGridViewCellEventArgs e)
  367. {
  368. if (Prodiodetail.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString() != "")
  369. {
  370. LoadBarcodeioData(Prodiodetail.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString());
  371. Console.WriteLine(Prodiodetail.Rows[e.RowIndex].Cells["pr_brand"].Value.ToString());
  372. es_custcode.Text = Prodiodetail.Rows[e.RowIndex].Cells["pr_brand"].Value.ToString();
  373. PR_CODE.Text = Prodiodetail.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString();
  374. pr_orispeccode2.Text = Prodiodetail.Rows[e.RowIndex].Cells["pr_orispeccode1"].Value.ToString();
  375. LoadBarcodeioData(Prodiodetail.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString());
  376. SelectIndex = e.RowIndex;
  377. }
  378. }
  379. private void ChooseAll_Click(object sender, EventArgs e)
  380. {
  381. for (int i = 0; i < BarcodeIO.Rows.Count; i++)
  382. {
  383. BarcodeIO.Rows[i].Cells["CheckBox"].Value = true;
  384. }
  385. }
  386. private void PrintBox_Click(object sender, EventArgs e)
  387. {
  388. List<string> outboxcode = new List<string>();
  389. for (int i = 0; i < BarcodeIO.Rows.Count; i++)
  390. {
  391. if (BarcodeIO.Rows[i].Cells["CheckBox"].FormattedValue != null && BarcodeIO.Rows[i].Cells["CheckBox"].FormattedValue.ToString() == "True")
  392. {
  393. if (!outboxcode.Contains(BarcodeIO.Rows[i].Cells["bi_outboxcode"].FormattedValue))
  394. {
  395. outboxcode.Add(BarcodeIO.Rows[i].Cells["bi_outboxcode"].Value.ToString());
  396. }
  397. }
  398. }
  399. string[] box = outboxcode.ToArray();
  400. for (int i = 0; i < box.Length; i++)
  401. {
  402. string sql = "select bi_outboxcode,sum(bi_inqty)bi_inqty,max(bi_datecode)bi_datecode,max(bi_vendbarcode)bi_vendbarcode,max(to_char(bi_madedate,'yyyy-mm-dd'))bi_madedate," +
  403. "max(pr_detail)pr_detail,max(pr_spec)pr_spec,max(bi_prodcode)bi_prodcode,max(pr_orispeccode)pr_orispeccode,max(pr_detail)pr_detail from barcodeio left join product on bi_prodcode=pr_code where bi_outboxcode='" + box[i] + "' group by bi_outboxcode";
  404. DataTable dt = (DataTable)dh.ExecuteSql(sql, "select");
  405. for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++)
  406. {
  407. if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "BARCODE")
  408. {
  409. if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null)
  410. OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["bi_outboxcode"].ToString();
  411. }
  412. if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "DC")
  413. {
  414. if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null)
  415. OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["bi_madedate"].ToString();
  416. }
  417. if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "LOTNO")
  418. {
  419. if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null)
  420. OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["bi_vendbarcode"].ToString();
  421. }
  422. if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "QTY")
  423. {
  424. if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null)
  425. OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["bi_inqty"].ToString();
  426. }
  427. if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "PRCODE")
  428. {
  429. if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null)
  430. OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["bi_prodcode"].ToString();
  431. }
  432. if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "PRSPEC")
  433. {
  434. if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null)
  435. OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["pr_spec"].ToString();
  436. }
  437. if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "PRDETAIL")
  438. {
  439. if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null)
  440. OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["pr_detail"].ToString();
  441. }
  442. if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "ORISPEC")
  443. {
  444. if (BarcodeIO.Rows[i].Cells["bi_madedate"].Value != null)
  445. OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["pr_orispeccode"].ToString();
  446. }
  447. if (OutDoc.Variables.FreeVariables.Item(j + 1).Name.ToUpper() == "DC_WEEK")
  448. {
  449. if (BarcodeIO.Rows[i].Cells["dc_week"].Value != null)
  450. OutDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0]["dc_week"].ToString();
  451. }
  452. }
  453. OutDoc.Printer.SwitchTo(PrinterList.Text);
  454. OutDoc.PrintDocument();
  455. }
  456. }
  457. private void PrintStockBarCode_Click(object sender, EventArgs e)
  458. {
  459. 库存条码打印 form = new 库存条码打印();
  460. form.ShowDialog();
  461. }
  462. private void DeletaBarcode_Click(object sender, EventArgs e)
  463. {
  464. for (int i = 0; i < BarcodeIO.Rows.Count; i++)
  465. {
  466. if (BarcodeIO.Rows[i].Cells["CheckBox"].FormattedValue != null && BarcodeIO.Rows[i].Cells["CheckBox"].FormattedValue.ToString() == "True")
  467. {
  468. dh.ExecuteSql("delete from barcodeio where bi_barcode='" + BarcodeIO.Rows[i].Cells["bi_barcode"].Value.ToString() + "'", "delete");
  469. }
  470. }
  471. LoadBarcodeioData(PR_CODE.Text);
  472. }
  473. Thread thread;
  474. string FileName = "";
  475. public void Play(string Type)
  476. {
  477. if (Type == "OK")
  478. {
  479. FileName = System.Windows.Forms.Application.StartupPath + @"\Resources\Sound\8378.wav";
  480. thread = new Thread(PlaySound);
  481. thread.Start();
  482. }
  483. else
  484. {
  485. FileName = System.Windows.Forms.Application.StartupPath + @"\Resources\Sound\5185.wav";
  486. thread = new Thread(PlaySound);
  487. thread.Start();
  488. }
  489. }
  490. private void PlaySound()
  491. {
  492. //要加载COM组件:Microsoft speech object Library
  493. if (!System.IO.File.Exists(FileName))
  494. {
  495. return;
  496. }
  497. try
  498. {
  499. SoundPlayer player = new SoundPlayer();
  500. player.SoundLocation = FileName;
  501. player.Load();
  502. player.Play();
  503. }
  504. catch (Exception e)
  505. {
  506. MessageBox.Show(e.Message);
  507. }
  508. }
  509. }
  510. }