UAS_出货标签管理.cs 82 KB

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