UAS_出货标签管理.cs 125 KB

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