UAS_出货标签管理.cs 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587
  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_特殊解析规则;
  14. using UAS_LabelMachine.PublicForm;
  15. using System.Threading;
  16. using System.IO;
  17. using System.Globalization;
  18. using System.IO.Ports;
  19. using UAS_LabelMachine.CustomControl;
  20. namespace UAS_LabelMachine
  21. {
  22. public partial class UAS_出货标签打印 : Form
  23. {
  24. //自适应屏幕
  25. AutoSizeFormClass asc = new AutoSizeFormClass();
  26. DataHelper dh;
  27. AccessDBHelper adh;
  28. DataTable dt;
  29. StringBuilder sql = new StringBuilder();
  30. /// <summary>
  31. /// CodeSoft新建打印机引擎
  32. /// </summary>
  33. ApplicationClass lbl;
  34. /// <summary>
  35. /// 单盘打印文件
  36. /// </summary>
  37. Document SingleDoc;
  38. /// <summary>
  39. /// 中盒打印文件
  40. /// </summary>
  41. Document MidDoc;
  42. /// <summary>
  43. /// 外箱打印文件
  44. /// </summary>
  45. Document OutBoxDoc;
  46. /// <summary>
  47. /// Loading窗口
  48. /// </summary>
  49. SetLoadingWindow stw;
  50. /// <summary>
  51. /// 弹窗线程
  52. /// </summary>
  53. Thread thread;
  54. /// <summary>
  55. /// 当前品牌
  56. /// </summary>
  57. string Brand;
  58. string PI_ID;
  59. /// <summary>
  60. /// 当前扫描的所在行
  61. /// </summary>
  62. int CurrentRowIndex = 0;
  63. /// <summary>
  64. /// 最大的出入口单号
  65. /// </summary>
  66. int MaxOutBoxCode = 1;
  67. /// <summary>
  68. /// 正则表达式用于项目匹配
  69. /// </summary>
  70. Regex reg;
  71. /*标识供应商物料编号采集是否通过*/
  72. bool CollectVeProdCodePass = true;
  73. bool CollectQTYPass = true;
  74. bool logout = false;
  75. DataTable SingleLabelParam;
  76. DataTable MidLabelParam;
  77. DataTable OutLabelParam;
  78. /// <summary>
  79. /// 存放单盘的ID
  80. /// </summary>
  81. List<string> SingleID = new List<string>();
  82. /// <summary>
  83. /// 单盘的打印参数
  84. /// </summary>
  85. List<string> SingleBoxArgument = new List<string>();
  86. /// <summary>
  87. /// 存放中盒的ID和盒号
  88. /// </summary>
  89. Dictionary<string, string> MidIDAndOutboxcode = new Dictionary<string, string>();
  90. /// <summary>
  91. /// 中盒的打印参数
  92. /// </summary>
  93. List<string> MidBoxArgument = new List<string>();
  94. /// <summary>
  95. /// 全部采集
  96. /// </summary>
  97. bool AllCollect = false;
  98. /// <summary>
  99. /// 是否全选
  100. /// </summary>
  101. bool AllChecked = false;
  102. /// <summary>
  103. /// 默认采集了指定的数据上传
  104. /// </summary>
  105. int UploadNum = 100;
  106. /// <summary>
  107. /// 是否获取过箱号
  108. /// </summary>
  109. bool GetPackingCode = false;
  110. string SG_Script;
  111. Dictionary<int, string> Si_Item = new Dictionary<int, string>();
  112. /*需要重绘的Cell*/
  113. Dictionary<DataGridViewCell, bool> PaintCell = new Dictionary<DataGridViewCell, bool>();
  114. /// <summary>
  115. /// 是否通过选择Combox来改变打开的文件
  116. /// </summary>
  117. bool ComBoxClickChangeLabelDoc = false;
  118. DataTable Attach;
  119. public UAS_出货标签打印(string Master)
  120. {
  121. InitializeComponent();
  122. Text = Text + "-" + Master;
  123. }
  124. protected override void WndProc(ref Message m)
  125. {
  126. //拦截双击标题栏、移动窗体的系统消息
  127. if (m.Msg != 0xA3)
  128. {
  129. base.WndProc(ref m);
  130. }
  131. }
  132. private void 贴标机条码打印_Load(object sender, EventArgs e)
  133. {
  134. //杀死之前全部未关闭的进程
  135. Process[] processes = System.Diagnostics.Process.GetProcessesByName("lppa");
  136. for (int i = 0; i < processes.Length; i++)
  137. {
  138. processes[i].Kill();
  139. }
  140. //用计时器重置数据库链接
  141. LogManager.DoLog("程序启动,登陆人员【" + User.UserName + "】");
  142. dh = SystemInf.dh;
  143. adh = SystemInf.adh;
  144. CheckForIllegalCrossThreadCalls = false;
  145. pi_inoutno.Focus();
  146. sg_code.FormName = Name;
  147. sg_code.SetValueField = new string[] { "sg_code" };
  148. sg_code.SelectField = "sg_code # 策略编号 ,sg_name # 策略名称,sg_brand # 品牌,sg_separator # 分隔符";
  149. sg_code.TableName = "scangroup";
  150. sg_code.DbChange += Sg_code_DbChange;
  151. Point pt = new Point();
  152. //禁止所有列的排序
  153. foreach (DataGridViewColumn dgv in LabelInf.Columns)
  154. {
  155. dgv.SortMode = DataGridViewColumnSortMode.NotSortable;
  156. }
  157. int ScreenWidth = Screen.GetWorkingArea(pt).Width;
  158. //设置获取当前屏幕大小自动全屏但是保留任务栏
  159. Rectangle ScreenArea = Screen.GetWorkingArea(this);
  160. Top = 0;
  161. Left = 0;
  162. Width = ScreenArea.Width;
  163. Height = ScreenArea.Height;
  164. MidBoxCapacity.Value = Properties.Settings.Default.MidBoxCapacity;
  165. OutboxCapacity.Value = Properties.Settings.Default.OutboxCapacity;
  166. asc.controllInitializeSize(this);
  167. asc.controlAutoSize(this);
  168. //实例化打印进程
  169. try
  170. {
  171. lbl = new ApplicationClass();
  172. }
  173. catch (Exception)
  174. {
  175. MessageBox.Show("未安装CodeSoft软件或者版本不正确");
  176. }
  177. RefreshDBConnect.Interval = 60000;
  178. RefreshDBConnect.Start();
  179. DataTable dt = (DataTable)adh.ExecuteSql("select * from cominfo", "select");
  180. DataRow[] dr = dt.Select("comtype='FrontendCheck'");
  181. if (dr.Length > 0)
  182. {
  183. FrontendCheck.PortName = dr[0]["COM"].ToString();
  184. FrontendCheck.Tag = "FrontendCheck";
  185. FrontendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
  186. FrontendCheck.DataReceived += Serial_DataReceived;
  187. FrontendCheck.Open();
  188. }
  189. dr = dt.Select("comtype='BackendCheck'");
  190. if (dr.Length > 0)
  191. {
  192. BackendCheck.PortName = dr[0]["COM"].ToString();
  193. BackendCheck.Tag = "BackendCheck";
  194. BackendCheck.BaudRate = int.Parse(dr[0]["BaudRate"].ToString());
  195. BackendCheck.DataReceived += Serial_DataReceived;
  196. BackendCheck.Open();
  197. }
  198. }
  199. //获取串口数据
  200. private void Serial_DataReceived(object sender, SerialDataReceivedEventArgs e)
  201. {
  202. try
  203. {
  204. SerialPortWithTag port = sender as SerialPortWithTag;
  205. int len = port.BytesToRead;
  206. byte[] readBuffer = new byte[len];
  207. port.Read(readBuffer, 0, len); //将数据读入缓存
  208. string msg = Encoding.ASCII.GetString(readBuffer, 0, len); //获取出入库产品编号
  209. string LotNo = "";
  210. string DateCode = "";
  211. string Order = "";
  212. string QTY = "";
  213. string PN = "";
  214. string OutBox = "";
  215. string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
  216. switch (port.Tag)
  217. {
  218. case "FrontendCheck":
  219. FrontCollect.Text = msg;
  220. MatchCollection matchs = reg.Matches(msg);
  221. int index = 0;
  222. foreach (var item in Si_Item)
  223. {
  224. switch (item.Value)
  225. {
  226. case "DateCode":
  227. DateCode = matchs[index].Value;
  228. break;
  229. case "LotNo":
  230. LotNo = matchs[index].Value;
  231. break;
  232. case "PN":
  233. PN = matchs[index].Value;
  234. break;
  235. case "Order":
  236. Order = matchs[index].Value;
  237. break;
  238. case "QTY":
  239. QTY = matchs[index].Value;
  240. break;
  241. case "OutBox":
  242. OutBox = matchs[index].Value;
  243. break;
  244. default:
  245. break;
  246. }
  247. index = index + 1;
  248. }
  249. adh.ExecuteSql("update prodiobarcode set pib_lotno='" + LotNo + "',pib_datecode='" + DateCode + "' where pib_id=" + pib_id, "update");
  250. break;
  251. case "BackendCheck":
  252. BackCheck.Text = msg;
  253. break;
  254. default:
  255. break;
  256. }
  257. }
  258. catch (Exception ex)
  259. {
  260. MessageBox.Show("接收返回消息异常!具体原因:" + ex.Message, "提示信息");
  261. }
  262. }
  263. private void Sg_code_DbChange(object sender, EventArgs e)
  264. {
  265. DataTable dt = sg_code.ReturnData;
  266. BaseUtil.SetFormValue(this.Controls, dt);
  267. }
  268. //只执行一次窗体自适应
  269. bool AutoSized = false;
  270. private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
  271. {
  272. if (!AutoSized)
  273. {
  274. asc.controlAutoSize(this);
  275. AutoSized = true;
  276. }
  277. }
  278. private void LabelMaintain_Click(object sender, EventArgs e)
  279. {
  280. 客户标签维护 form = new 客户标签维护();
  281. BaseUtil.SetFormCenter(form);
  282. if (SingleDoc != null)
  283. SingleDoc.Close();
  284. if (MidDoc != null)
  285. MidDoc.Close();
  286. if (OutBoxDoc != null)
  287. OutBoxDoc.Close();
  288. form.FormClosed += LabelFormClose;
  289. form.ShowDialog();
  290. }
  291. private void LabelFormClose(object sender, EventArgs e)
  292. {
  293. if (GetGridOnly.Checked)
  294. GetInOutInfAndLabelFile();
  295. else
  296. {
  297. GetGridOnly.Checked = true;
  298. GetInOutInfAndLabelFile();
  299. GetGridOnly.Checked = false;
  300. }
  301. }
  302. //输入框Enter事件
  303. private void Input_KeyDown(object sender, KeyEventArgs e)
  304. {
  305. if (e.KeyCode == Keys.Enter)
  306. {
  307. if (BackCheck.Text == "")
  308. {
  309. MessageBox.Show("采集的数据不能为空");
  310. return;
  311. }
  312. if (Si_ItemDGV.Rows.Count == 0)
  313. {
  314. MessageBox.Show("未维护采集策略");
  315. return;
  316. }
  317. CollectInputData();
  318. }
  319. }
  320. /// <summary>
  321. /// 采集数据
  322. /// </summary>
  323. private void CollectInputData()
  324. {
  325. LogManager.DoLog("采集数据【" + BackCheck.Text + "】,使用采集策略编号【" + sg_code.Text + "】");
  326. {
  327. //数据校验均已通过则勾选上已采集
  328. if (CollectVeProdCodePass && CollectQTYPass)
  329. {
  330. //如果按盒号采集,所有的此盒的均更新为
  331. DataTable dt = (DataTable)MidSource.DataSource;
  332. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifpick"].Value = true;
  333. LogicHandler.UpdateRowPicked(LabelInf.Rows[CurrentRowIndex].Cells["pib_id"].Value);
  334. LabelInf.Rows[CurrentRowIndex].Cells["Choose"].Value = true;
  335. //勾选了单盘自动打印
  336. if (SingleLabelAutoPrint.Checked)
  337. {
  338. if (SingleLabelCombox.SelectedValue != null)
  339. {
  340. AutoPrintSingleLabel();
  341. }
  342. else
  343. {
  344. MessageBox.Show("未维护单盘标签");
  345. return;
  346. }
  347. }
  348. //勾选了中盒自动打印
  349. if (MidLabelAutoPrint.Checked)
  350. AutoPrintMidLabel();
  351. }
  352. //采集未通过的时候
  353. else
  354. {
  355. //如果自动采集采集未成功需要移动到下一行
  356. if (!AutoMatch.Checked)
  357. SetRowIndexToCollectRow();
  358. }
  359. //未勾选自动匹配,设置到下一个未采集的行
  360. if (!AutoMatch.Checked)
  361. SetRowIndexToCollectRow();
  362. }
  363. //提醒用户需要采集的数据
  364. RemindUser();
  365. RefreshProcessData();
  366. MessageLog.AppendText(">>扫描到数据" + BackCheck.Text + "\n", Color.Blue);
  367. //如果所采集的行的物料不一样的话,重新计算箱内容量
  368. if (CurrentRowIndex - 1 > 0)
  369. {
  370. string LastRowProd = LabelInf.Rows[CurrentRowIndex - 1].Cells["pib_prodcode"].Value.ToString();
  371. string CurrentRowProd = LabelInf.Rows[CurrentRowIndex].Cells["pib_prodcode"].Value.ToString();
  372. }
  373. }
  374. //设置行的索引到当前需要采集的行
  375. private void SetRowIndexToCollectRow()
  376. {
  377. //获取当前需要采集的行
  378. for (int i = CurrentRowIndex; i < LabelInf.RowCount; i++)
  379. {
  380. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  381. {
  382. griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
  383. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
  384. break;
  385. }
  386. }
  387. }
  388. private void AutoPrintSingleLabel()
  389. {
  390. //用标签本身的变量作为最外层的循环条件去匹配;
  391. string pib_id = LabelInf.Rows[CurrentRowIndex].Cells["pib_id1"].Value.ToString();
  392. StringBuilder ParamLog = new StringBuilder();
  393. sql.Clear();
  394. sql.Append("select * from ");
  395. for (int i = 0; i < SingleLabelParam.Rows.Count; i++)
  396. {
  397. if (i != SingleLabelParam.Rows.Count - 1)
  398. sql.Append("(" + SingleLabelParam.Rows[i]["lp_sql"].ToString() + "),");
  399. else
  400. sql.Append("(" + SingleLabelParam.Rows[i]["lp_sql"].ToString() + ")");
  401. }
  402. DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString().ToLower().Replace("{pib_id}", pib_id), "select");
  403. for (int i = 0; i < SingleDoc.Variables.FreeVariables.Count; i++)
  404. {
  405. if (dt.Columns.Contains(SingleDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower()))
  406. SingleDoc.Variables.FreeVariables.Item(i + 1).Value = dt.Rows[0][SingleDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower()].ToString();
  407. if (SingleDoc.Variables.FreeVariables.Item(i + 1).Value == "")
  408. {
  409. DataRow[] dr1 = Attach.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower() + "'");
  410. if (dr1.Length > 0)
  411. SingleDoc.Variables.FreeVariables.Item(i + 1).Value = dr1[0]["lp_sql"].ToString();
  412. }
  413. }
  414. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  415. SingleDoc.PrintDocument();
  416. LogicHandler.UpdateRowPrinted(pib_id);
  417. LabelInf.Rows[CurrentRowIndex].Cells["pib_ifprint"].Value = true;
  418. }
  419. /// <summary>
  420. /// 提醒用户当前采集的项目
  421. /// </summary>
  422. private void RemindUser()
  423. {
  424. SetRowIndexToCollectRow();
  425. }
  426. //
  427. /// <summary>
  428. /// 设置外箱号
  429. /// </summary>
  430. /// <param name="BatchCollect">是否批量采集</param>
  431. private void SetOutBoxCode2(bool BatchCollect)
  432. {
  433. if (OutboxCapacity.Value != 0)
  434. {
  435. //获取当前出入口单最大的外箱号
  436. for (int i = 0; i < LabelInf.RowCount; i++)
  437. {
  438. string outboxcode = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  439. if (outboxcode.Contains("-"))
  440. {
  441. if (int.Parse(outboxcode.Split('-')[0] == "" ? "1" : outboxcode.Split('-')[0]) > MaxOutBoxCode)
  442. MaxOutBoxCode = int.Parse(outboxcode.Split('-')[0]);
  443. }
  444. else
  445. {
  446. if (int.Parse(outboxcode == "" ? "0" : outboxcode) > MaxOutBoxCode)
  447. MaxOutBoxCode = int.Parse(outboxcode);
  448. }
  449. }
  450. //统计最大的箱号存在多少
  451. int MaxOutBoxCodeCount = 0;
  452. for (int i = 0; i < LabelInf.RowCount; i++)
  453. {
  454. if (LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString() == MaxOutBoxCode.ToString())
  455. MaxOutBoxCodeCount = MaxOutBoxCodeCount + 1;
  456. }
  457. //如果是获取过包装单的话则不再继续追加箱号
  458. if (!GetPackingCode)
  459. {
  460. //如果箱内的盒数量小于容量,继续使用此箱号赋值,否则箱号+1
  461. if (BatchCollect)
  462. {
  463. if (MaxOutBoxCodeCount < OutboxCapacity.Value)
  464. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  465. else
  466. {
  467. MaxOutBoxCode = MaxOutBoxCode + 1;
  468. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  469. }
  470. }
  471. else
  472. {
  473. if (MaxOutBoxCodeCount <= OutboxCapacity.Value)
  474. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  475. else
  476. {
  477. MaxOutBoxCode = MaxOutBoxCode + 1;
  478. LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value = MaxOutBoxCode;
  479. }
  480. }
  481. }
  482. }
  483. }
  484. //关闭窗口前提示用户确认
  485. private void 贴标机条码打印_FormClosing(object sender, FormClosingEventArgs e)
  486. {
  487. //如果不是注销的话
  488. if (!logout)
  489. {
  490. string close = MessageBox.Show(this.ParentForm, "是否关闭", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  491. if (close.ToString() != "Yes")
  492. e.Cancel = true;
  493. else
  494. {
  495. lbl.Quit();
  496. LogManager.DoLog("关闭程序");
  497. }
  498. }
  499. }
  500. /// <summary>
  501. /// 获取打印标签
  502. /// </summary>
  503. private void GetInOutInfAndLabelFile()
  504. {
  505. ComBoxClickChangeLabelDoc = false;
  506. Attach = (DataTable)dh.ExecuteSql("select lap_param lp_name,lap_value lp_sql from LabelAttachPARAMETER where lap_custcode='" + pi_cardcode.Text + "'", "select");
  507. sql.Clear();
  508. 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 ");
  509. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  510. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='单盘' order by cl_custcode");
  511. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  512. SingleLabelCombox.DisplayMember = "cl_labelname";
  513. SingleLabelCombox.ValueMember = "la_id";
  514. SingleLabelCombox.DataSource = dt;
  515. if (SingleDoc != null)
  516. SingleDoc.Close();
  517. if (!GetGridOnly.Checked)
  518. for (int i = 0; i < dt.Rows.Count; i++)
  519. {
  520. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  521. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  522. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  523. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  524. if (time.ToString() != file.LastWriteTime.ToString())
  525. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  526. }
  527. if (SingleLabelCombox.Text != "")
  528. {
  529. SingleDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + SingleLabelCombox.Text);
  530. SingleLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + SingleLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
  531. }
  532. sql.Clear();
  533. 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 ");
  534. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  535. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='中盒' order by cl_custcode");
  536. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  537. MidLabelCombox.DisplayMember = "cl_labelname";
  538. MidLabelCombox.ValueMember = "la_id";
  539. MidLabelCombox.DataSource = dt;
  540. if (MidDoc != null)
  541. MidDoc.Close();
  542. if (!GetGridOnly.Checked)
  543. for (int i = 0; i < dt.Rows.Count; i++)
  544. {
  545. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  546. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  547. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  548. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  549. if (time.ToString() != file.LastWriteTime.ToString())
  550. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  551. }
  552. if (MidLabelCombox.Text != "")
  553. {
  554. MidDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + MidLabelCombox.Text);
  555. MidLabelParam = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id= lp_laid where la_id=" + MidLabelCombox.SelectedValue.ToString().Split('#')[0], "select");
  556. }
  557. //缓存中盒参数
  558. sql.Clear();
  559. 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 ");
  560. sql.Append("left join customer on cu_code=cl_custcode left join label on la_code=CL_LABELCODE where ((pi_cardcode='" + pi_cardcode.Text + "' ");
  561. sql.Append("and pi_inoutno='" + pi_inoutno.Text + "') or( cl_custcode is null)) and cl_labeltype='外箱' order by cl_custcode");
  562. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  563. OutBoxCombox.DisplayMember = "cl_labelname";
  564. OutBoxCombox.ValueMember = "la_id";
  565. OutBoxCombox.DataSource = dt;
  566. if (OutBoxDoc != null)
  567. OutBoxDoc.Close();
  568. if (!GetGridOnly.Checked)
  569. for (int i = 0; i < dt.Rows.Count; i++)
  570. {
  571. string LabelUrl = dt.Rows[i]["la_id"].ToString().Split('#')[1];
  572. string LabelName = dt.Rows[i]["cl_labelname"].ToString();
  573. System.DateTime time = Convert.ToDateTime(dt.Rows[i]["cl_date"].ToString());
  574. FileInfo file = new FileInfo(ftpOperater.DownLoadTo + LabelName);
  575. if (time.ToString() != file.LastWriteTime.ToString())
  576. BaseUtil.GetLabelUrl(LabelUrl, LabelName, time);
  577. }
  578. if (OutBoxCombox.Text != "")
  579. {
  580. OutBoxDoc = lbl.Documents.Open(ftpOperater.DownLoadTo + OutBoxCombox.Text);
  581. 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");
  582. }
  583. //缓存外箱参数
  584. ComBoxClickChangeLabelDoc = true;
  585. }
  586. /// <summary>
  587. /// 出入库单录入框的回车事件
  588. /// </summary>
  589. /// <param name="sender"></param>
  590. /// <param name="e"></param>
  591. private void pi_inoutno_KeyDown(object sender, KeyEventArgs e)
  592. {
  593. if (e.KeyCode == Keys.Enter)
  594. {
  595. sql.Clear();
  596. sql.Append("select pi_id,pi_cardcode,to_char(pi_date,'yyyymmdd')pi_date from prodinout where pi_inoutno='" + pi_inoutno.Text + "'");
  597. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  598. if (dt.Rows.Count > 0)
  599. {
  600. pi_cardcode.Text = dt.Rows[0]["pi_cardcode"].ToString();
  601. pi_date.Text = dt.Rows[0]["pi_date"].ToString();
  602. PI_ID = dt.Rows[0]["pi_id"].ToString();
  603. if (dh.GetConfig("AutoBarcode", "ProdInOut!Sale").ToString() != "")
  604. {
  605. string[] param = new string[] { PI_ID, "", "" };
  606. dh.CallProcedure("GetCustBarcode", param);
  607. }
  608. LoadGridData(sender, e);
  609. //重新输入单号后清除缓存
  610. MidBoxArgument.Clear();
  611. SingleBoxArgument.Clear();
  612. MidIDAndOutboxcode.Clear();
  613. SingleID.Clear();
  614. //刷新采集进度
  615. RefreshProcessData();
  616. thread = new Thread(GetInOutInfAndLabelFile);
  617. stw = new SetLoadingWindow(thread, "正在获取打印标签");
  618. BaseUtil.SetFormCenter(stw);
  619. stw.ShowDialog();
  620. LogManager.DoLog("输入单号【" + pi_inoutno.Text + "】");
  621. }
  622. else
  623. MessageBox.Show("当前出入库单号不存在!");
  624. }
  625. }
  626. private void SingleBoxPrint()
  627. {
  628. try
  629. {
  630. if (SingleDoc.Variables.FreeVariables.Count == 0) { }
  631. }
  632. catch (Exception)
  633. {
  634. MessageBox.Show("单盘标签未维护参数");
  635. }
  636. if (MidLabelAutoPrint.Checked)
  637. {
  638. try
  639. {
  640. if (MidDoc.Variables.FreeVariables.Count == 0) { }
  641. }
  642. catch (Exception)
  643. {
  644. MessageBox.Show("中盘标签未维护参数");
  645. }
  646. }
  647. if (SingleLabelParam.Rows.Count > 0 && LabelInf.Rows.Count > 0)
  648. {
  649. //每次打印清除之前缓存的行号和ID,后面会判断需要打印的数据重新加载
  650. MidIDAndOutboxcode.Clear();
  651. SingleID.Clear();
  652. //获取全部的中盒号
  653. Dictionary<string, bool> outboxcode1 = new Dictionary<string, bool>();
  654. //判断所有盒号为该盒的是否勾选已采集
  655. outboxcode1.Add(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString(), true);
  656. for (int i = 0; i < LabelInf.Rows.Count; i++)
  657. {
  658. if (!SingleID.Contains(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString()))
  659. SingleID.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString());
  660. 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")
  661. {
  662. //如果不存在中盒号则进行添加
  663. if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))
  664. {
  665. MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
  666. }
  667. }
  668. }
  669. if (SingleID.ToArray().Length == 0)
  670. {
  671. MessageBox.Show("选择的行未勾选采集或者已打印");
  672. return;
  673. }
  674. for (int i = 0; i < LabelInf.RowCount; i++)
  675. {
  676. if (i + 1 < LabelInf.RowCount)
  677. {
  678. //如果本行的中盒号和下一行不相等的话
  679. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() != LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString())
  680. {
  681. if (!outboxcode1.ContainsKey(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString()))
  682. outboxcode1.Add(LabelInf.Rows[i + 1].Cells["pib_outboxcode1"].Value.ToString(), true);
  683. }
  684. }
  685. //只要有一行没有采集满就不打印
  686. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  687. {
  688. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  689. outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()] = false;
  690. }
  691. }
  692. //用于判断用户是否勾选了行
  693. int CheckedRowCount = 0;
  694. for (int i = 0; i < LabelInf.RowCount; i++)
  695. {
  696. //勾选了并且未打印
  697. 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")
  698. {
  699. CheckedRowCount = CheckedRowCount + 1;
  700. CurrentRowIndex = i;
  701. //以标签模板的参数为基准,循环取数
  702. try
  703. {
  704. string pib_id = LabelInf.Rows[i].Cells["pib_id1"].Value.ToString();
  705. sql.Clear();
  706. sql.Append("select * from ");
  707. for (int j = 0; j < SingleLabelParam.Rows.Count; j++)
  708. {
  709. if (j != SingleLabelParam.Rows.Count - 1)
  710. sql.Append("(" + SingleLabelParam.Rows[j]["lp_sql"].ToString() + "),");
  711. else
  712. sql.Append("(" + SingleLabelParam.Rows[j]["lp_sql"].ToString() + ")");
  713. }
  714. DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString().ToLower().Replace("{pib_id}", pib_id), "select");
  715. for (int j = 0; j < SingleDoc.Variables.FreeVariables.Count; j++)
  716. {
  717. if (dt.Columns.Contains(SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower()))
  718. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dt.Rows[0][SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower()].ToString();
  719. if (SingleDoc.Variables.FreeVariables.Item(j + 1).Value == "")
  720. {
  721. DataRow[] dr1 = Attach.Select("lp_name='" + SingleDoc.Variables.FreeVariables.Item(j + 1).Name.ToLower() + "'");
  722. if (dr1.Length > 0)
  723. SingleDoc.Variables.FreeVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
  724. }
  725. }
  726. SingleDoc.Printer.SwitchTo(SingleLabelPrinter.Text);
  727. SingleDoc.PrintDocument();
  728. LogicHandler.UpdateRowPrinted(pib_id);
  729. if (MidLabelAutoPrint.Checked)
  730. {
  731. //判断当前行的盒号和下一行不相等或者已经是最后一行了
  732. 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())
  733. {
  734. if (outboxcode1[LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()])
  735. {
  736. if (MidLabelCombox.SelectedValue != null)
  737. {
  738. MidBoxCodePrint(CurrentRowIndex);
  739. }
  740. }
  741. }
  742. }
  743. //勾选为已打印
  744. LabelInf.Rows[i].Cells["pib_ifprint"].Value = true;
  745. }
  746. catch (Exception ex) { LogManager.DoLog(ex.Message); }
  747. }
  748. }
  749. dh.BatchInsert("update prodiobarcode set pib_printdate=sysdate where pib_id=:pib_id", new string[] { "pib_id" }, SingleID.ToArray());
  750. if (CheckedRowCount == 0)
  751. MessageBox.Show("未勾选打印明细!");
  752. else if (CurrentRowIndex + 1 < LabelInf.Rows.Count)
  753. CurrentRowIndex = CurrentRowIndex + 1;
  754. outboxcode1.Clear();
  755. }
  756. else
  757. {
  758. MessageBox.Show("此模板尚未维护参数或不存在打印明细");
  759. return;
  760. }
  761. }
  762. private void SingleLabelPrint_Click(object sender, EventArgs e)
  763. {
  764. if (SingleLabelCombox.Text != "")
  765. {
  766. if (SingleBoxBegin.Text != "" || SingleBoxEnd.Text != "")
  767. {
  768. try
  769. {
  770. int begin = int.Parse(SingleBoxBegin.Text == "" ? "1" : SingleBoxBegin.Text);
  771. int end = int.Parse(SingleBoxEnd.Text == "" ? LabelInf.Rows.Count.ToString() : SingleBoxEnd.Text);
  772. if (begin > 0 && end <= LabelInf.Rows.Count && begin <= end)
  773. {
  774. for (int i = begin - 1; i < end; i++)
  775. {
  776. LabelInf.Rows[i].Cells["Choose"].Value = true;
  777. LabelInf.Rows[i].Cells["pib_ifpick"].Value = true;
  778. LabelInf.Rows[i].Cells["pib_ifprint"].Value = false;
  779. }
  780. }
  781. else
  782. {
  783. MessageBox.Show("单盘打印范围错误");
  784. return;
  785. }
  786. }
  787. catch (Exception)
  788. {
  789. MessageBox.Show("单盘打印范围错误");
  790. return;
  791. }
  792. }
  793. thread = new Thread(SingleBoxPrint);
  794. stw = new SetLoadingWindow(thread, "正在打印单盘");
  795. BaseUtil.SetFormCenter(stw);
  796. stw.ShowDialog();
  797. }
  798. else
  799. MessageBox.Show("未维护单盘标签");
  800. }
  801. private void MidBoxLabelPrint()
  802. {
  803. //未输入内容打印全部中盒
  804. if (MidLabelNum.Text == "")
  805. {
  806. int begin = 0;
  807. int end = 0;
  808. if (MidBoxBegin.Text != "" || MidBoxEnd.Text != "")
  809. {
  810. try
  811. {
  812. begin = int.Parse(MidBoxBegin.Text == "" ? "1" : MidBoxBegin.Text);
  813. end = int.Parse(MidBoxEnd.Text == "" ? LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString() : MidBoxEnd.Text);
  814. int minmidbox = int.Parse(LabelInf.Rows[0].Cells["pib_outboxcode1"].Value.ToString());
  815. int maxmidbox = int.Parse(LabelInf.Rows[LabelInf.Rows.Count - 1].Cells["pib_outboxcode1"].Value.ToString());
  816. if (begin >= minmidbox && end <= maxmidbox && begin <= end)
  817. {
  818. //设置中盒打印范围的行号
  819. for (int i = 0; i < LabelInf.Rows.Count; i++)
  820. {
  821. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == begin)
  822. {
  823. begin = i;
  824. }
  825. if (int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()) == end)
  826. {
  827. end = i;
  828. }
  829. }
  830. }
  831. else
  832. {
  833. MessageBox.Show("中盒打印范围错误");
  834. return;
  835. }
  836. }
  837. catch (Exception)
  838. {
  839. MessageBox.Show("中盒打印范围错误");
  840. return;
  841. }
  842. }
  843. MidBoxArgument.Clear();
  844. List<int> MidOutBoxCode = new List<int>();
  845. List<int> MidOutBoxCodeIndex = new List<int>();
  846. string la_id = MidLabelCombox.SelectedValue.ToString().Split('#')[0];
  847. for (int i = (begin == 0 ? 0 : begin); i <= (end == 0 ? LabelInf.Rows.Count - 1 : end); i++)
  848. {
  849. if (!MidIDAndOutboxcode.ContainsValue(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()))
  850. MidIDAndOutboxcode.Add(LabelInf.Rows[i].Cells["pib_id1"].Value.ToString(), LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString());
  851. if (!MidOutBoxCode.Contains(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())))
  852. {
  853. MidOutBoxCode.Add(int.Parse(LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString()));
  854. MidOutBoxCodeIndex.Add(i);
  855. }
  856. }
  857. for (int i = 0; i < MidOutBoxCodeIndex.Count; i++)
  858. {
  859. MidBoxCodePrint(MidOutBoxCodeIndex[i]);
  860. }
  861. MidBoxArgument.Clear();
  862. return;
  863. }
  864. bool FindMidLabel = false;
  865. if (MidLabelCombox.SelectedValue != null)
  866. {
  867. //中盒号所在的行
  868. int MidLabelRowIndex = 0;
  869. //缓存中盒数据
  870. for (int i = 0; i < LabelInf.RowCount; i++)
  871. {
  872. if (MidLabelNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  873. {
  874. //找到了输入的中盒号停止循环
  875. FindMidLabel = true;
  876. MidLabelRowIndex = i;
  877. }
  878. }
  879. //找到了指定的盒号
  880. if (FindMidLabel)
  881. MidBoxCodePrint(MidLabelRowIndex);
  882. else
  883. MessageBox.Show("该出入库单未找到该中盒号!");
  884. }
  885. else
  886. MessageBox.Show("未维护中盒模板");
  887. }
  888. private void MidLabelPrint_Click(object sender, EventArgs e)
  889. {
  890. if (MidLabelCombox.Text != "")
  891. {
  892. thread = new Thread(MidBoxLabelPrint);
  893. stw = new SetLoadingWindow(thread, "正在打印中盒");
  894. BaseUtil.SetFormCenter(stw);
  895. stw.ShowDialog();
  896. }
  897. else
  898. MessageBox.Show("未维护中盒标签");
  899. }
  900. private void OutBoxPrint()
  901. {
  902. List<string> Outboxcode = new List<string>();
  903. //如果未勾选箱号则对勾选的数据的箱号进行整合
  904. if (OutBoxNum.Text == "")
  905. {
  906. for (int i = 0; i < LabelInf.RowCount; i++)
  907. {
  908. if (LabelInf.Rows[i].Cells["Choose"].FormattedValue.ToString() == "True")
  909. {
  910. string outboxcode2 = LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString();
  911. //富为使用包装单的逻辑
  912. //如果不包含该箱号则进行添加
  913. if (!Outboxcode.Contains(outboxcode2))
  914. Outboxcode.Add(outboxcode2);
  915. }
  916. }
  917. //按获取到的箱号列表进行打印
  918. if (Outboxcode.ToArray().Length > 0)
  919. {
  920. try
  921. {
  922. // 循环打印外箱号
  923. for (int i = 0; i < Outboxcode.ToArray().Length; i++)
  924. {
  925. for (int h = 0; h < LabelInf.RowCount; h++)
  926. {
  927. if (LabelInf.Rows[h].Cells["pib_outboxcode2"].Value.ToString() == Outboxcode.ToArray()[i])
  928. {
  929. OutBoxCodePrint(h);
  930. break;
  931. }
  932. }
  933. }
  934. }
  935. catch { }
  936. }
  937. else
  938. {
  939. MessageBox.Show("请勾选需要打印的外箱");
  940. }
  941. }
  942. else
  943. {
  944. bool FindMidLabel = false;
  945. try
  946. {
  947. int OutBoxLabelRowIndex = 0;
  948. //查找是否存在该中盒号
  949. for (int i = 0; i < LabelInf.RowCount; i++)
  950. {
  951. if (OutBoxNum.Text == LabelInf.Rows[i].Cells["pib_outboxcode2"].Value.ToString())
  952. {
  953. //找到了输入的中盒号停止循环
  954. FindMidLabel = true;
  955. OutBoxLabelRowIndex = i;
  956. break;
  957. }
  958. }
  959. //找到了指定的盒号
  960. if (FindMidLabel)
  961. OutBoxCodePrint(OutBoxLabelRowIndex);
  962. else
  963. MessageBox.Show("该出入库单未找到该外箱号!");
  964. }
  965. catch (Exception) { }
  966. }
  967. Outboxcode.Clear();
  968. }
  969. private void MidBoxCodePrint(int rowindex)
  970. {
  971. //获取对应行的pib_id
  972. string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
  973. string pib_outboxcode1 = LabelInf.Rows[rowindex].Cells["pib_outboxcode1"].Value.ToString();
  974. sql.Clear();
  975. sql.Append("select * from ");
  976. for (int i = 0; i < MidLabelParam.Rows.Count; i++)
  977. {
  978. if (i != MidLabelParam.Rows.Count - 1)
  979. sql.Append("(" + MidLabelParam.Rows[i]["lp_sql"].ToString() + "),");
  980. else
  981. sql.Append("(" + MidLabelParam.Rows[i]["lp_sql"].ToString() + ")");
  982. }
  983. DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString().ToLower().Replace("{pib_id}", pib_id).Replace("{pib_outboxcode1}", pib_outboxcode1), "select");
  984. for (int i = 0; i < MidDoc.Variables.FreeVariables.Count; i++)
  985. {
  986. if (dt.Columns.Contains(MidDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower()))
  987. MidDoc.Variables.FreeVariables.Item(i + 1).Value = dt.Rows[0][MidDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower()].ToString();
  988. if (MidDoc.Variables.FreeVariables.Item(i + 1).Value == "")
  989. {
  990. DataRow[] dr1 = Attach.Select("lp_name='" + MidDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower() + "'");
  991. if (dr1.Length > 0)
  992. MidDoc.Variables.FreeVariables.Item(i + 1).Value = dr1[0]["lp_sql"].ToString();
  993. }
  994. }
  995. MidDoc.Printer.SwitchTo(MidLabelPrinter.Text);
  996. MidDoc.PrintDocument();
  997. }
  998. /// <summary>
  999. /// 执行打印外箱号
  1000. /// </summary>
  1001. private void OutBoxCodePrint(int rowindex)
  1002. {
  1003. //获取对应行的pib_id
  1004. string pib_id = LabelInf.Rows[rowindex].Cells["pib_id1"].Value.ToString();
  1005. string pib_outboxcode2 = LabelInf.Rows[rowindex].Cells["pib_outboxcode2"].Value.ToString();
  1006. sql.Clear();
  1007. sql.Append("select * from ");
  1008. for (int i = 0; i < OutLabelParam.Rows.Count; i++)
  1009. {
  1010. if (i != OutLabelParam.Rows.Count - 1)
  1011. sql.Append("(" + OutLabelParam.Rows[i]["lp_sql"].ToString() + "),");
  1012. else
  1013. sql.Append("(" + OutLabelParam.Rows[i]["lp_sql"].ToString() + ")");
  1014. }
  1015. DataTable dt = (DataTable)dh.ExecuteSql(sql.ToString().ToLower().Replace("{pib_id}", pib_id).Replace("{pib_outboxcode2}", pib_outboxcode2), "select");
  1016. for (int i = 0; i < OutBoxDoc.Variables.FreeVariables.Count; i++)
  1017. {
  1018. if (dt.Columns.Contains(OutBoxDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower()))
  1019. OutBoxDoc.Variables.FreeVariables.Item(i + 1).Value = dt.Rows[0][OutBoxDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower()].ToString();
  1020. if (OutBoxDoc.Variables.FreeVariables.Item(i + 1).Value == "")
  1021. {
  1022. DataRow[] dr1 = Attach.Select("lp_name='" + OutBoxDoc.Variables.FreeVariables.Item(i + 1).Name.ToLower() + "'");
  1023. if (dr1.Length > 0)
  1024. OutBoxDoc.Variables.FreeVariables.Item(i + 1).Value = dr1[0]["lp_sql"].ToString();
  1025. }
  1026. }
  1027. OutBoxDoc.Printer.SwitchTo(OutBoxPrinter.Text);
  1028. OutBoxDoc.PrintDocument();
  1029. }
  1030. private void OutBoxLabelPrint_Click(object sender, EventArgs e)
  1031. {
  1032. if (OutBoxCombox.Text != "")
  1033. {
  1034. thread = new Thread(OutBoxPrint);
  1035. stw = new SetLoadingWindow(thread, "正在打印外箱");
  1036. BaseUtil.SetFormCenter(stw);
  1037. stw.ShowDialog();
  1038. }
  1039. else
  1040. MessageBox.Show("未维护外箱标签");
  1041. }
  1042. /// <summary>
  1043. /// 刷新采集进度
  1044. /// </summary>
  1045. private void RefreshProcessData()
  1046. {
  1047. if (LabelInf.Rows.Count > 0)
  1048. {
  1049. //设置初始化的采集进度
  1050. int Count = 0;
  1051. int CurrentMidBoxCollectedCount = 0;
  1052. //当前盒号的总盘数
  1053. int CurrentMidBoxTotalCount = 0;
  1054. //未超出当前范围的时候
  1055. for (int i = 0; i < LabelInf.RowCount; i++)
  1056. {
  1057. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() == "True")
  1058. Count++;
  1059. //和当前编辑箱号相等行
  1060. 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())
  1061. CurrentMidBoxCollectedCount++;
  1062. //当前盒号一共有几盘
  1063. if (LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString())
  1064. CurrentMidBoxTotalCount++;
  1065. }
  1066. Capacity.Text = "可装" + CurrentMidBoxTotalCount + "盘";
  1067. Installed.Text = "已装" + CurrentMidBoxCollectedCount + "盘";
  1068. //设置当前的箱号和盒号
  1069. Process_outboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode2"].Value.ToString();
  1070. Process_midboxcode.Text = LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString();
  1071. //设置当前总数和已采集数量
  1072. TotalCount.Text = LabelInf.RowCount.ToString();
  1073. CollectedCount.Text = Count.ToString();
  1074. }
  1075. }
  1076. private void LoadGridData()
  1077. {
  1078. LoadGridData(new object(), new EventArgs());
  1079. }
  1080. /// <summary>
  1081. /// 自定义函数 加载明细行的数据,多处使用添加进函数
  1082. /// </summary>
  1083. /// <param name="sender"></param>
  1084. /// <param name="e"></param>
  1085. private void LoadGridData(object sender, EventArgs e)
  1086. {
  1087. AllCollect = false;
  1088. dt = (DataTable)adh.ExecuteSql("select * from prodiobarcode where pib_inoutno='" + pi_inoutno.Text + "'", "select");
  1089. if (dt.Rows.Count == 0)
  1090. {
  1091. sql.Clear();
  1092. sql.Append("select pd_custprodcode,pib_inoutno,pd_custprodspec,nvl(pib_ifrecheck,0)pib_ifrecheck,nvl(pib_ifupload,0)pib_ifupload,nvl(pib_ifmodify,0)pib_ifmodify,pd_pocode,pib_madein,pib_custbarcode,pib_custoutboxcode,pib_id,pib_pdid,pib_piid,pib_pdno,pib_prodcode,nvl(nvl(pd_brand,pib_brand),pr_brand)pib_brand, pr_vendprodcode,");
  1093. sql.Append("pib_lotno,pib_datecode,pib_qty,pr_spec,pr_zxbzs,pr_unit,pib_barcode,pib_outboxcode1,pib_outboxcode2,nvl(pib_ifpick,0)pib_ifpick,nvl(pib_ifprint,0)pib_ifprint");
  1094. sql.Append(" from prodiobarcode left join prodiodetail on pib_piid=pd_piid and pd_pdno=pib_pdno and ");
  1095. sql.Append(" pd_prodcode=pib_prodcode left join product on pr_code=pib_prodcode left join sale on sa_code=pib_ordercode ");
  1096. sql.Append("where pib_piid='" + PI_ID + "' order by to_number(pib_outboxcode1),pib_id,pd_prodcode");
  1097. dt = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  1098. adh.SaveDataTable(dt, "prodiobarcode");
  1099. }
  1100. //获取系统设置的上传数量,如参数异常则默认为100
  1101. if (!int.TryParse(adh.getFieldDataByCondition("dataextra", "uploadnum", "id=1").ToString(), out UploadNum))
  1102. {
  1103. UploadNum = 100;
  1104. }
  1105. MidSource.DataSource = dt;
  1106. BaseUtil.FillDgvWithDataTable(LabelInf, (DataTable)MidSource.DataSource);
  1107. //有数据的话默认取第一条的品牌去取采集策略
  1108. TotalCount.Text = LabelInf.RowCount.ToString();
  1109. if (LabelInf.RowCount > 0)
  1110. {
  1111. Brand = LabelInf.Rows[0].Cells["pib_brand"].FormattedValue.ToString();
  1112. if (Brand != "")
  1113. {
  1114. dt = (DataTable)dh.ExecuteSql("select sg_script,sg_id from scangroup where sg_brand='" + Brand + "'", "select");
  1115. if (dt.Rows.Count > 0)
  1116. {
  1117. string sgid = dt.Rows[0]["sg_id"].ToString();
  1118. SG_Script = dt.Rows[0]["sg_script"].ToString();
  1119. reg = new Regex(SG_Script);
  1120. DataTable dt1 = (DataTable)dh.ExecuteSql("select si_name,si_item,si_expression from scanitem where si_sgid='" + sgid + "' and si_enable<>0", "select");
  1121. for (int i = 0; i < dt1.Rows.Count; i++)
  1122. {
  1123. if (SG_Script.IndexOf(dt1.Rows[i]["si_name"].ToString()) >= 0)
  1124. {
  1125. Si_Item.Add(SG_Script.IndexOf(dt1.Rows[i]["si_name"].ToString()), dt1.Rows[i]["si_item"].ToString());
  1126. }
  1127. }
  1128. //根据索引进行排序
  1129. Si_Item = (from entry in Si_Item orderby entry.Key ascending select entry).ToDictionary(pair => pair.Key, pair => pair.Value);
  1130. }
  1131. }
  1132. }
  1133. //绑定数据之后往下找到未采集的数据显示在当前采集的栏目
  1134. for (int i = 0; i < LabelInf.RowCount; i++)
  1135. {
  1136. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1137. {
  1138. griddetno.Text = LabelInf.Rows[i].Cells["pib_pdno"].FormattedValue.ToString();
  1139. pib_id.Text = LabelInf.Rows[i].Cells["pib_id1"].FormattedValue.ToString();
  1140. CurrentRowIndex = LabelInf.Rows[i].Cells["pib_prodcode"].RowIndex;
  1141. break;
  1142. }
  1143. }
  1144. }
  1145. /// <summary>
  1146. /// 重绘Cell的颜色
  1147. /// </summary>
  1148. /// <param name="sender"></param>
  1149. /// <param name="e"></param>
  1150. private void LabelInf_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  1151. {
  1152. bool mouseOver = e.CellBounds.Contains(this.PointToClient(Cursor.Position));
  1153. if (e.ColumnIndex > 0)
  1154. {
  1155. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_lotno" || LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
  1156. {
  1157. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1158. e.Graphics.FillRectangle(mouseOver ? solidBrush : Brushes.LightSeaGreen, e.CellBounds);
  1159. Rectangle border = e.CellBounds;
  1160. border.Width -= 1;
  1161. e.Graphics.DrawRectangle(Pens.White, border);
  1162. e.PaintContent(e.CellBounds);
  1163. e.Handled = true;
  1164. }
  1165. if (e.RowIndex >= 0)
  1166. {
  1167. //重绘制定的Cell,表示采集的数量不匹配
  1168. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_qty" && PaintCell.ContainsKey(LabelInf.Rows[e.RowIndex].Cells["pib_qty"]))
  1169. {
  1170. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1171. e.Graphics.FillRectangle(PaintCell[LabelInf.Rows[e.RowIndex].Cells["pib_qty"]] ? Brushes.ForestGreen : Brushes.Red, e.CellBounds);
  1172. Rectangle border = e.CellBounds;
  1173. border.Width -= 1;
  1174. e.Graphics.DrawRectangle(Pens.Black, border);
  1175. e.PaintContent(e.CellBounds);
  1176. e.Handled = true;
  1177. }
  1178. //表示采集的供应商物料编号不匹配
  1179. if (LabelInf.Columns[e.ColumnIndex].Name == "pr_vendprodcode" && PaintCell.ContainsKey(LabelInf.Rows[e.RowIndex].Cells["pr_vendprodcode"]))
  1180. {
  1181. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1182. e.Graphics.FillRectangle(PaintCell[LabelInf.Rows[e.RowIndex].Cells["pr_vendprodcode"]] ? Brushes.ForestGreen : Brushes.Red, e.CellBounds);
  1183. Rectangle border = e.CellBounds;
  1184. border.Width -= 1;
  1185. e.Graphics.DrawRectangle(Pens.Black, border);
  1186. e.PaintContent(e.CellBounds);
  1187. e.Handled = true;
  1188. }
  1189. //表示采集的供应商物料编号不匹配
  1190. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_brand" && PaintCell.ContainsKey(LabelInf.Rows[e.RowIndex].Cells["pib_brand"]))
  1191. {
  1192. SolidBrush solidBrush = new SolidBrush(Color.FromArgb(51, 153, 255));
  1193. e.Graphics.FillRectangle(PaintCell[LabelInf.Rows[e.RowIndex].Cells["pib_brand"]] ? Brushes.ForestGreen : Brushes.Red, e.CellBounds);
  1194. Rectangle border = e.CellBounds;
  1195. border.Width -= 1;
  1196. e.Graphics.DrawRectangle(Pens.Black, border);
  1197. e.PaintContent(e.CellBounds);
  1198. e.Handled = true;
  1199. }
  1200. }
  1201. }
  1202. }
  1203. private void CusLabelPrint()
  1204. {
  1205. //MaxOutBoxCode = MaxOutBoxCode + 1;
  1206. List<int> CusOutBoxCode = new List<int>();
  1207. //统计客户外箱号
  1208. if (LabelInf.Rows.Count > 0)
  1209. CusOutBoxCode.Add(0);
  1210. for (int i = 0; i < LabelInf.Rows.Count; i++)
  1211. {
  1212. if (i - 1 > 0 && LabelInf.Rows[i].Cells["pib_ifprint"].FormattedValue.ToString() == "True")
  1213. {
  1214. string cutboxcode = LabelInf.Rows[i].Cells["pib_cusoutboxcode"].Value.ToString();
  1215. string nextcutboxcode = LabelInf.Rows[i - 1].Cells["pib_cusoutboxcode"].Value.ToString();
  1216. if (cutboxcode != nextcutboxcode)
  1217. CusOutBoxCode.Add(i);
  1218. }
  1219. }
  1220. }
  1221. private void Refresh_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1222. {
  1223. KeyEventArgs e2 = new KeyEventArgs(Keys.Enter);
  1224. pi_inoutno_KeyDown(sender, e2);
  1225. }
  1226. /// <summary>
  1227. /// 采集明细切换
  1228. /// </summary>
  1229. /// <param name="sender"></param>
  1230. /// <param name="e"></param>
  1231. private void griddetno_KeyDown(object sender, KeyEventArgs e)
  1232. {
  1233. if (Keys.Enter == e.KeyData)
  1234. {
  1235. bool FindDetno = false;
  1236. for (int i = 0; i < LabelInf.RowCount; i++)
  1237. {
  1238. if (LabelInf.Rows[i].Cells["pib_pdno"].Value.ToString() == griddetno.Text && LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1239. {
  1240. FindDetno = true;
  1241. CurrentRowIndex = i;
  1242. RemindUser();
  1243. break;
  1244. }
  1245. }
  1246. if (!FindDetno)
  1247. {
  1248. MessageBox.Show("不存在未采集的明细序号" + griddetno.Text);
  1249. return;
  1250. }
  1251. }
  1252. }
  1253. private void AutoPrintMidLabel()
  1254. {
  1255. bool FullBox = true;
  1256. //判断所有盒号未该盒的是否勾选已采集
  1257. for (int i = 0; i < LabelInf.RowCount; i++)
  1258. {
  1259. if (LabelInf.Rows[i].Cells["pib_outboxcode1"].Value.ToString() == LabelInf.Rows[CurrentRowIndex].Cells["pib_outboxcode1"].Value.ToString())
  1260. {
  1261. if (LabelInf.Rows[i].Cells["pib_ifpick"].FormattedValue.ToString() != "True")
  1262. FullBox = false;
  1263. }
  1264. }
  1265. //如果当前箱号已经装满了
  1266. if (FullBox)
  1267. {
  1268. if (MidLabelCombox.SelectedValue != null)
  1269. {
  1270. MidBoxCodePrint(CurrentRowIndex);
  1271. }
  1272. else
  1273. MessageBox.Show("未维护中盒模板");
  1274. }
  1275. }
  1276. /// <summary>
  1277. /// 勾选的时候自动打印
  1278. /// </summary>
  1279. /// <param name="sender"></param>
  1280. /// <param name="e"></param>
  1281. private void LabelInf_CellValueChanged(object sender, DataGridViewCellEventArgs e)
  1282. {
  1283. if (LabelInf.Columns[e.ColumnIndex].Name == "pib_datecode")
  1284. {
  1285. string datecode = LabelInf.Rows[e.RowIndex].Cells["pib_datecode"].Value.ToString();
  1286. try
  1287. {
  1288. System.DateTime dt = System.DateTime.ParseExact(datecode, "yyyyMMdd", CultureInfo.CurrentCulture);
  1289. GregorianCalendar gc = new GregorianCalendar();
  1290. int weekOfYear = gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
  1291. if (weekOfYear < 10)
  1292. LabelInf.Rows[e.RowIndex].Cells["pib_datecode1"].Value = dt.Year.ToString().Substring(2, 2) + "0" + weekOfYear;
  1293. else
  1294. LabelInf.Rows[e.RowIndex].Cells["pib_datecode1"].Value = dt.Year.ToString().Substring(2, 2) + weekOfYear;
  1295. }
  1296. catch (Exception) { }
  1297. }
  1298. }
  1299. private void AllCollected_Click(object sender, EventArgs e)
  1300. {
  1301. if (AllCollect == false)
  1302. {
  1303. foreach (DataGridViewRow dr in LabelInf.Rows)
  1304. dr.Cells[1].Value = true;
  1305. AllCollect = true;
  1306. }
  1307. else
  1308. {
  1309. foreach (DataGridViewRow dr in LabelInf.Rows)
  1310. dr.Cells[1].Value = false;
  1311. AllCollect = false;
  1312. }
  1313. }
  1314. private void LogingOut_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1315. {
  1316. string close = MessageBox.Show(this.ParentForm, "是否注销", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1317. if (close.ToString() == "Yes")
  1318. {
  1319. Login login = new Login();
  1320. //注销的时候需要将拼接的连接字符串置空
  1321. DataHelper.DBConnectionString = null;
  1322. logout = true;
  1323. lbl.Quit();
  1324. this.Hide();
  1325. login.ShowDialog();
  1326. this.Close();
  1327. }
  1328. }
  1329. private void LabelInf_DataError(object sender, DataGridViewDataErrorEventArgs e) { }
  1330. /// <summary>
  1331. /// 切换打开的单盘文件
  1332. /// </summary>
  1333. /// <param name="sender"></param>
  1334. /// <param name="e"></param>
  1335. private void SingleLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1336. {
  1337. try
  1338. {
  1339. if (ComBoxClickChangeLabelDoc)
  1340. {
  1341. if (SingleDoc != null)
  1342. SingleDoc.Close();
  1343. if (SingleLabelCombox.Text != "" && SingleLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  1344. {
  1345. System.DateTime time = Convert.ToDateTime(SingleLabelCombox.SelectedValue.ToString().Split('#')[2]);
  1346. SingleDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(SingleLabelCombox.SelectedValue.ToString().Split('#')[1], SingleLabelCombox.Text, time));
  1347. }
  1348. }
  1349. }
  1350. catch (Exception) { }
  1351. }
  1352. /// <summary>
  1353. /// 切换打开的中盒文件
  1354. /// </summary>
  1355. /// <param name="sender"></param>
  1356. /// <param name="e"></param>
  1357. private void MidLabelCombox_SelectedIndexChanged(object sender, EventArgs e)
  1358. {
  1359. try
  1360. {
  1361. if (ComBoxClickChangeLabelDoc)
  1362. {
  1363. if (MidDoc != null)
  1364. MidDoc.Close();
  1365. if (MidLabelCombox.Text != "" && MidLabelCombox.SelectedValue != null && !GetGridOnly.Checked)
  1366. {
  1367. System.DateTime time = Convert.ToDateTime(MidLabelCombox.SelectedValue.ToString().Split('#')[2]);
  1368. MidDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(MidLabelCombox.SelectedValue.ToString().Split('#')[1], MidLabelCombox.Text, time));
  1369. }
  1370. }
  1371. }
  1372. catch (Exception) { }
  1373. }
  1374. /// <summary>
  1375. /// 切换打开的外箱文件
  1376. /// </summary>
  1377. /// <param name="sender"></param>
  1378. /// <param name="e"></param>
  1379. private void OutBoxCombox_SelectedIndexChanged(object sender, EventArgs e)
  1380. {
  1381. try
  1382. {
  1383. if (ComBoxClickChangeLabelDoc)
  1384. {
  1385. if (OutBoxDoc != null)
  1386. OutBoxDoc.Close();
  1387. if (OutBoxCombox.Text != "" && OutBoxCombox.SelectedValue != null && !GetGridOnly.Checked)
  1388. {
  1389. System.DateTime time = Convert.ToDateTime(OutBoxCombox.SelectedValue.ToString().Split('#')[2]);
  1390. OutBoxDoc = lbl.Documents.Open(BaseUtil.GetLabelUrl(OutBoxCombox.SelectedValue.ToString().Split('#')[1], OutBoxCombox.Text, time));
  1391. }
  1392. }
  1393. }
  1394. catch (Exception) { }
  1395. }
  1396. private void ChooseAll_Click(object sender, EventArgs e)
  1397. {
  1398. if (AllChecked)
  1399. {
  1400. foreach (DataGridViewRow dr in LabelInf.Rows)
  1401. dr.Cells[0].Value = false;
  1402. AllChecked = false;
  1403. }
  1404. else
  1405. {
  1406. foreach (DataGridViewRow dr in LabelInf.Rows)
  1407. dr.Cells[0].Value = true;
  1408. AllChecked = true;
  1409. }
  1410. }
  1411. private void ExportData_Click(object sender, EventArgs e)
  1412. {
  1413. ExportFileDialog.Description = "选择导出的路径";
  1414. DialogResult result = ExportFileDialog.ShowDialog();
  1415. if (result == DialogResult.OK)
  1416. {
  1417. ExcelHandler eh = new ExcelHandler();
  1418. DataTable dt = ((DataTable)MidSource.DataSource).Copy();
  1419. for (int i = dt.Columns.Count - 1; i >= 0; i--)
  1420. {
  1421. for (int j = 0; j < LabelInf.Columns.Count; j++)
  1422. {
  1423. //去除ID列
  1424. 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")
  1425. {
  1426. dt.Columns.RemoveAt(i);
  1427. break;
  1428. }
  1429. switch (dt.Columns[i].ColumnName.ToLower())
  1430. {
  1431. case "pib_lotno":
  1432. dt.Columns[i].ColumnName = "批次号";
  1433. break;
  1434. case "pib_datecode":
  1435. dt.Columns[i].ColumnName = "生产日期";
  1436. break;
  1437. case "pib_custbarcode":
  1438. dt.Columns[i].ColumnName = "最小产品包装条码";
  1439. break;
  1440. default:
  1441. break;
  1442. }
  1443. if (dt.Columns[i].ColumnName.ToLower() == LabelInf.Columns[j].DataPropertyName.ToLower())
  1444. {
  1445. dt.Columns[i].ColumnName = LabelInf.Columns[j].HeaderText;
  1446. break;
  1447. }
  1448. }
  1449. }
  1450. eh.ExportExcel(dt, ExportFileDialog.SelectedPath, pi_date.Text + "-" + pi_inoutno.Text);
  1451. string close = MessageBox.Show(this.ParentForm, "导出成功,是否打开文件", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  1452. if (close.ToString() == "Yes")
  1453. System.Diagnostics.Process.Start(ExportFileDialog.SelectedPath + "\\" + pi_date.Text + "-" + pi_inoutno.Text + ".xls");
  1454. }
  1455. }
  1456. private void MidBoxCapacity_Leave(object sender, EventArgs e)
  1457. {
  1458. NumericUpDown nup = (NumericUpDown)sender;
  1459. switch (nup.Name)
  1460. {
  1461. case "MidBoxCapacity":
  1462. Properties.Settings.Default.MidBoxCapacity = nup.Value;
  1463. Properties.Settings.Default.Save();
  1464. break;
  1465. case "OutboxCapacity":
  1466. Properties.Settings.Default.OutboxCapacity = nup.Value;
  1467. Properties.Settings.Default.Save();
  1468. break;
  1469. default:
  1470. break;
  1471. }
  1472. }
  1473. private void RefreshDBConnect_Tick(object sender, EventArgs e)
  1474. {
  1475. dh.getRowCount("employee", "1=1");
  1476. }
  1477. private void ButtonSetting_Click(object sender, EventArgs e)
  1478. {
  1479. ListButtonMenu.BringToFront();
  1480. ListButtonMenu.Visible = true;
  1481. }
  1482. private void ListButtonMenu_SelectedIndexChanged(object sender, EventArgs e)
  1483. {
  1484. ListButtonMenu.Visible = false;
  1485. switch (ListButtonMenu.SelectedItem.ToString())
  1486. {
  1487. case "采集策略设置":
  1488. 采集策略_NEW form = new 采集策略_NEW();
  1489. BaseUtil.SetFormCenter(form);
  1490. form.ShowDialog();
  1491. break;
  1492. case "附加信息设置":
  1493. if (pi_cardcode.Text != "")
  1494. {
  1495. 附件内容打印 att = new 附件内容打印(pi_cardcode.Text);
  1496. att.ShowDialog();
  1497. }
  1498. else MessageBox.Show("请先获取出库单信息");
  1499. break;
  1500. case "客户标签维护":
  1501. 客户标签维护 form1 = new 客户标签维护();
  1502. BaseUtil.SetFormCenter(form1);
  1503. if (SingleDoc != null)
  1504. SingleDoc.Close();
  1505. if (MidDoc != null)
  1506. MidDoc.Close();
  1507. if (OutBoxDoc != null)
  1508. OutBoxDoc.Close();
  1509. form1.FormClosed += LabelFormClose;
  1510. form1.ShowDialog();
  1511. break;
  1512. case "客户采集规则":
  1513. CustomerRule cust = new CustomerRule();
  1514. BaseUtil.SetFormCenter(cust);
  1515. cust.ShowDialog();
  1516. break;
  1517. case "参数配置":
  1518. ParamSetting form2 = new ParamSetting();
  1519. BaseUtil.SetFormCenter(form2);
  1520. form2.ShowDialog();
  1521. break;
  1522. default:
  1523. break;
  1524. }
  1525. }
  1526. }
  1527. }