UAS_出货标签管理.cs 163 KB

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