TextFile1.txt 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using System.Text.RegularExpressions;
  6. using System.Text;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using LabelManager2;
  10. using UAS_出货标签管理.CustomControl.GroupBoxWithBorder;
  11. using UAS_出货标签管理.PublicMethod;
  12. using UAS_出货标签管理.Entity;
  13. using UAS_特殊解析规则;
  14. namespace UAS_出货标签管理
  15. {
  16. public partial class 贴标机条码打印 : Form
  17. {
  18. AutoSizeFormClass asc = new AutoSizeFormClass();
  19. DataHelper dh;
  20. DataTable dt;
  21. StringBuilder sql = new StringBuilder();
  22. /*CodeSoft新建打印机引擎*/
  23. ApplicationClass lbl;
  24. /*单盘打印文件*/
  25. Document SingleDoc;
  26. /*中盒打印文件*/
  27. Document MidDoc;
  28. /*外箱打印文件*/
  29. Document OutBoxDoc;
  30. //当前品牌
  31. string Brand;
  32. string PI_ID;
  33. //当前扫描的项目
  34. int CurrentItemIndex = 0;
  35. //当前扫描的所在行
  36. int CurrentRowIndex = 0;
  37. //最大的出入口单号
  38. int MaxOutBoxCode = 1;
  39. /*正则表达式用于项目匹配*/
  40. Regex reg;
  41. /*标识供应商物料编号采集是否通过*/
  42. bool CollectVeProdCodePass;
  43. bool CollectQTYPass;
  44. bool logout = false;
  45. /*用于存放采集项目的Grid信息*/
  46. Dictionary<string, Dictionary<string, string>> SiItem;
  47. /*需要重绘的Cell*/
  48. Dictionary<DataGridViewCell, bool> PaintCell = new Dictionary<DataGridViewCell, bool>();
  49. //使用二位数组进行排序
  50. ArrayList<ArrayList<string>> ScanData;
  51. ArrayList<string> GetData;
  52. public 贴标机条码打印()
  53. {
  54. InitializeComponent();
  55. }
  56. protected override void WndProc(ref Message m)
  57. {
  58. //拦截双击标题栏、移动窗体的系统消息
  59. if (m.Msg != 0xA3)
  60. {
  61. base.WndProc(ref m);
  62. }
  63. }
  64. private void 贴标机条码打印_Load(object sender, EventArgs e)
  65. {
  66. asc.controllInitializeSize(this);
  67. LogManager.DoLog("程序启动,登陆人员" + User.UserName);
  68. dh = new DataHelper();
  69. pi_inoutno.Focus();
  70. //将本地读取的打印机设置进Combox,并选中默认打印机
  71. sg_code.FormName = Name;
  72. sg_code.SetValueField = new string[] { "sg_code" };
  73. sg_code.SelectField = "sg_code # 策略编号 ,sg_name # 策略名称,sg_brand # 品牌,sg_separator # 分隔符";
  74. sg_code.TableName = "scangroup";
  75. pr_code.FormName = Name;
  76. pr_code.SetValueField = new string[] { "pr_code", "pib_id" };
  77. pr_code.TableName = "prodiodetail ";
  78. pr_code.SelectField = "pd_pdno # 行号,pd_prodcode # 物料编号";
  79. ChooseAll.ChooseAll(LabelInf);
  80. CollectionUnit.Text = "盘";
  81. Point pt = new Point();
  82. int ScreenHeight = Screen.GetWorkingArea(pt).Width;
  83. //如果分辨率大的设置的字体对应的变大
  84. if (ScreenHeight > 1366)
  85. {
  86. foreach (Control ctl in Controls)
  87. {
  88. if (ctl is CheckBox || ctl is Label || ctl is RadioButton)
  89. {
  90. ctl.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
  91. }
  92. if (ctl is GroupBoxWithBorder)
  93. {
  94. GroupBoxWithBorder gb = ctl as GroupBoxWithBorder;
  95. for (int i = 0; i < gb.Controls.Count; i++)
  96. {
  97. if (gb.Controls[i] is CheckBox || gb.Controls[i] is Label || gb.Controls[i] is RadioButton)
  98. {
  99. gb.Controls[i].Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
  100. }
  101. }
  102. }
  103. }
  104. }
  105. //设置获取当前屏幕大小自动全屏但是保留任务栏
  106. Rectangle ScreenArea = Screen.GetWorkingArea(this);
  107. Top = 0;
  108. Left = 0;
  109. Width = ScreenArea.Width;
  110. Height = ScreenArea.Height;
  111. asc.controlAutoSize(this);
  112. //实例化打印进程
  113. try
  114. {
  115. lbl = new ApplicationClass();
  116. }
  117. catch (Exception)
  118. {
  119. MessageBox.Show("未安装CodeSoft软件或者版本不正确");
  120. }
  121. }
  122. private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
  123. {
  124. asc.controlAutoSize(this);
  125. }
  126. private void GenerateBarCode_Click(object sender, EventArgs e)
  127. {
  128. 生成条码 form = new 生成条码(pi_inoutno.Text);
  129. form.FormClosed += LoadGridData;
  130. BaseUtil.SetFormCenter(form);
  131. form.ShowDialog();
  132. }
  133. private void CollectionSetting_Click(object sender, EventArgs e)
  134. {
  135. 采集策略 form = new 采集策略(sg_code.Text);
  136. form.FormClosed += sg_code_UserControlTextChanged;
  137. BaseUtil.SetFormCenter(form);
  138. form.ShowDialog();
  139. }
  140. private void LabelMaintain_Click(object sender, EventArgs e)
  141. {
  142. 客户标签维护 form = new 客户标签维护();
  143. BaseUtil.SetFormCenter(form);
  144. form.ShowDialog();
  145. }
  146. /// <summary>
  147. /// 保存明细
  148. /// </summary>
  149. /// <param name="sender"></param>
  150. /// <param name="e"></param>
  151. private void SaveGrid_Click(object sender, EventArgs e)
  152. {
  153. DataTable savedt = LabelInf.DataSource as DataTable;
  154. if (LabelInf.DataSource != null && savedt.GetChanges() != null)
  155. {
  156. dh.UpDateTableByCondition((LabelInf.DataSource as DataTable).GetChanges(), "ProdioBarCode", "pib_id");
  157. MessageBox.Show("保存成功!");
  158. }
  159. }
  160. //放大镜选择后出发的事件
  161. private void sg_code_UserControlTextChanged(object sender, EventArgs e)
  162. {
  163. //取已启用的的按照采集次序排序
  164. 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");
  165. BaseUtil.FillDgvWithDataTable(Si_ItemDGV, dt);
  166. if (dt.Rows.Count > 0)
  167. {
  168. sg_separator.Text = dt.Rows[0]["sg_separator"].ToString();
  169. }
  170. //按DetNo排列之后的采集项
  171. ScanData = new ArrayList<ArrayList<string>>();
  172. //每个采集项目的子项
  173. GetData = new ArrayList<string>();
  174. //将数据添加进一个List的二维数组中
  175. for (int i = 0; i < Si_ItemDGV.RowCount; i++)
  176. {
  177. //如果不包含这个则添加进数组
  178. if (!GetData.Contains(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString()))
  179. {
  180. GetData.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString());
  181. }
  182. //如果和后一个的采集次序相同
  183. 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())
  184. {
  185. GetData.Add(Si_ItemDGV.Rows[i + 1].Cells["si_item"].Value.ToString());
  186. }
  187. else {
  188. ScanData.Add(GetData);
  189. //添加完一次数据需要一个新的List
  190. GetData = new ArrayList<string>();
  191. }
  192. }
  193. RemindUser();
  194. if (ScanData.ToArray().Length > 0)
  195. {
  196. object[] arr = (ScanData.ToArray()[0] as ArrayList<string>).ToArray();
  197. if (arr.Contains("MPN"))
  198. {
  199. AutoMatch.CheckState = CheckState.Checked;
  200. AutoMatch.Enabled = true;
  201. }
  202. else {
  203. AutoMatch.CheckState = CheckState.Unchecked;
  204. AutoMatch.Enabled = false;
  205. }
  206. }
  207. }
  208. //输入框Enter事件
  209. private void Input_KeyDown(object sender, KeyEventArgs e)
  210. {
  211. if (e.KeyCode == Keys.Enter)
  212. {
  213. if (Input.Text == "")
  214. {
  215. BaseUtil.ShowError("采集的数据不能为空");
  216. }
  217. CollectData();
  218. }
  219. }
  220. /// <summary>
  221. /// 设置自动匹配的数据的行号
  222. /// </summary>
  223. /// <returns></returns>
  224. private void SetAutoMatchRow()
  225. {
  226. //采集策略的第一组数据
  227. string[] arr = Input.Text.Split(sg_separator.Text.ToCharArray()).ToArray();
  228. bool FindAutoMatch = false;
  229. for (int i = 0; i < LabelInf.RowCount; i++)
  230. {
  231. for (int j = 0; j < arr.Length; j++)
  232. {
  233. if (LabelInf.Rows[i].Cells["pr_vendprodcode"].Value.ToString() == MatchStr(arr[j].ToString(), "MPN") && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  234. {
  235. CurrentRowIndex = i;
  236. FindAutoMatch = true;
  237. break;
  238. }
  239. }
  240. if (FindAutoMatch)
  241. {
  242. break;
  243. }
  244. }
  245. }
  246. /// <summary>
  247. /// 采集数据
  248. /// </summary>
  249. private void CollectData()
  250. {
  251. LogManager.DoLog("采集数据" + Input.Text + ",使用采集策略编号" + sg_code.Text);
  252. //按DetNo排列之后的采集项
  253. ScanData = new ArrayList<ArrayList<string>>();
  254. //每个采集项目的子项
  255. GetData = new ArrayList<string>();
  256. //用于保存采集策略的具体信息
  257. SiItem = new Dictionary<string, Dictionary<string, string>>();
  258. for (int i = 0; i < Si_ItemDGV.RowCount; i++)
  259. {
  260. //如果不包含这个则添加进数组
  261. if (!GetData.Contains(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString()))
  262. {
  263. GetData.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString());
  264. }
  265. //如果和后一个的采集次序相同
  266. 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())
  267. {
  268. GetData.Add(Si_ItemDGV.Rows[i + 1].Cells["si_item"].Value.ToString());
  269. }
  270. else {
  271. ScanData.Add(GetData);
  272. //添加完一次数据需要一个新的List
  273. GetData = new ArrayList<string>();
  274. }
  275. Dictionary<string, string> item = new Dictionary<string, string>();
  276. for (int j = 0; j < Si_ItemDGV.ColumnCount; j++)
  277. {
  278. item.Add(Si_ItemDGV.Columns[j].DataPropertyName, Si_ItemDGV.Rows[i].Cells[j].Value.ToString());
  279. }
  280. SiItem.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString().ToUpper(), item);
  281. }
  282. //采集项目的数组
  283. object[] ItemData = (ScanData.ToArray()[CurrentItemIndex] as ArrayList<string>).ToArray();
  284. //分隔符不为空的时候 //采集的项和Grid的数目不等
  285. if (sg_separator.Text == "" && ScanData.ToArray().Length != Si_ItemDGV.RowCount)
  286. {
  287. BaseUtil.ShowError("所选采集策略和当前采集项目不符合,含有同顺序采集项时必须维护分隔符!");
  288. }
  289. else {
  290. //用户采集的数据的分割数组
  291. List<string> CollectData = Input.Text.Split(sg_separator.Text.ToCharArray()).ToList();
  292. //首先判断当前采集的个数,如果采集的个数为1则不对数据进行分隔符验证
  293. if (ItemData.Length == 1)
  294. {
  295. CollectData.Clear();
  296. CollectData.Add(Input.Text);
  297. //勾选了自动匹配调用该函数
  298. if (AutoMatch.Checked)
  299. {
  300. SetAutoMatchRow();
  301. }
  302. //将筛选之后的值赋给Cell
  303. SetDataToCell(ref CollectData, ItemData[0].ToString().ToUpper());
  304. }
  305. //如果本次采集的数据分割后和当前的采集项目个数不一样提示用户错误
  306. else if (CollectData.ToArray().Length == ItemData.Length)
  307. {
  308. for (int i = 0; i < ItemData.Length; i++)
  309. {
  310. //勾选了自动匹配调用该函数
  311. if (AutoMatch.Checked)
  312. {
  313. SetAutoMatchRow();
  314. }
  315. //将筛选之后的值赋给Cell
  316. SetDataToCell(ref CollectData, ItemData[i].ToString().ToUpper());
  317. }
  318. }
  319. else {
  320. BaseUtil.ShowError("所采集的数据个数和采集项目不符");
  321. }
  322. }
  323. //采集项目的索引+1
  324. CurrentItemIndex = CurrentItemIndex + 1;
  325. //如果已经采集完了最后一个
  326. if (CurrentItemIndex == ScanData.ToArray().Length)
  327. {
  328. //数据校验均已通过则勾选上已采集
  329. if (CollectVeProdCodePass && CollectQTYPass)
  330. {
  331. //如果按盒号采集,所有的此盒的均更新为
  332. if (CollectionUnit.Text == "盒")
  333. {
  334. for (int i = 0; i < LabelInf.RowCount; i++)
  335. {
  336. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  337. {
  338. LabelInf.Rows[i].Cells["pib_lotno"].Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value;
  339. LabelInf.Rows[i].Cells["pib_datecode"].Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value;
  340. //将采集数据正确的Cell添加到键值对中
  341. if (PaintCell.ContainsKey(LabelInf.Rows[i].Cells["pr_vendprodcode"]))
  342. {
  343. PaintCell.Remove(LabelInf.Rows[i].Cells["pr_vendprodcode"]);
  344. }
  345. PaintCell.Add(LabelInf.Rows[i].Cells["pr_vendprodcode"], true);
  346. if (PaintCell.ContainsKey(LabelInf.Rows[i].Cells["pib_qty"]))
  347. {
  348. PaintCell.Remove(LabelInf.Rows[i].Cells["pib_qty"]);
  349. }
  350. PaintCell.Add(LabelInf.Rows[i].Cells["pib_qty"], true);
  351. LabelInf.Refresh();
  352. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  353. if (SingleLabelAutoPrint.Checked)
  354. {
  355. string la_id = SingleLabelCombox.SelectedValue.ToString();
  356. string cl_labelname = SingleLabelCombox.Text;
  357. string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString();
  358. SingleDoc = lbl.Documents.Open(LabelUrl);
  359. dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id, "select");
  360. for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++)
  361. {
  362. //将维护的模板参数和模板本身的参数名称进行比对
  363. for (int k = 0; k < dt.Rows.Count; k++)
  364. {
  365. //名称相等的时候,取SQL进行值的查询
  366. if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
  367. {
  368. //获取打印执行的SQL
  369. string sql = dt.Rows[k]["lp_sql"].ToString();
  370. sql = sql.Substring(0, sql.IndexOf("{"));
  371. //获取对应行的pib_id
  372. string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  373. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql + pib_id).ToString();
  374. }
  375. }
  376. }
  377. //保存参数打印
  378. SingleDoc.Save();
  379. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  380. SingleDoc.PrintDocument();
  381. LogManager.DoLog("执行打印单盘,pib_id:" + LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  382. LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
  383. }
  384. if (MidLabelAutoPrint.Checked)
  385. {
  386. AutoPrintMidLabel();
  387. }
  388. }
  389. }
  390. }
  391. else {
  392. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
  393. //勾选了单盘自动打印
  394. if (SingleLabelAutoPrint.Checked)
  395. {
  396. string la_id = SingleLabelCombox.SelectedValue.ToString();
  397. string cl_labelname = SingleLabelCombox.Text;
  398. string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString();
  399. SingleDoc = lbl.Documents.Open(LabelUrl);
  400. dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id, "select");
  401. for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++)
  402. {
  403. //将维护的模板参数和模板本身的参数名称进行比对
  404. for (int k = 0; k < dt.Rows.Count; k++)
  405. {
  406. //名称相等的时候,取SQL进行值的查询
  407. if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
  408. {
  409. //获取打印执行的SQL
  410. string sql = dt.Rows[k]["lp_sql"].ToString();
  411. if (sql.IndexOf("{") == 0)
  412. {
  413. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql).ToString();
  414. LogManager.DoLog("打印参数" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "赋值," + "取值SQL:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value);
  415. }
  416. else {
  417. sql = sql.Substring(0, sql.IndexOf("{"));
  418. //获取对应行的pib_id
  419. string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
  420. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql + pib_id).ToString();
  421. LogManager.DoLog("打印参数" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "赋值," + "取值SQL:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value);
  422. }
  423. }
  424. }
  425. }
  426. //保存参数打印
  427. SingleDoc.Save();
  428. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  429. SingleDoc.PrintDocument();
  430. LogManager.DoLog("执行打印单盘,pib_id:" + LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString());
  431. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifprint"].Value = true;
  432. }
  433. //勾选了中盒自动打印
  434. if (MidLabelAutoPrint.Checked)
  435. {
  436. AutoPrintMidLabel();
  437. }
  438. //勾选了外箱自动打印
  439. if (OutBoxLabelAutoPrint.Checked)
  440. {
  441. }
  442. }
  443. }
  444. //采集未通过的时候
  445. else {
  446. //如果自动采集采集未成功需要移动到下一行
  447. if (!AutoMatch.Checked)
  448. {
  449. SetRowIndexToCollectRow();
  450. }
  451. }
  452. //当前项目已采集完成,重置采集项目
  453. CurrentItemIndex = 0;
  454. if (!AutoMatch.Checked)
  455. {
  456. SetRowIndexToCollectRow();
  457. }
  458. //采集完了一行后Index+1
  459. CurrentRowIndex = (CurrentRowIndex + 1 == LabelInf.RowCount) ? CurrentRowIndex : CurrentRowIndex + 1;
  460. }
  461. //提醒用户需要采集的数据
  462. RemindUser();
  463. RefreshProcessData();
  464. }
  465. //设置行的索引到当前需要采集的行
  466. private void SetRowIndexToCollectRow()
  467. {
  468. //获取当前需要采集的行
  469. for (int i = CurrentRowIndex; i < LabelInf.RowCount; i++)
  470. {
  471. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  472. {
  473. griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
  474. pr_code.Text = LabelInf.Rows[i].Cells["pib_prodcode"].FormattedValue.ToString();
  475. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
  476. break;
  477. }
  478. }
  479. }
  480. /// <summary>
  481. /// 提醒用户当前采集的项目
  482. /// </summary>
  483. private void RemindUser()
  484. {
  485. SetRowIndexToCollectRow();
  486. if (ScanData.ToArray().Length > 0)
  487. {
  488. object[] arr = (ScanData.ToArray()[CurrentItemIndex] as ArrayList<string>).ToArray();
  489. string Inf = "";
  490. for (int i = 0; i < arr.Length; i++)
  491. {
  492. Inf += arr[i] + " ";
  493. }
  494. MessageLog.AppendText(">>当前采集行" + (CurrentRowIndex + 1) + ",请采集" + Inf + "\n", Color.Green);
  495. }
  496. }
  497. /// <summary>
  498. /// 自定义函数 将匹配之后的值设置到Cell中,传递引用,每次赋值之后从List中移除已使用过的
  499. /// </summary>
  500. /// <param name="data"></param>
  501. /// <param name="kind"></param>
  502. private void SetDataToCell(ref List<string> setdata, string kind)
  503. {
  504. int length = setdata.ToArray().Length;
  505. for (int j = 0; j < length; j++)
  506. {
  507. string[] data = setdata.ToArray();
  508. for (int i = 0; i < data.Length; i++)
  509. {
  510. DataGridViewCell cell = null;
  511. string Matchstr = "";
  512. switch (kind.ToString().ToUpper())
  513. {
  514. case "DATECODE":
  515. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"];
  516. Matchstr = MatchStr(data[j], "DATECODE");
  517. setdata.Remove(data[j]);
  518. length--;
  519. break;
  520. case "LOTNO":
  521. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"];
  522. Matchstr = MatchStr(data[j], "LOTNO");
  523. setdata.Remove(data[j]);
  524. length--;
  525. break;
  526. case "MPN":
  527. cell = LabelInf.Rows[CurrentRowIndex].Cells["pr_vendprodcode"];
  528. Matchstr = MatchStr(data[j], "MPN");
  529. //采集的供应商号不匹配的话
  530. if (cell.Value.ToString() != Matchstr)
  531. {
  532. CollectVeProdCodePass = false;
  533. //添加需要重绘的Cell
  534. if (PaintCell.ContainsKey(cell))
  535. {
  536. PaintCell.Remove(cell);
  537. }
  538. PaintCell.Add(cell, false);
  539. LabelInf.Refresh();
  540. MessageLog.AppendText(">>供应商物料编号不匹配\n", Color.Red);
  541. }
  542. else {
  543. if (PaintCell.ContainsKey(cell))
  544. {
  545. PaintCell.Remove(cell);
  546. }
  547. PaintCell.Add(cell, true);
  548. LabelInf.Refresh();
  549. CollectVeProdCodePass = true;
  550. }
  551. setdata.Remove(data[j]);
  552. length--;
  553. break;
  554. case "QTY":
  555. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_qty"];
  556. Matchstr = MatchStr(data[j], "QTY");
  557. //如果采集的数量不相等的话
  558. if (cell.Value.ToString() != Matchstr)
  559. {
  560. CollectQTYPass = false;
  561. //添加需要重绘的Cell
  562. if (PaintCell.ContainsKey(cell))
  563. {
  564. PaintCell.Remove(cell);
  565. }
  566. PaintCell.Add(cell, false);
  567. LabelInf.Refresh();
  568. MessageLog.AppendText(">>数量不匹配\n", Color.Red);
  569. }
  570. else {
  571. if (PaintCell.ContainsKey(cell))
  572. {
  573. PaintCell.Remove(cell);
  574. }
  575. PaintCell.Add(cell, true);
  576. LabelInf.Refresh();
  577. CollectQTYPass = true;
  578. }
  579. setdata.Remove(data[j]);
  580. length--;
  581. break;
  582. default:
  583. break;
  584. }
  585. //如果数据为空或者数据不为空的时候但是和需要采集的数据不相等的情况下进行采集
  586. //MPN和QTY只做比较不需要赋值
  587. if (cell.Value.ToString() == "" || cell.Value.ToString() != Matchstr)
  588. {
  589. if (kind != "MPN" && kind != "QTY")
  590. {
  591. cell.Value = Matchstr;
  592. }
  593. LogManager.DoLog("采集项" + kind + ",匹配方式:" + SiItem[kind]["si_kind"] + ",匹配后字符串" + Matchstr);
  594. }
  595. }
  596. }
  597. //添加外箱号,如果外箱号的箱内容量不为0并且已经采集完成
  598. if (OutboxCapacity.Value != 0 && CurrentItemIndex == ScanData.ToArray().Length - 1)
  599. {
  600. //获取当前出入口单最大的外箱号
  601. for (int i = 0; i < LabelInf.RowCount; i++)
  602. {
  603. string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  604. if (int.Parse(outboxcode == "" ? "1" : outboxcode) > MaxOutBoxCode)
  605. {
  606. MaxOutBoxCode = int.Parse(outboxcode);
  607. }
  608. }
  609. //统计最大的箱号存在多少
  610. int MaxOutBoxCodeCount = 0;
  611. for (int i = 0; i < LabelInf.RowCount; i++)
  612. {
  613. if (LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString() == MaxOutBoxCode.ToString())
  614. {
  615. MaxOutBoxCodeCount = MaxOutBoxCodeCount + 1;
  616. }
  617. }
  618. //如果箱内的盒数量小于容量,继续使用此箱号赋值,否则箱号+1
  619. if (MaxOutBoxCodeCount < OutboxCapacity.Value)
  620. {
  621. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  622. }
  623. else {
  624. MaxOutBoxCode = MaxOutBoxCode + 1;
  625. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  626. }
  627. }
  628. }
  629. /// <summary>
  630. /// 自定义函数 根据匹配规则
  631. /// si_item的二维数组,str是需要赋值的字符串,item表示DateCode,LotNo等
  632. /// </summary>
  633. /// <param name="SiItem"></param>
  634. /// <param name="str"></param>
  635. /// <param name="item"></param>
  636. /// <returns></returns>
  637. private string MatchStr(string str, string item)
  638. {
  639. string kind = SiItem[item]["si_kind"];
  640. //起始字符不为空的时候
  641. switch (kind)
  642. {
  643. case "起始位置":
  644. if (SiItem[item]["si_index"] != "")
  645. {
  646. try
  647. {
  648. //长度不为空的时候按照指定的长度去取数据
  649. if (SiItem[item]["si_length"] != "")
  650. {
  651. str = str.Substring(int.Parse(SiItem[item]["si_index"]), int.Parse(SiItem[item]["si_length"]));
  652. }
  653. //长度为空的时候取index之后的全部数据
  654. else {
  655. str = str.Substring(int.Parse(SiItem[item]["si_index"]));
  656. }
  657. }
  658. catch (Exception)
  659. {
  660. }
  661. }
  662. break;
  663. case "索引字符":
  664. try
  665. {
  666. if (SiItem[item]["si_indexstring"] != "")
  667. {
  668. //长度不为空的时候按照指定的长度去取数据
  669. if (SiItem[item]["si_length"] != "")
  670. {
  671. str = str.Substring(str.IndexOf(SiItem[item]["si_indexstring"]) + 1, int.Parse(SiItem[item]["si_length"]));
  672. }
  673. //长度为空的时候取index之后的全部数据
  674. else {
  675. str = str.Substring(str.IndexOf(SiItem[item]["si_indexstring"]) + 1);
  676. }
  677. }
  678. }
  679. catch (Exception)
  680. {
  681. }
  682. break;
  683. case "二次解析":
  684. str = Analysis.AnalysisData(Brand, item, str);
  685. break;
  686. case "全部":
  687. break;
  688. default:
  689. break;
  690. }
  691. if (SiItem[item]["si_expression"] != "")
  692. {
  693. reg = new Regex(SiItem[item]["si_expression"]);
  694. str = reg.Match(str).Value;
  695. }
  696. return str;
  697. }
  698. //关闭窗口前提示用户确认
  699. private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
  700. {
  701. //如果不是注销的话
  702. if (!logout)
  703. {
  704. string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  705. if (close.ToString() != "Yes")
  706. {
  707. e.Cancel = true;
  708. }
  709. else {
  710. //防止未安装打印程序时报错导致窗体无法关闭
  711. try
  712. {
  713. lbl.Application.Quit();
  714. LogManager.DoLog("关闭程序");
  715. // System.Windows.Forms.Application.Exit();
  716. }
  717. catch
  718. {
  719. }
  720. }
  721. }
  722. }
  723. /// <summary>
  724. /// 出入库单录入框的回车事件
  725. /// </summary>
  726. /// <param name="sender"></param>
  727. /// <param name="e"></param>
  728. private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
  729. {
  730. if (e.KeyCode == Keys.Enter)
  731. {
  732. sql.Clear();
  733. sql.Append("select pi_id,pi_cardcode from prodinout where pi_inoutno='" + pi_inoutno.Text + "'");
  734. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  735. if (dt.Rows.Count > 0)
  736. {
  737. pi_cardcode.Text = dt.Rows[0]["pi_cardcode"].ToString();
  738. PI_ID = dt.Rows[0]["pi_id"].ToString();
  739. LoadGridData(sender, e);
  740. //刷新采集进度
  741. RefreshProcessData();
  742. //设置当前的最大箱号
  743. for (int i = 0; i < LabelInf.RowCount; i++)
  744. {
  745. string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  746. if (int.Parse(outboxcode == "" ? "1" : outboxcode) > MaxOutBoxCode)
  747. {
  748. MaxOutBoxCode = int.Parse(outboxcode);
  749. }
  750. }
  751. sql.Clear();
  752. sql.Append("select cl_labelname,cl_isdefault,la_id from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  753. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  754. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode='共用')) and cl_labeltype='单盘'");
  755. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  756. SingleLabelCombox.DataSource = dt;
  757. SingleLabelCombox.DisplayMember = "cl_labelname";
  758. SingleLabelCombox.ValueMember = "la_id";
  759. sql.Clear();
  760. sql.Append("select cl_labelname,cl_isdefault,la_id from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  761. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  762. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode='共用')) and cl_labeltype='中盒'");
  763. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  764. MidLabelCombox.DataSource = dt.Copy();
  765. MidLabelCombox.DisplayMember = "cl_labelname";
  766. MidLabelCombox.ValueMember = "la_id";
  767. sql.Clear();
  768. sql.Append("select cl_labelname,cl_isdefault,la_id from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  769. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  770. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode='共用')) and cl_labeltype='外箱'");
  771. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  772. OutBoxCombox.DataSource = dt.Copy();
  773. OutBoxCombox.DisplayMember = "cl_labelname";
  774. OutBoxCombox.ValueMember = "la_id";
  775. //重置采集项次
  776. CurrentItemIndex = 0;
  777. LogManager.DoLog("输入单号" + pi_inoutno.Text);
  778. }
  779. else {
  780. MessageBox.Show("当前出入库单号不存在!");
  781. }
  782. }
  783. }
  784. private void SingleLabelPrint_Click(object sender, EventArgs e)
  785. {
  786. string la_id = SingleLabelCombox.SelectedValue.ToString();
  787. string cl_labelname = SingleLabelCombox.Text;
  788. string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString();
  789. SingleDoc = lbl.Documents.Open(LabelUrl);
  790. //查询该模板维护的所有参数
  791. dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id, "select");
  792. if (dt.Rows.Count > 0)
  793. {
  794. //打印所有的选中行
  795. for (int i = 0; i < LabelInf.RowCount; i++)
  796. {
  797. //勾选了并且未打印
  798. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
  799. {
  800. //以标签模板的参数为基准,循环取数
  801. for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++)
  802. {
  803. //将维护的模板参数和模板本身的参数名称进行比对
  804. for (int k = 0; k < dt.Rows.Count; k++)
  805. {
  806. //名称相等的时候,取SQL进行值的查询
  807. if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
  808. {
  809. //获取打印执行的SQL
  810. string sql = dt.Rows[k]["lp_sql"].ToString();
  811. if (sql.IndexOf("{") == 0)
  812. {
  813. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql).ToString();
  814. LogManager.DoLog("打印参数" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "赋值," + "取值SQL:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value);
  815. }
  816. else {
  817. sql = sql.Substring(0, sql.IndexOf("{"));
  818. //获取对应行的pib_id
  819. string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  820. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql + pib_id).ToString();
  821. LogManager.DoLog("打印参数" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "赋值," + "取值SQL:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value);
  822. }
  823. }
  824. }
  825. }
  826. //保存参数打印
  827. SingleDoc.Save();
  828. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  829. SingleDoc.PrintDocument();
  830. LogManager.DoLog("执行打印单盘,pib_id:" + LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  831. //勾选为已打印
  832. LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
  833. }
  834. }
  835. }
  836. else {
  837. BaseUtil.ShowError("此模板尚未维护参数");
  838. }
  839. }
  840. private void MidLabelPrint_Click(object sender, EventArgs e)
  841. {
  842. if (MidLabelNum.Text == "")
  843. {
  844. BaseUtil.ShowError("手动打印必须填写盒号");
  845. }
  846. bool FindMidLabel = false;
  847. if (MidLabelCombox.SelectedValue != null)
  848. {
  849. string la_id = MidLabelCombox.SelectedValue.ToString();
  850. string cl_labelname = MidLabelCombox.Text;
  851. string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString();
  852. MidDoc = lbl.Documents.Open(LabelUrl);
  853. //中盒号所在的行
  854. int MidLabelRowIndex = 0;
  855. //查找是否存在该中盒号
  856. for (int i = 0; i < LabelInf.RowCount; i++)
  857. {
  858. if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  859. {
  860. //找到了输入的中盒号停止循环
  861. FindMidLabel = true;
  862. MidLabelRowIndex = i;
  863. break;
  864. }
  865. }
  866. //找到了指定的盒号
  867. if (FindMidLabel)
  868. {
  869. dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id, "select");
  870. for (int j = 0; j < MidDoc.Variables.FreeVariables.Count; j++)
  871. {
  872. //将维护的模板参数和模板本身的参数名称进行比对
  873. for (int k = 0; k < dt.Rows.Count; k++)
  874. {
  875. //名称相等的时候,取SQL进行值的查询
  876. if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
  877. {
  878. //获取对应行的pib_id
  879. string pib_id = LabelInf.Rows[MidLabelRowIndex].Cells["pib_id1"].Value.ToString();
  880. string pib_outboxcode1 = LabelInf.Rows[MidLabelRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  881. //获取打印执行的SQL
  882. string sql = dt.Rows[k]["lp_sql"].ToString();
  883. //select * from productiobarcode where pib_id={pib_id} and pib_outboxcode1={pib_outboxcode1}
  884. try
  885. {
  886. //获取打印执行的SQL
  887. if (sql.IndexOf("{") == 0)
  888. {
  889. MidDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql).ToString();
  890. LogManager.DoLog("打印参数" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "赋值," + "取值SQL:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value);
  891. }
  892. else {
  893. string ExeSQL = sql.Substring(0, sql.IndexOf("{")) + pib_id + sql.Substring(sql.IndexOf("}") + 1);
  894. ExeSQL = ExeSQL.Substring(0, ExeSQL.IndexOf("{")) + pib_outboxcode1;
  895. MidDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(ExeSQL).ToString();
  896. LogManager.DoLog("打印参数" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "赋值," + "取值SQL:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value);
  897. }
  898. }
  899. catch (Exception)
  900. {
  901. BaseUtil.ShowError("SQL维护不正确,请检查SQL语句\n" + sql);
  902. }
  903. }
  904. }
  905. }
  906. //保存参数打印
  907. MidDoc.Save();
  908. MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
  909. MidDoc.PrintDocument();
  910. LogManager.DoLog("执行打印中盒,pib_id:" + LabelInf.Rows[MidLabelRowIndex].Cells["pib_id1"].Value.ToString());
  911. }
  912. else {
  913. BaseUtil.ShowError("该出入库单未找到该中盒号!");
  914. }
  915. }
  916. else {
  917. MessageBox.Show("未维护中盒模板");
  918. }
  919. }
  920. private void OutBoxLabelPrint_Click(object sender, EventArgs e)
  921. {
  922. if (OutBoxNum.Text == "")
  923. {
  924. BaseUtil.ShowError("手动打印必须填写箱号");
  925. }
  926. bool FindMidLabel = false;
  927. string la_id = OutBoxCombox.SelectedValue.ToString();
  928. string cl_labelname = OutBoxCombox.Text;
  929. string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString();
  930. OutBoxDoc = lbl.Documents.Open(LabelUrl);
  931. //中盒号所在的行
  932. int OutBoxLabelRowIndex = 0;
  933. //查找是否存在该中盒号
  934. for (int i = 0; i < LabelInf.RowCount; i++)
  935. {
  936. if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString())
  937. {
  938. //找到了输入的中盒号停止循环
  939. FindMidLabel = true;
  940. OutBoxLabelRowIndex = i;
  941. break;
  942. }
  943. }
  944. //找到了指定的盒号
  945. if (FindMidLabel)
  946. {
  947. dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id, "select");
  948. for (int j = 0; j < OutBoxDoc.Variables.FreeVariables.Count; j++)
  949. {
  950. //将维护的模板参数和模板本身的参数名称进行比对
  951. for (int k = 0; k < dt.Rows.Count; k++)
  952. {
  953. //名称相等的时候,取SQL进行值的查询
  954. if (OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
  955. {
  956. //如果毛重填写的是毛重或者净重
  957. if (dt.Rows[k]["lp_valuetype"].ToString() == "字符串" && dt.Rows[k]["lp_sql"].ToString() == "GW")
  958. {
  959. OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = WeightGross.Text;
  960. LogManager.DoLog("打印参数毛重赋值," + WeightGross.Text);
  961. }
  962. else if (dt.Rows[k]["lp_valuetype"].ToString() == "字符串" && dt.Rows[k]["lp_sql"].ToString() == "NW")
  963. {
  964. OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = WeightNet.Text;
  965. LogManager.DoLog("打印参数净重赋值," + WeightNet.Text);
  966. }
  967. else {
  968. //获取对应行的pib_id
  969. string pib_id = LabelInf.Rows[OutBoxLabelRowIndex].Cells["pib_id1"].Value.ToString();
  970. string pib_outboxcode2 = LabelInf.Rows[OutBoxLabelRowIndex].Cells["pib_outboxcode2"].Value.ToString();
  971. //获取打印执行的SQL
  972. string sql = dt.Rows[k]["lp_sql"].ToString();
  973. //select * from productiobarcode where pib_id={pib_id} and pib_outboxcode1={pib_outboxcode1}
  974. try
  975. {
  976. string ExeSQL = sql.Substring(0, sql.IndexOf("{")) + pib_id + sql.Substring(sql.IndexOf("}") + 1);
  977. ExeSQL = ExeSQL.Substring(0, ExeSQL.IndexOf("{")) + pib_outboxcode2;
  978. OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(ExeSQL).ToString();
  979. LogManager.DoLog("打印参数" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name + "赋值," + "取值SQL:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value);
  980. }
  981. catch (Exception)
  982. {
  983. LogManager.DoLog("SQL维护不正确,请检查SQL语句" + sql);
  984. BaseUtil.ShowError("SQL维护不正确,请检查SQL语句\n" + sql);
  985. }
  986. }
  987. }
  988. }
  989. }
  990. //保存参数打印
  991. OutBoxDoc.Save();
  992. OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
  993. OutBoxDoc.PrintDocument();
  994. LogManager.DoLog("执行打印外箱,pib_id:" + LabelInf.Rows[OutBoxLabelRowIndex].Cells["pib_id1"].Value.ToString());
  995. }
  996. else {
  997. BaseUtil.ShowError("该出入库单未找到该外箱号!");
  998. }
  999. }
  1000. private void CleanDetail_Click(object sender, EventArgs e)
  1001. {
  1002. ArrayList<string> DeleteID = new ArrayList<string>();
  1003. for (int i = 0; i < LabelInf.RowCount; i++)
  1004. {
  1005. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  1006. {
  1007. DeleteID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1008. }
  1009. }
  1010. //勾选了删除的明细之后
  1011. if (DeleteID.ToArray().Length > 0)
  1012. {
  1013. string close = MessageBox.Show(this.ParentForm, "删除后不可恢复,是否确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1014. if (close.ToString() == "Yes")
  1015. {
  1016. dh.BatchInsert("delete from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray());
  1017. MessageBox.Show("删除成功");
  1018. LoadGridData(sender, e);
  1019. RefreshProcessData();
  1020. }
  1021. }
  1022. else {
  1023. MessageBox.Show("尚未勾选需要删除的明细");
  1024. }
  1025. }
  1026. /// <summary>
  1027. /// 刷新采集进度
  1028. /// </summary>
  1029. private void RefreshProcessData()
  1030. {
  1031. if (LabelInf.Rows.Count > 0)
  1032. {
  1033. //设置初始化的采集进度
  1034. int Count = 0;
  1035. int CurrentMidBoxCollectedCount = 0;
  1036. //当前盒号的总盘数
  1037. int CurrentMidBoxTotalCount = 0;
  1038. //未超出当前范围的时候
  1039. for (int i = 0; i < LabelInf.RowCount; i++)
  1040. {
  1041. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
  1042. {
  1043. Count++;
  1044. }
  1045. //和当前编辑箱号相等行
  1046. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1047. {
  1048. CurrentMidBoxCollectedCount++;
  1049. }
  1050. //当前盒号一共有几盘
  1051. if (LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1052. {
  1053. CurrentMidBoxTotalCount++;
  1054. }
  1055. }
  1056. Capacity.Text = "可装" + CurrentMidBoxTotalCount.ToString() + "盘";
  1057. Installed.Text = "已装" + CurrentMidBoxCollectedCount.ToString() + "盘";
  1058. //设置当前的箱号和盒号
  1059. Process_outboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value.ToString();
  1060. Process_midboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  1061. //设置当前总数和已采集数量
  1062. TotalCount.Text = LabelInf.RowCount.ToString();
  1063. CollectedCount.Text = Count.ToString();
  1064. }
  1065. }
  1066. /// <summary>
  1067. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  1068. /// </summary>
  1069. /// <param name="sender"></param>
  1070. /// <param name="e"></param>
  1071. private void LoadGridData(object sender, EventArgs e)
  1072. {
  1073. sql.Clear();
  1074. sql.Append("select pib_id,pib_pdid,pib_piid,pib_pdno,pib_prodcode,pr_brand,pr_vendprodcode,");
  1075. sql.Append("pib_lotno,pib_datecode,pib_qty,pib_barcode,pib_outboxcode1 ,pib_outboxcode2,");
  1076. sql.Append("pib_ifpick, pib_ifprint from prodiobarcode left join prodiodetail on pib_piid=pd_piid and ");
  1077. sql.Append("pd_pdno=pib_pdno and pd_prodcode=pib_prodcode left join product on ");
  1078. sql.Append("pr_code=pib_prodcode where pd_piid='" + PI_ID + "' order by pd_id ,pib_id");
  1079. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1080. BaseUtil.FillDgvWithDataTable(LabelInf, dt);
  1081. //有数据的话默认取第一条的品牌去取采集策略
  1082. TotalCount.Text = LabelInf.RowCount.ToString();
  1083. if (LabelInf.RowCount > 0)
  1084. {
  1085. Brand = LabelInf.Rows[0].Cells["pr_brand"].FormattedValue.ToString();
  1086. if (Brand != "")
  1087. sg_code.Text = dh.getFieldDataByCondition("scangroup", "sg_code", "sg_brand='" + Brand + "'").ToString();
  1088. }
  1089. //绑定数据之后往下找到未采集的数据显示在当前采集的栏目
  1090. for (int i = 0; i < LabelInf.RowCount; i++)
  1091. {
  1092. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1093. {
  1094. griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
  1095. pr_code.Text = LabelInf.Rows[i].Cells["pib_prodcode"].FormattedValue.ToString();
  1096. pib_id.Text = LabelInf.Rows[i].Cells["pib_id1"].FormattedValue.ToString();
  1097. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
  1098. break;
  1099. }
  1100. }
  1101. }
  1102. /// <summary>
  1103. /// 重绘Cell的颜色
  1104. /// </summary>
  1105. /// <param name="sender"></param>
  1106. /// <param name="e"></param>
  1107. private void LabelInf_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  1108. {
  1109. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  1110. if (e.ColumnIndex > 0)
  1111. {
  1112. 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")
  1113. {
  1114. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1115. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  1116. Rectangle border = e.CellBounds;
  1117. border.Width -= 1;
  1118. e.Graphics.DrawRectangle(Pens.White, border);
  1119. e.PaintContent(e.CellBounds);
  1120. e.Handled = true;
  1121. }
  1122. if (e.RowIndex >= 0)
  1123. {
  1124. //重绘制定的Cell,表示采集的数量不匹配
  1125. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_qty" && PaintCell.ContainsKey(LabelInf.Rows[e.RowIndex].Cells["pib_qty"]))
  1126. {
  1127. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1128. e.Graphics.FillRectangle(PaintCell[LabelInf.Rows[e.RowIndex].Cells["pib_qty"]] ? Brushes.ForestGreen : Brushes.Red, e.CellBounds);
  1129. Rectangle border = e.CellBounds;
  1130. border.Width -= 1;
  1131. e.Graphics.DrawRectangle(Pens.Black, border);
  1132. e.PaintContent(e.CellBounds);
  1133. e.Handled = true;
  1134. }
  1135. //表示采集的供应商物料编号不匹配
  1136. if (LabelInf.Columns[e.ColumnIndex].Name == "pr_vendprodcode" && PaintCell.ContainsKey(LabelInf.Rows[e.RowIndex].Cells["pr_vendprodcode"]))
  1137. {
  1138. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1139. e.Graphics.FillRectangle(PaintCell[LabelInf.Rows[e.RowIndex].Cells["pr_vendprodcode"]] ? Brushes.ForestGreen : Brushes.Red, e.CellBounds);
  1140. Rectangle border = e.CellBounds;
  1141. border.Width -= 1;
  1142. e.Graphics.DrawRectangle(Pens.Black, border);
  1143. e.PaintContent(e.CellBounds);
  1144. e.Handled = true;
  1145. }
  1146. }
  1147. }
  1148. }
  1149. private void pr_code_SearchIconClick(object sender, EventArgs e)
  1150. {
  1151. pr_code.Condition = " pd_inoutno='" + pi_inoutno.Text + "'";
  1152. }
  1153. private void OutBoxLabelPackage_Click(object sender, EventArgs e)
  1154. {
  1155. LogManager.DoLog("几个日志");
  1156. MaxOutBoxCode = MaxOutBoxCode + 1;
  1157. }
  1158. private void pr_code_UserControlTextChanged(object sender, EventArgs e)
  1159. {
  1160. //用户在重新勾选后重置采集项目的索引
  1161. CurrentItemIndex = 0;
  1162. for (int i = 0; i < LabelInf.RowCount; i++)
  1163. {
  1164. if (pr_code.Text == LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1165. {
  1166. CurrentRowIndex = i;
  1167. break;
  1168. }
  1169. }
  1170. }
  1171. private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1172. {
  1173. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  1174. pi_inoutno_KeyDown(sender, e2);
  1175. }
  1176. /// <summary>
  1177. /// 采集明细切换
  1178. /// </summary>
  1179. /// <param name="sender"></param>
  1180. /// <param name="e"></param>
  1181. private void griddetno_KeyDown(object sender, KeyEventArgs e)
  1182. {
  1183. if (Keys.Enter == e.KeyData)
  1184. {
  1185. bool FindDetno = false;
  1186. for (int i = 0; i < LabelInf.RowCount; i++)
  1187. {
  1188. if (LabelInf.Rows[i].Cells["pib_pdno"].Value.ToString() == griddetno.Text && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1189. {
  1190. FindDetno = true;
  1191. CurrentItemIndex = 0;
  1192. CurrentRowIndex = i;
  1193. RemindUser();
  1194. break;
  1195. }
  1196. }
  1197. if (!FindDetno)
  1198. {
  1199. BaseUtil.ShowError("不存在未采集的明细序号" + griddetno.Text);
  1200. }
  1201. }
  1202. }
  1203. private void AutoPrintMidLabel()
  1204. {
  1205. bool FullBox = true;
  1206. //判断所有盒号未该盒的是否勾选已采集
  1207. for (int i = 0; i < LabelInf.RowCount; i++)
  1208. {
  1209. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  1210. {
  1211. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1212. {
  1213. FullBox = false;
  1214. }
  1215. }
  1216. }
  1217. //如果当前箱号已经装满了
  1218. if (FullBox)
  1219. {
  1220. if (MidLabelCombox.SelectedValue != null)
  1221. {
  1222. string la_id = MidLabelCombox.SelectedValue.ToString();
  1223. string cl_labelname = MidLabelCombox.Text;
  1224. string LabelUrl = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id + "' and cl_labelname='" + cl_labelname + "'").ToString();
  1225. MidDoc = lbl.Documents.Open(LabelUrl);
  1226. dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id, "select");
  1227. for (int j = 0; j < MidDoc.Variables.FreeVariables.Count; j++)
  1228. {
  1229. //将维护的模板参数和模板本身的参数名称进行比对
  1230. for (int k = 0; k < dt.Rows.Count; k++)
  1231. {
  1232. //名称相等的时候,取SQL进行值的查询
  1233. if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
  1234. {
  1235. //获取对应行的pib_id
  1236. string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
  1237. string pib_outboxcode1 = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  1238. //获取打印执行的SQL
  1239. string sql = dt.Rows[k]["lp_sql"].ToString();
  1240. //select * from productiobarcode where pib_id={pib_id} and pib_outboxcode1={pib_outboxcode1}
  1241. try
  1242. {
  1243. string ExeSQL = sql.Substring(0, sql.IndexOf("{")) + pib_id + sql.Substring(sql.IndexOf("}") + 1);
  1244. ExeSQL = ExeSQL.Substring(0, ExeSQL.IndexOf("{")) + pib_outboxcode1;
  1245. MidDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(ExeSQL).ToString();
  1246. LogManager.DoLog("打印参数" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "赋值," + "取值SQL:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value);
  1247. }
  1248. catch (Exception)
  1249. {
  1250. BaseUtil.ShowError("SQL维护不正确,请检查SQL语句");
  1251. }
  1252. }
  1253. }
  1254. }
  1255. //保存参数打印
  1256. MidDoc.Save();
  1257. MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
  1258. MidDoc.PrintDocument();
  1259. LogManager.DoLog("执行打印中盒,pib_id:" + LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString());
  1260. }
  1261. else {
  1262. MessageBox.Show("未维护中盒模板");
  1263. }
  1264. }
  1265. }
  1266. private void LoginOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1267. {
  1268. Login login = new Login();
  1269. logout = true;
  1270. Hide();
  1271. login.ShowDialog();
  1272. Close();
  1273. }
  1274. }
  1275. }