UAS_出货标签管理.cs 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643
  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.Diagnostics;
  9. using LabelManager2;
  10. using UAS_LabelMachine.PublicMethod;
  11. using UAS_LabelMachine.Entity;
  12. using UAS_LabelMachine.PublicForm;
  13. using System.Threading;
  14. using System.IO;
  15. using System.Globalization;
  16. using FastReport;
  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. /// <summary>
  27. /// 单盘打印文件
  28. /// </summary>
  29. Report SingleReport = new Report();
  30. /// <summary>
  31. /// 中盒打印文件
  32. /// </summary>
  33. Report MidReport = new Report();
  34. /// <summary>
  35. /// 外箱打印文件
  36. /// </summary>
  37. Report OutReport = new Report();
  38. /// <summary>
  39. /// 唛头文件打印
  40. /// </summary>
  41. Report FootReport = new Report();
  42. /// <summary>
  43. /// Loading窗口
  44. /// </summary>
  45. SetLoadingWindow stw;
  46. /// <summary>
  47. /// 弹窗线程
  48. /// </summary>
  49. Thread thread;
  50. /// <summary>
  51. /// 当前品牌
  52. /// </summary>
  53. string PI_ID;
  54. bool logout = false;
  55. //主表数据源
  56. DataTable LabelInfDataTable;
  57. /// <summary>
  58. /// 存放单盘的ID
  59. /// </summary>
  60. List<string> SingleID = new List<string>();
  61. /// <summary>
  62. /// 是否全选
  63. /// </summary>
  64. bool AllChecked = false;
  65. /// <summary>
  66. /// 是否通过选择Combox来改变打开的文件
  67. /// </summary>
  68. bool ComBoxClickChangeLabelDoc = false;
  69. //当前采集的物料编号
  70. string CurrentPrCode = "";
  71. //当前采集的最小包装
  72. string CurrentZXBZ = "";
  73. //当前采集的单位
  74. string CurrentUnit = "";
  75. //当前采集的总数
  76. string CurrentPrCount = "";
  77. //当前明细序号
  78. string CurrentPDNO = "";
  79. //当前的物料品牌
  80. string CurrentBrand = "";
  81. string Prefix = "";
  82. string Suffix = "";
  83. int MaxNum = 0;
  84. int NumLength = 0;
  85. int Radix = 0;
  86. private bool EnablePrint = true;
  87. string[] PIBID;
  88. DataTable Attach;
  89. public UAS_出货标签打印(string Master)
  90. {
  91. InitializeComponent();
  92. Text = Text + "-" + Master;
  93. }
  94. protected override void WndProc(ref Message m)
  95. {
  96. //拦截双击标题栏、移动窗体的系统消息
  97. if (m.Msg != 0xA3)
  98. {
  99. base.WndProc(ref m);
  100. }
  101. }
  102. private void 贴标机条码打印_Load(object sender, EventArgs e)
  103. {
  104. //用计时器重置数据库链接
  105. LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
  106. dh = SystemInf.dh;
  107. CheckForIllegalCrossThreadCalls = false;
  108. pi_inoutno.Focus();
  109. Point pt = new Point();
  110. //禁止所有列的排序
  111. foreach (DataGridViewColumn dgv in LabelInf.Columns)
  112. {
  113. dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
  114. }
  115. int ScreenWidth = Screen.GetWorkingArea(pt).Width;
  116. //设置获取当前屏幕大小自动全屏但是保留任务栏
  117. Rectangle ScreenArea = Screen.GetWorkingArea(this);
  118. Top = 0;
  119. Left = 0;
  120. Width = ScreenArea.Width;
  121. Height = ScreenArea.Height;
  122. OutboxCapacity.Value = Properties.Settings.Default.OutboxCapacity;
  123. MidboxCapacity.Value = Properties.Settings.Default.MidBoxCapacity;
  124. DCCheck.Text = Properties.Settings.Default.DCCheck.ToString();
  125. OutBoxPrinter.Text = Properties.Settings.Default.OPrinter;
  126. MidLabelPrinter.Text = Properties.Settings.Default.MPrinter;
  127. SingleLabelPrinter.Text = Properties.Settings.Default.SPrinter;
  128. asc.controllInitializeSize(this);
  129. asc.controlAutoSize(this);
  130. RefreshDBConnect.Interval = 60000;
  131. RefreshDBConnect.Start();
  132. }
  133. //只执行一次窗体自适应
  134. bool AutoSized = false;
  135. private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
  136. {
  137. if (!AutoSized)
  138. {
  139. asc.controlAutoSize(this);
  140. AutoSized = true;
  141. }
  142. }
  143. private void LabelMaintain_Click(object sender, EventArgs e)
  144. {
  145. 客户标签维护 form = new 客户标签维护();
  146. BaseUtil.SetFormCenter(form);
  147. form.FormClosed += LabelFormClose;
  148. form.ShowDialog();
  149. }
  150. private void LabelFormClose(object sender, EventArgs e)
  151. {
  152. if (GetGridOnly.Checked)
  153. GetInOutInfAndLabelFile();
  154. else
  155. {
  156. GetGridOnly.Checked = true;
  157. GetInOutInfAndLabelFile();
  158. GetGridOnly.Checked = false;
  159. }
  160. }
  161. //输入框Enter事件
  162. private void Input_KeyDown(object sender, KeyEventArgs e)
  163. {
  164. if (e.KeyCode == Keys.Enter)
  165. {
  166. if (Input.Text == "")
  167. {
  168. MessageBox.Show("采集的数据不能为空");
  169. return;
  170. }
  171. CollectInputData();
  172. }
  173. }
  174. /// <summary>
  175. /// 采集数据
  176. /// </summary>
  177. private void CollectInputData()
  178. {
  179. if (Input.Text == "SC")
  180. {
  181. PrintStatus.PerformClick();
  182. Input.Text = "";
  183. return;
  184. }
  185. Dictionary<string, string> Data = new Dictionary<string, string>();
  186. string[] SplitData = Input.Text.Split('*');
  187. if (SplitData.Length < 6)
  188. {
  189. MessageBox.Show("数据格式错误,无法解析", "提示");
  190. Input.SelectAll();
  191. return;
  192. }
  193. for (int i = 0; i < SplitData.Length; i++)
  194. {
  195. switch (i.ToString())
  196. {
  197. case "0":
  198. Data.Add("PRCODE", SplitData[i]);
  199. break;
  200. case "1":
  201. Data.Add("QTY", SplitData[i]);
  202. break;
  203. case "2":
  204. Data.Add("DATECODE", SplitData[i]);
  205. break;
  206. case "3":
  207. Data.Add("BRAND", SplitData[i]);
  208. break;
  209. case "4":
  210. Data.Add("LOTNO", SplitData[i]);
  211. break;
  212. case "5":
  213. Data.Add("PO", SplitData[i]);
  214. break;
  215. case "6":
  216. Data.Add("SERIAL", SplitData[i]);
  217. break;
  218. default:
  219. break;
  220. }
  221. }
  222. //校验DateCode是否过期
  223. if (!CheckDateCode(Data["DATECODE"]))
  224. {
  225. MessageBox.Show("物料" + Data["PRCODE"] + "【DateCode】超出校验日期");
  226. Input.SelectAll();
  227. return;
  228. }
  229. if (Data["PRCODE"] != CurrentPrCode)
  230. {
  231. MessageBox.Show("当前采集【物料编号】不对应,请重新采集", "提示");
  232. Input.SelectAll();
  233. return;
  234. }
  235. if (Data["BRAND"] != CurrentBrand)
  236. {
  237. MessageBox.Show("当前采集【品牌】不对应,请重新采集", "提示");
  238. Input.SelectAll();
  239. return;
  240. }
  241. int CodeCount = 0;
  242. //如果单位是KPCS则需要除1000
  243. int CollectNum = 0;
  244. if (CurrentUnit == "KPCS")
  245. {
  246. //如果单位是KPCS则必须是1000的整数倍
  247. if (int.Parse(Data["QTY"]) % 1000 != 0 || int.Parse(Data["QTY"]) / 1000 % int.Parse(CurrentZXBZ) != 0)
  248. {
  249. MessageBox.Show("物料" + Data["PRCODE"] + "采集数量无法按照最小包装数拆分", "提示");
  250. Input.SelectAll();
  251. return;
  252. }
  253. CodeCount = int.Parse(Data["QTY"]) / 1000 / int.Parse(CurrentZXBZ);
  254. CollectNum = int.Parse(Data["QTY"]) / 1000;
  255. }
  256. else
  257. {
  258. if (int.Parse(Data["QTY"]) % int.Parse(CurrentZXBZ) != 0)
  259. {
  260. MessageBox.Show("采集【数量】无法按照最小包装数拆分", "提示");
  261. Input.SelectAll();
  262. return;
  263. }
  264. CodeCount = int.Parse(Data["QTY"]) / int.Parse(CurrentZXBZ);
  265. CollectNum = int.Parse(Data["QTY"]);
  266. }
  267. string pib_barcode = Data.ContainsKey("SERIAL") ? Data["SERIAL"] : "";
  268. //获取ID
  269. PIBID = dh.GetSEQ("prodiobarcode_seq", CodeCount);
  270. string pib_outboxcode2 = "";
  271. if (OutBoxNum.Text == "新增")
  272. {
  273. string maxoutbox = dh.getFieldDataByCondition("prodiobarcode", "max(pib_outboxcode2)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  274. //如果没有则从开始插入
  275. if (maxoutbox == "")
  276. {
  277. pib_outboxcode2 = "1";
  278. }
  279. else
  280. {
  281. pib_outboxcode2 = (int.Parse(maxoutbox) + 1).ToString();
  282. }
  283. }
  284. else
  285. {
  286. pib_outboxcode2 = OutBoxNum.Text;
  287. }
  288. //计算当前采集数量
  289. string collectqty = (LabelInfDataTable.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  290. int CollectQty = (collectqty == "" ? 0 : int.Parse(collectqty));
  291. if (CollectQty + CollectNum > int.Parse(CurrentPrCount))
  292. {
  293. MessageBox.Show("物料" + Data["PRCODE"] + "采集后数量为" + (CollectQty + CollectNum) + ",【超出】本行出货数量" + CurrentPrCount, "提示");
  294. Input.SelectAll();
  295. return;
  296. }
  297. List<string> CustBarCode = new List<string>();
  298. if (!(Radix > 0))
  299. {
  300. string close = MessageBox.Show(this.ParentForm, "未维护条码规则,是否继续生成", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  301. if (close.ToString() != "Yes")
  302. return;
  303. }
  304. for (int i = 0; i < CodeCount; i++)
  305. {
  306. if (Radix > 0)
  307. {
  308. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  309. for (int j = serialcode.ToString().Length; j < NumLength; j++)
  310. {
  311. serialcode = "0" + serialcode;
  312. }
  313. CustBarCode.Add(Prefix + serialcode + Suffix);
  314. MaxNum = MaxNum + 1;
  315. }
  316. else
  317. {
  318. CustBarCode.Add("");
  319. }
  320. }
  321. sql.Clear();
  322. sql.Append("insert into prodiobarcode(PIB_ID,PIB_PRODCODE,PIB_INDATE,PIB_INOUTNO,PIB_PIID,PIB_PDNO, PIB_PDID,PIB_PICLASS,");
  323. sql.Append("PIB_BARCODE,PIB_CUSTBARCODE,PIB_QTY,pib_brand,pib_datecode,pib_lotno,PIB_OUTBOXCODE2,pib_inman,PIB_IFPRINT,PIB_ORDERCODE,PIB_CUSTPO,pib_remark) ");
  324. sql.Append("select :PIB_ID,pd_prodcode,sysdate,pi_inoutno,pi_id,pd_pdno,pd_id,pi_class,");
  325. sql.Append("'" + pib_barcode + "',:PIB_CUSTBARCODE,'" + CurrentZXBZ + "',pjd_brand,'" + Data["DATECODE"] + "','" + Data["LOTNO"] + "','" + pib_outboxcode2 + "','" + User.UserCode + "','" + (EnablePrint && SingleLabelAutoPrint.Checked ? 1 : 0).ToString() + "',pd_ordercode,pd_pocode,pd_remark ");
  326. sql.Append("from prodinout left join prodiodetail on pi_id=pd_piid left join PRODJOINVENDDETAIL on pjd_brand =pd_brand and pjd_prodcode=pd_prodcode where pi_id='" + PI_ID + "' and pd_prodcode='" + CurrentPrCode + "' and pd_pdno='" + CurrentPDNO + "'");
  327. dh.BatchInsert(sql.ToString(), new string[] { "PIB_ID", "PIB_CUSTBARCODE" }, PIBID, CustBarCode.ToArray());
  328. //更新流水号
  329. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum) + "'", "rmn_nrcode='" + pi_cardcode.Text + "' and rmn_prefix='" + Prefix + "'");
  330. LoadGridData(new object(), new EventArgs());
  331. //加载完数据之后进行容量的判断
  332. int BoxNum = LabelInfDataTable.Select("pib_outboxcode2='" + OutBoxNum.Text + "'").Length;
  333. if (BoxNum > OutboxCapacity.Value)
  334. {
  335. MessageBox.Show("箱号【" + OutBoxNum.Text + "】超出容量,当前已采集" + BoxNum, "提示");
  336. }
  337. if (SingleLabelAutoPrint.Checked)
  338. {
  339. thread = new Thread(AutoPrintSingleLabel);
  340. stw = new SetLoadingWindow(thread, "正在打印单盘标签");
  341. BaseUtil.SetFormCenter(stw);
  342. stw.ShowDialog();
  343. }
  344. //采集后重新计数,自动跳到下一行
  345. collectqty = (LabelInfDataTable.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  346. CollectQty = (collectqty == "" ? 0 : int.Parse(collectqty));
  347. //采集达到了数量进行换行
  348. if (CollectQty == int.Parse(CurrentPrCount))
  349. {
  350. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  351. {
  352. string outqty = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  353. string collectnum = GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString();
  354. //采集之前的行,如后续行有物料编号相同的并且编号较大的跳到这样
  355. if (GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString() == CurrentPrCode && int.Parse(outqty) > int.Parse(collectnum == "" ? "0" : collectnum))
  356. {
  357. if (int.Parse(GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString()) > int.Parse(CurrentPDNO))
  358. {
  359. GridPrcode.Rows[i].Selected = true;
  360. return;
  361. }
  362. }
  363. }
  364. for (int i = GridPrcode.Rows.Count - 1; i >= 0; i--)
  365. {
  366. string outqty = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  367. string collectnum = GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString();
  368. if (int.Parse(outqty) > int.Parse(collectnum == "" ? "0" : collectnum))
  369. {
  370. GridPrcode.Rows[i].Selected = true;
  371. }
  372. }
  373. }
  374. Input.Clear();
  375. OutBoxNum_Click(new object(), new EventArgs());
  376. }
  377. private void AutoPrintSingleLabel()
  378. {
  379. if (EnablePrint)
  380. {
  381. //用标签本身的变量作为最外层的循环条件去匹配;
  382. StringBuilder ParamLog = new StringBuilder();
  383. string pibid = "";
  384. for (int i = 0; i < PIBID.Length; i++)
  385. {
  386. if (i != PIBID.Length - 1)
  387. pibid += PIBID[i] + ",";
  388. else
  389. pibid += PIBID[i];
  390. }
  391. for (int j = 0; j < SingleReport.Parameters.Count; j++)
  392. {
  393. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, "");
  394. for (int k = 0; k < Attach.Rows.Count; k++)
  395. {
  396. if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name)
  397. {
  398. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  399. }
  400. }
  401. }
  402. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiosingleinfo_view where 主键ID in (" + pibid + ")", "select");
  403. SingleReport.RegisterData(dt, "prodiosingleinfo_view");
  404. SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true;
  405. SingleReport.PrintSettings.ShowDialog = false;
  406. SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  407. try
  408. {
  409. SingleReport.Print();
  410. }
  411. catch (Exception e)
  412. {
  413. MessageBox.Show(e.Message);
  414. return;
  415. }
  416. Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text;
  417. Properties.Settings.Default.Save();
  418. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "自动打印箱标", "打印成功");
  419. }
  420. }
  421. //关闭窗口前提示用户确认
  422. private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
  423. {
  424. //如果不是注销的话
  425. if (!logout)
  426. {
  427. string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  428. if (close.ToString() != "Yes")
  429. e.Cancel = true;
  430. else
  431. {
  432. LogManager.DoLog("关闭程序");
  433. }
  434. }
  435. }
  436. /// <summary>
  437. /// 获取打印标签
  438. /// </summary>
  439. private void GetInOutInfAndLabelFile()
  440. {
  441. ComBoxClickChangeLabelDoc = false;
  442. sql.Clear();
  443. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  444. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  445. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='单盘' order by cl_custcode,cl_date desc");
  446. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  447. SingleLabelCombox.DisplayMember = "cl_labelname";
  448. SingleLabelCombox.ValueMember = "la_id";
  449. SingleLabelCombox.DataSource = dt;
  450. if (!GetGridOnly.Checked)
  451. for (int i = 0; i < dt.Rows.Count; i++)
  452. {
  453. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  454. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  455. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  456. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  457. if (time.ToString() != file.LastWriteTime.ToString())
  458. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  459. }
  460. if (SingleLabelCombox.Text != "")
  461. {
  462. SingleReport.Load(ftpOperater.DownLoadTo + SingleLabelCombox.Text);
  463. }
  464. sql.Clear();
  465. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  466. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  467. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='中盒' order by cl_custcode,cl_date desc");
  468. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  469. MidLabelCombox.DisplayMember = "cl_labelname";
  470. MidLabelCombox.ValueMember = "la_id";
  471. MidLabelCombox.DataSource = dt;
  472. if (!GetGridOnly.Checked)
  473. for (int i = 0; i < dt.Rows.Count; i++)
  474. {
  475. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  476. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  477. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  478. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  479. if (time.ToString() != file.LastWriteTime.ToString())
  480. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  481. }
  482. if (MidLabelCombox.Text != "")
  483. {
  484. MidReport.Load(ftpOperater.DownLoadTo + MidLabelCombox.Text);
  485. }
  486. //缓存中盒参数
  487. sql.Clear();
  488. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  489. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  490. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='外箱' order by cl_custcode,cl_date desc");
  491. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  492. OutBoxCombox.DisplayMember = "cl_labelname";
  493. OutBoxCombox.ValueMember = "la_id";
  494. OutBoxCombox.DataSource = dt;
  495. if (!GetGridOnly.Checked)
  496. for (int i = 0; i < dt.Rows.Count; i++)
  497. {
  498. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  499. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  500. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  501. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  502. if (time.ToString() != file.LastWriteTime.ToString())
  503. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  504. }
  505. if (OutBoxCombox.Text != "")
  506. {
  507. OutReport.Load(ftpOperater.DownLoadTo + OutBoxCombox.Text);
  508. }
  509. BaseUtil.GetLabelUrl(DataHelper.FTPAdress, "唛头.frx", System.DateTime.Now);
  510. FootReport.Load(ftpOperater.DownLoadTo + "唛头.frx");
  511. //缓存外箱参数
  512. ComBoxClickChangeLabelDoc = true;
  513. }
  514. /// <summary>
  515. /// 出入库单录入框的回车事件
  516. /// </summary>
  517. /// <param name="sender"></param>
  518. /// <param name="e"></param>
  519. private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
  520. {
  521. if (e.KeyCode == Keys.Enter)
  522. {
  523. Input.Clear();
  524. sql.Clear();
  525. sql.Append("select pi_id,pi_cardcode,to_char(pi_date,'yyyymmdd')pi_date from prodinout where pi_inoutno='" + pi_inoutno.Text + "' and pi_invostatuscode='AUDITED'");
  526. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  527. if (dt.Rows.Count > 0)
  528. {
  529. pi_cardcode.Text = dt.Rows[0]["pi_cardcode"].ToString();
  530. if (pi_cardcode.Text != "ZGCC")
  531. {
  532. CustomerLabel.Enabled = false;
  533. }
  534. else
  535. {
  536. CustomerLabel.Enabled = true;
  537. }
  538. pi_date.Text = dt.Rows[0]["pi_date"].ToString();
  539. PI_ID = dt.Rows[0]["pi_id"].ToString();
  540. OutBoxNum_Click(new object(), new EventArgs());
  541. LoadPrcodeData();
  542. LoadGridData(sender, e);
  543. //获取条码规则
  544. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix);
  545. SingleID.Clear();
  546. Input.Focus();
  547. //从后往前找未采集的行
  548. for (int i = GridPrcode.Rows.Count - 1; i >= 0; i--)
  549. {
  550. string outqty = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  551. string collectnum = GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString();
  552. if (int.Parse(outqty) > int.Parse(collectnum == "" ? "0" : collectnum))
  553. {
  554. GridPrcode.Rows[i].Selected = true;
  555. }
  556. }
  557. bi_inman.Text = dh.getFieldDataByCondition("barcodeio left join employee on bi_inman=em_code", "wm_concat(distinct em_name)", "bi_piid=" + PI_ID).ToString();
  558. pib_inman.Text = dh.getFieldDataByCondition("prodiobarcode left join employee on pib_inman=em_code", "wm_concat(distinct em_name)", "pib_piid=" + PI_ID).ToString();
  559. Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LABELATTACHPARAMETER where lap_custcode='" + pi_cardcode.Text + "'", "select");
  560. thread = new Thread(GetInOutInfAndLabelFile);
  561. stw = new SetLoadingWindow(thread, "正在获取打印标签");
  562. BaseUtil.SetFormCenter(stw);
  563. stw.ShowDialog();
  564. LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
  565. }
  566. else MessageBox.Show("当前出入库单号不存在或者未审核!", "提示");
  567. }
  568. }
  569. private void SingleBoxPrint()
  570. {
  571. if (EnablePrint)
  572. {
  573. if (LabelInf.Rows.Count > 0)
  574. {
  575. //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
  576. SingleID.Clear();
  577. //获取全部的中盒号
  578. Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
  579. //判断所有盒号为该盒的是否勾选已采集
  580. outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
  581. for (int i = 0; i < LabelInf.Rows.Count; i++)
  582. {
  583. if (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()))
  584. SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  585. }
  586. if (SingleID.ToArray().Length == 0)
  587. {
  588. MessageBox.Show("选择的行未勾选采集或者已打印", "提示");
  589. return;
  590. }
  591. for (int i = 0; i < LabelInf.RowCount; i++)
  592. {
  593. if (i + 1 < LabelInf.RowCount)
  594. {
  595. //如果本行的中盒号和下一行不相等的话
  596. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString())
  597. {
  598. if (!outboxcode1.ContainsKey(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  599. outboxcode1.Add(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString(), true);
  600. }
  601. }
  602. }
  603. string pibid = "";
  604. for (int i = 0; i < LabelInf.RowCount; i++)
  605. {
  606. //勾选了并且未打印
  607. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue != null && LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString().ToLower() != "true")
  608. {
  609. pibid += LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + ",";
  610. LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
  611. }
  612. }
  613. for (int j = 0; j < SingleReport.Parameters.Count; j++)
  614. {
  615. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, "");
  616. for (int k = 0; k < Attach.Rows.Count; k++)
  617. {
  618. if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name)
  619. {
  620. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  621. }
  622. }
  623. }
  624. if (pibid != "")
  625. {
  626. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiosingleinfo_view where 主键ID in (" + pibid.Substring(0, pibid.Length - 1) + ")", "select");
  627. SingleReport.RegisterData(dt, "prodiosingleinfo_view");
  628. SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true;
  629. //保存参数打印
  630. SingleReport.PrintSettings.ShowDialog = false;
  631. SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  632. try
  633. {
  634. SingleReport.Print();
  635. }
  636. catch (Exception e)
  637. {
  638. MessageBox.Show(e.Message);
  639. return;
  640. }
  641. Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text;
  642. Properties.Settings.Default.Save();
  643. }
  644. else
  645. {
  646. MessageBox.Show("未勾选打印明细!", "提示");
  647. }
  648. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印箱标", "打印成功");
  649. dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray());
  650. outboxcode1.Clear();
  651. }
  652. else
  653. {
  654. MessageBox.Show("此模板尚未维护参数或不存在打印明细", "提示");
  655. return;
  656. }
  657. }
  658. }
  659. private void SingleLabelPrint_Click(object sender, EventArgs e)
  660. {
  661. if (SingleLabelCombox.Text != "")
  662. {
  663. if (SingleBoxBegin.Text != "" || SingleBoxEnd.Text != "")
  664. {
  665. try
  666. {
  667. int begin = int.Parse(SingleBoxBegin.Text == "" ? "1" : SingleBoxBegin.Text);
  668. int end = int.Parse(SingleBoxEnd.Text == "" ? LabelInf.Rows.Count.ToString() : SingleBoxEnd.Text);
  669. if (begin > 0 && end <= LabelInf.Rows.Count && begin <= end)
  670. {
  671. for (int i = begin - 1; i < end; i++)
  672. {
  673. LabelInf.Rows[i].Cells["Choose"].Value = true;
  674. LabelInf.Rows[i].Cells["pib_ifprint"].Value = false;
  675. }
  676. }
  677. else
  678. {
  679. MessageBox.Show("单盘打印范围错误", "提示");
  680. return;
  681. }
  682. }
  683. catch (Exception)
  684. {
  685. MessageBox.Show("单盘打印范围错误", "提示");
  686. return;
  687. }
  688. }
  689. thread = new Thread(SingleBoxPrint);
  690. stw = new SetLoadingWindow(thread, "正在打印单盘");
  691. BaseUtil.SetFormCenter(stw);
  692. stw.ShowDialog();
  693. Input.Focus();
  694. }
  695. else
  696. {
  697. MessageBox.Show("未维护单盘标签", "提示");
  698. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印箱标", "打印失败,未维护标签");
  699. }
  700. }
  701. private void MidBoxLabelPrint()
  702. {
  703. //未输入内容打印全部中盒
  704. if (MidLabelNum.Text == "")
  705. {
  706. int begin = 0;
  707. int end = 0;
  708. if (MidBoxBegin.Text != "" || MidBoxEnd.Text != "")
  709. {
  710. try
  711. {
  712. begin = int.Parse(MidBoxBegin.Text == "" ? "1" : MidBoxBegin.Text);
  713. end = int.Parse(MidBoxEnd.Text == "" ? LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString() : MidBoxEnd.Text);
  714. int minmidbox = int.Parse(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString());
  715. int maxmidbox = int.Parse(LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString());
  716. if (begin >= minmidbox && end <= maxmidbox && begin <= end)
  717. {
  718. //设置中盒打印范围的行号
  719. for (int i = 0; i < LabelInf.Rows.Count; i++)
  720. {
  721. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == begin)
  722. {
  723. begin = i;
  724. }
  725. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == end)
  726. {
  727. end = i;
  728. }
  729. }
  730. }
  731. else
  732. {
  733. MessageBox.Show("中盒打印范围错误", "提示");
  734. return;
  735. }
  736. }
  737. catch (Exception)
  738. {
  739. MessageBox.Show("中盒打印范围错误", "提示");
  740. return;
  741. }
  742. }
  743. List<int> MidOutBoxCode = new List<int>();
  744. List<int> MidOutBoxCodeIndex = new List<int>();
  745. string la_id = MidLabelCombox.SelectedValue.ToString().Split('#')[0];
  746. for (int i = (begin == 0 ? 0 : begin); i <= (end == 0 ? LabelInf.Rows.Count - 1 : end); i++)
  747. {
  748. try
  749. {
  750. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  751. {
  752. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  753. MidOutBoxCodeIndex.Add(i);
  754. }
  755. }
  756. catch (Exception)
  757. {
  758. MessageBox.Show("请先封箱!");
  759. return;
  760. }
  761. }
  762. for (int i = 0; i < MidOutBoxCodeIndex.Count; i++)
  763. {
  764. try
  765. {
  766. MidBoxCodePrint(la_id, MidOutBoxCodeIndex[i]);
  767. }
  768. catch (Exception e)
  769. {
  770. MessageBox.Show(e.Message);
  771. return;
  772. }
  773. }
  774. return;
  775. }
  776. bool FindMidLabel = false;
  777. if (MidLabelCombox.SelectedValue != null)
  778. {
  779. string la_id = MidLabelCombox.SelectedValue.ToString().Split('#')[0];
  780. string cl_labelname = MidLabelCombox.Text;
  781. 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();
  782. //中盒号所在的行
  783. int MidLabelRowIndex = 0;
  784. //缓存中盒数据
  785. for (int i = 0; i < LabelInf.RowCount; i++)
  786. {
  787. if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  788. {
  789. //找到了输入的中盒号停止循环
  790. FindMidLabel = true;
  791. MidLabelRowIndex = i;
  792. }
  793. }
  794. //找到了指定的盒号
  795. if (FindMidLabel)
  796. MidBoxCodePrint(la_id, MidLabelRowIndex);
  797. else
  798. MessageBox.Show("该出入库单未找到该中盒号!", "提示");
  799. }
  800. else
  801. MessageBox.Show("未维护中盒模板", "提示");
  802. }
  803. private void MidLabelPrint_Click(object sender, EventArgs e)
  804. {
  805. if (MidLabelCombox.Text != "")
  806. {
  807. PackMidBox_Click(sender, e);
  808. thread = new Thread(MidBoxLabelPrint);
  809. stw = new SetLoadingWindow(thread, "正在打印中盒");
  810. BaseUtil.SetFormCenter(stw);
  811. stw.ShowDialog();
  812. }
  813. else
  814. MessageBox.Show("未维护中盒标签", "提示");
  815. }
  816. private void OutBoxPrint()
  817. {
  818. List<string> Outboxcode = new List<string>();
  819. //如果未勾选箱号则对勾选的数据的箱号进行整合
  820. string la_id = OutBoxCombox.SelectedValue.ToString().Split('#')[0];
  821. string cl_labelname = OutBoxCombox.Text;
  822. 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();
  823. if (OutBoxNum.Text == "" || OutBoxNum.Text == "新增")
  824. {
  825. for (int i = 0; i < LabelInf.RowCount; i++)
  826. {
  827. string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  828. //富为使用包装单的逻辑
  829. //如果不包含该箱号则进行添加
  830. if (!Outboxcode.Contains(outboxcode2))
  831. Outboxcode.Add(outboxcode2);
  832. }
  833. //按获取到的箱号列表进行打印
  834. if (Outboxcode.ToArray().Length > 0)
  835. {
  836. for (int i = 0; i < Outboxcode.ToArray().Length; i++)
  837. {
  838. for (int h = 0; h < LabelInf.RowCount; h++)
  839. {
  840. if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i])
  841. {
  842. OutBoxCodePrint(la_id, h);
  843. break;
  844. }
  845. }
  846. }
  847. }
  848. else
  849. {
  850. MessageBox.Show("请勾选需要打印的外箱", "提示");
  851. }
  852. }
  853. else
  854. {
  855. bool FindMidLabel = false;
  856. try
  857. {
  858. int OutBoxLabelRowIndex = 0;
  859. //查找是否存在该中盒号
  860. for (int i = 0; i < LabelInf.RowCount; i++)
  861. {
  862. if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString())
  863. {
  864. //找到了输入的中盒号停止循环
  865. FindMidLabel = true;
  866. OutBoxLabelRowIndex = i;
  867. break;
  868. }
  869. }
  870. //找到了指定的盒号
  871. if (FindMidLabel)
  872. OutBoxCodePrint(la_id, OutBoxLabelRowIndex);
  873. else
  874. MessageBox.Show("该出入库单未找到该外箱号!", "提示");
  875. }
  876. catch (Exception) { }
  877. }
  878. Outboxcode.Clear();
  879. }
  880. private void MidBoxCodePrint(string la_id, int rowindex)
  881. {
  882. if (EnablePrint)
  883. {
  884. for (int j = 0; j < MidReport.Parameters.Count; j++)
  885. {
  886. MidReport.SetParameterValue(MidReport.Parameters[j].Name, "");
  887. for (int i = 0; i < Attach.Rows.Count; i++)
  888. {
  889. if (Attach.Rows[i][0].ToString() == MidReport.Parameters[j].Name)
  890. {
  891. MidReport.SetParameterValue(MidReport.Parameters[j].Name, Attach.Rows[i][1].ToString());
  892. }
  893. }
  894. }
  895. //名称相等的时候,取SQL进行值的查询
  896. string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
  897. string pib_outboxcode1 = LabelInf.Rows[rowindex].Cells["pib_outboxcode1"].Value.ToString();
  898. DataTable dt;
  899. if (MidLabelAutoPrint.Checked)
  900. {
  901. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号='" + pib_outboxcode1 + "'", "select");
  902. }
  903. else
  904. {
  905. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号='" + pib_outboxcode1 + "' and 中盒数量=10", "select");
  906. }
  907. if (dt.Rows.Count > 0)
  908. {
  909. MidReport.RegisterData(dt, "prodiomidinfo_view");
  910. MidReport.GetDataSource("prodiomidinfo_view").Enabled = true;
  911. MidReport.PrintSettings.ShowDialog = false;
  912. MidReport.PrintSettings.Printer = MidLabelPrinter.Text;
  913. MidReport.Print();
  914. }
  915. Properties.Settings.Default.MPrinter = MidLabelPrinter.Text;
  916. Properties.Settings.Default.Save();
  917. }
  918. }
  919. /// <summary>
  920. /// 执行打印外箱号
  921. /// </summary>
  922. private void OutBoxCodePrint(string la_id, int rowindex)
  923. {
  924. if (EnablePrint)
  925. {
  926. for (int j = 0; j < OutReport.Parameters.Count; j++)
  927. {
  928. OutReport.SetParameterValue(OutReport.Parameters[j].Name, "");
  929. for (int i = 0; i < Attach.Rows.Count; i++)
  930. {
  931. if (Attach.Rows[i][0].ToString() == OutReport.Parameters[j].Name)
  932. {
  933. OutReport.SetParameterValue(OutReport.Parameters[j].Name, Attach.Rows[i][1].ToString());
  934. }
  935. }
  936. }
  937. string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
  938. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiooutinfo_view where 出货单号='" + pi_inoutno.Text + "' and 外箱号='" + pib_outboxcode2 + "'", "select");
  939. DataTable dt1 = dt.Clone();
  940. for (int i = 0; i < dt.Rows.Count; i++)
  941. {
  942. DataRow dr = dt1.NewRow();
  943. for (int j = 0; j < dt.Columns.Count; j++)
  944. {
  945. dr[j] = dt.Rows[i][j].ToString();
  946. }
  947. dt1.Rows.Add(dr);
  948. if ((i + 1) % 5 == 0 || (i + 1) == dt.Rows.Count)
  949. {
  950. OutReport.RegisterData(dt1, "prodiooutinfo_view");
  951. OutReport.GetDataSource("prodiooutinfo_view").Enabled = true;
  952. OutReport.PrintSettings.ShowDialog = false;
  953. OutReport.PrintSettings.Printer = OutBoxPrinter.Text;
  954. try
  955. {
  956. OutReport.Print();
  957. }
  958. catch (Exception e)
  959. {
  960. MessageBox.Show(e.Message);
  961. return;
  962. }
  963. BaseUtil.CleanDataTableData(dt1);
  964. }
  965. }
  966. }
  967. }
  968. private void CleanDetail_Click(object sender, EventArgs e)
  969. {
  970. ArrayList<string> DeleteID = new ArrayList<string>();
  971. for (int i = 0; i < LabelInf.RowCount; i++)
  972. {
  973. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true")
  974. DeleteID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  975. }
  976. //勾选了删除的明细之后
  977. if (DeleteID.ToArray().Length > 0)
  978. {
  979. string close = MessageBox.Show(this.ParentForm, "删除后不可恢复,是否确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  980. if (close.ToString() == "Yes")
  981. {
  982. dh.BatchInsert("delete from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray());
  983. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "删除明细", "删除明细成功");
  984. MessageBox.Show("删除成功", "提示");
  985. Input.Clear();
  986. LoadPrcodeData();
  987. LoadGridData(sender, e);
  988. }
  989. }
  990. else
  991. MessageBox.Show("尚未勾选需要删除的明细", "提示");
  992. }
  993. private void OutBoxLabelPrint_Click(object sender, EventArgs e)
  994. {
  995. if (OutBoxCombox.Text != "")
  996. {
  997. thread = new Thread(OutBoxPrint);
  998. stw = new SetLoadingWindow(thread, "正在打印外箱");
  999. BaseUtil.SetFormCenter(stw);
  1000. stw.ShowDialog();
  1001. Input.Focus();
  1002. }
  1003. else
  1004. MessageBox.Show("未维护外箱标签", "提示");
  1005. }
  1006. private void LoadGridData()
  1007. {
  1008. LoadGridData(new object(), new EventArgs());
  1009. }
  1010. /// <summary>
  1011. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  1012. /// </summary>
  1013. /// <param name="sender"></param>
  1014. /// <param name="e"></param>
  1015. private void LoadGridData(object sender, EventArgs e)
  1016. {
  1017. AllChecked = false;
  1018. sql.Clear();
  1019. sql.Append("select pd_custprodcode,pd_custprodspec,pib_custmidboxcode,pd_pocode,pjd_orispeccode,pib_madein,pib_custbarcode,pib_custoutboxcode,pib_id,pib_datecode1,pib_pdid,pib_piid,");
  1020. sql.Append("pib_pdno,pib_prodcode,nvl(nvl(pd_brand,pib_brand),pr_brand)pib_brand,pr_vendprodcode,pib_lotno,pib_datecode,pib_qty,pr_spec,");
  1021. sql.Append("pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,pib_outboxcode2,nvl(pib_ifprint,0)pib_ifprint from prodiobarcode left join ");
  1022. sql.Append("prodiodetail on pib_piid=pd_piid and pd_pdno=pib_pdno and pd_prodcode=pib_prodcode left join product on pr_code=pib_prodcode ");
  1023. sql.Append("left join sale on sa_code=pib_ordercode left join PRODJOINVENDDETAIL on pjd_brand =pd_brand and pjd_prodcode=pd_prodcode where pib_piid='" + PI_ID + "' ");
  1024. sql.Append(" order by to_number(pib_outboxcode2),pib_id,pd_prodcode");
  1025. LabelInfDataTable = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1026. if (OutBoxNum.Text != "新增")
  1027. {
  1028. BaseUtil.FillDgvWithDataTable(LabelInf, BaseUtil.filterDataTable(LabelInfDataTable, " pib_outboxcode2='" + OutBoxNum.Text + "'"));
  1029. }
  1030. else
  1031. {
  1032. BaseUtil.FillDgvWithDataTable(LabelInf, LabelInfDataTable);
  1033. }
  1034. //有数据的话默认取第一条的品牌去取采集策略
  1035. if (LabelInf.Rows.Count > 0)
  1036. LabelInf.FirstDisplayedScrollingRowIndex = LabelInf.Rows.Count - 1;
  1037. //计算所有的采集数量
  1038. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1039. {
  1040. string CurrentPrCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1041. string CurrentPDNO = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  1042. string collectqty = (LabelInfDataTable.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  1043. GridPrcode.Rows[i].Cells["CollectedNum"].Value = collectqty;
  1044. GridPrcode.Rows[i].Cells["UnCollectedNum"].Value = int.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString()) - int.Parse(collectqty == "" ? "0" : collectqty);
  1045. }
  1046. }
  1047. private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1048. {
  1049. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  1050. pi_inoutno_KeyDown(sender, e2);
  1051. }
  1052. /// <summary>
  1053. /// 勾选的时候自动打印
  1054. /// </summary>
  1055. /// <param name="sender"></param>
  1056. /// <param name="e"></param>
  1057. private void LabelInf_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  1058. {
  1059. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
  1060. {
  1061. string datecode = LabelInf.Rows[e.RowIndex].Cells["pib_datecode"].Value.ToString();
  1062. try
  1063. {
  1064. System.DateTime dt = System.DateTime.ParseExact(datecode, "yyyyMMdd", CultureInfo.CurrentCulture);
  1065. GregorianCalendar gc = new GregorianCalendar();
  1066. int weekOfYear = gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
  1067. if (weekOfYear < 10)
  1068. LabelInf.Rows[e.RowIndex].Cells["pib_datecode1"].Value = dt.Year.ToString().Substring(2, 2) + "0" + weekOfYear;
  1069. else
  1070. LabelInf.Rows[e.RowIndex].Cells["pib_datecode1"].Value = dt.Year.ToString().Substring(2, 2) + weekOfYear;
  1071. }
  1072. catch (Exception) { }
  1073. }
  1074. }
  1075. private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1076. {
  1077. string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1078. if (close.ToString() == "Yes")
  1079. {
  1080. Login login = new Login();
  1081. //注销的时候需要将拼接的连接字符串置空
  1082. DataHelper.DBConnectionString = null;
  1083. logout = true;
  1084. this.Hide();
  1085. login.ShowDialog();
  1086. this.Close();
  1087. }
  1088. }
  1089. private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1090. /// <summary>
  1091. /// 切换打开的单盘文件
  1092. /// </summary>
  1093. /// <param name="sender"></param>
  1094. /// <param name="e"></param>
  1095. private void SingleLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1096. {
  1097. try
  1098. {
  1099. if (ComBoxClickChangeLabelDoc)
  1100. {
  1101. SingleReport.Load(ftpOperater.DownLoadTo + SingleLabelCombox.Text);
  1102. }
  1103. }
  1104. catch (Exception) { }
  1105. }
  1106. /// <summary>
  1107. /// 切换打开的中盒文件
  1108. /// </summary>
  1109. /// <param name="sender"></param>
  1110. /// <param name="e"></param>
  1111. private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1112. {
  1113. try
  1114. {
  1115. if (ComBoxClickChangeLabelDoc)
  1116. {
  1117. MidReport.Load(ftpOperater.DownLoadTo + MidLabelCombox.Text);
  1118. }
  1119. }
  1120. catch (Exception) { }
  1121. }
  1122. /// <summary>
  1123. /// 切换打开的外箱文件
  1124. /// </summary>
  1125. /// <param name="sender"></param>
  1126. /// <param name="e"></param>
  1127. private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e)
  1128. {
  1129. try
  1130. {
  1131. if (ComBoxClickChangeLabelDoc)
  1132. {
  1133. OutReport.Load(ftpOperater.DownLoadTo + OutBoxCombox.Text);
  1134. }
  1135. }
  1136. catch (Exception) { }
  1137. }
  1138. private void ChooseAll_Click(object sender, EventArgs e)
  1139. {
  1140. if (AllChecked)
  1141. {
  1142. foreach (DataGridViewRow dr in LabelInf.Rows)
  1143. dr.Cells[0].Value = false;
  1144. AllChecked = false;
  1145. }
  1146. else
  1147. {
  1148. foreach (DataGridViewRow dr in LabelInf.Rows)
  1149. dr.Cells[0].Value = true;
  1150. AllChecked = true;
  1151. }
  1152. }
  1153. private void ExportData_Click(object sender, EventArgs e)
  1154. {
  1155. ExportFileDialog.Description = "选择导出的路径";
  1156. DialogResult result = ExportFileDialog.ShowDialog();
  1157. if (result == DialogResult.OK)
  1158. {
  1159. ExcelHandler eh = new ExcelHandler();
  1160. DataTable dt = LabelInfDataTable.Copy();
  1161. for (int i = dt.Columns.Count - 1; i >= 0; i--)
  1162. {
  1163. for (int j = 0; j < LabelInf.Columns.Count; j++)
  1164. {
  1165. //去除ID列
  1166. if (dt.Columns[i].ColumnName.ToLower().Contains("id") || dt.Columns[i].ColumnName.ToLower() == "pib_barcode" || dt.Columns[i].ColumnName.ToLower() == "pib_pdno" || dt.Columns[i].ColumnName.ToLower() == "pib_ifprint" || dt.Columns[i].ColumnName.ToLower() == "pib_datecode1" || dt.Columns[i].ColumnName.ToLower() == "pr_vendprodcode")
  1167. {
  1168. dt.Columns.RemoveAt(i);
  1169. break;
  1170. }
  1171. switch (dt.Columns[i].ColumnName.ToLower())
  1172. {
  1173. case "pib_lotno":
  1174. dt.Columns[i].ColumnName = "批次号";
  1175. break;
  1176. case "pib_datecode":
  1177. dt.Columns[i].ColumnName = "生产日期";
  1178. break;
  1179. case "pib_custbarcode":
  1180. dt.Columns[i].ColumnName = "最小产品包装条码";
  1181. break;
  1182. default:
  1183. break;
  1184. }
  1185. if (dt.Columns[i].ColumnName.ToLower() == LabelInf.Columns[j].DataPropertyName.ToLower())
  1186. {
  1187. dt.Columns[i].ColumnName = LabelInf.Columns[j].HeaderText;
  1188. break;
  1189. }
  1190. }
  1191. }
  1192. eh.ExportExcel(dt, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text);
  1193. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1194. if (close.ToString() == "Yes")
  1195. Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + ".xls");
  1196. }
  1197. }
  1198. private void AttachInfo_Click(object sender, EventArgs e)
  1199. {
  1200. if (pi_cardcode.Text != "")
  1201. {
  1202. 附件内容打印 att = new 附件内容打印(pi_cardcode.Text);
  1203. att.ShowDialog();
  1204. }
  1205. else MessageBox.Show("请先获取出库单信息", "提示");
  1206. }
  1207. private void MidBoxCapacity_Leave(object sender, EventArgs e)
  1208. {
  1209. NumericUpDown nup = (NumericUpDown)sender;
  1210. switch (nup.Name)
  1211. {
  1212. case "MidBoxCapacity":
  1213. Properties.Settings.Default.MidBoxCapacity = nup.Value;
  1214. Properties.Settings.Default.Save();
  1215. break;
  1216. case "OutboxCapacity":
  1217. Properties.Settings.Default.OutboxCapacity = nup.Value;
  1218. Properties.Settings.Default.Save();
  1219. break;
  1220. default:
  1221. break;
  1222. }
  1223. }
  1224. private void RefreshDBConnect_Tick(object sender, EventArgs e)
  1225. {
  1226. dh.ExecuteSql("select sysdate from dual", "select");
  1227. }
  1228. private void LoadPrcodeData()
  1229. {
  1230. GridPrcode.DataSource = (DataTable)dh.ExecuteSql("select pd_pdno,pd_prodcode,'0' CollectedNum,'0' UnCollectedNum,pd_outqty,pr_unit,pd_brand,pjd_zxbzs_user,pjd_id from prodiodetail left join prodinout on pi_id=pd_piid left join PRODJOINVENDDETAIL on pjd_brand =pd_brand and pjd_prodcode=pd_prodcode left join product on pd_prodcode=pr_code where pi_id='" + PI_ID + "' order by pd_pdno", "select");
  1231. if (GridPrcode.Rows.Count > 0)
  1232. {
  1233. CurrentPrCode = GridPrcode.Rows[0].Cells["pd_prodcode"].Value.ToString();
  1234. CurrentZXBZ = GridPrcode.Rows[0].Cells["pjd_zxbzs_user"].Value.ToString();
  1235. CurrentUnit = GridPrcode.Rows[0].Cells["pr_unit"].Value.ToString();
  1236. CurrentPDNO = GridPrcode.Rows[0].Cells["pd_pdno"].Value.ToString();
  1237. CurrentPrCount = GridPrcode.Rows[0].Cells["pd_outqty"].Value.ToString();
  1238. CurrentBrand = GridPrcode.Rows[0].Cells["pd_brand"].Value.ToString();
  1239. GridPrcode.Rows[0].Selected = true;
  1240. }
  1241. }
  1242. private void OutBoxNum_Click(object sender, EventArgs e)
  1243. {
  1244. OutBoxNum.Items.Clear();
  1245. DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by pib_outboxcode2", "select");
  1246. ItemObject io = new ItemObject("新增", "新增");
  1247. OutBoxNum.Items.Add(io);
  1248. for (int i = 0; i < dt.Rows.Count; i++)
  1249. {
  1250. string pib_outboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  1251. io = new ItemObject(pib_outboxcode2, pib_outboxcode2);
  1252. OutBoxNum.Items.Add(io);
  1253. }
  1254. if (OutBoxNum.Text == "新增" || OutBoxNum.Text == "")
  1255. OutBoxNum.SelectedIndex = OutBoxNum.Items.Count - 1;
  1256. }
  1257. /// <summary>
  1258. /// 获取条码规则
  1259. /// </summary>
  1260. /// <param name="Type"></param>
  1261. /// <param name="Prefix"></param>
  1262. /// <param name="Suffix"></param>
  1263. /// <param name="MaxNum"></param>
  1264. /// <param name="SerialNumLength"></param>
  1265. /// <param name="Radix"></param>
  1266. private void GetBarCodeRule(out string Prefix, out string Suffix, out int MaxNum, out int SerialNumLength, out int Radix)
  1267. {
  1268. //获取编码规则
  1269. Prefix = "";
  1270. Suffix = "";
  1271. MaxNum = 0;
  1272. SerialNumLength = 0;
  1273. Radix = 0;
  1274. DataTable Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_type,nrd_radix,nrd_sql,nrd_length from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode='" + pi_cardcode.Text + "' order by nrd_detno", "select");
  1275. //如果没有则取公共规则
  1276. if (Nr.Rows.Count == 0)
  1277. Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_radix,nrd_type,nrd_sql,nrd_length from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode is null and nr_isdefault <> 0 order by nrd_detno", "select");
  1278. //用于过滤参数的正则表达式
  1279. Regex match = new Regex("{\\w+}");
  1280. //用于存放每一项的明细的数据
  1281. string[] NrData = new string[Nr.Rows.Count];
  1282. //流水长度
  1283. Dictionary<int, string> NrDic = new Dictionary<int, string>();
  1284. Prefix = "";
  1285. for (int m = 0; m < Nr.Rows.Count; m++)
  1286. {
  1287. switch (Nr.Rows[m]["nrd_type"].ToString())
  1288. {
  1289. //常量直接进行拼接
  1290. case "常量":
  1291. Prefix += Nr.Rows[m]["nrd_sql"].ToString();
  1292. Suffix += Nr.Rows[m]["nrd_sql"].ToString();
  1293. break;
  1294. case "SQL":
  1295. string SQL = Nr.Rows[m]["nrd_sql"].ToString();
  1296. DataTable Temp;
  1297. //如果不包含参数替换
  1298. if (SQL.IndexOf("{") == 0)
  1299. {
  1300. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  1301. }
  1302. else
  1303. {
  1304. //替换参数后重新执行SQL
  1305. foreach (Match mch in match.Matches(SQL))
  1306. {
  1307. SQL = SQL.Replace(mch.Value.Trim(), "'" + pi_inoutno.Text + "'");
  1308. }
  1309. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  1310. }
  1311. if (Temp.Rows.Count > 0)
  1312. {
  1313. Prefix += Temp.Rows[0][0].ToString();
  1314. Suffix += Temp.Rows[0][0].ToString();
  1315. }
  1316. break;
  1317. //流水需要通过MaxNumber去取
  1318. case "流水":
  1319. string maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + pi_cardcode.Text + "' and rmn_prefix='" + Prefix + "'").ToString();
  1320. //设置当前流水
  1321. if (maxnum == "")
  1322. {
  1323. dh.ExecuteSql("insert into RuleMaxNum(rmn_id,rmn_nrcode,rmn_prefix,rmn_maxnumber) values(RuleMaxNum_seq.nextval,'" + pi_cardcode.Text + "','" + Prefix + "','1')", "insert");
  1324. MaxNum = 1;
  1325. }
  1326. else
  1327. {
  1328. MaxNum = int.Parse(maxnum);
  1329. }
  1330. SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
  1331. Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString());
  1332. Suffix = "";
  1333. break;
  1334. default:
  1335. break;
  1336. }
  1337. }
  1338. }
  1339. private void GridPrcode_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  1340. {
  1341. string Value = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  1342. string ID = GridPrcode.Rows[e.RowIndex].Cells["pjd_id"].Value.ToString();
  1343. dh.UpdateByCondition("PRODJOINVENDDETAIL", "pjd_zxbzs_user='" + Value + "'", "pjd_id='" + ID + "'");
  1344. //删除对应物料的明细
  1345. CurrentPrCode = GridPrcode.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString();
  1346. CurrentZXBZ = GridPrcode.Rows[e.RowIndex].Cells["pjd_zxbzs_user"].Value.ToString();
  1347. CurrentUnit = GridPrcode.Rows[e.RowIndex].Cells["pr_unit"].Value.ToString();
  1348. CurrentPDNO = GridPrcode.Rows[e.RowIndex].Cells["pd_pdno"].Value.ToString();
  1349. CurrentPrCount = GridPrcode.Rows[e.RowIndex].Cells["pd_outqty"].Value.ToString();
  1350. CurrentBrand = GridPrcode.Rows[e.RowIndex].Cells["pd_brand"].Value.ToString();
  1351. GridPrcode.Rows[e.RowIndex].Selected = true;
  1352. dh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno='" + CurrentPDNO + "' and pib_prodcode='" + CurrentPrCode + "'", "delete");
  1353. LoadGridData(sender, new EventArgs());
  1354. }
  1355. private void GridPrcode_SelectionChanged(object sender, EventArgs e)
  1356. {
  1357. if (GridPrcode.SelectedRows.Count > 0)
  1358. {
  1359. DataGridViewSelectedRowCollection dsc = GridPrcode.SelectedRows;
  1360. CurrentPrCode = GridPrcode.Rows[dsc[0].Index].Cells["pd_prodcode"].Value.ToString();
  1361. CurrentZXBZ = GridPrcode.Rows[dsc[0].Index].Cells["pjd_zxbzs_user"].Value.ToString();
  1362. CurrentUnit = GridPrcode.Rows[dsc[0].Index].Cells["pr_unit"].Value.ToString();
  1363. CurrentPDNO = GridPrcode.Rows[dsc[0].Index].Cells["pd_pdno"].Value.ToString();
  1364. CurrentPrCount = GridPrcode.Rows[dsc[0].Index].Cells["pd_outqty"].Value.ToString();
  1365. CurrentBrand = GridPrcode.Rows[dsc[0].Index].Cells["pd_brand"].Value.ToString();
  1366. GridPrcode.Rows[dsc[0].Index].Selected = true;
  1367. }
  1368. }
  1369. private void GridPrcode_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1370. private void GridPrcode_CellClick(object sender, DataGridViewCellEventArgs e)
  1371. {
  1372. if (e.RowIndex >= 0)
  1373. {
  1374. GridPrcode.Rows[e.RowIndex].Selected = true;
  1375. }
  1376. }
  1377. private void DCCheck_Leave(object sender, EventArgs e)
  1378. {
  1379. try
  1380. {
  1381. Properties.Settings.Default.DCCheck = int.Parse(DCCheck.Text);
  1382. Properties.Settings.Default.Save();
  1383. }
  1384. catch (Exception)
  1385. {
  1386. MessageBox.Show("DC校验时间必须是整数");
  1387. }
  1388. }
  1389. /// <summary>
  1390. /// 校验DateCode
  1391. /// </summary>
  1392. /// <param name="DateCode"></param>
  1393. private bool CheckDateCode(string DateCode)
  1394. {
  1395. //根据DateCode计算的日期
  1396. string Year = DateCode.Substring(0, 2);
  1397. System.DateTime dt = new System.DateTime(int.Parse("20" + Year), 01, 01);
  1398. string Week = DateCode.Substring(2, 2);
  1399. System.DateTime dt1 = dt.AddDays(int.Parse(Week) * 7);
  1400. //减去DC校验后的日期
  1401. System.DateTime now = System.DateTime.Now;
  1402. System.DateTime now1 = now.AddDays(-int.Parse(DCCheck.Text));
  1403. //物料的DateCode大于限制日期即可
  1404. if (dt1 > now1)
  1405. {
  1406. return true;
  1407. }
  1408. return false;
  1409. }
  1410. private void PrintFooter_Click(object sender, EventArgs e)
  1411. {
  1412. DataTable dt = (DataTable)dh.ExecuteSql("select pib_outboxcode2,max(pib_id) pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' group by pib_outboxcode2 order by pib_outboxcode2", "select");
  1413. string SQL = "select pib_outboxcode2||'/'||(select max(pib_outboxcode2) from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "') from prodiobarcode where pib_id=";
  1414. for (int i = 0; i < dt.Rows.Count; i++)
  1415. {
  1416. DataTable dt1 = (DataTable)dh.ExecuteSql(SQL + dt.Rows[i]["pib_id"].ToString(), "select");
  1417. FootReport.SetParameterValue("唛头", dt1.Rows[0][0].ToString());
  1418. FootReport.PrintSettings.ShowDialog = false;
  1419. FootReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  1420. FootReport.Print();
  1421. }
  1422. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "打印唛头", "成功");
  1423. }
  1424. private void Input_KeyUp(object sender, KeyEventArgs e)
  1425. {
  1426. if (e.KeyCode == Keys.Enter)
  1427. {
  1428. Input.SelectAll();
  1429. }
  1430. }
  1431. private void GridPrcode_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  1432. {
  1433. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  1434. if (e.ColumnIndex > 0 && e.RowIndex >= 0)
  1435. {
  1436. if (GridPrcode.Columns[e.ColumnIndex].Name == "pd_outqty")
  1437. {
  1438. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1439. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  1440. Rectangle border = e.CellBounds;
  1441. border.Width -= 1;
  1442. e.Graphics.DrawRectangle(Pens.White, border);
  1443. e.PaintContent(e.CellBounds);
  1444. e.Handled = true;
  1445. }
  1446. if (GridPrcode.Columns[e.ColumnIndex].Name == "UnCollectedNum" || GridPrcode.Columns[e.ColumnIndex].Name == "CollectedNum")
  1447. {
  1448. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1449. if (GridPrcode.Rows[e.RowIndex].Cells["UnCollectedNum"].Value.ToString() == "0")
  1450. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  1451. else
  1452. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.Gray, e.CellBounds);
  1453. Rectangle border = e.CellBounds;
  1454. border.Width -= 1;
  1455. e.Graphics.DrawRectangle(Pens.White, border);
  1456. e.PaintContent(e.CellBounds);
  1457. e.Handled = true;
  1458. }
  1459. }
  1460. }
  1461. private void GridPrcode_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
  1462. {
  1463. if (e.Button == MouseButtons.Right)
  1464. {
  1465. if (e.RowIndex >= 0 && e.ColumnIndex > 0)
  1466. {
  1467. string Conetent = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  1468. Clipboard.SetText(Conetent);
  1469. MessageBox.Show("已复制内容" + Conetent);
  1470. }
  1471. }
  1472. }
  1473. private void OutBoxNum_SelectedIndexChanged(object sender, EventArgs e)
  1474. {
  1475. LoadGridData(sender, e);
  1476. }
  1477. private void Pack_Click(object sender, EventArgs e)
  1478. {
  1479. if (LabelInf.Rows.Count > 0)
  1480. {
  1481. DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by pib_outboxcode2", "select");
  1482. string pibcustoutboxcode = dh.getFieldDataByCondition("prodiobarcode", "pib_custoutboxcode", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode2"].Value.ToString() + "' and pib_custoutboxcode is not null").ToString();
  1483. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix);
  1484. if (Radix > 0)
  1485. {
  1486. //生成外箱条码
  1487. for (int i = 0; i < dt.Rows.Count; i++)
  1488. {
  1489. List<string> OutBoxCode = new List<string>();
  1490. List<string> PIBOUTBOXCODE2 = new List<string>();
  1491. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  1492. for (int k = serialcode.ToString().Length; k < NumLength; k++)
  1493. {
  1494. serialcode = "0" + serialcode;
  1495. }
  1496. if (pibcustoutboxcode == "")
  1497. {
  1498. OutBoxCode.Add(Prefix + serialcode + Suffix);
  1499. MaxNum = MaxNum + 1;
  1500. }
  1501. else
  1502. {
  1503. OutBoxCode.Add(pibcustoutboxcode);
  1504. }
  1505. PIBOUTBOXCODE2.Add(dt.Rows[i]["pib_outboxcode2"].ToString());
  1506. dh.BatchInsert("update prodiobarcode set pib_custoutboxcode=:pib_custoutboxcode where pib_outboxcode2=:pib_outboxcode2 and pib_custoutboxcode is null", new string[] { "pib_custoutboxcode", "pib_outboxcode2" }, OutBoxCode.ToArray(), PIBOUTBOXCODE2.ToArray());
  1507. }
  1508. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + MaxNum + "'", "rmn_nrcode='" + pi_cardcode.Text + "' and rmn_prefix='" + Prefix + "'");
  1509. }
  1510. LoadGridData(sender, e);
  1511. }
  1512. }
  1513. private void PackMidBox_Click(object sender, EventArgs e)
  1514. {
  1515. DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by pib_outboxcode2", "select");
  1516. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix);
  1517. if (Radix > 0)
  1518. {
  1519. //生成中盒条码
  1520. int pib_outboxcode1 = int.Parse(dh.getFieldDataByCondition("prodiobarcode", "nvl(max(pib_outboxcode1),0)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString());
  1521. MaxNum = MaxNum - 1;
  1522. for (int i = 0; i < dt.Rows.Count; i++)
  1523. {
  1524. List<string> MidBoxCode = new List<string>();
  1525. List<string> PIBID = new List<string>();
  1526. List<string> PIBOUTBOXCODE1 = new List<string>();
  1527. DataTable dt1 = (DataTable)dh.ExecuteSql("select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + dt.Rows[i]["pib_outboxcode2"].ToString() + "' and pib_outboxcode1 is null order by to_number(pib_id)", "select");
  1528. //如果不是10的整数倍则为尾盒
  1529. for (int j = 0; j < dt1.Rows.Count; j++)
  1530. {
  1531. if (j % 10 == 0)
  1532. {
  1533. pib_outboxcode1 = pib_outboxcode1 + 1;
  1534. MaxNum = MaxNum + 1;
  1535. }
  1536. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  1537. for (int k = serialcode.ToString().Length; k < NumLength; k++)
  1538. {
  1539. serialcode = "0" + serialcode;
  1540. }
  1541. MidBoxCode.Add(Prefix + serialcode + Suffix);
  1542. PIBID.Add(dt1.Rows[j]["pib_id"].ToString());
  1543. PIBOUTBOXCODE1.Add(pib_outboxcode1.ToString());
  1544. }
  1545. dh.BatchInsert("update prodiobarcode set pib_custmidboxcode=:pib_custmidboxcode,pib_outboxcode1=:pib_outboxcode1 where pib_id=:pib_id and pib_custmidboxcode is null", new string[] { "pib_custmidboxcode", "pib_outboxcode1", "pib_id" }, MidBoxCode.ToArray(), PIBOUTBOXCODE1.ToArray(), PIBID.ToArray());
  1546. }
  1547. MaxNum = MaxNum + 1;
  1548. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + MaxNum + "'", "rmn_nrcode='" + pi_cardcode.Text + "' and rmn_prefix='" + Prefix + "'");
  1549. }
  1550. LoadGridData(sender, e);
  1551. }
  1552. private void PrintStatus_Click(object sender, EventArgs e)
  1553. {
  1554. EnablePrint = !EnablePrint;
  1555. if (EnablePrint)
  1556. {
  1557. SetPrintStatus_label.ForeColor = Color.Green;
  1558. SetPrintStatus_label.Text = "可打印";
  1559. }
  1560. else
  1561. {
  1562. SetPrintStatus_label.ForeColor = Color.Red;
  1563. SetPrintStatus_label.Text = "暂停打印";
  1564. }
  1565. Input.Focus();
  1566. }
  1567. private void CustomerLabel_Click(object sender, EventArgs e)
  1568. {
  1569. sql.Clear();
  1570. sql.Append("update prodiobarcode set pib_custbarcode=case when instr(pib_custbarcode,'SL')=0 ");
  1571. sql.Append("then ('SL'||pib_custbarcode)else pib_custbarcode end, pib_custoutboxcode=case when instr");
  1572. sql.Append("(pib_custoutboxcode,'SC')=0 then ('SC'||pib_custoutboxcode)else pib_custoutboxcode end where pib_inoutno='" + pi_inoutno.Text + "'");
  1573. dh.ExecuteSql(sql.ToString(), "select");
  1574. LoadGridData(sender, e);
  1575. CustomerLabel.Enabled = false;
  1576. }
  1577. }
  1578. }