UAS_出货标签管理.cs 110 KB

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