UAS_出货标签管理.cs 94 KB

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