UAS_出货标签管理.cs 129 KB

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