UAS_出货标签管理.cs 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using System.Text.RegularExpressions;
  6. using System.Text;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Diagnostics;
  10. using LabelManager2;
  11. using UAS_LabelMachine.PublicMethod;
  12. using UAS_LabelMachine.Entity;
  13. using UAS_LabelMachine.PublicForm;
  14. using System.Threading;
  15. using System.IO;
  16. using System.Globalization;
  17. using System.Reflection;
  18. using Seagull.BarTender.Print;
  19. namespace UAS_LabelMachine
  20. {
  21. public partial class UAS_出货标签打印 : Form
  22. {
  23. //自适应屏幕
  24. AutoSizeFormClass asc = new AutoSizeFormClass();
  25. DataHelper dh;
  26. SqliteDBHelper sdh;
  27. DataTable dt;
  28. /// <summary>
  29. /// 已经打印过的Vivo外箱号
  30. /// </summary>
  31. List<string> PrintedVivoOutboxCode = new List<string>();
  32. StringBuilder sql = new StringBuilder();
  33. /// <summary>
  34. /// CodeSoft新建打印机引擎
  35. /// </summary>
  36. ApplicationClass lbl;
  37. /// <summary>
  38. /// CodeSoft单盘打印文件
  39. /// </summary>
  40. Document SingleDoc;
  41. /// <summary>
  42. /// CodeSoft中盒打印文件
  43. /// </summary>
  44. Document MidDoc;
  45. /// <summary>
  46. /// CodeSoft外箱打印文件
  47. /// </summary>
  48. Document OutBoxDoc;
  49. /// <summary>
  50. /// Loading窗口
  51. /// </summary>
  52. SetLoadingWindow stw;
  53. /// <summary>
  54. /// 弹窗线程
  55. /// </summary>
  56. Thread thread;
  57. /// <summary>
  58. /// 当前品牌
  59. /// </summary>
  60. string Brand;
  61. string PI_ID;
  62. /// <summary>
  63. /// 当前扫描的项目
  64. /// </summary>
  65. int CurrentItemIndex = 0;
  66. /// <summary>
  67. /// 当前扫描的所在行
  68. /// </summary>
  69. int CurrentRowIndex = 0;
  70. /// <summary>
  71. /// 最大的出入口单号
  72. /// </summary>
  73. int MaxOutBoxCode = 1;
  74. /// <summary>
  75. /// 正则表达式用于项目匹配
  76. /// </summary>
  77. Regex reg;
  78. /*标识供应商物料编号采集是否通过*/
  79. bool CollectVeProdCodePass = true;
  80. bool CollectQTYPass = true;
  81. bool logout = false;
  82. //每个不同序号存在的
  83. object[] ItemData;
  84. DataTable SingleLabelParam;
  85. DataTable MidLabelParam;
  86. DataTable OutLabelParam;
  87. /// <summary>
  88. /// BarTender引擎
  89. /// </summary>
  90. Engine engine;
  91. /// <summary>
  92. /// BarTender单盘
  93. /// </summary>
  94. LabelFormatDocument SingleFormat;
  95. /// <summary>
  96. /// BarTender中盒
  97. /// </summary>
  98. LabelFormatDocument MidFormat;
  99. /// <summary>
  100. /// BarTender外箱
  101. /// </summary>
  102. LabelFormatDocument OutFormat;
  103. Dictionary<string, string> CollectData;
  104. //缓存单盘数据数据的DataTable
  105. /// <summary>
  106. /// 存放单盘的ID
  107. /// </summary>
  108. List<string> SingleID = new List<string>();
  109. /// <summary>
  110. /// 单盘的打印参数
  111. /// </summary>
  112. List<string> SingleBoxArgument = new List<string>();
  113. /// <summary>
  114. /// 中盒缓存数据
  115. /// </summary>
  116. /// <summary>
  117. /// 存放中盒的ID和盒号
  118. /// </summary>
  119. Dictionary<string, string> MidIDAndOutboxcode = new Dictionary<string, string>();
  120. /// <summary>
  121. /// 中盒的打印参数
  122. /// </summary>
  123. List<string> MidBoxArgument = new List<string>();
  124. /// <summary>
  125. /// 全部采集
  126. /// </summary>
  127. bool AllCollect = false;
  128. /// <summary>
  129. /// 是否全选
  130. /// </summary>
  131. bool AllChecked = false;
  132. /// <summary>
  133. /// 是否获取过箱号
  134. /// </summary>
  135. bool GetPackingCode = false;
  136. /*用于存放采集项目的Grid信息*/
  137. Dictionary<string, Dictionary<string, string>> SiItem;
  138. int CloumnCount = 0;
  139. //使用二维数组进行排序
  140. ArrayList<ArrayList<string>> ScanData;
  141. ArrayList<string> GetData;
  142. /// <summary>
  143. /// 是否通过选择Combox来改变打开的文件
  144. /// </summary>
  145. bool ComBoxClickChangeLabelDoc = false;
  146. List<string> MidParam = new List<string>();
  147. List<string> OutParam = new List<string>();
  148. public static DataTable Attach;
  149. public string PrintMethod = "CodeSoft";
  150. public UAS_出货标签打印(string Master)
  151. {
  152. //设置窗体的双缓冲
  153. this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
  154. this.UpdateStyles();
  155. InitializeComponent();
  156. //利用反射设置DataGridView的双缓冲
  157. Type dgvType = this.LabelInf.GetType();
  158. PropertyInfo pi = dgvType.GetProperty("DoubleBuffered", BindingFlags.Instance | BindingFlags.NonPublic);
  159. pi.SetValue(this.LabelInf, true, null);
  160. Text = Text + "-" + Master;
  161. }
  162. protected override void WndProc(ref System.Windows.Forms.Message m)
  163. {
  164. //拦截双击标题栏、移动窗体的系统消息
  165. if (m.Msg != 0xA3)
  166. {
  167. base.WndProc(ref m);
  168. }
  169. }
  170. private void 贴标机条码打印_Load(object sender, EventArgs e)
  171. {
  172. //杀死之前全部未关闭的进程
  173. Process[] processes = System.Diagnostics.Process.GetProcessesByName("lppa");
  174. Process[] processes1 = System.Diagnostics.Process.GetProcessesByName("bartend");
  175. for (int i = 0; i < processes1.Length; i++)
  176. {
  177. processes1[i].Kill();
  178. }
  179. for (int i = 0; i < processes.Length; i++)
  180. {
  181. processes[i].Kill();
  182. }
  183. //用计时器重置数据库链接
  184. LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
  185. dh = SystemInf.dh;
  186. sdh = SystemInf.sdh;
  187. sdh.ExecuteZip();
  188. CheckForIllegalCrossThreadCalls = false;
  189. CloumnCount = LabelInf.Columns.Count;
  190. pi_inoutno.Focus();
  191. //将本地读取的打印机设置进Combox,并选中默认打印机
  192. sg_code.FormName = Name;
  193. sg_code.SetValueField = new string[] { "sg_code" };
  194. sg_code.SelectField = "sg_code # 策略编号 ,sg_name # 策略名称,sg_brand # 品牌,sg_separator # 分隔符";
  195. sg_code.TableName = "scangroup";
  196. sg_code.DbChange += Sg_code_DbChange;
  197. pr_code.FormName = Name;
  198. pr_code.SetValueField = new string[] { "pr_code" };
  199. pr_code.TableName = "prodiodetail left join product on pd_prodcode=pr_code";
  200. pr_code.SelectField = "pd_pdno # 行号,pr_code # 物料编号";
  201. cu_code.FormName = Name;
  202. cu_code.SetValueField = new string[] { "cu_code" };
  203. cu_code.TableName = "customer";
  204. cu_code.SelectField = "cu_code # 客户编号,cu_name # 客户名称";
  205. CollectionUnit.Text = "盘";
  206. Point pt = new Point();
  207. //禁止所有列的排序
  208. foreach (DataGridViewColumn dgv in LabelInf.Columns)
  209. {
  210. dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
  211. }
  212. int ScreenWidth = Screen.GetWorkingArea(pt).Width;
  213. //设置获取当前屏幕大小自动全屏但是保留任务栏
  214. Rectangle ScreenArea = Screen.GetWorkingArea(this);
  215. Top = 0;
  216. Left = 0;
  217. Width = ScreenArea.Width;
  218. Height = ScreenArea.Height;
  219. MidBoxCapacity.Value = Properties.Settings.Default.MidBoxCapacity;
  220. OutboxCapacity.Value = Properties.Settings.Default.OutboxCapacity;
  221. asc.controllInitializeSize(this);
  222. asc.controlAutoSize(this);
  223. string Code = dh.GetConfig("PrintMethod", "CodeOrBar").ToString();
  224. if (Code == "")
  225. {
  226. try
  227. {
  228. lbl = new ApplicationClass();
  229. }
  230. catch (Exception)
  231. {
  232. MessageBox.Show("未安装CodeSoft软件或者版本不正确");
  233. }
  234. }
  235. else
  236. {
  237. engine = new Engine(true);
  238. PrintMethod = "BarTender";
  239. }
  240. }
  241. private void Sg_code_DbChange(object sender, EventArgs e)
  242. {
  243. DataTable dt = sg_code.ReturnData;
  244. BaseUtil.SetFormValue(this.Controls, dt);
  245. }
  246. //只执行一次窗体自适应
  247. bool AutoSized = false;
  248. private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
  249. {
  250. if (!AutoSized)
  251. {
  252. asc.controlAutoSize(this);
  253. AutoSized = true;
  254. }
  255. }
  256. private void GenerateBarCode_Click(object sender, EventArgs e)
  257. {
  258. 生成条码 form = new 生成条码(pi_inoutno.Text);
  259. form.FormClosed += LoadGridData;
  260. BaseUtil.SetFormCenter(form);
  261. form.ShowDialog();
  262. }
  263. private void LabelFormClose(object sender, EventArgs e)
  264. {
  265. if (GetGridOnly.Checked)
  266. GetInOutInfAndLabelFile();
  267. else
  268. {
  269. GetInOutInfAndLabelFile();
  270. }
  271. }
  272. /// <summary>
  273. /// 保存明细
  274. /// </summary>
  275. /// <param name="sender"></param>
  276. /// <param name="e"></param>
  277. private void SaveGrid_Click(object sender, EventArgs e)
  278. {
  279. DataTable savedt = (LabelInf.DataSource as DataTable);
  280. if (savedt != null && savedt.GetChanges() != null)
  281. {
  282. dh.SaveDataTable(savedt.GetChanges(), "ProdioBarCode", "pib_id");
  283. MessageBox.Show("保存成功!");
  284. }
  285. }
  286. //放大镜选择后出发的事件
  287. private void sg_code_UserControlTextChanged(object sender, EventArgs e)
  288. {
  289. //取已启用的的按照采集次序排序
  290. 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");
  291. BaseUtil.FillDgvWithDataTable(Si_ItemDGV, dt);
  292. if (dt.Rows.Count > 0)
  293. {
  294. sg_separator.Text = dt.Rows[0]["sg_separator"].ToString();
  295. }
  296. //按DetNo排列之后的采集项
  297. ScanData = new ArrayList<ArrayList<string>>();
  298. //每个采集项目的子项
  299. GetData = new ArrayList<string>();
  300. //将数据添加进一个List的二维数组中
  301. for (int i = 0; i < Si_ItemDGV.RowCount; i++)
  302. {
  303. //如果不包含这个则添加进数组
  304. if (!GetData.Contains(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString()))
  305. {
  306. GetData.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString());
  307. }
  308. //如果和后一个的采集次序相同
  309. 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())
  310. {
  311. GetData.Add(Si_ItemDGV.Rows[i + 1].Cells["si_item"].Value.ToString());
  312. }
  313. else
  314. {
  315. ScanData.Add(GetData);
  316. //添加完一次数据需要一个新的List
  317. GetData = new ArrayList<string>();
  318. }
  319. }
  320. RemindUser();
  321. if (ScanData.ToArray().Length > 0)
  322. {
  323. object[] arr = (ScanData.ToArray()[0] as ArrayList<string>).ToArray();
  324. if (arr.Contains("MPN"))
  325. {
  326. AutoMatch.CheckState = CheckState.Checked;
  327. AutoMatch.Enabled = true;
  328. }
  329. else
  330. {
  331. AutoMatch.CheckState = CheckState.Unchecked;
  332. AutoMatch.Enabled = false;
  333. }
  334. }
  335. }
  336. //输入框Enter事件
  337. private void Input_KeyDown(object sender, KeyEventArgs e)
  338. {
  339. if (e.KeyCode == Keys.Enter)
  340. {
  341. if (Input.Text == "")
  342. {
  343. MessageBox.Show("采集的数据不能为空");
  344. return;
  345. }
  346. if (Si_ItemDGV.Rows.Count == 0)
  347. {
  348. MessageBox.Show("未维护采集策略");
  349. return;
  350. }
  351. CollectInputData();
  352. }
  353. }
  354. /// <summary>
  355. /// 设置自动匹配的数据的行号
  356. /// </summary>
  357. /// <returns></returns>
  358. private void SetAutoMatchRow()
  359. {
  360. //采集策略的第一组数据
  361. string[] arr = new string[ItemData.Length];
  362. if (sg_separator.Text == "")
  363. {
  364. for (int i = 0; i < arr.Length; i++)
  365. {
  366. arr[i] = Input.Text;
  367. }
  368. }
  369. else
  370. {
  371. arr = Input.Text.Split(sg_separator.Text.ToCharArray()).ToArray();
  372. }
  373. bool FindAutoMatch = false;
  374. for (int i = 0; i < LabelInf.RowCount; i++)
  375. {
  376. for (int j = 0; j < arr.Length; j++)
  377. {
  378. if (LabelInf.Rows[i].Cells["pr_vendprodcode"].Value.ToString() == MatchStr(arr[j].ToString(), "MPN") && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  379. {
  380. CurrentRowIndex = i;
  381. FindAutoMatch = true;
  382. break;
  383. }
  384. }
  385. if (FindAutoMatch)
  386. break;
  387. }
  388. }
  389. /// <summary>
  390. /// 采集数据
  391. /// </summary>
  392. private void CollectInputData()
  393. {
  394. LogManager.DoLog("采集数据【" + Input.Text + "】,使用采集策略编号【" + sg_code.Text + "】");
  395. //按DetNo排列之后的采集项
  396. ScanData = new ArrayList<ArrayList<string>>();
  397. //每个采集项目的子项
  398. GetData = new ArrayList<string>();
  399. //用于保存采集策略的具体信息
  400. SiItem = new Dictionary<string, Dictionary<string, string>>();
  401. for (int i = 0; i < Si_ItemDGV.RowCount; i++)
  402. {
  403. //如果不包含这个则添加进数组
  404. if (!GetData.Contains(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString()))
  405. GetData.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString());
  406. //如果和后一个的采集次序相同
  407. 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())
  408. GetData.Add(Si_ItemDGV.Rows[i + 1].Cells["si_item"].Value.ToString());
  409. else
  410. {
  411. ScanData.Add(GetData);
  412. //添加完一次数据需要一个新的List
  413. GetData = new ArrayList<string>();
  414. }
  415. Dictionary<string, string> item = new Dictionary<string, string>();
  416. for (int j = 0; j < Si_ItemDGV.ColumnCount; j++)
  417. {
  418. item.Add(Si_ItemDGV.Columns[j].DataPropertyName, Si_ItemDGV.Rows[i].Cells[j].Value.ToString());
  419. }
  420. SiItem.Add(Si_ItemDGV.Rows[i].Cells["si_item"].Value.ToString().ToUpper(), item);
  421. }
  422. //采集项目的数组
  423. ItemData = (ScanData.ToArray()[CurrentItemIndex] as ArrayList<string>).ToArray();
  424. //分隔符不为空的时候 //采集的项和Grid的数目不等
  425. //用户采集的数据的分割数组
  426. CollectData = new Dictionary<string, string>();
  427. if (sg_separator.Text == "")
  428. {
  429. for (int i = 0; i < ItemData.Length; i++)
  430. CollectData.Add(ItemData[i].ToString().ToUpper(), Input.Text);
  431. }
  432. else
  433. {
  434. int DataCount = Input.Text.Split(sg_separator.Text.ToCharArray()).Length;
  435. if (DataCount > ItemData.Length)
  436. {
  437. MessageBox.Show("采集数据大于采集项次");
  438. return;
  439. }
  440. else if (DataCount < ItemData.Length)
  441. {
  442. MessageBox.Show("采集数据小于采集项次");
  443. return;
  444. }
  445. for (int i = 0; i < DataCount; i++)
  446. CollectData.Add(ItemData[i].ToString().ToUpper(), Input.Text.Split(sg_separator.Text.ToCharArray())[i]);
  447. }
  448. //首先判断当前采集的个数,如果采集的个数为1则不对数据进行分隔符验证
  449. if (ItemData.Length == 1)
  450. {
  451. CollectData.Clear();
  452. CollectData.Add(ItemData[0].ToString().ToUpper(), Input.Text);
  453. //勾选了自动匹配调用该函数
  454. if (AutoMatch.Checked)
  455. SetAutoMatchRow();
  456. //将筛选之后的值赋给Cell
  457. SetDataToCell(ref CollectData, ItemData[0].ToString().ToUpper());
  458. }
  459. //如果本次采集的数据分割后和当前的采集项目个数不一样提示用户错误
  460. else if (CollectData.ToArray().Length == ItemData.Length)
  461. {
  462. for (int i = 0; i < ItemData.Length; i++)
  463. {
  464. //勾选了自动匹配调用该函数
  465. if (AutoMatch.Checked)
  466. SetAutoMatchRow();
  467. //将筛选之后的值赋给Cell
  468. SetDataToCell(ref CollectData, ItemData[i].ToString().ToUpper());
  469. }
  470. }
  471. else
  472. {
  473. MessageBox.Show("所采集的数据个数和采集项目不符");
  474. return;
  475. }
  476. //采集项目的索引+1
  477. CurrentItemIndex = CurrentItemIndex + 1;
  478. //如果已经采集完了最后一个
  479. if (CurrentItemIndex == ScanData.ToArray().Length)
  480. {
  481. //数据校验均已通过则勾选上已采集
  482. if (CollectVeProdCodePass && CollectQTYPass)
  483. {
  484. //如果按盒号采集,所有的此盒的均更新为
  485. DataTable dt = (DataTable)LabelInf.DataSource;
  486. StringBuilder pibid1 = new StringBuilder();
  487. if (CollectionUnit.Text == "盒")
  488. {
  489. string lotno = "";
  490. string datecode = "";
  491. for (int i = 0; i < LabelInf.RowCount; i++)
  492. {
  493. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  494. {
  495. lotno = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString();
  496. datecode = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString();
  497. string pibid = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  498. dt.Rows[i]["pib_lotno"] = lotno;
  499. dt.Rows[i]["pib_datecode"] = datecode;
  500. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  501. LabelInf.Rows[i].Cells["Choose"].Value = true;
  502. pibid1.Append(pibid + ",");
  503. LabelInf.Invalidate();
  504. //当前行的索引随循环增长
  505. CurrentRowIndex = i;
  506. if (SingleLabelAutoPrint.Checked)
  507. {
  508. AutoPrintSingleLabel(pibid);
  509. }
  510. if (MidLabelAutoPrint.Checked)
  511. AutoPrintMidLabel();
  512. SetOutBoxCode2(true);
  513. }
  514. }
  515. pibid1.Append("1");
  516. sdh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_lotno='" + lotno + "',pib_datecode='" + pib_datecode + "' where pib_id in (" + pibid1 + ")", "update");
  517. }
  518. else if (CollectionUnit.Text == "全部")
  519. {
  520. string lotno = "";
  521. string datecode = "";
  522. for (int i = 0; i < LabelInf.RowCount; i++)
  523. {
  524. lotno = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString();
  525. datecode = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString();
  526. string pibid = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  527. dt.Rows[i]["pib_lotno"] = lotno;
  528. dt.Rows[i]["pib_datecode"] = datecode;
  529. CurrentRowIndex = i;
  530. LabelInf.Refresh();
  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. SetOutBoxCode2(true);
  536. }
  537. pibid1.Append("1");
  538. sdh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_lotno='" + lotno + "',pib_datecode='" + pib_datecode + "' where pib_id in (" + pibid1 + ")", "update");
  539. }
  540. else
  541. {
  542. string lotno = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"].Value.ToString();
  543. string datecode = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"].Value.ToString();
  544. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
  545. LabelInf.Rows[CurrentRowIndex].Cells["Choose"].Value = true;
  546. sdh.ExecuteSql("update prodiobarcode set pib_ifpick=-1,pib_lotno='" + lotno + "',pib_datecode='" + pib_datecode + "' where pib_id in (" + pibid1 + ")", "update");
  547. LabelInf.Invalidate();
  548. //勾选了单盘自动打印
  549. if (SingleLabelAutoPrint.Checked)
  550. {
  551. if (SingleLabelCombox.SelectedValue != null)
  552. {
  553. AutoPrintSingleLabel(LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString());
  554. }
  555. else
  556. {
  557. MessageBox.Show("未维护单盘标签");
  558. return;
  559. }
  560. }
  561. //勾选了中盒自动打印
  562. if (MidLabelAutoPrint.Checked)
  563. AutoPrintMidLabel();
  564. }
  565. }
  566. //采集未通过的时候
  567. else
  568. {
  569. //如果自动采集采集未成功需要移动到下一行
  570. if (!AutoMatch.Checked)
  571. SetRowIndexToCollectRow();
  572. }
  573. //当前项目已采集完成,重置采集项目
  574. CurrentItemIndex = 0;
  575. //未勾选自动匹配,设置到下一个未采集的行
  576. if (!AutoMatch.Checked)
  577. SetRowIndexToCollectRow();
  578. }
  579. //提醒用户需要采集的数据
  580. RemindUser();
  581. RefreshProcessData();
  582. MessageLog.AppendText(">>扫描到数据" + Input.Text + "\n", Color.Blue);
  583. //如果所采集的行的物料不一样的话,重新计算箱内容量
  584. if (CurrentRowIndex - 1 > 0)
  585. {
  586. string LastRowProd = LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_prodcode"].Value.ToString();
  587. string CurrentRowProd = LabelInf.Rows[CurrentRowIndex].Cells["pib_prodcode"].Value.ToString();
  588. //如果两行的物料资料不相等的话
  589. if (LastRowProd != CurrentRowProd)
  590. SetOutBoxCapacity(CurrentRowProd);
  591. }
  592. if (CleanInputAfterCollect.Checked)
  593. Input.Text = "";
  594. }
  595. /// <summary>
  596. /// 根据物料资料的参数设置外箱容量
  597. /// </summary>
  598. /// <param name="pr_code"></param>
  599. private void SetOutBoxCapacity(string pr_code)
  600. {
  601. DataTable temp = (DataTable)dh.ExecuteSql("select pr_qtyperplace,pr_zxbzs from product where pr_code='" + pr_code + "'", "select");
  602. if (temp.Rows.Count > 0)
  603. {
  604. //try { OutboxCapacity.Value = (decimal)temp.Rows[0]["pr_qtyperplace"] / (decimal)temp.Rows[0]["pr_zxbzs"]; }
  605. //catch (Exception) { }
  606. }
  607. }
  608. //设置行的索引到当前需要采集的行
  609. private void SetRowIndexToCollectRow()
  610. {
  611. //获取当前需要采集的行
  612. for (int i = CurrentRowIndex; i < LabelInf.RowCount; i++)
  613. {
  614. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  615. {
  616. griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
  617. pr_code.Text = LabelInf.Rows[i].Cells["pib_prodcode"].FormattedValue.ToString();
  618. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
  619. break;
  620. }
  621. }
  622. }
  623. private void AutoPrintSingleLabel(string pib_id)
  624. {
  625. if (PrintMethod == "CodeSoft")
  626. Print.CodeSoft.SinglePrint(SingleDoc, SingleLabelParam, pib_id);
  627. else
  628. Print.BarTender.SinglePrint(SingleFormat, SingleLabelParam, pib_id);
  629. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifprint"].Value = true;
  630. }
  631. /// <summary>
  632. /// 提醒用户当前采集的项目
  633. /// </summary>
  634. private void RemindUser()
  635. {
  636. SetRowIndexToCollectRow();
  637. if (ScanData.ToArray().Length > 0)
  638. {
  639. object[] arr = (ScanData.ToArray()[CurrentItemIndex] as ArrayList<string>).ToArray();
  640. string Inf = "";
  641. for (int i = 0; i < arr.Length; i++)
  642. {
  643. Inf += arr[i] + " ";
  644. }
  645. MessageLog.AppendText(">>当前采集行" + (CurrentRowIndex + 1) + ",请采集" + Inf + "\n", Color.Green);
  646. }
  647. }
  648. /// <summary>
  649. /// 自定义函数 将匹配之后的值设置到Cell中,传递引用,每次赋值之后从List中移除已使用过的
  650. /// </summary>
  651. /// <param name="data"></param>
  652. /// <param name="kind"></param>
  653. private void SetDataToCell(ref Dictionary<string, string> setdata, string kind)
  654. {
  655. int length = setdata.Count;
  656. for (int j = 0; j < length; j++)
  657. {
  658. string[] data = new string[setdata.Count];
  659. for (int i = 0; i < length; i++)
  660. {
  661. data[i] = setdata[kind];
  662. }
  663. for (int i = 0; i < data.Length; i++)
  664. {
  665. DataGridViewCell cell = null;
  666. string Matchstr = "";
  667. switch (kind.ToString().ToUpper())
  668. {
  669. case "DATECODE":
  670. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_datecode"];
  671. Matchstr = MatchStr(data[j], "DATECODE");
  672. setdata.Remove("DATECODE");
  673. length--;
  674. break;
  675. case "LOTNO":
  676. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_lotno"];
  677. Matchstr = MatchStr(data[j], "LOTNO");
  678. setdata.Remove("LOTNO");
  679. length--;
  680. break;
  681. case "MPN":
  682. cell = LabelInf.Rows[CurrentRowIndex].Cells["pr_vendprodcode"];
  683. Matchstr = MatchStr(data[j], "MPN");
  684. //采集的供应商号不匹配的话
  685. if (cell.Value.ToString() != Matchstr)
  686. {
  687. CollectVeProdCodePass = false;
  688. //添加需要重绘的Cell
  689. LabelInf.Refresh();
  690. MessageLog.AppendText(">>供应商物料编号不匹配\n", Color.Red);
  691. }
  692. else
  693. {
  694. LabelInf.Refresh();
  695. CollectVeProdCodePass = true;
  696. }
  697. setdata.Remove("MPN");
  698. length--;
  699. break;
  700. case "QTY":
  701. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_qty"];
  702. Matchstr = MatchStr(data[j], "QTY");
  703. //如果采集的数量不相等的话
  704. if (cell.Value.ToString() != Matchstr)
  705. {
  706. CollectQTYPass = false;
  707. LabelInf.Refresh();
  708. MessageLog.AppendText(">>数量不匹配\n", Color.Red);
  709. }
  710. else
  711. {
  712. LabelInf.Refresh();
  713. CollectQTYPass = true;
  714. }
  715. setdata.Remove("QTY");
  716. length--;
  717. break;
  718. case "品牌":
  719. cell = LabelInf.Rows[CurrentRowIndex].Cells["pib_brand"];
  720. Matchstr = MatchStr(data[j], "品牌");
  721. //如果采集的数量不相等的话
  722. if (cell.Value.ToString() != Matchstr)
  723. {
  724. CollectQTYPass = false;
  725. LabelInf.Refresh();
  726. MessageLog.AppendText(">>品牌不匹配\n", Color.Red);
  727. }
  728. else
  729. {
  730. LabelInf.Refresh();
  731. CollectQTYPass = true;
  732. }
  733. setdata.Remove("品牌");
  734. length--;
  735. break;
  736. default:
  737. break;
  738. }
  739. //如果数据为空或者数据不为空的时候但是和需要采集的数据不相等的情况下进行采集
  740. //MPN和QTY只做比较不需要赋值
  741. if (cell.Value.ToString() == "" || cell.Value.ToString() != Matchstr)
  742. {
  743. string MatchResult = "";
  744. if (kind != "MPN" && kind != "QTY" && kind != "品牌")
  745. {
  746. DataTable dt = (DataTable)LabelInf.DataSource;
  747. cell.Value = Matchstr;
  748. MatchResult = "成功";
  749. }
  750. else
  751. MatchResult = "失败";
  752. switch (SiItem[kind]["si_kind"])
  753. {
  754. case "索引字符":
  755. LogManager.DoLog("采集项" + kind + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[kind]["si_kind"] + ",使用字符" + SiItem[kind]["si_indexstring"] + ",匹配后字符串" + Matchstr);
  756. break;
  757. case "起始位置":
  758. LogManager.DoLog("采集项" + kind + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[kind]["si_kind"] + ",从第" + SiItem[kind]["si_index"] + "位开始匹配,匹配后字符串" + Matchstr);
  759. break;
  760. case "二次解析":
  761. LogManager.DoLog("采集项" + kind + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[kind]["si_kind"] + ",匹配后字符串" + Matchstr);
  762. break;
  763. case "全部":
  764. LogManager.DoLog("采集项" + kind + ",匹配结果:【" + MatchResult + "】,匹配方式:" + SiItem[kind]["si_kind"] + ",匹配后字符串" + Matchstr);
  765. break;
  766. default:
  767. break;
  768. }
  769. }
  770. else
  771. LogManager.DoLog("采集项" + kind + ",匹配结果:【成功】,匹配方式:" + SiItem[kind]["si_kind"] + ",,匹配后字符串" + Matchstr);
  772. }
  773. }
  774. //添加外箱号,如果外箱号的箱内容量不为0并且已经采集完成
  775. SetOutBoxCode2(false);
  776. }
  777. //
  778. /// <summary>
  779. /// 设置外箱号
  780. /// </summary>
  781. /// <param name="BatchCollect">是否批量采集</param>
  782. private void SetOutBoxCode2(bool BatchCollect)
  783. {
  784. if (OutboxCapacity.Value != 0)
  785. {
  786. //获取当前出入口单最大的外箱号
  787. for (int i = 0; i < LabelInf.RowCount; i++)
  788. {
  789. string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  790. if (outboxcode.Contains("-"))
  791. {
  792. if (int.Parse(outboxcode.Split('-')[0] == "" ? "1" : outboxcode.Split('-')[0]) > MaxOutBoxCode)
  793. MaxOutBoxCode = int.Parse(outboxcode.Split('-')[0]);
  794. }
  795. else
  796. {
  797. if (int.Parse(outboxcode == "" ? "0" : outboxcode) > MaxOutBoxCode)
  798. MaxOutBoxCode = int.Parse(outboxcode);
  799. }
  800. }
  801. //统计最大的箱号存在多少
  802. int MaxOutBoxCodeCount = 0;
  803. for (int i = 0; i < LabelInf.RowCount; i++)
  804. {
  805. if (LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString() == MaxOutBoxCode.ToString())
  806. MaxOutBoxCodeCount = MaxOutBoxCodeCount + 1;
  807. }
  808. //如果是获取过包装单的话则不再继续追加箱号
  809. if (!GetPackingCode)
  810. {
  811. //如果箱内的盒数量小于容量,继续使用此箱号赋值,否则箱号+1
  812. if (BatchCollect)
  813. {
  814. if (MaxOutBoxCodeCount < OutboxCapacity.Value)
  815. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  816. else
  817. {
  818. MaxOutBoxCode = MaxOutBoxCode + 1;
  819. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  820. }
  821. }
  822. else
  823. {
  824. if (MaxOutBoxCodeCount <= OutboxCapacity.Value)
  825. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  826. else
  827. {
  828. MaxOutBoxCode = MaxOutBoxCode + 1;
  829. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  830. }
  831. }
  832. }
  833. }
  834. }
  835. /// <summary>
  836. /// 自定义函数 根据匹配规则
  837. /// si_item的二维数组,str是需要赋值的字符串,item表示DateCode,LotNo等
  838. /// </summary>
  839. /// <param name="SiItem"></param>
  840. /// <param name="str"></param>
  841. /// <param name="item"></param>
  842. /// <returns></returns>
  843. private string MatchStr(string str, string item)
  844. {
  845. string kind = SiItem[item]["si_kind"];
  846. //起始字符不为空的时候
  847. switch (kind)
  848. {
  849. case "起始位置":
  850. if (SiItem[item]["si_index"] != "")
  851. {
  852. try
  853. {
  854. //长度不为空的时候按照指定的长度去取数据
  855. if (SiItem[item]["si_length"] != "")
  856. str = str.Substring(int.Parse(SiItem[item]["si_index"]), int.Parse(SiItem[item]["si_length"]));
  857. //长度为空的时候取index之后的全部数据
  858. else
  859. str = str.Substring(int.Parse(SiItem[item]["si_index"]));
  860. }
  861. catch (Exception e) { LogManager.DoLog(e.StackTrace); }
  862. }
  863. break;
  864. case "索引字符":
  865. try
  866. {
  867. if (SiItem[item]["si_indexstring"] != "")
  868. {
  869. //长度不为空的时候按照指定的长度去取数据
  870. if (SiItem[item]["si_length"] != "")
  871. str = str.Substring(str.IndexOf(SiItem[item]["si_indexstring"]) + 1, int.Parse(SiItem[item]["si_length"]));
  872. //长度为空的时候取index之后的全部数据
  873. else
  874. str = str.Substring(str.IndexOf(SiItem[item]["si_indexstring"]) + 1);
  875. }
  876. }
  877. catch (Exception e) { LogManager.DoLog(e.StackTrace); }
  878. break;
  879. case "全部":
  880. break;
  881. default:
  882. break;
  883. }
  884. if (SiItem[item]["si_expression"] != "")
  885. {
  886. string log = "使用正则表达式" + SiItem[item]["si_expression"] + "匹配数据" + str;
  887. reg = new Regex(SiItem[item]["si_expression"]);
  888. try
  889. {
  890. str = reg.Matches(str)[int.Parse(SiItem[item]["si_expressionitem"].ToString()) - 1].Value;
  891. }
  892. catch (Exception)
  893. {
  894. }
  895. log += ",匹配后数据" + str;
  896. LogManager.DoLog(log);
  897. }
  898. return str;
  899. }
  900. //关闭窗口前提示用户确认
  901. private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
  902. {
  903. //如果不是注销的话
  904. if (!logout)
  905. {
  906. string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  907. if (close.ToString() != "Yes")
  908. e.Cancel = true;
  909. else
  910. {
  911. if (lbl != null)
  912. lbl.Quit();
  913. if (engine != null)
  914. engine.Dispose();
  915. LogManager.DoLog("关闭程序");
  916. }
  917. }
  918. }
  919. /// <summary>
  920. /// 获取打印标签
  921. /// </summary>
  922. private void GetInOutInfAndLabelFile()
  923. {
  924. ComBoxClickChangeLabelDoc = false;
  925. Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LabelAttachPARAMETER where lap_custcode='" + cu_code.Text + "'", "select");
  926. sql.Clear();
  927. 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') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  928. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + cu_code.Text + "' ");
  929. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='单盘' order by cl_custcode");
  930. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  931. SingleLabelCombox.DisplayMember = "cl_labelname";
  932. SingleLabelCombox.ValueMember = "la_id";
  933. SingleLabelCombox.DataSource = dt;
  934. if (SingleDoc != null)
  935. SingleDoc.Close();
  936. if (SingleFormat != null)
  937. SingleFormat.Close(SaveOptions.DoNotSaveChanges);
  938. if (!GetGridOnly.Checked)
  939. for (int i = 0; i < dt.Rows.Count; i++)
  940. {
  941. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  942. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  943. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  944. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  945. if (time.ToString() != file.LastWriteTime.ToString())
  946. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  947. }
  948. if (SingleLabelCombox.Text != "")
  949. {
  950. if (PrintMethod == "CodeSoft")
  951. {
  952. SingleDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + SingleLabelCombox.Text);
  953. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  954. }
  955. else
  956. {
  957. SingleFormat = engine.Documents.Open(ftpOperater.DownLoadTo + SingleLabelCombox.Text);
  958. SingleFormat.PrintSetup.PrinterName = SingleLabelPrinter.Text;
  959. }
  960. 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");
  961. }
  962. sql.Clear();
  963. 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') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  964. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + cu_code.Text + "' ");
  965. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='中盒' order by cl_custcode");
  966. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  967. MidLabelCombox.DisplayMember = "cl_labelname";
  968. MidLabelCombox.ValueMember = "la_id";
  969. MidLabelCombox.DataSource = dt;
  970. if (MidDoc != null)
  971. MidDoc.Close();
  972. if (MidFormat != null)
  973. MidFormat.Close(SaveOptions.DoNotSaveChanges);
  974. if (!GetGridOnly.Checked)
  975. for (int i = 0; i < dt.Rows.Count; i++)
  976. {
  977. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  978. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  979. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  980. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  981. if (time.ToString() != file.LastWriteTime.ToString())
  982. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  983. }
  984. if (MidLabelCombox.Text != "")
  985. {
  986. if (PrintMethod == "CodeSoft")
  987. {
  988. MidDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + MidLabelCombox.Text);
  989. MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
  990. }
  991. else
  992. {
  993. MidFormat = engine.Documents.Open(ftpOperater.DownLoadTo + MidLabelCombox.Text);
  994. MidFormat.PrintSetup.PrinterName = MidLabelPrinter.Text;
  995. }
  996. 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");
  997. }
  998. //缓存中盒参数
  999. sql.Clear();
  1000. 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') la_id,cl_custcode from customerlabel left join prodinout on pi_cardcode=cl_custcode ");
  1001. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + cu_code.Text + "' ");
  1002. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='外箱' order by cl_custcode");
  1003. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1004. OutBoxCombox.DisplayMember = "cl_labelname";
  1005. OutBoxCombox.ValueMember = "la_id";
  1006. OutBoxCombox.DataSource = dt;
  1007. if (OutBoxDoc != null)
  1008. OutBoxDoc.Close();
  1009. if (OutFormat != null)
  1010. OutFormat.Close(SaveOptions.DoNotSaveChanges);
  1011. if (!GetGridOnly.Checked)
  1012. for (int i = 0; i < dt.Rows.Count; i++)
  1013. {
  1014. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  1015. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  1016. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  1017. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  1018. if (time.ToString() != file.LastWriteTime.ToString())
  1019. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  1020. }
  1021. if (OutBoxCombox.Text != "")
  1022. {
  1023. if (PrintMethod == "CodeSoft")
  1024. {
  1025. OutBoxDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + OutBoxCombox.Text);
  1026. OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
  1027. }
  1028. else
  1029. {
  1030. OutFormat = engine.Documents.Open(ftpOperater.DownLoadTo + OutBoxCombox.Text);
  1031. OutFormat.PrintSetup.PrinterName = OutBoxPrinter.Text;
  1032. }
  1033. 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");
  1034. }
  1035. //缓存外箱参数
  1036. ComBoxClickChangeLabelDoc = true;
  1037. }
  1038. bool InitGetLabel = true;
  1039. /// <summary>
  1040. /// 出入库单录入框的回车事件
  1041. /// </summary>
  1042. /// <param name="sender"></param>
  1043. /// <param name="e"></param>
  1044. private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
  1045. {
  1046. if (e.KeyCode == Keys.Enter)
  1047. {
  1048. sql.Clear();
  1049. sql.Append("select pi_id,pi_cardcode,to_char(pi_date,'yyyymmdd')pi_date from prodinout where pi_inoutno='" + pi_inoutno.Text + "'");
  1050. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1051. if (dt.Rows.Count > 0)
  1052. {
  1053. InitGetLabel = true;
  1054. cu_code.Text = dt.Rows[0]["pi_cardcode"].ToString();
  1055. InitGetLabel = false;
  1056. pi_date.Text = dt.Rows[0]["pi_date"].ToString();
  1057. PI_ID = dt.Rows[0]["pi_id"].ToString();
  1058. if (dh.GetConfig("AutoBarcode", "ProdInOut!Sale").ToString() != "")
  1059. {
  1060. string[] param = new string[] { PI_ID, "" };
  1061. dh.CallProcedure("GetCustBarcode", param);
  1062. }
  1063. LoadGridData(sender, e);
  1064. //重新输入单号后清除缓存
  1065. MidBoxArgument.Clear();
  1066. SingleBoxArgument.Clear();
  1067. MidIDAndOutboxcode.Clear();
  1068. SingleID.Clear();
  1069. //刷新采集进度
  1070. RefreshProcessData();
  1071. //设置当前的最大箱号
  1072. for (int i = 0; i < LabelInf.RowCount; i++)
  1073. {
  1074. string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  1075. //如果包含有-,则需要解析
  1076. if (outboxcode.Contains("-"))
  1077. if (int.Parse(outboxcode.Split('-')[0] == "" ? "1" : outboxcode.Split('-')[0]) > MaxOutBoxCode)
  1078. MaxOutBoxCode = int.Parse(outboxcode.Split('-')[0]);
  1079. //else
  1080. //if (int.Parse(outboxcode == "" ? "1" : outboxcode) > MaxOutBoxCode)
  1081. // MaxOutBoxCode = int.Parse(outboxcode);
  1082. }
  1083. thread = new Thread(GetInOutInfAndLabelFile);
  1084. stw = new SetLoadingWindow(thread, "正在获取打印标签");
  1085. BaseUtil.SetFormCenter(stw);
  1086. stw.ShowDialog();
  1087. //重置采集项次
  1088. CurrentItemIndex = 0;
  1089. LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
  1090. }
  1091. else
  1092. MessageBox.Show("当前出入库单号不存在!");
  1093. }
  1094. }
  1095. private void SingleBoxPrint()
  1096. {
  1097. if (SingleLabelParam.Rows.Count > 0 && LabelInf.Rows.Count > 0)
  1098. {
  1099. //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
  1100. MidIDAndOutboxcode.Clear();
  1101. SingleID.Clear();
  1102. //获取全部的中盒号
  1103. Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
  1104. //判断所有盒号为该盒的是否勾选已采集
  1105. outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
  1106. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1107. {
  1108. if (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()))
  1109. SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1110. 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")
  1111. {
  1112. //如果不存在中盒号则进行添加
  1113. if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))
  1114. {
  1115. MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
  1116. }
  1117. }
  1118. }
  1119. if (SingleID.ToArray().Length == 0)
  1120. {
  1121. MessageBox.Show("选择的行未勾选采集或者已打印");
  1122. return;
  1123. }
  1124. for (int i = 0; i < LabelInf.RowCount; i++)
  1125. {
  1126. if (i + 1 < LabelInf.RowCount)
  1127. {
  1128. //如果本行的中盒号和下一行不相等的话
  1129. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString())
  1130. {
  1131. if (!outboxcode1.ContainsKey(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  1132. outboxcode1.Add(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString(), true);
  1133. }
  1134. }
  1135. //只要有一行没有采集满就不打印
  1136. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  1137. {
  1138. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1139. outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()] = false;
  1140. }
  1141. }
  1142. //用于判断用户是否勾选了行
  1143. int CheckedRowCount = 0;
  1144. string[] arg = SingleBoxArgument.ToArray();
  1145. for (int i = 0; i < LabelInf.RowCount; i++)
  1146. {
  1147. //勾选了并且未打印
  1148. 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")
  1149. {
  1150. CheckedRowCount = CheckedRowCount + 1;
  1151. CurrentRowIndex = i;
  1152. //以标签模板的参数为基准,循环取数
  1153. try
  1154. {
  1155. string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  1156. AutoPrintSingleLabel(pib_id);
  1157. if (MidLabelAutoPrint.Checked)
  1158. {
  1159. //判断当前行的盒号和下一行不相等或者已经是最后一行了
  1160. 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())
  1161. {
  1162. if (outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()])
  1163. {
  1164. if (MidLabelCombox.SelectedValue != null)
  1165. {
  1166. MidBoxCodePrint(CurrentRowIndex);
  1167. }
  1168. }
  1169. }
  1170. }
  1171. //勾选为已打印
  1172. LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
  1173. }
  1174. catch (Exception ex) { LogManager.DoLog(ex.Message); }
  1175. }
  1176. }
  1177. dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray());
  1178. if (CheckedRowCount == 0)
  1179. MessageBox.Show("未勾选打印明细!");
  1180. else if (CurrentRowIndex + 1 < LabelInf.Rows.Count)
  1181. CurrentRowIndex = CurrentRowIndex + 1;
  1182. outboxcode1.Clear();
  1183. }
  1184. else
  1185. {
  1186. MessageBox.Show("此模板尚未维护参数或不存在打印明细");
  1187. return;
  1188. }
  1189. }
  1190. private void SingleLabelPrint_Click(object sender, EventArgs e)
  1191. {
  1192. if (SingleLabelCombox.Text != "")
  1193. {
  1194. if (SingleBoxBegin.Text != "" || SingleBoxEnd.Text != "")
  1195. {
  1196. try
  1197. {
  1198. int begin = int.Parse(SingleBoxBegin.Text == "" ? "1" : SingleBoxBegin.Text);
  1199. int end = int.Parse(SingleBoxEnd.Text == "" ? LabelInf.Rows.Count.ToString() : SingleBoxEnd.Text);
  1200. if (begin > 0 && end <= LabelInf.Rows.Count && begin <= end)
  1201. {
  1202. for (int i = begin - 1; i < end; i++)
  1203. {
  1204. LabelInf.Rows[i].Cells["Choose"].Value = true;
  1205. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  1206. LabelInf.Rows[i].Cells["pib_ifprint"].Value = false;
  1207. }
  1208. }
  1209. else
  1210. {
  1211. MessageBox.Show("单盘打印范围错误");
  1212. return;
  1213. }
  1214. LabelInf.Invalidate();
  1215. }
  1216. catch (Exception)
  1217. {
  1218. MessageBox.Show("单盘打印范围错误");
  1219. return;
  1220. }
  1221. }
  1222. thread = new Thread(SingleBoxPrint);
  1223. stw = new SetLoadingWindow(thread, "正在打印单盘");
  1224. BaseUtil.SetFormCenter(stw);
  1225. stw.ShowDialog();
  1226. }
  1227. else
  1228. MessageBox.Show("未维护单盘标签");
  1229. }
  1230. private void MidBoxLabelPrint()
  1231. {
  1232. //未输入内容打印全部中盒
  1233. if (MidLabelNum.Text == "")
  1234. {
  1235. int begin = 0;
  1236. int end = 0;
  1237. if (MidBoxBegin.Text != "" || MidBoxEnd.Text != "")
  1238. {
  1239. try
  1240. {
  1241. begin = int.Parse(MidBoxBegin.Text == "" ? "1" : MidBoxBegin.Text);
  1242. end = int.Parse(MidBoxEnd.Text == "" ? LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString() : MidBoxEnd.Text);
  1243. int minmidbox = int.Parse(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString());
  1244. int maxmidbox = int.Parse(LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString());
  1245. if (begin >= minmidbox && end <= maxmidbox && begin <= end)
  1246. {
  1247. //设置中盒打印范围的行号
  1248. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1249. {
  1250. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == begin)
  1251. {
  1252. begin = i;
  1253. }
  1254. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == end)
  1255. {
  1256. end = i;
  1257. }
  1258. }
  1259. }
  1260. else
  1261. {
  1262. MessageBox.Show("中盒打印范围错误");
  1263. return;
  1264. }
  1265. }
  1266. catch (Exception)
  1267. {
  1268. MessageBox.Show("中盒打印范围错误");
  1269. return;
  1270. }
  1271. }
  1272. MidBoxArgument.Clear();
  1273. List<int> MidOutBoxCode = new List<int>();
  1274. List<int> MidOutBoxCodeIndex = new List<int>();
  1275. for (int i = (begin == 0 ? 0 : begin); i <= (end == 0 ? LabelInf.Rows.Count - 1 : end); i++)
  1276. {
  1277. if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))
  1278. MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
  1279. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  1280. {
  1281. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  1282. MidOutBoxCodeIndex.Add(i);
  1283. }
  1284. }
  1285. for (int i = 0; i < MidOutBoxCodeIndex.Count; i++)
  1286. {
  1287. MidBoxCodePrint(MidOutBoxCodeIndex[i]);
  1288. }
  1289. MidBoxArgument.Clear();
  1290. return;
  1291. }
  1292. bool FindMidLabel = false;
  1293. if (MidLabelCombox.SelectedValue != null)
  1294. {
  1295. //中盒号所在的行
  1296. int MidLabelRowIndex = 0;
  1297. //查找是否存在该中盒号
  1298. List<int> MidRowIndex = new List<int>();
  1299. //缓存中盒数据
  1300. for (int i = 0; i < LabelInf.RowCount; i++)
  1301. {
  1302. if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1303. {
  1304. //找到了输入的中盒号停止循环
  1305. FindMidLabel = true;
  1306. MidLabelRowIndex = i;
  1307. MidRowIndex.Add(i);
  1308. }
  1309. }
  1310. //找到了指定的盒号
  1311. if (FindMidLabel)
  1312. MidBoxCodePrint(MidLabelRowIndex);
  1313. else
  1314. MessageBox.Show("该出入库单未找到该中盒号!");
  1315. }
  1316. else
  1317. MessageBox.Show("未维护中盒模板");
  1318. }
  1319. private void MidLabelPrint_Click(object sender, EventArgs e)
  1320. {
  1321. if (MidLabelCombox.Text != "")
  1322. {
  1323. thread = new Thread(MidBoxLabelPrint);
  1324. stw = new SetLoadingWindow(thread, "正在打印中盒");
  1325. BaseUtil.SetFormCenter(stw);
  1326. stw.ShowDialog();
  1327. }
  1328. else
  1329. MessageBox.Show("未维护中盒标签");
  1330. }
  1331. private void OutBoxPrint()
  1332. {
  1333. List<string> Outboxcode = new List<string>();
  1334. //如果未勾选箱号则对勾选的数据的箱号进行整合
  1335. if (OutBoxNum.Text == "")
  1336. {
  1337. for (int i = 0; i < LabelInf.RowCount; i++)
  1338. {
  1339. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  1340. {
  1341. string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  1342. //富为使用包装单的逻辑
  1343. //如果不包含该箱号则进行添加
  1344. if (!Outboxcode.Contains(outboxcode2))
  1345. Outboxcode.Add(outboxcode2);
  1346. }
  1347. }
  1348. //按获取到的箱号列表进行打印
  1349. if (Outboxcode.ToArray().Length > 0)
  1350. {
  1351. try
  1352. {
  1353. // 循环打印外箱号
  1354. for (int i = 0; i < Outboxcode.ToArray().Length; i++)
  1355. {
  1356. for (int h = 0; h < LabelInf.RowCount; h++)
  1357. {
  1358. if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i])
  1359. {
  1360. OutBoxCodePrint(h);
  1361. break;
  1362. }
  1363. }
  1364. }
  1365. }
  1366. catch { }
  1367. }
  1368. else
  1369. {
  1370. MessageBox.Show("请勾选需要打印的外箱");
  1371. }
  1372. }
  1373. else
  1374. {
  1375. bool FindMidLabel = false;
  1376. try
  1377. {
  1378. int OutBoxLabelRowIndex = 0;
  1379. //查找是否存在该中盒号
  1380. for (int i = 0; i < LabelInf.RowCount; i++)
  1381. {
  1382. if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString())
  1383. {
  1384. //找到了输入的中盒号停止循环
  1385. FindMidLabel = true;
  1386. OutBoxLabelRowIndex = i;
  1387. break;
  1388. }
  1389. }
  1390. //找到了指定的盒号
  1391. if (FindMidLabel)
  1392. OutBoxCodePrint(OutBoxLabelRowIndex);
  1393. else
  1394. MessageBox.Show("该出入库单未找到该外箱号!");
  1395. }
  1396. catch (Exception) { }
  1397. }
  1398. Outboxcode.Clear();
  1399. }
  1400. private void MidBoxCodePrint(int rowindex)
  1401. {
  1402. //获取对应行的pib_id
  1403. string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
  1404. string pib_outboxcode1 = LabelInf.Rows[rowindex].Cells["pib_outboxcode1"].Value.ToString();
  1405. if (PrintMethod == "CodeSoft")
  1406. Print.CodeSoft.MidPrint(MidDoc, MidLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode1);
  1407. else
  1408. Print.BarTender.MidPrint(MidFormat, MidLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode1);
  1409. }
  1410. private void OutBoxCodePrint(int rowindex)
  1411. {
  1412. //获取对应行的pib_id
  1413. string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
  1414. string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
  1415. if (PrintMethod == "CodeSoft")
  1416. Print.CodeSoft.OutPrint(OutBoxDoc, OutLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode2);
  1417. else
  1418. Print.BarTender.OutPrint(OutFormat, OutLabelParam, pi_inoutno.Text, pib_id, pib_outboxcode2);
  1419. }
  1420. private void CleanDetail_Click(object sender, EventArgs e)
  1421. {
  1422. ArrayList<string> DeleteID = new ArrayList<string>();
  1423. StringBuilder pibid = new StringBuilder();
  1424. for (int i = 0; i < LabelInf.RowCount; i++)
  1425. {
  1426. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  1427. {
  1428. DeleteID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  1429. pibid.Append(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString() + ",");
  1430. }
  1431. }
  1432. //勾选了删除的明细之后
  1433. if (DeleteID.ToArray().Length > 0)
  1434. {
  1435. string close = MessageBox.Show(this.ParentForm, "删除后不可恢复,是否确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1436. if (close.ToString() == "Yes")
  1437. {
  1438. pibid.Append("1");
  1439. sdh.ExecuteSql("delete from prodiobarcode where pib_id in(" + pibid + ")", "delete");
  1440. dh.BatchInsert("delete from prodiobarcode where pib_id=:pib_id", new string[] { "pib_id" }, DeleteID.ToArray());
  1441. MessageBox.Show("删除成功");
  1442. LoadGridData(sender, e);
  1443. RefreshProcessData();
  1444. }
  1445. }
  1446. else
  1447. MessageBox.Show("尚未勾选需要删除的明细");
  1448. }
  1449. private void OutBoxLabelPrint_Click(object sender, EventArgs e)
  1450. {
  1451. if (OutBoxCombox.Text != "")
  1452. {
  1453. thread = new Thread(OutBoxPrint);
  1454. stw = new SetLoadingWindow(thread, "正在打印外箱");
  1455. BaseUtil.SetFormCenter(stw);
  1456. stw.ShowDialog();
  1457. }
  1458. else
  1459. MessageBox.Show("未维护外箱标签");
  1460. }
  1461. /// <summary>
  1462. /// 刷新采集进度
  1463. /// </summary>
  1464. private void RefreshProcessData()
  1465. {
  1466. if (LabelInf.Rows.Count > 0)
  1467. {
  1468. //设置初始化的采集进度
  1469. int Count = 0;
  1470. int CurrentMidBoxCollectedCount = 0;
  1471. //当前盒号的总盘数
  1472. int CurrentMidBoxTotalCount = 0;
  1473. //未超出当前范围的时候
  1474. for (int i = 0; i < LabelInf.RowCount; i++)
  1475. {
  1476. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
  1477. Count++;
  1478. //和当前编辑箱号相等行
  1479. 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())
  1480. CurrentMidBoxCollectedCount++;
  1481. //当前盒号一共有几盘
  1482. if (LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1483. CurrentMidBoxTotalCount++;
  1484. }
  1485. Capacity.Text = "可装" + CurrentMidBoxTotalCount + "盘";
  1486. Installed.Text = "已装" + CurrentMidBoxCollectedCount + "盘";
  1487. //设置当前的箱号和盒号
  1488. Process_outboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value.ToString();
  1489. Process_midboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  1490. //设置当前总数和已采集数量
  1491. TotalCount.Text = LabelInf.RowCount.ToString();
  1492. CollectedCount.Text = Count.ToString();
  1493. }
  1494. }
  1495. private void LoadGridData()
  1496. {
  1497. LoadGridData(new object(), new EventArgs());
  1498. }
  1499. DataTable LabelInfDataTable;
  1500. /// <summary>
  1501. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  1502. /// </summary>
  1503. /// <param name="sender"></param>
  1504. /// <param name="e"></param>
  1505. private void LoadGridData(object sender, EventArgs e)
  1506. {
  1507. AllCollect = false;
  1508. //查询Oracle数据库
  1509. sql.Clear();
  1510. sql.Append("select t.*,rownum from prodiobarcode_view t where pib_inoutno='" + pi_inoutno.Text + "'");
  1511. LabelInfDataTable = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1512. //查询本地数据库
  1513. sql.Clear();
  1514. sql.Append("select * from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' limit 0,1 ");
  1515. DataTable dt = (DataTable)sdh.ExecuteSql(sql.ToString(), "select");
  1516. //如果本地没有缓存过
  1517. if (dt.Rows.Count == 0)
  1518. {
  1519. //检验查询的字段和本地数据库字段是否匹配
  1520. sdh.AddColumFromDataTable(LabelInfDataTable, "prodiobarcode");
  1521. //将数据保存在本地数据库
  1522. sdh.SaveDataTable(LabelInfDataTable, "prodiobarcode");
  1523. }
  1524. else if (LabelInfDataTable.Columns.Count != dt.Columns.Count)
  1525. {
  1526. //检验查询的字段和本地数据库字段是否匹配
  1527. sdh.AddColumFromDataTable(LabelInfDataTable, "prodiobarcode");
  1528. sdh.BatchInsert("prodiobarcode", LabelInfDataTable);
  1529. }
  1530. sql.Clear();
  1531. sql.Append("select * from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "' order by rownum ");
  1532. LabelInfDataTable = (DataTable)sdh.ExecuteSql(sql.ToString(), "select");
  1533. bindingsource(LabelInf, LabelInfDataTable);
  1534. BaseUtil.FillDgvWithDataTable(LabelInf, LabelInfDataTable);
  1535. //有数据的话默认取第一条的品牌去取采集策略
  1536. TotalCount.Text = LabelInf.RowCount.ToString();
  1537. if (LabelInf.RowCount > 0)
  1538. {
  1539. Brand = LabelInf.Rows[0].Cells["pib_brand"].FormattedValue.ToString();
  1540. if (Brand != "")
  1541. sg_code.Text = dh.getFieldDataByCondition("scangroup", "sg_code", "sg_brand='" + Brand + "'").ToString();
  1542. SetOutBoxCapacity(LabelInf.Rows[0].Cells["pib_prodcode"].Value.ToString());
  1543. }
  1544. //绑定数据之后往下找到未采集的数据显示在当前采集的栏目
  1545. for (int i = 0; i < LabelInf.RowCount; i++)
  1546. {
  1547. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1548. {
  1549. griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
  1550. pr_code.Text = LabelInf.Rows[i].Cells["pib_prodcode"].FormattedValue.ToString();
  1551. pib_id.Text = LabelInf.Rows[i].Cells["pib_id1"].FormattedValue.ToString();
  1552. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
  1553. break;
  1554. }
  1555. }
  1556. }
  1557. delegate void BindDataSource(DataGridView dgv, DataTable dt);//定义委托
  1558. void bindingsource(DataGridView dgv, DataTable dt)
  1559. {
  1560. if (dgv.InvokeRequired)
  1561. {
  1562. dgv.Invoke(new BindDataSource(bindingsource), new object[] { dgv, dt });
  1563. }
  1564. else
  1565. {
  1566. dgv.AutoGenerateColumns = false;
  1567. dgv.DataSource = dt;
  1568. }
  1569. }
  1570. /// <summary>
  1571. /// 重绘Cell的颜色
  1572. /// </summary>
  1573. /// <param name="sender"></param>
  1574. /// <param name="e"></param>
  1575. private void LabelInf_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  1576. {
  1577. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  1578. if (e.ColumnIndex > 0)
  1579. {
  1580. 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 == "pib_brand")
  1581. {
  1582. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1583. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  1584. Rectangle border = e.CellBounds;
  1585. border.Width -= 1;
  1586. e.Graphics.DrawRectangle(Pens.White, border);
  1587. e.PaintContent(e.CellBounds);
  1588. e.Handled = true;
  1589. }
  1590. if (e.RowIndex >= 0)
  1591. {
  1592. if (LabelInf.Rows[e.RowIndex].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
  1593. {
  1594. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_lotno" || LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
  1595. {
  1596. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1597. e.Graphics.FillRectangle(Brushes.ForestGreen, e.CellBounds);
  1598. Rectangle border = e.CellBounds;
  1599. border.Width -= 1;
  1600. e.Graphics.DrawRectangle(Pens.Black, border);
  1601. e.PaintContent(e.CellBounds);
  1602. e.Handled = true;
  1603. }
  1604. }
  1605. }
  1606. }
  1607. }
  1608. private void pr_code_SearchIconClick(object sender, EventArgs e)
  1609. {
  1610. pr_code.Condition = " pd_inoutno='" + pi_inoutno.Text + "'";
  1611. }
  1612. private void pr_code_UserControlTextChanged(object sender, EventArgs e)
  1613. {
  1614. //用户在重新勾选后重置采集项目的索引
  1615. CurrentItemIndex = 0;
  1616. for (int i = 0; i < LabelInf.RowCount; i++)
  1617. {
  1618. if (pr_code.Text == LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1619. {
  1620. CurrentRowIndex = i;
  1621. break;
  1622. }
  1623. }
  1624. }
  1625. private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1626. {
  1627. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  1628. pi_inoutno_KeyDown(sender, e2);
  1629. }
  1630. /// <summary>
  1631. /// 采集明细切换
  1632. /// </summary>
  1633. /// <param name="sender"></param>
  1634. /// <param name="e"></param>
  1635. private void griddetno_KeyDown(object sender, KeyEventArgs e)
  1636. {
  1637. if (Keys.Enter == e.KeyData)
  1638. {
  1639. bool FindDetno = false;
  1640. for (int i = 0; i < LabelInf.RowCount; i++)
  1641. {
  1642. if (LabelInf.Rows[i].Cells["pib_pdno"].Value.ToString() == griddetno.Text && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1643. {
  1644. FindDetno = true;
  1645. CurrentItemIndex = 0;
  1646. CurrentRowIndex = i;
  1647. RemindUser();
  1648. break;
  1649. }
  1650. }
  1651. if (!FindDetno)
  1652. {
  1653. MessageBox.Show("不存在未采集的明细序号" + griddetno.Text);
  1654. return;
  1655. }
  1656. }
  1657. }
  1658. private void AutoPrintMidLabel()
  1659. {
  1660. bool FullBox = true;
  1661. //判断所有盒号未该盒的是否勾选已采集
  1662. for (int i = 0; i < LabelInf.RowCount; i++)
  1663. {
  1664. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  1665. {
  1666. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1667. FullBox = false;
  1668. }
  1669. }
  1670. //如果当前箱号已经装满了
  1671. if (FullBox)
  1672. {
  1673. if (MidLabelCombox.SelectedValue != null)
  1674. {
  1675. MidBoxCodePrint(CurrentRowIndex);
  1676. }
  1677. else
  1678. MessageBox.Show("未维护中盒模板");
  1679. }
  1680. }
  1681. /// <summary>
  1682. /// 勾选的时候自动打印
  1683. /// </summary>
  1684. /// <param name="sender"></param>
  1685. /// <param name="e"></param>
  1686. private void LabelInf_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  1687. {
  1688. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
  1689. {
  1690. string datecode = LabelInf.Rows[e.RowIndex].Cells["pib_datecode"].Value.ToString();
  1691. try
  1692. {
  1693. System.DateTime dt = System.DateTime.ParseExact(datecode, "yyyyMMdd", CultureInfo.CurrentCulture);
  1694. GregorianCalendar gc = new GregorianCalendar();
  1695. int weekOfYear = gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
  1696. if (weekOfYear < 10)
  1697. LabelInf.Rows[e.RowIndex].Cells["pib_datecode1"].Value = dt.Year.ToString().Substring(2, 2) + "0" + weekOfYear;
  1698. else
  1699. LabelInf.Rows[e.RowIndex].Cells["pib_datecode1"].Value = dt.Year.ToString().Substring(2, 2) + weekOfYear;
  1700. }
  1701. catch (Exception) { }
  1702. }
  1703. }
  1704. private void AllCollected_Click(object sender, EventArgs e)
  1705. {
  1706. if (AllCollect == false)
  1707. {
  1708. foreach (DataGridViewRow dr in LabelInf.Rows)
  1709. dr.Cells[1].Value = true;
  1710. AllCollect = true;
  1711. }
  1712. else
  1713. {
  1714. foreach (DataGridViewRow dr in LabelInf.Rows)
  1715. dr.Cells[1].Value = false;
  1716. AllCollect = false;
  1717. }
  1718. }
  1719. private void GetOutBoxCode_Click(object sender, EventArgs e)
  1720. {
  1721. if (dh.GetConfig("UsingPacking", "ProdInOut!Sale").ToString() != "")
  1722. {
  1723. int Current = 0;
  1724. sql.Clear();
  1725. 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 ");
  1726. 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");
  1727. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1728. if (dt.Rows.Count > 0)
  1729. {
  1730. try { OutboxCapacity.Value = (decimal)dt.Rows[0]["pr_qtyperplace"] / (decimal)dt.Rows[0]["pr_zxbzs"]; }
  1731. catch (Exception) { }
  1732. }
  1733. try
  1734. {
  1735. for (int i = 0; i < dt.Rows.Count; i++)
  1736. {
  1737. int pd_qty = int.Parse(dt.Rows[i]["pd_qty"].ToString());
  1738. int pr_zxbzs = int.Parse(dt.Rows[i]["pr_zxbzs"].ToString());
  1739. int pd_cartons = int.Parse(dt.Rows[i]["pd_cartons"].ToString());
  1740. for (int j = 0; j < pd_qty * pd_cartons / pr_zxbzs; j++)
  1741. {
  1742. LabelInf.Rows[Current].Cells["pib_outboxcode2"].Value = dt.Rows[i]["pd_cartonno"].ToString();
  1743. Current++;
  1744. }
  1745. }
  1746. GetPackingCode = true;
  1747. }
  1748. catch (Exception)
  1749. {
  1750. }
  1751. }
  1752. else
  1753. {
  1754. int BoxCode = 1;
  1755. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1756. {
  1757. LabelInf.Rows[i].Cells["pib_outboxcode2"].Value = BoxCode;
  1758. if (i + 1 < LabelInf.Rows.Count)
  1759. {
  1760. 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()))
  1761. {
  1762. BoxCode = BoxCode + 1;
  1763. }
  1764. else if (LabelInf.Rows[i].Cells["pib_prodcode"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_prodcode"].Value.ToString())
  1765. {
  1766. BoxCode = BoxCode + 1;
  1767. }
  1768. }
  1769. }
  1770. sdh.BatchInsert("prodiobarcode", LabelInf.DataSource as DataTable);
  1771. }
  1772. SaveGrid_Click(sender, e);
  1773. }
  1774. private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1775. {
  1776. string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1777. if (close.ToString() == "Yes")
  1778. {
  1779. Login login = new Login();
  1780. //注销的时候需要将拼接的连接字符串置空
  1781. DataHelper.DBConnectionString = null;
  1782. logout = true;
  1783. if (lbl != null)
  1784. lbl.Quit();
  1785. if (engine != null)
  1786. engine.Dispose();
  1787. this.Hide();
  1788. login.ShowDialog();
  1789. this.Close();
  1790. }
  1791. }
  1792. private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1793. /// <summary>
  1794. /// 切换打开的单盘文件
  1795. /// </summary>
  1796. /// <param name="sender"></param>
  1797. /// <param name="e"></param>
  1798. private void SingleLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1799. {
  1800. try
  1801. {
  1802. if (ComBoxClickChangeLabelDoc)
  1803. {
  1804. if (SingleDoc != null)
  1805. SingleDoc.Close();
  1806. if (SingleFormat != null)
  1807. SingleFormat.Close(SaveOptions.DoNotSaveChanges);
  1808. System.DateTime time = Convert.ToDateTime(SingleLabelCombox.SelectedValue.ToString().Split('#')[2]);
  1809. if (SingleLabelCombox.Text != "" && SingleLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  1810. {
  1811. if (PrintMethod == "CodeSoft")
  1812. SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
  1813. else
  1814. SingleFormat = engine.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
  1815. }
  1816. }
  1817. }
  1818. catch (Exception) { }
  1819. }
  1820. /// <summary>
  1821. /// 切换打开的中盒文件
  1822. /// </summary>
  1823. /// <param name="sender"></param>
  1824. /// <param name="e"></param>
  1825. private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1826. {
  1827. try
  1828. {
  1829. if (ComBoxClickChangeLabelDoc)
  1830. {
  1831. if (MidDoc != null)
  1832. MidDoc.Close();
  1833. if (MidFormat != null)
  1834. MidFormat.Close(SaveOptions.DoNotSaveChanges);
  1835. if (MidLabelCombox.Text != "" && MidLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  1836. {
  1837. System.DateTime time = Convert.ToDateTime(MidLabelCombox.SelectedValue.ToString().Split('#')[2]);
  1838. if (PrintMethod == "CodeSoft")
  1839. MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
  1840. else
  1841. MidFormat = engine.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
  1842. }
  1843. }
  1844. }
  1845. catch (Exception) { }
  1846. }
  1847. /// <summary>
  1848. /// 切换打开的外箱文件
  1849. /// </summary>
  1850. /// <param name="sender"></param>
  1851. /// <param name="e"></param>
  1852. private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e)
  1853. {
  1854. try
  1855. {
  1856. if (ComBoxClickChangeLabelDoc)
  1857. {
  1858. if (OutBoxDoc != null)
  1859. OutBoxDoc.Close();
  1860. if (OutFormat != null)
  1861. OutFormat.Close(SaveOptions.DoNotSaveChanges);
  1862. System.DateTime time = Convert.ToDateTime(OutBoxCombox.SelectedValue.ToString().Split('#')[2]);
  1863. if (OutBoxCombox.Text != "" && OutBoxCombox.SelectedValue != null && !GetGridOnly.Checked)
  1864. {
  1865. if (PrintMethod == "CodeSoft")
  1866. OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
  1867. else
  1868. OutFormat = engine.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
  1869. }
  1870. }
  1871. }
  1872. catch (Exception) { }
  1873. }
  1874. private void ChooseAll_Click(object sender, EventArgs e)
  1875. {
  1876. if (AllChecked)
  1877. {
  1878. foreach (DataGridViewRow dr in LabelInf.Rows)
  1879. dr.Cells[0].Value = false;
  1880. AllChecked = false;
  1881. }
  1882. else
  1883. {
  1884. foreach (DataGridViewRow dr in LabelInf.Rows)
  1885. dr.Cells[0].Value = true;
  1886. AllChecked = true;
  1887. }
  1888. }
  1889. private void LabelInf_CellEndEdit(object sender, DataGridViewCellEventArgs e)
  1890. {
  1891. StringBuilder pibid = new StringBuilder();
  1892. string madein = LabelInf.Rows[e.RowIndex].Cells["pib_madein"].Value.ToString();
  1893. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_madein" && CollectionUnit.Text == "盒")
  1894. {
  1895. string midbox = LabelInf.Rows[e.RowIndex].Cells["pib_outboxcode1"].Value.ToString();
  1896. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1897. {
  1898. if (midbox == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1899. {
  1900. LabelInf.Rows[i].Cells["pib_madein"].Value = madein;
  1901. pibid.Append(LabelInf.Rows[i].Cells["pib_id1"].Value + ",");
  1902. }
  1903. }
  1904. }
  1905. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_madein" && CollectionUnit.Text == "全部")
  1906. {
  1907. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1908. {
  1909. LabelInf.Rows[i].Cells["pib_madein"].Value = madein;
  1910. pibid.Append(LabelInf.Rows[i].Cells["pib_id1"].Value + ",");
  1911. }
  1912. }
  1913. pibid.Append("1");
  1914. sdh.ExecuteSql("update prodiobarcode set pib_madein='" + madein + "' where pib_id in (" + pibid + ")", "update");
  1915. }
  1916. private void ExportData_Click(object sender, EventArgs e)
  1917. {
  1918. }
  1919. private void MidBoxCapacity_Leave(object sender, EventArgs e)
  1920. {
  1921. NumericUpDown nup = (NumericUpDown)sender;
  1922. switch (nup.Name)
  1923. {
  1924. case "MidBoxCapacity":
  1925. Properties.Settings.Default.MidBoxCapacity = nup.Value;
  1926. Properties.Settings.Default.Save();
  1927. break;
  1928. case "OutboxCapacity":
  1929. Properties.Settings.Default.OutboxCapacity = nup.Value;
  1930. Properties.Settings.Default.Save();
  1931. break;
  1932. default:
  1933. break;
  1934. }
  1935. }
  1936. private void CleanBarCode_Click(object sender, EventArgs e)
  1937. {
  1938. string close = MessageBox.Show(this.ParentForm, "是否清除该出货单条码", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1939. if (close.ToString() == "Yes")
  1940. {
  1941. sdh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  1942. dh.ExecuteSql("delete from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "delete");
  1943. LoadGridData(sender, e);
  1944. }
  1945. }
  1946. private void LabelPrinter_UserOnSelectIndexChange(object sender, EventArgs e)
  1947. {
  1948. switch ((sender as Control).Parent.Name)
  1949. {
  1950. case "SingleLabelPrinter":
  1951. if (PrintMethod == "CodeSoft")
  1952. {
  1953. if (SingleDoc != null)
  1954. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  1955. }
  1956. else
  1957. {
  1958. if (SingleFormat != null)
  1959. SingleFormat.PrintSetup.PrinterName = SingleLabelPrinter.Text;
  1960. }
  1961. break;
  1962. case "MidLabelPrinter":
  1963. if (PrintMethod == "CodeSoft")
  1964. {
  1965. if (MidDoc != null)
  1966. MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
  1967. }
  1968. else
  1969. {
  1970. if (MidFormat != null)
  1971. MidFormat.PrintSetup.PrinterName = MidLabelPrinter.Text;
  1972. }
  1973. break;
  1974. case "OutBoxPrinter":
  1975. if (PrintMethod == "CodeSoft")
  1976. {
  1977. if (OutBoxDoc != null)
  1978. OutBoxDoc.Printer.SwitchTo(OutBoxLabelPrint.Text);
  1979. }
  1980. else
  1981. {
  1982. if (OutFormat != null)
  1983. OutFormat.PrintSetup.PrinterName = OutBoxPrinter.Text;
  1984. }
  1985. break;
  1986. default:
  1987. break;
  1988. }
  1989. }
  1990. private void DocRefresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1991. {
  1992. switch ((sender as Control).Name)
  1993. {
  1994. case "SingleDocRefresh":
  1995. if (SingleDoc != null)
  1996. SingleDoc.Close();
  1997. if (SingleLabelCombox.Text != "" && SingleLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  1998. {
  1999. System.DateTime time = Convert.ToDateTime(SingleLabelCombox.SelectedValue.ToString().Split('#')[2]);
  2000. SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
  2001. }
  2002. break;
  2003. case "MidDocRefresh":
  2004. if (MidDoc != null)
  2005. MidDoc.Close();
  2006. if (MidLabelCombox.Text != "" && MidLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  2007. {
  2008. System.DateTime time = Convert.ToDateTime(MidLabelCombox.SelectedValue.ToString().Split('#')[2]);
  2009. MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
  2010. }
  2011. break;
  2012. case "OutDocRefresh":
  2013. if (OutBoxDoc != null)
  2014. OutBoxDoc.Close();
  2015. if (OutBoxCombox.Text != "" && OutBoxCombox.SelectedValue != null && !GetGridOnly.Checked)
  2016. {
  2017. System.DateTime time = Convert.ToDateTime(OutBoxCombox.SelectedValue.ToString().Split('#')[2]);
  2018. OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
  2019. }
  2020. break;
  2021. default:
  2022. break;
  2023. }
  2024. }
  2025. private void cu_code_UserControlTextChanged(object sender, EventArgs e)
  2026. {
  2027. if (!InitGetLabel)
  2028. GetInOutInfAndLabelFile();
  2029. }
  2030. private void MenuSetting_Click(object sender, EventArgs e)
  2031. {
  2032. Menu.Show(new Point(MenuSetting.Location.X, MenuSetting.Location.Y + 20));
  2033. }
  2034. private void Menu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  2035. {
  2036. switch (e.ClickedItem.Text)
  2037. {
  2038. case "采集策略设置":
  2039. 采集策略 form = new 采集策略(sg_code.Text);
  2040. form.FormClosed += sg_code_UserControlTextChanged;
  2041. BaseUtil.SetFormCenter(form);
  2042. form.ShowDialog();
  2043. break;
  2044. case "附件信息设置":
  2045. if (cu_code.Text != "")
  2046. {
  2047. 附件内容打印 att = new 附件内容打印(cu_code.Text);
  2048. att.ShowDialog();
  2049. }
  2050. else MessageBox.Show("请先获取出库单信息");
  2051. break;
  2052. case "标签维护":
  2053. 客户标签维护 form1 = new 客户标签维护();
  2054. BaseUtil.SetFormCenter(form1);
  2055. if (SingleDoc != null)
  2056. SingleDoc.Close();
  2057. if (MidDoc != null)
  2058. MidDoc.Close();
  2059. if (OutBoxDoc != null)
  2060. OutBoxDoc.Close();
  2061. if (SingleFormat != null)
  2062. SingleFormat.Close(SaveOptions.DoNotSaveChanges);
  2063. if (MidFormat != null)
  2064. MidFormat.Close(SaveOptions.DoNotSaveChanges);
  2065. if (OutFormat != null)
  2066. OutFormat.Close(SaveOptions.DoNotSaveChanges);
  2067. form1.FormClosed += LabelFormClose;
  2068. form1.ShowDialog();
  2069. break;
  2070. case "导出数据":
  2071. ExportFileDialog.Description = "选择导出的路径";
  2072. DialogResult result = ExportFileDialog.ShowDialog();
  2073. if (result == DialogResult.OK)
  2074. {
  2075. ExcelHandler eh = new ExcelHandler();
  2076. DataTable dt = ((DataTable)LabelInf.DataSource).Copy();
  2077. for (int i = dt.Columns.Count - 1; i >= 0; i--)
  2078. {
  2079. for (int j = 0; j < LabelInf.Columns.Count; j++)
  2080. {
  2081. //去除ID列
  2082. 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")
  2083. {
  2084. dt.Columns.RemoveAt(i);
  2085. break;
  2086. }
  2087. switch (dt.Columns[i].ColumnName.ToLower())
  2088. {
  2089. case "pib_lotno":
  2090. dt.Columns[i].ColumnName = "批次号";
  2091. break;
  2092. case "pib_datecode":
  2093. dt.Columns[i].ColumnName = "生产日期";
  2094. break;
  2095. case "pib_custbarcode":
  2096. dt.Columns[i].ColumnName = "最小产品包装条码";
  2097. break;
  2098. default:
  2099. break;
  2100. }
  2101. if (dt.Columns[i].ColumnName.ToLower() == LabelInf.Columns[j].DataPropertyName.ToLower())
  2102. {
  2103. dt.Columns[i].ColumnName = LabelInf.Columns[j].HeaderText;
  2104. break;
  2105. }
  2106. }
  2107. }
  2108. eh.ExportExcel(dt, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text);
  2109. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  2110. if (close.ToString() == "Yes")
  2111. System.Diagnostics.Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + ".xls");
  2112. }
  2113. break;
  2114. case "权限设置":
  2115. PowerSetting pw = new PowerSetting();
  2116. BaseUtil.SetFormCenter(pw);
  2117. pw.ShowDialog();
  2118. break;
  2119. default:
  2120. break;
  2121. }
  2122. }
  2123. }
  2124. }