UAS_出货标签管理.cs 107 KB

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