新建文本文档.txt 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using 贴标机标签打印.CustomControl.GroupBoxWithBorder;
  6. using 贴标机标签打印.PublicMethod;
  7. using System.Text.RegularExpressions;
  8. using System.Text;
  9. using LabelManager2;
  10. using System.Collections.Generic;
  11. namespace 贴标机标签打印
  12. {
  13. public partial class 贴标机条码打印 : Form
  14. {
  15. AutoSizeFormClass asc = new AutoSizeFormClass();
  16. DataHelper dh;
  17. DataTable dt;
  18. StringBuilder sql = new StringBuilder();
  19. /*CodeSoft新建打印机引擎*/
  20. ApplicationClass lbl;
  21. /*单盘打印文件*/
  22. Document SingleDoc;
  23. /*中盒打印文件*/
  24. Document MidDoc;
  25. /*外箱打印文件*/
  26. Document OutBoxDoc;
  27. string PI_ID;
  28. //当前扫描的项目
  29. int CurrentIndex = 0;
  30. //当前扫描的所在行
  31. int CurrentRowIndex = 0;
  32. //需要重绘的Cell的RowIndx
  33. int CellRowIndex = -2;
  34. /*正则表达式用于项目匹配*/
  35. Regex reg;
  36. /*标识一行采集是否通过*/
  37. bool CollectPass = true;
  38. /*用于存放采集项目的Grid信息*/
  39. Dictionary<string, Dictionary<string, string>> SiItem;
  40. //使用二位数组进行排序
  41. ArrayList<ArrayList<string>> Data;
  42. ArrayList<string> GetData;
  43. public 贴标机条码打印()
  44. {
  45. InitializeComponent();
  46. }
  47. protected override void WndProc(ref System.Windows.Forms.Message m)
  48. {
  49. //拦截双击标题栏、移动窗体的系统消息
  50. if (m.Msg != 0xA3)
  51. {
  52. base.WndProc(ref m);
  53. }
  54. }
  55. private void 贴标机条码打印_Load(object sender, EventArgs e)
  56. {
  57. asc.controllInitializeSize(this);
  58. dh = new DataHelper();
  59. pi_inoutno.Focus();
  60. //将本地读取的打印机设置进Combox,并选中默认打印机
  61. sg_code.Caller = "LabelMachine";
  62. sg_code.FormName = Name;
  63. sg_code.SetValueField = new string[] { "sg_code" };
  64. pr_code.Caller = "LabelMachine";
  65. pr_code.FormName = Name;
  66. pr_code.SetValueField = new string[] { "pr_code", "pib_id" };
  67. ChooseAll.ChooseAll(LabelInf);
  68. Point pt = new Point();
  69. int ScreenHeight = Screen.GetWorkingArea(pt).Width;
  70. //如果分辨率大的设置的字体对应的变大
  71. if (ScreenHeight > 1366)
  72. {
  73. foreach (Control ctl in Controls)
  74. {
  75. if (ctl is CheckBox || ctl is Label || ctl is RadioButton)
  76. {
  77. ctl.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
  78. }
  79. if (ctl is GroupBoxWithBorder)
  80. {
  81. GroupBoxWithBorder gb = ctl as GroupBoxWithBorder;
  82. for (int i = 0; i < gb.Controls.Count; i++)
  83. {
  84. if (gb.Controls[i] is CheckBox || gb.Controls[i] is Label || gb.Controls[i] is RadioButton)
  85. {
  86. gb.Controls[i].Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
  87. }
  88. }
  89. }
  90. }
  91. }
  92. //设置获取当前屏幕大小自动全屏但是保留任务栏
  93. Rectangle ScreenArea = Screen.GetWorkingArea(this);
  94. Top = 0;
  95. Left = 0;
  96. Width = ScreenArea.Width;
  97. Height = ScreenArea.Height;
  98. asc.controlAutoSize(this);
  99. //实例化打印进程
  100. try
  101. {
  102. lbl = new ApplicationClass();
  103. }
  104. catch (Exception)
  105. {
  106. MessageBox.Show("未安装CodeSoft软件或者版本错误");
  107. }
  108. }
  109. private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
  110. {
  111. asc.controlAutoSize(this);
  112. }
  113. private void GenerateBarCode_Click(object sender, EventArgs e)
  114. {
  115. 生成条码 form = new 生成条码(pi_inoutno.Text);
  116. form.FormClosed += LoadGridData;
  117. BaseUtil.SetFormCenter(form);
  118. form.ShowDialog();
  119. }
  120. private void CollectionSetting_Click(object sender, EventArgs e)
  121. {
  122. 采集策略 form = new 采集策略(sg_code.Text);
  123. form.FormClosed += sg_code_UserControlTextChanged;
  124. BaseUtil.SetFormCenter(form);
  125. form.ShowDialog();
  126. }
  127. private void LabelMaintain_Click(object sender, EventArgs e)
  128. {
  129. 客户标签维护 form = new 客户标签维护();
  130. BaseUtil.SetFormCenter(form);
  131. form.ShowDialog();
  132. }
  133. /// <summary>
  134. /// 保存明细
  135. /// </summary>
  136. /// <param name="sender"></param>
  137. /// <param name="e"></param>
  138. private void SaveGrid_Click(object sender, EventArgs e)
  139. {
  140. DataTable savedt = LabelInf.DataSource as DataTable;
  141. if (LabelInf.DataSource != null && savedt.GetChanges() != null)
  142. {
  143. dh.UpDateTableByCondition((LabelInf.DataSource as DataTable).GetChanges(), "ProdioBarCode", "pib_id");
  144. }
  145. }
  146. //放大镜选择后出发的事件
  147. private void sg_code_UserControlTextChanged(object sender, EventArgs e)
  148. {
  149. //取已启用的的按照采集次序排序
  150. dt = (DataTable)dh.ExecuteSql("select si_item,si_detno,sg_separator,si_kind,si_expression,si_index,si_indexstring,si_length from scanitem left join scangroup on si_sgid=sg_id where sg_code='" + sg_code.Text + "' and si_enable<>0 order by si_detno", "select");
  151. BaseUtil.FillDgvWithDataTable(Si_ItemDGV, dt);
  152. if (dt.Rows.Count > 0)
  153. {
  154. sg_separator.Text = dt.Rows[0]["sg_separator"].ToString();
  155. }
  156. Data = new ArrayList<ArrayList<string>>();
  157. GetData = new ArrayList<string>();
  158. //将数据添加进一个List的二维数组中
  159. for (int i = 0; i < Si_ItemDGV.RowCount; i++)
  160. {
  161. //如果不包含这个则添加进数组
  162. if (!GetData.Contains(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString()))
  163. {
  164. GetData.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString());
  165. }
  166. //如果和后一个的采集次序相同
  167. if (((i + 1) < Si_ItemDGV.RowCount) && Si_ItemDGV.Rows[i].Cells["si_detno"].Value.ToString() == Si_ItemDGV.Rows[i + 1].Cells["si_detno"].Value.ToString())
  168. {
  169. GetData.Add(Si_ItemDGV.Rows[i + 1].Cells["si_item"].Value.ToString());
  170. }
  171. else {
  172. Data.Add(GetData);
  173. //添加完一次数据需要一个新的List
  174. GetData = new ArrayList<string>();
  175. }
  176. }
  177. if (Data.ToArray().Length > 0)
  178. {
  179. if ((Data.ToArray()[0] as ArrayList<string>).Contains("MPN"))
  180. {
  181. AutoMatch.CheckState = CheckState.Checked;
  182. AutoMatch.Enabled = true;
  183. }
  184. else {
  185. AutoMatch.CheckState = CheckState.Unchecked;
  186. AutoMatch.Enabled = false;
  187. }
  188. }
  189. }
  190. //输入框Enter事件
  191. private void Input_KeyDown(object sender, KeyEventArgs e)
  192. {
  193. if (e.KeyCode == Keys.Enter)
  194. {
  195. if (Input.Text == "")
  196. {
  197. BaseUtil.ShowError("采集的数据不能为空");
  198. }
  199. //如果勾选了自动采集
  200. if (AutoMatch.Checked)
  201. {
  202. CollectData();
  203. }
  204. else {
  205. if (pib_id.Text != "")
  206. {
  207. for (int i = 0; i < LabelInf.RowCount; i++)
  208. {
  209. if (LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() == pib_id.Text)
  210. {
  211. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_id1"].RowIndex;
  212. }
  213. }
  214. }
  215. else {
  216. BaseUtil.ShowError("非自动匹配时必须选择指定的行");
  217. }
  218. CollectData();
  219. }
  220. }
  221. }
  222. private void ComSetting_Click(object sender, EventArgs e)
  223. {
  224. 参数及端口配置 form = new 参数及端口配置();
  225. BaseUtil.SetFormCenter(form);
  226. form.ShowDialog();
  227. }
  228. /// <summary>
  229. /// 采集数据
  230. /// </summary>
  231. private void CollectData()
  232. {
  233. Data = new ArrayList<ArrayList<string>>();
  234. GetData = new ArrayList<string>();
  235. //用于保存采集策略的具体信息
  236. SiItem = new Dictionary<string, Dictionary<string, string>>();
  237. //是否通过,一行采集结束时会通过此参数进行验证
  238. CollectPass = true;
  239. for (int i = 0; i < Si_ItemDGV.RowCount; i++)
  240. {
  241. //如果不包含这个则添加进数组
  242. if (!GetData.Contains(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString()))
  243. {
  244. GetData.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString());
  245. }
  246. //如果和后一个的采集次序相同
  247. if (((i + 1) < Si_ItemDGV.RowCount) && Si_ItemDGV.Rows[i].Cells["si_detno"].Value.ToString() == Si_ItemDGV.Rows[i + 1].Cells["si_detno"].Value.ToString())
  248. {
  249. GetData.Add(Si_ItemDGV.Rows[i + 1].Cells["si_item"].Value.ToString());
  250. }
  251. else {
  252. Data.Add(GetData);
  253. //添加完一次数据需要一个新的List
  254. GetData = new ArrayList<string>();
  255. }
  256. Dictionary<string, string> item = new Dictionary<string, string>();
  257. for (int j = 0; j < Si_ItemDGV.ColumnCount; j++)
  258. {
  259. item.Add(Si_ItemDGV.Columns[j].DataPropertyName, Si_ItemDGV.Rows[i].Cells[j].Value.ToString());
  260. }
  261. SiItem.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString().ToUpper(), item);
  262. }
  263. //采集项目的数组
  264. object[] ItemData = (Data.ToArray()[CurrentIndex] as ArrayList<string>).ToArray();
  265. //分隔符不为空的时候
  266. if (sg_separator.Text != "")
  267. {
  268. //用户采集的数据的分割数组
  269. string[] CollectData = Input.Text.Split(sg_separator.Text.ToCharArray());
  270. //首先判断当前采集的个数,如果采集的个数为1则不对数据进行分隔符验证
  271. if (ItemData.Length == 1)
  272. {
  273. //将筛选之后的值赋给Cell
  274. SetDataToCell(CollectData, ItemData[0].ToString().ToUpper());
  275. }
  276. //如果本次采集的数据分割后和当前的采集项目个数不一样提示用户错误
  277. else if (CollectData.Length == ItemData.Length)
  278. {
  279. for (int i = 0; i < ItemData.Length; i++)
  280. {
  281. //将筛选之后的值赋给Cell
  282. Console.WriteLine("ITEM:" + CollectData[i]);
  283. Console.WriteLine("Data"+ ItemData[i].ToString());
  284. SetDataToCell(CollectData, ItemData[i].ToString().ToUpper());
  285. }
  286. }
  287. else {
  288. BaseUtil.ShowError("所采集的数据个数和采集项目不符");
  289. }
  290. }
  291. else {
  292. if (Data.ToArray().Length != Si_ItemDGV.RowCount)
  293. {
  294. BaseUtil.ShowError("所选采集策略和当前采集项目不符合,含有同顺序采集项时必须维护分隔符!");
  295. }
  296. }
  297. Console.WriteLine(CurrentIndex);
  298. CurrentIndex = CurrentIndex + 1;
  299. if (CurrentIndex == Data.ToArray().Length)
  300. {
  301. if (CollectPass)
  302. {
  303. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
  304. //CollectedCount.Text = (int.Parse(CollectedCount.Text) + 1).ToString();
  305. }
  306. else {
  307. //如果自动采集采集未成功需要移动到下一行
  308. if (AutoMatch.Checked)
  309. {
  310. //如果已经到了最后一行则不移动
  311. CurrentRowIndex = CurrentRowIndex + 1 == LabelInf.RowCount ? CurrentRowIndex : CurrentRowIndex + 1;
  312. }
  313. }
  314. //当前项目已采集完成,重置采集项目
  315. CurrentIndex = 0;
  316. if (AutoMatch.Checked)
  317. {
  318. for (int i = CurrentRowIndex; i < LabelInf.RowCount; i++)
  319. {
  320. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  321. {
  322. griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
  323. pr_code.Text = LabelInf.Rows[i].Cells["pib_prodcode"].FormattedValue.ToString();
  324. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
  325. break;
  326. }
  327. }
  328. }
  329. }
  330. }
  331. /// <summary>
  332. /// 自定义函数 将匹配之后的值设置到Cell中
  333. /// </summary>
  334. /// <param name="data"></param>
  335. /// <param name="kind"></param>
  336. private void SetDataToCell(string[] data, string kind)
  337. {
  338. for (int i = 0; i < data.Length; i++)
  339. {
  340. switch (kind.ToString().ToUpper())
  341. {
  342. case "DATECODE":
  343. LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value = MatchStr(data[i], "DATECODE");
  344. break;
  345. case "LOTNO":
  346. LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value = MatchStr(data[i], "LOTNO");
  347. break;
  348. case "MPN":
  349. if (LabelInf.Rows[CurrentRowIndex].Cells["pr_vendprodcode"].Value.ToString() != MatchStr(data[i], "MPN"))
  350. {
  351. CellRowIndex = CurrentRowIndex;
  352. LabelInf.Rows[CurrentRowIndex].Cells["pr_vendprodcode"].Selected = true;
  353. CollectPass = false;
  354. MessageLog.AppendText(">>供应商物料编号不匹配\n", Color.Red);
  355. }
  356. break;
  357. case "QTY":
  358. //如果采集的数量不相等的话
  359. if (LabelInf.Rows[CurrentRowIndex].Cells["pib_qty"].Value.ToString() != MatchStr(data[i], "QTY"))
  360. {
  361. CellRowIndex = CurrentRowIndex;
  362. LabelInf.Rows[CurrentRowIndex].Cells["pib_qty"].Selected = true;
  363. CollectPass = false;
  364. MessageLog.AppendText(">>数量不匹配\n", Color.Red);
  365. }
  366. break;
  367. default:
  368. break;
  369. }
  370. }
  371. }
  372. /// <summary>
  373. /// 自定义函数 根据匹配规则
  374. /// si_item的二维数组,str是需要赋值的字符串,item表示DateCode,LotNo等
  375. /// </summary>
  376. /// <param name="SiItem"></param>
  377. /// <param name="str"></param>
  378. /// <param name="item"></param>
  379. /// <returns></returns>
  380. private string MatchStr(string str, string item)
  381. {
  382. string kind = SiItem[item]["si_kind"];
  383. //起始字符不为空的时候
  384. switch (kind)
  385. {
  386. case "起始位置":
  387. if (SiItem[item]["si_index"] != "")
  388. {
  389. //长度不为空的时候按照指定的长度去取数据
  390. if (SiItem[item]["si_length"] != "")
  391. {
  392. str = str.Substring(int.Parse(SiItem[item]["si_index"]), int.Parse(SiItem[item]["si_length"]));
  393. }
  394. //长度为空的时候取index之后的全部数据
  395. else {
  396. str = str.Substring(int.Parse(SiItem[item]["si_index"]));
  397. }
  398. }
  399. break;
  400. case "索引字符":
  401. if (SiItem[item]["si_indexstring"] != "")
  402. {
  403. //长度不为空的时候按照指定的长度去取数据
  404. if (SiItem[item]["si_length"] != "")
  405. {
  406. str = str.Substring(str.IndexOf(SiItem[item]["si_indexstring"]) + 1, int.Parse(SiItem[item]["si_length"]));
  407. }
  408. //长度为空的时候取index之后的全部数据
  409. else {
  410. str = str.Substring(int.Parse(SiItem[item]["si_indexstring"]));
  411. }
  412. }
  413. break;
  414. default:
  415. break;
  416. }
  417. if (SiItem[item]["si_expression"] != "")
  418. {
  419. reg = new Regex(SiItem[item]["si_expression"]);
  420. str = reg.Match(str).Value;
  421. }
  422. return str;
  423. }
  424. //关闭窗口前提示用户确认
  425. private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
  426. {
  427. string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  428. if (close.ToString() != "Yes")
  429. {
  430. e.Cancel = true;
  431. }
  432. else {
  433. //防止未安装打印程序时报错导致窗体无法关闭
  434. try
  435. {
  436. lbl.Application.Quit();
  437. }
  438. catch {
  439. }
  440. }
  441. }
  442. /// <summary>
  443. /// 出入库单录入框的回车事件
  444. /// </summary>
  445. /// <param name="sender"></param>
  446. /// <param name="e"></param>
  447. private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
  448. {
  449. if (e.KeyCode == Keys.Enter)
  450. {
  451. sql.Clear();
  452. sql.Append("select pi_id,pi_cardcode from prodinout where pi_inoutno='" + pi_inoutno.Text + "'");
  453. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  454. if (dt.Rows.Count > 0)
  455. {
  456. string pi_cardcode = dt.Rows[0]["pi_cardcode"].ToString();
  457. PI_ID = dt.Rows[0]["pi_id"].ToString();
  458. LoadGridData(sender, e);
  459. sql.Clear();
  460. sql.Append("select cl_labelcode,cl_labelurl,cl_isdefault from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  461. sql.Append("where pi_cardcode='" + pi_cardcode + "' and pi_inoutno='" + pi_inoutno.Text + "' and cl_labeltype='单盘'");
  462. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  463. SingleLabelCombox.DataSource = dt;
  464. SingleLabelCombox.DisplayMember = "cl_labelcode";
  465. SingleLabelCombox.ValueMember = "cl_labelurl";
  466. sql.Clear();
  467. sql.Append("select cl_labelcode,cl_labelurl,cl_isdefault from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  468. sql.Append("where pi_cardcode='" + pi_cardcode + "' and pi_inoutno='" + pi_inoutno.Text + "' and cl_labeltype='中盒'");
  469. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  470. MidLabelCombox.DataSource = dt.Copy();
  471. MidLabelCombox.DisplayMember = "cl_labelcode";
  472. MidLabelCombox.ValueMember = "cl_labelurl";
  473. sql.Clear();
  474. sql.Append("select cl_labelcode,cl_labelurl,cl_isdefault from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  475. sql.Append("where pi_cardcode='" + pi_cardcode + "' and pi_inoutno='" + pi_inoutno.Text + "' and cl_labeltype='外箱'");
  476. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  477. OutBoxCombox.DataSource = dt.Copy();
  478. OutBoxCombox.DisplayMember = "cl_labelcode";
  479. OutBoxCombox.ValueMember = "cl_labelurl";
  480. }
  481. else {
  482. MessageBox.Show("当前出入库单号不存在!");
  483. }
  484. }
  485. }
  486. private void SingleLabelPrint_Click(object sender, EventArgs e)
  487. {
  488. SingleDoc = lbl.Documents.Open(SingleLabelCombox.SelectedValue.ToString());
  489. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  490. SingleDoc.PrintDocument();
  491. }
  492. private void MidLabelPrint_Click(object sender, EventArgs e)
  493. {
  494. MidDoc = lbl.Documents.Open(MidLabelCombox.SelectedValue.ToString());
  495. MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
  496. MidDoc.PrintDocument();
  497. }
  498. private void OutBoxLabelPrint_Click(object sender, EventArgs e)
  499. {
  500. OutBoxDoc = lbl.Documents.Open(OutBoxCombox.SelectedValue.ToString());
  501. OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
  502. OutBoxDoc.PrintDocument();
  503. }
  504. private void CleanDetail_Click(object sender, EventArgs e)
  505. {
  506. ArrayList<string> DeleteID = new ArrayList<string>();
  507. for (int i = 0; i < LabelInf.RowCount; i++)
  508. {
  509. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  510. {
  511. DeleteID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  512. }
  513. }
  514. //勾选了删除的明细之后
  515. if (DeleteID.ToArray().Length > 0)
  516. {
  517. string close = MessageBox.Show(this.ParentForm, "删除后不可恢复,是否确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  518. if (close.ToString() == "Yes")
  519. {
  520. dh.BatchInsert("delete from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray());
  521. MessageBox.Show("删除成功");
  522. LoadGridData(sender, e);
  523. }
  524. }
  525. else {
  526. MessageBox.Show("尚未勾选需要删除的明细");
  527. }
  528. }
  529. /// <summary>
  530. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  531. /// </summary>
  532. /// <param name="sender"></param>
  533. /// <param name="e"></param>
  534. private void LoadGridData(object sender, EventArgs e)
  535. {
  536. sql.Clear();
  537. sql.Append("select pib_id,pib_pdid,pib_piid,pib_pdno,pib_prodcode,pr_brand,pr_vendprodcode,");
  538. sql.Append("pib_lotno,pib_datecode,pib_qty,pib_barcode,pib_outboxcode1 ,pib_outboxcode2,");
  539. sql.Append("pib_ifpick, pib_ifprint from prodiodetail left join prodiobarcode on pib_piid=pd_piid and ");
  540. sql.Append("pd_pdno=pib_pdno and pd_prodcode=pib_prodcode left join product on ");
  541. sql.Append("pr_code=pib_prodcode where pd_piid='" + PI_ID + "' order by pd_id ,pib_id");
  542. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  543. BaseUtil.FillDgvWithDataTable(LabelInf, dt);
  544. //有数据的话默认取第一条的品牌去取采集策略
  545. TotalCount.Text = LabelInf.RowCount.ToString();
  546. if (LabelInf.RowCount > 0)
  547. {
  548. string brand = LabelInf.Rows[0].Cells["pr_brand"].FormattedValue.ToString();
  549. if (brand != "")
  550. sg_code.Text = dh.getFieldDataByCondition("scangroup", "sg_code", "sg_brand='" + brand + "'").ToString();
  551. }
  552. //绑定数据之后往下找到未采集的数据显示在当前采集的栏目
  553. for (int i = 0; i < LabelInf.RowCount; i++)
  554. {
  555. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  556. {
  557. griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
  558. pr_code.Text = LabelInf.Rows[i].Cells["pib_prodcode"].FormattedValue.ToString();
  559. pib_id.Text = LabelInf.Rows[i].Cells["pib_id1"].FormattedValue.ToString();
  560. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
  561. break;
  562. }
  563. }
  564. CellRowIndex = -2;
  565. }
  566. /// <summary>
  567. /// 重绘Cell的颜色
  568. /// </summary>
  569. /// <param name="sender"></param>
  570. /// <param name="e"></param>
  571. private void LabelInf_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  572. {
  573. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  574. if (e.ColumnIndex > 0)
  575. {
  576. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_lotno" || LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode" || LabelInf.Columns[e.ColumnIndex].Name == "pib_outboxcode1" || LabelInf.Columns[e.ColumnIndex].Name == "pib_outboxcode2")
  577. {
  578. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  579. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  580. Rectangle border = e.CellBounds;
  581. border.Width -= 1;
  582. e.Graphics.DrawRectangle(Pens.White, border);
  583. e.PaintContent(e.CellBounds);
  584. e.Handled = true;
  585. }
  586. //重绘制定的Cell,表示采集的数据不匹配
  587. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_qty" && e.RowIndex == CellRowIndex)
  588. {
  589. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  590. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.Red, e.CellBounds);
  591. Rectangle border = e.CellBounds;
  592. border.Width -= 1;
  593. e.Graphics.DrawRectangle(Pens.White, border);
  594. e.PaintContent(e.CellBounds);
  595. e.Handled = true;
  596. }
  597. if (LabelInf.Columns[e.ColumnIndex].Name == "pr_vendprodcode" && e.RowIndex == CellRowIndex)
  598. {
  599. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  600. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.Red, e.CellBounds);
  601. Rectangle border = e.CellBounds;
  602. border.Width -= 1;
  603. e.Graphics.DrawRectangle(Pens.White, border);
  604. e.PaintContent(e.CellBounds);
  605. e.Handled = true;
  606. }
  607. }
  608. }
  609. private void pr_code_SearchIconClick(object sender, EventArgs e)
  610. {
  611. pr_code.Condition = " pib_inoutno='" + pi_inoutno.Text + "'";
  612. }
  613. private void OutBoxLabelPackage_Click(object sender, EventArgs e)
  614. {
  615. SingleDoc = lbl.Documents.Open(@"\\WIN-EIQKLDB7074\CodeSoft打印\Document21.lab");
  616. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  617. SingleDoc.PrintDocument();
  618. }
  619. private void pr_code_UserControlTextChanged(object sender, EventArgs e)
  620. {
  621. //用户在重新勾选后重置采集项目的索引
  622. CurrentIndex = 0;
  623. }
  624. }
  625. }