UAS_出货标签管理.cs 129 KB

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