UAS_出货标签管理.cs 139 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949
  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.Linq;
  9. using System.Diagnostics;
  10. using LabelManager2;
  11. using UAS_LabelMachine.PublicMethod;
  12. using UAS_LabelMachine.Entity;
  13. using UAS_LabelMachine.PublicForm;
  14. using System.Threading;
  15. using System.IO;
  16. using System.Globalization;
  17. using System.Reflection;
  18. using Seagull.BarTender.Print;
  19. namespace UAS_LabelMachine
  20. {
  21. public partial class UAS_出货标签打印 : Form
  22. {
  23. //自适应屏幕
  24. AutoSizeFormClass asc = new AutoSizeFormClass();
  25. DataHelper dh;
  26. SqliteDBHelper sdh;
  27. DataTable dt;
  28. /// <summary>
  29. /// 已经打印过的Vivo外箱号
  30. /// </summary>
  31. List<string> PrintedVivoOutboxCode = new List<string>();
  32. StringBuilder sql = new StringBuilder();
  33. /// <summary>
  34. /// CodeSoft新建打印机引擎
  35. /// </summary>
  36. ApplicationClass lbl;
  37. /// <summary>
  38. /// CodeSoft单盘打印文件
  39. /// </summary>
  40. Document SingleDoc;
  41. /// <summary>
  42. /// CodeSoft中盒打印文件
  43. /// </summary>
  44. Document MidDoc;
  45. /// <summary>
  46. /// CodeSoft外箱打印文件
  47. /// </summary>
  48. Document OutBoxDoc;
  49. /// <summary>
  50. /// Loading窗口
  51. /// </summary>
  52. SetLoadingWindow stw;
  53. /// <summary>
  54. /// 弹窗线程
  55. /// </summary>
  56. Thread thread;
  57. /// <summary>
  58. /// 当前品牌
  59. /// </summary>
  60. string Brand;
  61. string PI_ID;
  62. /// <summary>
  63. /// 当前扫描的项目
  64. /// </summary>
  65. int CurrentItemIndex = 0;
  66. /// <summary>
  67. /// 当前扫描的所在行
  68. /// </summary>
  69. int CurrentRowIndex = 0;
  70. /// <summary>
  71. /// 最大的出入口单号
  72. /// </summary>
  73. int MaxOutBoxCode = 1;
  74. /// <summary>
  75. /// 正则表达式用于项目匹配
  76. /// </summary>
  77. Regex reg;
  78. /*标识供应商物料编号采集是否通过*/
  79. bool CollectVeProdCodePass = true;
  80. bool CollectQTYPass = true;
  81. bool logout = false;
  82. //每个不同序号存在的
  83. object[] ItemData;
  84. DataTable SingleLabelParam;
  85. DataTable MidLabelParam;
  86. DataTable OutLabelParam;
  87. /// <summary>
  88. /// BarTender引擎
  89. /// </summary>
  90. Engine engine;
  91. /// <summary>
  92. /// BarTender单盘
  93. /// </summary>
  94. LabelFormatDocument SingleFormat;
  95. /// <summary>
  96. /// BarTender中盒
  97. /// </summary>
  98. LabelFormatDocument MidFormat;
  99. /// <summary>
  100. /// BarTender外箱
  101. /// </summary>
  102. LabelFormatDocument OutFormat;
  103. Dictionary<string, string> CollectData;
  104. //缓存单盘数据数据的DataTable
  105. /// <summary>
  106. /// 存放单盘的ID
  107. /// </summary>
  108. List<string> SingleID = new List<string>();
  109. /// <summary>
  110. /// 单盘的打印参数
  111. /// </summary>
  112. List<string> SingleBoxArgument = new List<string>();
  113. /// <summary>
  114. /// 中盒缓存数据
  115. /// </summary>
  116. /// <summary>
  117. /// 存放中盒的ID和盒号
  118. /// </summary>
  119. Dictionary<string, string> MidIDAndOutboxcode = new Dictionary<string, string>();
  120. /// <summary>
  121. /// 中盒的打印参数
  122. /// </summary>
  123. List<string> MidBoxArgument = new List<string>();
  124. /// <summary>
  125. /// 全部采集
  126. /// </summary>
  127. bool AllCollect = false;
  128. /// <summary>
  129. /// 是否获取过箱号
  130. /// </summary>
  131. bool GetPackingCode = false;
  132. /*用于存放采集项目的Grid信息*/
  133. Dictionary<string, Dictionary<string, string>> SiItem;
  134. int CloumnCount = 0;
  135. //使用二维数组进行排序
  136. ArrayList<ArrayList<string>> ScanData;
  137. ArrayList<string> GetData;
  138. /// <summary>
  139. /// 是否通过选择Combox来改变打开的文件
  140. /// </summary>
  141. bool ComBoxClickChangeLabelDoc = false;
  142. List<string> MidParam = new List<string>();
  143. List<string> OutParam = new List<string>();
  144. public static DataTable Attach;
  145. public string PrintMethod = "CodeSoft";
  146. public UAS_出货标签打印(string Master)
  147. {
  148. //设置窗体的双缓冲
  149. this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
  150. this.UpdateStyles();
  151. InitializeComponent();
  152. //利用反射设置DataGridView的双缓冲
  153. Type dgvType = this.LabelInf.GetType();
  154. PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
  155. pi.SetValue(this.LabelInf, true, null);
  156. Text = Text + "-" + Master;
  157. }
  158. protected override void WndProc(ref System.Windows.Forms.Message m)
  159. {
  160. //拦截双击标题栏、移动窗体的系统消息
  161. if (m.Msg != 0xA3)
  162. {
  163. base.WndProc(ref m);
  164. }
  165. }
  166. private void 贴标机条码打印_Load(object sender, EventArgs e)
  167. {
  168. //杀死之前全部未关闭的进程
  169. Process[] processes = System.Diagnostics.Process.GetProcessesByName("lppa");
  170. Process[] processes1 = System.Diagnostics.Process.GetProcessesByName("bartend");
  171. for (int i = 0; i < processes1.Length; i++)
  172. {
  173. processes1[i].Kill();
  174. }
  175. for (int i = 0; i < processes.Length; i++)
  176. {
  177. processes[i].Kill();
  178. }
  179. //用计时器重置数据库链接
  180. LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
  181. dh = SystemInf.dh;
  182. sdh = SystemInf.sdh;
  183. sdh.ExecuteZip();
  184. CheckForIllegalCrossThreadCalls = false;
  185. CloumnCount = LabelInf.Columns.Count;
  186. pi_inoutno.TableName = "prodinout";
  187. pi_inoutno.Field = "pi_inoutno";
  188. pi_inoutno.ValueField = "pi_inoutno";
  189. pi_inoutno.Condition = "pi_class in('出货单','拨出单')";
  190. pi_inoutno.Focus();
  191. //将本地读取的打印机设置进Combox,并选中默认打印机
  192. sg_code.FormName = Name;
  193. sg_code.SetValueField = new string[] { "sg_code" };
  194. sg_code.SelectField = "sg_code # 策略编号 ,sg_name # 策略名称,sg_brand # 品牌,sg_separator # 分隔符";
  195. sg_code.TableName = "scangroup";
  196. sg_code.DbChange += Sg_code_DbChange;
  197. pr_code.FormName = Name;
  198. pr_code.SetValueField = new string[] { "pr_code" };
  199. pr_code.TableName = "prodiodetail left join product on pd_prodcode=pr_code";
  200. pr_code.SelectField = "pd_pdno # 行号,pr_code # 物料编号";
  201. cu_code.FormName = Name;
  202. cu_code.SetValueField = new string[] { "cu_code" };
  203. cu_code.TableName = "customer";
  204. cu_code.SelectField = "cu_code # 客户编号,cu_name # 客户名称";
  205. CollectionUnit.Text = "盘";
  206. Point pt = new Point();
  207. //禁止所有列的排序
  208. foreach (DataGridViewColumn dgv in LabelInf.Columns)
  209. {
  210. dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
  211. }
  212. int ScreenWidth = Screen.GetWorkingArea(pt).Width;
  213. //设置获取当前屏幕大小自动全屏但是保留任务栏
  214. Rectangle ScreenArea = Screen.GetWorkingArea(this);
  215. Top = 0;
  216. Left = 0;
  217. Width = ScreenArea.Width;
  218. Height = ScreenArea.Height;
  219. MidBoxCapacity.Value = Properties.Settings.Default.MidBoxCapacity;
  220. OutboxCapacity.Value = Properties.Settings.Default.OutboxCapacity;
  221. SingleLabelPrinter.Text = Properties.Settings.Default.SinglePrinter;
  222. MidLabelPrinter.Text = Properties.Settings.Default.MidPrinter;
  223. OutBoxPrinter.Text = Properties.Settings.Default.OutPrinter;
  224. asc.controllInitializeSize(this);
  225. asc.controlAutoSize(this);
  226. string Code = dh.GetConfig("PrintMethod", "CodeOrBar").ToString();
  227. SystemInf.CheckDcAndLotNo = dh.GetConfig("PrintCheck", "CheckDcAndLotNo").ToString() == "" ? false : true;
  228. if (Code == "")
  229. {
  230. try
  231. {
  232. lbl = new ApplicationClass();
  233. }
  234. catch (Exception)
  235. {
  236. MessageBox.Show("未安装CodeSoft软件或者版本不正确");
  237. }
  238. }
  239. else
  240. {
  241. engine = new Engine(true);
  242. PrintMethod = "BarTender";
  243. }
  244. pi_inoutno.BringToFront();
  245. }
  246. private void Sg_code_DbChange(object sender, EventArgs e)
  247. {
  248. DataTable dt = sg_code.ReturnData;
  249. BaseUtil.SetFormValue(this.Controls, dt);
  250. }
  251. //只执行一次窗体自适应
  252. bool AutoSized = false;
  253. private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
  254. {
  255. if (!AutoSized)
  256. {
  257. asc.controlAutoSize(this);
  258. AutoSized = true;
  259. }
  260. }
  261. private void GenerateBarCode_Click(object sender, EventArgs e)
  262. {
  263. 生成条码 form = new 生成条码(pi_inoutno.Text);
  264. form.FormClosed += LoadGridData;
  265. BaseUtil.SetFormCenter(form);
  266. form.ShowDialog();
  267. }
  268. private void LabelFormClose(object sender, EventArgs e)
  269. {
  270. if (GetGridOnly.Checked)
  271. GetInOutInfAndLabelFile();
  272. else
  273. {
  274. GetInOutInfAndLabelFile();
  275. }
  276. }
  277. /// <summary>
  278. /// 保存明细
  279. /// </summary>
  280. /// <param name="sender"></param>
  281. /// <param name="e"></param>
  282. private void SaveGrid_Click(object sender, EventArgs e)
  283. {
  284. DataTable dt = (DataTable)sdh.ExecuteSql("select pib_id,pib_outboxcode1,pib_outboxcode2,pib_custmidboxcode,pib_custoutboxcode,pib_lotno,pib_datecode,pib_ifupload,pib_ifpick,pib_ifprint from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_ifpick=-1 ", "select");
  285. if (dt.Rows.Count > 0)
  286. {
  287. dh.CallProcedure("sp_uploadbarcode", dt);
  288. MessageBox.Show("保存成功!");
  289. }
  290. }
  291. //放大镜选择后出发的事件
  292. private void sg_code_UserControlTextChanged(object sender, EventArgs e)
  293. {
  294. //取已启用的的按照采集次序排序
  295. dt = (DataTable)dh.ExecuteSql("select si_item,si_detno,sg_separator,si_kind,si_expression,si_expressionitem,si_index,si_indexstring,si_length from scanitem left join scangroup on si_sgid=sg_id where sg_code='" + sg_code.Text + "' and si_enable<>0 order by si_detno,si_innerdetno", "select");
  296. BaseUtil.FillDgvWithDataTable(Si_ItemDGV, dt);
  297. if (dt.Rows.Count > 0)
  298. {
  299. sg_separator.Text = dt.Rows[0]["sg_separator"].ToString();
  300. }
  301. //按DetNo排列之后的采集项
  302. ScanData = new ArrayList<ArrayList<string>>();
  303. //每个采集项目的子项
  304. GetData = new ArrayList<string>();
  305. //将数据添加进一个List的二维数组中
  306. for (int i = 0; i < Si_ItemDGV.RowCount; i++)
  307. {
  308. //如果不包含这个则添加进数组
  309. if (!GetData.Contains(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString()))
  310. {
  311. GetData.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString());
  312. }
  313. //如果和后一个的采集次序相同
  314. if (((i + 1) < Si_ItemDGV.RowCount) && Si_ItemDGV.Rows[i].Cells["si_detno"].Value.ToString() == Si_ItemDGV.Rows[i + 1].Cells["si_detno"].Value.ToString())
  315. {
  316. GetData.Add(Si_ItemDGV.Rows[i + 1].Cells["si_item"].Value.ToString());
  317. }
  318. else
  319. {
  320. ScanData.Add(GetData);
  321. //添加完一次数据需要一个新的List
  322. GetData = new ArrayList<string>();
  323. }
  324. }
  325. RemindUser();
  326. if (ScanData.ToArray().Length > 0)
  327. {
  328. object[] arr = (ScanData.ToArray()[0] as ArrayList<string>).ToArray();
  329. if (arr.Contains("MPN"))
  330. {
  331. AutoMatch.CheckState = CheckState.Checked;
  332. AutoMatch.Enabled = true;
  333. }
  334. else
  335. {
  336. AutoMatch.CheckState = CheckState.Unchecked;
  337. AutoMatch.Enabled = false;
  338. }
  339. }
  340. }
  341. //输入框Enter事件
  342. private void Input_KeyDown(object sender, KeyEventArgs e)
  343. {
  344. if (e.KeyCode == Keys.Enter)
  345. {
  346. if (Input.Text == "")
  347. {
  348. MessageBox.Show("采集的数据不能为空");
  349. return;
  350. }
  351. if (Si_ItemDGV.Rows.Count == 0)
  352. {
  353. MessageBox.Show("未维护采集策略");
  354. return;
  355. }
  356. CollectInputData();
  357. }
  358. }
  359. /// <summary>
  360. /// 设置自动匹配的数据的行号
  361. /// </summary>
  362. /// <returns></returns>
  363. private void SetAutoMatchRow()
  364. {
  365. //采集策略的第一组数据
  366. string[] arr = new string[ItemData.Length];
  367. if (sg_separator.Text == "")
  368. {
  369. for (int i = 0; i < arr.Length; i++)
  370. {
  371. arr[i] = Input.Text;
  372. }
  373. }
  374. else
  375. {
  376. arr = Input.Text.Split(sg_separator.Text.ToCharArray()).ToArray();
  377. }
  378. bool FindAutoMatch = false;
  379. for (int i = 0; i < LabelInf.RowCount; i++)
  380. {
  381. for (int j = 0; j < arr.Length; j++)
  382. {
  383. if (LabelInf.Rows[i].Cells["pr_vendprodcode"].Value.ToString() == MatchStr(arr[j].ToString(), "MPN") && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  384. {
  385. CurrentRowIndex = i;
  386. FindAutoMatch = true;
  387. break;
  388. }
  389. }
  390. if (FindAutoMatch)
  391. break;
  392. }
  393. }
  394. /// <summary>
  395. /// 采集数据
  396. /// </summary>
  397. private void CollectInputData()
  398. {
  399. LogManager.DoLog("采集数据【" + Input.Text + "】,使用采集策略编号【" + sg_code.Text + "】");
  400. //按DetNo排列之后的采集项
  401. ScanData = new ArrayList<ArrayList<string>>();
  402. //每个采集项目的子项
  403. GetData = new ArrayList<string>();
  404. //用于保存采集策略的具体信息
  405. SiItem = new Dictionary<string, Dictionary<string, string>>();
  406. for (int i = 0; i < Si_ItemDGV.RowCount; i++)
  407. {
  408. //如果不包含这个则添加进数组
  409. if (!GetData.Contains(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString()))
  410. GetData.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString());
  411. //如果和后一个的采集次序相同
  412. if (((i + 1) < Si_ItemDGV.RowCount) && Si_ItemDGV.Rows[i].Cells["si_detno"].Value.ToString() == Si_ItemDGV.Rows[i + 1].Cells["si_detno"].Value.ToString())
  413. GetData.Add(Si_ItemDGV.Rows[i + 1].Cells["si_item"].Value.ToString());
  414. else
  415. {
  416. ScanData.Add(GetData);
  417. //添加完一次数据需要一个新的List
  418. GetData = new ArrayList<string>();
  419. }
  420. Dictionary<string, string> item = new Dictionary<string, string>();
  421. for (int j = 0; j < Si_ItemDGV.ColumnCount; j++)
  422. {
  423. item.Add(Si_ItemDGV.Columns[j].DataPropertyName, Si_ItemDGV.Rows[i].Cells[j].Value.ToString());
  424. }
  425. SiItem.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString().ToUpper(), item);
  426. }
  427. //采集项目的数组
  428. ItemData = (ScanData.ToArray()[CurrentItemIndex] as ArrayList<string>).ToArray();
  429. //分隔符不为空的时候 //采集的项和Grid的数目不等
  430. //用户采集的数据的分割数组
  431. CollectData = new Dictionary<string, string>();
  432. if (sg_separator.Text == "")
  433. {
  434. for (int i = 0; i < ItemData.Length; i++)
  435. CollectData.Add(ItemData[i].ToString().ToUpper(), Input.Text);
  436. }
  437. else
  438. {
  439. int DataCount = Input.Text.Split(sg_separator.Text.ToCharArray()).Length;
  440. if (DataCount > ItemData.Length)
  441. {
  442. MessageBox.Show("采集数据大于采集项次");
  443. return;
  444. }
  445. else if (DataCount < ItemData.Length)
  446. {
  447. MessageBox.Show("采集数据小于采集项次");
  448. return;
  449. }
  450. for (int i = 0; i < DataCount; i++)
  451. CollectData.Add(ItemData[i].ToString().ToUpper(), Input.Text.Split(sg_separator.Text.ToCharArray())[i]);
  452. }
  453. //首先判断当前采集的个数,如果采集的个数为1则不对数据进行分隔符验证
  454. if (ItemData.Length > 0)
  455. {
  456. //CollectData.Clear();
  457. //for (int i = 0; i < ItemData.Length; i++)
  458. //{
  459. // CollectData.Add(ItemData[i].ToString().ToUpper(), Input.Text);
  460. //}
  461. //勾选了自动匹配调用该函数
  462. if (AutoMatch.Checked)
  463. SetAutoMatchRow();
  464. //将筛选之后的值赋给Cell
  465. SetDataToCell(ref CollectData);
  466. }
  467. else
  468. {
  469. MessageBox.Show("所采集的数据个数和采集项目不符");
  470. return;
  471. }
  472. //采集项目的索引+1
  473. CurrentItemIndex = CurrentItemIndex + 1;
  474. //如果已经采集完了最后一个
  475. if (CurrentItemIndex == ScanData.ToArray().Length)
  476. {
  477. //数据校验均已通过则勾选上已采集
  478. if (CollectVeProdCodePass && CollectQTYPass)
  479. {
  480. //如果按盒号采集,所有的此盒的均更新为
  481. DataTable dt = (DataTable)LabelInf.DataSource;
  482. StringBuilder pibid1 = new StringBuilder();
  483. string year = "0";
  484. string month = "0";
  485. string day = "0";
  486. string date = "";
  487. string lotno = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString();
  488. string datecode = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString();
  489. string pr_brand = LabelInf.Rows[CurrentRowIndex].Cells["pib_brand"].Value.ToString();
  490. LogicHandler.GetTimeFromDatecode(datecode, pr_brand, out year, out month, out day, out date);
  491. if (CollectionUnit.Text == "盒")
  492. {
  493. for (int i = 0; i < LabelInf.RowCount; i++)
  494. {
  495. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  496. {
  497. string pibid = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  498. dt.Rows[i]["pib_lotno"] = lotno;
  499. dt.Rows[i]["pib_datecode"] = datecode;
  500. dt.Rows[i]["pib_year"] = year;
  501. dt.Rows[i]["pib_month"] = month;
  502. dt.Rows[i]["pib_day"] = day;
  503. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  504. LabelInf.Rows[i].Cells["Choose"].Value = true;
  505. pibid1.Append(pibid + ",");
  506. LabelInf.Invalidate();
  507. //当前行的索引随循环增长
  508. CurrentRowIndex = i;
  509. if (SingleLabelAutoPrint.Checked)
  510. {
  511. AutoPrintSingleLabel(pibid);
  512. }
  513. if (MidLabelAutoPrint.Checked)
  514. AutoPrintMidLabel();
  515. SetOutBoxCode2(true);
  516. }
  517. }
  518. pibid1.Append("1");
  519. sdh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (" + pibid1 + ")", "update");
  520. }
  521. else if (CollectionUnit.Text == "全部")
  522. {
  523. for (int i = 0; i < LabelInf.RowCount; i++)
  524. {
  525. string pibid = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  526. dt.Rows[i]["pib_lotno"] = lotno;
  527. dt.Rows[i]["pib_datecode"] = datecode;
  528. dt.Rows[i]["pib_year"] = year;
  529. dt.Rows[i]["pib_month"] = month;
  530. dt.Rows[i]["pib_day"] = day;
  531. CurrentRowIndex = i;
  532. LabelInf.Refresh();
  533. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  534. LabelInf.Rows[i].Cells["Choose"].Value = true;
  535. pibid1.Append(pibid + ",");
  536. LabelInf.Invalidate();
  537. SetOutBoxCode2(true);
  538. }
  539. pibid1.Append("1");
  540. sdh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (" + pibid1 + ")", "update");
  541. }
  542. else
  543. {
  544. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
  545. LabelInf.Rows[CurrentRowIndex].Cells["Choose"].Value = true;
  546. LabelInf.Rows[CurrentRowIndex].Cells["pib_year"].Value = year;
  547. LabelInf.Rows[CurrentRowIndex].Cells["pib_month"].Value = month;
  548. LabelInf.Rows[CurrentRowIndex].Cells["pib_day"].Value = day;
  549. sdh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (" + pibid1 + ")", "update");
  550. LabelInf.Invalidate();
  551. //勾选了单盘自动打印
  552. if (SingleLabelAutoPrint.Checked)
  553. {
  554. if (SingleLabelCombox.SelectedValue != null)
  555. {
  556. AutoPrintSingleLabel(LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString());
  557. }
  558. else
  559. {
  560. MessageBox.Show("未维护单盘标签");
  561. return;
  562. }
  563. }
  564. //勾选了中盒自动打印
  565. if (MidLabelAutoPrint.Checked)
  566. AutoPrintMidLabel();
  567. }
  568. }
  569. //采集未通过的时候
  570. else
  571. {
  572. //如果自动采集采集未成功需要移动到下一行
  573. if (!AutoMatch.Checked)
  574. SetRowIndexToCollectRow();
  575. }
  576. //当前项目已采集完成,重置采集项目
  577. CurrentItemIndex = 0;
  578. //未勾选自动匹配,设置到下一个未采集的行
  579. if (!AutoMatch.Checked)
  580. SetRowIndexToCollectRow();
  581. }
  582. //提醒用户需要采集的数据
  583. RemindUser();
  584. RefreshProcessData();
  585. MessageLog.AppendText(">>扫描到数据" + Input.Text + "\n", Color.Blue);
  586. //如果所采集的行的物料不一样的话,重新计算箱内容量
  587. if (CurrentRowIndex - 1 > 0)
  588. {
  589. string LastRowProd = LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_prodcode"].Value.ToString();
  590. string CurrentRowProd = LabelInf.Rows[CurrentRowIndex].Cells["pib_prodcode"].Value.ToString();
  591. //如果两行的物料资料不相等的话
  592. if (LastRowProd != CurrentRowProd)
  593. SetOutBoxCapacity(CurrentRowProd);
  594. }
  595. if (CleanInputAfterCollect.Checked)
  596. Input.Text = "";
  597. }
  598. /// <summary>
  599. /// 根据物料资料的参数设置外箱容量
  600. /// </summary>
  601. /// <param name="pr_code"></param>
  602. private void SetOutBoxCapacity(string pr_code)
  603. {
  604. DataTable temp = (DataTable)dh.ExecuteSql("select pr_qtyperplace,pr_zxbzs from product where pr_code='" + pr_code + "'", "select");
  605. if (temp.Rows.Count > 0)
  606. {
  607. //try { OutboxCapacity.Value = (decimal)temp.Rows[0]["pr_qtyperplace"] / (decimal)temp.Rows[0]["pr_zxbzs"]; }
  608. //catch (Exception) { }
  609. }
  610. }
  611. //设置行的索引到当前需要采集的行
  612. private void SetRowIndexToCollectRow()
  613. {
  614. //获取当前需要采集的行
  615. for (int i = CurrentRowIndex; i < LabelInf.RowCount; i++)
  616. {
  617. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  618. {
  619. griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
  620. pr_code.Text = LabelInf.Rows[i].Cells["pib_prodcode"].FormattedValue.ToString();
  621. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
  622. break;
  623. }
  624. }
  625. }
  626. private void AutoPrintSingleLabel(string pib_id)
  627. {
  628. if (PrintMethod == "CodeSoft")
  629. Print.CodeSoft.SinglePrint(SingleDoc, SingleLabelParam, pib_id);
  630. else
  631. Print.BarTender.SinglePrint(SingleFormat, SingleLabelParam, pib_id);
  632. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifprint"].Value = true;
  633. sdh.ExecuteSql("update prodiobarcode set pib_ifprint=-1 where pib_id='" + pib_id + "'", "update");
  634. }
  635. /// <summary>
  636. /// 提醒用户当前采集的项目
  637. /// </summary>
  638. private void RemindUser()
  639. {
  640. SetRowIndexToCollectRow();
  641. if (ScanData.ToArray().Length > 0)
  642. {
  643. object[] arr = (ScanData.ToArray()[CurrentItemIndex] as ArrayList<string>).ToArray();
  644. string Inf = "";
  645. for (int i = 0; i < arr.Length; i++)
  646. {
  647. Inf += arr[i] + " ";
  648. }
  649. MessageLog.AppendText(">>当前采集行" + (CurrentRowIndex + 1) + ",请采集" + Inf + "\n", Color.Green);
  650. }
  651. }
  652. /// <summary>
  653. /// 自定义函数 将匹配之后的值设置到Cell中,传递引用,每次赋值之后从List中移除已使用过的
  654. /// </summary>
  655. /// <param name="data"></param>
  656. /// <param name="kind"></param>
  657. private void SetDataToCell(ref Dictionary<string, string> setdata)
  658. {
  659. int length = setdata.Count;
  660. string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
  661. string LotNo = "";
  662. string DateCode = "";
  663. foreach (var item in setdata)
  664. {
  665. string[] data = new string[setdata.Count];
  666. for (int i = 0; i < length; i++)
  667. {
  668. data[i] = setdata[item.Key];
  669. }
  670. DataGridViewCell cell = null;
  671. string Matchstr = "";
  672. switch (item.Key)
  673. {
  674. case "DATECODE":
  675. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"];
  676. Matchstr = MatchStr(item.Value, "DATECODE");
  677. DateCode = Matchstr;
  678. length--;
  679. break;
  680. case "LOTNO":
  681. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"];
  682. Matchstr = MatchStr(item.Value, "LOTNO");
  683. LotNo = Matchstr;
  684. length--;
  685. break;
  686. case "MPN":
  687. cell = LabelInf.Rows[CurrentRowIndex].Cells["pr_vendprodcode"];
  688. Matchstr = MatchStr(item.Value, "MPN");
  689. //采集的供应商号不匹配的话
  690. if (cell.Value.ToString() != Matchstr)
  691. {
  692. CollectVeProdCodePass = false;
  693. //添加需要重绘的Cell
  694. LabelInf.Refresh();
  695. MessageLog.AppendText(">>供应商物料编号不匹配\n", Color.Red);
  696. }
  697. else
  698. {
  699. LabelInf.Refresh();
  700. CollectVeProdCodePass = true;
  701. }
  702. length--;
  703. break;
  704. case "QTY":
  705. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_qty"];
  706. Matchstr = MatchStr(item.Value, "QTY");
  707. //如果采集的数量不相等的话
  708. if (cell.Value.ToString() != Matchstr)
  709. {
  710. CollectQTYPass = false;
  711. LabelInf.Refresh();
  712. MessageLog.AppendText(">>数量不匹配\n", Color.Red);
  713. }
  714. else
  715. {
  716. LabelInf.Refresh();
  717. CollectQTYPass = true;
  718. }
  719. length--;
  720. break;
  721. case "品牌":
  722. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_brand"];
  723. Matchstr = MatchStr(item.Value, "品牌");
  724. //如果采集的数量不相等的话
  725. if (cell.Value.ToString() != Matchstr)
  726. {
  727. CollectQTYPass = false;
  728. LabelInf.Refresh();
  729. MessageLog.AppendText(">>品牌不匹配\n", Color.Red);
  730. }
  731. else
  732. {
  733. LabelInf.Refresh();
  734. CollectQTYPass = true;
  735. }
  736. length--;
  737. break;
  738. default:
  739. break;
  740. }
  741. //如果数据为空或者数据不为空的时候但是和需要采集的数据不相等的情况下进行采集
  742. //MPN和QTY只做比较不需要赋值
  743. if (cell.Value.ToString() == "" || cell.Value.ToString() != Matchstr)
  744. {
  745. string MatchResult = "";
  746. if (item.Key != "MPN" && item.Key != "QTY" && item.Key != "品牌")
  747. {
  748. DataTable dt = (DataTable)LabelInf.DataSource;
  749. cell.Value = Matchstr;
  750. MatchResult = "成功";
  751. }
  752. else
  753. MatchResult = "失败";
  754. switch (SiItem[item.Key]["si_kind"])
  755. {
  756. case "索引字符":
  757. LogManager.DoLog("采集项" + item.Key + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[item.Key]["si_kind"] + ",使用字符" + SiItem[item.Key]["si_indexstring"] + ",匹配后字符串" + Matchstr);
  758. break;
  759. case "起始位置":
  760. LogManager.DoLog("采集项" + item.Key + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[item.Key]["si_kind"] + ",从第" + SiItem[item.Key]["si_index"] + "位开始匹配,匹配后字符串" + Matchstr);
  761. break;
  762. case "二次解析":
  763. LogManager.DoLog("采集项" + item.Key + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[item.Key]["si_kind"] + ",匹配后字符串" + Matchstr);
  764. break;
  765. case "全部":
  766. LogManager.DoLog("采集项" + item.Key + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[item.Key]["si_kind"] + ",匹配后字符串" + Matchstr);
  767. break;
  768. default:
  769. break;
  770. }
  771. }
  772. else
  773. LogManager.DoLog("采集项" + item.Key + ",匹配结果:【成功】,匹配方式:" + SiItem[item.Key]["si_kind"] + ",,匹配后字符串" + Matchstr);
  774. }
  775. sql.Clear();
  776. sql.Append("update prodiobarcode set pib_ifpick=-1");
  777. if (LotNo != "")
  778. {
  779. sql.Append(",pib_lotno='" + LotNo + "'");
  780. }
  781. if (DateCode != "")
  782. {
  783. string year = "";
  784. string month = "";
  785. string day = "";
  786. string date = "";
  787. string pr_brand = LabelInf.Rows[CurrentRowIndex].Cells["pib_brand"].Value.ToString();
  788. LogicHandler.GetTimeFromDatecode(DateCode, pr_brand, out year, out month, out day, out date);
  789. sql.Append(",pib_datecode='" + DateCode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' ");
  790. }
  791. sql.Append("where pib_id='" + pib_id + "'");
  792. sdh.ExecuteSql(sql.ToString(), "update");
  793. //添加外箱号,如果外箱号的箱内容量不为0并且已经采集完成
  794. SetOutBoxCode2(false);
  795. }
  796. //
  797. /// <summary>
  798. /// 设置外箱号
  799. /// </summary>
  800. /// <param name="BatchCollect">是否批量采集</param>
  801. private void SetOutBoxCode2(bool BatchCollect)
  802. {
  803. if (OutboxCapacity.Value != 0)
  804. {
  805. //获取当前出入口单最大的外箱号
  806. for (int i = 0; i < LabelInf.RowCount; i++)
  807. {
  808. string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  809. if (outboxcode.Contains("-"))
  810. {
  811. if (int.Parse(outboxcode.Split('-')[0] == "" ? "1" : outboxcode.Split('-')[0]) > MaxOutBoxCode)
  812. MaxOutBoxCode = int.Parse(outboxcode.Split('-')[0]);
  813. }
  814. else
  815. {
  816. if (int.Parse(outboxcode == "" ? "0" : outboxcode) > MaxOutBoxCode)
  817. MaxOutBoxCode = int.Parse(outboxcode);
  818. }
  819. }
  820. //统计最大的箱号存在多少
  821. int MaxOutBoxCodeCount = 0;
  822. for (int i = 0; i < LabelInf.RowCount; i++)
  823. {
  824. if (LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString() == MaxOutBoxCode.ToString())
  825. MaxOutBoxCodeCount = MaxOutBoxCodeCount + 1;
  826. }
  827. //如果是获取过包装单的话则不再继续追加箱号
  828. if (!GetPackingCode)
  829. {
  830. //如果箱内的盒数量小于容量,继续使用此箱号赋值,否则箱号+1
  831. if (BatchCollect)
  832. {
  833. if (MaxOutBoxCodeCount < OutboxCapacity.Value)
  834. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  835. else
  836. {
  837. MaxOutBoxCode = MaxOutBoxCode + 1;
  838. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  839. }
  840. }
  841. else
  842. {
  843. if (MaxOutBoxCodeCount <= OutboxCapacity.Value)
  844. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  845. else
  846. {
  847. MaxOutBoxCode = MaxOutBoxCode + 1;
  848. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  849. }
  850. }
  851. }
  852. }
  853. }
  854. /// <summary>
  855. /// 自定义函数 根据匹配规则
  856. /// si_item的二维数组,str是需要赋值的字符串,item表示DateCode,LotNo等
  857. /// </summary>
  858. /// <param name="SiItem"></param>
  859. /// <param name="str"></param>
  860. /// <param name="item"></param>
  861. /// <returns></returns>
  862. private string MatchStr(string str, string item)
  863. {
  864. string kind = SiItem[item]["si_kind"];
  865. //起始字符不为空的时候
  866. switch (kind)
  867. {
  868. case "起始位置":
  869. if (SiItem[item]["si_index"] != "")
  870. {
  871. try
  872. {
  873. //长度不为空的时候按照指定的长度去取数据
  874. if (SiItem[item]["si_length"] != "")
  875. str = str.Substring(int.Parse(SiItem[item]["si_index"]), int.Parse(SiItem[item]["si_length"]));
  876. //长度为空的时候取index之后的全部数据
  877. else
  878. str = str.Substring(int.Parse(SiItem[item]["si_index"]));
  879. }
  880. catch (Exception e) { LogManager.DoLog(e.StackTrace); }
  881. }
  882. break;
  883. case "索引字符":
  884. try
  885. {
  886. if (SiItem[item]["si_indexstring"] != "")
  887. {
  888. //长度不为空的时候按照指定的长度去取数据
  889. if (SiItem[item]["si_length"] != "")
  890. str = str.Substring(str.IndexOf(SiItem[item]["si_indexstring"]) + 1, int.Parse(SiItem[item]["si_length"]));
  891. //长度为空的时候取index之后的全部数据
  892. else
  893. str = str.Substring(str.IndexOf(SiItem[item]["si_indexstring"]) + 1);
  894. }
  895. }
  896. catch (Exception e) { LogManager.DoLog(e.StackTrace); }
  897. break;
  898. case "全部":
  899. break;
  900. default:
  901. break;
  902. }
  903. if (SiItem[item]["si_expression"] != "")
  904. {
  905. string log = "使用正则表达式" + SiItem[item]["si_expression"] + "匹配数据" + str;
  906. reg = new Regex(SiItem[item]["si_expression"]);
  907. try
  908. {
  909. str = reg.Matches(str)[int.Parse(SiItem[item]["si_expressionitem"].ToString()) - 1].Value;
  910. }
  911. catch (Exception)
  912. {
  913. }
  914. log += ",匹配后数据" + str;
  915. LogManager.DoLog(log);
  916. }
  917. return str;
  918. }
  919. //关闭窗口前提示用户确认
  920. private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
  921. {
  922. //如果不是注销的话
  923. if (!logout)
  924. {
  925. string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  926. if (close.ToString() != "Yes")
  927. e.Cancel = true;
  928. else
  929. {
  930. if (lbl != null)
  931. lbl.Quit();
  932. if (engine != null)
  933. engine.Dispose();
  934. LogManager.DoLog("关闭程序");
  935. }
  936. }
  937. }
  938. /// <summary>
  939. /// 获取打印标签
  940. /// </summary>
  941. private void GetInOutInfAndLabelFile()
  942. {
  943. ComBoxClickChangeLabelDoc = false;
  944. Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LabelAttachPARAMETER where lap_custcode='" + cu_code.Text + "'", "select");
  945. sql.Clear();
  946. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') ");
  947. sql.Append(" la_id,cl_custcode from customerlabel left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where (cl_custcode='" + cu_code.Text + "' ");
  948. sql.Append(" or cl_custcode is null) and cl_labeltype='单盘' order by cl_custcode");
  949. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  950. SingleLabelCombox.DisplayMember = "cl_labelname";
  951. SingleLabelCombox.ValueMember = "la_id";
  952. SingleLabelCombox.DataSource = dt;
  953. if (SingleDoc != null)
  954. SingleDoc.Close();
  955. if (!GetGridOnly.Checked)
  956. for (int i = 0; i < dt.Rows.Count; i++)
  957. {
  958. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  959. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  960. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  961. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  962. if (time.ToString() != file.LastWriteTime.ToString())
  963. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  964. }
  965. if (SingleLabelCombox.Text != "")
  966. {
  967. if (PrintMethod == "CodeSoft")
  968. {
  969. SingleDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + SingleLabelCombox.Text);
  970. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  971. }
  972. else
  973. {
  974. if (SingleFormat != null)
  975. {
  976. SingleFormat.Close(SaveOptions.DoNotSaveChanges);
  977. }
  978. SingleFormat = engine.Documents.Open(ftpOperater.DownLoadTo + SingleLabelCombox.Text);
  979. SingleFormat.PrintSetup.PrinterName = SingleLabelPrinter.Text;
  980. }
  981. SingleLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + SingleLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
  982. }
  983. sql.Clear();
  984. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') ");
  985. sql.Append(" la_id,cl_custcode from customerlabel left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where (cl_custcode='" + cu_code.Text + "' ");
  986. sql.Append(" or cl_custcode is null) and cl_labeltype='中盒' order by cl_custcode");
  987. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  988. MidLabelCombox.DisplayMember = "cl_labelname";
  989. MidLabelCombox.ValueMember = "la_id";
  990. MidLabelCombox.DataSource = dt;
  991. if (MidDoc != null)
  992. MidDoc.Close();
  993. if (!GetGridOnly.Checked)
  994. for (int i = 0; i < dt.Rows.Count; i++)
  995. {
  996. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  997. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  998. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  999. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  1000. if (time.ToString() != file.LastWriteTime.ToString())
  1001. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  1002. }
  1003. if (MidLabelCombox.Text != "")
  1004. {
  1005. if (PrintMethod == "CodeSoft")
  1006. {
  1007. MidDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + MidLabelCombox.Text);
  1008. MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
  1009. }
  1010. else
  1011. {
  1012. if (MidFormat != null)
  1013. {
  1014. MidFormat.Close(SaveOptions.DoNotSaveChanges);
  1015. }
  1016. MidFormat = engine.Documents.Open(ftpOperater.DownLoadTo + MidLabelCombox.Text);
  1017. MidFormat.PrintSetup.PrinterName = MidLabelPrinter.Text;
  1018. }
  1019. MidLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + MidLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
  1020. }
  1021. //缓存中盒参数
  1022. sql.Clear();
  1023. sql.Append("select to_char(nvl(cl_date,sysdate),'YYYY-MM-DD HH24:Mi:SS') cl_date,cl_labelname,cl_isdefault,la_id||'#'||cl_labelurl||'#'||to_char(cl_date,'YYYY-MM-DD HH24:Mi:SS') ");
  1024. sql.Append(" la_id,cl_custcode from customerlabel left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where (cl_custcode='" + cu_code.Text + "' ");
  1025. sql.Append(" or cl_custcode is null) and cl_labeltype='外箱' order by cl_custcode");
  1026. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1027. OutBoxCombox.DisplayMember = "cl_labelname";
  1028. OutBoxCombox.ValueMember = "la_id";
  1029. OutBoxCombox.DataSource = dt;
  1030. if (OutBoxDoc != null)
  1031. OutBoxDoc.Close();
  1032. if (!GetGridOnly.Checked)
  1033. for (int i = 0; i < dt.Rows.Count; i++)
  1034. {
  1035. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  1036. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  1037. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  1038. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  1039. if (time.ToString() != file.LastWriteTime.ToString())
  1040. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  1041. }
  1042. if (OutBoxCombox.Text != "")
  1043. {
  1044. if (PrintMethod == "CodeSoft")
  1045. {
  1046. OutBoxDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + OutBoxCombox.Text);
  1047. OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
  1048. }
  1049. else
  1050. {
  1051. if (OutFormat != null)
  1052. {
  1053. OutFormat.Close(SaveOptions.DoNotSaveChanges);
  1054. }
  1055. OutFormat = engine.Documents.Open(ftpOperater.DownLoadTo + OutBoxCombox.Text);
  1056. OutFormat.PrintSetup.PrinterName = OutBoxPrinter.Text;
  1057. }
  1058. OutLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql,lp_valuetype from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + OutBoxCombox.SelectedValue.ToString().Split('#')[0], "select");
  1059. }
  1060. //缓存外箱参数
  1061. ComBoxClickChangeLabelDoc = true;
  1062. }
  1063. bool InitGetLabel = true;
  1064. /// <summary>
  1065. /// 出入库单录入框的回车事件
  1066. /// </summary>
  1067. /// <param name="sender"></param>
  1068. /// <param name="e"></param>
  1069. private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
  1070. {
  1071. if (e.KeyCode == Keys.Enter)
  1072. {
  1073. sql.Clear();
  1074. sql.Append("select pi_id,pi_cardcode,pi_class,to_char(pi_date,'yyyymmdd')pi_date from prodinout where pi_inoutno='" + pi_inoutno.Text + "'");
  1075. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1076. if (dt.Rows.Count > 0)
  1077. {
  1078. InitGetLabel = true;
  1079. cu_code.Text = dt.Rows[0]["pi_cardcode"].ToString();
  1080. InitGetLabel = false;
  1081. pi_date.Text = dt.Rows[0]["pi_date"].ToString();
  1082. pi_class.Text = dt.Rows[0]["pi_class"].ToString();
  1083. PI_ID = dt.Rows[0]["pi_id"].ToString();
  1084. if (dh.GetConfig("AutoBarcode", "ProdInOut!Sale").ToString() != "")
  1085. {
  1086. string[] param = new string[] { PI_ID, "" };
  1087. dh.CallProcedure("GetCustBarcode", ref param);
  1088. }
  1089. CurrentItemIndex = 0;
  1090. CurrentRowIndex = 0;
  1091. LoadGridData(sender, e);
  1092. //重新输入单号后清除缓存
  1093. MidBoxArgument.Clear();
  1094. SingleBoxArgument.Clear();
  1095. MidIDAndOutboxcode.Clear();
  1096. SingleID.Clear();
  1097. //刷新采集进度
  1098. RefreshProcessData();
  1099. //设置当前的最大箱号
  1100. for (int i = 0; i < LabelInf.RowCount; i++)
  1101. {
  1102. string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  1103. //如果包含有-,则需要解析
  1104. if (outboxcode.Contains("-"))
  1105. if (int.Parse(outboxcode.Split('-')[0] == "" ? "1" : outboxcode.Split('-')[0]) > MaxOutBoxCode)
  1106. MaxOutBoxCode = int.Parse(outboxcode.Split('-')[0]);
  1107. //else
  1108. //if (int.Parse(outboxcode == "" ? "1" : outboxcode) > MaxOutBoxCode)
  1109. // MaxOutBoxCode = int.Parse(outboxcode);
  1110. }
  1111. thread = new Thread(GetInOutInfAndLabelFile);
  1112. stw = new SetLoadingWindow(thread, "正在获取打印标签");
  1113. BaseUtil.SetFormCenter(stw);
  1114. stw.ShowDialog();
  1115. //重置采集项次
  1116. LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
  1117. }
  1118. else
  1119. MessageBox.Show("当前出入库单号不存在!");
  1120. }
  1121. }
  1122. private void SingleBoxPrint()
  1123. {
  1124. if (SingleLabelParam.Rows.Count > 0 && LabelInf.Rows.Count > 0)
  1125. {
  1126. //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
  1127. MidIDAndOutboxcode.Clear();
  1128. SingleID.Clear();
  1129. //获取全部的中盒号
  1130. Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
  1131. //判断所有盒号为该盒的是否勾选已采集
  1132. outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
  1133. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1134. {
  1135. if (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()))
  1136. SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1137. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() != "True")
  1138. {
  1139. //如果不存在中盒号则进行添加
  1140. if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))
  1141. {
  1142. MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
  1143. }
  1144. }
  1145. }
  1146. if (SingleID.ToArray().Length == 0)
  1147. {
  1148. MessageBox.Show("选择的行未勾选采集或者已打印");
  1149. return;
  1150. }
  1151. for (int i = 0; i < LabelInf.RowCount; i++)
  1152. {
  1153. if (i + 1 < LabelInf.RowCount)
  1154. {
  1155. //如果本行的中盒号和下一行不相等的话
  1156. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString())
  1157. {
  1158. if (!outboxcode1.ContainsKey(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  1159. outboxcode1.Add(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString(), true);
  1160. }
  1161. }
  1162. //只要有一行没有采集满就不打印
  1163. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  1164. {
  1165. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1166. outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()] = false;
  1167. }
  1168. }
  1169. //用于判断用户是否勾选了行
  1170. int CheckedRowCount = 0;
  1171. string[] arg = SingleBoxArgument.ToArray();
  1172. for (int i = 0; i < LabelInf.RowCount; i++)
  1173. {
  1174. //勾选了并且未打印
  1175. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() != "True")
  1176. {
  1177. CheckedRowCount = CheckedRowCount + 1;
  1178. CurrentRowIndex = i;
  1179. //以标签模板的参数为基准,循环取数
  1180. try
  1181. {
  1182. string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  1183. AutoPrintSingleLabel(pib_id);
  1184. if (MidLabelAutoPrint.Checked)
  1185. {
  1186. //判断当前行的盒号和下一行不相等或者已经是最后一行了
  1187. if (i + 1 == LabelInf.RowCount || LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1 == LabelInf.RowCount ? i : i + 1].Cells["pib_outboxcode1"].Value.ToString())
  1188. {
  1189. if (outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()])
  1190. {
  1191. if (MidLabelCombox.SelectedValue != null)
  1192. {
  1193. MidBoxCodePrint(CurrentRowIndex);
  1194. }
  1195. }
  1196. }
  1197. }
  1198. //勾选为已打印
  1199. LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
  1200. sdh.ExecuteSql("update prodiobarcode set pib_ifprint=-1 where pib_id='" + pib_id + "'", "update");
  1201. }
  1202. catch (Exception ex) { LogManager.DoLog(ex.Message); }
  1203. }
  1204. }
  1205. dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray());
  1206. if (CheckedRowCount == 0)
  1207. MessageBox.Show("未勾选打印明细!");
  1208. else if (CurrentRowIndex + 1 < LabelInf.Rows.Count)
  1209. CurrentRowIndex = CurrentRowIndex + 1;
  1210. outboxcode1.Clear();
  1211. }
  1212. else
  1213. {
  1214. MessageBox.Show("此模板尚未维护参数或不存在打印明细");
  1215. return;
  1216. }
  1217. }
  1218. private void SingleLabelPrint_Click(object sender, EventArgs e)
  1219. {
  1220. if (SingleLabelCombox.Text != "")
  1221. {
  1222. if (SingleBoxBegin.Text != "" || SingleBoxEnd.Text != "")
  1223. {
  1224. try
  1225. {
  1226. int begin = int.Parse(SingleBoxBegin.Text == "" ? "1" : SingleBoxBegin.Text);
  1227. int end = int.Parse(SingleBoxEnd.Text == "" ? LabelInf.Rows.Count.ToString() : SingleBoxEnd.Text);
  1228. if (begin > 0 && end <= LabelInf.Rows.Count && begin <= end)
  1229. {
  1230. for (int i = begin - 1; i < end; i++)
  1231. {
  1232. LabelInf.Rows[i].Cells["Choose"].Value = true;
  1233. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  1234. LabelInf.Rows[i].Cells["pib_ifprint"].Value = false;
  1235. }
  1236. }
  1237. else
  1238. {
  1239. MessageBox.Show("单盘打印范围错误");
  1240. return;
  1241. }
  1242. LabelInf.Invalidate();
  1243. }
  1244. catch (Exception)
  1245. {
  1246. MessageBox.Show("单盘打印范围错误");
  1247. return;
  1248. }
  1249. }
  1250. thread = new Thread(SingleBoxPrint);
  1251. stw = new SetLoadingWindow(thread, "正在打印单盘");
  1252. BaseUtil.SetFormCenter(stw);
  1253. stw.ShowDialog();
  1254. }
  1255. else
  1256. MessageBox.Show("未维护单盘标签");
  1257. }
  1258. private void MidBoxLabelPrint()
  1259. {
  1260. //未输入内容打印全部中盒
  1261. if (MidLabelNum.Text == "")
  1262. {
  1263. int begin = 0;
  1264. int end = 0;
  1265. if (MidBoxBegin.Text != "" || MidBoxEnd.Text != "")
  1266. {
  1267. try
  1268. {
  1269. begin = int.Parse(MidBoxBegin.Text == "" ? "1" : MidBoxBegin.Text);
  1270. end = int.Parse(MidBoxEnd.Text == "" ? LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString() : MidBoxEnd.Text);
  1271. int minmidbox = int.Parse(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString());
  1272. int maxmidbox = int.Parse(LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString());
  1273. if (begin >= minmidbox && end <= maxmidbox && begin <= end)
  1274. {
  1275. //设置中盒打印范围的行号
  1276. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1277. {
  1278. string outboxcode1 = LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString();
  1279. if (outboxcode1 != "")
  1280. {
  1281. if (int.Parse(outboxcode1) == begin)
  1282. {
  1283. begin = i;
  1284. }
  1285. if (int.Parse(outboxcode1) == end)
  1286. {
  1287. end = i;
  1288. }
  1289. }
  1290. }
  1291. }
  1292. else
  1293. {
  1294. MessageBox.Show("中盒打印范围错误");
  1295. return;
  1296. }
  1297. }
  1298. catch (Exception)
  1299. {
  1300. MessageBox.Show("中盒打印范围错误");
  1301. return;
  1302. }
  1303. }
  1304. else
  1305. {
  1306. end = LabelInf.Rows.Count - 1;
  1307. }
  1308. MidBoxArgument.Clear();
  1309. List<int> MidOutBoxCode = new List<int>();
  1310. List<int> MidOutBoxCodeIndex = new List<int>();
  1311. for (int i = (begin == 0 ? 0 : begin); i <= (end - begin); i++)
  1312. {
  1313. string outboxcode1 = LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString();
  1314. if (outboxcode1 != "")
  1315. {
  1316. if (!MidIDAndOutboxcode.ContainsValue(outboxcode1))
  1317. MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), outboxcode1);
  1318. if (!MidOutBoxCode.Contains(int.Parse(outboxcode1)))
  1319. {
  1320. MidOutBoxCode.Add(int.Parse(outboxcode1));
  1321. MidOutBoxCodeIndex.Add(i);
  1322. }
  1323. }
  1324. }
  1325. for (int i = 0; i < MidOutBoxCodeIndex.Count; i++)
  1326. {
  1327. MidBoxCodePrint(MidOutBoxCodeIndex[i]);
  1328. }
  1329. MidBoxArgument.Clear();
  1330. return;
  1331. }
  1332. bool FindMidLabel = false;
  1333. if (MidLabelCombox.SelectedValue != null)
  1334. {
  1335. //中盒号所在的行
  1336. int MidLabelRowIndex = 0;
  1337. //查找是否存在该中盒号
  1338. List<int> MidRowIndex = new List<int>();
  1339. //缓存中盒数据
  1340. for (int i = 0; i < LabelInf.RowCount; i++)
  1341. {
  1342. if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1343. {
  1344. //找到了输入的中盒号停止循环
  1345. FindMidLabel = true;
  1346. MidLabelRowIndex = i;
  1347. MidRowIndex.Add(i);
  1348. }
  1349. }
  1350. //找到了指定的盒号
  1351. if (FindMidLabel)
  1352. MidBoxCodePrint(MidLabelRowIndex);
  1353. else
  1354. MessageBox.Show("该出入库单未找到该中盒号!");
  1355. }
  1356. else
  1357. MessageBox.Show("未维护中盒模板");
  1358. }
  1359. private void MidLabelPrint_Click(object sender, EventArgs e)
  1360. {
  1361. if (MidLabelCombox.Text != "")
  1362. {
  1363. thread = new Thread(MidBoxLabelPrint);
  1364. stw = new SetLoadingWindow(thread, "正在打印中盒");
  1365. BaseUtil.SetFormCenter(stw);
  1366. stw.ShowDialog();
  1367. }
  1368. else
  1369. MessageBox.Show("未维护中盒标签");
  1370. }
  1371. private void OutBoxPrint()
  1372. {
  1373. List<string> Outboxcode = new List<string>();
  1374. //如果未勾选箱号则对勾选的数据的箱号进行整合
  1375. if (OutBoxNum.Text == "")
  1376. {
  1377. for (int i = 0; i < LabelInf.RowCount; i++)
  1378. {
  1379. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  1380. {
  1381. string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  1382. //富为使用包装单的逻辑
  1383. //如果不包含该箱号则进行添加
  1384. if (!Outboxcode.Contains(outboxcode2))
  1385. Outboxcode.Add(outboxcode2);
  1386. }
  1387. }
  1388. //按获取到的箱号列表进行打印
  1389. if (Outboxcode.ToArray().Length > 0)
  1390. {
  1391. try
  1392. {
  1393. // 循环打印外箱号
  1394. for (int i = 0; i < Outboxcode.ToArray().Length; i++)
  1395. {
  1396. for (int h = 0; h < LabelInf.RowCount; h++)
  1397. {
  1398. if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i])
  1399. {
  1400. OutBoxCodePrint(h);
  1401. break;
  1402. }
  1403. }
  1404. }
  1405. }
  1406. catch { }
  1407. }
  1408. else
  1409. {
  1410. MessageBox.Show("请勾选需要打印的外箱");
  1411. }
  1412. }
  1413. else
  1414. {
  1415. bool FindMidLabel = false;
  1416. try
  1417. {
  1418. int OutBoxLabelRowIndex = 0;
  1419. //查找是否存在该中盒号
  1420. for (int i = 0; i < LabelInf.RowCount; i++)
  1421. {
  1422. if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString())
  1423. {
  1424. //找到了输入的中盒号停止循环
  1425. FindMidLabel = true;
  1426. OutBoxLabelRowIndex = i;
  1427. break;
  1428. }
  1429. }
  1430. //找到了指定的盒号
  1431. if (FindMidLabel)
  1432. OutBoxCodePrint(OutBoxLabelRowIndex);
  1433. else
  1434. MessageBox.Show("该出入库单未找到该外箱号!");
  1435. }
  1436. catch (Exception) { }
  1437. }
  1438. Outboxcode.Clear();
  1439. }
  1440. private void MidBoxCodePrint(int rowindex)
  1441. {
  1442. //获取对应行的pib_id
  1443. string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
  1444. string pib_outboxcode1 = LabelInf.Rows[rowindex].Cells["pib_outboxcode1"].Value.ToString();
  1445. if (PrintMethod == "CodeSoft")
  1446. Print.CodeSoft.MidPrint(MidDoc, MidLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode1);
  1447. else
  1448. Print.BarTender.MidPrint(MidFormat, MidLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode1);
  1449. }
  1450. private void OutBoxCodePrint(int rowindex)
  1451. {
  1452. //获取对应行的pib_id
  1453. string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
  1454. string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
  1455. if (PrintMethod == "CodeSoft")
  1456. Print.CodeSoft.OutPrint(OutBoxDoc, OutLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode2, cu_print_outprod.Checked, cu_print_outpo.Checked, cu_print_ordercode.Checked, cu_print_outdc.Checked, cu_print_outlotno.Checked);
  1457. else
  1458. Print.BarTender.OutPrint(OutFormat, OutLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode2, cu_print_outprod.Checked, cu_print_outpo.Checked, cu_print_ordercode.Checked, cu_print_outdc.Checked, cu_print_outlotno.Checked);
  1459. }
  1460. private void CleanDetail_Click(object sender, EventArgs e)
  1461. {
  1462. ArrayList<string> DeleteID = new ArrayList<string>();
  1463. StringBuilder pibid = new StringBuilder();
  1464. for (int i = 0; i < LabelInf.RowCount; i++)
  1465. {
  1466. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  1467. {
  1468. DeleteID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1469. pibid.Append(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + ",");
  1470. }
  1471. }
  1472. //勾选了删除的明细之后
  1473. if (DeleteID.ToArray().Length > 0)
  1474. {
  1475. string close = MessageBox.Show(this.ParentForm, "删除后不可恢复,是否确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1476. if (close.ToString() == "Yes")
  1477. {
  1478. pibid.Append("1");
  1479. sdh.ExecuteSql("delete from prodiobarcode where pib_id in(" + pibid + ")", "delete");
  1480. dh.BatchInsert("delete from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray());
  1481. MessageBox.Show("删除成功");
  1482. LoadGridData(sender, e);
  1483. RefreshProcessData();
  1484. }
  1485. }
  1486. else
  1487. MessageBox.Show("尚未勾选需要删除的明细");
  1488. }
  1489. private void OutBoxLabelPrint_Click(object sender, EventArgs e)
  1490. {
  1491. if (OutBoxCombox.Text != "")
  1492. {
  1493. thread = new Thread(OutBoxPrint);
  1494. stw = new SetLoadingWindow(thread, "正在打印外箱");
  1495. BaseUtil.SetFormCenter(stw);
  1496. stw.ShowDialog();
  1497. }
  1498. else
  1499. MessageBox.Show("未维护外箱标签");
  1500. }
  1501. /// <summary>
  1502. /// 刷新采集进度
  1503. /// </summary>
  1504. private void RefreshProcessData()
  1505. {
  1506. if (LabelInf.Rows.Count > 0)
  1507. {
  1508. //设置初始化的采集进度
  1509. int Count = 0;
  1510. int CurrentMidBoxCollectedCount = 0;
  1511. //当前盒号的总盘数
  1512. int CurrentMidBoxTotalCount = 0;
  1513. //未超出当前范围的时候
  1514. for (int i = 0; i < LabelInf.RowCount; i++)
  1515. {
  1516. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
  1517. Count++;
  1518. //和当前编辑箱号相等行
  1519. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True" && LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1520. CurrentMidBoxCollectedCount++;
  1521. //当前盒号一共有几盘
  1522. if (LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1523. CurrentMidBoxTotalCount++;
  1524. }
  1525. Capacity.Text = "可装" + CurrentMidBoxTotalCount + "盘";
  1526. Installed.Text = "已装" + CurrentMidBoxCollectedCount + "盘";
  1527. //设置当前的箱号和盒号
  1528. Process_outboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value.ToString();
  1529. Process_midboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  1530. //设置当前总数和已采集数量
  1531. TotalCount.Text = LabelInf.RowCount.ToString();
  1532. CollectedCount.Text = Count.ToString();
  1533. }
  1534. }
  1535. private void LoadGridData()
  1536. {
  1537. LoadGridData(new object(), new EventArgs());
  1538. }
  1539. DataTable LabelInfDataTable;
  1540. /// <summary>
  1541. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  1542. /// </summary>
  1543. /// <param name="sender"></param>
  1544. /// <param name="e"></param>
  1545. private void LoadGridData(object sender, EventArgs e)
  1546. {
  1547. AllCollect = false;
  1548. //查询Oracle数据库
  1549. sql.Clear();
  1550. sql.Append("select t.*,rownum from prodiobarcode_view t where pib_inoutno='" + pi_inoutno.Text + "' order by to_number(pib_id)");
  1551. LabelInfDataTable = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1552. //查询本地数据库
  1553. sql.Clear();
  1554. sql.Append("select count(1) from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'");
  1555. DataTable dt = (DataTable)sdh.ExecuteSql(sql.ToString(), "select");
  1556. int rowcount = int.Parse(dt.Rows[0][0].ToString());
  1557. //如果本地没有缓存过
  1558. if (rowcount == 0 || rowcount != LabelInfDataTable.Rows.Count)
  1559. {
  1560. if (rowcount != LabelInfDataTable.Rows.Count && rowcount != 0)
  1561. {
  1562. string close = MessageBox.Show(this.ParentForm, "本地条码和服务器条码数量不一致,覆盖本地条码", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1563. if (close == "Yes")
  1564. {
  1565. sdh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  1566. //检验查询的字段和本地数据库字段是否匹配
  1567. sdh.AddColumFromDataTable(LabelInfDataTable, "prodiobarcode");
  1568. //将数据保存在本地数据库
  1569. sdh.SaveDataTable(LabelInfDataTable, "prodiobarcode");
  1570. }
  1571. }
  1572. else
  1573. {
  1574. //检验查询的字段和本地数据库字段是否匹配
  1575. sdh.AddColumFromDataTable(LabelInfDataTable, "prodiobarcode");
  1576. //将数据保存在本地数据库
  1577. sdh.SaveDataTable(LabelInfDataTable, "prodiobarcode");
  1578. }
  1579. }
  1580. else if (LabelInfDataTable.Columns.Count != dt.Columns.Count)
  1581. {
  1582. //检验查询的字段和本地数据库字段是否匹配
  1583. sdh.AddColumFromDataTable(LabelInfDataTable, "prodiobarcode");
  1584. sdh.BatchInsert("prodiobarcode", LabelInfDataTable);
  1585. }
  1586. sql.Clear();
  1587. sql.Append("select * from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by pib_id ");
  1588. LabelInfDataTable = (DataTable)sdh.ExecuteSql(sql.ToString(), "select");
  1589. bindingsource(LabelInf, LabelInfDataTable);
  1590. //有数据的话默认取第一条的品牌去取采集策略
  1591. TotalCount.Text = LabelInf.RowCount.ToString();
  1592. if (LabelInf.RowCount > 0)
  1593. {
  1594. Brand = LabelInf.Rows[0].Cells["pib_brand"].FormattedValue.ToString();
  1595. if (Brand != "")
  1596. sg_code.Text = dh.getFieldDataByCondition("scangroup", "sg_code", "sg_brand='" + Brand + "'").ToString();
  1597. SetOutBoxCapacity(LabelInf.Rows[0].Cells["pib_prodcode"].Value.ToString());
  1598. }
  1599. //绑定数据之后往下找到未采集的数据显示在当前采集的栏目
  1600. for (int i = 0; i < LabelInf.RowCount; i++)
  1601. {
  1602. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1603. {
  1604. griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
  1605. pr_code.Text = LabelInf.Rows[i].Cells["pib_prodcode"].FormattedValue.ToString();
  1606. pib_id.Text = LabelInf.Rows[i].Cells["pib_id1"].FormattedValue.ToString();
  1607. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
  1608. break;
  1609. }
  1610. }
  1611. }
  1612. delegate void BindDataSource(DataGridView dgv, DataTable dt);//定义委托
  1613. void bindingsource(DataGridView dgv, DataTable dt)
  1614. {
  1615. if (dgv.InvokeRequired)
  1616. {
  1617. dgv.Invoke(new BindDataSource(bindingsource), new object[] { dgv, dt });
  1618. }
  1619. else
  1620. {
  1621. dgv.AutoGenerateColumns = false;
  1622. dgv.DataSource = dt;
  1623. }
  1624. }
  1625. /// <summary>
  1626. /// 重绘Cell的颜色
  1627. /// </summary>
  1628. /// <param name="sender"></param>
  1629. /// <param name="e"></param>
  1630. private void LabelInf_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  1631. {
  1632. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  1633. if (e.ColumnIndex > 0)
  1634. {
  1635. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_madein" || LabelInf.Columns[e.ColumnIndex].Name == "pib_lotno" || LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode" || LabelInf.Columns[e.ColumnIndex].Name == "pib_outboxcode1" || LabelInf.Columns[e.ColumnIndex].Name == "pib_outboxcode2" || LabelInf.Columns[e.ColumnIndex].Name == "pr_brand")
  1636. {
  1637. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1638. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  1639. Rectangle border = e.CellBounds;
  1640. border.Width -= 1;
  1641. e.Graphics.DrawRectangle(Pens.White, border);
  1642. e.PaintContent(e.CellBounds);
  1643. e.Handled = true;
  1644. }
  1645. if (e.RowIndex >= 0)
  1646. {
  1647. if (LabelInf.Rows[e.RowIndex].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
  1648. {
  1649. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_lotno" || LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
  1650. {
  1651. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1652. e.Graphics.FillRectangle(Brushes.ForestGreen, e.CellBounds);
  1653. Rectangle border = e.CellBounds;
  1654. border.Width -= 1;
  1655. e.Graphics.DrawRectangle(Pens.Black, border);
  1656. e.PaintContent(e.CellBounds);
  1657. e.Handled = true;
  1658. }
  1659. }
  1660. }
  1661. }
  1662. }
  1663. private void pr_code_SearchIconClick(object sender, EventArgs e)
  1664. {
  1665. pr_code.Condition = " pd_inoutno='" + pi_inoutno.Text + "'";
  1666. }
  1667. private void pr_code_UserControlTextChanged(object sender, EventArgs e)
  1668. {
  1669. //用户在重新勾选后重置采集项目的索引
  1670. CurrentItemIndex = 0;
  1671. for (int i = 0; i < LabelInf.RowCount; i++)
  1672. {
  1673. if (pr_code.Text == LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1674. {
  1675. CurrentRowIndex = i;
  1676. break;
  1677. }
  1678. }
  1679. }
  1680. private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1681. {
  1682. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  1683. pi_inoutno_KeyDown(sender, e2);
  1684. }
  1685. /// <summary>
  1686. /// 采集明细切换
  1687. /// </summary>
  1688. /// <param name="sender"></param>
  1689. /// <param name="e"></param>
  1690. private void griddetno_KeyDown(object sender, KeyEventArgs e)
  1691. {
  1692. if (Keys.Enter == e.KeyData)
  1693. {
  1694. bool FindDetno = false;
  1695. for (int i = 0; i < LabelInf.RowCount; i++)
  1696. {
  1697. if (LabelInf.Rows[i].Cells["pib_pdno"].Value.ToString() == griddetno.Text && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1698. {
  1699. FindDetno = true;
  1700. CurrentItemIndex = 0;
  1701. CurrentRowIndex = i;
  1702. RemindUser();
  1703. break;
  1704. }
  1705. }
  1706. if (!FindDetno)
  1707. {
  1708. MessageBox.Show("不存在未采集的明细序号" + griddetno.Text);
  1709. return;
  1710. }
  1711. }
  1712. }
  1713. private void AutoPrintMidLabel()
  1714. {
  1715. bool FullBox = true;
  1716. //判断所有盒号未该盒的是否勾选已采集
  1717. for (int i = 0; i < LabelInf.RowCount; i++)
  1718. {
  1719. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  1720. {
  1721. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1722. FullBox = false;
  1723. }
  1724. }
  1725. //如果当前箱号已经装满了
  1726. if (FullBox)
  1727. {
  1728. if (MidLabelCombox.SelectedValue != null)
  1729. {
  1730. MidBoxCodePrint(CurrentRowIndex);
  1731. }
  1732. else
  1733. MessageBox.Show("未维护中盒模板");
  1734. }
  1735. }
  1736. /// <summary>
  1737. /// 勾选的时候自动打印
  1738. /// </summary>
  1739. /// <param name="sender"></param>
  1740. /// <param name="e"></param>
  1741. private void LabelInf_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  1742. {
  1743. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
  1744. {
  1745. string datecode = LabelInf.Rows[e.RowIndex].Cells["pib_datecode"].Value.ToString();
  1746. try
  1747. {
  1748. System.DateTime dt = System.DateTime.ParseExact(datecode, "yyyyMMdd", CultureInfo.CurrentCulture);
  1749. GregorianCalendar gc = new GregorianCalendar();
  1750. int weekOfYear = gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
  1751. if (weekOfYear < 10)
  1752. LabelInf.Rows[e.RowIndex].Cells["pib_datecode1"].Value = dt.Year.ToString().Substring(2, 2) + "0" + weekOfYear;
  1753. else
  1754. LabelInf.Rows[e.RowIndex].Cells["pib_datecode1"].Value = dt.Year.ToString().Substring(2, 2) + weekOfYear;
  1755. }
  1756. catch (Exception) { }
  1757. }
  1758. }
  1759. private void AllCollected_Click(object sender, EventArgs e)
  1760. {
  1761. if (AllCollect == false)
  1762. {
  1763. foreach (DataGridViewRow dr in LabelInf.Rows)
  1764. dr.Cells[1].Value = true;
  1765. AllCollect = true;
  1766. }
  1767. else
  1768. {
  1769. foreach (DataGridViewRow dr in LabelInf.Rows)
  1770. dr.Cells[1].Value = false;
  1771. AllCollect = false;
  1772. }
  1773. }
  1774. private void GetOutBoxCode_Click(object sender, EventArgs e)
  1775. {
  1776. if (dh.GetConfig("UsingPacking", "ProdInOut!Sale").ToString() != "")
  1777. {
  1778. int Current = 0;
  1779. sql.Clear();
  1780. sql.Append("select pr_qtyperplace,pd_qty,packingdetail.pd_cartonno,pr_zxbzs,packingdetail.pd_cartons from packingdetail left join packing on pd_piid=pi_id left join prodinout on ");
  1781. sql.Append("pi_packingcode=packing.pi_code left join product on pd_prodcode=pr_code where pi_inoutno='" + pi_inoutno.Text + "' order by pr_code,pd_detno");
  1782. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1783. if (dt.Rows.Count > 0)
  1784. {
  1785. try { OutboxCapacity.Value = (decimal)dt.Rows[0]["pr_qtyperplace"] / (decimal)dt.Rows[0]["pr_zxbzs"]; }
  1786. catch (Exception) { }
  1787. }
  1788. try
  1789. {
  1790. for (int i = 0; i < dt.Rows.Count; i++)
  1791. {
  1792. int pd_qty = int.Parse(dt.Rows[i]["pd_qty"].ToString());
  1793. int pr_zxbzs = int.Parse(dt.Rows[i]["pr_zxbzs"].ToString());
  1794. int pd_cartons = int.Parse(dt.Rows[i]["pd_cartons"].ToString());
  1795. for (int j = 0; j < pd_qty * pd_cartons / pr_zxbzs; j++)
  1796. {
  1797. LabelInf.Rows[Current].Cells["pib_outboxcode2"].Value = dt.Rows[i]["pd_cartonno"].ToString();
  1798. Current++;
  1799. }
  1800. }
  1801. GetPackingCode = true;
  1802. }
  1803. catch (Exception)
  1804. {
  1805. }
  1806. }
  1807. else
  1808. {
  1809. int BoxCode = 1;
  1810. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1811. {
  1812. LabelInf.Rows[i].Cells["pib_outboxcode2"].Value = BoxCode;
  1813. if (i + 1 < LabelInf.Rows.Count)
  1814. {
  1815. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) % OutboxCapacity.Value == 0 && (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  1816. {
  1817. BoxCode = BoxCode + 1;
  1818. }
  1819. else if (cu_print_outdc.Checked)
  1820. {
  1821. if (LabelInf.Rows[i].Cells["pib_datecode"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_datecode"].Value.ToString())
  1822. {
  1823. BoxCode = BoxCode + 1;
  1824. }
  1825. }
  1826. else if (cu_print_outlotno.Checked)
  1827. {
  1828. if (LabelInf.Rows[i].Cells["pib_lotno"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_lotno"].Value.ToString())
  1829. {
  1830. BoxCode = BoxCode + 1;
  1831. }
  1832. }
  1833. else if (cu_print_outpo.Checked)
  1834. {
  1835. if (LabelInf.Rows[i].Cells["pd_pocode"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pd_pocode"].Value.ToString())
  1836. {
  1837. BoxCode = BoxCode + 1;
  1838. }
  1839. }
  1840. else if (cu_print_outprod.Checked)
  1841. {
  1842. if (LabelInf.Rows[i].Cells["pib_custprodcode"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_custprodcode"].Value.ToString())
  1843. {
  1844. BoxCode = BoxCode + 1;
  1845. }
  1846. }
  1847. else if (cu_print_ordercode.Checked)
  1848. {
  1849. if (LabelInf.Rows[i].Cells["pd_ordercode"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pd_ordercode"].Value.ToString())
  1850. {
  1851. BoxCode = BoxCode + 1;
  1852. }
  1853. }
  1854. }
  1855. }
  1856. sdh.BatchInsert("prodiobarcode", LabelInf.DataSource as DataTable);
  1857. }
  1858. DataTable dt1 = (DataTable)sdh.ExecuteSql("select pib_id,pib_outboxcode1,pib_outboxcode2,pib_custmidboxcode,pib_custoutboxcode,pib_lotno,pib_datecode,pib_ifupload,pib_ifpick,pib_ifprint from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' ", "select");
  1859. if (dt1.Rows.Count > 0)
  1860. {
  1861. dh.CallProcedure("sp_uploadbarcode", dt1);
  1862. }
  1863. }
  1864. private void GetMidBoxCode_Click(object sender, EventArgs e)
  1865. {
  1866. int BoxCode = 1;
  1867. int innerboxcount = 1;
  1868. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1869. {
  1870. string midcapa = LabelInf.Rows[i].Cells["pr_midboxcapacity_user"].Value.ToString();
  1871. if (!(midcapa == "" || midcapa == "0"))
  1872. {
  1873. //如果出现值为空或者0默认界面上填写的值
  1874. MidBoxCapacity.Value = decimal.Parse((midcapa == "" || midcapa == "0") ? MidBoxCapacity.Value.ToString() : midcapa);
  1875. LabelInf.Rows[i].Cells["pib_outboxcode1"].Value = BoxCode;
  1876. if (i + 1 < LabelInf.Rows.Count)
  1877. {
  1878. if (innerboxcount == MidBoxCapacity.Value)
  1879. {
  1880. BoxCode = BoxCode + 1;
  1881. innerboxcount = 1;
  1882. }
  1883. else if (LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString())
  1884. {
  1885. BoxCode = BoxCode + 1;
  1886. innerboxcount = 1;
  1887. }
  1888. else
  1889. {
  1890. innerboxcount = innerboxcount + 1;
  1891. }
  1892. }
  1893. }
  1894. }
  1895. sdh.BatchInsert("prodiobarcode", LabelInf.DataSource as DataTable);
  1896. DataTable dt1 = (DataTable)sdh.ExecuteSql("select pib_id,pib_outboxcode1,pib_outboxcode2,pib_custmidboxcode,pib_custoutboxcode,pib_lotno,pib_datecode,pib_ifupload,pib_ifpick,pib_ifprint from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' ", "select");
  1897. if (dt1.Rows.Count > 0)
  1898. {
  1899. dh.CallProcedure("sp_uploadbarcode", dt1);
  1900. }
  1901. }
  1902. private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1903. {
  1904. string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1905. if (close.ToString() == "Yes")
  1906. {
  1907. Login login = new Login();
  1908. //注销的时候需要将拼接的连接字符串置空
  1909. DataHelper.DBConnectionString = null;
  1910. logout = true;
  1911. if (lbl != null)
  1912. lbl.Quit();
  1913. if (engine != null)
  1914. engine.Dispose();
  1915. this.Hide();
  1916. login.ShowDialog();
  1917. this.Close();
  1918. }
  1919. }
  1920. private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1921. /// <summary>
  1922. /// 切换打开的单盘文件
  1923. /// </summary>
  1924. /// <param name="sender"></param>
  1925. /// <param name="e"></param>
  1926. private void SingleLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1927. {
  1928. try
  1929. {
  1930. if (ComBoxClickChangeLabelDoc)
  1931. {
  1932. if (SingleDoc != null)
  1933. SingleDoc.Close();
  1934. if (SingleFormat != null)
  1935. SingleFormat.Close(SaveOptions.DoNotSaveChanges);
  1936. System.DateTime time = Convert.ToDateTime(SingleLabelCombox.SelectedValue.ToString().Split('#')[2]);
  1937. if (SingleLabelCombox.Text != "" && SingleLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  1938. {
  1939. if (PrintMethod == "CodeSoft")
  1940. {
  1941. SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
  1942. SingleDoc.Printer.Name = SingleLabelPrinter.Text;
  1943. }
  1944. else
  1945. {
  1946. SingleFormat = engine.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
  1947. SingleFormat.PrintSetup.PrinterName = SingleLabelPrinter.Text;
  1948. }
  1949. }
  1950. }
  1951. }
  1952. catch (Exception) { }
  1953. }
  1954. /// <summary>
  1955. /// 切换打开的中盒文件
  1956. /// </summary>
  1957. /// <param name="sender"></param>
  1958. /// <param name="e"></param>
  1959. private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1960. {
  1961. try
  1962. {
  1963. if (ComBoxClickChangeLabelDoc)
  1964. {
  1965. if (MidDoc != null)
  1966. MidDoc.Close();
  1967. if (MidFormat != null)
  1968. MidFormat.Close(SaveOptions.DoNotSaveChanges);
  1969. if (MidLabelCombox.Text != "" && MidLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  1970. {
  1971. System.DateTime time = Convert.ToDateTime(MidLabelCombox.SelectedValue.ToString().Split('#')[2]);
  1972. if (PrintMethod == "CodeSoft")
  1973. {
  1974. MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
  1975. MidDoc.Printer.Name = MidLabelPrinter.Text;
  1976. }
  1977. else
  1978. {
  1979. MidFormat = engine.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
  1980. MidFormat.PrintSetup.PrinterName = MidLabelPrinter.Text;
  1981. }
  1982. }
  1983. }
  1984. }
  1985. catch (Exception) { }
  1986. }
  1987. /// <summary>
  1988. /// 切换打开的外箱文件
  1989. /// </summary>
  1990. /// <param name="sender"></param>
  1991. /// <param name="e"></param>
  1992. private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e)
  1993. {
  1994. try
  1995. {
  1996. if (ComBoxClickChangeLabelDoc)
  1997. {
  1998. if (OutBoxDoc != null)
  1999. OutBoxDoc.Close();
  2000. if (OutFormat != null)
  2001. OutFormat.Close(SaveOptions.DoNotSaveChanges);
  2002. System.DateTime time = Convert.ToDateTime(OutBoxCombox.SelectedValue.ToString().Split('#')[2]);
  2003. if (OutBoxCombox.Text != "" && OutBoxCombox.SelectedValue != null && !GetGridOnly.Checked)
  2004. {
  2005. if (PrintMethod == "CodeSoft")
  2006. {
  2007. OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
  2008. OutBoxDoc.Printer.Name = OutBoxPrinter.Text;
  2009. }
  2010. else
  2011. {
  2012. OutFormat = engine.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
  2013. OutFormat.PrintSetup.PrinterName = OutBoxPrinter.Text;
  2014. }
  2015. }
  2016. }
  2017. }
  2018. catch (Exception) { }
  2019. }
  2020. private void ChooseAll_Click(object sender, EventArgs e)
  2021. {
  2022. if (LabelInf.Rows.Count > 0)
  2023. {
  2024. if (LabelInf.Rows.Count > 0)
  2025. {
  2026. if (LabelInf.Rows[0].Cells["Choose"].FormattedValue.ToString() == "True")
  2027. {
  2028. foreach (DataGridViewRow dr in LabelInf.Rows)
  2029. dr.Cells[0].Value = false;
  2030. }
  2031. else
  2032. {
  2033. foreach (DataGridViewRow dr in LabelInf.Rows)
  2034. dr.Cells[0].Value = true;
  2035. }
  2036. }
  2037. }
  2038. }
  2039. private void LabelInf_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  2040. {
  2041. if (e.RowIndex > 0)
  2042. {
  2043. if (LabelInf.Columns[e.ColumnIndex].Name == "pin_madein")
  2044. {
  2045. StringBuilder pibid = new StringBuilder();
  2046. string madein = LabelInf.Rows[e.RowIndex].Cells["pib_madein"].Value.ToString();
  2047. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_madein" && CollectionUnit.Text == "盒")
  2048. {
  2049. string midbox = LabelInf.Rows[e.RowIndex].Cells["pib_outboxcode1"].Value.ToString();
  2050. for (int i = 0; i < LabelInf.Rows.Count; i++)
  2051. {
  2052. if (midbox == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  2053. {
  2054. LabelInf.Rows[i].Cells["pib_madein"].Value = madein;
  2055. pibid.Append(LabelInf.Rows[i].Cells["pib_id1"].Value + ",");
  2056. }
  2057. }
  2058. }
  2059. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_madein" && CollectionUnit.Text == "全部")
  2060. {
  2061. for (int i = 0; i < LabelInf.Rows.Count; i++)
  2062. {
  2063. LabelInf.Rows[i].Cells["pib_madein"].Value = madein;
  2064. pibid.Append(LabelInf.Rows[i].Cells["pib_id1"].Value + ",");
  2065. }
  2066. }
  2067. pibid.Append("1");
  2068. sdh.ExecuteSql("update prodiobarcode set pib_madein='" + madein + "' where pib_id in (" + pibid + ")", "update");
  2069. }
  2070. }
  2071. }
  2072. private void ExportData_Click(object sender, EventArgs e)
  2073. {
  2074. }
  2075. private void MidBoxCapacity_Leave(object sender, EventArgs e)
  2076. {
  2077. NumericUpDown nup = (NumericUpDown)sender;
  2078. switch (nup.Name)
  2079. {
  2080. case "MidBoxCapacity":
  2081. Properties.Settings.Default.MidBoxCapacity = nup.Value;
  2082. Properties.Settings.Default.Save();
  2083. break;
  2084. case "OutboxCapacity":
  2085. Properties.Settings.Default.OutboxCapacity = nup.Value;
  2086. Properties.Settings.Default.Save();
  2087. break;
  2088. default:
  2089. break;
  2090. }
  2091. }
  2092. private void CleanBarCode_Click(object sender, EventArgs e)
  2093. {
  2094. string close = MessageBox.Show(this.ParentForm, "是否清除该出货单条码", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  2095. if (close.ToString() == "Yes")
  2096. {
  2097. sdh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  2098. dh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  2099. LoadGridData(sender, e);
  2100. }
  2101. }
  2102. private void LabelPrinter_UserOnSelectIndexChange(object sender, EventArgs e)
  2103. {
  2104. switch ((sender as Control).Parent.Name)
  2105. {
  2106. case "SingleLabelPrinter":
  2107. if (PrintMethod == "CodeSoft")
  2108. {
  2109. if (SingleDoc != null)
  2110. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  2111. }
  2112. else
  2113. {
  2114. if (SingleFormat != null)
  2115. SingleFormat.PrintSetup.PrinterName = SingleLabelPrinter.Text;
  2116. }
  2117. Properties.Settings.Default.SinglePrinter = SingleLabelPrinter.Text;
  2118. break;
  2119. case "MidLabelPrinter":
  2120. if (PrintMethod == "CodeSoft")
  2121. {
  2122. if (MidDoc != null)
  2123. MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
  2124. }
  2125. else
  2126. {
  2127. if (MidFormat != null)
  2128. MidFormat.PrintSetup.PrinterName = MidLabelPrinter.Text;
  2129. }
  2130. Properties.Settings.Default.MidPrinter = MidLabelPrinter.Text;
  2131. break;
  2132. case "OutBoxPrinter":
  2133. if (PrintMethod == "CodeSoft")
  2134. {
  2135. if (OutBoxDoc != null)
  2136. OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
  2137. }
  2138. else
  2139. {
  2140. if (OutFormat != null)
  2141. OutFormat.PrintSetup.PrinterName = OutBoxPrinter.Text;
  2142. }
  2143. Properties.Settings.Default.OutPrinter = OutBoxPrinter.Text;
  2144. break;
  2145. default:
  2146. break;
  2147. }
  2148. Properties.Settings.Default.Save();
  2149. }
  2150. private void DocRefresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  2151. {
  2152. switch ((sender as Control).Name)
  2153. {
  2154. case "SingleDocRefresh":
  2155. if (SingleDoc != null)
  2156. SingleDoc.Close();
  2157. if (SingleLabelCombox.Text != "" && SingleLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  2158. {
  2159. System.DateTime time = Convert.ToDateTime(SingleLabelCombox.SelectedValue.ToString().Split('#')[2]);
  2160. SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
  2161. }
  2162. break;
  2163. case "MidDocRefresh":
  2164. if (MidDoc != null)
  2165. MidDoc.Close();
  2166. if (MidLabelCombox.Text != "" && MidLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  2167. {
  2168. System.DateTime time = Convert.ToDateTime(MidLabelCombox.SelectedValue.ToString().Split('#')[2]);
  2169. MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
  2170. }
  2171. break;
  2172. case "OutDocRefresh":
  2173. if (OutBoxDoc != null)
  2174. OutBoxDoc.Close();
  2175. if (OutBoxCombox.Text != "" && OutBoxCombox.SelectedValue != null && !GetGridOnly.Checked)
  2176. {
  2177. System.DateTime time = Convert.ToDateTime(OutBoxCombox.SelectedValue.ToString().Split('#')[2]);
  2178. OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
  2179. }
  2180. break;
  2181. default:
  2182. break;
  2183. }
  2184. }
  2185. private void cu_code_UserControlTextChanged(object sender, EventArgs e)
  2186. {
  2187. if (!InitGetLabel)
  2188. GetInOutInfAndLabelFile();
  2189. }
  2190. private void MenuSetting_Click(object sender, EventArgs e)
  2191. {
  2192. Menu.Show(new Point(MenuSetting.Location.X, MenuSetting.Location.Y + 20));
  2193. }
  2194. private void Menu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  2195. {
  2196. Menu.Close();
  2197. DataTable dt;
  2198. DialogResult result;
  2199. switch (e.ClickedItem.Text)
  2200. {
  2201. case "采集策略设置":
  2202. 采集策略 form = new 采集策略(sg_code.Text);
  2203. form.FormClosed += sg_code_UserControlTextChanged;
  2204. BaseUtil.SetFormCenter(form);
  2205. form.ShowDialog();
  2206. break;
  2207. case "附加信息设置":
  2208. if (cu_code.Text != "")
  2209. {
  2210. 附件内容打印 att = new 附件内容打印(cu_code.Text);
  2211. att.FormClosed += Att_FormClosed;
  2212. att.ShowDialog();
  2213. }
  2214. else MessageBox.Show("请先获取出库单信息");
  2215. break;
  2216. case "标签维护":
  2217. 客户标签维护 form1 = new 客户标签维护();
  2218. BaseUtil.SetFormCenter(form1);
  2219. if (SingleDoc != null)
  2220. SingleDoc.Close();
  2221. if (MidDoc != null)
  2222. MidDoc.Close();
  2223. if (OutBoxDoc != null)
  2224. OutBoxDoc.Close();
  2225. //if (SingleFormat != null)
  2226. // SingleFormat.Close(SaveOptions.DoNotSaveChanges);
  2227. //if (MidFormat != null)
  2228. // MidFormat.Close(SaveOptions.DoNotSaveChanges);
  2229. //if (OutFormat != null)
  2230. // OutFormat.Close(SaveOptions.DoNotSaveChanges);
  2231. form1.FormClosed += LabelFormClose;
  2232. form1.ShowDialog();
  2233. break;
  2234. case "导出数据":
  2235. ExportFileDialog.Description = "选择导出的路径";
  2236. result = ExportFileDialog.ShowDialog();
  2237. if (result == DialogResult.OK)
  2238. {
  2239. ExcelHandler eh = new ExcelHandler();
  2240. dt = ((DataTable)LabelInf.DataSource).Copy();
  2241. for (int i = dt.Columns.Count - 1; i >= 0; i--)
  2242. {
  2243. for (int j = 0; j < LabelInf.Columns.Count; j++)
  2244. {
  2245. //去除ID列
  2246. if (dt.Columns[i].ColumnName.ToLower().Contains("id") || dt.Columns[i].ColumnName.ToLower() == "pib_barcode" || dt.Columns[i].ColumnName.ToLower() == "pib_pdno" || dt.Columns[i].ColumnName.ToLower() == "pib_ifpick" || dt.Columns[i].ColumnName.ToLower() == "pib_ifprint" || dt.Columns[i].ColumnName.ToLower() == "pib_datecode1" || dt.Columns[i].ColumnName.ToLower() == "pr_vendprodcode")
  2247. {
  2248. dt.Columns.RemoveAt(i);
  2249. break;
  2250. }
  2251. switch (dt.Columns[i].ColumnName.ToLower())
  2252. {
  2253. case "pib_lotno":
  2254. dt.Columns[i].ColumnName = "批次号";
  2255. break;
  2256. case "pib_datecode":
  2257. dt.Columns[i].ColumnName = "生产日期";
  2258. break;
  2259. case "pib_custbarcode":
  2260. dt.Columns[i].ColumnName = "最小产品包装条码";
  2261. break;
  2262. default:
  2263. break;
  2264. }
  2265. if (dt.Columns[i].ColumnName.ToLower() == LabelInf.Columns[j].DataPropertyName.ToLower())
  2266. {
  2267. dt.Columns[i].ColumnName = LabelInf.Columns[j].HeaderText;
  2268. break;
  2269. }
  2270. }
  2271. }
  2272. eh.ExportExcel(dt, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text);
  2273. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  2274. if (close.ToString() == "Yes")
  2275. System.Diagnostics.Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + ".xls");
  2276. }
  2277. break;
  2278. case "权限设置":
  2279. PowerSetting pw = new PowerSetting();
  2280. BaseUtil.SetFormCenter(pw);
  2281. pw.ShowDialog();
  2282. break;
  2283. case "条码导入生成":
  2284. ImportExcel.Filter = "(*.xls)|*.xlsx;*.xls";
  2285. result = ImportExcel.ShowDialog();
  2286. if (result == DialogResult.OK)
  2287. {
  2288. thread = new Thread(ImportBarcode);
  2289. stw = new SetLoadingWindow(thread, "正在生成条码");
  2290. BaseUtil.SetFormCenter(stw);
  2291. stw.ShowDialog();
  2292. }
  2293. break;
  2294. case "下载模板":
  2295. ExportFileDialog.Description = "选择导出的路径";
  2296. result = ExportFileDialog.ShowDialog();
  2297. if (result == DialogResult.OK)
  2298. {
  2299. File.Copy(System.Windows.Forms.Application.StartupPath + "\\导入模板.xls", ExportFileDialog.SelectedPath + "\\导入模板.xls", true);
  2300. System.Diagnostics.Process.Start(ExportFileDialog.SelectedPath + "\\导入模板.xls");
  2301. }
  2302. break;
  2303. case "客户合并规则":
  2304. CustomerRule cust = new CustomerRule();
  2305. BaseUtil.SetFormCenter(cust);
  2306. cust.ShowDialog();
  2307. break;
  2308. case "流水调整":
  2309. if (cu_code.Text != "")
  2310. {
  2311. ReSetMaxNum reset = new ReSetMaxNum(cu_code.Text, pi_inoutno.Text);
  2312. BaseUtil.SetFormCenter(reset);
  2313. reset.ShowDialog();
  2314. }
  2315. else
  2316. {
  2317. MessageBox.Show("请先输入出货单号");
  2318. }
  2319. break;
  2320. default:
  2321. break;
  2322. }
  2323. }
  2324. private void Att_FormClosed(object sender, FormClosedEventArgs e)
  2325. {
  2326. Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LabelAttachPARAMETER where lap_custcode='" + cu_code.Text + "'", "select");
  2327. }
  2328. //生成客户条码
  2329. public string BarcodeMethod1(string Prefix, string Suffix, int Index, int Length, int radix)
  2330. {
  2331. string str = Prefix;
  2332. //如果是流水则需要在前面加0
  2333. string serialcode = BaseUtil.DToAny(custserialnum, radix);
  2334. for (int j = serialcode.ToString().Length; j < Length; j++)
  2335. {
  2336. serialcode = "0" + serialcode;
  2337. }
  2338. str += serialcode;
  2339. str += Suffix;
  2340. custserialnum = custserialnum + 1;
  2341. return str;
  2342. }
  2343. //前缀
  2344. string Prefix = "";
  2345. //后缀
  2346. string Suffix = "";
  2347. //编码规则编号
  2348. string NrCode = "";
  2349. string PrefixFixed = "";
  2350. //流水号的索引
  2351. int SerialNumIndex = 0;
  2352. //流水长度
  2353. int SerialNumLength = 0;
  2354. //存放键值对
  2355. int Radix = 10;
  2356. //客户的流水号
  2357. int custserialnum = 0;
  2358. public void GetCustRule()
  2359. {
  2360. //前缀
  2361. Prefix = "";
  2362. //后缀
  2363. Suffix = "";
  2364. //编码规则编号
  2365. NrCode = "";
  2366. PrefixFixed = "";
  2367. //流水号的索引
  2368. SerialNumIndex = 0;
  2369. //流水长度
  2370. SerialNumLength = 0;
  2371. //存放键值对
  2372. Radix = 10;
  2373. DataTable Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_type,nrd_radix,nrd_sql,nrd_length,nr_code,nvl(nrd_iscombine,-1)nrd_iscombine from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode='" + cu_code.Text + "' order by nrd_detno", "select");
  2374. //如果没有则取公共规则
  2375. if (Nr.Rows.Count == 0)
  2376. Nr = (DataTable)dh.ExecuteSql("select nrd_detno,nrd_name,nrd_radix,nrd_type,nrd_sql,nrd_length,nr_code,nvl(nrd_iscombine,-1)nrd_iscombine from NoRuleDetail left join norule on nrd_nrid=nr_id where nr_custcode is null and nr_isdefault <> 0 order by nrd_detno", "select");
  2377. //用于过滤参数的正则表达式
  2378. if (Nr.Rows.Count > 0)
  2379. {
  2380. NrCode = Nr.Rows[0]["nr_code"].ToString();
  2381. }
  2382. Regex match = new Regex("{\\w+}");
  2383. //用于存放每一项的明细的数据
  2384. string[] NrData = new string[Nr.Rows.Count];
  2385. for (int m = 0; m < Nr.Rows.Count; m++)
  2386. {
  2387. switch (Nr.Rows[m]["nrd_type"].ToString())
  2388. {
  2389. //常量直接进行拼接
  2390. case "常量":
  2391. NrData[m] = Nr.Rows[m]["nrd_sql"].ToString();
  2392. Prefix += NrData[m];
  2393. Suffix += NrData[m];
  2394. break;
  2395. case "SQL":
  2396. string SQL = Nr.Rows[m]["nrd_sql"].ToString();
  2397. DataTable Temp;
  2398. //如果不包含参数替换
  2399. if (SQL.IndexOf("{") == 0)
  2400. {
  2401. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  2402. }
  2403. else
  2404. {
  2405. //替换参数后重新执行SQL
  2406. foreach (Match mch in match.Matches(SQL))
  2407. {
  2408. SQL = SQL.Replace(mch.Value.Trim(), "'" + pi_inoutno.Text + "'");
  2409. }
  2410. Temp = (DataTable)dh.ExecuteSql(SQL, "select");
  2411. }
  2412. if (Temp.Rows.Count > 0)
  2413. {
  2414. NrData[m] = Temp.Rows[0][0].ToString();
  2415. Prefix += NrData[m];
  2416. Suffix += NrData[m];
  2417. }
  2418. else
  2419. {
  2420. NrData[m] = "";
  2421. Prefix += NrData[m];
  2422. Suffix += NrData[m];
  2423. }
  2424. break;
  2425. //流水需要通过MaxNumber去取
  2426. case "流水":
  2427. NrData[m] = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "'").ToString();
  2428. Suffix = "";
  2429. PrefixFixed = Prefix;
  2430. //设置当前流水
  2431. custserialnum = int.Parse(NrData[m] == "" ? "0" : NrData[m]);
  2432. SerialNumIndex = m;
  2433. SerialNumLength = int.Parse(Nr.Rows[m]["nrd_length"].ToString());
  2434. Radix = int.Parse(Nr.Rows[m]["nrd_radix"].ToString());
  2435. break;
  2436. default:
  2437. break;
  2438. }
  2439. }
  2440. string maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'").ToString();
  2441. if (maxnum == "")
  2442. {
  2443. dh.ExecuteSql("insert into RuleMaxNum(rmn_id,rmn_nrcode,rmn_prefix,rmn_maxnumber) values(RuleMaxNum_seq.nextval,'" + NrCode + "','" + Prefix + "','1')", "insert");
  2444. maxnum = dh.getFieldDataByCondition("RuleMaxNum", "rmn_maxnumber", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'").ToString();
  2445. custserialnum = int.Parse(maxnum);
  2446. }//如果流水号不为空则取当前流水
  2447. else
  2448. {
  2449. custserialnum = int.Parse(maxnum);
  2450. }
  2451. }
  2452. public void ImportBarcode()
  2453. {
  2454. try
  2455. {
  2456. GetCustRule();
  2457. //获取最大的流水号
  2458. DataTable dt = ExcelHandler.ExcelToDataTable(ImportExcel.FileName, true);
  2459. if (dt == null)
  2460. {
  2461. MessageBox.Show("文件" + ImportExcel.FileName + "被占用或者格式不正确");
  2462. return;
  2463. }
  2464. string outsql = "";
  2465. LogicHandler.GenerateBarCode(PI_ID, cu_code.Text, out outsql);
  2466. sql.Clear();
  2467. sql.Append(outsql);
  2468. DataTable dt1 = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  2469. //需要插入的参数
  2470. ArrayList<string> barcode = new ArrayList<string>();
  2471. ArrayList<string> custbarcode = new ArrayList<string>();
  2472. ArrayList<string> datecode = new ArrayList<string>();
  2473. ArrayList<string> lotno = new ArrayList<string>();
  2474. ArrayList<string> pib_inqty = new ArrayList<string>();
  2475. ArrayList<string> piboutboxcode2 = new ArrayList<string>();
  2476. ArrayList<string> pdordercode = new ArrayList<string>();
  2477. ArrayList<string> pdorderdetno = new ArrayList<string>();
  2478. ArrayList<string> pdpdno = new ArrayList<string>();
  2479. ArrayList<string> pdid = new ArrayList<string>();
  2480. ArrayList<string> prbrand = new ArrayList<string>();
  2481. ArrayList<string> pdprodcode = new ArrayList<string>();
  2482. ArrayList<string> pib_custoutboxcode = new ArrayList<string>();
  2483. ArrayList<string> brand = new ArrayList<string>();
  2484. ArrayList<string> madein = new ArrayList<string>();
  2485. ArrayList<string> size = new ArrayList<string>();
  2486. ArrayList<string> weight = new ArrayList<string>();
  2487. ArrayList<string> prdetail = new ArrayList<string>();
  2488. //用于数量的校验
  2489. Dictionary<string, decimal> sumqty = new Dictionary<string, decimal>();
  2490. Dictionary<string, Dictionary<string, decimal>> outsumqty = new Dictionary<string, Dictionary<string, decimal>>();
  2491. for (int i = 0; i < dt.Rows.Count; i++)
  2492. {
  2493. string pr_spec = dt.Rows[i]["规格型号"].ToString().Trim();
  2494. if (pr_spec.Trim() == "")
  2495. {
  2496. break;
  2497. }
  2498. string qty = Regex.Replace(dt.Rows[i]["数量"].ToString(), @"[^\d]*", ""); ;
  2499. //累计Excel该型号的数量
  2500. if (!sumqty.ContainsKey(pr_spec))
  2501. {
  2502. sumqty.Add(pr_spec, 0);
  2503. }
  2504. //累计Excel该型号的数量
  2505. sumqty[pr_spec] += decimal.Parse(qty);
  2506. }
  2507. for (int i = 0; i < dt1.Rows.Count; i++)
  2508. {
  2509. //不包含型号则进行添加
  2510. string pr_spec = dt1.Rows[i]["pr_spec"].ToString().Trim();
  2511. string pd_pdno = dt1.Rows[i]["pd_pdno"].ToString();
  2512. decimal pd_outqty = decimal.Parse(dt1.Rows[i]["pd_outqty"].ToString());
  2513. if (!outsumqty.ContainsKey(pr_spec))
  2514. {
  2515. Dictionary<string, decimal> dic = new Dictionary<string, decimal>();
  2516. dic.Add(pd_pdno, pd_outqty);
  2517. outsumqty.Add(pr_spec, dic);
  2518. }
  2519. else
  2520. {
  2521. outsumqty[pr_spec].Add(pd_pdno, pd_outqty);
  2522. }
  2523. }
  2524. //上一个的最小外箱号,如果箱号没有发生变化则外箱条码也不变化
  2525. for (int i = 0; i < dt.Rows.Count; i++)
  2526. {
  2527. string pr_spec = dt.Rows[i]["规格型号"].ToString().Trim();
  2528. string 品牌 = dt.Rows[i]["品牌"].ToString().Trim();
  2529. string 产地 = dt.Rows[i]["产地"].ToString().Trim();
  2530. string 尺寸 = dt.Rows[i]["尺寸"].ToString().Trim();
  2531. string 重量 = dt.Rows[i]["重量"].ToString().Trim();
  2532. string 名称 = dt.Rows[i]["产品名称"].ToString().Trim();
  2533. string 订单编号 = dt.Rows[i]["订单编号"].ToString().Trim();
  2534. if (pr_spec.Trim() == "")
  2535. {
  2536. break;
  2537. }
  2538. string qty = dt.Rows[i]["数量"].ToString();
  2539. string DateCode = "";
  2540. string LotNo = "";
  2541. if (dt.Columns.Contains("DC/LOT NO"))
  2542. {
  2543. if (dt.Rows[i]["DC/LOT NO"].ToString().IndexOf("-") > 0)
  2544. {
  2545. DateCode = dt.Rows[i]["DC/LOT NO"].ToString().Split('-')[0];
  2546. LotNo = dt.Rows[i]["DC/LOT NO"].ToString().Split('-')[1];
  2547. }
  2548. else if (dt.Rows[i]["DC/LOT NO"].ToString().IndexOf(" ") > 0)
  2549. {
  2550. DateCode = dt.Rows[i]["DC/LOT NO"].ToString().Split(' ')[0];
  2551. LotNo = dt.Rows[i]["DC/LOT NO"].ToString().Split(' ')[1];
  2552. }
  2553. }
  2554. if (dt.Columns.Contains("DC") && DateCode == "")
  2555. {
  2556. DateCode = dt.Rows[i]["DC"].ToString();
  2557. }
  2558. if (dt.Columns.Contains("LOT NO") && LotNo == "")
  2559. {
  2560. LotNo = dt.Rows[i]["LOT NO"].ToString();
  2561. }
  2562. string pib_outboxcode2 = dt.Rows[i]["箱号"].ToString();
  2563. DataRow[] dr = dt1.Select("pr_spec='" + pr_spec + "'");
  2564. if (dr.Length == 0)
  2565. {
  2566. LogicHandler.FilterData(cu_code.Text, "FUDAN", pr_spec, qty, DateCode, LotNo, out pr_spec, out qty, out DateCode, out LotNo);
  2567. dr = dt1.Select("pr_spec='" + pr_spec + "'");
  2568. }
  2569. else
  2570. {
  2571. LogicHandler.FilterData(cu_code.Text, dr[0]["pr_brand"].ToString(), pr_spec, qty, DateCode, LotNo, out pr_spec, out qty, out DateCode, out LotNo);
  2572. }
  2573. decimal outqty = decimal.Parse(Regex.Replace(qty, @"[^\d]*", ""));
  2574. for (int k = 0; k < dr.Length; k++)
  2575. {
  2576. string pd_orderdetno = dr[k]["pd_orderdetno"].ToString();
  2577. string pd_prodcode = dr[k]["pd_prodcode"].ToString();
  2578. string pd_ordercode = dr[k]["pd_ordercode"].ToString();
  2579. string pd_piid = dr[k]["pd_piid"].ToString();
  2580. string pr_brand = dr[k]["pr_brand"].ToString();
  2581. string pd_pdno = dr[k]["pd_pdno"].ToString();
  2582. string pd_id = dr[k]["pd_id"].ToString();
  2583. string pd_piclass = dr[k]["pd_piclass"].ToString();
  2584. string pr_id = dr[k]["pr_id"].ToString();
  2585. string pr_madein = dr[k]["pr_madein"].ToString();
  2586. string pr_detail = dr[k]["pr_detail"].ToString();
  2587. //已导入数量
  2588. decimal zxbzs = decimal.Parse(dr[k]["pr_zxbzs"].ToString());
  2589. decimal pd_outqty = 0;
  2590. decimal barcodenum = 0;
  2591. if (outsumqty[pr_spec][pd_pdno] == 0)
  2592. {
  2593. continue;
  2594. }
  2595. //如果导入行的数量小于改明细的出货数量
  2596. if (outsumqty[pr_spec][pd_pdno] >= outqty)
  2597. {
  2598. //使用导入明细行数量
  2599. pd_outqty = outqty;
  2600. }
  2601. else
  2602. {
  2603. ////使用该出货单明细行数量,并且数量置为0
  2604. pd_outqty = outsumqty[pr_spec][pd_pdno];
  2605. }
  2606. string pib_barcode = dh.getFieldDataByCondition("prodiobarcode", "max(pib_barcode)", "PIB_INOUTNO='" + pi_inoutno.Text + "'").ToString();
  2607. if (pd_outqty % zxbzs != 0)
  2608. {
  2609. barcodenum = Math.Floor(pd_outqty / zxbzs) + 1;
  2610. //如果有余数先加上所有最小包最后加尾数
  2611. for (int j = 0; j < barcodenum - 1; j++)
  2612. {
  2613. barcode.Add(BaseUtil.BarcodeMethod1(pd_id, pr_id, pib_barcode));
  2614. custbarcode.Add(BarcodeMethod1(PrefixFixed, Suffix, SerialNumIndex, SerialNumLength, Radix));
  2615. pib_custoutboxcode.Add(pib_outboxcode2);
  2616. piboutboxcode2.Add(pib_outboxcode2);
  2617. pib_inqty.Add(zxbzs);
  2618. datecode.Add(DateCode);
  2619. lotno.Add(LotNo);
  2620. pdordercode.Add(订单编号 == "" ? pd_ordercode : 订单编号);
  2621. pdorderdetno.Add(pd_orderdetno);
  2622. pdpdno.Add(pd_pdno);
  2623. pdid.Add(pd_id);
  2624. prbrand.Add(品牌 == "" ? pr_brand : 品牌);
  2625. madein.Add(产地 == "" ? pr_madein : 产地);
  2626. size.Add(尺寸);
  2627. weight.Add(重量);
  2628. pdprodcode.Add(pd_prodcode);
  2629. prdetail.Add(名称 == "" ? pr_detail : 名称);
  2630. }
  2631. custbarcode.Add(BarcodeMethod1(PrefixFixed, Suffix, SerialNumIndex, SerialNumLength, Radix));
  2632. pib_custoutboxcode.Add(pib_outboxcode2);
  2633. barcode.Add(BaseUtil.BarcodeMethod1(pd_id, pr_id, pib_barcode));
  2634. pib_inqty.Add(pd_outqty % zxbzs);
  2635. piboutboxcode2.Add(pib_outboxcode2);
  2636. datecode.Add(DateCode);
  2637. lotno.Add(LotNo);
  2638. pdordercode.Add(订单编号 == "" ? pd_ordercode : 订单编号);
  2639. pdorderdetno.Add(pd_orderdetno);
  2640. pdpdno.Add(pd_pdno);
  2641. pdid.Add(pd_id);
  2642. prbrand.Add(品牌 == "" ? pr_brand : 品牌);
  2643. madein.Add(产地 == "" ? pr_madein : 产地);
  2644. size.Add(尺寸);
  2645. weight.Add(重量);
  2646. pdprodcode.Add(pd_prodcode);
  2647. prdetail.Add(名称 == "" ? pr_detail : 名称);
  2648. }
  2649. else
  2650. {
  2651. barcodenum = pd_outqty / zxbzs;
  2652. for (int j = 0; j < barcodenum; j++)
  2653. {
  2654. barcode.Add(BaseUtil.BarcodeMethod1(pd_id, pr_id, pib_barcode));
  2655. custbarcode.Add(BarcodeMethod1(PrefixFixed, Suffix, SerialNumIndex, SerialNumLength, Radix));
  2656. pib_custoutboxcode.Add(pib_outboxcode2);
  2657. pib_inqty.Add(zxbzs);
  2658. piboutboxcode2.Add(pib_outboxcode2);
  2659. datecode.Add(DateCode);
  2660. lotno.Add(LotNo);
  2661. pdordercode.Add(订单编号 == "" ? pd_ordercode : 订单编号);
  2662. pdorderdetno.Add(pd_orderdetno);
  2663. pdpdno.Add(pd_pdno);
  2664. pdid.Add(pd_id);
  2665. prbrand.Add(品牌 == "" ? pr_brand : 品牌);
  2666. madein.Add(产地 == "" ? pr_madein : 产地);
  2667. size.Add(尺寸);
  2668. weight.Add(重量);
  2669. pdprodcode.Add(pd_prodcode);
  2670. prdetail.Add(名称 == "" ? pr_detail : 名称);
  2671. }
  2672. }
  2673. outqty -= outsumqty[pr_spec][pd_pdno];
  2674. if (outqty <= 0)
  2675. {
  2676. outqty = 0;
  2677. }
  2678. outsumqty[pr_spec][pd_pdno] -= pd_outqty;
  2679. }
  2680. }
  2681. string Lastoutbox = "";
  2682. string Lastoutboxcode = "";
  2683. List<string> custoutboxcode = new List<string>();
  2684. //根据记录的箱号,在料盘的流水之后拼接外箱的流水
  2685. for (int i = 0; i < pib_custoutboxcode.Count; i++)
  2686. {
  2687. if (Lastoutbox != pib_custoutboxcode[i].ToString())
  2688. {
  2689. Lastoutboxcode = BarcodeMethod1(PrefixFixed, Suffix, SerialNumIndex, SerialNumLength, Radix);
  2690. custoutboxcode.Add(Lastoutboxcode);
  2691. Lastoutbox = pib_custoutboxcode[i].ToString();
  2692. }
  2693. else
  2694. {
  2695. custoutboxcode.Add(Lastoutboxcode);
  2696. }
  2697. }
  2698. //插叙所有的统计数量
  2699. string ErrMsg = "";
  2700. foreach (var item in sumqty)
  2701. {
  2702. dt = (DataTable)dh.ExecuteSql("select nvl(sum(pd_outqty),0)pd_outqty,pr_spec from prodiodetail left join product on pr_code=pd_prodcode where pd_piid='" + PI_ID + "' group by pr_spec", "select");
  2703. dt1 = (DataTable)dh.ExecuteSql("select nvl(sum(pib_qty),0)pib_qty,pr_spec from prodiobarcode left join product on pib_prodcode=pr_code where pib_piid='" + PI_ID + "' group by pr_spec", "select");
  2704. DataRow[] dr = dt.Select("pr_spec='" + item.Key + "'");
  2705. DataRow[] dr1 = dt1.Select("pr_spec='" + item.Key + "'");
  2706. if (dr.Length > 0)
  2707. {
  2708. decimal pd_outqty = decimal.Parse(dr[0]["pd_outqty"].ToString());
  2709. decimal pib_qty = 0;
  2710. //如果有已导入的数量
  2711. if (dr1.Length > 0)
  2712. {
  2713. pib_qty = decimal.Parse(dr1[0]["pib_qty"].ToString());
  2714. }
  2715. //本次导入的数量和原有导入数量累加和出库数量做对比
  2716. if (pd_outqty < item.Value + pib_qty)
  2717. {
  2718. ErrMsg += "型号" + dr[0]["pr_spec"].ToString() + "出货数量" + pd_outqty + ",已导入数量" + pib_qty + ",本次导入" + item.Value + ",超出数量" + (item.Value + pib_qty - pd_outqty) + "\n";
  2719. }
  2720. }
  2721. }
  2722. if (ErrMsg == "")
  2723. {
  2724. if (pdprodcode.Count > 0)
  2725. {
  2726. sql.Clear();
  2727. sql.Append("insert into prodiobarcode (PIB_ID,PIB_PRODCODE,pib_inman,PIB_INDATE,PIB_INOUTNO,PIB_PIID,pib_brand,PIB_BARCODE,PIB_PDNO,");
  2728. sql.Append("PIB_PDID,PIB_PICLASS,PIB_QTY,pib_datecode,pib_lotno,PIB_IFPRINT,PIB_IFPICK,PIB_ORDERCODE,pib_orderdetno,");
  2729. sql.Append("pib_outboxcode2,pib_custbarcode,pib_custoutboxcode,pib_madein,pib_size,pib_weight,pib_prdetail)values(prodiobarcode_seq.nextval,:pd_prodcode,'" + User.UserName + "',sysdate,");
  2730. sql.Append("'" + pi_inoutno.Text + "'," + PI_ID + ",:pr_brand,:barcode,:pd_pdno,:pd_id,'" + pi_class.Text + "',:pib_inqty,");
  2731. sql.Append(":pib_datecode,:pib_lotno,0,-1,:pd_ordercode,:pd_orderdetno,:outboxcode,:custbarcode,:pib_custoutboxcode,:pib_madein,:pib_size,:pib_weight,:pib_prdetail)");
  2732. dh.BatchInsert(sql.ToString(), new string[] { "pd_prodcode", "pr_brand", "barcode", "pd_pdno", "pd_id", "pib_inqty", "pib_datecode", "pib_lotno", "pd_ordercode", "pd_orderdetno", "outboxcode", "custbarcode", "pib_custoutboxcode", "pib_madein", "pib_size", "pib_weight", "pib_prdetail" }, pdprodcode.ToArray(), prbrand.ToArray(), barcode.ToArray(), pdpdno.ToArray(), pdid.ToArray(), pib_inqty.ToArray(), datecode.ToArray(), lotno.ToArray(), pdordercode.ToArray(), pdorderdetno.ToArray(), piboutboxcode2.ToArray(), custbarcode.ToArray(), custoutboxcode.ToArray(), madein.ToArray(), size.ToArray(), weight.ToArray(), prdetail.ToArray());
  2733. //更新流水
  2734. dh.UpdateByCondition("RuleMaxNum", "rmn_maxnumber='" + custserialnum + "'", "rmn_nrcode='" + NrCode + "' and rmn_prefix='" + Prefix + "'");
  2735. LoadGridData();
  2736. }
  2737. else
  2738. {
  2739. MessageBox.Show("解析数据不包含出货单数据,请重新导入", "提示");
  2740. }
  2741. }
  2742. else
  2743. {
  2744. MessageBox.Show(ErrMsg, "超出数量提醒");
  2745. }
  2746. }
  2747. catch (Exception ex)
  2748. {
  2749. LogManager.DoLog(ex.StackTrace);
  2750. MessageBox.Show(ex.Message);
  2751. }
  2752. }
  2753. int rowindex = 0;
  2754. private void LabelInf_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
  2755. {
  2756. if (e.Button == MouseButtons.Right)
  2757. {
  2758. rowindex = e.RowIndex;
  2759. DateCodeSetAndPrint date = new DateCodeSetAndPrint();
  2760. date.Controls["SetValue"].Click += SetValue_ButtonClick;
  2761. date.Controls["SetValueAndPrint"].Click += SetValueAndPrint_ButtonClick;
  2762. date.ShowDialog();
  2763. }
  2764. }
  2765. private void SetValue_ButtonClick(object sender, EventArgs e)
  2766. {
  2767. Button setvalue = sender as Button;
  2768. string pdno = LabelInf.Rows[rowindex].Cells["pib_pdno"].Value.ToString();
  2769. string pr_brand = LabelInf.Rows[rowindex].Cells["pib_brand"].Value.ToString();
  2770. string datecode = setvalue.FindForm().Controls["datecode"].Text;
  2771. string lotno = setvalue.FindForm().Controls["lotno"].Text;
  2772. string nums = setvalue.FindForm().Controls["Nums"].Text;
  2773. string year = "0";
  2774. string month = "0";
  2775. string day = "0";
  2776. string date = "";
  2777. string sql = "update prodiobarcode set pib_autoset=-1,pib_ifrecheck=-1,pib_ifpick=-1,pib_ifmodify=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno;
  2778. if (datecode != "")
  2779. {
  2780. LogicHandler.GetTimeFromDatecode(datecode, pr_brand, out year, out month, out day, out date);
  2781. sql += " and (pib_datecode='' or pib_datecode is null) ";
  2782. }
  2783. if (lotno != "")
  2784. {
  2785. sql += " and (pib_lotno='' or pib_lotno is null) ";
  2786. }
  2787. if (nums == "")
  2788. {
  2789. sql += ")";
  2790. }
  2791. else
  2792. {
  2793. sql += " limit 0," + nums + ")";
  2794. }
  2795. sdh.ExecuteSql(sql, "update");
  2796. LoadGridData();
  2797. setvalue.FindForm().Close();
  2798. }
  2799. private void SetValueAndPrint_ButtonClick(object sender, EventArgs e)
  2800. {
  2801. Button setvalueandprint = sender as Button;
  2802. string pdno = LabelInf.Rows[rowindex].Cells["pib_pdno"].Value.ToString();
  2803. string pr_brand = LabelInf.Rows[rowindex].Cells["pib_brand"].Value.ToString();
  2804. string datecode = setvalueandprint.FindForm().Controls["datecode"].Text;
  2805. string lotno = setvalueandprint.FindForm().Controls["lotno"].Text;
  2806. string nums = setvalueandprint.FindForm().Controls["Nums"].Text;
  2807. string year = "0";
  2808. string month = "0";
  2809. string day = "0";
  2810. string date = "";
  2811. string sql = "update prodiobarcode set pib_autoset=-1,pib_ifrecheck=-1,pib_ifpick=-1,pib_ifmodify=-1,pib_ifprint=-1,pib_lotno='" + lotno + "',pib_datecode='" + datecode + "',pib_year='" + year + "',pib_month='" + month + "',pib_day='" + day + "' where pib_id in (select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno;
  2812. string PrintSQL = "select pib_id from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' and pib_pdno=" + pdno;
  2813. if (datecode != "")
  2814. {
  2815. LogicHandler.GetTimeFromDatecode(datecode, pr_brand, out year, out month, out day, out date);
  2816. sql += " and (pib_datecode='' or pib_datecode is null) ";
  2817. PrintSQL += " and (pib_datecode='' or pib_datecode is null) ";
  2818. }
  2819. if (lotno != "")
  2820. {
  2821. sql += " and (pib_lotno='' or pib_lotno is null) ";
  2822. PrintSQL += " and (pib_lotno='' or pib_lotno is null) ";
  2823. }
  2824. if (nums == "")
  2825. {
  2826. sql += ")";
  2827. }
  2828. else
  2829. {
  2830. sql += " limit 0," + nums + ")";
  2831. PrintSQL += " limit 0," + nums;
  2832. }
  2833. DataTable pibid_dt = (DataTable)sdh.ExecuteSql(PrintSQL, "select");
  2834. sdh.ExecuteSql(sql, "update");
  2835. for (int i = 0; i < pibid_dt.Rows.Count; i++)
  2836. {
  2837. if (PrintMethod == "CodeSoft")
  2838. Print.CodeSoft.SinglePrint(SingleDoc, SingleLabelParam, pibid_dt.Rows[i]["pib_id"].ToString());
  2839. else
  2840. Print.BarTender.SinglePrint(SingleFormat, SingleLabelParam, pibid_dt.Rows[i]["pib_id"].ToString());
  2841. }
  2842. setvalueandprint.FindForm().Close();
  2843. }
  2844. /// <summary>
  2845. /// 特殊业务逻辑
  2846. /// </summary>
  2847. /// <param name="sender"></param>
  2848. /// <param name="e"></param>
  2849. private void CustBarCode_Click(object sender, EventArgs e)
  2850. {
  2851. string SQL = "";
  2852. LogicHandler.CustBarCode(pi_inoutno.Text, out SQL);
  2853. sdh.ExecuteSql(SQL, "update");
  2854. LoadGridData();
  2855. }
  2856. }
  2857. }