UAS_出货标签管理.cs 83 KB

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