贴标机条码打印.cs 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020
  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_LabelMachine.PublicMethod;
  11. using UAS_LabelMachine.Entity;
  12. using UAS_特殊解析规则;
  13. using System.Globalization;
  14. using UAS_LabelMachine.CustomControl.GroupBoxWithBorder;
  15. using UAS_LabelMachine.PublicForm;
  16. using System.Threading;
  17. namespace UAS_LabelMachine
  18. {
  19. public partial class UAS_出货标签打印 : Form
  20. {
  21. //自适应屏幕
  22. AutoSizeFormClass asc = new AutoSizeFormClass();
  23. DataHelper dh;
  24. DataTable dt;
  25. StringBuilder sql = new StringBuilder();
  26. /*CodeSoft新建打印机引擎*/
  27. ApplicationClass lbl;
  28. /*单盘打印文件*/
  29. Document SingleDoc;
  30. /*中盒打印文件*/
  31. Document MidDoc;
  32. /*外箱打印文件*/
  33. Document OutBoxDoc;
  34. SetLoadingWindow stw;
  35. Thread thread;
  36. //当前品牌
  37. string Brand;
  38. string PI_ID;
  39. //当前扫描的项目
  40. int CurrentItemIndex = 0;
  41. //当前扫描的所在行
  42. int CurrentRowIndex = 0;
  43. //最大的出入口单号
  44. int MaxOutBoxCode = 1;
  45. /*正则表达式用于项目匹配*/
  46. Regex reg;
  47. /*标识供应商物料编号采集是否通过*/
  48. bool CollectVeProdCodePass = true;
  49. bool CollectQTYPass = true;
  50. bool logout = false;
  51. object[] ItemData;
  52. Dictionary<string, string> CollectData;
  53. bool AllCollect = false;
  54. /*用于存放采集项目的Grid信息*/
  55. Dictionary<string, Dictionary<string, string>> SiItem;
  56. /*需要重绘的Cell*/
  57. Dictionary<DataGridViewCell, bool> PaintCell = new Dictionary<DataGridViewCell, bool>();
  58. //使用二维数组进行排序
  59. ArrayList<ArrayList<string>> ScanData;
  60. ArrayList<string> GetData;
  61. public UAS_出货标签打印()
  62. {
  63. InitializeComponent();
  64. }
  65. protected override void WndProc(ref Message m)
  66. {
  67. //拦截双击标题栏、移动窗体的系统消息
  68. if (m.Msg != 0xA3)
  69. {
  70. base.WndProc(ref m);
  71. }
  72. }
  73. private void 贴标机条码打印_Load(object sender, EventArgs e)
  74. {
  75. LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
  76. dh = new DataHelper();
  77. CheckForIllegalCrossThreadCalls = false;
  78. pi_inoutno.Focus();
  79. //将本地读取的打印机设置进Combox,并选中默认打印机
  80. if (User.UserAccountType == "admin")
  81. {
  82. PowerSetting.Visible = true;
  83. }
  84. sg_code.FormName = Name;
  85. sg_code.SetValueField = new string[] { "sg_code" };
  86. sg_code.SelectField = "sg_code # 策略编号 ,sg_name # 策略名称,sg_brand # 品牌,sg_separator # 分隔符";
  87. sg_code.TableName = "scangroup";
  88. pr_code.FormName = Name;
  89. pr_code.SetValueField = new string[] { "pr_code", "pib_id" };
  90. pr_code.TableName = "prodiodetail ";
  91. pr_code.SelectField = "pd_pdno # 行号,pd_prodcode # 物料编号";
  92. ChooseAll.ChooseAll(LabelInf);
  93. CollectionUnit.Text = "盘";
  94. Point pt = new Point();
  95. int ScreenWidth = Screen.GetWorkingArea(pt).Width;
  96. //如果分辨率大的设置的字体对应的变大
  97. if (ScreenWidth > 1366)
  98. {
  99. foreach (Control ctl in Controls)
  100. {
  101. if (ctl is CheckBox || ctl is Label || ctl is RadioButton)
  102. {
  103. ctl.Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
  104. }
  105. if (ctl is GroupBoxWithBorder)
  106. {
  107. GroupBoxWithBorder gb = ctl as GroupBoxWithBorder;
  108. for (int i = 0; i < gb.Controls.Count; i++)
  109. {
  110. if (gb.Controls[i] is CheckBox || gb.Controls[i] is Label || gb.Controls[i] is RadioButton)
  111. {
  112. gb.Controls[i].Font = new Font("微软雅黑", 10.5F, FontStyle.Regular, GraphicsUnit.Point, 134);
  113. }
  114. }
  115. }
  116. }
  117. }
  118. //设置获取当前屏幕大小自动全屏但是保留任务栏
  119. Rectangle ScreenArea = Screen.GetWorkingArea(this);
  120. Top = 0;
  121. Left = 0;
  122. Width = ScreenArea.Width;
  123. Height = ScreenArea.Height;
  124. //怡海能达添加的特殊字段
  125. if (DataHelper.DBConnectionString.Contains("sz.hi-mantech.com") || DataHelper.DBConnectionString.Contains("192.168.1.200"))
  126. {
  127. DateCode1.Visible = true;
  128. }
  129. asc.controlAutoSize(this);
  130. //实例化打印进程
  131. try
  132. {
  133. lbl = new ApplicationClass();
  134. }
  135. catch (Exception)
  136. {
  137. MessageBox.Show("未安装CodeSoft软件或者版本不正确");
  138. }
  139. }
  140. private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
  141. {
  142. asc.controlAutoSize(this);
  143. }
  144. private void GenerateBarCode_Click(object sender, EventArgs e)
  145. {
  146. 生成条码 form = new 生成条码(pi_inoutno.Text);
  147. form.FormClosed += LoadGridData;
  148. BaseUtil.SetFormCenter(form);
  149. form.ShowDialog();
  150. }
  151. private void CollectionSetting_Click(object sender, EventArgs e)
  152. {
  153. 采集策略 form = new 采集策略(sg_code.Text);
  154. form.FormClosed += sg_code_UserControlTextChanged;
  155. BaseUtil.SetFormCenter(form);
  156. form.ShowDialog();
  157. }
  158. private void LabelMaintain_Click(object sender, EventArgs e)
  159. {
  160. 客户标签维护 form = new 客户标签维护();
  161. BaseUtil.SetFormCenter(form);
  162. form.ShowDialog();
  163. }
  164. /// <summary>
  165. /// 保存明细
  166. /// </summary>
  167. /// <param name="sender"></param>
  168. /// <param name="e"></param>
  169. private void SaveGrid_Click(object sender, EventArgs e)
  170. {
  171. DataTable savedt = LabelInf.DataSource as DataTable;
  172. if (LabelInf.DataSource != null && savedt.GetChanges() != null)
  173. {
  174. dh.UpDateTableByCondition((LabelInf.DataSource as DataTable), "ProdioBarCode", "pib_id");
  175. LoadGridData(sender, e);
  176. MessageBox.Show("保存成功!");
  177. }
  178. }
  179. //放大镜选择后出发的事件
  180. private void sg_code_UserControlTextChanged(object sender, EventArgs e)
  181. {
  182. //取已启用的的按照采集次序排序
  183. 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");
  184. BaseUtil.FillDgvWithDataTable(Si_ItemDGV, dt);
  185. if (dt.Rows.Count > 0)
  186. {
  187. sg_separator.Text = dt.Rows[0]["sg_separator"].ToString();
  188. }
  189. //按DetNo排列之后的采集项
  190. ScanData = new ArrayList<ArrayList<string>>();
  191. //每个采集项目的子项
  192. GetData = new ArrayList<string>();
  193. //将数据添加进一个List的二维数组中
  194. for (int i = 0; i < Si_ItemDGV.RowCount; i++)
  195. {
  196. //如果不包含这个则添加进数组
  197. if (!GetData.Contains(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString()))
  198. {
  199. GetData.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString());
  200. }
  201. //如果和后一个的采集次序相同
  202. 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())
  203. {
  204. GetData.Add(Si_ItemDGV.Rows[i + 1].Cells["si_item"].Value.ToString());
  205. }
  206. else
  207. {
  208. ScanData.Add(GetData);
  209. //添加完一次数据需要一个新的List
  210. GetData = new ArrayList<string>();
  211. }
  212. }
  213. RemindUser();
  214. if (ScanData.ToArray().Length > 0)
  215. {
  216. object[] arr = (ScanData.ToArray()[0] as ArrayList<string>).ToArray();
  217. if (arr.Contains("MPN"))
  218. {
  219. AutoMatch.CheckState = CheckState.Checked;
  220. AutoMatch.Enabled = true;
  221. }
  222. else
  223. {
  224. AutoMatch.CheckState = CheckState.Unchecked;
  225. AutoMatch.Enabled = false;
  226. }
  227. }
  228. }
  229. //输入框Enter事件
  230. private void Input_KeyDown(object sender, KeyEventArgs e)
  231. {
  232. if (e.KeyCode == Keys.Enter)
  233. {
  234. if (Input.Text == "")
  235. {
  236. BaseUtil.ShowError("采集的数据不能为空");
  237. }
  238. CollectInputData();
  239. }
  240. }
  241. /// <summary>
  242. /// 设置自动匹配的数据的行号
  243. /// </summary>
  244. /// <returns></returns>
  245. private void SetAutoMatchRow()
  246. {
  247. //采集策略的第一组数据
  248. string[] arr = new string[ItemData.Length];
  249. if (sg_separator.Text == "")
  250. {
  251. for (int i = 0; i < arr.Length; i++)
  252. {
  253. arr[i] = Input.Text;
  254. }
  255. }
  256. else
  257. {
  258. arr = Input.Text.Split(sg_separator.Text.ToCharArray()).ToArray();
  259. }
  260. bool FindAutoMatch = false;
  261. for (int i = 0; i < LabelInf.RowCount; i++)
  262. {
  263. for (int j = 0; j < arr.Length; j++)
  264. {
  265. if (LabelInf.Rows[i].Cells["pr_vendprodcode"].Value.ToString() == MatchStr(arr[j].ToString(), "MPN") && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  266. {
  267. CurrentRowIndex = i;
  268. FindAutoMatch = true;
  269. break;
  270. }
  271. }
  272. if (FindAutoMatch)
  273. {
  274. break;
  275. }
  276. }
  277. }
  278. /// <summary>
  279. /// 采集数据
  280. /// </summary>
  281. private void CollectInputData()
  282. {
  283. LogManager.DoLog("采集数据【" + Input.Text + "】,使用采集策略编号【" + sg_code.Text + "】");
  284. //按DetNo排列之后的采集项
  285. ScanData = new ArrayList<ArrayList<string>>();
  286. //每个采集项目的子项
  287. GetData = new ArrayList<string>();
  288. //用于保存采集策略的具体信息
  289. SiItem = new Dictionary<string, Dictionary<string, string>>();
  290. for (int i = 0; i < Si_ItemDGV.RowCount; i++)
  291. {
  292. //如果不包含这个则添加进数组
  293. if (!GetData.Contains(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString()))
  294. {
  295. GetData.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString());
  296. }
  297. //如果和后一个的采集次序相同
  298. 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())
  299. {
  300. GetData.Add(Si_ItemDGV.Rows[i + 1].Cells["si_item"].Value.ToString());
  301. }
  302. else
  303. {
  304. ScanData.Add(GetData);
  305. //添加完一次数据需要一个新的List
  306. GetData = new ArrayList<string>();
  307. }
  308. Dictionary<string, string> item = new Dictionary<string, string>();
  309. for (int j = 0; j < Si_ItemDGV.ColumnCount; j++)
  310. {
  311. item.Add(Si_ItemDGV.Columns[j].DataPropertyName, Si_ItemDGV.Rows[i].Cells[j].Value.ToString());
  312. }
  313. SiItem.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString().ToUpper(), item);
  314. }
  315. //采集项目的数组
  316. ItemData = (ScanData.ToArray()[CurrentItemIndex] as ArrayList<string>).ToArray();
  317. //分隔符不为空的时候 //采集的项和Grid的数目不等
  318. //用户采集的数据的分割数组
  319. CollectData = new Dictionary<string, string>();
  320. if (sg_separator.Text == "")
  321. {
  322. for (int i = 0; i < ItemData.Length; i++)
  323. {
  324. CollectData.Add(ItemData[i].ToString().ToUpper(), Input.Text);
  325. }
  326. }
  327. else
  328. {
  329. for (int i = 0; i < Input.Text.Split(sg_separator.Text.ToCharArray()).Length; i++)
  330. {
  331. CollectData.Add(ItemData[i].ToString().ToUpper(), Input.Text.Split(sg_separator.Text.ToCharArray())[i]);
  332. }
  333. }
  334. //首先判断当前采集的个数,如果采集的个数为1则不对数据进行分隔符验证
  335. if (ItemData.Length == 1)
  336. {
  337. CollectData.Clear();
  338. CollectData.Add(ItemData[0].ToString().ToUpper(), Input.Text);
  339. //勾选了自动匹配调用该函数
  340. if (AutoMatch.Checked)
  341. {
  342. SetAutoMatchRow();
  343. }
  344. //将筛选之后的值赋给Cell
  345. SetDataToCell(ref CollectData, ItemData[0].ToString().ToUpper());
  346. }
  347. //如果本次采集的数据分割后和当前的采集项目个数不一样提示用户错误
  348. else if (CollectData.ToArray().Length == ItemData.Length)
  349. {
  350. for (int i = 0; i < ItemData.Length; i++)
  351. {
  352. //勾选了自动匹配调用该函数
  353. if (AutoMatch.Checked)
  354. {
  355. SetAutoMatchRow();
  356. }
  357. //将筛选之后的值赋给Cell
  358. SetDataToCell(ref CollectData, ItemData[i].ToString().ToUpper());
  359. }
  360. }
  361. else
  362. {
  363. BaseUtil.ShowError("所采集的数据个数和采集项目不符");
  364. }
  365. //采集项目的索引+1
  366. CurrentItemIndex = CurrentItemIndex + 1;
  367. //如果已经采集完了最后一个
  368. if (CurrentItemIndex == ScanData.ToArray().Length)
  369. {
  370. //数据校验均已通过则勾选上已采集
  371. if (CollectVeProdCodePass && CollectQTYPass)
  372. {
  373. //如果按盒号采集,所有的此盒的均更新为
  374. if (CollectionUnit.Text == "盒")
  375. {
  376. string la_id = SingleLabelCombox.SelectedValue.ToString();
  377. string cl_labelname = SingleLabelCombox.Text;
  378. 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();
  379. //获取打印的标签文件
  380. SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelUrl, cl_labelname));
  381. try
  382. {
  383. for (int i = 0; i < LabelInf.RowCount; i++)
  384. {
  385. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  386. {
  387. LabelInf.Rows[i].Cells["pib_lotno"].Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value;
  388. LabelInf.Rows[i].Cells["pib_datecode"].Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value;
  389. //将采集数据正确的Cell添加到键值对中
  390. if (PaintCell.ContainsKey(LabelInf.Rows[i].Cells["pr_vendprodcode"]))
  391. {
  392. PaintCell.Remove(LabelInf.Rows[i].Cells["pr_vendprodcode"]);
  393. }
  394. PaintCell.Add(LabelInf.Rows[i].Cells["pr_vendprodcode"], true);
  395. if (PaintCell.ContainsKey(LabelInf.Rows[i].Cells["pib_qty"]))
  396. {
  397. PaintCell.Remove(LabelInf.Rows[i].Cells["pib_qty"]);
  398. }
  399. PaintCell.Add(LabelInf.Rows[i].Cells["pib_qty"], true);
  400. LabelInf.Refresh();
  401. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  402. //当前行的索引随循环增长
  403. CurrentRowIndex = i;
  404. if (SingleLabelAutoPrint.Checked)
  405. {
  406. AutoPrintSingleLabel(la_id, LabelUrl);
  407. }
  408. if (MidLabelAutoPrint.Checked)
  409. {
  410. AutoPrintMidLabel();
  411. }
  412. SetOutBoxCode2(true);
  413. }
  414. }
  415. SingleDoc.Close();
  416. }
  417. catch (Exception)
  418. {
  419. SingleDoc.Close();
  420. }
  421. }
  422. else if (CollectionUnit.Text == "全部")
  423. {
  424. for (int i = 0; i < LabelInf.RowCount; i++)
  425. {
  426. LabelInf.Rows[i].Cells["pib_lotno"].Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value;
  427. LabelInf.Rows[i].Cells["pib_datecode"].Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value;
  428. CurrentRowIndex = i;
  429. //将采集数据正确的Cell添加到键值对中
  430. if (PaintCell.ContainsKey(LabelInf.Rows[i].Cells["pr_vendprodcode"]))
  431. {
  432. PaintCell.Remove(LabelInf.Rows[i].Cells["pr_vendprodcode"]);
  433. }
  434. PaintCell.Add(LabelInf.Rows[i].Cells["pr_vendprodcode"], true);
  435. if (PaintCell.ContainsKey(LabelInf.Rows[i].Cells["pib_qty"]))
  436. {
  437. PaintCell.Remove(LabelInf.Rows[i].Cells["pib_qty"]);
  438. }
  439. PaintCell.Add(LabelInf.Rows[i].Cells["pib_qty"], true);
  440. LabelInf.Refresh();
  441. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  442. SetOutBoxCode2(true);
  443. }
  444. }
  445. else
  446. {
  447. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
  448. //勾选了单盘自动打印
  449. if (SingleLabelAutoPrint.Checked)
  450. {
  451. try
  452. {
  453. string la_id = SingleLabelCombox.SelectedValue.ToString();
  454. string cl_labelname = SingleLabelCombox.Text;
  455. 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();
  456. SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelUrl, cl_labelname));
  457. AutoPrintSingleLabel(la_id, LabelUrl);
  458. SingleDoc.Close();
  459. }
  460. catch (Exception)
  461. {
  462. SingleDoc.Close();
  463. }
  464. }
  465. //勾选了中盒自动打印
  466. if (MidLabelAutoPrint.Checked)
  467. {
  468. AutoPrintMidLabel();
  469. }
  470. //勾选了外箱自动打印
  471. if (OutBoxLabelAutoPrint.Checked)
  472. {
  473. }
  474. }
  475. }
  476. //采集未通过的时候
  477. else
  478. {
  479. //如果自动采集采集未成功需要移动到下一行
  480. if (!AutoMatch.Checked)
  481. {
  482. SetRowIndexToCollectRow();
  483. }
  484. }
  485. //当前项目已采集完成,重置采集项目
  486. CurrentItemIndex = 0;
  487. //未勾选自动匹配,设置到下一个未采集的行
  488. if (!AutoMatch.Checked)
  489. {
  490. SetRowIndexToCollectRow();
  491. }
  492. //采集完了一行后Index+1
  493. //CurrentRowIndex = (CurrentRowIndex + 1 == LabelInf.RowCount) ? CurrentRowIndex : CurrentRowIndex + 1;
  494. }
  495. //提醒用户需要采集的数据
  496. RemindUser();
  497. RefreshProcessData();
  498. MessageLog.AppendText(">>扫描到数据" + Input.Text + "\n", Color.Blue);
  499. if (CleanInputAfterCollect.Checked)
  500. {
  501. Input.Text = "";
  502. }
  503. }
  504. //设置行的索引到当前需要采集的行
  505. private void SetRowIndexToCollectRow()
  506. {
  507. //获取当前需要采集的行
  508. for (int i = CurrentRowIndex; i < LabelInf.RowCount; i++)
  509. {
  510. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  511. {
  512. griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
  513. pr_code.Text = LabelInf.Rows[i].Cells["pib_prodcode"].FormattedValue.ToString();
  514. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
  515. break;
  516. }
  517. }
  518. }
  519. private void AutoPrintSingleLabel(string la_id, string LabelUrl)
  520. {
  521. //获取维护的变量名称和SQL
  522. 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");
  523. //用标签本身的变量作为最外层的循环条件去匹配
  524. for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++)
  525. {
  526. Console.WriteLine(j);
  527. Console.WriteLine(SingleDoc.Variables.FreeVariables.Item(j + 1).Name);
  528. Console.WriteLine(SingleDoc.Variables.FreeVariables.Item(j + 1).DisplayValue);
  529. //将维护的模板参数和模板本身的参数名称进行比对
  530. for (int k = 0; k < dt.Rows.Count; k++)
  531. {
  532. //名称相等的时候,取SQL进行值的查询
  533. if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
  534. {
  535. //获取打印执行的SQL
  536. string sql = dt.Rows[k]["lp_sql"].ToString();
  537. if (sql.IndexOf("{") == 0)
  538. {
  539. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql).ToString();
  540. LogManager.DoLog("打印参数【" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + sql + ",取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value);
  541. }
  542. else
  543. {
  544. sql = sql.Substring(0, sql.IndexOf("{"));
  545. //获取对应行的pib_id
  546. string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
  547. if (sql.ToLower().Contains("pib_lotno"))
  548. {
  549. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString();
  550. }
  551. else if (sql.ToLower().Contains("pib_datecode"))
  552. {
  553. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString();
  554. }
  555. else
  556. {
  557. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql + pib_id).ToString();
  558. }
  559. LogManager.DoLog("打印参数【" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + sql + pib_id + ",取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value);
  560. }
  561. }
  562. else if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name == "DateCode1")
  563. {
  564. if (LabelInf.Rows[CurrentRowIndex].Cells["DateCode1"].Value != null)
  565. {
  566. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["DateCode1"].Value.ToString();
  567. }
  568. }
  569. }
  570. }
  571. //保存参数打印
  572. SingleDoc.Save();
  573. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  574. SingleDoc.PrintDocument();
  575. LogManager.DoLog("执行打印单盘,pib_id:" + LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString() + ",标签地址" + LabelUrl);
  576. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifprint"].Value = true;
  577. LogManager.DoLog("打印文件" + SingleDoc.Name + "关闭");
  578. }
  579. /// <summary>
  580. /// 提醒用户当前采集的项目
  581. /// </summary>
  582. private void RemindUser()
  583. {
  584. SetRowIndexToCollectRow();
  585. if (ScanData.ToArray().Length > 0)
  586. {
  587. object[] arr = (ScanData.ToArray()[CurrentItemIndex] as ArrayList<string>).ToArray();
  588. string Inf = "";
  589. for (int i = 0; i < arr.Length; i++)
  590. {
  591. Inf += arr[i] + " ";
  592. }
  593. MessageLog.AppendText(">>当前采集行" + (CurrentRowIndex + 1) + ",请采集" + Inf + "\n", Color.Green);
  594. }
  595. }
  596. /// <summary>
  597. /// 自定义函数 将匹配之后的值设置到Cell中,传递引用,每次赋值之后从List中移除已使用过的
  598. /// </summary>
  599. /// <param name="data"></param>
  600. /// <param name="kind"></param>
  601. private void SetDataToCell(ref Dictionary<string, string> setdata, string kind)
  602. {
  603. int length = setdata.Count;
  604. for (int j = 0; j < length; j++)
  605. {
  606. string[] data = new string[setdata.Count];
  607. for (int i = 0; i < length; i++)
  608. {
  609. data[i] = setdata[kind];
  610. }
  611. for (int i = 0; i < data.Length; i++)
  612. {
  613. DataGridViewCell cell = null;
  614. string Matchstr = "";
  615. switch (kind.ToString().ToUpper())
  616. {
  617. case "DATECODE":
  618. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"];
  619. Matchstr = MatchStr(data[j], "DATECODE");
  620. setdata.Remove("DATECODE");
  621. length--;
  622. break;
  623. case "LOTNO":
  624. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"];
  625. Matchstr = MatchStr(data[j], "LOTNO");
  626. setdata.Remove("LOTNO");
  627. length--;
  628. break;
  629. case "MPN":
  630. cell = LabelInf.Rows[CurrentRowIndex].Cells["pr_vendprodcode"];
  631. Matchstr = MatchStr(data[j], "MPN");
  632. //采集的供应商号不匹配的话
  633. if (cell.Value.ToString() != Matchstr)
  634. {
  635. CollectVeProdCodePass = false;
  636. //添加需要重绘的Cell
  637. if (PaintCell.ContainsKey(cell))
  638. {
  639. PaintCell.Remove(cell);
  640. }
  641. PaintCell.Add(cell, false);
  642. LabelInf.Refresh();
  643. MessageLog.AppendText(">>供应商物料编号不匹配\n", Color.Red);
  644. }
  645. else
  646. {
  647. if (PaintCell.ContainsKey(cell))
  648. {
  649. PaintCell.Remove(cell);
  650. }
  651. PaintCell.Add(cell, true);
  652. LabelInf.Refresh();
  653. CollectVeProdCodePass = true;
  654. }
  655. setdata.Remove("MPN");
  656. length--;
  657. break;
  658. case "QTY":
  659. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_qty"];
  660. Matchstr = MatchStr(data[j], "QTY");
  661. //如果采集的数量不相等的话
  662. if (cell.Value.ToString() != Matchstr)
  663. {
  664. CollectQTYPass = false;
  665. //添加需要重绘的Cell
  666. if (PaintCell.ContainsKey(cell))
  667. {
  668. PaintCell.Remove(cell);
  669. }
  670. PaintCell.Add(cell, false);
  671. LabelInf.Refresh();
  672. MessageLog.AppendText(">>数量不匹配\n", Color.Red);
  673. }
  674. else
  675. {
  676. if (PaintCell.ContainsKey(cell))
  677. {
  678. PaintCell.Remove(cell);
  679. }
  680. PaintCell.Add(cell, true);
  681. LabelInf.Refresh();
  682. CollectQTYPass = true;
  683. }
  684. setdata.Remove("QTY");
  685. length--;
  686. break;
  687. default:
  688. break;
  689. }
  690. //如果数据为空或者数据不为空的时候但是和需要采集的数据不相等的情况下进行采集
  691. //MPN和QTY只做比较不需要赋值
  692. if (cell.Value.ToString() == "" || cell.Value.ToString() != Matchstr)
  693. {
  694. string MatchResult = "";
  695. if (kind != "MPN" && kind != "QTY")
  696. {
  697. cell.Value = Matchstr;
  698. MatchResult = "成功";
  699. }
  700. else
  701. {
  702. MatchResult = "失败";
  703. }
  704. switch (SiItem[kind]["si_kind"])
  705. {
  706. case "索引字符":
  707. LogManager.DoLog("采集项" + kind + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[kind]["si_kind"] + ",使用字符" + SiItem[kind]["si_indexstring"] + ",匹配后字符串" + Matchstr);
  708. break;
  709. case "起始位置":
  710. LogManager.DoLog("采集项" + kind + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[kind]["si_kind"] + ",从第" + SiItem[kind]["si_index"] + "位开始匹配,匹配后字符串" + Matchstr);
  711. break;
  712. case "二次解析":
  713. LogManager.DoLog("采集项" + kind + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[kind]["si_kind"] + ",匹配后字符串" + Matchstr);
  714. break;
  715. case "全部":
  716. LogManager.DoLog("采集项" + kind + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[kind]["si_kind"] + ",匹配后字符串" + Matchstr);
  717. break;
  718. default:
  719. break;
  720. }
  721. }
  722. else
  723. {
  724. LogManager.DoLog("采集项" + kind + ",匹配结果:【成功】,匹配方式:" + SiItem[kind]["si_kind"] + ",,匹配后字符串" + Matchstr);
  725. }
  726. }
  727. }
  728. //添加外箱号,如果外箱号的箱内容量不为0并且已经采集完成
  729. SetOutBoxCode2(false);
  730. }
  731. //
  732. /// <summary>
  733. /// 设置外箱号
  734. /// </summary>
  735. /// <param name="BatchCollect">是否批量采集</param>
  736. private void SetOutBoxCode2(bool BatchCollect)
  737. {
  738. if (OutboxCapacity.Value != 0)
  739. {
  740. //获取当前出入口单最大的外箱号
  741. for (int i = 0; i < LabelInf.RowCount; i++)
  742. {
  743. string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  744. if (outboxcode.Contains("-"))
  745. {
  746. if (int.Parse(outboxcode.Split('-')[0] == "" ? "1" : outboxcode.Split('-')[0]) > MaxOutBoxCode)
  747. {
  748. MaxOutBoxCode = int.Parse(outboxcode.Split('-')[0]);
  749. }
  750. }
  751. else
  752. {
  753. if (int.Parse(outboxcode == "" ? "0" : outboxcode) > MaxOutBoxCode)
  754. {
  755. MaxOutBoxCode = int.Parse(outboxcode);
  756. }
  757. }
  758. }
  759. //统计最大的箱号存在多少
  760. int MaxOutBoxCodeCount = 0;
  761. for (int i = 0; i < LabelInf.RowCount; i++)
  762. {
  763. if (LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString() == MaxOutBoxCode.ToString())
  764. {
  765. MaxOutBoxCodeCount = MaxOutBoxCodeCount + 1;
  766. }
  767. }
  768. //如果箱内的盒数量小于容量,继续使用此箱号赋值,否则箱号+1
  769. if (BatchCollect)
  770. {
  771. if (MaxOutBoxCodeCount < OutboxCapacity.Value)
  772. {
  773. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  774. }
  775. else
  776. {
  777. MaxOutBoxCode = MaxOutBoxCode + 1;
  778. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  779. }
  780. }
  781. else
  782. {
  783. if (MaxOutBoxCodeCount <= OutboxCapacity.Value)
  784. {
  785. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  786. }
  787. else
  788. {
  789. MaxOutBoxCode = MaxOutBoxCode + 1;
  790. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  791. }
  792. }
  793. }
  794. }
  795. /// <summary>
  796. /// 自定义函数 根据匹配规则
  797. /// si_item的二维数组,str是需要赋值的字符串,item表示DateCode,LotNo等
  798. /// </summary>
  799. /// <param name="SiItem"></param>
  800. /// <param name="str"></param>
  801. /// <param name="item"></param>
  802. /// <returns></returns>
  803. private string MatchStr(string str, string item)
  804. {
  805. string kind = SiItem[item]["si_kind"];
  806. //起始字符不为空的时候
  807. switch (kind)
  808. {
  809. case "起始位置":
  810. if (SiItem[item]["si_index"] != "")
  811. {
  812. try
  813. {
  814. //长度不为空的时候按照指定的长度去取数据
  815. if (SiItem[item]["si_length"] != "")
  816. {
  817. str = str.Substring(int.Parse(SiItem[item]["si_index"]), int.Parse(SiItem[item]["si_length"]));
  818. }
  819. //长度为空的时候取index之后的全部数据
  820. else
  821. {
  822. str = str.Substring(int.Parse(SiItem[item]["si_index"]));
  823. }
  824. }
  825. catch (Exception e)
  826. {
  827. LogManager.DoLog(e.Message);
  828. }
  829. }
  830. break;
  831. case "索引字符":
  832. try
  833. {
  834. if (SiItem[item]["si_indexstring"] != "")
  835. {
  836. //长度不为空的时候按照指定的长度去取数据
  837. if (SiItem[item]["si_length"] != "")
  838. {
  839. str = str.Substring(str.IndexOf(SiItem[item]["si_indexstring"]) + 1, int.Parse(SiItem[item]["si_length"]));
  840. }
  841. //长度为空的时候取index之后的全部数据
  842. else
  843. {
  844. str = str.Substring(str.IndexOf(SiItem[item]["si_indexstring"]) + 1);
  845. }
  846. }
  847. }
  848. catch (Exception e)
  849. {
  850. LogManager.DoLog(e.Message);
  851. }
  852. break;
  853. case "二次解析":
  854. str = Analysis.AnalysisData(Brand, item, str);
  855. break;
  856. case "全部":
  857. break;
  858. default:
  859. break;
  860. }
  861. if (SiItem[item]["si_expression"] != "")
  862. {
  863. string log = "使用正则表达式" + SiItem[item]["si_expression"] + "匹配数据" + str;
  864. reg = new Regex(SiItem[item]["si_expression"]);
  865. str = reg.Match(str).Value;
  866. log += ",匹配后数据" + str;
  867. LogManager.DoLog(log);
  868. }
  869. return str;
  870. }
  871. //关闭窗口前提示用户确认
  872. private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
  873. {
  874. //如果不是注销的话
  875. if (!logout)
  876. {
  877. string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  878. if (close.ToString() != "Yes")
  879. {
  880. e.Cancel = true;
  881. }
  882. else
  883. {
  884. //防止未安装打印程序时报错导致窗体无法关闭
  885. try
  886. {
  887. lbl.Application.Quit();
  888. LogManager.DoLog("关闭程序");
  889. // System.Windows.Forms.Application.Exit();
  890. }
  891. catch
  892. {
  893. }
  894. }
  895. }
  896. }
  897. /// <summary>
  898. /// 出入库单录入框的回车事件
  899. /// </summary>
  900. /// <param name="sender"></param>
  901. /// <param name="e"></param>
  902. private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
  903. {
  904. if (e.KeyCode == Keys.Enter)
  905. {
  906. sql.Clear();
  907. sql.Append("select pi_id,pi_cardcode from prodinout where pi_inoutno='" + pi_inoutno.Text + "'");
  908. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  909. if (dt.Rows.Count > 0)
  910. {
  911. pi_cardcode.Text = dt.Rows[0]["pi_cardcode"].ToString();
  912. PI_ID = dt.Rows[0]["pi_id"].ToString();
  913. LoadGridData(sender, e);
  914. //刷新采集进度
  915. RefreshProcessData();
  916. //设置当前的最大箱号
  917. for (int i = 0; i < LabelInf.RowCount; i++)
  918. {
  919. string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  920. //如果包含有-,则需要解析
  921. if (outboxcode.Contains("-"))
  922. {
  923. if (int.Parse(outboxcode.Split('-')[0] == "" ? "1" : outboxcode.Split('-')[0]) > MaxOutBoxCode)
  924. {
  925. MaxOutBoxCode = int.Parse(outboxcode.Split('-')[0]);
  926. }
  927. }
  928. else
  929. {
  930. if (int.Parse(outboxcode == "" ? "1" : outboxcode) > MaxOutBoxCode)
  931. {
  932. MaxOutBoxCode = int.Parse(outboxcode);
  933. }
  934. }
  935. }
  936. sql.Clear();
  937. sql.Append("select cl_labelname,cl_isdefault,la_id from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  938. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  939. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode='共用')) and cl_labeltype='单盘'");
  940. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  941. SingleLabelCombox.DataSource = dt;
  942. SingleLabelCombox.DisplayMember = "cl_labelname";
  943. SingleLabelCombox.ValueMember = "la_id";
  944. sql.Clear();
  945. sql.Append("select cl_labelname,cl_isdefault,la_id from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  946. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  947. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode='共用')) and cl_labeltype='中盒'");
  948. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  949. MidLabelCombox.DataSource = dt.Copy();
  950. MidLabelCombox.DisplayMember = "cl_labelname";
  951. MidLabelCombox.ValueMember = "la_id";
  952. sql.Clear();
  953. sql.Append("select cl_labelname,cl_isdefault,la_id from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  954. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  955. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode='共用')) and cl_labeltype='外箱'");
  956. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  957. OutBoxCombox.DataSource = dt.Copy();
  958. OutBoxCombox.DisplayMember = "cl_labelname";
  959. OutBoxCombox.ValueMember = "la_id";
  960. //重置采集项次
  961. CurrentItemIndex = 0;
  962. LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
  963. }
  964. else
  965. {
  966. MessageBox.Show("当前出入库单号不存在!");
  967. }
  968. }
  969. }
  970. private void SingleBoxPrint()
  971. {
  972. try
  973. {
  974. string la_id = SingleLabelCombox.SelectedValue.ToString();
  975. string cl_labelname = SingleLabelCombox.Text;
  976. 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();
  977. SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelUrl, cl_labelname));
  978. //查询该模板维护的所有参数
  979. 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");
  980. if (dt.Rows.Count > 0)
  981. {
  982. //获取全部的中盒号
  983. Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
  984. //判断所有盒号为该盒的是否勾选已采集
  985. outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
  986. for (int i = 0; i < LabelInf.RowCount; i++)
  987. {
  988. if (i + 1 < LabelInf.RowCount)
  989. {
  990. //如果本行的中盒数量和下一行相等的话
  991. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString())
  992. {
  993. if (!outboxcode1.ContainsKey(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  994. {
  995. outboxcode1.Add(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString(), true);
  996. }
  997. }
  998. }
  999. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  1000. {
  1001. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1002. {
  1003. outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()] = false;
  1004. }
  1005. }
  1006. }
  1007. //用于判断用户是否勾选了行
  1008. int CheckedRowCount=0;
  1009. //打印所有的选中行
  1010. for (int i = 0; i < LabelInf.RowCount; i++)
  1011. {
  1012. //勾选了并且未打印
  1013. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
  1014. {
  1015. CheckedRowCount = CheckedRowCount + 1;
  1016. CurrentRowIndex = i;
  1017. //以标签模板的参数为基准,循环取数
  1018. for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++)
  1019. {
  1020. //将维护的模板参数和模板本身的参数名称进行比对
  1021. for (int k = 0; k < dt.Rows.Count; k++)
  1022. {
  1023. //名称相等的时候,取SQL进行值的查询
  1024. if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
  1025. {
  1026. //获取打印执行的SQL
  1027. string sql = dt.Rows[k]["lp_sql"].ToString();
  1028. if (sql.IndexOf("{") == 0)
  1029. {
  1030. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql).ToString();
  1031. LogManager.DoLog("打印参数【" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value);
  1032. }
  1033. else
  1034. {
  1035. sql = sql.Substring(0, sql.IndexOf("{"));
  1036. //获取对应行的pib_id
  1037. string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  1038. if (sql.ToLower().Contains("pib_lotno"))
  1039. {
  1040. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString();
  1041. }
  1042. else if (sql.ToLower().Contains("pib_datecode"))
  1043. {
  1044. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString();
  1045. }
  1046. else
  1047. {
  1048. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql + pib_id).ToString();
  1049. }
  1050. LogManager.DoLog("打印参数【" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + sql + pib_id + ",取到值" + SingleDoc.Variables.FreeVariables.Item(j + 1).Value);
  1051. }
  1052. }
  1053. else if (SingleDoc.Variables.FreeVariables.Item(j + 1).Name == "DateCode1")
  1054. {
  1055. if (LabelInf.Rows[i].Cells["DateCode1"].Value != null)
  1056. {
  1057. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[i].Cells["DateCode1"].Value.ToString();
  1058. }
  1059. }
  1060. }
  1061. }
  1062. //保存参数打印
  1063. SingleDoc.Save();
  1064. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  1065. SingleDoc.PrintDocument();
  1066. LogManager.DoLog("执行打印单盘,pib_id:" + LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + ",标签地址" + LabelUrl);
  1067. //勾选为已打印
  1068. LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
  1069. }
  1070. if (MidLabelAutoPrint.Checked)
  1071. {
  1072. //判断当前行的盒号和下一行不相等或者已经是最后一行了
  1073. if (i + 1 == LabelInf.RowCount || LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1 == LabelInf.RowCount ? i : i + 1].Cells["pib_outboxcode1"].Value.ToString())
  1074. {
  1075. if (outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()])
  1076. {
  1077. if (MidLabelCombox.SelectedValue != null)
  1078. {
  1079. string la_id_mid = MidLabelCombox.SelectedValue.ToString();
  1080. string cl_labelname_mid = MidLabelCombox.Text;
  1081. string LabelUrl_mid = dh.getFieldDataByCondition("label left join customerlabel on la_code=cl_labelcode", "cl_labelurl", "la_id='" + la_id_mid + "' and cl_labelname='" + cl_labelname_mid + "'").ToString();
  1082. MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelUrl_mid, cl_labelname_mid));
  1083. DataTable dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + la_id_mid, "select");
  1084. for (int j = 0; j < MidDoc.Variables.FreeVariables.Count; j++)
  1085. {
  1086. //将维护的模板参数和模板本身的参数名称进行比对
  1087. for (int k = 0; k < dt.Rows.Count; k++)
  1088. {
  1089. //名称相等的时候,取SQL进行值的查询
  1090. if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
  1091. {
  1092. //获取对应行的pib_id
  1093. string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
  1094. string pib_outboxcode1 = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  1095. //获取打印执行的SQL
  1096. string sql = dt.Rows[k]["lp_sql"].ToString();
  1097. //select * from productiobarcode where pib_id={pib_id} and pib_outboxcode1={pib_outboxcode1}
  1098. try
  1099. {
  1100. string ExeSQL = "";
  1101. if (sql.Contains("pib_lotno"))
  1102. {
  1103. MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString();
  1104. }
  1105. else if (sql.Contains("pib_datecode"))
  1106. {
  1107. MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString();
  1108. }
  1109. else
  1110. {
  1111. ExeSQL = sql.Substring(0, sql.IndexOf("{")) + pib_id + sql.Substring(sql.IndexOf("}") + 1);
  1112. ExeSQL = ExeSQL.Substring(0, ExeSQL.IndexOf("{")) + pib_outboxcode1;
  1113. MidDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(ExeSQL).ToString();
  1114. }
  1115. LogManager.DoLog("打印参数【" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + ExeSQL + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value);
  1116. }
  1117. catch (Exception)
  1118. {
  1119. BaseUtil.ShowError("SQL维护不正确,请检查SQL语句");
  1120. }
  1121. }
  1122. else if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == "DateCode1")
  1123. {
  1124. if (LabelInf.Rows[i].Cells["DateCode1"].Value != null)
  1125. {
  1126. MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[i].Cells["DateCode1"].Value.ToString();
  1127. }
  1128. }
  1129. }
  1130. }
  1131. //保存参数打印
  1132. MidDoc.Save();
  1133. MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
  1134. MidDoc.PrintDocument();
  1135. LogManager.DoLog("执行打印中盒,pib_id:" + LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString());
  1136. lbl.ActiveDocument.Close();
  1137. LogManager.DoLog("打印文件" + MidDoc.Name + "关闭");
  1138. }
  1139. }
  1140. }
  1141. }
  1142. }
  1143. if (CheckedRowCount == 0) {
  1144. MessageBox.Show("未勾选打印明细!");
  1145. }
  1146. if (SingleDoc != null)
  1147. {
  1148. SingleDoc.Close();
  1149. LogManager.DoLog("打印文件" + SingleDoc.Name + "关闭");
  1150. }
  1151. if (MidDoc != null)
  1152. {
  1153. MidDoc.Close();
  1154. LogManager.DoLog("打印文件" + MidDoc.Name + "关闭");
  1155. }
  1156. outboxcode1.Clear();
  1157. }
  1158. else
  1159. {
  1160. BaseUtil.ShowError("此模板尚未维护参数");
  1161. }
  1162. }
  1163. catch (Exception ex)
  1164. {
  1165. if (SingleDoc != null)
  1166. {
  1167. SingleDoc.Close();
  1168. }
  1169. if (MidDoc != null)
  1170. {
  1171. MidDoc.Close();
  1172. }
  1173. LogManager.DoLog(ex.Message);
  1174. }
  1175. }
  1176. private void SingleLabelPrint_Click(object sender, EventArgs e)
  1177. {
  1178. thread = new Thread(SingleBoxPrint);
  1179. stw = new SetLoadingWindow(thread, "正在打印单盘");
  1180. BaseUtil.SetFormCenter(stw);
  1181. stw.ShowDialog();
  1182. }
  1183. private void MidLabelPrint_Click(object sender, EventArgs e)
  1184. {
  1185. if (MidLabelNum.Text == "")
  1186. {
  1187. BaseUtil.ShowError("手动打印必须填写盒号");
  1188. }
  1189. bool FindMidLabel = false;
  1190. if (MidLabelCombox.SelectedValue != null)
  1191. {
  1192. string la_id = MidLabelCombox.SelectedValue.ToString();
  1193. string cl_labelname = MidLabelCombox.Text;
  1194. 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();
  1195. MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelUrl, cl_labelname));
  1196. //中盒号所在的行
  1197. int MidLabelRowIndex = 0;
  1198. //查找是否存在该中盒号
  1199. for (int i = 0; i < LabelInf.RowCount; i++)
  1200. {
  1201. if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1202. {
  1203. //找到了输入的中盒号停止循环
  1204. FindMidLabel = true;
  1205. MidLabelRowIndex = i;
  1206. break;
  1207. }
  1208. }
  1209. //找到了指定的盒号
  1210. if (FindMidLabel)
  1211. {
  1212. 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");
  1213. try
  1214. {
  1215. for (int j = 0; j < MidDoc.Variables.FreeVariables.Count; j++)
  1216. {
  1217. //将维护的模板参数和模板本身的参数名称进行比对
  1218. for (int k = 0; k < dt.Rows.Count; k++)
  1219. {
  1220. //名称相等的时候,取SQL进行值的查询
  1221. if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
  1222. {
  1223. //获取对应行的pib_id
  1224. string pib_id = LabelInf.Rows[MidLabelRowIndex].Cells["pib_id1"].Value.ToString();
  1225. string pib_outboxcode1 = LabelInf.Rows[MidLabelRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  1226. //获取打印执行的SQL
  1227. string sql = dt.Rows[k]["lp_sql"].ToString();
  1228. //select * from productiobarcode where pib_id={pib_id} and pib_outboxcode1={pib_outboxcode1}
  1229. try
  1230. {
  1231. //获取打印执行的SQL
  1232. if (sql.IndexOf("{") == 0)
  1233. {
  1234. MidDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(sql).ToString();
  1235. LogManager.DoLog("打印参数【" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + dt.Rows[k]["lp_sql"].ToString() + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value);
  1236. }
  1237. else
  1238. {
  1239. string ExeSQL = "";
  1240. if (sql.Contains("pib_lotno"))
  1241. {
  1242. MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[MidLabelRowIndex].Cells["pib_lotno"].Value.ToString();
  1243. }
  1244. else if (sql.Contains("pib_datecode"))
  1245. {
  1246. MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[MidLabelRowIndex].Cells["pib_datecode"].Value.ToString();
  1247. }
  1248. else
  1249. {
  1250. ExeSQL = sql.Substring(0, sql.IndexOf("{")) + pib_id + sql.Substring(sql.IndexOf("}") + 1);
  1251. ExeSQL = ExeSQL.Substring(0, ExeSQL.IndexOf("{")) + pib_outboxcode1;
  1252. MidDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(ExeSQL).ToString();
  1253. }
  1254. LogManager.DoLog("打印参数【" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + ExeSQL + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value);
  1255. }
  1256. }
  1257. catch (Exception)
  1258. {
  1259. BaseUtil.ShowError("SQL维护不正确,请检查SQL语句\n" + sql);
  1260. }
  1261. }
  1262. else if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == "DateCode1")
  1263. {
  1264. if (LabelInf.Rows[MidLabelRowIndex].Cells["DateCode1"].Value != null)
  1265. {
  1266. MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[MidLabelRowIndex].Cells["DateCode1"].Value.ToString();
  1267. }
  1268. }
  1269. }
  1270. }
  1271. //保存参数打印
  1272. MidDoc.Save();
  1273. MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
  1274. MidDoc.PrintDocument();
  1275. LogManager.DoLog("执行打印中盒,pib_id:" + LabelInf.Rows[MidLabelRowIndex].Cells["pib_id1"].Value.ToString() + ",标签地址" + LabelUrl);
  1276. MidDoc.Close();
  1277. LogManager.DoLog("打印文件" + MidDoc.Name + "关闭");
  1278. }
  1279. catch (Exception)
  1280. {
  1281. MidDoc.Close();
  1282. }
  1283. }
  1284. else
  1285. {
  1286. BaseUtil.ShowError("该出入库单未找到该中盒号!");
  1287. }
  1288. }
  1289. else
  1290. {
  1291. MessageBox.Show("未维护中盒模板");
  1292. }
  1293. }
  1294. private void OutBoxPrint()
  1295. {
  1296. List<string> Outboxcode = new List<string>();
  1297. //如果未勾选箱号则对勾选的数据的箱号进行整合
  1298. if (OutBoxNum.Text == "")
  1299. {
  1300. for (int i = 0; i < LabelInf.RowCount; i++)
  1301. {
  1302. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  1303. {
  1304. string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  1305. //富为使用包装单的逻辑
  1306. if (outboxcode2.Contains("-")&& !Outboxcode.Contains(outboxcode2))
  1307. {
  1308. int small = int.Parse(outboxcode2.Split('-')[0]);
  1309. int big = int.Parse(outboxcode2.Split('-')[1]);
  1310. for (int n = 0; n < big-small+1; n++)
  1311. {
  1312. Outboxcode.Add(outboxcode2);
  1313. }
  1314. }
  1315. //如果不包含该箱号则进行添加
  1316. if (!Outboxcode.Contains(outboxcode2))
  1317. {
  1318. Outboxcode.Add(outboxcode2);
  1319. }
  1320. }
  1321. }
  1322. if (Outboxcode.ToArray().Length > 0)
  1323. {
  1324. string la_id = OutBoxCombox.SelectedValue.ToString();
  1325. string cl_labelname = OutBoxCombox.Text;
  1326. 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();
  1327. OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelUrl, cl_labelname));
  1328. try
  1329. {
  1330. // 循环打印外箱号
  1331. for (int i = 0; i < Outboxcode.ToArray().Length; i++)
  1332. {
  1333. for (int h = 0; h < LabelInf.RowCount; h++)
  1334. {
  1335. //try
  1336. //{
  1337. if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i])
  1338. {
  1339. 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");
  1340. for (int j = 0; j < OutBoxDoc.Variables.FreeVariables.Count; j++)
  1341. {
  1342. //将维护的模板参数和模板本身的参数名称进行比对
  1343. for (int k = 0; k < dt.Rows.Count; k++)
  1344. {
  1345. //名称相等的时候,取SQL进行值的查询
  1346. if (OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
  1347. {
  1348. //如果毛重填写的是毛重或者净重
  1349. if (dt.Rows[k]["lp_valuetype"].ToString() == "字符串" && dt.Rows[k]["lp_sql"].ToString() == "GW")
  1350. {
  1351. OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = WeightGross.Text;
  1352. LogManager.DoLog("打印参数【毛重】赋值," + WeightGross.Text);
  1353. }
  1354. else if (dt.Rows[k]["lp_valuetype"].ToString() == "字符串" && dt.Rows[k]["lp_sql"].ToString() == "NW")
  1355. {
  1356. OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = WeightNet.Text;
  1357. LogManager.DoLog("打印参数【净重】赋值," + WeightNet.Text);
  1358. }
  1359. else
  1360. {
  1361. //获取对应行的pib_id
  1362. string pib_id = LabelInf.Rows[h].Cells["pib_id1"].Value.ToString();
  1363. string pib_outboxcode2 = LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString();
  1364. string ExeSQL = "";
  1365. //获取打印执行的SQL
  1366. string sql = dt.Rows[k]["lp_sql"].ToString();
  1367. //try
  1368. //{
  1369. if (sql.Contains("pib_lotno"))
  1370. {
  1371. OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[h].Cells["pib_lotno"].Value.ToString();
  1372. }
  1373. else if (sql.Contains("pib_datecode"))
  1374. {
  1375. OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[h].Cells["pib_datecode"].Value.ToString();
  1376. }
  1377. else
  1378. {
  1379. ExeSQL = sql.Substring(0, sql.IndexOf("{")) + pib_id + sql.Substring(sql.IndexOf("}") + 1);
  1380. ExeSQL = ExeSQL.Substring(0, ExeSQL.IndexOf("{")) + "'" + pib_outboxcode2 + "'";
  1381. OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(ExeSQL).ToString();
  1382. }
  1383. LogManager.DoLog("打印参数【" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + ExeSQL + ",取到值" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value);
  1384. }
  1385. }
  1386. else if (OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name == "DateCode1")
  1387. {
  1388. if (LabelInf.Rows[h].Cells["DateCode1"].Value != null)
  1389. {
  1390. OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[h].Cells["DateCode1"].Value.ToString();
  1391. }
  1392. }
  1393. }
  1394. }
  1395. //保存参数打印
  1396. OutBoxDoc.Save();
  1397. OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
  1398. OutBoxDoc.PrintDocument();
  1399. LogManager.DoLog("执行打印外箱,pib_id:" + LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + ",标签地址" + LabelUrl);
  1400. break;
  1401. }
  1402. }
  1403. }
  1404. OutBoxDoc.Close();
  1405. LogManager.DoLog("打印文件" + OutBoxDoc.Name + "关闭");
  1406. }
  1407. catch
  1408. {
  1409. if (OutBoxDoc != null) {
  1410. OutBoxDoc.Close();
  1411. }
  1412. LogManager.DoLog("打印文件" + OutBoxDoc.Name + "关闭");
  1413. }
  1414. }
  1415. }
  1416. else
  1417. {
  1418. bool FindMidLabel = false;
  1419. string la_id = OutBoxCombox.SelectedValue.ToString();
  1420. string cl_labelname = OutBoxCombox.Text;
  1421. 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();
  1422. OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelUrl, cl_labelname));
  1423. try
  1424. {
  1425. int OutBoxLabelRowIndex = 0;
  1426. //查找是否存在该中盒号
  1427. for (int i = 0; i < LabelInf.RowCount; i++)
  1428. {
  1429. if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString())
  1430. {
  1431. //找到了输入的中盒号停止循环
  1432. FindMidLabel = true;
  1433. OutBoxLabelRowIndex = i;
  1434. break;
  1435. }
  1436. }
  1437. //找到了指定的盒号
  1438. if (FindMidLabel)
  1439. {
  1440. 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");
  1441. for (int j = 0; j < OutBoxDoc.Variables.FreeVariables.Count; j++)
  1442. {
  1443. //将维护的模板参数和模板本身的参数名称进行比对
  1444. for (int k = 0; k < dt.Rows.Count; k++)
  1445. {
  1446. //名称相等的时候,取SQL进行值的查询
  1447. if (OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
  1448. {
  1449. //如果毛重填写的是毛重或者净重
  1450. if (dt.Rows[k]["lp_valuetype"].ToString() == "字符串" && dt.Rows[k]["lp_sql"].ToString() == "GW")
  1451. {
  1452. OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = WeightGross.Text;
  1453. LogManager.DoLog("打印参数【毛重】赋值," + WeightGross.Text);
  1454. }
  1455. else if (dt.Rows[k]["lp_valuetype"].ToString() == "字符串" && dt.Rows[k]["lp_sql"].ToString() == "NW")
  1456. {
  1457. OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = WeightNet.Text;
  1458. LogManager.DoLog("打印参数【净重】赋值," + WeightNet.Text);
  1459. }
  1460. else
  1461. {
  1462. //获取对应行的pib_id
  1463. string pib_id = LabelInf.Rows[OutBoxLabelRowIndex].Cells["pib_id1"].Value.ToString();
  1464. string pib_outboxcode2 = LabelInf.Rows[OutBoxLabelRowIndex].Cells["pib_outboxcode2"].Value.ToString();
  1465. //获取打印执行的SQL
  1466. string sql = dt.Rows[k]["lp_sql"].ToString();
  1467. //select * from productiobarcode where pib_id={pib_id} and pib_outboxcode1={pib_outboxcode1}
  1468. try
  1469. {
  1470. string ExeSQL = "";
  1471. if (sql.Contains("pib_lotno"))
  1472. {
  1473. OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[OutBoxLabelRowIndex].Cells["pib_lotno"].Value.ToString();
  1474. }
  1475. else if (sql.Contains("pib_datecode"))
  1476. {
  1477. OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[OutBoxLabelRowIndex].Cells["pib_datecode"].Value.ToString();
  1478. }
  1479. else
  1480. {
  1481. ExeSQL = sql.Substring(0, sql.IndexOf("{")) + pib_id + sql.Substring(sql.IndexOf("}") + 1);
  1482. ExeSQL = ExeSQL.Substring(0, ExeSQL.IndexOf("{")) + "'" + pib_outboxcode2 + "'";
  1483. OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(ExeSQL).ToString();
  1484. }
  1485. LogManager.DoLog("打印参数【" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + ExeSQL + ",取到值" + OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value);
  1486. }
  1487. catch (Exception)
  1488. {
  1489. LogManager.DoLog("SQL维护不正确,请检查SQL语句" + sql);
  1490. BaseUtil.ShowError("SQL维护不正确,请检查SQL语句\n" + sql);
  1491. }
  1492. }
  1493. }
  1494. else if (OutBoxDoc.Variables.FreeVariables.Item(j + 1).Name == "DateCode1")
  1495. {
  1496. if (LabelInf.Rows[OutBoxLabelRowIndex].Cells["DateCode1"].Value != null)
  1497. {
  1498. OutBoxDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[OutBoxLabelRowIndex].Cells["DateCode1"].Value.ToString();
  1499. }
  1500. }
  1501. }
  1502. }
  1503. //保存参数打印
  1504. OutBoxDoc.Save();
  1505. OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
  1506. OutBoxDoc.PrintDocument();
  1507. LogManager.DoLog("执行打印外箱,pib_id:" + LabelInf.Rows[OutBoxLabelRowIndex].Cells["pib_id1"].Value.ToString() + ",标签地址" + LabelUrl);
  1508. OutBoxDoc.Close();
  1509. LogManager.DoLog("打印文件" + OutBoxDoc.Name + "关闭");
  1510. }
  1511. else
  1512. {
  1513. BaseUtil.ShowError("该出入库单未找到该外箱号!");
  1514. }
  1515. }
  1516. catch (Exception)
  1517. {
  1518. OutBoxDoc.Close();
  1519. LogManager.DoLog("打印文件" + OutBoxDoc.Name + "关闭");
  1520. }
  1521. }
  1522. Outboxcode.Clear();
  1523. }
  1524. private void CleanDetail_Click(object sender, EventArgs e)
  1525. {
  1526. ArrayList<string> DeleteID = new ArrayList<string>();
  1527. for (int i = 0; i < LabelInf.RowCount; i++)
  1528. {
  1529. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  1530. {
  1531. DeleteID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1532. }
  1533. }
  1534. //勾选了删除的明细之后
  1535. if (DeleteID.ToArray().Length > 0)
  1536. {
  1537. string close = MessageBox.Show(this.ParentForm, "删除后不可恢复,是否确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1538. if (close.ToString() == "Yes")
  1539. {
  1540. dh.BatchInsert("delete from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray());
  1541. MessageBox.Show("删除成功");
  1542. LoadGridData(sender, e);
  1543. RefreshProcessData();
  1544. }
  1545. }
  1546. else
  1547. {
  1548. MessageBox.Show("尚未勾选需要删除的明细");
  1549. }
  1550. }
  1551. private void OutBoxLabelPrint_Click(object sender, EventArgs e)
  1552. {
  1553. thread = new Thread(OutBoxPrint);
  1554. stw = new SetLoadingWindow(thread, "正在打印外箱");
  1555. BaseUtil.SetFormCenter(stw);
  1556. stw.ShowDialog();
  1557. }
  1558. /// <summary>
  1559. /// 刷新采集进度
  1560. /// </summary>
  1561. private void RefreshProcessData()
  1562. {
  1563. if (LabelInf.Rows.Count > 0)
  1564. {
  1565. //设置初始化的采集进度
  1566. int Count = 0;
  1567. int CurrentMidBoxCollectedCount = 0;
  1568. //当前盒号的总盘数
  1569. int CurrentMidBoxTotalCount = 0;
  1570. //未超出当前范围的时候
  1571. for (int i = 0; i < LabelInf.RowCount; i++)
  1572. {
  1573. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
  1574. {
  1575. Count++;
  1576. }
  1577. //和当前编辑箱号相等行
  1578. 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())
  1579. {
  1580. CurrentMidBoxCollectedCount++;
  1581. }
  1582. //当前盒号一共有几盘
  1583. if (LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1584. {
  1585. CurrentMidBoxTotalCount++;
  1586. }
  1587. }
  1588. Capacity.Text = "可装" + CurrentMidBoxTotalCount.ToString() + "盘";
  1589. Installed.Text = "已装" + CurrentMidBoxCollectedCount.ToString() + "盘";
  1590. //设置当前的箱号和盒号
  1591. Process_outboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value.ToString();
  1592. Process_midboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  1593. //设置当前总数和已采集数量
  1594. TotalCount.Text = LabelInf.RowCount.ToString();
  1595. CollectedCount.Text = Count.ToString();
  1596. }
  1597. }
  1598. /// <summary>
  1599. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  1600. /// </summary>
  1601. /// <param name="sender"></param>
  1602. /// <param name="e"></param>
  1603. private void LoadGridData(object sender, EventArgs e)
  1604. {
  1605. //如果是富为则使用特殊的查询语句
  1606. if (DataHelper.DBConnectionString.Contains("richwell") || DataHelper.DBConnectionString.Contains("192.168.0.88"))
  1607. {
  1608. sql.Clear();
  1609. sql.Append("select pd_pocode,pd_inoutno,pib_id,pib_pdid,pib_piid,pib_pdno,pib_prodcode,pr_brand,pr_vendprodcode,");
  1610. sql.Append("pib_lotno,pib_datecode,pib_qty,pib_barcode,pib_outboxcode1,pib_outboxcode2,pib_ifpick,pib_ifprint,");
  1611. sql.Append("pr_spec,pd_prodcode,pd_pocode from prodiobarcode left join prodiodetail on pib_piid=pd_piid and pd_pdno=pib_pdno ");
  1612. sql.Append("and pd_prodcode=pib_prodcode left join product on pr_code=pib_prodcode left join (select pd_prodcode ");
  1613. sql.Append("prcode,pd_pocode pocode,max(pd_detno) pd_detno from prodinout left join packing on packing.pi_code=prodinout.pi_packingcode ");
  1614. sql.Append("left join packingdetail on packing.pi_id=pd_piid where prodinout.pi_id='" + PI_ID + "' group by pd_prodcode,pd_pocode");
  1615. sql.Append(")A on pd_pocode=A.pocode and pd_prodcode=A.PRCODE where pd_piid='" + PI_ID + "' order by a.pd_detno,pib_id");
  1616. GetOutBoxCode.Visible = true;
  1617. }
  1618. else
  1619. {
  1620. sql.Clear();
  1621. sql.Append("select pd_pocode,pib_id,pib_pdid,pib_piid,pib_pdno,pib_prodcode,pr_brand,pr_vendprodcode,");
  1622. sql.Append("pib_lotno,pib_datecode,pib_qty,pib_barcode,pib_outboxcode1,pib_outboxcode2,pib_ifpick,pib_ifprint");
  1623. sql.Append(",sa_pocode from prodiobarcode left join prodiodetail on pib_piid=pd_piid and pd_pdno=pib_pdno and ");
  1624. sql.Append(" pd_prodcode=pib_prodcode left join product on pr_code=pib_prodcode left join sale on sa_code=pib_ordercode ");
  1625. sql.Append("where pd_piid='" + PI_ID + "' order by pr_spec,pd_prodcode,pib_id");
  1626. }
  1627. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1628. BaseUtil.FillDgvWithDataTable(LabelInf, dt);
  1629. //有数据的话默认取第一条的品牌去取采集策略
  1630. TotalCount.Text = LabelInf.RowCount.ToString();
  1631. if (LabelInf.RowCount > 0)
  1632. {
  1633. Brand = LabelInf.Rows[0].Cells["pr_brand"].FormattedValue.ToString();
  1634. if (Brand != "")
  1635. sg_code.Text = dh.getFieldDataByCondition("scangroup", "sg_code", "sg_brand='" + Brand + "'").ToString();
  1636. }
  1637. //绑定数据之后往下找到未采集的数据显示在当前采集的栏目
  1638. for (int i = 0; i < LabelInf.RowCount; i++)
  1639. {
  1640. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1641. {
  1642. griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
  1643. pr_code.Text = LabelInf.Rows[i].Cells["pib_prodcode"].FormattedValue.ToString();
  1644. pib_id.Text = LabelInf.Rows[i].Cells["pib_id1"].FormattedValue.ToString();
  1645. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
  1646. break;
  1647. }
  1648. }
  1649. }
  1650. /// <summary>
  1651. /// 重绘Cell的颜色
  1652. /// </summary>
  1653. /// <param name="sender"></param>
  1654. /// <param name="e"></param>
  1655. private void LabelInf_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  1656. {
  1657. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  1658. if (e.ColumnIndex > 0)
  1659. {
  1660. 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")
  1661. {
  1662. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1663. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  1664. Rectangle border = e.CellBounds;
  1665. border.Width -= 1;
  1666. e.Graphics.DrawRectangle(Pens.White, border);
  1667. e.PaintContent(e.CellBounds);
  1668. e.Handled = true;
  1669. }
  1670. if (e.RowIndex >= 0)
  1671. {
  1672. //重绘制定的Cell,表示采集的数量不匹配
  1673. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_qty" && PaintCell.ContainsKey(LabelInf.Rows[e.RowIndex].Cells["pib_qty"]))
  1674. {
  1675. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1676. e.Graphics.FillRectangle(PaintCell[LabelInf.Rows[e.RowIndex].Cells["pib_qty"]] ? Brushes.ForestGreen : Brushes.Red, e.CellBounds);
  1677. Rectangle border = e.CellBounds;
  1678. border.Width -= 1;
  1679. e.Graphics.DrawRectangle(Pens.Black, border);
  1680. e.PaintContent(e.CellBounds);
  1681. e.Handled = true;
  1682. }
  1683. //表示采集的供应商物料编号不匹配
  1684. if (LabelInf.Columns[e.ColumnIndex].Name == "pr_vendprodcode" && PaintCell.ContainsKey(LabelInf.Rows[e.RowIndex].Cells["pr_vendprodcode"]))
  1685. {
  1686. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1687. e.Graphics.FillRectangle(PaintCell[LabelInf.Rows[e.RowIndex].Cells["pr_vendprodcode"]] ? Brushes.ForestGreen : Brushes.Red, e.CellBounds);
  1688. Rectangle border = e.CellBounds;
  1689. border.Width -= 1;
  1690. e.Graphics.DrawRectangle(Pens.Black, border);
  1691. e.PaintContent(e.CellBounds);
  1692. e.Handled = true;
  1693. }
  1694. }
  1695. }
  1696. }
  1697. private void pr_code_SearchIconClick(object sender, EventArgs e)
  1698. {
  1699. pr_code.Condition = " pd_inoutno='" + pi_inoutno.Text + "'";
  1700. }
  1701. private void OutBoxLabelPackage_Click(object sender, EventArgs e)
  1702. {
  1703. MaxOutBoxCode = MaxOutBoxCode + 1;
  1704. }
  1705. private void pr_code_UserControlTextChanged(object sender, EventArgs e)
  1706. {
  1707. //用户在重新勾选后重置采集项目的索引
  1708. CurrentItemIndex = 0;
  1709. for (int i = 0; i < LabelInf.RowCount; i++)
  1710. {
  1711. if (pr_code.Text == LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1712. {
  1713. CurrentRowIndex = i;
  1714. break;
  1715. }
  1716. }
  1717. }
  1718. private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1719. {
  1720. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  1721. pi_inoutno_KeyDown(sender, e2);
  1722. }
  1723. /// <summary>
  1724. /// 采集明细切换
  1725. /// </summary>
  1726. /// <param name="sender"></param>
  1727. /// <param name="e"></param>
  1728. private void griddetno_KeyDown(object sender, KeyEventArgs e)
  1729. {
  1730. if (Keys.Enter == e.KeyData)
  1731. {
  1732. bool FindDetno = false;
  1733. for (int i = 0; i < LabelInf.RowCount; i++)
  1734. {
  1735. if (LabelInf.Rows[i].Cells["pib_pdno"].Value.ToString() == griddetno.Text && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1736. {
  1737. FindDetno = true;
  1738. CurrentItemIndex = 0;
  1739. CurrentRowIndex = i;
  1740. RemindUser();
  1741. break;
  1742. }
  1743. }
  1744. if (!FindDetno)
  1745. {
  1746. BaseUtil.ShowError("不存在未采集的明细序号" + griddetno.Text);
  1747. }
  1748. }
  1749. }
  1750. private void AutoPrintMidLabel()
  1751. {
  1752. bool FullBox = true;
  1753. //判断所有盒号未该盒的是否勾选已采集
  1754. for (int i = 0; i < LabelInf.RowCount; i++)
  1755. {
  1756. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  1757. {
  1758. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1759. {
  1760. FullBox = false;
  1761. }
  1762. }
  1763. }
  1764. //如果当前箱号已经装满了
  1765. if (FullBox)
  1766. {
  1767. if (MidLabelCombox.SelectedValue != null)
  1768. {
  1769. try
  1770. {
  1771. string la_id = MidLabelCombox.SelectedValue.ToString();
  1772. string cl_labelname = MidLabelCombox.Text;
  1773. 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();
  1774. MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(LabelUrl, cl_labelname));
  1775. 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");
  1776. for (int j = 0; j < MidDoc.Variables.FreeVariables.Count; j++)
  1777. {
  1778. //将维护的模板参数和模板本身的参数名称进行比对
  1779. for (int k = 0; k < dt.Rows.Count; k++)
  1780. {
  1781. //名称相等的时候,取SQL进行值的查询
  1782. if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == dt.Rows[k]["lp_name"].ToString())
  1783. {
  1784. //获取对应行的pib_id
  1785. string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
  1786. string pib_outboxcode1 = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  1787. //获取打印执行的SQL
  1788. string sql = dt.Rows[k]["lp_sql"].ToString();
  1789. //select * from productiobarcode where pib_id={pib_id} and pib_outboxcode1={pib_outboxcode1}
  1790. try
  1791. {
  1792. string ExeSQL = "";
  1793. if (sql.Contains("pib_lotno"))
  1794. {
  1795. MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString();
  1796. }
  1797. else if (sql.Contains("pib_datecode"))
  1798. {
  1799. MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString();
  1800. }
  1801. else
  1802. {
  1803. ExeSQL = sql.Substring(0, sql.IndexOf("{")) + pib_id + sql.Substring(sql.IndexOf("}") + 1);
  1804. ExeSQL = ExeSQL.Substring(0, ExeSQL.IndexOf("{")) + pib_outboxcode1;
  1805. MidDoc.Variables.FreeVariables.Item(j + 1).Value = dh.GetLabelParam(ExeSQL).ToString();
  1806. }
  1807. LogManager.DoLog("打印参数【" + MidDoc.Variables.FreeVariables.Item(j + 1).Name + "】赋值," + "取值SQL:" + ExeSQL + ",取到值" + MidDoc.Variables.FreeVariables.Item(j + 1).Value);
  1808. }
  1809. catch (Exception)
  1810. {
  1811. BaseUtil.ShowError("SQL维护不正确,请检查SQL语句");
  1812. }
  1813. }
  1814. else if (MidDoc.Variables.FreeVariables.Item(j + 1).Name == "DateCode1")
  1815. {
  1816. if (LabelInf.Rows[CurrentRowIndex].Cells["DateCode1"].Value != null)
  1817. {
  1818. MidDoc.Variables.FreeVariables.Item(j + 1).Value = LabelInf.Rows[CurrentRowIndex].Cells["DateCode1"].Value.ToString();
  1819. }
  1820. }
  1821. }
  1822. }
  1823. //保存参数打印
  1824. MidDoc.Save();
  1825. MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
  1826. MidDoc.PrintDocument();
  1827. LogManager.DoLog("执行打印中盒,pib_id:" + LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString());
  1828. MidDoc.Close();
  1829. LogManager.DoLog("打印文件" + MidDoc.Name + "关闭");
  1830. }
  1831. catch (Exception)
  1832. {
  1833. MidDoc.Close();
  1834. }
  1835. }
  1836. else
  1837. {
  1838. MessageBox.Show("未维护中盒模板");
  1839. }
  1840. }
  1841. }
  1842. private void LoginOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1843. {
  1844. Login login = new Login();
  1845. logout = true;
  1846. Hide();
  1847. login.ShowDialog();
  1848. Close();
  1849. }
  1850. /// <summary>
  1851. /// 勾选的时候自动打印
  1852. /// </summary>
  1853. /// <param name="sender"></param>
  1854. /// <param name="e"></param>
  1855. private void LabelInf_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  1856. {
  1857. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
  1858. {
  1859. string datecode = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString();
  1860. try
  1861. {
  1862. System.DateTime dt = System.DateTime.ParseExact(datecode, "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture);
  1863. GregorianCalendar gc = new GregorianCalendar();
  1864. int weekOfYear = gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
  1865. if (weekOfYear < 10)
  1866. {
  1867. LabelInf.Rows[CurrentRowIndex].Cells["DateCode1"].Value = dt.Year.ToString().Substring(2, 2) + "0" + weekOfYear;
  1868. }
  1869. else
  1870. {
  1871. LabelInf.Rows[CurrentRowIndex].Cells["DateCode1"].Value = dt.Year.ToString().Substring(2, 2) + weekOfYear;
  1872. }
  1873. }
  1874. catch (Exception ex)
  1875. {
  1876. Console.WriteLine(ex.Message);
  1877. }
  1878. }
  1879. }
  1880. private void AllCollected_Click(object sender, EventArgs e)
  1881. {
  1882. if (AllCollect == false)
  1883. {
  1884. for (int i = 0; i < LabelInf.RowCount; i++)
  1885. {
  1886. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "False")
  1887. {
  1888. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  1889. AllCollect = true;
  1890. CurrentRowIndex = i;
  1891. }
  1892. }
  1893. }
  1894. else
  1895. {
  1896. for (int i = 0; i < LabelInf.RowCount; i++)
  1897. {
  1898. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
  1899. {
  1900. LabelInf.Rows[i].Cells["pib_ifpick"].Value = false;
  1901. AllCollect = false;
  1902. }
  1903. }
  1904. }
  1905. }
  1906. private void PowerSetting_Click(object sender, EventArgs e)
  1907. {
  1908. PowerSetting pw = new PowerSetting();
  1909. BaseUtil.SetFormCenter(pw);
  1910. pw.ShowDialog();
  1911. }
  1912. private void GetOutBoxCode_Click(object sender, EventArgs e)
  1913. {
  1914. int Current = 0;
  1915. sql.Clear();
  1916. sql.Append("select pd_qty,pd_cartonno,pr_zxbzs,pd_cartons from packingdetail left join packing on pd_piid=pi_id left join prodinout on ");
  1917. sql.Append("pi_packingcode=packing.pi_code left join product on pd_prodcode=pr_code where pi_inoutno='" + pi_inoutno.Text + "' order by pd_detno");
  1918. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1919. for (int i = 0; i < dt.Rows.Count; i++)
  1920. {
  1921. int pd_qty = int.Parse(dt.Rows[i]["pd_qty"].ToString());
  1922. int pr_zxbzs = int.Parse(dt.Rows[i]["pr_zxbzs"].ToString());
  1923. int pd_cartons = int.Parse(dt.Rows[i]["pd_cartons"].ToString());
  1924. for (int j = 0; j < pd_qty * pd_cartons / pr_zxbzs; j++)
  1925. {
  1926. LabelInf.Rows[Current].Cells["pib_outboxcode2"].Value = dt.Rows[i]["pd_cartonno"].ToString();
  1927. Current++;
  1928. }
  1929. }
  1930. SaveGrid_Click(sender, e);
  1931. }
  1932. private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1933. {
  1934. string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1935. if (close.ToString() == "Yes")
  1936. {
  1937. Login login = new Login();
  1938. //注销的时候需要将拼接的连接字符串置空
  1939. DataHelper.DBConnectionString = null;
  1940. this.Hide();
  1941. login.ShowDialog();
  1942. this.Close();
  1943. }
  1944. }
  1945. private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e)
  1946. {
  1947. }
  1948. }
  1949. }