UAS_出货标签管理.cs 139 KB

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