UAS_出货标签管理.cs 104 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150
  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 UAS_LabelMachine.PublicMethod;
  10. using UAS_LabelMachine.Entity;
  11. using UAS_LabelMachine.PublicForm;
  12. using System.Threading;
  13. using FastReport;
  14. using System.Linq;
  15. using System.Reflection;
  16. using UAS_LabelMachine.CustomControl;
  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. DataTable SumQty;
  66. /// <summary>
  67. /// 是否通过选择Combox来改变打开的文件
  68. /// </summary>
  69. bool ComBoxClickChangeLabelDoc = false;
  70. //当前采集的物料编号
  71. string CurrentPrCode = "";
  72. //当前采集的最小包装
  73. string CurrentZXBZ = "";
  74. //当前采集的单位
  75. string CurrentUnit = "";
  76. //当前采集的总数
  77. string CurrentPrCount = "";
  78. //当前明细序号
  79. string CurrentPDNO = "";
  80. //当前的物料品牌
  81. string CurrentBrand = "";
  82. string Prefix = "";
  83. string Suffix = "";
  84. int MaxNum = 0;
  85. int NumLength = 0;
  86. int Radix = 0;
  87. private bool EnablePrint = true;
  88. string[] PIBID;
  89. DataTable Attach;
  90. public UAS_出货标签打印(string Master)
  91. {
  92. this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
  93. this.UpdateStyles();
  94. InitializeComponent();
  95. //利用反射设置DataGridView的双缓冲
  96. Type dgvType = this.LabelInf.GetType();
  97. PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
  98. pi.SetValue(this.LabelInf, true, null);
  99. pi.SetValue(this.GridPrcode, true, null);
  100. (new EnvironmentSettings()).ReportSettings.ShowProgress = false;
  101. Text = Text + "-" + Master;
  102. }
  103. protected override void WndProc(ref Message m)
  104. {
  105. //拦截双击标题栏、移动窗体的系统消息
  106. if (m.Msg != 0xA3)
  107. {
  108. base.WndProc(ref m);
  109. }
  110. }
  111. delegate void BindDataSource(DataGridView dgv, DataTable dt);//定义委托
  112. void bindingsource(DataGridView dgv, DataTable dt)
  113. {
  114. if (dgv.InvokeRequired)
  115. {
  116. dgv.Invoke(new BindDataSource(bindingsource), new object[] { dgv, dt });
  117. }
  118. else
  119. {
  120. dgv.AutoGenerateColumns = false;
  121. dgv.DataSource = dt;
  122. }
  123. }
  124. private void 贴标机条码打印_Load(object sender, EventArgs e)
  125. {
  126. //用计时器重置数据库链接
  127. LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
  128. dh = SystemInf.dh;
  129. CheckForIllegalCrossThreadCalls = false;
  130. pi_inoutno.Focus();
  131. Point pt = new Point();
  132. //禁止所有列的排序
  133. foreach (DataGridViewColumn dgv in LabelInf.Columns)
  134. {
  135. dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
  136. }
  137. int ScreenWidth = Screen.GetWorkingArea(pt).Width;
  138. //设置获取当前屏幕大小自动全屏但是保留任务栏
  139. Rectangle ScreenArea = Screen.GetWorkingArea(this);
  140. Top = 0;
  141. Left = 0;
  142. Width = ScreenArea.Width;
  143. Height = ScreenArea.Height;
  144. //OutboxCapacity.Value = Properties.Settings.Default.OutboxCapacity;
  145. MidboxCapacity.Value = Properties.Settings.Default.MidBoxCapacity;
  146. if (MidboxCapacity.Value == 0)
  147. {
  148. MidboxCapacity.Value = 10;
  149. }
  150. DCCheck.Text = Properties.Settings.Default.DCCheck.ToString();
  151. OutBoxPrinter.Text = Properties.Settings.Default.OPrinter;
  152. MidLabelPrinter.Text = Properties.Settings.Default.MPrinter;
  153. SingleLabelPrinter.Text = Properties.Settings.Default.SPrinter;
  154. asc.controllInitializeSize(this);
  155. asc.controlAutoSize(this);
  156. RefreshDBConnect.Interval = 60000;
  157. RefreshDBConnect.Start();
  158. }
  159. //只执行一次窗体自适应
  160. bool AutoSized = false;
  161. private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
  162. {
  163. if (!AutoSized)
  164. {
  165. asc.controlAutoSize(this);
  166. AutoSized = true;
  167. }
  168. }
  169. private void LabelMaintain_Click(object sender, EventArgs e)
  170. {
  171. 客户标签维护 form = new 客户标签维护();
  172. BaseUtil.SetFormCenter(form);
  173. form.FormClosed += LabelFormClose;
  174. form.ShowDialog();
  175. }
  176. private void LabelFormClose(object sender, EventArgs e)
  177. {
  178. GetInOutInfAndLabelFile();
  179. }
  180. //输入框Enter事件
  181. private void Input_KeyDown(object sender, KeyEventArgs e)
  182. {
  183. if (e.KeyCode == Keys.Enter)
  184. {
  185. if (Input.Text == "")
  186. {
  187. MessageBox.Show("采集的数据不能为空");
  188. return;
  189. }
  190. CollectInputData();
  191. }
  192. }
  193. /// <summary>
  194. /// 采集数据
  195. /// </summary>
  196. private void CollectInputData()
  197. {
  198. if (Input.Text == "SC")
  199. {
  200. PrintStatus.PerformClick();
  201. Input.Text = "";
  202. return;
  203. }
  204. Input.Text = Input.Text.Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "");
  205. Dictionary<string, string> Data = new Dictionary<string, string>();
  206. string[] SplitData = Input.Text.Split('*');
  207. if (SplitData.Length < 5)
  208. {
  209. MessageBox.Show("数据格式错误,无法解析", "提示");
  210. Input.SelectAll();
  211. return;
  212. }
  213. for (int i = 0; i < SplitData.Length; i++)
  214. {
  215. switch (i.ToString())
  216. {
  217. case "0":
  218. Data.Add("PRCODE", SplitData[i]);
  219. break;
  220. case "1":
  221. Data.Add("QTY", SplitData[i]);
  222. break;
  223. case "2":
  224. Data.Add("DATECODE", SplitData[i]);
  225. break;
  226. case "3":
  227. Data.Add("BRAND", SplitData[i]);
  228. break;
  229. case "4":
  230. Data.Add("LOTNO", SplitData[i]);
  231. break;
  232. case "5":
  233. Data.Add("PO", SplitData[i]);
  234. break;
  235. case "6":
  236. Data.Add("SERIAL", SplitData[i]);
  237. break;
  238. default:
  239. break;
  240. }
  241. }
  242. //校验DateCode是否过期
  243. if (!CheckDateCode(Data["DATECODE"]))
  244. {
  245. string close = MessageBox.Show(this.ParentForm, "物料" + Data["PRCODE"] + "【DateCode】超出校验日期,是否继续", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  246. if (close != "Yes")
  247. {
  248. Input.SelectAll();
  249. return;
  250. }
  251. }
  252. if (Data["PRCODE"] != CurrentPrCode)
  253. {
  254. MessageBox.Show("当前采集【物料编号】不对应,请重新采集", "提示");
  255. Input.SelectAll();
  256. return;
  257. }
  258. if (Data["BRAND"] != CurrentBrand)
  259. {
  260. string close = MessageBox.Show(this.ParentForm, "当前采集【品牌】不对应,是否继续采集", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  261. if (close != "Yes")
  262. {
  263. Input.SelectAll();
  264. return;
  265. }
  266. }
  267. int CodeCount = 0;
  268. //如果单位是KPCS则需要除1000
  269. double CollectNum = 0;
  270. if (CurrentUnit == "KPCS")
  271. {
  272. try
  273. {
  274. double.Parse(CurrentZXBZ);
  275. }
  276. catch (Exception)
  277. {
  278. MessageBox.Show("请检查最小包装数");
  279. }
  280. //如果单位是KPCS则必须是1000的整数倍
  281. if (int.Parse((Convert.ToDouble((double.Parse(Data["QTY"]) / 1000).ToString("0.000")) / Convert.ToDouble(double.Parse(CurrentZXBZ).ToString("0.000"))).ToString()) % 1 != 0)
  282. {
  283. MessageBox.Show("物料" + Data["PRCODE"] + "采集数量无法按照最小包装数拆分", "提示");
  284. Input.SelectAll();
  285. return;
  286. }
  287. CodeCount = int.Parse((double.Parse(Data["QTY"]) / 1000 / double.Parse(CurrentZXBZ)).ToString());
  288. CollectNum = double.Parse(Data["QTY"]) / 1000;
  289. }
  290. else
  291. {
  292. if (double.Parse(Data["QTY"]) % double.Parse(CurrentZXBZ) != 0)
  293. {
  294. MessageBox.Show("采集【数量】无法按照最小包装数拆分", "提示");
  295. Input.SelectAll();
  296. return;
  297. }
  298. CodeCount = int.Parse((double.Parse(Data["QTY"]) / double.Parse(CurrentZXBZ)).ToString());
  299. CollectNum = double.Parse(Data["QTY"]);
  300. }
  301. string pib_barcode = Data.ContainsKey("SERIAL") ? Data["SERIAL"] : "";
  302. //获取ID
  303. PIBID = dh.GetSEQ("prodiobarcode_seq", CodeCount);
  304. string pib_outboxcode2 = "";
  305. if (OutBoxNum.Text == "新增")
  306. {
  307. string maxoutbox = dh.getFieldDataByCondition("prodiobarcode", "max(to_number(pib_outboxcode2))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  308. //如果没有则从开始插入
  309. if (maxoutbox == "")
  310. {
  311. pib_outboxcode2 = "1";
  312. }
  313. else
  314. {
  315. pib_outboxcode2 = (int.Parse(maxoutbox) + 1).ToString();
  316. }
  317. }
  318. else
  319. {
  320. pib_outboxcode2 = OutBoxNum.Text;
  321. }
  322. if (OutBoxNum.Text == "全部")
  323. {
  324. MessageBox.Show("请选择指定箱号或者新增");
  325. return;
  326. }
  327. //加载完数据之后进行容量的判断
  328. int BoxNum = LabelInfDataTable.Select("pib_outboxcode2='" + OutBoxNum.Text + "'").Length;
  329. if (BoxNum + CodeCount > OutboxCapacity.Value)
  330. {
  331. string close = MessageBox.Show(this.ParentForm, "箱号【" + OutBoxNum.Text + "】后超数量为" + (BoxNum + CodeCount) + ",超出容量" + OutboxCapacity.Value + ",是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  332. if (close != "Yes")
  333. {
  334. Input.SelectAll();
  335. return;
  336. }
  337. }
  338. //计算当前采集数量
  339. string collectqty = dh.getFieldDataByCondition("prodiobarcode", "sum(pib_qty)", "pib_inoutno='" + pi_inoutno.Text + "' and pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString();
  340. double CollectQty = (collectqty == "" ? 0 : double.Parse(collectqty));
  341. if (Convert.ToDouble((CollectQty + CollectNum).ToString("0.000")) > Convert.ToDouble(double.Parse(CurrentPrCount).ToString("0.000")))
  342. {
  343. MessageBox.Show("物料" + Data["PRCODE"] + "采集后数量为" + (CollectQty + CollectNum) + ",【超出】本行出货数量" + CurrentPrCount, "提示");
  344. Input.SelectAll();
  345. return;
  346. }
  347. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, CodeCount);
  348. List<string> CustBarCode = new List<string>();
  349. if (!(Radix > 0))
  350. {
  351. string close = MessageBox.Show(this.ParentForm, "未维护条码规则,是否继续生成", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  352. if (close.ToString() != "Yes")
  353. return;
  354. }
  355. for (int i = 0; i < CodeCount; i++)
  356. {
  357. if (Radix > 0)
  358. {
  359. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  360. for (int j = serialcode.ToString().Length; j < NumLength; j++)
  361. {
  362. serialcode = "0" + serialcode;
  363. }
  364. CustBarCode.Add(Prefix + serialcode + Suffix);
  365. MaxNum = MaxNum + 1;
  366. }
  367. else
  368. {
  369. CustBarCode.Add("");
  370. }
  371. }
  372. sql.Clear();
  373. sql.Append("insert into prodiobarcode(PIB_ID,PIB_PRODCODE,PIB_INDATE,PIB_INOUTNO,PIB_PIID,PIB_PDNO, PIB_PDID,PIB_PICLASS,");
  374. 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,pib_midcapatity,pib_custcode) ");
  375. sql.Append("select :PIB_ID,pd_prodcode,sysdate,pi_inoutno,pi_id,pd_pdno,pd_id,pi_class,");
  376. sql.Append("'" + pib_barcode + "',:PIB_CUSTBARCODE,'" + CurrentZXBZ + "','" + Data["BRAND"] + "','" + Data["DATECODE"] + "','" + Data["LOTNO"] + "','" + pib_outboxcode2 + "','" + User.UserCode + "','" + (EnablePrint && SingleLabelAutoPrint.Checked ? 1 : 0).ToString() + "',pd_ordercode,pd_pocode,pd_remark,'" + MidboxCapacity.Value + "','" + pi_cardcode.Text + "' ");
  377. 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 + "'");
  378. int rowsnum = 0;
  379. try
  380. {
  381. rowsnum = dh.BatchInsert(sql.ToString(), new string[] { "PIB_ID", "PIB_CUSTBARCODE" }, PIBID, CustBarCode.ToArray());
  382. }
  383. catch (Exception)
  384. {
  385. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "' and rmn_prefix='" + Prefix + "'");
  386. CollectInputData();
  387. return;
  388. }
  389. if (rowsnum == 0)
  390. {
  391. MessageBox.Show("未成功插入数据,请核对出货单当前明细", "提示");
  392. }
  393. //更新流水号
  394. LoadGridData(new object(), new EventArgs());
  395. if (LabelInf.Rows.Count > 0)
  396. {
  397. LabelInf.Rows[LabelInf.Rows.Count - 1].Selected = true;
  398. }
  399. if (SingleLabelAutoPrint.Checked)
  400. {
  401. thread = new Thread(AutoPrintSingleLabel);
  402. stw = new SetLoadingWindow(thread, "正在打印单盘标签");
  403. BaseUtil.SetFormCenter(stw);
  404. stw.ShowDialog();
  405. }
  406. //采集后重新计数,自动跳到下一行
  407. collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  408. CollectQty = (collectqty == "" ? 0 : double.Parse(collectqty));
  409. int combined = 0;
  410. if (Combindetail.Checked)
  411. combined = 1;
  412. if (CombindetailTwo.Checked)
  413. combined = 2;
  414. dh.UpdateByCondition("CS$InoutPrcode", "Collectednum='" + CollectQty + "'", "pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + CurrentPDNO + "' and combined=" + combined);
  415. CollectNum = 0;
  416. double OutNum = 0;
  417. if (GridPrcode.SelectedRows.Count > 0)
  418. {
  419. GridPrcode.Rows[GridPrcode.SelectedRows[0].Index].Cells["CollectedNum"].Value = CollectQty;
  420. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  421. {
  422. CollectNum += float.Parse(GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString());
  423. OutNum += float.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString());
  424. }
  425. }
  426. ProcessCount.Text = CollectNum + "/" + OutNum;
  427. if (CollectNum == OutNum)
  428. {
  429. dh.UpdateByCondition("prodinout", "pi_user_packingstatus='Packed'", "pi_inoutno='" + pi_inoutno.Text + "'");
  430. }
  431. //采集达到了数量进行换行
  432. if (CollectQty == double.Parse(CurrentPrCount))
  433. {
  434. DataGridViewSelectedRowCollection selectrow = GridPrcode.SelectedRows;
  435. if (selectrow.Count > 0)
  436. {
  437. if (selectrow[0].Index + 1 < GridPrcode.Rows.Count)
  438. {
  439. string outqty = GridPrcode.Rows[selectrow[0].Index + 1].Cells["pd_outqty"].Value.ToString();
  440. string collectnum = GridPrcode.Rows[selectrow[0].Index + 1].Cells["CollectedNum"].Value.ToString();
  441. if (double.Parse(outqty) > double.Parse(collectnum == "" ? "0" : collectnum))
  442. {
  443. GridPrcode.Rows[selectrow[0].Index + 1].Selected = true;
  444. }
  445. }
  446. }
  447. }
  448. Input.Clear();
  449. if (OutBoxNum.Text == "新增")
  450. {
  451. OutBoxNum.Items.Clear();
  452. DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by to_number(pib_outboxcode2) desc", "select");
  453. ItemObject io = new ItemObject("新增", "新增");
  454. OutBoxNum.Items.Add(io);
  455. io = new ItemObject("全部", "全部");
  456. OutBoxNum.Items.Add(io);
  457. for (int i = 0; i < dt.Rows.Count; i++)
  458. {
  459. string piboutboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  460. io = new ItemObject(piboutboxcode2, piboutboxcode2);
  461. OutBoxNum.Items.Add(io);
  462. }
  463. if (OutBoxNum.Items.Count > 2)
  464. OutBoxNum.SelectedIndex = 2;
  465. }
  466. }
  467. private void AutoPrintSingleLabel()
  468. {
  469. if (EnablePrint)
  470. {
  471. //用标签本身的变量作为最外层的循环条件去匹配;
  472. StringBuilder ParamLog = new StringBuilder();
  473. string pibid = "";
  474. for (int i = 0; i < PIBID.Length; i++)
  475. {
  476. if (i != PIBID.Length - 1)
  477. pibid += PIBID[i] + ",";
  478. else
  479. pibid += PIBID[i];
  480. }
  481. if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  482. SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
  483. for (int j = 0; j < SingleReport.Parameters.Count; j++)
  484. {
  485. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, "");
  486. for (int k = 0; k < Attach.Rows.Count; k++)
  487. {
  488. if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name)
  489. {
  490. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  491. }
  492. }
  493. }
  494. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiosingleinfo_view where 主键ID in (" + pibid + ")", "select");
  495. SingleReport.RegisterData(dt, "prodiosingleinfo_view");
  496. SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true;
  497. SingleReport.PrintSettings.ShowDialog = false;
  498. SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  499. try
  500. {
  501. SingleReport.Print();
  502. }
  503. catch (Exception e)
  504. {
  505. MessageBox.Show(e.Message);
  506. return;
  507. }
  508. Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text;
  509. Properties.Settings.Default.Save();
  510. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "自动打印箱标", "打印成功");
  511. }
  512. }
  513. //关闭窗口前提示用户确认
  514. private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
  515. {
  516. //如果不是注销的话
  517. if (!logout)
  518. {
  519. string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  520. if (close.ToString() != "Yes")
  521. e.Cancel = true;
  522. else
  523. {
  524. LogManager.DoLog("关闭程序");
  525. }
  526. }
  527. }
  528. /// <summary>
  529. /// 获取打印标签
  530. /// </summary>
  531. private void GetInOutInfAndLabelFile()
  532. {
  533. ComBoxClickChangeLabelDoc = false;
  534. sql.Clear();
  535. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelurl,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 ");
  536. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  537. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='单盘' order by cl_custcode,cl_date desc");
  538. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  539. SingleLabelCombox.DisplayMember = "cl_labelname";
  540. SingleLabelCombox.ValueMember = "cl_labelurl";
  541. SingleLabelCombox.DataSource = dt;
  542. sql.Clear();
  543. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelurl,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 ");
  544. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  545. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='中盒' order by cl_custcode,cl_date desc");
  546. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  547. MidLabelCombox.DisplayMember = "cl_labelname";
  548. MidLabelCombox.ValueMember = "cl_labelurl";
  549. MidLabelCombox.DataSource = dt;
  550. sql.Clear();
  551. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelurl,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 ");
  552. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  553. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='外箱' order by cl_custcode,cl_date desc");
  554. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  555. OutBoxCombox.DisplayMember = "cl_labelname";
  556. OutBoxCombox.ValueMember = "cl_labelurl";
  557. OutBoxCombox.DataSource = dt;
  558. ComBoxClickChangeLabelDoc = true;
  559. }
  560. bool LoadCheck = true;
  561. /// <summary>
  562. /// 出入库单录入框的回车事件
  563. /// </summary>
  564. /// <param name="sender"></param>
  565. /// <param name="e"></param>
  566. private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
  567. {
  568. if (e.KeyCode == Keys.Enter)
  569. {
  570. LoadCheck = false;
  571. Combindetail.Checked = false;
  572. CombindetailTwo.Checked = false;
  573. LoadCheck = true;
  574. Input.Clear();
  575. sql.Clear();
  576. sql.Append("select pi_id,pi_cardcode,pi_combine_user,pi_title,to_char(pi_date,'yyyymmdd')pi_date,nvl(pi_combine_user,0)pi_combine_user from prodinout where pi_inoutno='" + pi_inoutno.Text + "' /*and pi_invostatuscode='AUDITED'*/");
  577. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  578. if (dt.Rows.Count > 0)
  579. {
  580. pi_cardcode.Text = dt.Rows[0]["pi_cardcode"].ToString();
  581. pi_title.Text = dt.Rows[0]["pi_title"].ToString();
  582. pi_date.Text = dt.Rows[0]["pi_date"].ToString();
  583. PI_ID = dt.Rows[0]["pi_id"].ToString();
  584. switch (dt.Rows[0]["pi_combine_user"].ToString())
  585. {
  586. case "1":
  587. Combindetail.Checked = true;
  588. break;
  589. case "2":
  590. CombindetailTwo.Checked = true;
  591. break;
  592. default:
  593. break;
  594. }
  595. if (pi_cardcode.Text != "ZGCC")
  596. {
  597. CustomerLabel.Enabled = false;
  598. }
  599. else
  600. {
  601. CustomerLabel.Enabled = true;
  602. }
  603. OutBoxNum_Click(new object(), new EventArgs());
  604. LoadPrcodeData();
  605. //获取条码规则
  606. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, 1);
  607. SingleID.Clear();
  608. Input.Focus();
  609. ////从后往前找未采集的行
  610. for (int i = GridPrcode.Rows.Count - 1; i >= 0; i--)
  611. {
  612. string outqty = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  613. string collectnum = GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString();
  614. if (double.Parse(outqty) > double.Parse(collectnum == "" ? "0" : collectnum))
  615. {
  616. GridPrcode.Rows[i].Selected = true;
  617. if (i - 2 >= 0)
  618. GridPrcode.FirstDisplayedScrollingRowIndex = i - 2;
  619. else
  620. GridPrcode.FirstDisplayedScrollingRowIndex = i;
  621. }
  622. }
  623. bi_inman.Text = dh.getFieldDataByCondition("barcodeio left join employee on bi_inman=em_code", "wm_concat(distinct em_name)", "bi_piid=" + PI_ID).ToString();
  624. pib_inman.Text = dh.getFieldDataByCondition("prodiobarcode left join employee on pib_inman=em_code", "wm_concat(distinct em_name)", "pib_piid=" + PI_ID).ToString();
  625. Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LABELATTACHPARAMETER where lap_custcode='" + pi_cardcode.Text + "' and lap_inman='" + User.UserCode + "'", "select");
  626. thread = new Thread(GetInOutInfAndLabelFile);
  627. stw = new SetLoadingWindow(thread, "正在获取打印标签");
  628. BaseUtil.SetFormCenter(stw);
  629. stw.ShowDialog();
  630. LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
  631. }
  632. else MessageBox.Show("当前出入库单号不存在或者未审核!", "提示");
  633. }
  634. }
  635. private void SingleBoxPrint()
  636. {
  637. if (EnablePrint)
  638. {
  639. if (LabelInf.Rows.Count > 0)
  640. {
  641. //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
  642. SingleID.Clear();
  643. //获取全部的中盒号
  644. Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
  645. //判断所有盒号为该盒的是否勾选已采集
  646. outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
  647. for (int i = 0; i < LabelInf.Rows.Count; i++)
  648. {
  649. if (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()))
  650. SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  651. }
  652. if (SingleID.ToArray().Length == 0)
  653. {
  654. MessageBox.Show("选择的行未勾选采集或者已打印", "提示");
  655. return;
  656. }
  657. for (int i = 0; i < LabelInf.RowCount; i++)
  658. {
  659. if (i + 1 < LabelInf.RowCount)
  660. {
  661. //如果本行的中盒号和下一行不相等的话
  662. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString())
  663. {
  664. if (!outboxcode1.ContainsKey(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  665. outboxcode1.Add(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString(), true);
  666. }
  667. }
  668. }
  669. string pibid = "";
  670. for (int i = 0; i < LabelInf.RowCount; i++)
  671. {
  672. //勾选了并且未打印
  673. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue != null && LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true")
  674. {
  675. pibid += LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + ",";
  676. LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
  677. }
  678. }
  679. if (pibid != "")
  680. {
  681. if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  682. SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
  683. for (int j = 0; j < SingleReport.Parameters.Count; j++)
  684. {
  685. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, "");
  686. for (int k = 0; k < Attach.Rows.Count; k++)
  687. {
  688. if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name)
  689. {
  690. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  691. }
  692. }
  693. }
  694. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiosingleinfo_view where 主键ID in (" + pibid.Substring(0, pibid.Length - 1) + ")", "select");
  695. SingleReport.RegisterData(dt, "prodiosingleinfo_view");
  696. SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true;
  697. //保存参数打印
  698. SingleReport.PrintSettings.ShowDialog = false;
  699. SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  700. try
  701. {
  702. SingleReport.Print();
  703. }
  704. catch (Exception e)
  705. {
  706. MessageBox.Show(e.Message);
  707. return;
  708. }
  709. Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text;
  710. Properties.Settings.Default.Save();
  711. }
  712. else
  713. {
  714. MessageBox.Show("未勾选打印明细", "提示", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  715. }
  716. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印盘标", "打印成功");
  717. dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray());
  718. outboxcode1.Clear();
  719. }
  720. else
  721. {
  722. MessageBox.Show("此模板尚未维护参数或不存在打印明细", "提示");
  723. return;
  724. }
  725. }
  726. }
  727. private void SingleLabelPrint_Click(object sender, EventArgs e)
  728. {
  729. if (SingleLabelCombox.Text != "")
  730. {
  731. if (SingleBoxBegin.Text != "" || SingleBoxEnd.Text != "")
  732. {
  733. try
  734. {
  735. int begin = int.Parse(SingleBoxBegin.Text == "" ? "1" : SingleBoxBegin.Text);
  736. int end = int.Parse(SingleBoxEnd.Text == "" ? LabelInf.Rows.Count.ToString() : SingleBoxEnd.Text);
  737. if (begin > 0 && end <= LabelInf.Rows.Count && begin <= end)
  738. {
  739. for (int i = begin - 1; i < end; i++)
  740. {
  741. LabelInf.Rows[i].Cells["Choose"].Value = true;
  742. LabelInf.Rows[i].Cells["pib_ifprint"].Value = false;
  743. }
  744. }
  745. else
  746. {
  747. MessageBox.Show("单盘打印范围错误", "提示");
  748. return;
  749. }
  750. }
  751. catch (Exception)
  752. {
  753. MessageBox.Show("单盘打印范围错误", "提示");
  754. return;
  755. }
  756. }
  757. thread = new Thread(SingleBoxPrint);
  758. stw = new SetLoadingWindow(thread, "正在打印单盘");
  759. BaseUtil.SetFormCenter(stw);
  760. stw.ShowDialog();
  761. Input.Focus();
  762. }
  763. else
  764. {
  765. MessageBox.Show("未维护单盘标签", "提示");
  766. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印盘标", "打印失败,未维护标签");
  767. }
  768. }
  769. private void MidBoxLabelPrint()
  770. {
  771. //未输入内容打印全部中盒
  772. if (MidLabelNum.Text == "")
  773. {
  774. int begin = 0;
  775. int end = 0;
  776. if (MidBoxBegin.Text != "" || MidBoxEnd.Text != "")
  777. {
  778. try
  779. {
  780. begin = int.Parse(MidBoxBegin.Text == "" ? "1" : MidBoxBegin.Text);
  781. end = int.Parse(MidBoxEnd.Text == "" ? LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString() : MidBoxEnd.Text);
  782. int minmidbox = int.Parse(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString());
  783. int maxmidbox = int.Parse(LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString());
  784. if (begin >= minmidbox && end <= maxmidbox && begin <= end)
  785. {
  786. //设置中盒打印范围的行号
  787. for (int i = 0; i < LabelInf.Rows.Count; i++)
  788. {
  789. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == begin)
  790. {
  791. begin = i;
  792. }
  793. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == end)
  794. {
  795. end = i;
  796. }
  797. }
  798. }
  799. else
  800. {
  801. MessageBox.Show("中盒打印范围错误", "提示");
  802. return;
  803. }
  804. }
  805. catch (Exception)
  806. {
  807. MessageBox.Show("中盒打印范围错误", "提示");
  808. return;
  809. }
  810. }
  811. List<int> MidOutBoxCode = new List<int>();
  812. List<int> MidOutBoxCodeIndex = new List<int>();
  813. for (int i = (begin == 0 ? 0 : begin); i <= (end == 0 ? LabelInf.Rows.Count - 1 : end); i++)
  814. {
  815. try
  816. {
  817. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  818. {
  819. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  820. MidOutBoxCodeIndex.Add(i);
  821. }
  822. }
  823. catch (Exception)
  824. {
  825. MessageBox.Show("请先封箱!");
  826. return;
  827. }
  828. }
  829. //如果有选中行
  830. if (SelectRowIndex >= 0)
  831. {
  832. MidOutBoxCode.Clear();
  833. MidOutBoxCodeIndex.Clear();
  834. SelectProdcode = LabelInf.Rows[SelectRowIndex].Cells["pib_prodcode"].Value.ToString();
  835. for (int i = SelectRowIndex; i >= 0; i--)
  836. {
  837. if ((LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() == SelectProdcode && LabelInf.Rows[i].Cells["pib_midifprint"].FormattedValue.ToString().ToLower() != "true") || i == SelectRowIndex)
  838. {
  839. LabelInf.Rows[i].Cells["pib_midifprint"].Value = true;
  840. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  841. {
  842. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  843. MidOutBoxCodeIndex.Add(i);
  844. }
  845. }
  846. else
  847. {
  848. break;
  849. }
  850. }
  851. for (int i = SelectRowIndex; i < LabelInf.Rows.Count - 1; i++)
  852. {
  853. if ((LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() == SelectProdcode && LabelInf.Rows[i].Cells["pib_midifprint"].FormattedValue.ToString().ToLower() != "true") || i == SelectRowIndex)
  854. {
  855. LabelInf.Rows[i].Cells["pib_midifprint"].Value = true;
  856. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  857. {
  858. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  859. MidOutBoxCodeIndex.Add(i);
  860. }
  861. }
  862. else
  863. {
  864. break;
  865. }
  866. }
  867. }
  868. try
  869. {
  870. MidBoxCodePrint(MidOutBoxCodeIndex.ToArray());
  871. }
  872. catch (Exception e)
  873. {
  874. MessageBox.Show(e.Message);
  875. return;
  876. }
  877. return;
  878. }
  879. bool FindMidLabel = false;
  880. if (MidLabelCombox.SelectedValue != null)
  881. {
  882. //中盒号所在的行
  883. int MidLabelRowIndex = 0;
  884. //缓存中盒数据
  885. for (int i = 0; i < LabelInf.RowCount; i++)
  886. {
  887. if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  888. {
  889. //找到了输入的中盒号停止循环
  890. FindMidLabel = true;
  891. MidLabelRowIndex = i;
  892. }
  893. }
  894. int[] rowindx = new int[] { MidLabelRowIndex };
  895. //找到了指定的盒号
  896. if (FindMidLabel)
  897. MidBoxCodePrint(rowindx);
  898. else
  899. MessageBox.Show("该出入库单未找到该中盒号!", "提示");
  900. }
  901. else
  902. MessageBox.Show("未维护中盒模板", "提示");
  903. }
  904. private void MidLabelPrint_Click(object sender, EventArgs e)
  905. {
  906. if (MidLabelCombox.Text != "")
  907. {
  908. PackMidBox_Click(sender, e);
  909. thread = new Thread(MidBoxLabelPrint);
  910. stw = new SetLoadingWindow(thread, "正在打印中盒");
  911. BaseUtil.SetFormCenter(stw);
  912. stw.ShowDialog();
  913. }
  914. else
  915. MessageBox.Show("未维护中盒标签", "提示");
  916. Input.Focus();
  917. }
  918. private void OutBoxPrint()
  919. {
  920. List<string> Outboxcode = new List<string>();
  921. //如果未勾选箱号则对勾选的数据的箱号进行整合
  922. if (OutBoxNum.Text == "" || OutBoxNum.Text == "全部")
  923. {
  924. for (int i = 0; i < LabelInf.RowCount; i++)
  925. {
  926. string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  927. //富为使用包装单的逻辑
  928. //如果不包含该箱号则进行添加
  929. if (!Outboxcode.Contains(outboxcode2))
  930. Outboxcode.Add(outboxcode2);
  931. }
  932. //按获取到的箱号列表进行打印
  933. if (Outboxcode.ToArray().Length > 0)
  934. {
  935. for (int i = 0; i < Outboxcode.ToArray().Length; i++)
  936. {
  937. for (int h = 0; h < LabelInf.RowCount; h++)
  938. {
  939. if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i])
  940. {
  941. if (!AllLabel.Checked)
  942. OutBoxCodePrint(h);
  943. else
  944. OutBoxCodePrint(h, true);
  945. break;
  946. }
  947. }
  948. }
  949. }
  950. else
  951. {
  952. MessageBox.Show("请勾选需要打印的外箱", "提示");
  953. }
  954. }
  955. else
  956. {
  957. bool FindMidLabel = false;
  958. try
  959. {
  960. int OutBoxLabelRowIndex = 0;
  961. //查找是否存在该中盒号
  962. for (int i = 0; i < LabelInf.RowCount; i++)
  963. {
  964. if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString())
  965. {
  966. //找到了输入的中盒号停止循环
  967. FindMidLabel = true;
  968. OutBoxLabelRowIndex = i;
  969. break;
  970. }
  971. }
  972. //找到了指定的盒号
  973. if (FindMidLabel)
  974. {
  975. if (!AllLabel.Checked)
  976. OutBoxCodePrint(OutBoxLabelRowIndex);
  977. else
  978. OutBoxCodePrint(OutBoxLabelRowIndex, true);
  979. }
  980. else
  981. MessageBox.Show("该出入库单未找到该外箱号!", "提示");
  982. }
  983. catch (Exception) { }
  984. }
  985. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印箱标" + OutBoxNum.Text, "打印成功");
  986. Outboxcode.Clear();
  987. }
  988. private void MidBoxCodePrint(int[] rowindex)
  989. {
  990. if (EnablePrint)
  991. {
  992. string pib_outboxcode1 = "";
  993. for (int i = 0; i < rowindex.Length; i++)
  994. {
  995. if (i != rowindex.Length - 1)
  996. pib_outboxcode1 += "'" + LabelInf.Rows[rowindex[i]].Cells["pib_outboxcode1"].Value.ToString() + "'" + ",";
  997. else
  998. pib_outboxcode1 += "'" + LabelInf.Rows[rowindex[i]].Cells["pib_outboxcode1"].Value.ToString() + "'";
  999. }
  1000. //名称相等的时候,取SQL进行值的查询
  1001. DataTable dt;
  1002. if (MidLabelAutoPrint.Checked)
  1003. {
  1004. if (CurrentRowOnly.Checked)
  1005. {
  1006. string PDNO = "";
  1007. if (SelectRowIndex >= 0)
  1008. {
  1009. PDNO = LabelInf.Rows[SelectRowIndex].Cells["pib_pdno"].Value.ToString();
  1010. }
  1011. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ") and 出货序号='" + (PDNO == "" ? CurrentPDNO : PDNO) + "'", "select");
  1012. }
  1013. else
  1014. {
  1015. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ")", "select");
  1016. }
  1017. }
  1018. else
  1019. {
  1020. if (CurrentRowOnly.Checked)
  1021. {
  1022. string PDNO = "";
  1023. if (SelectRowIndex >= 0)
  1024. {
  1025. PDNO = LabelInf.Rows[SelectRowIndex].Cells["pib_pdno"].Value.ToString();
  1026. }
  1027. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ") and 中盒标识='外' and 出货序号='" + (PDNO == "" ? CurrentPDNO : PDNO) + "'", "select");
  1028. }
  1029. else
  1030. {
  1031. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ") and 中盒标识='外'", "select");
  1032. }
  1033. }
  1034. if (dt.Rows.Count > 0)
  1035. {
  1036. if (!MidLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1037. MidReport.Load(MidLabelCombox.SelectedValue.ToString());
  1038. for (int j = 0; j < MidReport.Parameters.Count; j++)
  1039. {
  1040. MidReport.SetParameterValue(MidReport.Parameters[j].Name, "");
  1041. for (int i = 0; i < Attach.Rows.Count; i++)
  1042. {
  1043. if (Attach.Rows[i][0].ToString() == MidReport.Parameters[j].Name)
  1044. {
  1045. MidReport.SetParameterValue(MidReport.Parameters[j].Name, Attach.Rows[i][1].ToString());
  1046. }
  1047. }
  1048. }
  1049. MidReport.RegisterData(dt, "prodiomidinfo_view");
  1050. MidReport.GetDataSource("prodiomidinfo_view").Enabled = true;
  1051. MidReport.PrintSettings.ShowDialog = false;
  1052. MidReport.PrintSettings.Printer = MidLabelPrinter.Text;
  1053. MidReport.Print();
  1054. dh.UpdateByCondition("prodiobarcode", "pib_midifprint=-1", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1 in (" + pib_outboxcode1 + ")");
  1055. SelectRowIndex = -1;
  1056. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "打印中盒" + pib_outboxcode1.Replace("'", ""), "打印成功");
  1057. }
  1058. Properties.Settings.Default.MPrinter = MidLabelPrinter.Text;
  1059. Properties.Settings.Default.Save();
  1060. }
  1061. }
  1062. /// <summary>
  1063. /// 执行打印外箱号
  1064. /// </summary>
  1065. private void OutBoxCodePrint(int rowindex)
  1066. {
  1067. if (EnablePrint)
  1068. {
  1069. if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1070. OutReport.Load(OutBoxCombox.SelectedValue.ToString());
  1071. for (int j = 0; j < OutReport.Parameters.Count; j++)
  1072. {
  1073. OutReport.SetParameterValue(OutReport.Parameters[j].Name, "");
  1074. for (int i = 0; i < Attach.Rows.Count; i++)
  1075. {
  1076. if (Attach.Rows[i][0].ToString() == OutReport.Parameters[j].Name)
  1077. {
  1078. OutReport.SetParameterValue(OutReport.Parameters[j].Name, Attach.Rows[i][1].ToString());
  1079. }
  1080. }
  1081. }
  1082. string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
  1083. string SQL = "";
  1084. if (OnlyOneRow.Checked)
  1085. {
  1086. SQL = "select * from prodiooutinfo_view where 出货单号 = '" + pi_inoutno.Text + "' and 外箱号 = '" + pib_outboxcode2 + "' and rownum=1";
  1087. }
  1088. else
  1089. {
  1090. SQL = "select * from prodiooutinfo_view where 出货单号 = '" + pi_inoutno.Text + "' and 外箱号 = '" + pib_outboxcode2 + "'";
  1091. }
  1092. DataTable dt = (DataTable)dh.ExecuteSql(SQL, "select");
  1093. OutReport.RegisterData(dt, "prodiooutinfo_view");
  1094. OutReport.GetDataSource("prodiooutinfo_view").Enabled = true;
  1095. OutReport.PrintSettings.ShowDialog = false;
  1096. OutReport.PrintSettings.Printer = OutBoxPrinter.Text;
  1097. OutReport.Print();
  1098. Properties.Settings.Default.OPrinter = OutBoxPrinter.Text;
  1099. Properties.Settings.Default.Save();
  1100. dh.UpdateByCondition("prodiobarcode", "pib_outifprint=-1", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + pib_outboxcode2 + "'");
  1101. }
  1102. }
  1103. /// <summary>
  1104. /// 执行打印外箱号
  1105. /// </summary>
  1106. private void OutBoxCodePrint(int rowindex, bool AllLabel)
  1107. {
  1108. if (EnablePrint)
  1109. {
  1110. int selectedindex = OutBoxCombox.SelectedIndex;
  1111. for (int i = 0; i < OutBoxCombox.Items.Count; i++)
  1112. {
  1113. OutBoxCombox.SelectedIndex = i;
  1114. if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1115. OutReport.Load(OutBoxCombox.SelectedValue.ToString());
  1116. for (int j = 0; j < OutReport.Parameters.Count; j++)
  1117. {
  1118. OutReport.SetParameterValue(OutReport.Parameters[j].Name, "");
  1119. for (int k = 0; k < Attach.Rows.Count; k++)
  1120. {
  1121. if (Attach.Rows[k][0].ToString() == OutReport.Parameters[j].Name)
  1122. {
  1123. OutReport.SetParameterValue(OutReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  1124. }
  1125. }
  1126. }
  1127. string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
  1128. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiooutinfo_view where 出货单号='" + pi_inoutno.Text + "' and 外箱号='" + pib_outboxcode2 + "'", "select");
  1129. OutReport.RegisterData(dt, "prodiooutinfo_view");
  1130. OutReport.GetDataSource("prodiooutinfo_view").Enabled = true;
  1131. OutReport.PrintSettings.ShowDialog = false;
  1132. OutReport.PrintSettings.Printer = OutBoxPrinter.Text;
  1133. OutReport.Print();
  1134. }
  1135. OutBoxCombox.SelectedIndex = selectedindex;
  1136. Properties.Settings.Default.OPrinter = OutBoxPrinter.Text;
  1137. Properties.Settings.Default.Save();
  1138. dh.UpdateByCondition("prodiobarcode", "pib_outifprint=-1", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + pib_outboxcode2 + "'");
  1139. }
  1140. }
  1141. private void CleanDetail_Click(object sender, EventArgs e)
  1142. {
  1143. if (dh.getFieldDataByCondition("prodinout", "pi_statuscode", "pi_inoutno='" + pi_inoutno.Text + "'").ToString() == "POSTED")
  1144. {
  1145. //MessageBox.Show("单据" + pi_inoutno.Text + "已过账,不允许删除条码");
  1146. //return;
  1147. }
  1148. ArrayList<string> DeleteID = new ArrayList<string>();
  1149. for (int i = 0; i < LabelInf.RowCount; i++)
  1150. {
  1151. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true")
  1152. DeleteID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1153. }
  1154. //勾选了删除的明细之后
  1155. if (DeleteID.ToArray().Length > 0)
  1156. {
  1157. string close = MessageBox.Show(this.ParentForm, "删除后不可恢复,是否确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1158. if (close.ToString() == "Yes")
  1159. {
  1160. dh.BatchInsert("delete from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray());
  1161. dh.UpdateByCondition("CS$InoutPrcode", "collectednum=(select nvl(sum(pib_qty),0) from prodiobarcode where pib_inoutno=pd_inoutno and pib_pdno=pd_pdno)", "pd_inoutno='" + pi_inoutno.Text + "'");
  1162. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "删除明细", "删除明细成功");
  1163. MessageBox.Show("删除成功", "提示");
  1164. Input.Clear();
  1165. LoadPrcodeData();
  1166. LoadGridData(sender, e);
  1167. if (int.Parse(dh.getFieldDataByCondition("prodiobarcode", "count(1)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString()) == 0)
  1168. {
  1169. dh.UpdateByCondition("prodinout", "pi_user_packingstatus=''", "pi_inoutno='" + pi_inoutno.Text + "'");
  1170. }
  1171. else
  1172. {
  1173. dh.UpdateByCondition("prodinout", "pi_user_packingstatus='Packing'", "pi_inoutno='" + pi_inoutno.Text + "'");
  1174. }
  1175. }
  1176. }
  1177. else
  1178. MessageBox.Show("尚未勾选需要删除的明细", "提示");
  1179. }
  1180. private void OutBoxLabelPrint_Click(object sender, EventArgs e)
  1181. {
  1182. if (OutBoxCombox.Text != "")
  1183. {
  1184. Pack_Click(sender, e);
  1185. if (Weight.Text != "" && Weight.Text != "0.000")
  1186. {
  1187. //记录整箱的重量
  1188. sql.Clear();
  1189. sql.Append("update prodiobarcode set pib_totalweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  1190. sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "'");
  1191. dh.ExecuteSql(sql.ToString(), "update");
  1192. }
  1193. LoadGridData(sender, e);
  1194. thread = new Thread(OutBoxPrint);
  1195. stw = new SetLoadingWindow(thread, "正在打印外箱");
  1196. BaseUtil.SetFormCenter(stw);
  1197. stw.ShowDialog();
  1198. Input.Focus();
  1199. }
  1200. else
  1201. MessageBox.Show("未维护外箱标签", "提示");
  1202. Input.Focus();
  1203. }
  1204. /// <summary>
  1205. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  1206. /// </summary>
  1207. /// <param name="sender"></param>
  1208. /// <param name="e"></param>
  1209. private void LoadGridData(object sender, EventArgs e)
  1210. {
  1211. AllChecked = false;
  1212. sql.Clear();
  1213. sql.Append("select pib_boxweight,pib_totalweight,pd_custprodcode,pd_custprodspec,nvl(pib_midifprint,0)pib_midifprint,pib_custmidboxcode,pd_pocode,pjd_orispeccode,pib_madein,pib_custbarcode,pib_custoutboxcode,pib_id,pib_datecode1,pib_pdid,pib_piid,");
  1214. sql.Append("pib_pdno,pib_prodcode,pib_brand,pr_vendprodcode,pib_lotno,pib_datecode,week_to_date(pib_datecode) datecode1,pib_qty,pr_spec,");
  1215. sql.Append("pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,pib_outboxcode2,nvl(pib_ifprint,0)pib_ifprint from prodiobarcode left join ");
  1216. 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 ");
  1217. 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 + "' ");
  1218. if (OutBoxNum.Text != "全部")
  1219. {
  1220. sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "' ");
  1221. }
  1222. sql.Append(" order by to_number(pib_outboxcode2),pib_id,pd_prodcode");
  1223. LabelInfDataTable = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1224. BoxCount.Text = LabelInfDataTable.Compute("sum(pib_qty)", "1=1").ToString() + "KPCS";
  1225. bindingsource(LabelInf, LabelInfDataTable);
  1226. if (LabelInf.Rows.Count > 0)
  1227. {
  1228. LabelInf.FirstDisplayedScrollingRowIndex = LabelInf.Rows.Count - 1;
  1229. }
  1230. sql.Clear();
  1231. sql.Append("select pib_pdno,pib_prodcode,sum(pib_qty) pib_qty from prodiodetail left join prodiobarcode on pd_id=pib_pdid and pd_pdno=pib_pdno ");
  1232. sql.Append("where pib_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno ");
  1233. SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1234. }
  1235. private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1236. {
  1237. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  1238. pi_inoutno_KeyDown(sender, e2);
  1239. }
  1240. private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1241. {
  1242. string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1243. if (close.ToString() == "Yes")
  1244. {
  1245. Login login = new Login();
  1246. //注销的时候需要将拼接的连接字符串置空
  1247. DataHelper.DBConnectionString = null;
  1248. logout = true;
  1249. this.Hide();
  1250. login.ShowDialog();
  1251. this.Close();
  1252. }
  1253. }
  1254. private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1255. /// <summary>
  1256. /// 切换打开的单盘文件
  1257. /// </summary>
  1258. /// <param name="sender"></param>
  1259. /// <param name="e"></param>
  1260. private void SingleLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1261. {
  1262. try
  1263. {
  1264. if (ComBoxClickChangeLabelDoc)
  1265. {
  1266. if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1267. SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
  1268. }
  1269. }
  1270. catch (Exception) { }
  1271. }
  1272. /// <summary>
  1273. /// 切换打开的中盒文件
  1274. /// </summary>
  1275. /// <param name="sender"></param>
  1276. /// <param name="e"></param>
  1277. private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1278. {
  1279. try
  1280. {
  1281. if (ComBoxClickChangeLabelDoc)
  1282. {
  1283. if (!MidLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1284. MidReport.Load(MidLabelCombox.SelectedValue.ToString());
  1285. }
  1286. }
  1287. catch (Exception) { }
  1288. }
  1289. /// <summary>
  1290. /// 切换打开的外箱文件
  1291. /// </summary>
  1292. /// <param name="sender"></param>
  1293. /// <param name="e"></param>
  1294. private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e)
  1295. {
  1296. try
  1297. {
  1298. if (ComBoxClickChangeLabelDoc)
  1299. {
  1300. if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1301. OutReport.Load(OutBoxCombox.SelectedValue.ToString());
  1302. }
  1303. }
  1304. catch (Exception) { }
  1305. }
  1306. private void ChooseAll_Click(object sender, EventArgs e)
  1307. {
  1308. if (AllChecked)
  1309. {
  1310. foreach (DataGridViewRow dr in LabelInf.Rows)
  1311. dr.Cells[0].Value = false;
  1312. AllChecked = false;
  1313. }
  1314. else
  1315. {
  1316. foreach (DataGridViewRow dr in LabelInf.Rows)
  1317. dr.Cells[0].Value = true;
  1318. AllChecked = true;
  1319. }
  1320. }
  1321. private void ExportData_Click(object sender, EventArgs e)
  1322. {
  1323. ExportFileDialog.Description = "选择导出的路径";
  1324. DialogResult result = ExportFileDialog.ShowDialog();
  1325. if (result == DialogResult.OK)
  1326. {
  1327. ExcelHandler eh = new ExcelHandler();
  1328. DataTable dt = LabelInfDataTable.Copy();
  1329. for (int i = dt.Columns.Count - 1; i >= 0; i--)
  1330. {
  1331. for (int j = 0; j < LabelInf.Columns.Count; j++)
  1332. {
  1333. //去除ID列
  1334. 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")
  1335. {
  1336. dt.Columns.RemoveAt(i);
  1337. break;
  1338. }
  1339. switch (dt.Columns[i].ColumnName.ToLower())
  1340. {
  1341. case "pib_lotno":
  1342. dt.Columns[i].ColumnName = "批次号";
  1343. break;
  1344. case "pib_datecode":
  1345. dt.Columns[i].ColumnName = "生产年周";
  1346. break;
  1347. case "pib_custbarcode":
  1348. dt.Columns[i].ColumnName = "最小产品包装条码";
  1349. break;
  1350. case "datecode1":
  1351. dt.Columns[i].ColumnName = "生产日期";
  1352. break;
  1353. default:
  1354. break;
  1355. }
  1356. if (dt.Columns[i].ColumnName.ToLower() == LabelInf.Columns[j].DataPropertyName.ToLower())
  1357. {
  1358. dt.Columns[i].ColumnName = LabelInf.Columns[j].HeaderText;
  1359. break;
  1360. }
  1361. }
  1362. }
  1363. eh.ExportExcel(dt, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text);
  1364. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1365. if (close.ToString() == "Yes")
  1366. Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + ".xls");
  1367. }
  1368. }
  1369. private void AttachInfo_Click(object sender, EventArgs e)
  1370. {
  1371. if (pi_cardcode.Text != "")
  1372. {
  1373. 附件内容打印 att = new 附件内容打印(pi_cardcode.Text);
  1374. att.ShowDialog();
  1375. }
  1376. else MessageBox.Show("请先获取出库单信息", "提示");
  1377. }
  1378. private void MidBoxCapacity_Leave(object sender, EventArgs e)
  1379. {
  1380. NumericUpDown nup = (NumericUpDown)sender;
  1381. switch (nup.Name)
  1382. {
  1383. case "MidBoxCapacity":
  1384. Properties.Settings.Default.MidBoxCapacity = nup.Value;
  1385. Properties.Settings.Default.Save();
  1386. break;
  1387. case "OutboxCapacity":
  1388. Properties.Settings.Default.OutboxCapacity = nup.Value;
  1389. Properties.Settings.Default.Save();
  1390. break;
  1391. default:
  1392. break;
  1393. }
  1394. }
  1395. private void RefreshDBConnect_Tick(object sender, EventArgs e)
  1396. {
  1397. dh.ExecuteSql("select sysdate from dual", "select");
  1398. }
  1399. DataTable CSPrcode;
  1400. private void LoadPrcodeData()
  1401. {
  1402. DataTable Prcode = (DataTable)dh.ExecuteSql("select '' pd_piid,pd_inoutno,pd_custprodcode,pd_pocode,pd_whcode,pd_prodcode,'0' CollectedNum,'0' UnCollectedNum,pd_outqty,pr_unit,pd_brand,pjd_zxbzs_user,pjd_id,pd_pdno,pr_spec 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");
  1403. GridPrcode.DataSource = Prcode;
  1404. List<int> RemoveIndex = new List<int>();
  1405. double CollectNum = 0;
  1406. double OutNum = 0;
  1407. int combined = 0;
  1408. if (Combindetail.Checked)
  1409. combined = 1;
  1410. if (CombindetailTwo.Checked)
  1411. combined = 2;
  1412. if (Combindetail.Checked || CombindetailTwo.Checked)
  1413. {
  1414. CSPrcode = (DataTable)dh.ExecuteSql("select pd_piid,pd_pdno,pd_custprodcode,pd_whcode,pd_prodcode,CollectedNum,UnCollectedNum,pd_outqty,pr_unit,pr_spec,pd_brand,pjd_zxbzs_user,pjd_id,pd_inoutno,pd_pocode from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "' and combined=" + combined + " order by pd_pdno", "select");
  1415. if (CSPrcode.Rows.Count == 0)
  1416. {
  1417. int CurrentIndex = 0;
  1418. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1419. {
  1420. string CurrentPrCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1421. string CurrentPDNO = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  1422. string CurrentOutQTY = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  1423. string collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  1424. CollectNum += double.Parse(collectqty == "" ? "0" : collectqty);
  1425. OutNum += double.Parse(CurrentOutQTY);
  1426. GridPrcode.Rows[i].Cells["CollectedNum"].Value = collectqty == "" ? "0" : collectqty;
  1427. }
  1428. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1429. {
  1430. if (i + 1 < GridPrcode.Rows.Count)
  1431. {
  1432. string BProdCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1433. string BCustProdCode = GridPrcode.Rows[i].Cells["pd_custprodcode1"].Value.ToString();
  1434. string BWhCode = GridPrcode.Rows[i].Cells["pd_whcode"].Value.ToString();
  1435. string BPrUnit = GridPrcode.Rows[i].Cells["pr_unit"].Value.ToString();
  1436. string BPrBrand = GridPrcode.Rows[i].Cells["pd_brand"].Value.ToString();
  1437. string BPoCode = GridPrcode.Rows[i].Cells["pd_pocode1"].Value.ToString();
  1438. string FProdCode = GridPrcode.Rows[i + 1].Cells["pd_prodcode"].Value.ToString();
  1439. string FCustProdCode = GridPrcode.Rows[i + 1].Cells["pd_custprodcode1"].Value.ToString();
  1440. string FPrUnit = GridPrcode.Rows[i + 1].Cells["pr_unit"].Value.ToString();
  1441. string FrBrand = GridPrcode.Rows[i + 1].Cells["pd_brand"].Value.ToString();
  1442. string FWhCode = GridPrcode.Rows[i + 1].Cells["pd_whcode"].Value.ToString();
  1443. string FPoCode = GridPrcode.Rows[i + 1].Cells["pd_pocode1"].Value.ToString();
  1444. if (BProdCode == FProdCode && BPrBrand == FrBrand && BCustProdCode == FCustProdCode && (CombindetailTwo.Checked && FPoCode == BPoCode || Combindetail.Checked))
  1445. {
  1446. GridPrcode.Rows[CurrentIndex].Cells["pd_outqty"].Value = double.Parse(GridPrcode.Rows[CurrentIndex].Cells["pd_outqty"].Value.ToString()) + double.Parse(GridPrcode.Rows[i + 1].Cells["pd_outqty"].Value.ToString());
  1447. GridPrcode.Rows[CurrentIndex].Cells["CollectedNum"].Value = double.Parse(GridPrcode.Rows[CurrentIndex].Cells["CollectedNum"].Value.ToString()) + double.Parse(GridPrcode.Rows[i + 1].Cells["CollectedNum"].Value.ToString());
  1448. RemoveIndex.Add(i + 1);
  1449. }
  1450. else
  1451. {
  1452. CurrentIndex = i + 1;
  1453. }
  1454. }
  1455. }
  1456. foreach (int item in RemoveIndex.OrderByDescending(x => x))
  1457. {
  1458. (GridPrcode.DataSource as DataTable).Rows.RemoveAt(item);
  1459. }
  1460. }
  1461. else GridPrcode.DataSource = CSPrcode;
  1462. }
  1463. else
  1464. {
  1465. CSPrcode = (DataTable)dh.ExecuteSql("select pd_piid,pd_pdno,pd_custprodcode,pd_whcode,pd_prodcode,CollectedNum,UnCollectedNum,pd_outqty,pr_unit,pr_spec,pd_brand,pjd_zxbzs_user,pjd_id,pd_inoutno,pd_pocode from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "' and combined=" + combined + " order by pd_pdno", "select");
  1466. if (CSPrcode.Rows.Count == 0)
  1467. {
  1468. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1469. {
  1470. string CurrentPrCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1471. string CurrentPDNO = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  1472. string CurrentOutQTY = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  1473. string collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  1474. CollectNum += double.Parse(collectqty == "" ? "0" : collectqty);
  1475. OutNum += double.Parse(CurrentOutQTY);
  1476. GridPrcode.Rows[i].Cells["CollectedNum"].Value = collectqty == "" ? "0" : collectqty;
  1477. }
  1478. }
  1479. else GridPrcode.DataSource = CSPrcode;
  1480. }
  1481. dh.UpdateByCondition("prodinout", "pi_combine_user=" + combined, "pi_inoutno='" + pi_inoutno.Text + "'");
  1482. if (CSPrcode.Rows.Count == 0)
  1483. {
  1484. sql.Clear();
  1485. sql.Append("insert into CS$InoutPrcode (pd_piid,pd_pdno,pd_custprodcode,pd_whcode,pd_prodcode,");
  1486. sql.Append("CollectedNum,UnCollectedNum,pd_outqty,pr_unit,pr_spec,pd_brand,pjd_zxbzs_user,pjd_id,pd_inoutno,combined,pd_pocode)");
  1487. sql.Append("values ('',:pd_pdno,:pd_custprodcode,:pd_whcode,:pd_prodcode,:CollectedNum,:UnCollectedNum,:pd_outqty,:pr_unit,:pr_spec,:pd_brand,:pjd_zxbzs_user,:pjd_id,:pd_inoutno,'" + combined + "',:pd_pocode)");
  1488. dh.SaveDataTable((GridPrcode.DataSource as DataTable), "CS$InoutPrcode", "pd_piid", sql.ToString());
  1489. }
  1490. else
  1491. {
  1492. CollectNum = float.Parse(CSPrcode.Compute("sum(CollectedNum)", "1=1").ToString());
  1493. OutNum = float.Parse(CSPrcode.Compute("sum(pd_outqty)", "1=1").ToString());
  1494. }
  1495. ProcessCount.Text = CollectNum + "/" + OutNum;
  1496. if (GridPrcode.Rows.Count > 0)
  1497. {
  1498. CurrentPrCode = GridPrcode.Rows[0].Cells["pd_prodcode"].Value.ToString();
  1499. CurrentZXBZ = GridPrcode.Rows[0].Cells["pjd_zxbzs_user"].Value.ToString();
  1500. CurrentUnit = GridPrcode.Rows[0].Cells["pr_unit"].Value.ToString();
  1501. CurrentPDNO = GridPrcode.Rows[0].Cells["pd_pdno"].Value.ToString();
  1502. CurrentPrCount = GridPrcode.Rows[0].Cells["pd_outqty"].Value.ToString();
  1503. CurrentBrand = GridPrcode.Rows[0].Cells["pd_brand"].Value.ToString();
  1504. GridPrcode.Rows[0].Selected = true;
  1505. }
  1506. }
  1507. private void OutBoxNum_Click(object sender, EventArgs e)
  1508. {
  1509. string OutBox = OutBoxNum.Text;
  1510. OutBoxNum.Items.Clear();
  1511. DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by to_number(pib_outboxcode2) desc", "select");
  1512. ItemObject io = new ItemObject("新增", "新增");
  1513. OutBoxNum.Items.Add(io);
  1514. io = new ItemObject("全部", "全部");
  1515. OutBoxNum.Items.Add(io);
  1516. for (int i = 0; i < dt.Rows.Count; i++)
  1517. {
  1518. string pib_outboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  1519. io = new ItemObject(pib_outboxcode2, pib_outboxcode2);
  1520. OutBoxNum.Items.Add(io);
  1521. }
  1522. if (OutBoxNum.Text == "新增" || OutBoxNum.Text == "")
  1523. {
  1524. if (dt.Rows.Count > 0)
  1525. OutBoxNum.SelectedIndex = 2;
  1526. else
  1527. OutBoxNum.SelectedIndex = 0;
  1528. }
  1529. if (OutBox != "新增" && OutBox != "")
  1530. OutBoxNum.Text = OutBox;
  1531. }
  1532. /// <summary>
  1533. /// 获取条码规则
  1534. /// </summary>
  1535. /// <param name="Type"></param>
  1536. /// <param name="Prefix"></param>
  1537. /// <param name="Suffix"></param>
  1538. /// <param name="MaxNum"></param>
  1539. /// <param name="SerialNumLength"></param>
  1540. /// <param name="Radix"></param>
  1541. private void GetBarCodeRule(out string Prefix, out string Suffix, out int MaxNum, out int SerialNumLength, out int Radix, int Count)
  1542. {
  1543. //获取编码规则
  1544. Prefix = "";
  1545. Suffix = "";
  1546. MaxNum = 0;
  1547. SerialNumLength = 0;
  1548. Radix = 0;
  1549. 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");
  1550. //如果没有则取公共规则
  1551. if (Nr.Rows.Count == 0)
  1552. 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");
  1553. //用于过滤参数的正则表达式
  1554. Regex match = new Regex("{\\w+}");
  1555. //用于存放每一项的明细的数据
  1556. string[] NrData = new string[Nr.Rows.Count];
  1557. //流水长度
  1558. Dictionary<int, string> NrDic = new Dictionary<int, string>();
  1559. Prefix = "";
  1560. for (int m = 0; m < Nr.Rows.Count; m++)
  1561. {
  1562. switch (Nr.Rows[m]["nrd_type"].ToString())
  1563. {
  1564. //常量直接进行拼接
  1565. case "常量":
  1566. Prefix += Nr.Rows[m]["nrd_sql"].ToString();
  1567. Suffix += Nr.Rows[m]["nrd_sql"].ToString();
  1568. break;
  1569. case "SQL":
  1570. string SQL = Nr.Rows[m]["nrd_sql"].ToString();
  1571. DataTable Temp;
  1572. //如果不包含参数替换
  1573. if (SQL.IndexOf("{") == 0)
  1574. {
  1575. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  1576. }
  1577. else
  1578. {
  1579. SQL = SQL.Replace("{pd_pdno}", CurrentPDNO);
  1580. //替换参数后重新执行SQL
  1581. foreach (Match mch in match.Matches(SQL))
  1582. {
  1583. SQL = SQL.Replace(mch.Value.Trim(), "'" + pi_inoutno.Text + "'");
  1584. }
  1585. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  1586. }
  1587. if (Temp.Rows.Count > 0)
  1588. {
  1589. Prefix += Temp.Rows[0][0].ToString();
  1590. Suffix += Temp.Rows[0][0].ToString();
  1591. }
  1592. break;
  1593. //流水需要通过MaxNumber去取
  1594. case "流水":
  1595. string maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "' and rmn_prefix='" + Prefix + "'").ToString();
  1596. //设置当前流水
  1597. if (maxnum == "")
  1598. {
  1599. dh.ExecuteSql("insert into RuleMaxNum(rmn_id,rmn_nrcode,rmn_prefix,rmn_maxnumber) values(RuleMaxNum_seq.nextval,'" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "','" + Prefix + "','" + Count + "')", "insert");
  1600. MaxNum = 1;
  1601. }
  1602. else
  1603. {
  1604. MaxNum = int.Parse(maxnum);
  1605. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + Count) + "'", "rmn_nrcode='" + (pi_cardcode.Text == "" ? "Default" : pi_cardcode.Text) + "' and rmn_prefix='" + Prefix + "'");
  1606. }
  1607. SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
  1608. Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString());
  1609. Suffix = "";
  1610. break;
  1611. default:
  1612. break;
  1613. }
  1614. }
  1615. }
  1616. private void GridPrcode_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  1617. {
  1618. string Value = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  1619. string ID = GridPrcode.Rows[e.RowIndex].Cells["pjd_id"].Value.ToString();
  1620. dh.UpdateByCondition("PRODJOINVENDDETAIL", "pjd_zxbzs_user='" + Value + "'", "pjd_id='" + ID + "'");
  1621. dh.UpdateByCondition("CS$INOUTPRCODE", "pjd_zxbzs_user='" + Value + "'", "pjd_id='" + ID + "' and pd_inoutno='" + pi_inoutno.Text + "'");
  1622. //删除对应物料的明细
  1623. CurrentPrCode = GridPrcode.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString();
  1624. CurrentZXBZ = GridPrcode.Rows[e.RowIndex].Cells["pjd_zxbzs_user"].Value.ToString();
  1625. CurrentUnit = GridPrcode.Rows[e.RowIndex].Cells["pr_unit"].Value.ToString();
  1626. CurrentPDNO = GridPrcode.Rows[e.RowIndex].Cells["pd_pdno"].Value.ToString();
  1627. CurrentPrCount = GridPrcode.Rows[e.RowIndex].Cells["pd_outqty"].Value.ToString();
  1628. CurrentBrand = GridPrcode.Rows[e.RowIndex].Cells["pd_brand"].Value.ToString();
  1629. GridPrcode.Rows[e.RowIndex].Selected = true;
  1630. if (e.RowIndex - 2 >= 0)
  1631. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex - 2;
  1632. else
  1633. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex;
  1634. LoadGridData(sender, new EventArgs());
  1635. }
  1636. private void GridPrcode_SelectionChanged(object sender, EventArgs e)
  1637. {
  1638. if (GridPrcode.SelectedRows.Count > 0)
  1639. {
  1640. DataGridViewSelectedRowCollection dsc = GridPrcode.SelectedRows;
  1641. CurrentPrCode = GridPrcode.Rows[dsc[0].Index].Cells["pd_prodcode"].Value.ToString();
  1642. CurrentZXBZ = GridPrcode.Rows[dsc[0].Index].Cells["pjd_zxbzs_user"].Value.ToString();
  1643. CurrentUnit = GridPrcode.Rows[dsc[0].Index].Cells["pr_unit"].Value.ToString();
  1644. CurrentPDNO = GridPrcode.Rows[dsc[0].Index].Cells["pd_pdno"].Value.ToString();
  1645. CurrentPrCount = GridPrcode.Rows[dsc[0].Index].Cells["pd_outqty"].Value.ToString();
  1646. CurrentBrand = GridPrcode.Rows[dsc[0].Index].Cells["pd_brand"].Value.ToString();
  1647. GridPrcode.Rows[dsc[0].Index].Selected = true;
  1648. if (dsc[0].Index - 2 >= 0)
  1649. GridPrcode.FirstDisplayedScrollingRowIndex = dsc[0].Index - 2;
  1650. else
  1651. GridPrcode.FirstDisplayedScrollingRowIndex = dsc[0].Index;
  1652. }
  1653. }
  1654. private void GridPrcode_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1655. private void GridPrcode_CellClick(object sender, DataGridViewCellEventArgs e)
  1656. {
  1657. if (e.RowIndex >= 0)
  1658. {
  1659. GridPrcode.Rows[e.RowIndex].Selected = true;
  1660. if (e.RowIndex - 2 > 0)
  1661. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex - 2;
  1662. else
  1663. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex;
  1664. }
  1665. }
  1666. private void DCCheck_Leave(object sender, EventArgs e)
  1667. {
  1668. try
  1669. {
  1670. Properties.Settings.Default.DCCheck = int.Parse(DCCheck.Text);
  1671. Properties.Settings.Default.Save();
  1672. }
  1673. catch (Exception)
  1674. {
  1675. MessageBox.Show("DC校验时间必须是整数");
  1676. }
  1677. }
  1678. /// <summary>
  1679. /// 校验DateCode
  1680. /// </summary>
  1681. /// <param name="DateCode"></param>
  1682. private bool CheckDateCode(string DateCode)
  1683. {
  1684. try
  1685. {
  1686. //根据DateCode计算的日期
  1687. string Year = DateCode.Substring(0, 2);
  1688. System.DateTime dt = new System.DateTime(int.Parse("20" + Year), 01, 01);
  1689. string Week = DateCode.Substring(2, 2);
  1690. System.DateTime dt1 = dt.AddDays(int.Parse(Week) * 7);
  1691. //减去DC校验后的日期
  1692. System.DateTime now = System.DateTime.Now;
  1693. System.DateTime now1 = now.AddDays(-int.Parse(DCCheck.Text));
  1694. //物料的DateCode大于限制日期即可
  1695. if (dt1 > now1)
  1696. {
  1697. return true;
  1698. }
  1699. return false;
  1700. }
  1701. catch (Exception)
  1702. {
  1703. return false;
  1704. }
  1705. }
  1706. private void PrintFooter_Click(object sender, EventArgs e)
  1707. {
  1708. FootReport.Load(@"\\10.2.10.238\PRINTE\FASTREPORT\唛头.frx");
  1709. 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 to_number(pib_outboxcode2)", "select");
  1710. string SQL = "select pib_outboxcode2||'/'||(select max(to_number(pib_outboxcode2)) from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "') from prodiobarcode where pib_id=";
  1711. for (int i = 0; i < dt.Rows.Count; i++)
  1712. {
  1713. DataTable dt1 = (DataTable)dh.ExecuteSql(SQL + dt.Rows[i]["pib_id"].ToString(), "select");
  1714. FootReport.SetParameterValue("唛头", dt1.Rows[0][0].ToString());
  1715. FootReport.PrintSettings.ShowDialog = false;
  1716. FootReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  1717. FootReport.Print();
  1718. }
  1719. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "打印唛头", "成功");
  1720. }
  1721. private void Input_KeyUp(object sender, KeyEventArgs e)
  1722. {
  1723. if (e.KeyCode == Keys.Enter)
  1724. {
  1725. Input.SelectAll();
  1726. }
  1727. }
  1728. private void GridPrcode_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  1729. {
  1730. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  1731. if (e.ColumnIndex > 0 && e.RowIndex >= 0)
  1732. {
  1733. if (GridPrcode.Columns[e.ColumnIndex].Name == "CollectedNum")
  1734. {
  1735. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1736. if (GridPrcode.Rows[e.RowIndex].Cells["CollectedNum"].Value.ToString() != GridPrcode.Rows[e.RowIndex].Cells["pd_outqty"].Value.ToString())
  1737. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.Yellow, e.CellBounds);
  1738. else
  1739. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.White, e.CellBounds);
  1740. Rectangle border = e.CellBounds;
  1741. border.Width -= 1;
  1742. e.Graphics.DrawRectangle(Pens.White, border);
  1743. e.PaintContent(e.CellBounds);
  1744. e.Handled = true;
  1745. }
  1746. }
  1747. }
  1748. private void GridPrcode_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
  1749. {
  1750. if (e.Button == MouseButtons.Right)
  1751. {
  1752. if (e.RowIndex >= 0 && e.ColumnIndex > 0)
  1753. {
  1754. string Conetent = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  1755. Clipboard.SetText(Conetent);
  1756. MessageBox.Show("已复制内容" + Conetent);
  1757. }
  1758. }
  1759. }
  1760. private void Pack_Click(object sender, EventArgs e)
  1761. {
  1762. if (LabelInf.Rows.Count > 0)
  1763. {
  1764. int GetNumCount = 1;
  1765. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1766. {
  1767. if (LabelInf.Rows[i].Cells["pib_custoutboxcode"].Value.ToString() == "")
  1768. {
  1769. if (i + 1 < LabelInf.Rows.Count)
  1770. {
  1771. string FPrcode = LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString();
  1772. string FPocode = LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString();
  1773. string FWhcode = LabelInf.Rows[i].Cells["pib_brand"].Value.ToString();
  1774. string FDC = LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString();
  1775. string FLOTNO = LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString();
  1776. string FPDCustProdCode = LabelInf.Rows[i].Cells["pd_custprodcode"].Value.ToString();
  1777. string BPrcode = LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString();
  1778. string BPocode = LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString();
  1779. string BWhcode = LabelInf.Rows[i + 1].Cells["pib_brand"].Value.ToString();
  1780. string BDC = LabelInf.Rows[i + 1].Cells["pib_datecode"].Value.ToString();
  1781. string BLOTNO = LabelInf.Rows[i + 1].Cells["pib_lotno"].Value.ToString();
  1782. string BPDCustProdCode = LabelInf.Rows[i + 1].Cells["pd_custprodcode"].Value.ToString();
  1783. if (FPDCustProdCode != BPDCustProdCode || FPrcode != BPrcode || FPocode != BPocode || FWhcode != BWhcode || (DiffDC.Checked && FDC != BDC) || (DiffLotNo.Checked && FLOTNO != BLOTNO))
  1784. {
  1785. GetNumCount = GetNumCount + 1;
  1786. }
  1787. }
  1788. }
  1789. }
  1790. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, GetNumCount);
  1791. List<string> OutBoxCode = new List<string>();
  1792. List<string> PIBID = new List<string>();
  1793. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1794. {
  1795. if (LabelInf.Rows[i].Cells["pib_custoutboxcode"].Value.ToString() == "")
  1796. {
  1797. PIBID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1798. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  1799. for (int k = serialcode.ToString().Length; k < NumLength; k++)
  1800. {
  1801. serialcode = "0" + serialcode;
  1802. }
  1803. if (i + 1 < LabelInf.Rows.Count)
  1804. {
  1805. string FPrcode = LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString();
  1806. string FPocode = LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString();
  1807. string FWhcode = LabelInf.Rows[i].Cells["pib_brand"].Value.ToString();
  1808. string FDC = LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString();
  1809. string FLOTNO = LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString();
  1810. string BPrcode = LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString();
  1811. string BPocode = LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString();
  1812. string BWhcode = LabelInf.Rows[i + 1].Cells["pib_brand"].Value.ToString();
  1813. string BDC = LabelInf.Rows[i + 1].Cells["pib_datecode"].Value.ToString();
  1814. string BLOTNO = LabelInf.Rows[i + 1].Cells["pib_lotno"].Value.ToString();
  1815. if (FPrcode != BPrcode || FPocode != BPocode || FWhcode != BWhcode || (DiffDC.Checked && FDC != BDC) || (DiffLotNo.Checked && FLOTNO != BLOTNO))
  1816. {
  1817. MaxNum = MaxNum + 1;
  1818. }
  1819. }
  1820. OutBoxCode.Add(Prefix + serialcode + Suffix);
  1821. }
  1822. }
  1823. dh.BatchInsert("update prodiobarcode set pib_custoutboxcode=:pib_custoutboxcode where pib_id=:pib_id and pib_custoutboxcode is null", new string[] { "pib_custoutboxcode", "pib_outboxcode2" }, OutBoxCode.ToArray(), PIBID.ToArray());
  1824. LoadGridData(sender, e);
  1825. }
  1826. }
  1827. private void PackMidBox_Click(object sender, EventArgs e)
  1828. {
  1829. DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by pib_outboxcode2", "select");
  1830. DataTable dt1 = null;
  1831. int GetNumCount = 0;
  1832. for (int i = 0; i < dt.Rows.Count; i++)
  1833. {
  1834. dt1 = (DataTable)dh.ExecuteSql("select pib_id,pib_prodcode,pd_custprodcode from prodiobarcode left join prodiodetail on pib_pdid=pd_id 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");
  1835. //如果不是10的整数倍则为尾盒
  1836. int tencount = 0;
  1837. for (int j = 0; j < dt1.Rows.Count; j++)
  1838. {
  1839. if (tencount % MidboxCapacity.Value == 0 || (dt1.Rows[j]["pib_prodcode"].ToString() != dt1.Rows[j - 1]["pib_prodcode"].ToString()) || (dt1.Rows[j]["pd_custprodcode"].ToString() != dt1.Rows[j - 1]["pd_custprodcode"].ToString()))
  1840. {
  1841. GetNumCount = GetNumCount + 1;
  1842. }
  1843. tencount = tencount + 1;
  1844. }
  1845. }
  1846. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, GetNumCount);
  1847. if (Radix > 0)
  1848. {
  1849. //生成中盒条码
  1850. int pib_outboxcode1 = int.Parse(dh.getFieldDataByCondition("prodiobarcode", "max(to_number(nvl(pib_outboxcode1,0)))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString());
  1851. MaxNum = MaxNum - 1;
  1852. for (int i = 0; i < dt.Rows.Count; i++)
  1853. {
  1854. List<string> MidBoxCode = new List<string>();
  1855. List<string> PIBID = new List<string>();
  1856. List<string> PIBOUTBOXCODE1 = new List<string>();
  1857. dt1 = (DataTable)dh.ExecuteSql("select pib_id,pib_prodcode,pd_custprodcode from prodiobarcode left join prodiodetail on pib_pdid=pd_id 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");
  1858. //如果不是10的整数倍则为尾盒
  1859. int tencount = 0;
  1860. for (int j = 0; j < dt1.Rows.Count; j++)
  1861. {
  1862. if (tencount % MidboxCapacity.Value == 0 || (dt1.Rows[j]["pib_prodcode"].ToString() != dt1.Rows[j - 1]["pib_prodcode"].ToString()) || (dt1.Rows[j]["pd_custprodcode"].ToString() != dt1.Rows[j - 1]["pd_custprodcode"].ToString()))
  1863. {
  1864. pib_outboxcode1 = pib_outboxcode1 + 1;
  1865. MaxNum = MaxNum + 1;
  1866. tencount = 0;
  1867. }
  1868. tencount = tencount + 1;
  1869. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  1870. for (int k = serialcode.ToString().Length; k < NumLength; k++)
  1871. {
  1872. serialcode = "0" + serialcode;
  1873. }
  1874. MidBoxCode.Add(Prefix + serialcode + Suffix);
  1875. PIBID.Add(dt1.Rows[j]["pib_id"].ToString());
  1876. PIBOUTBOXCODE1.Add(pib_outboxcode1.ToString());
  1877. }
  1878. 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());
  1879. }
  1880. }
  1881. LoadGridData(sender, e);
  1882. }
  1883. private void PrintStatus_Click(object sender, EventArgs e)
  1884. {
  1885. EnablePrint = !EnablePrint;
  1886. if (EnablePrint)
  1887. {
  1888. SetPrintStatus_label.ForeColor = Color.Green;
  1889. SetPrintStatus_label.Text = "可打印";
  1890. }
  1891. else
  1892. {
  1893. SetPrintStatus_label.ForeColor = Color.Red;
  1894. SetPrintStatus_label.Text = "暂停打印";
  1895. }
  1896. Input.Focus();
  1897. }
  1898. private void CustomerLabel_Click(object sender, EventArgs e)
  1899. {
  1900. sql.Clear();
  1901. sql.Append("update prodiobarcode set pib_custbarcode=case when instr(pib_custbarcode,'SL')=0 ");
  1902. sql.Append("then ('SL'||pib_custbarcode)else pib_custbarcode end, pib_custoutboxcode=case when instr");
  1903. sql.Append("(pib_custoutboxcode,'SC')=0 then ('SC'||pib_custoutboxcode)else pib_custoutboxcode end where pib_inoutno='" + pi_inoutno.Text + "'");
  1904. dh.ExecuteSql(sql.ToString(), "select");
  1905. LoadGridData(sender, e);
  1906. CustomerLabel.Enabled = false;
  1907. }
  1908. private void Combindetail_CheckedChanged(object sender, EventArgs e)
  1909. {
  1910. if (Combindetail.Checked)
  1911. {
  1912. CombindetailTwo.Checked = false;
  1913. }
  1914. if (LoadCheck)
  1915. {
  1916. LoadPrcodeData();
  1917. string response = "";
  1918. string[] param = new string[] { PI_ID, "1", response };
  1919. dh.CallProcedure("USER_PRODOUT_GROUPQTY", param);
  1920. }
  1921. }
  1922. private void CombindetailTwo_CheckedChanged(object sender, EventArgs e)
  1923. {
  1924. if (CombindetailTwo.Checked)
  1925. {
  1926. Combindetail.Checked = false;
  1927. }
  1928. if (LoadCheck)
  1929. {
  1930. LoadPrcodeData();
  1931. string response = "";
  1932. string[] param = new string[] { PI_ID, "2", response };
  1933. dh.CallProcedure("USER_PRODOUT_GROUPQTY", param);
  1934. }
  1935. }
  1936. string SelectProdcode = "";
  1937. int SelectRowIndex = -1;
  1938. private void LabelInf_CellClick(object sender, DataGridViewCellEventArgs e)
  1939. {
  1940. if (e.RowIndex >= 0)
  1941. {
  1942. LabelInf.Rows[e.RowIndex].Selected = true;
  1943. SelectRowIndex = e.RowIndex;
  1944. }
  1945. }
  1946. private void OutBoxNum_SelectedIndexChanged(object sender, EventArgs e)
  1947. {
  1948. OutBoxNum1 = OutBoxNum.Text;
  1949. LoadGridData(sender, e);
  1950. }
  1951. private void LabelInf_SelectionChanged(object sender, EventArgs e)
  1952. {
  1953. DataGridViewSelectedRowCollection dsc = LabelInf.SelectedRows;
  1954. if (dsc.Count > 0)
  1955. {
  1956. SelectRowIndex = dsc[0].Index;
  1957. }
  1958. }
  1959. string OutBoxNum1 = "";
  1960. private void OutBoxNum_SelectionChangeCommitted(object sender, EventArgs e)
  1961. {
  1962. if (OutBoxNum1 != "全部" && OutBoxNum1 != "新增")
  1963. if (dh.getFieldDataByCondition("prodiobarcode", "pib_outifprint", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + OutBoxNum1 + "'").ToString() != "-1")
  1964. {
  1965. MessageBox.Show("外箱号" + OutBoxNum1 + "尚未打印标签");
  1966. }
  1967. OutBoxNum1 = OutBoxNum.Text;
  1968. }
  1969. private void Reset_Click(object sender, EventArgs e)
  1970. {
  1971. string close = MessageBox.Show(this.ParentForm, "清除当前已采集数据,刷新待采集数据", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1972. if (close.ToString() == "Yes")
  1973. {
  1974. dh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  1975. dh.ExecuteSql("delete from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "'", "delete");
  1976. dh.UpdateByCondition("prodinout", "pi_user_packingstatus=''", "pi_inoutno='" + pi_inoutno.Text + "'");
  1977. pi_inoutno_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  1978. }
  1979. }
  1980. private void AddNewOutBox_Click(object sender, EventArgs e)
  1981. {
  1982. OutBoxNum.Text = "新增";
  1983. }
  1984. private void GetPDdata_Click(object sender, EventArgs e)
  1985. {
  1986. dh.ExecuteSql("delete from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "'", "delete");
  1987. LoadPrcodeData();
  1988. dh.UpdateByCondition("CS$InoutPrcode", "collectednum=(select nvl(sum(pib_qty),0) from prodiobarcode where pib_inoutno=pd_inoutno and pib_pdno=pd_pdno)", "pd_inoutno='" + pi_inoutno.Text + "'");
  1989. MessageBox.Show("同步出货单明细数据成功", "提示");
  1990. }
  1991. private void ResetHBXH_Click(object sender, EventArgs e)
  1992. {
  1993. dh.ExecuteSql("update prodiodetail set PD_HBXH_USER=pd_pdno where pd_inoutno='" + pi_inoutno.Text + "'", "update");
  1994. MessageBox.Show("重置序号成功", "提示");
  1995. }
  1996. private void ButtonWeigh_Click(object sender, EventArgs e)
  1997. {
  1998. if (Weight.Text != "" && Weight.Text != "0.000")
  1999. {
  2000. sql.Clear();
  2001. sql.Append("update prodiobarcode set pib_boxweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  2002. sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "'");
  2003. dh.ExecuteSql(sql.ToString(), "update");
  2004. LoadGridData(sender, e);
  2005. }
  2006. else
  2007. {
  2008. MessageBox.Show("请先连接电子秤!");
  2009. }
  2010. }
  2011. Regex reg = new Regex(@"\d+.\d+");
  2012. ComInfoSet cis;
  2013. private void ConnectCom_Click(object sender, EventArgs e)
  2014. {
  2015. cis = new ComInfoSet();
  2016. (cis.Controls["PortName"] as SerialPortCombox).SelectedValue = Properties.Settings.Default.PortName;
  2017. cis.Controls["BaudRate"].Text = Properties.Settings.Default.BaudRate;
  2018. cis.Controls["Confirm"].Click += UAS_出货标签打印_Click;
  2019. cis.ShowDialog();
  2020. }
  2021. private void UAS_出货标签打印_Click(object sender, EventArgs e)
  2022. {
  2023. if (Com.IsOpen && Com.PortName == cis.Controls["PortName"].Text)
  2024. {
  2025. MessageBox.Show("串口" + Com.PortName + "已打开");
  2026. return;
  2027. }
  2028. else
  2029. {
  2030. if (Com.IsOpen)
  2031. {
  2032. Com.Close();
  2033. }
  2034. }
  2035. int BaudRate = 0;
  2036. Com.PortName = cis.Controls["PortName"].Text;
  2037. if (int.TryParse(cis.Controls["BaudRate"].Text, out BaudRate))
  2038. {
  2039. Com.BaudRate = BaudRate;
  2040. }
  2041. Properties.Settings.Default.BaudRate = BaudRate.ToString();
  2042. Properties.Settings.Default.PortName = cis.Controls["PortName"].Text;
  2043. Properties.Settings.Default.Save();
  2044. Com.DataReceived += Com_DataReceived;
  2045. Com.Open();
  2046. cis.Close();
  2047. }
  2048. private void Com_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
  2049. {
  2050. try
  2051. {
  2052. int len = Com.BytesToRead;
  2053. byte[] readBuffer = new byte[len];
  2054. Com.Read(readBuffer, 0, len); //将数据读入缓存
  2055. Weight.Text = reg.Match(Encoding.ASCII.GetString(readBuffer, 0, len)).Value;
  2056. //读不到数据的时间删掉
  2057. if (Weight.Text == "")
  2058. {
  2059. Com.DataReceived -= Com_DataReceived;
  2060. return;
  2061. }
  2062. }
  2063. catch (Exception)
  2064. {
  2065. return;
  2066. }
  2067. }
  2068. }
  2069. }