UAS_出货标签管理.cs 141 KB

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