UAS_出货标签管理.cs 77 KB

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