UAS_出货标签管理.cs 133 KB

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