UAS_出货标签管理.cs 151 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using System.Text.RegularExpressions;
  6. using System.Text;
  7. using System.Collections.Generic;
  8. using System.Diagnostics;
  9. using UAS_LabelMachine.PublicMethod;
  10. using UAS_LabelMachine.Entity;
  11. using UAS_LabelMachine.PublicForm;
  12. using System.Threading;
  13. using FastReport;
  14. using System.Linq;
  15. using System.Reflection;
  16. using UAS_LabelMachine.CustomControl;
  17. using System.Net.Sockets;
  18. namespace UAS_LabelMachine
  19. {
  20. public partial class UAS_出货标签打印 : Form
  21. {
  22. bool ConnectToMachine = false;
  23. //自适应屏幕
  24. AutoSizeFormClass asc = new AutoSizeFormClass();
  25. DataHelper dh;
  26. DataTable dt;
  27. StringBuilder sql = new StringBuilder();
  28. /// <summary>
  29. /// 单盘打印文件
  30. /// </summary>
  31. Report SingleReport = new Report();
  32. /// <summary>
  33. /// 中盒打印文件
  34. /// </summary>
  35. Report MidReport = new Report();
  36. /// <summary>
  37. /// 外箱打印文件
  38. /// </summary>
  39. Report OutReport = new Report();
  40. /// <summary>
  41. /// 唛头文件打印
  42. /// </summary>
  43. Report FootReport = new Report();
  44. /// <summary>
  45. /// Loading窗口
  46. /// </summary>
  47. SetLoadingWindow stw;
  48. /// <summary>
  49. /// 弹窗线程
  50. /// </summary>
  51. Thread thread;
  52. /// <summary>
  53. /// 当前品牌
  54. /// </summary>
  55. string PI_ID;
  56. bool logout = false;
  57. //主表数据源
  58. DataTable LabelInfDataTable;
  59. /// <summary>
  60. /// 存放单盘的ID
  61. /// </summary>
  62. List<string> SingleID = new List<string>();
  63. /// <summary>
  64. /// 是否全选
  65. /// </summary>
  66. bool AllChecked = false;
  67. DataTable SumQty;
  68. /// <summary>
  69. /// 是否通过选择Combox来改变打开的文件
  70. /// </summary>
  71. bool ComBoxClickChangeLabelDoc = false;
  72. //当前采集的物料编号
  73. string CurrentPrCode = "";
  74. //当前采集的最小包装
  75. string CurrentZXBZ = "";
  76. //当前采集的单位
  77. string CurrentUnit = "";
  78. //当前采集的总数
  79. string CurrentPrCount = "";
  80. //当前明细序号
  81. string CurrentPDNO = "";
  82. //当前的物料品牌
  83. string CurrentBrand = "";
  84. string NrCode = "";
  85. string Prefix = "";
  86. string Suffix = "";
  87. int MaxNum = 0;
  88. int NumLength = 0;
  89. int Radix = 0;
  90. private bool EnablePrint = true;
  91. string[] PIBID;
  92. DataTable Attach;
  93. //传送贴标角度
  94. string Angle = "";
  95. string X = "";
  96. string Y = "";
  97. //贴标机采集的行数
  98. int MachineCollectRowIndex = 0;
  99. public UAS_出货标签打印(string Master)
  100. {
  101. this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
  102. this.UpdateStyles();
  103. InitializeComponent();
  104. //利用反射设置DataGridView的双缓冲
  105. Type dgvType = this.LabelInf.GetType();
  106. PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
  107. pi.SetValue(this.LabelInf, true, null);
  108. pi.SetValue(this.GridPrcode, true, null);
  109. (new EnvironmentSettings()).ReportSettings.ShowProgress = false;
  110. Text = Text + "-" + Master;
  111. }
  112. //protected override void WndProc(ref Message m)
  113. //{
  114. // //拦截双击标题栏、移动窗体的系统消息
  115. // if (m.Msg != 0xA3)
  116. // {
  117. // base.WndProc(ref m);
  118. // }
  119. //}
  120. delegate void BindDataSource(DataGridView dgv, DataTable dt);//定义委托
  121. void bindingsource(DataGridView dgv, DataTable dt)
  122. {
  123. if (dgv.InvokeRequired)
  124. {
  125. dgv.Invoke(new BindDataSource(bindingsource), new object[] { dgv, dt });
  126. }
  127. else
  128. {
  129. dgv.AutoGenerateColumns = false;
  130. dgv.DataSource = dt;
  131. }
  132. }
  133. private void 贴标机条码打印_Load(object sender, EventArgs e)
  134. {
  135. //用计时器重置数据库链接
  136. LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
  137. dh = SystemInf.dh;
  138. CheckForIllegalCrossThreadCalls = false;
  139. pi_inoutno.Focus();
  140. Point pt = new Point();
  141. //禁止所有列的排序
  142. foreach (DataGridViewColumn dgv in LabelInf.Columns)
  143. {
  144. dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
  145. }
  146. foreach (DataGridViewColumn dgv in GridPrcode.Columns)
  147. {
  148. dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
  149. }
  150. int ScreenWidth = Screen.GetWorkingArea(pt).Width;
  151. //设置获取当前屏幕大小自动全屏但是保留任务栏
  152. Rectangle ScreenArea = Screen.GetWorkingArea(this);
  153. Top = 0;
  154. Left = 0;
  155. Width = ScreenArea.Width;
  156. Height = ScreenArea.Height;
  157. //OutboxCapacity.Value = Properties.Settings.Default.OutboxCapacity;
  158. MidboxCapacity.Value = Properties.Settings.Default.MidBoxCapacity;
  159. if (MidboxCapacity.Value == 0)
  160. {
  161. MidboxCapacity.Value = 10;
  162. }
  163. DCCheck.Text = Properties.Settings.Default.DCCheck.ToString();
  164. OutBoxPrinter.Text = Properties.Settings.Default.OPrinter;
  165. MidLabelPrinter.Text = Properties.Settings.Default.MPrinter;
  166. SingleLabelPrinter.Text = Properties.Settings.Default.SPrinter;
  167. asc.controllInitializeSize(this);
  168. asc.controlAutoSize(this);
  169. RefreshDBConnect.Interval = 60000;
  170. RefreshDBConnect.Start();
  171. }
  172. //只执行一次窗体自适应
  173. bool AutoSized = false;
  174. private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
  175. {
  176. if (!AutoSized)
  177. {
  178. asc.controlAutoSize(this);
  179. AutoSized = true;
  180. }
  181. }
  182. private void LabelMaintain_Click(object sender, EventArgs e)
  183. {
  184. 客户标签维护 form = new 客户标签维护();
  185. BaseUtil.SetFormCenter(form);
  186. form.FormClosed += LabelFormClose;
  187. form.ShowDialog();
  188. }
  189. int combined = 0;
  190. private void LabelFormClose(object sender, EventArgs e)
  191. {
  192. GetInOutInfAndLabelFile();
  193. }
  194. int PassTenCount = 1;
  195. int PassSixTenCount = 1;
  196. //输入框Enter事件
  197. private void Input_KeyDown(object sender, KeyEventArgs e)
  198. {
  199. if (e.KeyCode == Keys.Enter)
  200. {
  201. if (Input.Text == "")
  202. {
  203. richTextAutoBottom1.AppendText("采集的数据不能为空\n");
  204. receiveClient.Client.Send(Encoding.ASCII.GetBytes("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N")));
  205. return;
  206. }
  207. CollectInputData();
  208. }
  209. }
  210. /// <summary>
  211. /// 采集数据
  212. /// </summary>
  213. private void CollectInputData()
  214. {
  215. if (Input.Text == "SC")
  216. {
  217. PrintStatus.PerformClick();
  218. Input.Text = "";
  219. return;
  220. }
  221. Input.Text = Input.Text.Replace("\n", "").Replace(" ", "").Replace("\t", "").Replace("\r", "");
  222. Dictionary<string, string> Data = new Dictionary<string, string>();
  223. string[] SplitData = Input.Text.Split('*');
  224. if (SplitData.Length < 5)
  225. {
  226. richTextAutoBottom1.AppendText("数据格式错误,无法解析\n");
  227. if (ConnectToMachine)
  228. {
  229. receiveClient.Client.Send(Encoding.ASCII.GetBytes("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N")));
  230. }
  231. //Input.SelectAll();
  232. return;
  233. }
  234. for (int i = 0; i < SplitData.Length; i++)
  235. {
  236. switch (i.ToString())
  237. {
  238. case "0":
  239. Data.Add("PRCODE", SplitData[i]);
  240. break;
  241. case "1":
  242. Data.Add("QTY", SplitData[i]);
  243. break;
  244. case "2":
  245. Data.Add("DATECODE", SplitData[i]);
  246. break;
  247. case "3":
  248. Data.Add("BRAND", SplitData[i]);
  249. break;
  250. case "4":
  251. Data.Add("LOTNO", SplitData[i]);
  252. break;
  253. case "5":
  254. Data.Add("PO", SplitData[i]);
  255. break;
  256. case "6":
  257. Data.Add("SERIAL", SplitData[i]);
  258. break;
  259. default:
  260. break;
  261. }
  262. }
  263. if (Data["PRCODE"] != CurrentPrCode)
  264. {
  265. if (!MixPrCode.Checked)
  266. {
  267. richTextAutoBottom1.AppendText("当前采集【物料编号" + Data["PRCODE"] + "】不对应,请重新采集\n");
  268. //Input.SelectAll();
  269. if (ConnectToMachine)
  270. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))));
  271. return;
  272. }
  273. else
  274. {
  275. bool FindProd = false;
  276. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  277. {
  278. string prodcode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  279. string outqty = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  280. string collectnum = GridPrcode.Rows[i].Cells["collectednum"].Value.ToString();
  281. //判断其他行是否有料可以匹配
  282. if (prodcode == Data["PRCODE"] && decimal.Parse(outqty) > decimal.Parse(collectnum))
  283. {
  284. GridPrcode.Rows[i].Selected = true;
  285. FindProd = true;
  286. }
  287. }
  288. if (!FindProd)
  289. {
  290. richTextAutoBottom1.AppendText("当前采集【物料编号" + Data["PRCODE"] + "】没有需要采集的内容\n");
  291. //Input.SelectAll();
  292. if (ConnectToMachine)
  293. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))));
  294. return;
  295. }
  296. }
  297. }
  298. //校验DateCode是否过期
  299. if (!CheckDateCode(Data["DATECODE"]))
  300. {
  301. if (ConnectToMachine)
  302. {
  303. richTextAutoBottom1.AppendText("物料" + Data["PRCODE"] + "【DateCode】超出校验日期\n");
  304. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))));
  305. return;
  306. }
  307. else
  308. {
  309. string close = MessageBox.Show(this.ParentForm, "物料" + Data["PRCODE"] + "【DateCode】超出校验日期\n", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  310. if (close.ToString() != "Yes")
  311. return;
  312. }
  313. }
  314. if (Data["BRAND"] != CurrentBrand)
  315. {
  316. if (ConnectToMachine)
  317. {
  318. richTextAutoBottom1.AppendText("当前采集【品牌" + Data["BRAND"] + "】不对应\n");
  319. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))));
  320. return;
  321. }
  322. else
  323. {
  324. string close = MessageBox.Show(this.ParentForm, "当前采集【品牌" + Data["BRAND"] + "】不对应", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  325. if (close.ToString() != "Yes")
  326. return;
  327. }
  328. }
  329. int CodeCount = 0;
  330. //如果单位是KPCS则需要除1000
  331. double CollectNum = 0;
  332. if (CurrentUnit == "KPCS")
  333. {
  334. try
  335. {
  336. double.Parse(CurrentZXBZ);
  337. }
  338. catch (Exception)
  339. {
  340. MessageBox.Show("请检查最小包装数");
  341. }
  342. //如果单位是KPCS则必须是1000的整数倍
  343. if (decimal.Parse((Convert.ToDouble((double.Parse(Data["QTY"]) / 1000).ToString("0.000")) / Convert.ToDouble(double.Parse(CurrentZXBZ).ToString("0.000"))).ToString()) % 1 != 0)
  344. {
  345. richTextAutoBottom1.AppendText("物料" + Data["PRCODE"] + "采集数量无法按照最小包装数拆分\n");
  346. //Input.SelectAll();
  347. if (ConnectToMachine)
  348. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))));
  349. return;
  350. }
  351. CodeCount = int.Parse((double.Parse(Data["QTY"]) / 1000 / double.Parse(CurrentZXBZ)).ToString());
  352. CollectNum = double.Parse(Data["QTY"]) / 1000;
  353. }
  354. else
  355. {
  356. if (double.Parse(Data["QTY"]) % double.Parse(CurrentZXBZ) != 0)
  357. {
  358. richTextAutoBottom1.AppendText("采集【数量】无法按照最小包装数拆分\n");
  359. if (ConnectToMachine)
  360. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))));
  361. //Input.SelectAll();
  362. return;
  363. }
  364. CodeCount = int.Parse((double.Parse(Data["QTY"]) / double.Parse(CurrentZXBZ)).ToString());
  365. CollectNum = double.Parse(Data["QTY"]);
  366. }
  367. string pib_barcode = Data.ContainsKey("SERIAL") ? Data["SERIAL"] : "";
  368. //获取ID
  369. PIBID = dh.GetSEQ("prodiobarcode_seq", CodeCount);
  370. //加载完数据之后进行容量的判断
  371. string pib_outboxcode2 = "";
  372. int BoxNum = LabelInfDataTable.Select("pib_outboxcode2='" + OutBoxNum.Text + "'").Length;
  373. //if (!ConnectToMachine)
  374. {
  375. if (BoxNum + CodeCount > OutboxCapacity.Value && AutoSetOutBox.Checked)
  376. {
  377. string maxoutbox = dh.getFieldDataByCondition("prodiobarcode", "max(to_number(pib_outboxcode2))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  378. //如果没有则从开始插入
  379. if (maxoutbox == "")
  380. {
  381. pib_outboxcode2 = "1";
  382. }
  383. else
  384. {
  385. pib_outboxcode2 = (int.Parse(maxoutbox) + 1).ToString();
  386. }
  387. OutBoxNum.Items.Clear();
  388. 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");
  389. ItemObject io = new ItemObject("新增", "新增");
  390. OutBoxNum.Items.Add(io);
  391. io = new ItemObject("全部", "全部");
  392. OutBoxNum.Items.Add(io);
  393. io = new ItemObject(pib_outboxcode2, pib_outboxcode2);
  394. PassSixTenCount = 1;
  395. OutBoxNum.Items.Add(io);
  396. for (int i = 0; i < dt.Rows.Count; i++)
  397. {
  398. string piboutboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  399. io = new ItemObject(piboutboxcode2, piboutboxcode2);
  400. OutBoxNum.Items.Add(io);
  401. }
  402. if (OutBoxNum.Items.Count > 2)
  403. OutBoxNum.SelectedIndex = 2;
  404. BoxNum = LabelInfDataTable.Select("pib_outboxcode2='" + OutBoxNum.Text + "'").Length;
  405. }
  406. else
  407. {
  408. if (OutBoxNum.Text == "新增")
  409. {
  410. string maxoutbox = dh.getFieldDataByCondition("prodiobarcode", "max(to_number(pib_outboxcode2))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  411. //如果没有则从开始插入
  412. if (maxoutbox == "")
  413. {
  414. pib_outboxcode2 = "1";
  415. }
  416. else
  417. {
  418. pib_outboxcode2 = (int.Parse(maxoutbox) + 1).ToString();
  419. }
  420. OutBoxNum.Items.Clear();
  421. PassSixTenCount = 1;
  422. 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");
  423. ItemObject io = new ItemObject("新增", "新增");
  424. OutBoxNum.Items.Add(io);
  425. io = new ItemObject("全部", "全部");
  426. OutBoxNum.Items.Add(io);
  427. io = new ItemObject(pib_outboxcode2, pib_outboxcode2);
  428. OutBoxNum.Items.Add(io);
  429. for (int i = 0; i < dt.Rows.Count; i++)
  430. {
  431. string piboutboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  432. io = new ItemObject(piboutboxcode2, piboutboxcode2);
  433. OutBoxNum.Items.Add(io);
  434. }
  435. if (OutBoxNum.Items.Count > 2)
  436. OutBoxNum.SelectedIndex = 2;
  437. BoxNum = LabelInfDataTable.Select("pib_outboxcode2='" + OutBoxNum.Text + "'").Length;
  438. }
  439. else
  440. {
  441. pib_outboxcode2 = OutBoxNum.Text;
  442. }
  443. }
  444. }
  445. //else
  446. //{
  447. // if (OutBoxNum.Text == "新增")
  448. // {
  449. // string maxoutbox = dh.getFieldDataByCondition("prodiobarcode", "max(to_number(pib_outboxcode2))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  450. // //如果没有则从开始插入
  451. // if (maxoutbox == "")
  452. // {
  453. // pib_outboxcode2 = "1";
  454. // }
  455. // else
  456. // {
  457. // pib_outboxcode2 = (int.Parse(maxoutbox) + 1).ToString();
  458. // }
  459. // }
  460. // else
  461. // {
  462. // pib_outboxcode2 = OutBoxNum.Text;
  463. // }
  464. // if (!AutoPrintOutBox.Checked)
  465. // {
  466. // if (BoxNum + CodeCount > OutboxCapacity.Value)
  467. // {
  468. // string close = MessageBox.Show(this.ParentForm, "箱号【" + OutBoxNum.Text + "】后超数量为" + (BoxNum + CodeCount) + ",超出容量" + OutboxCapacity.Value + ",是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  469. // if (close != "Yes")
  470. // {
  471. // Input.SelectAll();
  472. // return;
  473. // }
  474. // }
  475. // }
  476. //}
  477. if (OutBoxNum.Text == "全部")
  478. {
  479. MessageBox.Show("请选择指定箱号或者新增");
  480. return;
  481. }
  482. //计算当前采集数量
  483. string collectqty = dh.getFieldDataByCondition("prodiobarcode", "sum(pib_qty)", "pib_inoutno='" + pi_inoutno.Text + "' and pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString();
  484. double CollectQty = (collectqty == "" ? 0 : double.Parse(collectqty));
  485. if (Convert.ToDouble((CollectQty + CollectNum).ToString("0.000")) > Convert.ToDouble(double.Parse(CurrentPrCount).ToString("0.000")))
  486. {
  487. richTextAutoBottom1.AppendText("物料" + Data["PRCODE"] + "采集后数量为" + (CollectQty + CollectNum) + ",【超出】本行出货数量" + CurrentPrCount + "\n");
  488. if (ConnectToMachine)
  489. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|NG|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))));
  490. //Input.SelectAll();
  491. return;
  492. }
  493. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, CodeCount);
  494. List<string> CustBarCode = new List<string>();
  495. if (!(Radix > 0))
  496. {
  497. string close = MessageBox.Show(this.ParentForm, "未维护条码规则,是否继续生成", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  498. if (close.ToString() != "Yes")
  499. return;
  500. }
  501. for (int i = 0; i < CodeCount; i++)
  502. {
  503. if (Radix > 0)
  504. {
  505. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  506. for (int j = serialcode.ToString().Length; j < NumLength; j++)
  507. {
  508. serialcode = "0" + serialcode;
  509. }
  510. CustBarCode.Add(Prefix + serialcode + Suffix);
  511. MaxNum = MaxNum + 1;
  512. }
  513. else
  514. {
  515. CustBarCode.Add("");
  516. }
  517. }
  518. sql.Clear();
  519. sql.Append("insert into prodiobarcode(PIB_ID,PIB_PRODCODE,PIB_INDATE,PIB_INOUTNO,PIB_PIID,PIB_PDNO, PIB_PDID,PIB_PICLASS,");
  520. 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,pib_ismachine) ");
  521. sql.Append("select :PIB_ID,pd_prodcode,sysdate,pi_inoutno,pi_id,pd_pdno,pd_id,pi_class,");
  522. 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 + "','" + (ConnectToMachine ? "Y" : "N") + "' ");
  523. 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 + "'");
  524. int rowsnum = 0;
  525. try
  526. {
  527. rowsnum = dh.BatchInsert(sql.ToString(), new string[] { "PIB_ID", "PIB_CUSTBARCODE" }, PIBID, CustBarCode.ToArray());
  528. }
  529. catch (Exception)
  530. {
  531. if (ReSetType != " ")
  532. {
  533. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'");
  534. }
  535. else
  536. {
  537. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "'");
  538. }
  539. CollectInputData();
  540. return;
  541. }
  542. if (rowsnum == 0)
  543. {
  544. MessageBox.Show("未成功插入数据,请核对出货单当前明细", "提示");
  545. }
  546. //更新流水号
  547. if (!ConnectToMachine)
  548. {
  549. if (OutBoxNum.Text == "新增")
  550. {
  551. OutBoxNum.Items.Clear();
  552. 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");
  553. ItemObject io = new ItemObject("新增", "新增");
  554. OutBoxNum.Items.Add(io);
  555. io = new ItemObject("全部", "全部");
  556. OutBoxNum.Items.Add(io);
  557. for (int i = 0; i < dt.Rows.Count; i++)
  558. {
  559. string piboutboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  560. io = new ItemObject(piboutboxcode2, piboutboxcode2);
  561. OutBoxNum.Items.Add(io);
  562. }
  563. if (OutBoxNum.Items.Count > 2)
  564. OutBoxNum.SelectedIndex = 2;
  565. }
  566. }
  567. LoadGridData(new object(), new EventArgs());
  568. if (LabelInf.Rows.Count > 0)
  569. {
  570. LabelInf.Rows[LabelInf.Rows.Count - 1].Selected = true;
  571. }
  572. if (SingleLabelAutoPrint.Checked)
  573. {
  574. thread = new Thread(AutoPrintSingleLabel);
  575. stw = new SetLoadingWindow(thread, "正在打印单盘标签");
  576. BaseUtil.SetFormCenter(stw);
  577. stw.ShowDialog();
  578. if (ConnectToMachine)
  579. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|OK|,|" + (SingleLabelAutoPrint.Checked ? "Y" : "N"))));
  580. }
  581. else
  582. {
  583. if (ConnectToMachine)
  584. receiveClient.Client.Send(Encoding.ASCII.GetBytes(GetSendCode("ReadId1|,|OK|,|N")));
  585. }
  586. if (SumQty.Columns.Count == 0)
  587. {
  588. sql.Clear();
  589. 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 ");
  590. sql.Append("where pib_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno ");
  591. SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  592. }
  593. //采集后重新计数,自动跳到下一行
  594. if (SumQty == null)
  595. {
  596. sql.Clear();
  597. 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 ");
  598. sql.Append("where pib_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno ");
  599. SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  600. }
  601. collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  602. CollectQty = (collectqty == "" ? 0 : double.Parse(collectqty));
  603. if (Combindetail.Checked)
  604. combined = 1;
  605. if (CombindetailTwo.Checked)
  606. combined = 2;
  607. dh.UpdateByCondition("CS$InoutPrcode", "Collectednum='" + CollectQty + "'", "pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + CurrentPDNO + "' and combined=" + combined);
  608. CollectNum = 0;
  609. double OutNum = 0;
  610. if (GridPrcode.SelectedRows.Count > 0)
  611. {
  612. GridPrcode.Rows[GridPrcode.SelectedRows[0].Index].Cells["CollectedNum"].Value = CollectQty;
  613. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  614. {
  615. CollectNum += float.Parse(GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString());
  616. OutNum += float.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString());
  617. }
  618. }
  619. ProcessCount.Text = CollectNum + "/" + OutNum;
  620. if (CollectNum == OutNum)
  621. {
  622. dh.UpdateByCondition("prodinout", "pi_user_packingstatus='Packed'", "pi_inoutno='" + pi_inoutno.Text + "'");
  623. }
  624. if (CollectQty / double.Parse(CurrentZXBZ) % double.Parse(MidboxCapacity.Value.ToString()) == 0)
  625. {
  626. if (LabelInf.Rows.Count > 0)
  627. LabelInf.Rows[LabelInf.Rows.Count - 1].Selected = true;
  628. if (AutoPrintMidBox.Checked)
  629. MidLabelPrint.PerformClick();
  630. }
  631. //采集达到了数量进行换行
  632. if (CollectQty == double.Parse(CurrentPrCount))
  633. {
  634. if (AutoPrintMidBox.Checked && (CollectQty / double.Parse(CurrentZXBZ) % double.Parse(MidboxCapacity.Value.ToString()) != 0))
  635. MidLabelPrint.PerformClick();
  636. //需要换行,当前最后一盒
  637. DataGridViewSelectedRowCollection selectrow = GridPrcode.SelectedRows;
  638. if (selectrow.Count > 0)
  639. {
  640. if (selectrow[0].Index + 1 < GridPrcode.Rows.Count)
  641. {
  642. string outqty = GridPrcode.Rows[selectrow[0].Index + 1].Cells["pd_outqty"].Value.ToString();
  643. string collectnum = GridPrcode.Rows[selectrow[0].Index + 1].Cells["CollectedNum"].Value.ToString();
  644. if (double.Parse(outqty) > double.Parse(collectnum == "" ? "0" : collectnum))
  645. {
  646. GridPrcode.Rows[selectrow[0].Index + 1].Selected = true;
  647. }
  648. }
  649. }
  650. }
  651. if (AutoPrintOutBox.Checked)
  652. {
  653. if (BoxNum + CodeCount >= OutboxCapacity.Value)
  654. {
  655. OutBoxLabelPrint.PerformClick();
  656. }
  657. }
  658. GridPrcode.Refresh();
  659. if (!IsSum)
  660. Input.Clear();
  661. }
  662. private void AutoPrintSingleLabel()
  663. {
  664. if (EnablePrint)
  665. {
  666. //用标签本身的变量作为最外层的循环条件去匹配;
  667. StringBuilder ParamLog = new StringBuilder();
  668. string pibid = "";
  669. for (int i = 0; i < PIBID.Length; i++)
  670. {
  671. if (i != PIBID.Length - 1)
  672. pibid += PIBID[i] + ",";
  673. else
  674. pibid += PIBID[i];
  675. }
  676. if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  677. SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
  678. for (int j = 0; j < SingleReport.Parameters.Count; j++)
  679. {
  680. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, "");
  681. for (int k = 0; k < Attach.Rows.Count; k++)
  682. {
  683. if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name)
  684. {
  685. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  686. }
  687. }
  688. }
  689. StringBuilder sql = new StringBuilder();
  690. sql.Clear();
  691. sql.Append("select * from (select to_char(pi_date,'yyiw')出库年周,to_char(sysdate,'yyiw')当前DateCode,pi_remark 单据备注,pi_date-1 出库前一天,pib_outboxcode2 外箱号,pd_orderdetno 订单序号,pib_totalweight 总重,pr_ywmc_user 英文名称,pib_boxweight 箱重,nvl(pib_totalweight,0)-nvl(pib_boxweight,0) 净重,pib_id 主键ID,pd_pdno 出货序号,pib_prodcode 物料编号,pr_detail 物料名称,to_char(pi_date,'yyyy-mm-dd') 送达日期,pd_custprodspec 客户型号,pd_custproddetail 客户物料名称,pi_title 客户全称,cu_shortname 客户简称,pr_spec 物料规格,pib_custbarcode 客户条码,pib_custmidboxcode 中盒条码,pib_custoutboxcode 外箱条码,pib_inoutno 出货单号,");
  692. sql.Append("PD_HBSL_USER 出库数量,PD_HBSL_USER*1000 出库数量k,pjd_orispeccode 原厂型号,pib_datecode DateCode,(week_to_date(pib_datecode))DateCode1,pd_remark 备注,pd_remark2 备注2,pd_remark3 备注3,pib_lotno LotNo,");
  693. sql.Append("nvl(nvl(pd_brand,pib_brand),pr_brand)品牌,pr_unit 单位, to_char(pi_date,'yyyy-mm-dd')出库日期,PIB_QTY 最小封装数量,PIB_QTY*1000 最小封装数量k,pd_pocode 客户PO,pd_custprodcode CPN客户料号,");
  694. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),12),'yyyy-mm-dd') 有效期一年,");
  695. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),24),'yyyy-mm-dd') 有效期两年,");
  696. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),36),'yyyy-mm-dd') 有效期三年,");
  697. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),12),'yyyy-iw')有效期一年_年周,");
  698. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),24),'yyyy-iw')有效期两年_年周,");
  699. sql.Append("to_char(ADD_MONTHS(to_date(week_to_date(pib_datecode),'yyyy-mm-dd'),36),'yyyy-iw')有效期三年_年周,");
  700. sql.Append("wh_ppmc_user 中文品牌,em_code 装箱员编号,em_name 装箱员名称 from prodiobarcode left join prodinout on pib_piid=pi_id left join product on pib_prodcode=pr_code left join ProdIODetail on pd_id=PIB_PDID ");
  701. sql.Append("left join PRODJOINVENDDETAIL on pjd_brand=pib_brand and pjd_prodcode=pib_prodcode left join customer on pi_cardcode=cu_code left join productcustomer on pc_custid=cu_id and pc_prodcode=pd_prodcode ");
  702. if (pibid.IndexOf(",") > 0)
  703. {
  704. sql.Append("and pc_custprodcode=pd_custprodcode left join WareHouse on wh_code=pd_whcode left join employee on em_code=pib_inman where pib_id in (" + pibid + ") order by pib_custbarcode)prodiosingleinfo_view");
  705. }
  706. else
  707. {
  708. sql.Append("and pc_custprodcode=pd_custprodcode left join WareHouse on wh_code=pd_whcode left join employee on em_code=pib_inman where pib_id='" + pibid + "' order by pib_custbarcode)prodiosingleinfo_view");
  709. }
  710. DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  711. SingleReport.RegisterData(dt, "prodiosingleinfo_view");
  712. SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true;
  713. SingleReport.PrintSettings.ShowDialog = false;
  714. SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  715. try
  716. {
  717. SingleReport.Print();
  718. }
  719. catch (Exception e)
  720. {
  721. MessageBox.Show(e.Message);
  722. return;
  723. }
  724. Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text;
  725. Properties.Settings.Default.Save();
  726. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "自动打印箱标", "打印成功");
  727. }
  728. }
  729. //关闭窗口前提示用户确认
  730. private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
  731. {
  732. //如果不是注销的话
  733. if (!logout)
  734. {
  735. string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  736. if (close.ToString() != "Yes")
  737. e.Cancel = true;
  738. else
  739. {
  740. LogManager.DoLog("关闭程序");
  741. }
  742. }
  743. }
  744. /// <summary>
  745. /// 获取打印标签
  746. /// </summary>
  747. private void GetInOutInfAndLabelFile()
  748. {
  749. ComBoxClickChangeLabelDoc = false;
  750. sql.Clear();
  751. 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 ");
  752. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  753. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='单盘' order by cl_custcode,cl_date desc");
  754. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  755. SingleLabelCombox.DisplayMember = "cl_labelname";
  756. SingleLabelCombox.ValueMember = "cl_labelurl";
  757. SingleLabelCombox.DataSource = dt;
  758. sql.Clear();
  759. 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 ");
  760. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  761. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='中盒' order by cl_custcode,cl_date desc");
  762. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  763. MidLabelCombox.DisplayMember = "cl_labelname";
  764. MidLabelCombox.ValueMember = "cl_labelurl";
  765. MidLabelCombox.DataSource = dt;
  766. sql.Clear();
  767. 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 ");
  768. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  769. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='外箱' order by cl_custcode,cl_date desc");
  770. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  771. OutBoxCombox.DisplayMember = "cl_labelname";
  772. OutBoxCombox.ValueMember = "cl_labelurl";
  773. OutBoxCombox.DataSource = dt;
  774. ComBoxClickChangeLabelDoc = true;
  775. }
  776. bool LoadCheck = true;
  777. /// <summary>
  778. /// 出入库单录入框的回车事件
  779. /// </summary>
  780. /// <param name="sender"></param>
  781. /// <param name="e"></param>
  782. private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
  783. {
  784. if (e.KeyCode == Keys.Enter)
  785. {
  786. LoadCheck = false;
  787. Combindetail.Checked = false;
  788. CombindetailTwo.Checked = false;
  789. LoadCheck = true;
  790. Input.Clear();
  791. sql.Clear();
  792. 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'");
  793. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  794. if (dt.Rows.Count > 0)
  795. {
  796. pi_cardcode.Text = dt.Rows[0]["pi_cardcode"].ToString();
  797. pi_title.Text = dt.Rows[0]["pi_title"].ToString();
  798. pi_date.Text = dt.Rows[0]["pi_date"].ToString();
  799. PI_ID = dt.Rows[0]["pi_id"].ToString();
  800. switch (dt.Rows[0]["pi_combine_user"].ToString())
  801. {
  802. case "1":
  803. Combindetail.Checked = true;
  804. break;
  805. case "2":
  806. CombindetailTwo.Checked = true;
  807. break;
  808. default:
  809. break;
  810. }
  811. PassTenCount = 1;
  812. PassSixTenCount = 1;
  813. if (pi_cardcode.Text != "ZGCC")
  814. {
  815. CustomerLabel.Enabled = false;
  816. }
  817. else
  818. {
  819. CustomerLabel.Enabled = true;
  820. }
  821. DataTable XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "' and px_machine='" + SystemInf.Machine + "'", "select");
  822. if (XY.Rows.Count == 0)
  823. {
  824. XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "'", "select");
  825. }
  826. if (XY.Rows.Count > 0)
  827. {
  828. Angle = XY.Rows[0]["px_angle"].ToString();
  829. X = XY.Rows[0]["px_x"].ToString();
  830. Y = XY.Rows[0]["px_y"].ToString();
  831. }
  832. OutBoxNum_Click(new object(), new EventArgs());
  833. LoadPrcodeData();
  834. //获取条码规则
  835. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, 1);
  836. SingleID.Clear();
  837. Input.Focus();
  838. ////从后往前找未采集的行
  839. for (int i = GridPrcode.Rows.Count - 1; i >= 0; i--)
  840. {
  841. string outqty = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  842. string collectnum = GridPrcode.Rows[i].Cells["CollectedNum"].Value.ToString();
  843. if (double.Parse(outqty) > double.Parse(collectnum == "" ? "0" : collectnum))
  844. {
  845. GridPrcode.Rows[i].Selected = true;
  846. MachineCollectRowIndex = GridPrcode.SelectedRows[0].Index;
  847. if (i - 2 >= 0)
  848. GridPrcode.FirstDisplayedScrollingRowIndex = i - 2;
  849. else
  850. GridPrcode.FirstDisplayedScrollingRowIndex = i;
  851. }
  852. }
  853. pib_indate.Text = dh.getFieldDataByCondition("prodiobarcode", "min(to_char(pib_indate,'yyyy-mm-dd'))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString();
  854. bi_inman.Text = dh.getFieldDataByCondition("barcodeio left join employee on bi_inman=em_code", "wm_concat(distinct em_name)", "bi_piid=" + PI_ID).ToString();
  855. pib_inman.Text = dh.getFieldDataByCondition("prodiobarcode left join employee on pib_inman=em_code", "wm_concat(distinct em_name)", "pib_piid=" + PI_ID).ToString();
  856. 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");
  857. thread = new Thread(GetInOutInfAndLabelFile);
  858. stw = new SetLoadingWindow(thread, "正在获取打印标签");
  859. BaseUtil.SetFormCenter(stw);
  860. stw.ShowDialog();
  861. LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
  862. }
  863. else MessageBox.Show("当前出入库单号不存在或者未审核!", "提示");
  864. }
  865. }
  866. private void SingleBoxPrint()
  867. {
  868. if (EnablePrint)
  869. {
  870. if (LabelInf.Rows.Count > 0)
  871. {
  872. //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
  873. SingleID.Clear();
  874. //获取全部的中盒号
  875. Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
  876. //判断所有盒号为该盒的是否勾选已采集
  877. outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
  878. for (int i = 0; i < LabelInf.Rows.Count; i++)
  879. {
  880. if (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()))
  881. SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  882. }
  883. if (SingleID.ToArray().Length == 0)
  884. {
  885. MessageBox.Show("选择的行未勾选采集或者已打印", "提示");
  886. return;
  887. }
  888. for (int i = 0; i < LabelInf.RowCount; i++)
  889. {
  890. if (i + 1 < LabelInf.RowCount)
  891. {
  892. //如果本行的中盒号和下一行不相等的话
  893. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString())
  894. {
  895. if (!outboxcode1.ContainsKey(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  896. outboxcode1.Add(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString(), true);
  897. }
  898. }
  899. }
  900. string pibid = "";
  901. for (int i = 0; i < LabelInf.RowCount; i++)
  902. {
  903. //勾选了并且未打印
  904. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue != null && LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true")
  905. {
  906. pibid += LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + ",";
  907. LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
  908. }
  909. }
  910. if (pibid != "")
  911. {
  912. if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  913. SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
  914. for (int j = 0; j < SingleReport.Parameters.Count; j++)
  915. {
  916. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, "");
  917. for (int k = 0; k < Attach.Rows.Count; k++)
  918. {
  919. if (Attach.Rows[k][0].ToString() == SingleReport.Parameters[j].Name)
  920. {
  921. SingleReport.SetParameterValue(SingleReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  922. }
  923. }
  924. }
  925. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiosingleinfo_view where 主键ID in (" + pibid.Substring(0, pibid.Length - 1) + ")", "select");
  926. SingleReport.RegisterData(dt, "prodiosingleinfo_view");
  927. SingleReport.GetDataSource("prodiosingleinfo_view").Enabled = true;
  928. //保存参数打印
  929. SingleReport.PrintSettings.ShowDialog = false;
  930. SingleReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  931. try
  932. {
  933. SingleReport.Print();
  934. }
  935. catch (Exception e)
  936. {
  937. MessageBox.Show(e.Message);
  938. return;
  939. }
  940. Properties.Settings.Default.SPrinter = SingleLabelPrinter.Text;
  941. Properties.Settings.Default.Save();
  942. }
  943. else
  944. {
  945. MessageBox.Show("未勾选打印明细", "提示", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);
  946. }
  947. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印盘标", "打印成功");
  948. dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray());
  949. outboxcode1.Clear();
  950. }
  951. else
  952. {
  953. MessageBox.Show("此模板尚未维护参数或不存在打印明细", "提示");
  954. return;
  955. }
  956. }
  957. }
  958. private void SingleLabelPrint_Click(object sender, EventArgs e)
  959. {
  960. if (SingleLabelCombox.Text != "")
  961. {
  962. if (SingleBoxBegin.Text != "" || SingleBoxEnd.Text != "")
  963. {
  964. try
  965. {
  966. int begin = int.Parse(SingleBoxBegin.Text == "" ? "1" : SingleBoxBegin.Text);
  967. int end = int.Parse(SingleBoxEnd.Text == "" ? LabelInf.Rows.Count.ToString() : SingleBoxEnd.Text);
  968. if (begin > 0 && end <= LabelInf.Rows.Count && begin <= end)
  969. {
  970. for (int i = begin - 1; i < end; i++)
  971. {
  972. LabelInf.Rows[i].Cells["Choose"].Value = true;
  973. LabelInf.Rows[i].Cells["pib_ifprint"].Value = false;
  974. }
  975. }
  976. else
  977. {
  978. MessageBox.Show("单盘打印范围错误", "提示");
  979. return;
  980. }
  981. }
  982. catch (Exception)
  983. {
  984. MessageBox.Show("单盘打印范围错误", "提示");
  985. return;
  986. }
  987. }
  988. thread = new Thread(SingleBoxPrint);
  989. stw = new SetLoadingWindow(thread, "正在打印单盘");
  990. BaseUtil.SetFormCenter(stw);
  991. stw.ShowDialog();
  992. Input.Focus();
  993. }
  994. else
  995. {
  996. MessageBox.Show("未维护单盘标签", "提示");
  997. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印盘标", "打印失败,未维护标签");
  998. }
  999. }
  1000. private void MidBoxLabelPrint()
  1001. {
  1002. //未输入内容打印全部中盒
  1003. if (MidLabelNum.Text == "")
  1004. {
  1005. int begin = 0;
  1006. int end = 0;
  1007. if (MidBoxBegin.Text != "" || MidBoxEnd.Text != "")
  1008. {
  1009. try
  1010. {
  1011. begin = int.Parse(MidBoxBegin.Text == "" ? "1" : MidBoxBegin.Text);
  1012. end = int.Parse(MidBoxEnd.Text == "" ? LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString() : MidBoxEnd.Text);
  1013. int minmidbox = int.Parse(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString());
  1014. int maxmidbox = int.Parse(LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString());
  1015. if (begin >= minmidbox && end <= maxmidbox && begin <= end)
  1016. {
  1017. //设置中盒打印范围的行号
  1018. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1019. {
  1020. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == begin)
  1021. {
  1022. begin = i;
  1023. }
  1024. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == end)
  1025. {
  1026. end = i;
  1027. }
  1028. }
  1029. }
  1030. else
  1031. {
  1032. MessageBox.Show("中盒打印范围错误", "提示");
  1033. return;
  1034. }
  1035. }
  1036. catch (Exception)
  1037. {
  1038. MessageBox.Show("中盒打印范围错误", "提示");
  1039. return;
  1040. }
  1041. }
  1042. List<int> MidOutBoxCode = new List<int>();
  1043. List<int> MidOutBoxCodeIndex = new List<int>();
  1044. for (int i = (begin == 0 ? 0 : begin); i <= (end == 0 ? LabelInf.Rows.Count - 1 : end); i++)
  1045. {
  1046. try
  1047. {
  1048. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  1049. {
  1050. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  1051. MidOutBoxCodeIndex.Add(i);
  1052. }
  1053. }
  1054. catch (Exception)
  1055. {
  1056. MessageBox.Show("请先封箱!");
  1057. return;
  1058. }
  1059. }
  1060. //如果有选中行
  1061. if (SelectRowIndex >= 0 && LabelInf.Rows.Count > SelectRowIndex)
  1062. {
  1063. MidOutBoxCode.Clear();
  1064. MidOutBoxCodeIndex.Clear();
  1065. SelectProdcode = LabelInf.Rows[SelectRowIndex].Cells["pib_prodcode"].Value.ToString();
  1066. for (int i = SelectRowIndex; i >= 0; i--)
  1067. {
  1068. if ((LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() == SelectProdcode && LabelInf.Rows[i].Cells["pib_midifprint"].FormattedValue.ToString().ToLower() != "true") || i == SelectRowIndex)
  1069. {
  1070. LabelInf.Rows[i].Cells["pib_midifprint"].Value = true;
  1071. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  1072. {
  1073. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  1074. MidOutBoxCodeIndex.Add(i);
  1075. }
  1076. }
  1077. else
  1078. {
  1079. break;
  1080. }
  1081. }
  1082. for (int i = SelectRowIndex; i < LabelInf.Rows.Count - 1; i++)
  1083. {
  1084. if ((LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() == SelectProdcode && LabelInf.Rows[i].Cells["pib_midifprint"].FormattedValue.ToString().ToLower() != "true") || i == SelectRowIndex)
  1085. {
  1086. LabelInf.Rows[i].Cells["pib_midifprint"].Value = true;
  1087. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  1088. {
  1089. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  1090. MidOutBoxCodeIndex.Add(i);
  1091. }
  1092. }
  1093. else
  1094. {
  1095. break;
  1096. }
  1097. }
  1098. }
  1099. try
  1100. {
  1101. MidBoxCodePrint(MidOutBoxCodeIndex.ToArray());
  1102. }
  1103. catch (Exception e)
  1104. {
  1105. MessageBox.Show(e.Message);
  1106. return;
  1107. }
  1108. return;
  1109. }
  1110. bool FindMidLabel = false;
  1111. if (MidLabelCombox.SelectedValue != null)
  1112. {
  1113. //中盒号所在的行
  1114. int MidLabelRowIndex = 0;
  1115. //缓存中盒数据
  1116. for (int i = 0; i < LabelInf.RowCount; i++)
  1117. {
  1118. if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1119. {
  1120. //找到了输入的中盒号停止循环
  1121. FindMidLabel = true;
  1122. MidLabelRowIndex = i;
  1123. }
  1124. }
  1125. int[] rowindx = new int[] { MidLabelRowIndex };
  1126. //找到了指定的盒号
  1127. if (FindMidLabel)
  1128. MidBoxCodePrint(rowindx);
  1129. else
  1130. MessageBox.Show("该出入库单未找到该中盒号!", "提示");
  1131. }
  1132. else
  1133. MessageBox.Show("未维护中盒模板", "提示");
  1134. }
  1135. private void MidLabelPrint_Click(object sender, EventArgs e)
  1136. {
  1137. if (MidLabelCombox.Text != "")
  1138. {
  1139. PackMidBox_Click(sender, e);
  1140. thread = new Thread(MidBoxLabelPrint);
  1141. stw = new SetLoadingWindow(thread, "正在打印中盒");
  1142. BaseUtil.SetFormCenter(stw);
  1143. stw.ShowDialog();
  1144. }
  1145. else
  1146. MessageBox.Show("未维护中盒标签", "提示");
  1147. Input.Focus();
  1148. }
  1149. private void OutBoxPrint()
  1150. {
  1151. List<string> Outboxcode = new List<string>();
  1152. //如果未勾选箱号则对勾选的数据的箱号进行整合
  1153. if (OutBoxNum.Text == "" || OutBoxNum.Text == "全部")
  1154. {
  1155. for (int i = 0; i < LabelInf.RowCount; i++)
  1156. {
  1157. string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  1158. //富为使用包装单的逻辑
  1159. //如果不包含该箱号则进行添加
  1160. if (!Outboxcode.Contains(outboxcode2))
  1161. Outboxcode.Add(outboxcode2);
  1162. }
  1163. //按获取到的箱号列表进行打印
  1164. if (Outboxcode.ToArray().Length > 0)
  1165. {
  1166. for (int i = 0; i < Outboxcode.ToArray().Length; i++)
  1167. {
  1168. for (int h = 0; h < LabelInf.RowCount; h++)
  1169. {
  1170. if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i])
  1171. {
  1172. if (!AllLabel.Checked)
  1173. OutBoxCodePrint(h);
  1174. else
  1175. OutBoxCodePrint(h, true);
  1176. break;
  1177. }
  1178. }
  1179. }
  1180. }
  1181. else
  1182. {
  1183. MessageBox.Show("请勾选需要打印的外箱", "提示");
  1184. }
  1185. }
  1186. else
  1187. {
  1188. bool FindMidLabel = false;
  1189. try
  1190. {
  1191. int OutBoxLabelRowIndex = 0;
  1192. //查找是否存在该中盒号
  1193. for (int i = 0; i < LabelInf.RowCount; i++)
  1194. {
  1195. if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString())
  1196. {
  1197. //找到了输入的中盒号停止循环
  1198. FindMidLabel = true;
  1199. OutBoxLabelRowIndex = i;
  1200. break;
  1201. }
  1202. }
  1203. //找到了指定的盒号
  1204. if (FindMidLabel)
  1205. {
  1206. if (!AllLabel.Checked)
  1207. OutBoxCodePrint(OutBoxLabelRowIndex);
  1208. else
  1209. OutBoxCodePrint(OutBoxLabelRowIndex, true);
  1210. }
  1211. else
  1212. MessageBox.Show("该出入库单未找到该外箱号!", "提示");
  1213. }
  1214. catch (Exception) { }
  1215. }
  1216. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "手动打印箱标" + OutBoxNum.Text, "打印成功");
  1217. Outboxcode.Clear();
  1218. }
  1219. private void MidBoxCodePrint(int[] rowindex)
  1220. {
  1221. if (EnablePrint)
  1222. {
  1223. string pib_outboxcode1 = "";
  1224. for (int i = 0; i < rowindex.Length; i++)
  1225. {
  1226. if (i != rowindex.Length - 1)
  1227. pib_outboxcode1 += "'" + LabelInf.Rows[rowindex[i]].Cells["pib_outboxcode1"].Value.ToString() + "'" + ",";
  1228. else
  1229. pib_outboxcode1 += "'" + LabelInf.Rows[rowindex[i]].Cells["pib_outboxcode1"].Value.ToString() + "'";
  1230. }
  1231. //名称相等的时候,取SQL进行值的查询
  1232. DataTable dt;
  1233. sql.Clear();
  1234. sql.Append("update prodiobarcode set pib_midboxweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  1235. sql.Append(" and pib_outboxcode1 in(" + pib_outboxcode1 + ")");
  1236. dh.ExecuteSql(sql.ToString(), "update");
  1237. if (MidLabelAutoPrint.Checked)
  1238. {
  1239. if (CurrentRowOnly.Checked)
  1240. {
  1241. string PDNO = "";
  1242. if (SelectRowIndex >= 0)
  1243. {
  1244. PDNO = LabelInf.Rows[SelectRowIndex].Cells["pib_pdno"].Value.ToString();
  1245. }
  1246. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ") and 出货序号='" + (PDNO == "" ? CurrentPDNO : PDNO) + "'", "select");
  1247. }
  1248. else
  1249. {
  1250. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ")", "select");
  1251. }
  1252. }
  1253. else
  1254. {
  1255. if (CurrentRowOnly.Checked)
  1256. {
  1257. string PDNO = "";
  1258. if (SelectRowIndex >= 0)
  1259. {
  1260. PDNO = LabelInf.Rows[SelectRowIndex].Cells["pib_pdno"].Value.ToString();
  1261. }
  1262. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ") and 中盒标识='外' and 出货序号='" + (PDNO == "" ? CurrentPDNO : PDNO) + "'", "select");
  1263. }
  1264. else
  1265. {
  1266. dt = (DataTable)dh.ExecuteSql("select * from prodiomidinfo_view where 出货单号='" + pi_inoutno.Text + "' and 中盒号 in(" + pib_outboxcode1 + ") and 中盒标识='外'", "select");
  1267. }
  1268. }
  1269. if (dt.Rows.Count > 0)
  1270. {
  1271. if (!MidLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1272. MidReport.Load(MidLabelCombox.SelectedValue.ToString());
  1273. for (int j = 0; j < MidReport.Parameters.Count; j++)
  1274. {
  1275. MidReport.SetParameterValue(MidReport.Parameters[j].Name, "");
  1276. for (int i = 0; i < Attach.Rows.Count; i++)
  1277. {
  1278. if (Attach.Rows[i][0].ToString() == MidReport.Parameters[j].Name)
  1279. {
  1280. MidReport.SetParameterValue(MidReport.Parameters[j].Name, Attach.Rows[i][1].ToString());
  1281. }
  1282. }
  1283. }
  1284. MidReport.RegisterData(dt, "prodiomidinfo_view");
  1285. MidReport.GetDataSource("prodiomidinfo_view").Enabled = true;
  1286. MidReport.PrintSettings.ShowDialog = false;
  1287. MidReport.PrintSettings.Printer = MidLabelPrinter.Text;
  1288. MidReport.Print();
  1289. dh.UpdateByCondition("prodiobarcode", "pib_midifprint=-1", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode1 in (" + pib_outboxcode1 + ")");
  1290. SelectRowIndex = -1;
  1291. LoadGridData(new object(), new EventArgs());
  1292. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "打印中盒" + pib_outboxcode1.Replace("'", ""), "打印成功");
  1293. }
  1294. Properties.Settings.Default.MPrinter = MidLabelPrinter.Text;
  1295. Properties.Settings.Default.Save();
  1296. }
  1297. }
  1298. /// <summary>
  1299. /// 执行打印外箱号
  1300. /// </summary>
  1301. private void OutBoxCodePrint(int rowindex)
  1302. {
  1303. if (EnablePrint)
  1304. {
  1305. if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1306. OutReport.Load(OutBoxCombox.SelectedValue.ToString());
  1307. for (int j = 0; j < OutReport.Parameters.Count; j++)
  1308. {
  1309. OutReport.SetParameterValue(OutReport.Parameters[j].Name, "");
  1310. for (int i = 0; i < Attach.Rows.Count; i++)
  1311. {
  1312. if (Attach.Rows[i][0].ToString() == OutReport.Parameters[j].Name)
  1313. {
  1314. OutReport.SetParameterValue(OutReport.Parameters[j].Name, Attach.Rows[i][1].ToString());
  1315. }
  1316. }
  1317. }
  1318. string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
  1319. string SQL = "";
  1320. if (OnlyOneRow.Checked)
  1321. {
  1322. SQL = "select * from prodiooutinfo_view where 出货单号 = '" + pi_inoutno.Text + "' and 外箱号 = '" + pib_outboxcode2 + "' and rownum=1";
  1323. }
  1324. else
  1325. {
  1326. SQL = "select * from prodiooutinfo_view where 出货单号 = '" + pi_inoutno.Text + "' and 外箱号 = '" + pib_outboxcode2 + "'";
  1327. }
  1328. DataTable dt = (DataTable)dh.ExecuteSql(SQL, "select");
  1329. OutReport.RegisterData(dt, "prodiooutinfo_view");
  1330. OutReport.GetDataSource("prodiooutinfo_view").Enabled = true;
  1331. OutReport.PrintSettings.ShowDialog = false;
  1332. OutReport.PrintSettings.Printer = OutBoxPrinter.Text;
  1333. OutReport.Print();
  1334. Properties.Settings.Default.OPrinter = OutBoxPrinter.Text;
  1335. Properties.Settings.Default.Save();
  1336. dh.UpdateByCondition("prodiobarcode", "pib_outifprint=-1", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + pib_outboxcode2 + "'");
  1337. }
  1338. }
  1339. /// <summary>
  1340. /// 执行打印外箱号
  1341. /// </summary>
  1342. private void OutBoxCodePrint(int rowindex, bool AllLabel)
  1343. {
  1344. if (EnablePrint)
  1345. {
  1346. int selectedindex = OutBoxCombox.SelectedIndex;
  1347. for (int i = 0; i < OutBoxCombox.Items.Count; i++)
  1348. {
  1349. OutBoxCombox.SelectedIndex = i;
  1350. if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1351. OutReport.Load(OutBoxCombox.SelectedValue.ToString());
  1352. for (int j = 0; j < OutReport.Parameters.Count; j++)
  1353. {
  1354. OutReport.SetParameterValue(OutReport.Parameters[j].Name, "");
  1355. for (int k = 0; k < Attach.Rows.Count; k++)
  1356. {
  1357. if (Attach.Rows[k][0].ToString() == OutReport.Parameters[j].Name)
  1358. {
  1359. OutReport.SetParameterValue(OutReport.Parameters[j].Name, Attach.Rows[k][1].ToString());
  1360. }
  1361. }
  1362. }
  1363. string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
  1364. DataTable dt = (DataTable)dh.ExecuteSql("select * from prodiooutinfo_view where 出货单号='" + pi_inoutno.Text + "' and 外箱号='" + pib_outboxcode2 + "'", "select");
  1365. OutReport.RegisterData(dt, "prodiooutinfo_view");
  1366. OutReport.GetDataSource("prodiooutinfo_view").Enabled = true;
  1367. OutReport.PrintSettings.ShowDialog = false;
  1368. OutReport.PrintSettings.Printer = OutBoxPrinter.Text;
  1369. OutReport.Print();
  1370. }
  1371. OutBoxCombox.SelectedIndex = selectedindex;
  1372. Properties.Settings.Default.OPrinter = OutBoxPrinter.Text;
  1373. Properties.Settings.Default.Save();
  1374. dh.UpdateByCondition("prodiobarcode", "pib_outifprint=-1", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + pib_outboxcode2 + "'");
  1375. }
  1376. }
  1377. private void CleanDetail_Click(object sender, EventArgs e)
  1378. {
  1379. if (dh.getFieldDataByCondition("prodinout", "pi_statuscode", "pi_inoutno='" + pi_inoutno.Text + "'").ToString() == "POSTED")
  1380. {
  1381. //MessageBox.Show("单据" + pi_inoutno.Text + "已过账,不允许删除条码");
  1382. //return;
  1383. }
  1384. ArrayList<string> DeleteID = new ArrayList<string>();
  1385. for (int i = 0; i < LabelInf.RowCount; i++)
  1386. {
  1387. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString().ToLower() == "true")
  1388. DeleteID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1389. }
  1390. //勾选了删除的明细之后
  1391. if (DeleteID.ToArray().Length > 0)
  1392. {
  1393. string close = MessageBox.Show(this.ParentForm, "删除后不可恢复,是否确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1394. if (close.ToString() == "Yes")
  1395. {
  1396. dh.BatchInsert("delete from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray());
  1397. 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 + "'");
  1398. //dh.UpdateByCondition("CS$InoutPrcode", "checknum=CollectedNum/pjd_zxbzs_user", "pd_inoutno='" + pi_inoutno.Text + "'");
  1399. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "删除明细", "删除明细成功");
  1400. MessageBox.Show("删除成功", "提示");
  1401. Input.Clear();
  1402. LoadPrcodeData();
  1403. LoadGridData(sender, e);
  1404. if (int.Parse(dh.getFieldDataByCondition("prodiobarcode", "count(1)", "pib_inoutno='" + pi_inoutno.Text + "'").ToString()) == 0)
  1405. {
  1406. dh.UpdateByCondition("prodinout", "pi_user_packingstatus=''", "pi_inoutno='" + pi_inoutno.Text + "'");
  1407. }
  1408. else
  1409. {
  1410. dh.UpdateByCondition("prodinout", "pi_user_packingstatus='Packing'", "pi_inoutno='" + pi_inoutno.Text + "'");
  1411. }
  1412. }
  1413. }
  1414. else
  1415. MessageBox.Show("尚未勾选需要删除的明细", "提示");
  1416. }
  1417. private void OutBoxLabelPrint_Click(object sender, EventArgs e)
  1418. {
  1419. if (OutBoxCombox.Text != "")
  1420. {
  1421. Pack_Click(sender, e);
  1422. if (Weight.Text != "" && Weight.Text != "0.000")
  1423. {
  1424. //记录整箱的重量
  1425. sql.Clear();
  1426. sql.Append("update prodiobarcode set pib_totalweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  1427. sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "'");
  1428. dh.ExecuteSql(sql.ToString(), "update");
  1429. }
  1430. LoadGridData(sender, e);
  1431. thread = new Thread(OutBoxPrint);
  1432. stw = new SetLoadingWindow(thread, "正在打印外箱");
  1433. BaseUtil.SetFormCenter(stw);
  1434. stw.ShowDialog();
  1435. Input.Focus();
  1436. }
  1437. else
  1438. MessageBox.Show("未维护外箱标签", "提示");
  1439. Input.Focus();
  1440. }
  1441. /// <summary>
  1442. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  1443. /// </summary>
  1444. /// <param name="sender"></param>
  1445. /// <param name="e"></param>
  1446. private void LoadGridData(object sender, EventArgs e)
  1447. {
  1448. AllChecked = false;
  1449. string SQL = "";
  1450. if (OutBoxNum.Text != "全部")
  1451. {
  1452. //LogicHandler.GetDataSQL(PI_ID, "and pib_outboxcode2='" + OutBoxNum.Text + "'", out SQL);
  1453. SQL = "select pib_boxweight,pib_midboxweight,pib_totalweight,pd_custprodcode,pd_custprodspec,nvl(pib_midifprint,0)pib_midifprint,pib_custmidboxcode,pd_pocode,pjd_orispeccode," +
  1454. "pib_madein,pib_custbarcode,pib_custoutboxcode,pib_id,pib_datecode1,pib_pdid,pib_piid,pib_pdno,pib_prodcode,pib_brand,pr_vendprodcode,pib_lotno,pib_datecode," +
  1455. "week_to_date(pib_datecode) datecode1,pib_qty,pr_spec,pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,pib_outboxcode2,nvl(pib_ifprint, 0)pib_ifprint,pd_remark,pd_remark2 from prodiobarcode left join " +
  1456. "prodiodetail on pib_piid = pd_piid and pd_pdno = pib_pdno and pd_prodcode = pib_prodcode left join product on pr_code = pib_prodcode left join sale on sa_code = pib_ordercode left join " +
  1457. "PRODJOINVENDDETAIL on pjd_brand = pd_brand and pjd_prodcode = pd_prodcode where pib_piid = '" + PI_ID + "' and pib_outboxcode2='" + OutBoxNum.Text + "' order by to_number(pib_outboxcode2),pib_id,pd_prodcode";
  1458. }
  1459. else
  1460. {
  1461. SQL = "select pib_boxweight,pib_midboxweight,pib_totalweight,pd_custprodcode,pd_custprodspec,nvl(pib_midifprint,0)pib_midifprint,pib_custmidboxcode,pd_pocode,pjd_orispeccode," +
  1462. "pib_madein,pib_custbarcode,pib_custoutboxcode,pib_id,pib_datecode1,pib_pdid,pib_piid,pib_pdno,pib_prodcode,pib_brand,pr_vendprodcode,pib_lotno,pib_datecode," +
  1463. "week_to_date(pib_datecode) datecode1,pib_qty,pr_spec,pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,pib_outboxcode2,nvl(pib_ifprint, 0)pib_ifprint,pd_remark,pd_remark2 from prodiobarcode left join " +
  1464. "prodiodetail on pib_piid = pd_piid and pd_pdno = pib_pdno and pd_prodcode = pib_prodcode left join product on pr_code = pib_prodcode left join sale on sa_code = pib_ordercode left join " +
  1465. "PRODJOINVENDDETAIL on pjd_brand = pd_brand and pjd_prodcode = pd_prodcode where pib_piid = '" + PI_ID + "' order by to_number(pib_outboxcode2),pib_id,pd_prodcode";
  1466. }
  1467. LabelInfDataTable = (DataTable)dh.ExecuteSql(SQL, "select");
  1468. BoxCount.Text = LabelInfDataTable.Compute("sum(pib_qty)", "1=1").ToString() + "KPCS";
  1469. bindingsource(LabelInf, LabelInfDataTable);
  1470. if (LabelInf.Rows.Count > 0)
  1471. {
  1472. LabelInf.FirstDisplayedScrollingRowIndex = LabelInf.Rows.Count - 1;
  1473. }
  1474. sql.Clear();
  1475. 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 ");
  1476. sql.Append("where pib_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno ");
  1477. SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1478. }
  1479. private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1480. {
  1481. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  1482. pi_inoutno_KeyDown(sender, e2);
  1483. }
  1484. private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1485. {
  1486. string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1487. if (close.ToString() == "Yes")
  1488. {
  1489. Login login = new Login();
  1490. //注销的时候需要将拼接的连接字符串置空
  1491. DataHelper.DBConnectionString = null;
  1492. logout = true;
  1493. this.Hide();
  1494. login.ShowDialog();
  1495. this.Close();
  1496. }
  1497. }
  1498. private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1499. /// <summary>
  1500. /// 切换打开的单盘文件
  1501. /// </summary>
  1502. /// <param name="sender"></param>
  1503. /// <param name="e"></param>
  1504. private void SingleLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1505. {
  1506. try
  1507. {
  1508. if (ComBoxClickChangeLabelDoc)
  1509. {
  1510. if (!SingleLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1511. SingleReport.Load(SingleLabelCombox.SelectedValue.ToString());
  1512. }
  1513. }
  1514. catch (Exception) { }
  1515. }
  1516. /// <summary>
  1517. /// 切换打开的中盒文件
  1518. /// </summary>
  1519. /// <param name="sender"></param>
  1520. /// <param name="e"></param>
  1521. private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1522. {
  1523. try
  1524. {
  1525. if (ComBoxClickChangeLabelDoc)
  1526. {
  1527. if (!MidLabelCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1528. MidReport.Load(MidLabelCombox.SelectedValue.ToString());
  1529. }
  1530. }
  1531. catch (Exception) { }
  1532. }
  1533. /// <summary>
  1534. /// 切换打开的外箱文件
  1535. /// </summary>
  1536. /// <param name="sender"></param>
  1537. /// <param name="e"></param>
  1538. private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e)
  1539. {
  1540. try
  1541. {
  1542. if (ComBoxClickChangeLabelDoc)
  1543. {
  1544. if (!OutBoxCombox.SelectedValue.ToString().Contains("System.Data.DataRowView"))
  1545. OutReport.Load(OutBoxCombox.SelectedValue.ToString());
  1546. }
  1547. }
  1548. catch (Exception) { }
  1549. }
  1550. private void ChooseAll_Click(object sender, EventArgs e)
  1551. {
  1552. if (AllChecked)
  1553. {
  1554. foreach (DataGridViewRow dr in LabelInf.Rows)
  1555. dr.Cells[0].Value = false;
  1556. AllChecked = false;
  1557. }
  1558. else
  1559. {
  1560. foreach (DataGridViewRow dr in LabelInf.Rows)
  1561. dr.Cells[0].Value = true;
  1562. AllChecked = true;
  1563. }
  1564. }
  1565. private void ExportData_Click(object sender, EventArgs e)
  1566. {
  1567. ShowMenu.Items.Clear();
  1568. DataTable dt = (DataTable)dh.ExecuteSql("select * from CS_EXPORTSETTING where es_custcode='" + pi_cardcode.Text + "'", "select");
  1569. if (dt.Rows.Count == 0)
  1570. dt = (DataTable)dh.ExecuteSql("select * from CS_EXPORTSETTING where es_custcode is null", "select");
  1571. for (int i = 0; i < dt.Rows.Count; i++)
  1572. {
  1573. ShowMenu.Items.Add(new ToolStripMenuItem(dt.Rows[i]["el_remark"].ToString() + "#" + dt.Rows[i]["el_type"].ToString()));
  1574. }
  1575. ShowMenu.Show(new Point(ExportData.Location.X, ExportData.Location.Y + 20));
  1576. }
  1577. private void ShowMenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  1578. {
  1579. //获取类型,单盘或者外箱
  1580. string type = e.ClickedItem.Text.Split('#')[1];
  1581. ExportFileDialog.Description = "选择导出的路径";
  1582. DialogResult result = ExportFileDialog.ShowDialog();
  1583. if (result == DialogResult.OK)
  1584. {
  1585. ExcelHandler eh = new ExcelHandler();
  1586. 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");
  1587. if (Field.Rows.Count == 0)
  1588. {
  1589. 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");
  1590. }
  1591. string Fileds = "";
  1592. for (int i = 0; i < Field.Rows.Count; i++)
  1593. {
  1594. Fileds += Field.Rows[i]["esd_filed"].ToString() + ",";
  1595. }
  1596. sql.Clear();
  1597. sql.Append("select " + Fileds.Substring(0, Fileds.Length - 1) + " from ExportView where pib_inoutno='" + pi_inoutno.Text + "'");
  1598. string finnalSQL = "";
  1599. LogicHandler.GetExportDataSQL(pi_inoutno.Text, pi_cardcode.Text, type, sql.ToString(), out finnalSQL);
  1600. dt = (DataTable)dh.ExecuteSql(finnalSQL, "select");
  1601. eh.ExportExcel(dt, Field, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text + type);
  1602. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1603. if (close.ToString() == "Yes")
  1604. Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + type + ".xls");
  1605. }
  1606. }
  1607. private void AttachInfo_Click(object sender, EventArgs e)
  1608. {
  1609. if (pi_cardcode.Text != "")
  1610. {
  1611. 附件内容打印 att = new 附件内容打印(pi_cardcode.Text);
  1612. att.ShowDialog();
  1613. }
  1614. else MessageBox.Show("请先获取出库单信息", "提示");
  1615. }
  1616. private void MidBoxCapacity_Leave(object sender, EventArgs e)
  1617. {
  1618. NumericUpDown nup = (NumericUpDown)sender;
  1619. switch (nup.Name)
  1620. {
  1621. case "MidBoxCapacity":
  1622. Properties.Settings.Default.MidBoxCapacity = nup.Value;
  1623. Properties.Settings.Default.Save();
  1624. break;
  1625. case "OutboxCapacity":
  1626. Properties.Settings.Default.OutboxCapacity = nup.Value;
  1627. Properties.Settings.Default.Save();
  1628. break;
  1629. default:
  1630. break;
  1631. }
  1632. }
  1633. private void RefreshDBConnect_Tick(object sender, EventArgs e)
  1634. {
  1635. dh.ExecuteSql("select sysdate from dual", "select");
  1636. }
  1637. DataTable CSPrcode;
  1638. private void LoadPrcodeData()
  1639. {
  1640. 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,0 checknum 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");
  1641. GridPrcode.DataSource = Prcode;
  1642. List<int> RemoveIndex = new List<int>();
  1643. double CollectNum = 0;
  1644. double OutNum = 0;
  1645. int combined = 0;
  1646. if (Combindetail.Checked)
  1647. combined = 1;
  1648. if (CombindetailTwo.Checked)
  1649. combined = 2;
  1650. if (Combindetail.Checked || CombindetailTwo.Checked)
  1651. {
  1652. 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,nvl(checknum,0)checknum from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "' and combined=" + combined + " order by pd_pdno", "select");
  1653. if (CSPrcode.Rows.Count == 0)
  1654. {
  1655. int CurrentIndex = 0;
  1656. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1657. {
  1658. string CurrentPrCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1659. string CurrentPDNO = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  1660. string CurrentOutQTY = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  1661. if (SumQty == null)
  1662. {
  1663. sql.Clear();
  1664. 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 ");
  1665. sql.Append("where pib_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno ");
  1666. SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1667. }
  1668. string collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  1669. CollectNum += double.Parse(collectqty == "" ? "0" : collectqty);
  1670. OutNum += double.Parse(CurrentOutQTY);
  1671. GridPrcode.Rows[i].Cells["CollectedNum"].Value = collectqty == "" ? "0" : collectqty;
  1672. }
  1673. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1674. {
  1675. if (i + 1 < GridPrcode.Rows.Count)
  1676. {
  1677. string BProdCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1678. string BCustProdCode = GridPrcode.Rows[i].Cells["pd_custprodcode1"].Value.ToString();
  1679. string BWhCode = GridPrcode.Rows[i].Cells["pd_whcode"].Value.ToString();
  1680. string BPrUnit = GridPrcode.Rows[i].Cells["pr_unit"].Value.ToString();
  1681. string BPrBrand = GridPrcode.Rows[i].Cells["pd_brand"].Value.ToString();
  1682. string BPoCode = GridPrcode.Rows[i].Cells["pd_pocode1"].Value.ToString();
  1683. string FProdCode = GridPrcode.Rows[i + 1].Cells["pd_prodcode"].Value.ToString();
  1684. string FCustProdCode = GridPrcode.Rows[i + 1].Cells["pd_custprodcode1"].Value.ToString();
  1685. string FPrUnit = GridPrcode.Rows[i + 1].Cells["pr_unit"].Value.ToString();
  1686. string FrBrand = GridPrcode.Rows[i + 1].Cells["pd_brand"].Value.ToString();
  1687. string FWhCode = GridPrcode.Rows[i + 1].Cells["pd_whcode"].Value.ToString();
  1688. string FPoCode = GridPrcode.Rows[i + 1].Cells["pd_pocode1"].Value.ToString();
  1689. if (BProdCode == FProdCode && BPrBrand == FrBrand && BCustProdCode == FCustProdCode && (CombindetailTwo.Checked && FPoCode == BPoCode || Combindetail.Checked))
  1690. {
  1691. 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());
  1692. 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());
  1693. RemoveIndex.Add(i + 1);
  1694. }
  1695. else
  1696. {
  1697. CurrentIndex = i + 1;
  1698. }
  1699. }
  1700. }
  1701. foreach (int item in RemoveIndex.OrderByDescending(x => x))
  1702. {
  1703. (GridPrcode.DataSource as DataTable).Rows.RemoveAt(item);
  1704. }
  1705. }
  1706. else GridPrcode.DataSource = CSPrcode;
  1707. }
  1708. else
  1709. {
  1710. 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,nvl(checknum,0)checknum from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "' and combined=" + combined + " order by pd_pdno", "select");
  1711. if (CSPrcode.Rows.Count == 0)
  1712. {
  1713. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  1714. {
  1715. string CurrentPrCode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  1716. string CurrentPDNO = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  1717. string CurrentOutQTY = GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString();
  1718. if (SumQty == null)
  1719. {
  1720. sql.Clear();
  1721. 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 ");
  1722. sql.Append("where pib_inoutno='" + pi_inoutno.Text + "' group by pib_prodcode,pib_pdno order by pib_pdno ");
  1723. SumQty = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1724. }
  1725. string collectqty = (SumQty.Compute("sum(pib_qty)", "pib_prodcode='" + CurrentPrCode + "' and pib_pdno='" + CurrentPDNO + "'").ToString());
  1726. CollectNum += double.Parse(collectqty == "" ? "0" : collectqty);
  1727. OutNum += double.Parse(CurrentOutQTY);
  1728. GridPrcode.Rows[i].Cells["CollectedNum"].Value = collectqty == "" ? "0" : collectqty;
  1729. }
  1730. }
  1731. else GridPrcode.DataSource = CSPrcode;
  1732. }
  1733. dh.UpdateByCondition("prodinout", "pi_combine_user=" + combined, "pi_inoutno='" + pi_inoutno.Text + "'");
  1734. if (CSPrcode.Rows.Count == 0)
  1735. {
  1736. sql.Clear();
  1737. sql.Append("insert into CS$InoutPrcode (pd_piid,pd_pdno,pd_custprodcode,pd_whcode,pd_prodcode,");
  1738. sql.Append("CollectedNum,UnCollectedNum,pd_outqty,pr_unit,pr_spec,pd_brand,pjd_zxbzs_user,pjd_id,pd_inoutno,combined,pd_pocode)");
  1739. 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)");
  1740. dh.SaveDataTable((GridPrcode.DataSource as DataTable), "CS$InoutPrcode", "pd_piid", sql.ToString());
  1741. }
  1742. else
  1743. {
  1744. CollectNum = float.Parse(CSPrcode.Compute("sum(CollectedNum)", "1=1").ToString());
  1745. OutNum = float.Parse(CSPrcode.Compute("sum(pd_outqty)", "1=1").ToString());
  1746. }
  1747. ProcessCount.Text = CollectNum + "/" + OutNum;
  1748. if (GridPrcode.Rows.Count > 0)
  1749. {
  1750. CurrentPrCode = GridPrcode.Rows[0].Cells["pd_prodcode"].Value.ToString();
  1751. CurrentZXBZ = GridPrcode.Rows[0].Cells["pjd_zxbzs_user"].Value.ToString();
  1752. CurrentUnit = GridPrcode.Rows[0].Cells["pr_unit"].Value.ToString();
  1753. CurrentPDNO = GridPrcode.Rows[0].Cells["pd_pdno"].Value.ToString();
  1754. CurrentPrCount = GridPrcode.Rows[0].Cells["pd_outqty"].Value.ToString();
  1755. CurrentBrand = GridPrcode.Rows[0].Cells["pd_brand"].Value.ToString();
  1756. GridPrcode.Rows[0].Selected = true;
  1757. }
  1758. }
  1759. private void OutBoxNum_Click(object sender, EventArgs e)
  1760. {
  1761. string OutBox = OutBoxNum.Text;
  1762. OutBoxNum.Items.Clear();
  1763. 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");
  1764. ItemObject io = new ItemObject("新增", "新增");
  1765. OutBoxNum.Items.Add(io);
  1766. io = new ItemObject("全部", "全部");
  1767. OutBoxNum.Items.Add(io);
  1768. for (int i = 0; i < dt.Rows.Count; i++)
  1769. {
  1770. string pib_outboxcode2 = dt.Rows[i]["pib_outboxcode2"].ToString();
  1771. io = new ItemObject(pib_outboxcode2, pib_outboxcode2);
  1772. OutBoxNum.Items.Add(io);
  1773. }
  1774. if (OutBoxNum.Text == "新增" || OutBoxNum.Text == "")
  1775. {
  1776. if (dt.Rows.Count > 0)
  1777. OutBoxNum.SelectedIndex = 2;
  1778. else
  1779. OutBoxNum.SelectedIndex = 0;
  1780. }
  1781. if (OutBox != "新增" && OutBox != "")
  1782. OutBoxNum.Text = OutBox;
  1783. }
  1784. string ReSetType = "";
  1785. /// <summary>
  1786. /// 获取条码规则
  1787. /// </summary>
  1788. /// <param name="Type"></param>
  1789. /// <param name="Prefix"></param>
  1790. /// <param name="Suffix"></param>
  1791. /// <param name="MaxNum"></param>
  1792. /// <param name="SerialNumLength"></param>
  1793. /// <param name="Radix"></param>
  1794. private void GetBarCodeRule(out string Prefix, out string Suffix, out int MaxNum, out int SerialNumLength, out int Radix, int Count)
  1795. {
  1796. //获取编码规则
  1797. Prefix = "";
  1798. Suffix = "";
  1799. NrCode = "";
  1800. MaxNum = 0;
  1801. SerialNumLength = 0;
  1802. Radix = 0;
  1803. 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");
  1804. //如果没有则取公共规则
  1805. if (Nr.Rows.Count == 0)
  1806. 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");
  1807. //用于过滤参数的正则表达式
  1808. ReSetType = "";
  1809. if (Nr.Rows.Count > 0)
  1810. {
  1811. string ShareRule = Nr.Rows[0]["nr_sharerule"].ToString();
  1812. 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");
  1813. if (dt1.Rows.Count > 0)
  1814. {
  1815. Nr = dt1;
  1816. }
  1817. else
  1818. {
  1819. if (ShareRule != "")
  1820. {
  1821. MessageBox.Show("共享规则" + ShareRule + "不存在");
  1822. return;
  1823. }
  1824. }
  1825. }
  1826. if (Nr.Rows.Count > 0)
  1827. {
  1828. switch (Nr.Rows[0]["nr_resettype"].ToString())
  1829. {
  1830. case "Year":
  1831. sql.Clear();
  1832. sql.Append("to_char(sysdate,'yyyy')");
  1833. break;
  1834. case "Month":
  1835. sql.Clear();
  1836. sql.Append("to_char(sysdate,'yyyyMM')");
  1837. break;
  1838. case "Week":
  1839. sql.Clear();
  1840. sql.Append("to_char(sysdate,'yyyyiw')");
  1841. break;
  1842. case "Day":
  1843. sql.Clear();
  1844. sql.Append("to_char(sysdate,'yyyyMMdd')");
  1845. break;
  1846. case " ":
  1847. sql.Clear();
  1848. sql.Append("' '");
  1849. break;
  1850. default:
  1851. break;
  1852. }
  1853. ReSetType = dh.getFieldDataByCondition("dual", sql.ToString(), "1=1").ToString();
  1854. }
  1855. Regex match = new Regex("{\\w+}");
  1856. //用于存放每一项的明细的数据
  1857. string[] NrData = new string[Nr.Rows.Count];
  1858. //流水长度
  1859. Dictionary<int, string> NrDic = new Dictionary<int, string>();
  1860. for (int m = 0; m < Nr.Rows.Count; m++)
  1861. {
  1862. NrCode = Nr.Rows[m]["nr_code"].ToString();
  1863. switch (Nr.Rows[m]["nrd_type"].ToString())
  1864. {
  1865. //常量直接进行拼接
  1866. case "常量":
  1867. Prefix += Nr.Rows[m]["nrd_sql"].ToString();
  1868. Suffix += Nr.Rows[m]["nrd_sql"].ToString();
  1869. break;
  1870. case "SQL":
  1871. string SQL = Nr.Rows[m]["nrd_sql"].ToString();
  1872. DataTable Temp;
  1873. //如果不包含参数替换
  1874. if (SQL.IndexOf("{") == 0)
  1875. {
  1876. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  1877. }
  1878. else
  1879. {
  1880. SQL = SQL.Replace("{pd_pdno}", CurrentPDNO);
  1881. //替换参数后重新执行SQL
  1882. foreach (Match mch in match.Matches(SQL))
  1883. {
  1884. SQL = SQL.Replace(mch.Value.Trim(), "'" + pi_inoutno.Text + "'");
  1885. }
  1886. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  1887. }
  1888. if (Temp.Rows.Count > 0)
  1889. {
  1890. Prefix += Temp.Rows[0][0].ToString();
  1891. Suffix += Temp.Rows[0][0].ToString();
  1892. }
  1893. break;
  1894. //流水需要通过MaxNumber去取
  1895. case "流水":
  1896. string maxnum = "";
  1897. if (ReSetType != " ")
  1898. {
  1899. maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'").ToString();
  1900. }
  1901. else
  1902. {
  1903. maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "' ").ToString();
  1904. }
  1905. //设置当前流水
  1906. if (maxnum == "")
  1907. {
  1908. if (ReSetType != " ")
  1909. {
  1910. maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'").ToString();
  1911. }
  1912. else
  1913. {
  1914. maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "' ").ToString();
  1915. }
  1916. if (maxnum == "")
  1917. {
  1918. maxnum = "1";
  1919. }
  1920. Count = int.Parse(maxnum) + Count;
  1921. 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");
  1922. MaxNum = int.Parse(maxnum);
  1923. }
  1924. else
  1925. {
  1926. MaxNum = int.Parse(maxnum);
  1927. if (ReSetType != " ")
  1928. {
  1929. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + Count) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'");
  1930. }
  1931. else
  1932. {
  1933. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + Count) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "'");
  1934. }
  1935. }
  1936. SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
  1937. Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString());
  1938. Suffix = "";
  1939. break;
  1940. default:
  1941. break;
  1942. }
  1943. }
  1944. }
  1945. private void GridPrcode_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  1946. {
  1947. string Value = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  1948. string ID = GridPrcode.Rows[e.RowIndex].Cells["pjd_id"].Value.ToString();
  1949. string checknum = GridPrcode.Rows[e.RowIndex].Cells["checknum"].Value.ToString();
  1950. string pdno = GridPrcode.Rows[e.RowIndex].Cells["pd_pdno"].Value.ToString();
  1951. if (GridPrcode.Columns[e.ColumnIndex].Name == "pjd_zxbzs_user")
  1952. {
  1953. dh.UpdateByCondition("PRODJOINVENDDETAIL", "pjd_zxbzs_user='" + Value + "'", "pjd_id='" + ID + "'");
  1954. dh.UpdateByCondition("CS$INOUTPRCODE", "pjd_zxbzs_user='" + Value + "'", "pjd_id='" + ID + "' and pd_inoutno='" + pi_inoutno.Text + "'");
  1955. }
  1956. if (GridPrcode.Columns[e.ColumnIndex].Name == "checknum")
  1957. {
  1958. //更新复核数据
  1959. dh.UpdateByCondition("CS$InoutPrcode", "checknum='" + checknum + "'", "pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + pdno + "' and combined=" + combined);
  1960. }
  1961. //删除对应物料的明细
  1962. CurrentPrCode = GridPrcode.Rows[e.RowIndex].Cells["pd_prodcode"].Value.ToString();
  1963. CurrentZXBZ = GridPrcode.Rows[e.RowIndex].Cells["pjd_zxbzs_user"].Value.ToString();
  1964. CurrentUnit = GridPrcode.Rows[e.RowIndex].Cells["pr_unit"].Value.ToString();
  1965. CurrentPDNO = GridPrcode.Rows[e.RowIndex].Cells["pd_pdno"].Value.ToString();
  1966. CurrentPrCount = GridPrcode.Rows[e.RowIndex].Cells["pd_outqty"].Value.ToString();
  1967. CurrentBrand = GridPrcode.Rows[e.RowIndex].Cells["pd_brand"].Value.ToString();
  1968. GridPrcode.Rows[e.RowIndex].Selected = true;
  1969. if (e.RowIndex - 2 >= 0)
  1970. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex - 2;
  1971. else
  1972. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex;
  1973. LoadGridData(sender, new EventArgs());
  1974. }
  1975. private void GridPrcode_SelectionChanged(object sender, EventArgs e)
  1976. {
  1977. if (GridPrcode.SelectedRows.Count > 0)
  1978. {
  1979. DataGridViewSelectedRowCollection dsc = GridPrcode.SelectedRows;
  1980. MachineCollectRowIndex = GridPrcode.SelectedRows[0].Index;
  1981. CurrentPrCode = GridPrcode.Rows[dsc[0].Index].Cells["pd_prodcode"].Value.ToString();
  1982. CurrentZXBZ = GridPrcode.Rows[dsc[0].Index].Cells["pjd_zxbzs_user"].Value.ToString();
  1983. CurrentUnit = GridPrcode.Rows[dsc[0].Index].Cells["pr_unit"].Value.ToString();
  1984. CurrentPDNO = GridPrcode.Rows[dsc[0].Index].Cells["pd_pdno"].Value.ToString();
  1985. CurrentPrCount = GridPrcode.Rows[dsc[0].Index].Cells["pd_outqty"].Value.ToString();
  1986. CurrentBrand = GridPrcode.Rows[dsc[0].Index].Cells["pd_brand"].Value.ToString();
  1987. GridPrcode.Rows[dsc[0].Index].Selected = true;
  1988. if (dsc[0].Index - 2 >= 0)
  1989. GridPrcode.FirstDisplayedScrollingRowIndex = dsc[0].Index - 2;
  1990. else
  1991. GridPrcode.FirstDisplayedScrollingRowIndex = dsc[0].Index;
  1992. }
  1993. }
  1994. private void GridPrcode_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1995. private void GridPrcode_CellClick(object sender, DataGridViewCellEventArgs e)
  1996. {
  1997. if (e.RowIndex >= 0)
  1998. {
  1999. GridPrcode.Rows[e.RowIndex].Selected = true;
  2000. if (e.RowIndex - 2 > 0)
  2001. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex - 2;
  2002. else
  2003. GridPrcode.FirstDisplayedScrollingRowIndex = e.RowIndex;
  2004. }
  2005. }
  2006. private void DCCheck_Leave(object sender, EventArgs e)
  2007. {
  2008. try
  2009. {
  2010. Properties.Settings.Default.DCCheck = int.Parse(DCCheck.Text);
  2011. Properties.Settings.Default.Save();
  2012. }
  2013. catch (Exception)
  2014. {
  2015. MessageBox.Show("DC校验时间必须是整数");
  2016. }
  2017. }
  2018. /// <summary>
  2019. /// 校验DateCode
  2020. /// </summary>
  2021. /// <param name="DateCode"></param>
  2022. private bool CheckDateCode(string DateCode)
  2023. {
  2024. try
  2025. {
  2026. //根据DateCode计算的日期
  2027. string Year = DateCode.Substring(0, 2);
  2028. System.DateTime dt = new System.DateTime(int.Parse("20" + Year), 01, 01);
  2029. string Week = DateCode.Substring(2, 2);
  2030. System.DateTime dt1 = dt.AddDays(int.Parse(Week) * 7);
  2031. //减去DC校验后的日期
  2032. System.DateTime now = System.DateTime.Now;
  2033. System.DateTime now1 = now.AddDays(-int.Parse(DCCheck.Text));
  2034. //物料的DateCode大于限制日期即可
  2035. if (dt1 > now1)
  2036. {
  2037. return true;
  2038. }
  2039. return false;
  2040. }
  2041. catch (Exception)
  2042. {
  2043. return false;
  2044. }
  2045. }
  2046. private void PrintFooter_Click(object sender, EventArgs e)
  2047. {
  2048. FootReport.Load(@"\\10.2.10.238\PRINTE\FASTREPORT\唛头.frx");
  2049. 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");
  2050. string SQL = "select pib_outboxcode2||'/'||(select max(to_number(pib_outboxcode2)) from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "') from prodiobarcode where pib_id=";
  2051. for (int i = 0; i < dt.Rows.Count; i++)
  2052. {
  2053. DataTable dt1 = (DataTable)dh.ExecuteSql(SQL + dt.Rows[i]["pib_id"].ToString(), "select");
  2054. FootReport.SetParameterValue("唛头", dt1.Rows[0][0].ToString());
  2055. FootReport.PrintSettings.ShowDialog = false;
  2056. FootReport.PrintSettings.Printer = SingleLabelPrinter.Text;
  2057. FootReport.Print();
  2058. }
  2059. LogManager.DoCommandLog(pi_inoutno.Text, User.UserCode, "打印唛头", "成功");
  2060. }
  2061. private void Input_KeyUp(object sender, KeyEventArgs e)
  2062. {
  2063. if (e.KeyCode == Keys.Enter)
  2064. {
  2065. Input.SelectAll();
  2066. }
  2067. }
  2068. private void GridPrcode_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  2069. {
  2070. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  2071. if (e.ColumnIndex > 0 && e.RowIndex >= 0)
  2072. {
  2073. if (GridPrcode.Columns[e.ColumnIndex].Name == "CollectedNum")
  2074. {
  2075. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  2076. if (GridPrcode.Rows[e.RowIndex].Cells["CollectedNum"].Value.ToString() != GridPrcode.Rows[e.RowIndex].Cells["pd_outqty"].Value.ToString())
  2077. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.Yellow, e.CellBounds);
  2078. else
  2079. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.White, e.CellBounds);
  2080. Rectangle border = e.CellBounds;
  2081. border.Width -= 1;
  2082. e.Graphics.DrawRectangle(Pens.White, border);
  2083. e.PaintContent(e.CellBounds);
  2084. e.Handled = true;
  2085. }
  2086. }
  2087. }
  2088. private void GridPrcode_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
  2089. {
  2090. if (e.Button == MouseButtons.Right)
  2091. {
  2092. if (e.RowIndex >= 0 && e.ColumnIndex > 0)
  2093. {
  2094. string Conetent = GridPrcode.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
  2095. Clipboard.SetText(Conetent);
  2096. MessageBox.Show("已复制内容" + Conetent);
  2097. }
  2098. }
  2099. }
  2100. private void Pack_Click(object sender, EventArgs e)
  2101. {
  2102. if (LabelInf.Rows.Count > 0)
  2103. {
  2104. int GetNumCount = 1;
  2105. for (int i = 0; i < LabelInf.Rows.Count; i++)
  2106. {
  2107. if (LabelInf.Rows[i].Cells["pib_custoutboxcode"].Value.ToString() == "")
  2108. {
  2109. if (i + 1 < LabelInf.Rows.Count)
  2110. {
  2111. string FPrcode = LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString();
  2112. string FPocode = LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString();
  2113. string FWhcode = LabelInf.Rows[i].Cells["pib_brand"].Value.ToString();
  2114. string FDC = LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString();
  2115. string FLOTNO = LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString();
  2116. string FPDCustProdCode = LabelInf.Rows[i].Cells["pd_custprodcode"].Value.ToString();
  2117. string BPrcode = LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString();
  2118. string BPocode = LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString();
  2119. string BWhcode = LabelInf.Rows[i + 1].Cells["pib_brand"].Value.ToString();
  2120. string BDC = LabelInf.Rows[i + 1].Cells["pib_datecode"].Value.ToString();
  2121. string BLOTNO = LabelInf.Rows[i + 1].Cells["pib_lotno"].Value.ToString();
  2122. string BPDCustProdCode = LabelInf.Rows[i + 1].Cells["pd_custprodcode"].Value.ToString();
  2123. if (FPDCustProdCode != BPDCustProdCode || FPrcode != BPrcode || FPocode != BPocode || FWhcode != BWhcode || (DiffDC.Checked && FDC != BDC) || (DiffLotNo.Checked && FLOTNO != BLOTNO))
  2124. {
  2125. GetNumCount = GetNumCount + 1;
  2126. }
  2127. }
  2128. }
  2129. }
  2130. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, GetNumCount);
  2131. List<string> OutBoxCode = new List<string>();
  2132. List<string> PIBID = new List<string>();
  2133. string Str_OutBoxCode = "";
  2134. for (int i = 0; i < LabelInf.Rows.Count; i++)
  2135. {
  2136. if (LabelInf.Rows[i].Cells["pib_custoutboxcode"].Value.ToString() == "")
  2137. {
  2138. PIBID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  2139. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  2140. for (int k = serialcode.ToString().Length; k < NumLength; k++)
  2141. {
  2142. serialcode = "0" + serialcode;
  2143. }
  2144. if (i + 1 < LabelInf.Rows.Count)
  2145. {
  2146. string FPrcode = LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString();
  2147. string FPocode = LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString();
  2148. string FWhcode = LabelInf.Rows[i].Cells["pib_brand"].Value.ToString();
  2149. string FDC = LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString();
  2150. string FLOTNO = LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString();
  2151. string FPDCustProdCode = LabelInf.Rows[i].Cells["pd_custprodcode"].Value.ToString();
  2152. string FPDNO = LabelInf.Rows[i].Cells["pib_pdno"].Value.ToString();
  2153. string BPrcode = LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString();
  2154. string BPocode = LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString();
  2155. string BWhcode = LabelInf.Rows[i + 1].Cells["pib_brand"].Value.ToString();
  2156. string BDC = LabelInf.Rows[i + 1].Cells["pib_datecode"].Value.ToString();
  2157. string BLOTNO = LabelInf.Rows[i + 1].Cells["pib_lotno"].Value.ToString();
  2158. string BPDCustProdCode = LabelInf.Rows[i + 1].Cells["pd_custprodcode"].Value.ToString();
  2159. string BPDNO = LabelInf.Rows[i + 1].Cells["pib_pdno"].Value.ToString();
  2160. if ((DiffDetno.Checked && BPDNO != FPDNO) || (DiffCPN.Checked && FPDCustProdCode != BPDCustProdCode) || FPrcode != BPrcode || FPocode != BPocode || FWhcode != BWhcode || (DiffDC.Checked && FDC != BDC) || (DiffLotNo.Checked && FLOTNO != BLOTNO))
  2161. {
  2162. MaxNum = MaxNum + 1;
  2163. }
  2164. }
  2165. OutBoxCode.Add(Prefix + serialcode + Suffix);
  2166. Str_OutBoxCode += "'" + Prefix + serialcode + Suffix + "',";
  2167. }
  2168. }
  2169. if (OutBoxCode.ToArray().Length > 0)
  2170. {
  2171. if (!dh.CheckExist("prodiobarcode", "pib_custcode='" + pi_cardcode.Text + "' and pib_custoutboxcode in (" + Str_OutBoxCode.Substring(0, Str_OutBoxCode.Length - 1) + ")"))
  2172. {
  2173. 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());
  2174. }
  2175. else
  2176. {
  2177. if (ReSetType != " ")
  2178. {
  2179. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and nvl(rmn_type,' ')='" + ReSetType + "'");
  2180. }
  2181. else
  2182. {
  2183. dh.UpdateByCondition("RULEMAXNUM", "rmn_maxnumber='" + (MaxNum + 1) + "'", "rmn_nrcode='" + (NrCode == "" ? "Default" : NrCode) + "' and rmn_prefix='" + Prefix + "'");
  2184. }
  2185. Pack_Click(sender, e);
  2186. return;
  2187. }
  2188. LoadGridData(sender, e);
  2189. }
  2190. }
  2191. }
  2192. private void PackMidBox_Click(object sender, EventArgs e)
  2193. {
  2194. DataTable dt = (DataTable)dh.ExecuteSql("select distinct pib_outboxcode2 from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + OutBoxNum.Text + "' order by pib_outboxcode2", "select");
  2195. DataTable dt1 = null;
  2196. int GetNumCount = 0;
  2197. for (int i = 0; i < dt.Rows.Count; i++)
  2198. {
  2199. 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");
  2200. //如果不是10的整数倍则为尾盒
  2201. int tencount = 0;
  2202. for (int j = 0; j < dt1.Rows.Count; j++)
  2203. {
  2204. 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()))
  2205. {
  2206. GetNumCount = GetNumCount + 1;
  2207. }
  2208. tencount = tencount + 1;
  2209. }
  2210. }
  2211. GetBarCodeRule(out Prefix, out Suffix, out MaxNum, out NumLength, out Radix, GetNumCount);
  2212. if (Radix > 0)
  2213. {
  2214. //生成中盒条码
  2215. int pib_outboxcode1 = int.Parse(dh.getFieldDataByCondition("prodiobarcode", "max(to_number(nvl(pib_outboxcode1,0)))", "pib_inoutno='" + pi_inoutno.Text + "'").ToString());
  2216. MaxNum = MaxNum - 1;
  2217. for (int i = 0; i < dt.Rows.Count; i++)
  2218. {
  2219. List<string> MidBoxCode = new List<string>();
  2220. List<string> PIBID = new List<string>();
  2221. List<string> PIBOUTBOXCODE1 = new List<string>();
  2222. 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");
  2223. //如果不是10的整数倍则为尾盒
  2224. int tencount = 0;
  2225. for (int j = 0; j < dt1.Rows.Count; j++)
  2226. {
  2227. 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()))
  2228. {
  2229. pib_outboxcode1 = pib_outboxcode1 + 1;
  2230. MaxNum = MaxNum + 1;
  2231. tencount = 0;
  2232. }
  2233. tencount = tencount + 1;
  2234. string serialcode = BaseUtil.DToAny(MaxNum, Radix);
  2235. for (int k = serialcode.ToString().Length; k < NumLength; k++)
  2236. {
  2237. serialcode = "0" + serialcode;
  2238. }
  2239. MidBoxCode.Add(Prefix + serialcode + Suffix);
  2240. PIBID.Add(dt1.Rows[j]["pib_id"].ToString());
  2241. PIBOUTBOXCODE1.Add(pib_outboxcode1.ToString());
  2242. }
  2243. 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());
  2244. }
  2245. }
  2246. LoadGridData(sender, e);
  2247. }
  2248. private void PrintStatus_Click(object sender, EventArgs e)
  2249. {
  2250. EnablePrint = !EnablePrint;
  2251. if (EnablePrint)
  2252. {
  2253. SetPrintStatus_label.ForeColor = Color.Green;
  2254. SetPrintStatus_label.Text = "可打印";
  2255. }
  2256. else
  2257. {
  2258. SetPrintStatus_label.ForeColor = Color.Red;
  2259. SetPrintStatus_label.Text = "暂停打印";
  2260. }
  2261. Input.Focus();
  2262. }
  2263. private void CustomerLabel_Click(object sender, EventArgs e)
  2264. {
  2265. sql.Clear();
  2266. sql.Append("update prodiobarcode set pib_custbarcode=case when instr(pib_custbarcode,'SL')=0 ");
  2267. sql.Append("then ('SL'||pib_custbarcode)else pib_custbarcode end, pib_custoutboxcode=case when instr");
  2268. sql.Append("(pib_custoutboxcode,'SC')=0 then ('SC'||pib_custoutboxcode)else pib_custoutboxcode end where pib_inoutno='" + pi_inoutno.Text + "'");
  2269. dh.ExecuteSql(sql.ToString(), "select");
  2270. LoadGridData(sender, e);
  2271. CustomerLabel.Enabled = false;
  2272. }
  2273. private void Combindetail_CheckedChanged(object sender, EventArgs e)
  2274. {
  2275. if (Combindetail.Checked)
  2276. {
  2277. CombindetailTwo.Checked = false;
  2278. }
  2279. if (LoadCheck)
  2280. {
  2281. LoadPrcodeData();
  2282. string response = "";
  2283. string[] param = new string[] { PI_ID, "1", response };
  2284. dh.CallProcedure("USER_PRODOUT_GROUPQTY", param);
  2285. }
  2286. }
  2287. private void CombindetailTwo_CheckedChanged(object sender, EventArgs e)
  2288. {
  2289. if (CombindetailTwo.Checked)
  2290. {
  2291. Combindetail.Checked = false;
  2292. }
  2293. if (LoadCheck)
  2294. {
  2295. LoadPrcodeData();
  2296. string response = "";
  2297. string[] param = new string[] { PI_ID, "2", response };
  2298. dh.CallProcedure("USER_PRODOUT_GROUPQTY", param);
  2299. }
  2300. }
  2301. string SelectProdcode = "";
  2302. int SelectRowIndex = -1;
  2303. private void LabelInf_CellClick(object sender, DataGridViewCellEventArgs e)
  2304. {
  2305. if (e.RowIndex >= 0)
  2306. {
  2307. LabelInf.Rows[e.RowIndex].Selected = true;
  2308. SelectRowIndex = e.RowIndex;
  2309. }
  2310. }
  2311. private void OutBoxNum_SelectedIndexChanged(object sender, EventArgs e)
  2312. {
  2313. OutBoxNum1 = OutBoxNum.Text;
  2314. LoadGridData(sender, e);
  2315. }
  2316. private void LabelInf_SelectionChanged(object sender, EventArgs e)
  2317. {
  2318. DataGridViewSelectedRowCollection dsc = LabelInf.SelectedRows;
  2319. if (dsc.Count > 0)
  2320. {
  2321. SelectRowIndex = dsc[0].Index;
  2322. }
  2323. }
  2324. string OutBoxNum1 = "";
  2325. private void OutBoxNum_SelectionChangeCommitted(object sender, EventArgs e)
  2326. {
  2327. if (OutBoxNum1 != "全部" && OutBoxNum1 != "新增")
  2328. if (dh.getFieldDataByCondition("prodiobarcode", "pib_outifprint", "pib_inoutno='" + pi_inoutno.Text + "' and pib_outboxcode2='" + OutBoxNum1 + "'").ToString() != "-1")
  2329. {
  2330. MessageBox.Show("外箱号" + OutBoxNum1 + "尚未打印标签");
  2331. }
  2332. OutBoxNum1 = OutBoxNum.Text;
  2333. if (OutBoxNum1 == "新增")
  2334. {
  2335. PassSixTenCount = 1;
  2336. PassTenCount = 1;
  2337. CurrentBoxNum.Value = 0;
  2338. CurrentOutBoxNum.Value = 0;
  2339. }
  2340. }
  2341. private void Reset_Click(object sender, EventArgs e)
  2342. {
  2343. string close = MessageBox.Show(this.ParentForm, "清除当前已采集数据,刷新待采集数据", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  2344. if (close.ToString() == "Yes")
  2345. {
  2346. dh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  2347. dh.ExecuteSql("delete from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "'", "delete");
  2348. dh.UpdateByCondition("prodinout", "pi_user_packingstatus=''", "pi_inoutno='" + pi_inoutno.Text + "'");
  2349. pi_inoutno_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  2350. }
  2351. }
  2352. private void AddNewOutBox_Click(object sender, EventArgs e)
  2353. {
  2354. OutBoxNum.Text = "新增";
  2355. }
  2356. private void GetPDdata_Click(object sender, EventArgs e)
  2357. {
  2358. dh.ExecuteSql("delete from CS$InoutPrcode where pd_inoutno='" + pi_inoutno.Text + "'", "delete");
  2359. LoadPrcodeData();
  2360. 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 + "'");
  2361. MessageBox.Show("同步出货单明细数据成功", "提示");
  2362. }
  2363. private void ResetHBXH_Click(object sender, EventArgs e)
  2364. {
  2365. dh.ExecuteSql("update prodiodetail set PD_HBXH_USER=pd_pdno where pd_inoutno='" + pi_inoutno.Text + "'", "update");
  2366. MessageBox.Show("重置序号成功", "提示");
  2367. }
  2368. private void ButtonWeigh_Click(object sender, EventArgs e)
  2369. {
  2370. if (Weight.Text != "" && Weight.Text != "0.000")
  2371. {
  2372. sql.Clear();
  2373. sql.Append("update prodiobarcode set pib_boxweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  2374. sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "'");
  2375. dh.ExecuteSql(sql.ToString(), "update");
  2376. LoadGridData(sender, e);
  2377. }
  2378. else
  2379. {
  2380. MessageBox.Show("请先连接电子秤!");
  2381. }
  2382. }
  2383. Regex reg = new Regex(@"\d+.\d+");
  2384. ComInfoSet cis;
  2385. private void ConnectCom_Click(object sender, EventArgs e)
  2386. {
  2387. cis = new ComInfoSet();
  2388. (cis.Controls["PortName"] as SerialPortCombox).SelectedValue = Properties.Settings.Default.PortName;
  2389. cis.Controls["BaudRate"].Text = Properties.Settings.Default.BaudRate;
  2390. cis.Controls["Confirm"].Click += UAS_出货标签打印_Click;
  2391. cis.ShowDialog();
  2392. }
  2393. private void UAS_出货标签打印_Click(object sender, EventArgs e)
  2394. {
  2395. if (Com.IsOpen && Com.PortName == cis.Controls["PortName"].Text)
  2396. {
  2397. MessageBox.Show("串口" + Com.PortName + "已打开");
  2398. return;
  2399. }
  2400. else
  2401. {
  2402. if (Com.IsOpen)
  2403. {
  2404. Com.Close();
  2405. }
  2406. }
  2407. int BaudRate = 0;
  2408. Com.PortName = cis.Controls["PortName"].Text;
  2409. if (int.TryParse(cis.Controls["BaudRate"].Text, out BaudRate))
  2410. {
  2411. Com.BaudRate = BaudRate;
  2412. }
  2413. Properties.Settings.Default.BaudRate = BaudRate.ToString();
  2414. Properties.Settings.Default.PortName = cis.Controls["PortName"].Text;
  2415. Properties.Settings.Default.Save();
  2416. Com.DataReceived += Com_DataReceived;
  2417. Com.Open();
  2418. cis.Close();
  2419. }
  2420. private void Com_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
  2421. {
  2422. try
  2423. {
  2424. int len = Com.BytesToRead;
  2425. byte[] readBuffer = new byte[len];
  2426. Com.Read(readBuffer, 0, len); //将数据读入缓存
  2427. string value = reg.Match(Encoding.ASCII.GetString(readBuffer, 0, len)).Value;
  2428. if (value != "")
  2429. {
  2430. Weight.Text = value;
  2431. }
  2432. //读不到数据的时间删掉
  2433. }
  2434. catch (Exception)
  2435. {
  2436. return;
  2437. }
  2438. }
  2439. private void CloseSerialPort_Click(object sender, EventArgs e)
  2440. {
  2441. if (Com.IsOpen)
  2442. {
  2443. Com.Close();
  2444. Com.DataReceived -= Com_DataReceived;
  2445. }
  2446. }
  2447. private void ShowMenu_Total_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  2448. {
  2449. ShowMenu_Total.Close();
  2450. switch (e.ClickedItem.Text)
  2451. {
  2452. case "清除明细":
  2453. CleanDetail_Click(sender, e);
  2454. break;
  2455. case "标签维护":
  2456. LabelMaintain_Click(sender, e);
  2457. break;
  2458. case "打印唛头":
  2459. PrintFooter_Click(sender, e);
  2460. break;
  2461. case "附加信息":
  2462. AttachInfo_Click(sender, e);
  2463. break;
  2464. case "打印状态":
  2465. PrintStatus_Click(sender, e);
  2466. break;
  2467. case "标签自定义":
  2468. CustomerLabel_Click(sender, e);
  2469. break;
  2470. case "同步出货数据":
  2471. GetPDdata_Click(sender, e);
  2472. break;
  2473. case "重置单据":
  2474. Reset_Click(sender, e);
  2475. break;
  2476. case "贴标机参数设置":
  2477. MachineSetting ms = new MachineSetting();
  2478. BaseUtil.SetFormCenter(ms);
  2479. ms.ShowDialog();
  2480. break;
  2481. case "断开贴标机":
  2482. receiveClient.Close();
  2483. sendClient.Close();
  2484. resetClient.Close();
  2485. break;
  2486. case "贴标角度设置":
  2487. if (pi_cardcode.Text != "")
  2488. {
  2489. 贴标角度设置 ms1 = new 贴标角度设置(pi_cardcode.Text);
  2490. ms1.FormClosed += Ms1_FormClosed;
  2491. BaseUtil.SetFormCenter(ms1);
  2492. ms1.ShowDialog();
  2493. }
  2494. else
  2495. {
  2496. MessageBox.Show("请先获取客户信息");
  2497. }
  2498. break;
  2499. }
  2500. }
  2501. private void Ms1_FormClosed(object sender, FormClosedEventArgs e)
  2502. {
  2503. DataTable XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "' and px_machine='" + SystemInf.Machine + "'", "select");
  2504. if (XY.Rows.Count == 0)
  2505. {
  2506. XY = (DataTable)dh.ExecuteSql("select * from PRINTXY where px_custcode='" + pi_cardcode.Text + "'", "select");
  2507. }
  2508. if (XY.Rows.Count > 0)
  2509. {
  2510. Angle = XY.Rows[0]["px_angle"].ToString();
  2511. X = XY.Rows[0]["px_x"].ToString();
  2512. Y = XY.Rows[0]["px_y"].ToString();
  2513. }
  2514. }
  2515. private void MenuManage_Click(object sender, EventArgs e)
  2516. {
  2517. ShowMenu_Total.Show(new Point(MenuManage.Location.X, MenuManage.Location.Y + 20));
  2518. }
  2519. SqliteDBHelper sdh = SystemInf.sdh;
  2520. //接受数据客户端
  2521. TcpClient receiveClient;
  2522. //发送指令客户端
  2523. TcpClient sendClient;
  2524. //复核数据客户端
  2525. TcpClient resetClient;
  2526. NetworkStream ns;
  2527. NetworkStream ns1;
  2528. Thread receiveThread;
  2529. Thread sendThread;
  2530. int dataindex = 0;
  2531. string ps_split = "";
  2532. private void Connect_Click(object sender, EventArgs e)
  2533. {
  2534. SingleLabelAutoPrint.Checked = true;
  2535. MidLabelAutoPrint.Checked = true;
  2536. CurrentRowOnly.Checked = true;
  2537. AutoPrintMidBox.Checked = true;
  2538. receiveClient = new TcpClient();
  2539. sendClient = new TcpClient();
  2540. resetClient = new TcpClient();
  2541. DataTable dt = (DataTable)sdh.ExecuteSql("select * from ParamSetting", "select");
  2542. if (dt.Rows.Count > 0)
  2543. {
  2544. try
  2545. {
  2546. //发起TCP连接
  2547. receiveClient.Connect(dt.Rows[0]["ps_ip"].ToString(), int.Parse(dt.Rows[0]["ps_receiveport"].ToString()));
  2548. sendClient.Connect(dt.Rows[0]["ps_ip"].ToString(), int.Parse(dt.Rows[0]["ps_sendport"].ToString()));
  2549. resetClient.Connect(dt.Rows[0]["ps_ip"].ToString(), int.Parse(dt.Rows[0]["ps_resetport"].ToString()));
  2550. dataindex = int.Parse(dt.Rows[0]["ps_dataindex"].ToString());
  2551. ps_split = dt.Rows[0]["ps_split"].ToString();
  2552. if (receiveClient != null)
  2553. {
  2554. MessageBox.Show("连接服务器成功");
  2555. ConnectToMachine = true;
  2556. //获得绑定的网络数据流
  2557. ns = receiveClient.GetStream();
  2558. ns1 = sendClient.GetStream();
  2559. Control.CheckForIllegalCrossThreadCalls = false;
  2560. //实例化并启动接受消息线程
  2561. receiveThread = new Thread(receive_message);
  2562. receiveThread.Start();
  2563. sendThread = new Thread(send_message);
  2564. sendThread.Start();
  2565. }
  2566. else
  2567. {
  2568. MessageBox.Show("连接服务器失败");
  2569. }
  2570. }
  2571. catch (Exception ex)
  2572. {
  2573. MessageBox.Show(ex.Message);
  2574. }
  2575. }
  2576. }
  2577. bool IsSum = false;
  2578. private void receive_message()
  2579. {
  2580. while (IsOnline(receiveClient))
  2581. {
  2582. try
  2583. {
  2584. //创建接收数据的字节流
  2585. byte[] getData = new byte[1024];
  2586. //从网络流中读取数据
  2587. ns.Read(getData, 0, getData.Length);
  2588. //将字节数组转换成文本形式
  2589. string getMsg = Encoding.Default.GetString(getData);
  2590. if (getMsg.Contains("ReadId"))
  2591. {
  2592. string msgStr = getMsg.Trim('\0').Replace("ReadId1|,|", "");
  2593. if (!msgStr.Contains("三星"))
  2594. {
  2595. msgStr = Regex.Match(msgStr, @"[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+").Value;
  2596. //设置索引和内容
  2597. // msgStr = msgStr.Split(ps_split.ToCharArray()[0])[dataindex];
  2598. Input.Text = msgStr;
  2599. IsSum = false;
  2600. }
  2601. else
  2602. {
  2603. IsSum = true;
  2604. }
  2605. Input_KeyDown(Input, new KeyEventArgs(Keys.Enter));
  2606. }
  2607. }
  2608. catch (Exception e)
  2609. {
  2610. //接受消息发生异常
  2611. break;
  2612. //并释放相关资源
  2613. //if (ns != null)
  2614. // ns.Dispose();
  2615. //break;
  2616. }
  2617. }
  2618. MessageBox.Show("网络中断");
  2619. }
  2620. private void send_message()
  2621. {
  2622. while (IsOnline(sendClient))
  2623. {
  2624. try
  2625. {
  2626. //创建接收数据的字节流
  2627. byte[] getData = new byte[1024];
  2628. //从网络流中读取数据 z
  2629. ns1.Read(getData, 0, getData.Length);
  2630. //将字节数组转换成文本形式
  2631. string getMsg = Encoding.Default.GetString(getData);
  2632. if (getMsg.Contains("ReadId3"))
  2633. {
  2634. string msgStr = getMsg.Trim('\0').Replace("ReadId3|,|", "");
  2635. string temp = Regex.Match(msgStr, @"[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+\*[-{0,5}/{0,5}.{0,5}0-9A-Za-z]+").Value;
  2636. string pr_code = "";
  2637. //如果不存在原厂标签的话
  2638. if (temp != "")
  2639. {
  2640. pr_code = temp.Split('*')[0];
  2641. }
  2642. //如果允许混料的话
  2643. bool OutBoxSplit = false;
  2644. if (PassSixTenCount > OutboxCapacity.Value)
  2645. {
  2646. string close = MessageBox.Show(this.ParentForm, "此箱号采集后超数量,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly).ToString();
  2647. if (close == "Yes")
  2648. {
  2649. OutBoxSplit = true;
  2650. PassSixTenCount = 1;
  2651. //sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|0"));
  2652. }
  2653. else
  2654. {
  2655. }
  2656. }
  2657. if (MixPrCode.Checked)
  2658. {
  2659. bool SendLast = false;
  2660. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  2661. {
  2662. //获取复核的数据
  2663. int checknum = int.Parse(GridPrcode.Rows[i].Cells["checknum"].Value.ToString());
  2664. double outqty = double.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString());
  2665. double zxbzs = double.Parse(GridPrcode.Rows[i].Cells["PJD_ZXBZS_USER"].Value.ToString());
  2666. string Prcode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  2667. string pdno = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  2668. if (checknum < outqty / zxbzs)
  2669. {
  2670. checknum = checknum + 1;
  2671. GridPrcode.Rows[i].Cells["checknum"].Value = checknum;
  2672. dh.ExecuteSql("update CS$InoutPrcode set checknum=nvl(checknum,0)+1 where pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + pdno + "' and combined=" + combined, "update");
  2673. if (i == GridPrcode.Rows.Count - 1 && checknum == outqty / zxbzs)
  2674. SendLast = true;
  2675. break;
  2676. }
  2677. }
  2678. if (PassTenCount == MidboxCapacity.Value)
  2679. {
  2680. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1"));
  2681. PassTenCount = 0;
  2682. }
  2683. else
  2684. {
  2685. if (SendLast)
  2686. {
  2687. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1"));
  2688. string close = MessageBox.Show("采集完此行数据,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly).ToString();
  2689. if (close == "Yes")
  2690. {
  2691. }
  2692. else
  2693. {
  2694. }
  2695. }
  2696. else
  2697. {
  2698. if (!OutBoxSplit)
  2699. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|0"));
  2700. }
  2701. }
  2702. }
  2703. else
  2704. {
  2705. bool SendLast = false;
  2706. for (int i = 0; i < GridPrcode.Rows.Count; i++)
  2707. {
  2708. //获取复核的数据
  2709. int checknum = int.Parse(GridPrcode.Rows[i].Cells["checknum"].Value.ToString());
  2710. double outqty = double.Parse(GridPrcode.Rows[i].Cells["pd_outqty"].Value.ToString());
  2711. double zxbzs = double.Parse(GridPrcode.Rows[i].Cells["PJD_ZXBZS_USER"].Value.ToString());
  2712. string Prcode = GridPrcode.Rows[i].Cells["pd_prodcode"].Value.ToString();
  2713. string pdno = GridPrcode.Rows[i].Cells["pd_pdno"].Value.ToString();
  2714. string SelectPrCode = GridPrcode.Rows[MachineCollectRowIndex].Cells["pd_prodcode"].Value.ToString();
  2715. if ((MachineCollectRowIndex == i && SelectPrCode == pr_code) || ((pr_code == Prcode || pr_code == "") && SelectPrCode != pr_code) && checknum < outqty / zxbzs)
  2716. {
  2717. checknum = checknum + 1;
  2718. GridPrcode.Rows[i].Cells["checknum"].Value = checknum;
  2719. if (checknum < outqty / zxbzs)
  2720. {
  2721. dh.ExecuteSql("update CS$InoutPrcode set checknum=nvl(checknum,0)+1 where pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + pdno + "' and combined=" + combined, "update");
  2722. }
  2723. else if (checknum == outqty / zxbzs)
  2724. {
  2725. dh.ExecuteSql("update CS$InoutPrcode set checknum=nvl(checknum,0)+1 where pd_inoutno='" + pi_inoutno.Text + "' and pd_pdno='" + pdno + "' and combined=" + combined, "update");
  2726. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1"));
  2727. checknum = 0;
  2728. SendLast = true;
  2729. PassTenCount = 0;
  2730. string close = MessageBox.Show("采集完此行数据,是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly).ToString();
  2731. if (close == "Yes")
  2732. {
  2733. }
  2734. else
  2735. {
  2736. }
  2737. }
  2738. break;
  2739. }
  2740. }
  2741. //达到了中盒容量之后
  2742. if (PassTenCount == MidboxCapacity.Value)
  2743. {
  2744. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|1"));
  2745. PassTenCount = 0;
  2746. }
  2747. else
  2748. {
  2749. //如果发送了最后一盒,则不发送继续堆叠的指令 或者需要分盒的时候
  2750. if ((!SendLast && !OutBoxSplit) || OutBoxSplit)
  2751. {
  2752. sendClient.Client.Send(Encoding.ASCII.GetBytes("ReadId3|,|OK|,|0"));
  2753. }
  2754. }
  2755. }
  2756. //中盒当前进度
  2757. CurrentBoxNum.Value = PassTenCount;
  2758. PassTenCount = PassTenCount + 1;
  2759. //外箱当前进度
  2760. CurrentOutBoxNum.Value = PassSixTenCount;
  2761. PassSixTenCount = PassSixTenCount + 1;
  2762. }
  2763. //设置索引和内容
  2764. //msgStr = msgStr.Split(ps_split.ToCharArray()[0])[dataindex];
  2765. //Input.Text = msgStr;
  2766. //Input_KeyDown(Input, new KeyEventArgs(Keys.Enter));
  2767. //}
  2768. //catch (ThreadAbortException)
  2769. //{
  2770. // //捕捉到线程被终止异常则表示是人为的断开TCP连接
  2771. // //不弹出错误提示
  2772. // break;
  2773. }
  2774. catch (Exception e)
  2775. {
  2776. //接受消息发生异常
  2777. break;
  2778. //并释放相关资源
  2779. //if (ns != null)
  2780. // ns.Dispose();
  2781. //break;
  2782. }
  2783. }
  2784. MessageBox.Show("网络中断");
  2785. }
  2786. private string GetSendCode(string Code)
  2787. {
  2788. if (Angle != "")
  2789. {
  2790. Code = Code + "|,|" + Angle;
  2791. }
  2792. if (X != "")
  2793. {
  2794. Code = Code + "|,|" + X;
  2795. }
  2796. if (Y != "")
  2797. {
  2798. Code = Code + "|,|" + Y;
  2799. }
  2800. return Code;
  2801. }
  2802. /// <summary>
  2803. /// 检测TCP连接是否存在还是已经中断
  2804. /// </summary>
  2805. /// <param name="c"></param>
  2806. /// <returns></returns>
  2807. public bool IsOnline(TcpClient c)
  2808. {
  2809. try
  2810. {
  2811. bool result = !((c.Client.Poll(1000, SelectMode.SelectRead) && (c.Client.Available == 0)) || !c.Client.Connected);
  2812. return result;
  2813. }
  2814. catch
  2815. {
  2816. return false;
  2817. }
  2818. }
  2819. private void CurrentBoxNum_ValueChanged(object sender, EventArgs e)
  2820. {
  2821. }
  2822. private void CurrentBoxNum_KeyDown(object sender, KeyEventArgs e)
  2823. {
  2824. if (e.KeyCode == Keys.Enter)
  2825. {
  2826. PassTenCount = int.Parse(CurrentBoxNum.Value.ToString()) + 1;
  2827. }
  2828. }
  2829. private void CurrentOutBoxNum_KeyDown(object sender, KeyEventArgs e)
  2830. {
  2831. if (e.KeyCode == Keys.Enter)
  2832. {
  2833. PassSixTenCount = int.Parse(CurrentOutBoxNum.Value.ToString()) + 1;
  2834. }
  2835. }
  2836. private void richTextAutoBottom1_TextChanged(object sender, EventArgs e)
  2837. {
  2838. }
  2839. private void Weight_Click(object sender, EventArgs e)
  2840. {
  2841. }
  2842. private void groupBoxWithBorder2_Enter(object sender, EventArgs e)
  2843. {
  2844. }
  2845. private void DCCheck_TextChanged(object sender, EventArgs e)
  2846. {
  2847. }
  2848. private void GridPrcode_CellContentClick(object sender, DataGridViewCellEventArgs e)
  2849. {
  2850. }
  2851. private void label18_Click(object sender, EventArgs e)
  2852. {
  2853. }
  2854. private void MidBoxEnd_TextChanged(object sender, EventArgs e)
  2855. {
  2856. }
  2857. private void MidBoxBegin_TextChanged(object sender, EventArgs e)
  2858. {
  2859. }
  2860. private void label16_Click(object sender, EventArgs e)
  2861. {
  2862. }
  2863. private void SingleBoxEnd_TextChanged(object sender, EventArgs e)
  2864. {
  2865. }
  2866. private void SingleBoxBegin_TextChanged(object sender, EventArgs e)
  2867. {
  2868. }
  2869. private void label12_Click(object sender, EventArgs e)
  2870. {
  2871. }
  2872. private void label7_Click(object sender, EventArgs e)
  2873. {
  2874. }
  2875. private void groupBoxWithBorder1_Enter(object sender, EventArgs e)
  2876. {
  2877. }
  2878. private void Input_TextChanged(object sender, EventArgs e)
  2879. {
  2880. }
  2881. private void LabelInf_CellContentClick(object sender, DataGridViewCellEventArgs e)
  2882. {
  2883. }
  2884. private void pi_inoutno_TextChanged(object sender, EventArgs e)
  2885. {
  2886. }
  2887. private void label14_Click(object sender, EventArgs e)
  2888. {
  2889. }
  2890. private void CurrentOutBoxNum_ValueChanged(object sender, EventArgs e)
  2891. {
  2892. }
  2893. private void label13_Click(object sender, EventArgs e)
  2894. {
  2895. }
  2896. private void SingleLabelPrinter_Load(object sender, EventArgs e)
  2897. {
  2898. }
  2899. private void SingleLabelAutoPrint_CheckedChanged(object sender, EventArgs e)
  2900. {
  2901. }
  2902. private void SingleLabel_Enter(object sender, EventArgs e)
  2903. {
  2904. }
  2905. private void CurrentRowOnly_CheckedChanged(object sender, EventArgs e)
  2906. {
  2907. }
  2908. private void MidboxCapacity_ValueChanged(object sender, EventArgs e)
  2909. {
  2910. }
  2911. private void label2_Click(object sender, EventArgs e)
  2912. {
  2913. }
  2914. private void MidLabelNum_TextChanged(object sender, EventArgs e)
  2915. {
  2916. }
  2917. private void label5_Click(object sender, EventArgs e)
  2918. {
  2919. }
  2920. private void MidLabelPrinter_Load(object sender, EventArgs e)
  2921. {
  2922. }
  2923. private void MidLabelAutoPrint_CheckedChanged(object sender, EventArgs e)
  2924. {
  2925. }
  2926. private void MidLabel_Enter(object sender, EventArgs e)
  2927. {
  2928. }
  2929. private void DiffDetno_CheckedChanged(object sender, EventArgs e)
  2930. {
  2931. }
  2932. private void DiffCPN_CheckedChanged(object sender, EventArgs e)
  2933. {
  2934. }
  2935. private void BoxCount_Click(object sender, EventArgs e)
  2936. {
  2937. }
  2938. private void DiffLotNo_CheckedChanged(object sender, EventArgs e)
  2939. {
  2940. }
  2941. private void DiffDC_CheckedChanged(object sender, EventArgs e)
  2942. {
  2943. }
  2944. private void OnlyOneRow_CheckedChanged(object sender, EventArgs e)
  2945. {
  2946. }
  2947. private void AllLabel_CheckedChanged(object sender, EventArgs e)
  2948. {
  2949. }
  2950. private void label10_Click(object sender, EventArgs e)
  2951. {
  2952. }
  2953. private void label6_Click(object sender, EventArgs e)
  2954. {
  2955. }
  2956. private void OutBoxPrinter_Load(object sender, EventArgs e)
  2957. {
  2958. }
  2959. private void OutboxCapacity_ValueChanged(object sender, EventArgs e)
  2960. {
  2961. }
  2962. private void OutBoxLabel_Enter(object sender, EventArgs e)
  2963. {
  2964. }
  2965. private void ButtonMidWeigh_Click(object sender, EventArgs e)
  2966. {
  2967. if (Weight.Text != "" && Weight.Text != "0.000")
  2968. {
  2969. string pib_outboxcode1 = LabelInf.Rows[SelectRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  2970. sql.Clear();
  2971. sql.Append("update prodiobarcode set pib_midboxweight='" + Weight.Text + "' where pib_inoutno='" + pi_inoutno.Text + "' ");
  2972. sql.Append(" and pib_outboxcode2='" + OutBoxNum.Text + "' and pib_outboxcode1='" + pib_outboxcode1 + "'");
  2973. dh.ExecuteSql(sql.ToString(), "update");
  2974. LoadGridData(sender, e);
  2975. }
  2976. else
  2977. {
  2978. MessageBox.Show("请先连接电子秤!");
  2979. }
  2980. }
  2981. }
  2982. }