UAS_出货标签管理.cs 101 KB

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