InterfaceHelper.cs 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451
  1. using DirectService.Tools;
  2. using JLHHJSvr.BLL;
  3. using JLHHJSvr.Com;
  4. using JLHHJSvr.Com.Model;
  5. using JLHHJSvr.LJException;
  6. using JLHHJSvr.Tools;
  7. using LJLib.DAL.SQL;
  8. using Newtonsoft.Json.Linq;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Data.SqlClient;
  12. using System.Linq;
  13. using System.Text;
  14. using static JLHHJSvr.Helper.CacheHelper;
  15. namespace JLHHJSvr.Helper
  16. {
  17. internal class InterfaceHelper : HelperBase
  18. {
  19. /// <summary>
  20. /// 床垫接口-保存
  21. /// </summary>
  22. /// <param name="mattress"></param>
  23. /// <param name="mxlist"></param>
  24. /// <param name="qdlist"></param>
  25. /// <exception cref="LJCommonException"></exception>
  26. public void SaveMattressInterface(u_mattress mattress, List<u_mattress_interface> mxlist, List<u_mattress_interface_qd> qdlist)
  27. {
  28. if (mattress.mattressid <= 0)
  29. {
  30. throw new LJCommonException("错误的床垫id");
  31. }
  32. // 检查锁
  33. if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattress.mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  34. // 检测版本
  35. CheckBillVersion<u_mattress>(cmd, mattress.mattressid, mattress.version);
  36. mattress.version++;
  37. DbSqlHelper.Update(cmd, mattress, "erp_mtrlname,erp_mtrltypeid,erp_mtrlmode,erp_mtrltype,erp_mtrlunit,erp_mtrlengname,erp_configcodetype,old_mtrlname,version");
  38. // 床垫清单保存
  39. cmd.CommandText = @"DELETE u_mattress_interface WHERE mattressid = @mattressid";
  40. cmd.Parameters.Clear();
  41. cmd.Parameters.AddWithValue("@mattressid", mattress.mattressid);
  42. cmd.ExecuteNonQuery();
  43. cmd.CommandText = @"DELETE u_mattress_interface_qd WHERE mattressid = @mattressid";
  44. cmd.Parameters.Clear();
  45. cmd.Parameters.AddWithValue("@mattressid", mattress.mattressid);
  46. cmd.ExecuteNonQuery();
  47. foreach (var mx in mxlist)
  48. {
  49. mx.mattressid = mattress.mattressid;
  50. mx.actual_size = mx.actual_size ?? "";
  51. mx.sb_craft = mx.sb_craft ?? "";
  52. mx.actual_size_sb = mx.actual_size_sb ?? "";
  53. DbSqlHelper.Insert(cmd, mx, "mattressid,printid,itemname,bj_pzname,bj_namemx,actual_size,sb_craft,actual_size_sb,erp_pzid,bj_inputtype,ss_rate,ls_rate");
  54. }
  55. foreach (var mx in qdlist)
  56. {
  57. mx.mattressid = mattress.mattressid;
  58. DbSqlHelper.Insert(cmd, mx, "mattressid,printid,itemname,bj_pzname,bj_pzname_mx,bj_pzname_mx_mx,wip_type,mtrlid,erp_mtrlid,wrkgrpid,wrkgrpid2,useqty,dscrp,actual_useqty,qd_actual_size,qd_pfgroupqty,ss_rate,ls_rate,sh_rate,formulaid,wrkgrpcode1,wrkgrpcode2");
  59. }
  60. AutoUpdateBcp(mattress.mattressid);
  61. }
  62. #region 清单审核
  63. /// <summary>
  64. /// 产品补充审核
  65. /// </summary>
  66. /// <param name="mattressid"></param>
  67. /// <exception cref="LJCommonException"></exception>
  68. public void MattressJSAudit(int mattressid)
  69. {
  70. // 检查锁
  71. if (LockHelper.CheckIsLock(cmd, BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  72. var mattress = new u_mattress() { mattressid = mattressid };
  73. DbSqlHelper.SelectOne(cmd, mattress, "yw_flag,js1_flag,version");
  74. if (mattress.js1_flag == 1)
  75. {
  76. throw new LJCommonException("床垫已技术1审核,不能技术1审核!");
  77. }
  78. //if (mattress.yw_flag == 0)
  79. //{
  80. // throw new LJCommonException("床垫未业务审核,不能技术1审核!");
  81. //}
  82. mattress.js1_flag = 1;
  83. mattress.js1_auditingdate = context.opdate;
  84. mattress.js1_auditingrep = context.tokendata.username;
  85. mattress.version++;
  86. DbSqlHelper.Update(cmd, mattress, "js1_flag,js1_auditingdate,js1_auditingrep,version");
  87. }
  88. /// <summary>
  89. /// 产品补充撤审
  90. /// </summary>
  91. /// <param name="mattressid"></param>
  92. /// <exception cref="LJCommonException"></exception>
  93. public void MattressJSCancelAudit(int mattressid)
  94. {
  95. // 检查锁
  96. if (LockHelper.CheckIsLock(cmd, BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  97. var mattress = new u_mattress() { mattressid = mattressid };
  98. DbSqlHelper.SelectOne(cmd, mattress, "yw_flag,js1_flag,creatmtrl_flag");
  99. //if (mattress.creatmtrl_flag == 1)
  100. //{
  101. // throw new LJCommonException("床垫已生成产品,不能技术1撤审!");
  102. //}
  103. if (mattress.js1_flag == 0)
  104. {
  105. throw new LJCommonException("床垫未技术1撤审,不能技术1撤审!");
  106. }
  107. mattress.js1_flag = 0;
  108. mattress.js1_auditingdate = null;
  109. mattress.js1_auditingrep = string.Empty;
  110. mattress.version++;
  111. DbSqlHelper.Update(cmd, mattress, "js1_flag,js1_auditingdate,js1_auditingrep,version");
  112. }
  113. /// <summary>
  114. /// 清单补充审核
  115. /// </summary>
  116. /// <param name="mattressid"></param>
  117. /// <exception cref="LJCommonException"></exception>
  118. public void MattressJS2Audit(int mattressid)
  119. {
  120. // 检查锁
  121. if (LockHelper.CheckIsLock(cmd, BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  122. var mattress = new u_mattress() { mattressid = mattressid };
  123. DbSqlHelper.SelectOne(cmd, mattress, "js2_flag,version");
  124. if (mattress.js2_flag == 1)
  125. {
  126. throw new LJCommonException("床垫已技术2审核,不能技术2审核!");
  127. }
  128. mattress.js2_flag = 1;
  129. mattress.js2_auditingdate = context.opdate;
  130. mattress.js2_auditingrep = context.tokendata.username;
  131. mattress.version++;
  132. DbSqlHelper.Update(cmd, mattress, "js2_flag,js2_auditingdate,js2_auditingrep,version");
  133. }
  134. /// <summary>
  135. /// 清单补充撤审
  136. /// </summary>
  137. /// <param name="mattressid"></param>
  138. /// <exception cref="LJCommonException"></exception>
  139. public void MattressJS2CancelAudit(int mattressid)
  140. {
  141. // 检查锁
  142. if (LockHelper.CheckIsLock(cmd, BillKeyWord, mattressid, context.tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  143. var mattress = new u_mattress() { mattressid = mattressid };
  144. DbSqlHelper.SelectOne(cmd, mattress, "js2_flag,version");
  145. if (mattress.js2_flag == 0)
  146. {
  147. throw new LJCommonException("床垫未技术2审核,不能技术2撤审!");
  148. }
  149. mattress.js2_flag = 0;
  150. mattress.js2_auditingdate = null;
  151. mattress.js2_auditingrep = string.Empty;
  152. mattress.version++;
  153. DbSqlHelper.Update(cmd, mattress, "js2_flag,js2_auditingdate,js2_auditingrep,version");
  154. }
  155. #endregion
  156. #region 保存半成品部件
  157. public void SaveMattressBcp(u_semi_finished_product mattress)
  158. {
  159. var dtNow = DateTime.Now;
  160. var fields = @"billdate,semi_finished_type,semi_finished_code,semi_finished_name,dscrp,production_size,hemming_process,
  161. hemmed_size,shrinkage_rate,elongation_rate,opemp,opdate,auditemp,auditdate";
  162. var fieldsMx = "billid,printid,mtrlid,formulaid,chastr,thickness,qty,erp_mtrlid,usenum,usedenom";
  163. if (mattress.billid <= 0)
  164. {
  165. //新建
  166. fields += ",billid,billcode";
  167. mattress.opdate = dtNow;
  168. mattress.opemp = context.tokendata.username;
  169. mattress.billid = BllHelper.GetID(cmd, "u_semi_finished_product");
  170. switch (mattress.semi_finished_type)
  171. {
  172. case 901:
  173. mattress.billcode = "JM";
  174. break;
  175. case 902:
  176. mattress.billcode = "JD";
  177. break;
  178. case 903:
  179. mattress.billcode = "BC";
  180. break;
  181. case 904:
  182. mattress.billcode = "XC";
  183. break;
  184. case 905:
  185. mattress.billcode = "VC";
  186. break;
  187. }
  188. // 编号-年月日+流水
  189. mattress.billcode = $"{mattress.billcode}-{dtNow.ToString("yyyyMMdd")}{(mattress.billid.Value % 10000).ToString("D4")}";
  190. DbSqlHelper.Insert(cmd, "u_semi_finished_product", null, mattress, fields);
  191. }
  192. else
  193. {
  194. //修改
  195. cmd.CommandText = @"DELETE FROM u_semi_finished_product_mx WHERE billid = @billid";
  196. cmd.Parameters.Clear();
  197. cmd.Parameters.AddWithValue("@billid", mattress.billid);
  198. cmd.ExecuteNonQuery();
  199. DbSqlHelper.Update(cmd, "u_semi_finished_product", null, mattress, "billid", fields);
  200. }
  201. var cnt = 0;
  202. foreach (var mx in mattress.mxlist)
  203. {
  204. AutoInit.AutoInitS(cmd, mx);
  205. mx.billid = mattress.billid;
  206. mx.printid = ++cnt;
  207. DbSqlHelper.Insert(cmd, "u_semi_finished_product_mx", null, mx, fieldsMx);
  208. }
  209. var hisprice = new u_his_price
  210. {
  211. bednetid_mattressid = mattress.billid,
  212. typeid = 2,
  213. cmpdate = dtNow,
  214. cmpemp = context.tokendata.username,
  215. nottax_dept_cost = 0,
  216. dept_cost = 0,
  217. foreign_cost = 0
  218. };
  219. var fieldsHs = "bednetid_mattressid, typeid, cmpdate, cmpemp, nottax_dept_cost, dept_cost, foreign_cost";
  220. DbSqlHelper.Insert(cmd, "u_his_price", null, hisprice, fieldsHs);
  221. }
  222. /// <summary>
  223. /// 自动更新半成品部件
  224. /// </summary>
  225. /// <param name="mattressid"></param>
  226. public void AutoUpdateBcp(int mattressid)
  227. {
  228. var qdList = new List<u_mattress_interface_qd>();
  229. var selectStr = @"
  230. SELECT u_mattress_interface_qd.mattressid
  231. ,u_mattress_interface_qd.printid
  232. ,u_mattress_interface_qd.itemname
  233. ,u_mattress_interface_qd.bj_pzname
  234. ,u_mattress_interface_qd.bj_pzname_mx
  235. ,u_mattress_interface_qd.bj_pzname_mx_mx
  236. ,u_mattress_interface_qd.mtrlid
  237. ,u_mattress_interface_qd.erp_mtrlid
  238. ,u_mattress_interface_qd.useqty
  239. ,u_mattress_interface_qd.dscrp
  240. ,u_mattress_interface_qd.actual_useqty
  241. ,u_mattress_interface_qd.qd_actual_size
  242. ,u_mattress_interface_qd.qd_pfgroupqty
  243. ,u_mattress_interface_qd.wrkgrpid
  244. ,u_mattress_interface_qd.ss_rate
  245. ,u_mattress_interface_qd.ls_rate
  246. ,u_mattress_interface_qd.sh_rate
  247. ,u_mattress_interface_qd.formulaid
  248. FROM u_mattress_interface_qd
  249. ";
  250. var whereList = new List<string>();
  251. whereList.Add("mattressid = @mattressid");
  252. var param = new Dictionary<string, object>();
  253. param.Add("@mattressid", mattressid);
  254. var outFields = "mattressid, printid, itemname, bj_pzname, bj_pzname_mx, bj_pzname_mx_mx, mtrlid, erp_mtrlid, useqty, dscrp, actual_useqty, qd_actual_size, qd_pfgroupqty, wrkgrpid, ss_rate, ls_rate, sh_rate, formulaid";
  255. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "printid", outFields, 0, 0, qdList);
  256. var chastrArr = new List<string>() { "裥面", "裥底", "顶布裥棉", "大侧", "小侧", "V侧" };
  257. var chastrType = new Dictionary<string, int>();
  258. Dictionary<string, List<u_mattress_interface_qd>> bcpQdlist = new Dictionary<string, List<u_mattress_interface_qd>>();
  259. foreach (var mx in qdList)
  260. {
  261. if (chastrArr.Contains(mx.itemname) && !string.IsNullOrEmpty(mx.bj_pzname_mx_mx))
  262. {
  263. if (!chastrType.ContainsKey(mx.bj_pzname_mx_mx))
  264. {
  265. switch (mx.itemname)
  266. {
  267. case "裥面":
  268. chastrType.Add(mx.bj_pzname_mx_mx, 901);
  269. mx.billtype = 901;
  270. break;
  271. case "裥底":
  272. chastrType.Add(mx.bj_pzname_mx_mx, 902);
  273. mx.billtype = 902;
  274. break;
  275. case "大侧":
  276. chastrType.Add(mx.bj_pzname_mx_mx, 903);
  277. mx.billtype = 903;
  278. break;
  279. case "小侧":
  280. chastrType.Add(mx.bj_pzname_mx_mx, 904);
  281. mx.billtype = 904;
  282. break;
  283. case "V侧":
  284. chastrType.Add(mx.bj_pzname_mx_mx, 905);
  285. mx.billtype = 905;
  286. break;
  287. }
  288. }
  289. if (!bcpQdlist.ContainsKey(mx.bj_pzname_mx_mx))
  290. {
  291. List<u_mattress_interface_qd> list = new List<u_mattress_interface_qd>();
  292. list.Add(mx);
  293. bcpQdlist.Add(mx.bj_pzname_mx_mx, list);
  294. }
  295. else
  296. {
  297. bcpQdlist[mx.bj_pzname_mx_mx].Add(mx);
  298. }
  299. }
  300. }
  301. foreach (var mx in bcpQdlist)
  302. {
  303. var billid = 0;
  304. cmd.CommandText = @"SELECT TOP 1 billid
  305. FROM u_semi_finished_product
  306. WHERE semi_finished_name = @semi_finished_name";
  307. cmd.Parameters.Clear();
  308. cmd.Parameters.AddWithValue("@semi_finished_name", mx.Key);
  309. using (var reader = cmd.ExecuteReader())
  310. {
  311. if (reader.Read())
  312. {
  313. billid = Convert.ToInt32(reader["billid"]);
  314. }
  315. }
  316. if (billid == 0)
  317. {
  318. //创建
  319. var bcpMattress = new u_semi_finished_product() { billid = 0 };
  320. AutoInit.AutoInitS(cmd, bcpMattress);
  321. bcpMattress.billid = 0;
  322. bcpMattress.billdate = DateTime.Now;
  323. bcpMattress.dscrp = "自动生成,来自mattressid:" + mattressid;
  324. //bcpMattress.production_size = DateTime.Now;
  325. //bcpMattress.hemming_process = DateTime.Now;
  326. //bcpMattress.hemmed_size = DateTime.Now;
  327. //bcpMattress.shrinkage_rate = DateTime.Now;
  328. //bcpMattress.elongation_rate = DateTime.Now;
  329. bcpMattress.opemp = context.tokendata.username;
  330. bcpMattress.opdate = DateTime.Now;
  331. bcpMattress.semi_finished_type = chastrType[mx.Key];
  332. bcpMattress.semi_finished_code = mx.Key;
  333. bcpMattress.semi_finished_name = mx.Key;
  334. var bcpMxList = new List<u_semi_finished_product_mx>();
  335. foreach (var qdmx in mx.Value)
  336. {
  337. var bcpmx = new u_semi_finished_product_mx()
  338. {
  339. mtrlid = qdmx.mtrlid.Value,
  340. erp_mtrlid = qdmx.erp_mtrlid,
  341. formulaid = qdmx.formulaid
  342. };
  343. bcpMxList.Add(bcpmx);
  344. }
  345. bcpMattress.mxlist = bcpMxList;
  346. SaveMattressBcp(bcpMattress);
  347. }
  348. else
  349. {
  350. // 判断不一样,就覆盖
  351. selectStr = @"
  352. SELECT u_semi_finished_product_mx.billid
  353. ,u_semi_finished_product_mx.printid
  354. ,u_semi_finished_product_mx.mtrlid
  355. ,u_semi_finished_product_mx.formulaid
  356. ,u_semi_finished_product_mx.chastr
  357. ,u_semi_finished_product_mx.thickness
  358. ,u_semi_finished_product_mx.qty
  359. ,u_semi_finished_product_mx.erp_mtrlid
  360. ,u_semi_finished_product_mx.usenum
  361. ,u_semi_finished_product_mx.usedenom
  362. FROM u_semi_finished_product_mx
  363. ";
  364. var bcpMxList = new List<u_semi_finished_product_mx>();
  365. whereList = new List<string>();
  366. whereList.Add("u_semi_finished_product_mx.billid = @billid");
  367. param.Clear();
  368. param.Add("@billid", billid);
  369. outFields = "billid, printid, mtrlid, formulaid, chastr, thickness, qty, erp_mtrlid, usenum, usedenom, mtrlname, if_mtrl, formula, formulatype, formulakind";
  370. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "formulatype, sortcode", outFields, 0, 0, bcpMxList);
  371. var ErpMtrlids = "";
  372. var BcpErpMtrlids = "";
  373. foreach (var qdmx in mx.Value)
  374. {
  375. ErpMtrlids += qdmx.erp_mtrlid + "+";
  376. }
  377. foreach (var qdmx in bcpMxList)
  378. {
  379. BcpErpMtrlids += qdmx.erp_mtrlid + "+";
  380. }
  381. if (ErpMtrlids != BcpErpMtrlids)
  382. {
  383. var bcpMattress = new u_semi_finished_product() { billid = billid };
  384. DbSqlHelper.SelectOne(cmd, bcpMattress, "billid, billdate, flag, semi_finished_type, semi_finished_code, semi_finished_name, dscrp, production_size, hemming_process, hemmed_size, shrinkage_rate, elongation_rate, opemp, opdate, auditemp, auditdate");
  385. bcpMattress.billid = billid;
  386. bcpMattress.auditemp = context.tokendata.username;
  387. bcpMattress.auditdate = DateTime.Now;
  388. foreach (var qdmx in bcpMxList)
  389. {
  390. var mtrlid = 0;
  391. var formulaid = 0;
  392. var arr = mx.Value.Where((itm) => itm.mtrlid == qdmx.mtrlid).ToList();
  393. if (arr.Count > 0)
  394. {
  395. mtrlid = arr[0].erp_mtrlid.Value;
  396. if (arr[0].formulaid != null) formulaid = arr[0].formulaid.Value;
  397. }
  398. qdmx.erp_mtrlid = mtrlid;
  399. qdmx.formulaid = formulaid;
  400. }
  401. bcpMattress.mxlist = bcpMxList;
  402. SaveMattressBcp(bcpMattress);
  403. }
  404. }
  405. }
  406. }
  407. #endregion
  408. public void AutoSetMtrlName(u_mattress mattress, List<u_mattress_interface> mxlist)
  409. {
  410. string mtrltypename = string.Empty, mtrltypecode = string.Empty;
  411. string mattresstypename = string.Empty, mattresstypecode = string.Empty;
  412. string packtypename = string.Empty, packtypecode = string.Empty;
  413. var materialCodes = new Dictionary<string, string>
  414. {
  415. { "两边单层", "21" },
  416. { "两边直出", "23" },
  417. { "三边加顶", "32" },
  418. { "三边直出", "33" },
  419. { "假三边", "34" },
  420. { "拉假边", "3C" },
  421. { "假三边加顶", "42" },
  422. { "上下假三边", "44" },
  423. { "四边双顶", "45" },
  424. { "四边顶上顶", "46" },
  425. { "四边假分体", "47" }
  426. };
  427. var mattressTypeCodes = new Dictionary<string, string>
  428. {
  429. { "袋装网", "P" },
  430. { "拉丝网", "C" },
  431. { "圆网", "B" }
  432. };
  433. var packTypeCodes = new Dictionary<string, string>
  434. {
  435. { "平压", "A" },
  436. { "卷包", "B" }
  437. };
  438. foreach (var mx in mxlist)
  439. {
  440. if (mx.bj_pzname.IndexOf("床垫类别") > -1)
  441. {
  442. mtrltypename = mx.bj_namemx;
  443. break;
  444. }
  445. }
  446. foreach (var mx in mxlist)
  447. {
  448. if (mx.bj_pzname.IndexOf("床网") > -1)
  449. {
  450. mattresstypename = mx.bj_namemx;
  451. break;
  452. }
  453. }
  454. foreach (var mx in mxlist)
  455. {
  456. if (mx.bj_pzname.IndexOf("包装方式") > -1)
  457. {
  458. packtypename = mx.bj_namemx;
  459. break;
  460. }
  461. }
  462. mtrltypecode = materialCodes.ContainsKey(mtrltypename) ? materialCodes[mtrltypename] : "99";
  463. mattresstypecode = mattressTypeCodes.ContainsKey(mtrltypename) ? mattressTypeCodes[mtrltypename] : "Z";
  464. packtypecode = packTypeCodes.ContainsKey(mtrltypename) ? packTypeCodes[mtrltypename] : "J";
  465. // 获取mxlist最后一项
  466. if (mattress.mattressid > 0)
  467. {
  468. mattress.erp_mtrlname = new StringBuilder().Append(mtrltypecode).Append(mattresstypecode).Append(packtypecode).ToString();
  469. }
  470. }
  471. public List<u_mattress_interface> GetMattressInterfaceList(int mattressid, int? configuretype)
  472. {
  473. var interfaceList = new List<u_mattress_interface>();
  474. var selectStr = @"SELECT mattressid
  475. ,printid
  476. ,itemname
  477. ,bj_pzname
  478. ,bj_namemx
  479. ,actual_size
  480. ,sb_craft
  481. ,actual_size_sb
  482. ,erp_pzid
  483. ,ss_rate
  484. ,ls_rate
  485. ,bj_inputtype
  486. FROM u_mattress_interface";
  487. DbSqlHelper.SelectJoin(cmd, selectStr, "mattressid = @mattressid", new Dictionary<string, object>() { { "@mattressid", mattressid } }, "printid", "mattressid,printid,itemname,bj_pzname,bj_namemx,actual_size,sb_craft,actual_size_sb,erp_pzid,ss_rate,ls_rate,bj_inputtype", 0, 0, interfaceList);
  488. if(interfaceList.Count <= 0)
  489. {
  490. interfaceList = RefreshMattressInterfaceList(mattressid, configuretype);
  491. foreach (var itm in interfaceList)
  492. {
  493. itm.mattressid = mattressid;
  494. itm.actual_size = itm.actual_size ?? "";
  495. itm.actual_size_sb = itm.actual_size_sb ?? "";
  496. itm.sb_craft = itm.sb_craft ?? "";
  497. itm.ss_rate = itm.ss_rate ?? 0;
  498. itm.ls_rate = itm.ls_rate ?? 0;
  499. }
  500. } else
  501. {
  502. MattressInterfaceFindERPPz(mattressid, interfaceList, configuretype);
  503. }
  504. return interfaceList;
  505. }
  506. public List<u_mattress_interface_qd> GetMattressInterfaceQdList(int mattressid)
  507. {
  508. var qdList = new List<u_mattress_interface_qd>();
  509. var selectStr = @"SELECT u_mattress_interface_qd.mattressid
  510. ,u_mattress_interface_qd.printid
  511. ,u_mattress_interface_qd.itemname
  512. ,u_mattress_interface_qd.bj_pzname
  513. ,u_mattress_interface_qd.bj_pzname_mx
  514. ,u_mattress_interface_qd.bj_pzname_mx_mx
  515. ,u_mattress_interface_qd.wip_type
  516. ,u_mattress_interface_qd.mtrlid
  517. ,u_mattress_interface_qd.erp_mtrlid
  518. ,u_mattress_interface_qd.useqty
  519. ,u_mattress_interface_qd.dscrp
  520. ,u_mtrl_price.name AS mtrlname
  521. ,u_mattress_interface_qd.actual_useqty
  522. ,u_mattress_interface_qd.qd_actual_size
  523. ,u_mattress_interface_qd.qd_pfgroupqty
  524. ,u_mattress_interface_qd.wrkgrpid
  525. ,u_mattress_interface_qd.wrkgrpcode1
  526. ,u_mattress_interface_qd.wrkgrpcode2
  527. ,u_mattress_interface_qd.wrkgrpid2
  528. ,u_mattress_interface_qd.ss_rate
  529. ,u_mattress_interface_qd.ls_rate
  530. ,u_mattress_interface_qd.sh_rate
  531. ,u_mattress_interface_qd.formulaid
  532. FROM u_mattress_interface_qd
  533. LEFT JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mattress_interface_qd.mtrlid";
  534. var outputFields = "mattressid,printid,itemname,bj_pzname,bj_pzname_mx,bj_pzname_mx_mx,wip_type,mtrlid,erp_mtrlid,useqty,dscrp,mtrlname,actual_useqty,qd_actual_size,qd_pfgroupqty,wrkgrpid,wrkgrpid2,ss_rate,ls_rate,sh_rate,wrkgrpcode1,wrkgrpcode2";
  535. DbSqlHelper.SelectJoin(cmd, selectStr, "mattressid = @mattressid", new Dictionary<string, object>() { { "@mattressid", mattressid } }, "printid", outputFields, 0, 0, qdList);
  536. if (qdList.Count <= 0)
  537. {
  538. qdList = RefreshMattressInterfaceQdList(mattressid);
  539. }
  540. return qdList;
  541. }
  542. #region 导入配置方法
  543. /// <summary>
  544. /// 刷新带出配置
  545. /// </summary>
  546. /// <param name="mattressid"></param>
  547. /// <returns></returns>
  548. public List<u_mattress_interface> RefreshMattressInterfaceList(int mattressid, int? configcodetype = 0)
  549. {
  550. var interfaceList = new List<u_mattress_interface>();
  551. // 导入配置
  552. ImportMattressInterfaceList(mattressid, interfaceList);
  553. MattressInterfaceFindERPPz(mattressid, interfaceList, configcodetype);
  554. return interfaceList;
  555. }
  556. /// <summary>
  557. /// 导入产品配置
  558. /// </summary>
  559. /// <param name="mattressid"></param>
  560. /// <exception cref="LJCommonException"></exception>
  561. public void ImportMattressInterfaceList(int mattressid, List<u_mattress_interface> interfaceList)
  562. {
  563. if (mattressid <= 0)
  564. {
  565. throw new LJCommonException("床垫id有误");
  566. }
  567. var mattressHelper = GetHelper<MattressHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  568. var mattress = mattressHelper.GetMattress(mattressid);
  569. var mattress_type = new u_mattress_type() { mattresstypeid = mattress.mattresstypeid };
  570. DbSqlHelper.SelectOne(cmd, mattress_type, "typename");
  571. var mxlist_all = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype IN (0,1,2,3,99,101,104,103)" });
  572. mattressHelper.wf_sort_mx(ref mxlist_all);
  573. var mxlist = mxlist_all.Where(t => new[]{ 0, 1, 2, 3, 99, 104, 103 }.Contains(t.formulatype.Value)).ToList();
  574. var mxlist_103 = mxlist_all.Where(t => t.formulatype == 103).ToList();
  575. var mxlist_101 = mxlist_all.Where(t => t.formulatype == 101).ToList();
  576. // 高度
  577. interfaceList.Add(InserMattressInterfacePz("床垫", "高度", 2, new string[] { $"{mattress.mattress_height}" }));
  578. // 参考外观
  579. interfaceList.Add(InserMattressInterfacePz("床垫", "参考外观", 1, new string[] { "" }));
  580. // 尺寸
  581. mattress.erp_mtrlcode = $"{mattress.mattress_width}*{mattress.mattress_length}*{mattress.mattress_height}";
  582. interfaceList.Add(InserMattressInterfacePz("床垫", "尺寸", 2, new string[] { mattress.erp_mtrlcode }));
  583. // 床垫类别
  584. interfaceList.Add(InserMattressInterfacePz("床垫", "床垫类别", 2, new string[] { mattress_type.typename }));
  585. // 拆装类型
  586. var name_arr = new string[1];
  587. name_arr[0] = string.Empty;
  588. if (mattress.if_m_chai == 1) name_arr[0] = AppendToString(name_arr[0], "面拆");
  589. if (mattress.if_z_chai == 1) name_arr[0] = AppendToString(name_arr[0], "中拆");
  590. if (mattress.if_d_chai == 1) name_arr[0] = AppendToString(name_arr[0], "底拆");
  591. interfaceList.Add(InserMattressInterfacePz("床垫", "拆装类型", 1, name_arr));
  592. // 床垫分类
  593. name_arr[0] = string.Empty;
  594. if (mattress.if_haimian_type == 1) name_arr[0] = AppendToString(name_arr[0], "海绵床垫");
  595. else name_arr[0] = AppendToString(name_arr[0], "弹簧床垫");
  596. if (mattress.if_zhedie_type == 1) name_arr[0] = AppendToString(name_arr[0], "折叠床垫");
  597. interfaceList.Add(InserMattressInterfacePz("床垫", "床垫分类", 1, name_arr));
  598. // 外观布套做法
  599. name_arr[0] = string.Empty;
  600. if (mattress.if_m_wbutao_way == 1) name_arr[0] = AppendToString(name_arr[0], $"面层向大侧覆盖{mattress.s_m_cover_qty}CM、大侧向底层覆盖{mattress.z_m_cover_qty}CM、底层向大侧覆盖{mattress.x_m_cover_qty}CM");
  601. interfaceList.Add(InserMattressInterfacePz("床垫", "外观布套做法", 1, name_arr));
  602. // 边带
  603. name_arr[0] = string.Empty;
  604. interfaceList.Add(InserMattressInterfacePz("床垫", "边带", 0, name_arr));
  605. #region 面料类清单导入 AutoSetFormulaTypeZeroPz()需要优化
  606. AutoSetFormulaTypeZeroPz(mxlist, interfaceList);
  607. interfaceList.Add(InserMattressInterfacePz("车位说明", "车位说明", 1, name_arr));
  608. #endregion
  609. #region 垫层类清单导入
  610. AutoSetFormulaTypeOnePz(mxlist, interfaceList);
  611. #endregion
  612. #region 辅料类清单导入
  613. AutoSetFormulaTypeTwoPz(mxlist, interfaceList);
  614. #endregion
  615. #region 包装类清单导入
  616. AutoSetFormulaTypeThreePz(mattress, mxlist, interfaceList);
  617. #endregion
  618. #region 内布套类清单导入
  619. AutoSetFormulaType101Pz(mattress, mxlist_101, interfaceList);
  620. #endregion
  621. #region 自定义配置导入
  622. if(mattress.erp_configcodetype != null && mattress.erp_configcodetype > 0)
  623. {
  624. var erpHelper = HelperBase.GetHelper<ERPHelper>(null);
  625. var parameters = new JObject();
  626. parameters.Add("dsname", "web_configure_code_list");
  627. var queryparams = new JObject();
  628. queryparams.Add("arg_configcodetype", mattress.erp_configcodetype);
  629. queryparams.Add("arg_ifpack", 1);
  630. parameters.Add("queryparams", queryparams);
  631. var resultList = erpHelper.GetERPList<erp_configure_code>("CommonDynamicSelect", parameters);
  632. foreach(var result in resultList)
  633. {
  634. var pzname = result.name;
  635. interfaceList.Add(InserMattressInterfacePz("自定义", pzname, 1, new string[] { "" }));
  636. }
  637. }
  638. #endregion
  639. }
  640. public void MattressInterfaceFindERPPz(int mattressid, List<u_mattress_interface> interfaceList, int? configcodetype = 0)
  641. {
  642. var mattress = new u_mattress() { mattressid = mattressid };
  643. if (configcodetype != 0)
  644. {
  645. mattress.erp_configcodetype = configcodetype;
  646. } else
  647. {
  648. DbSqlHelper.SelectOne(cmd, mattress, "erp_configcodetype");
  649. }
  650. MattressInterfaceFindERPPz(mattress, interfaceList);
  651. }
  652. public void MattressInterfaceFindERPPz(u_mattress mattress,List<u_mattress_interface> interfaceList)
  653. {
  654. InterfaceFindERPPz(mattress.erp_configcodetype.Value, interfaceList);
  655. }
  656. public u_mattress_interface InserMattressInterfacePz(string itemname, string bj_pzname, byte inputtype, string[] names)
  657. {
  658. return InserInterfacePz<u_mattress_interface>(itemname,bj_pzname,inputtype,names);
  659. }
  660. private string SetInterfacePzName(string[] names)
  661. {
  662. var result = string.Empty;
  663. foreach (var name in names)
  664. {
  665. if (string.IsNullOrEmpty(name)) continue;
  666. result = AppendToString(result, name);
  667. }
  668. return result;
  669. }
  670. private void AutoSetFormulaTypeZeroPz(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  671. {
  672. var powerDict = new Dictionary<string, int[]>()
  673. {
  674. {"面裥绵",new int[] { 0, 40, 50, 60, 70, 80 } },
  675. {"底裥绵",new int[] { 1, 41, 51, 61, 71, 81 } },
  676. {"顶布裥棉1",new int[] { 0, 40, 50, 60, 70, 80 } },
  677. {"顶布裥棉2",new int[] { 0, 40, 50, 60, 70, 80 } },
  678. {"顶布裥棉3",new int[] { 0, 40, 50, 60, 70, 80 } },
  679. {"顶布裥棉4",new int[] { 0, 40, 50, 60, 70, 80 } },
  680. {"普通大侧",new int[] { 2, 42, 52, 62, 72, 82 } },
  681. {"上下拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  682. {"上下拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  683. {"上下拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  684. {"左右拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  685. {"左右拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  686. {"左右拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  687. {"小侧1_EMPTY",new int[] { 3, 43, 53, 63, 73, 83 } },
  688. {"小侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  689. {"小侧1-上下拼侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  690. {"小侧1-上下拼侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  691. {"小侧1-上下拼侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  692. {"小侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  693. {"小侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  694. {"V侧1_EMPTY",new int[] { 4, 44, 54, 64, 74, 84 } },
  695. {"V侧1",new int[] { 4, 44, 54, 64, 74, 84 } },
  696. {"V侧2",new int[] { 4, 44, 54, 64, 74, 84 } },
  697. {"V侧3",new int[] { 4, 44, 54, 64, 74, 84 } }
  698. };
  699. var chastrArrDict = new Dictionary<string, string[]>()
  700. {
  701. {"面裥绵",new string[] { "裥面", "面层裥棉", "面层裥棉图案", "面层裥面说明" } },
  702. {"底裥绵",new string[] { "裥底", "底层裥棉", "底层裥棉图案", "底层裥棉说明" } },
  703. {"顶布裥棉1",new string[] { "顶布裥棉", "", "顶布裥棉1图案", "顶布裥棉1说明" } },
  704. {"顶布裥棉2",new string[] { "顶布裥棉", "", "顶布裥棉2图案", "顶布裥棉2说明" } },
  705. {"顶布裥棉3",new string[] { "顶布裥棉", "", "顶布裥棉3图案", "顶布裥棉3说明" } },
  706. {"顶布裥棉4",new string[] { "顶布裥棉","", "顶布裥棉4图案", "顶布裥棉4说明" } },
  707. {"普通大侧",new string[] { "大侧", "大侧裥棉", "大侧裥棉图案" } },
  708. {"上下拼侧1",new string[] {"大侧", "大侧-上下拼侧1", "大侧-上下拼侧1裥棉图案", "大侧-上下拼侧1高度"} },
  709. {"上下拼侧2",new string[] { "大侧", "大侧-上下拼侧2", "大侧-上下拼侧2裥棉图案", "大侧-上下拼侧2高度" } },
  710. {"上下拼侧3",new string[] { "大侧", "大侧-上下拼侧3", "大侧-上下拼侧3裥棉图案", "大侧-上下拼侧3高度" } },
  711. {"左右拼侧1",new string[] { "大侧", "大侧-左右拼侧1", "大侧-左右拼侧1裥棉图案", "大侧-左右拼侧1长度" } },
  712. {"左右拼侧2",new string[] { "大侧", "大侧-左右拼侧2", "大侧-左右拼侧2裥棉图案", "大侧-左右拼侧2长度" } },
  713. {"左右拼侧3",new string[] { "大侧", "大侧-左右拼侧3", "大侧-左右拼侧3裥棉图案", "大侧-左右拼侧3长度", "大侧说明" } },
  714. {"小侧1_EMPTY",new string[] { "小侧", "小侧1裥棉", "小侧1裥棉图案" } },
  715. {"小侧1",new string[] { "小侧", "小侧1裥棉", "小侧1裥棉图案" } },
  716. {"小侧1-上下拼侧1",new string[] { "小侧", "小侧1-上下拼侧1裥棉", "小侧1-上下拼侧1裥棉图案" } },
  717. {"小侧1-上下拼侧2",new string[] { "小侧", "小侧1-上下拼侧2裥棉", "小侧1-上下拼侧2裥棉图案" } },
  718. {"小侧1-上下拼侧3",new string[] { "小侧", "小侧1-上下拼侧3裥棉", "小侧1-上下拼侧3裥棉图案" } },
  719. {"小侧2",new string[] { "小侧", "小侧2裥棉", "小侧2裥棉图案" } },
  720. {"小侧3",new string[] { "小侧", "小侧3裥棉", "小侧3裥棉图案", "小侧说明" } },
  721. {"V侧1_EMPTY",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  722. {"V侧1",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  723. {"V侧2",new string[] { "V侧", "V侧2裥棉", "V侧2裥棉图案" } },
  724. {"V侧3",new string[] { "V侧", "V侧3裥棉", "V侧3裥棉图案", "V侧说明" } }
  725. };
  726. var jianmianList = mxlist.Where(t => t.formulatype == 0).ToList();
  727. var dingbuList = mxlist.Where(t => t.formulatype == 103).ToList();
  728. #region wf_import_qingdan + wf_import_qingdan_1 面料部分
  729. foreach (var item in powerDict)
  730. {
  731. if(item.Key.Contains("顶布裥棉")) SetFormulaTypeZeroPz(dingbuList, interfaceList, item.Value, item.Key, chastrArrDict[item.Key]);
  732. else SetFormulaTypeZeroPz(jianmianList, interfaceList, item.Value, item.Key, chastrArrDict[item.Key]);
  733. }
  734. #endregion
  735. #region wf_import_qingdan_next 面料部分
  736. // 拉手
  737. var lashouList = jianmianList.Where(t => t.formulakind == 5).ToList();
  738. for (int i = 0; i < lashouList.Count; i++)
  739. {
  740. var mx = lashouList[i];
  741. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  742. {
  743. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"拉手{i + 1}做法", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}只{mx.mtrlname}" }));
  744. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"拉手{i + 1}刺绣", 0, new string[] { "" }));
  745. }
  746. }
  747. // 刺绣
  748. var cixiuList = jianmianList.Where(t => t.formulakind == 6).ToList();
  749. var ls_temp_cnt = 0;
  750. for (int i = 0; i < cixiuList.Count; i++)
  751. {
  752. var mx = cixiuList[i];
  753. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  754. {
  755. for (int k = 0; k < mx.qty; k++)
  756. {
  757. ls_temp_cnt++;
  758. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"侧刺绣{ls_temp_cnt}做法", 1, new string[] { "" }));
  759. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"侧刺绣{ls_temp_cnt}位置", 0, new string[] { "" }));
  760. }
  761. }
  762. }
  763. // 大侧压压布
  764. var dcyybList = jianmianList.Where(t => t.formulakind == 7).ToList();
  765. for (int i = 0; i < dcyybList.Count; i++)
  766. {
  767. var mx = dcyybList[i];
  768. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  769. {
  770. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"大侧压压布{i + 1}", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  771. }
  772. }
  773. // 大侧压边带
  774. var dcybdList = jianmianList.Where(t => t.formulakind == 8).ToList();
  775. for (int i = 0; i < dcybdList.Count; i++)
  776. {
  777. var mx = dcybdList[i];
  778. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  779. {
  780. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"大侧压边带{i + 1}", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  781. }
  782. }
  783. // 大侧压织带
  784. var dcyzdList = jianmianList.Where(t => t.formulakind == 9).ToList();
  785. for (int i = 0; i < dcyzdList.Count; i++)
  786. {
  787. var mx = dcyzdList[i];
  788. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  789. {
  790. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"大侧压织带{i + 1}", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  791. }
  792. }
  793. // 大侧压上下压线
  794. var dcysxyxList = jianmianList.Where(t => t.formulakind == 10).ToList();
  795. for (int i = 0; i < dcysxyxList.Count; i++)
  796. {
  797. var mx = dcysxyxList[i];
  798. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  799. {
  800. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"大侧压上下压线{i + 1}", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  801. }
  802. }
  803. // 车花边
  804. var chbList = jianmianList.Where(t => t.formulakind == 205).ToList();
  805. for (int i = 0; i < chbList.Count; i++)
  806. {
  807. var mx = chbList[i];
  808. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  809. {
  810. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", "车花边", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  811. }
  812. }
  813. // 防火线
  814. var fhxList = jianmianList.Where(t => t.formulakind == 30).ToList();
  815. for (int i = 0; i < fhxList.Count; i++)
  816. {
  817. var mx = fhxList[i];
  818. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  819. {
  820. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", "防火线", 1, new string[] { mx.mtrlname }));
  821. }
  822. }
  823. // 拉链
  824. var llList = jianmianList.Where(t => t.formulakind == 202 && string.IsNullOrEmpty(t.chastr) && t.mtrlid > 0).ToList();
  825. for (int i = 0; i < llList.Count; i++)
  826. {
  827. var mx = llList[i];
  828. if (llList.Count > 1)
  829. {
  830. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", "拉链" + (i+1), 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  831. }
  832. else
  833. {
  834. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", "拉链", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  835. }
  836. }
  837. #endregion
  838. }
  839. private void SetFormulaTypeZeroPz(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList, int[] powerArr, string key, string[] chastrArr)
  840. {
  841. var mianList1 = new HashSet<string> { "面裥绵", "底裥绵" };
  842. var mianList2 = new string[4] { "顶布裥棉1", "顶布裥棉2", "顶布裥棉3", "顶布裥棉4" };
  843. var mianList3 = new HashSet<string> { "普通大侧", "上下拼侧1", "上下拼侧2", "上下拼侧3", "左右拼侧1", "左右拼侧2", "左右拼侧3", "小侧1", "小侧2", "小侧3" };
  844. //var mianList4 = new HashSet<string> { "小侧1", "小侧2", "小侧3" };
  845. var name_arr = new string[5];
  846. foreach (var mx in mxlist)
  847. {
  848. SetFormulaTypeZeroPzName(mx, key, powerArr, name_arr);
  849. }
  850. if (mianList2.Contains(key))
  851. {
  852. for (int i = 0; i < mianList2.Length; i++)
  853. {
  854. DingBuLianMian.SetValue(name_arr[i], Array.IndexOf(mianList2, key),i );
  855. }
  856. }
  857. //if (mianList4.Contains(key))
  858. //{
  859. // var _index = 0;
  860. // Regex regex = new Regex(@"\d+");
  861. // Match match = regex.Match(key);
  862. // _index = Convert.ToInt32(match.Value) - 1;
  863. // for (int i = 0; i < mianList4.Count; i++)
  864. // {
  865. // XiaoCePeizhi.SetValue(name_arr[i], i, _index);
  866. // }
  867. //}
  868. var sb = new StringBuilder();
  869. foreach (var name2 in name_arr)
  870. {
  871. sb.Append(name2);
  872. }
  873. bool ifchastr3 = false;
  874. if (sb.Length > 0)
  875. {
  876. if (!string.IsNullOrEmpty(chastrArr[1])) interfaceList.Add(InserMattressInterfacePz(chastrArr[0], chastrArr[1], 2, name_arr));
  877. interfaceList.Add(InserMattressInterfacePz(chastrArr[0], chastrArr[2], 1, new string[] { "" }));
  878. if (chastrArr.Length > 3)
  879. {
  880. if (chastrArr[3].Contains("说明")) ifchastr3 = true;
  881. interfaceList.Add(InserMattressInterfacePz(chastrArr[0], chastrArr[3], 1, new string[] { "" }));
  882. }
  883. }
  884. foreach (var name in chastrArr)
  885. {
  886. if (string.IsNullOrEmpty(name)) continue;
  887. if (name.Contains("说明") && !ifchastr3)
  888. {
  889. interfaceList.Add(InserMattressInterfacePz(chastrArr[0], name, 1, new string[] { "" }));
  890. }
  891. }
  892. }
  893. private void SetFormulaTypeZeroPzName(u_mattress_mx_mtrl mx, string key, int[] powerArr, string[] name_arr)
  894. {
  895. if (key.Contains("_EMPTY")) key = "";
  896. if (mx.mtrlid > 0 && key.Equals(mx.chastr) && powerArr.Contains(mx.formulakind.Value))
  897. {
  898. if (mx.formulakind == 0 || mx.formulakind == 1 || mx.formulakind == 2 || mx.formulakind == 3 || mx.formulakind == 4)
  899. {
  900. name_arr[0] = AppendToString(name_arr[0], SplitNameCount(mx.mtrlname, Convert.ToInt32(mx.qty.Value)));
  901. }
  902. if (mx.formulakind == 40 || mx.formulakind == 41 || mx.formulakind == 42 || mx.formulakind == 43 || mx.formulakind == 44)
  903. {
  904. name_arr[1] = AppendToString(name_arr[1], SplitNameCount(mx.mtrlname, Convert.ToInt32(mx.qty.Value)));
  905. }
  906. if (mx.formulakind == 50 || mx.formulakind == 51 || mx.formulakind == 52 || mx.formulakind == 53 || mx.formulakind == 54)
  907. {
  908. var mtrlname_temp = mx.mtrlname;
  909. if (!(mx.mtrlname.IndexOf("分") > -1 && mx.thickness == 0 || mx.if_inputqty == 1))
  910. {
  911. mtrlname_temp = $"{mx.thickness.Value.ToString("#,##0.0#")}分{mx.mtrlname}";
  912. }
  913. name_arr[2] = AppendToString(name_arr[2], SplitNameCount(mtrlname_temp, Convert.ToInt32(mx.qty.Value)));
  914. }
  915. if (mx.formulakind == 60 || mx.formulakind == 61 || mx.formulakind == 62 || mx.formulakind == 63 || mx.formulakind == 64)
  916. {
  917. name_arr[3] = AppendToString(name_arr[3], SplitNameCount(mx.mtrlname, Convert.ToInt32(mx.qty.Value)));
  918. }
  919. if (mx.formulakind == 80 || mx.formulakind == 81 || mx.formulakind == 82 || mx.formulakind == 83 || mx.formulakind == 84)
  920. {
  921. name_arr[0] = string.Format("{0}({1})", name_arr[0], mx.mtrlname);
  922. }
  923. }
  924. }
  925. public void AutoSetFormulaTypeOnePz(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  926. {
  927. var diancengList = mxlist.Where(t => t.formulatype == 1).ToList();
  928. var kindDict = new Dictionary<int, string>()
  929. {
  930. { 32,"垫层" },
  931. { 12,"顶布" },
  932. { 13,"毡类" },
  933. { 14,"打底无纺布" },
  934. { 29,"网面布料" },
  935. { 999,"床网" },
  936. { 1201,"顶布裥棉" },
  937. };
  938. var chastrSet = new HashSet<string>() { "大侧", "小侧1", "小侧2", "小侧3", "V侧1", "V侧2", "V侧3" };
  939. var countDict = new Dictionary<string, int>();
  940. foreach (var cha in chastrSet)
  941. {
  942. foreach (var kind in kindDict)
  943. {
  944. countDict.Add($"{cha}-{kind.Value}", 0);
  945. }
  946. }
  947. foreach (var mx in diancengList)
  948. {
  949. var key = $"{mx.chastr}-{kindDict[mx.formulakind.Value]}";
  950. if (mx.formulakind == 999)
  951. {
  952. this.ProcessChuangWangPz(mx, interfaceList, mx.chastr, ++countDict[key]);
  953. }
  954. else if (mx.mtrlid > 0 && mx.formulakind == 1201)
  955. {
  956. this.ProcessDingbuLianMianPz(mx, interfaceList, mx.chastr, ++countDict[key]);
  957. }
  958. else if (mx.mtrlid > 0 && new int[] { 32, 12, 13, 14, 29 }.Contains(mx.formulakind.Value))
  959. {
  960. this.ProcessWangMianBLPz(mx, interfaceList, mx.chastr, kindDict[mx.formulakind.Value], ++countDict[key]);
  961. }
  962. }
  963. if (countDict["大侧-垫层"] > 0)
  964. {
  965. interfaceList.Add(InserMattressInterfacePz("垫层", "大侧垫层生产说明", 1, new string[1]));
  966. }
  967. if (countDict["小侧1-垫层"] > 0)
  968. {
  969. interfaceList.Add(InserMattressInterfacePz("垫层", "小侧垫层生产说明", 1, new string[1]));
  970. }
  971. if (countDict["V侧1-垫层"] > 0)
  972. {
  973. interfaceList.Add(InserMattressInterfacePz("垫层", "V侧垫层生产说明", 1, new string[1]));
  974. }
  975. }
  976. /// <summary>
  977. /// 床网
  978. /// </summary>
  979. /// <param name="mx"></param>
  980. /// <param name="interfaceList"></param>
  981. /// <param name="chastr"></param>
  982. /// <param name="count"></param>
  983. private void ProcessChuangWangPz(u_mattress_mx_mtrl mx, List<u_mattress_interface> interfaceList, string chastr, int count)
  984. {
  985. var name_arr = new string[5];
  986. int bednetid = 0;
  987. int spongeMtrlid = 0; // 是否有海绵包边物料
  988. int spongeTcMtrlid = 0; // 是否有海绵填充物料
  989. cmd.CommandText = @"SELECT u_bednetmx.bednet_height,u_bednetmx.bednetid,u_bednet.sponge_mtrlid,u_bednet.sponge_tc_mtrlid
  990. FROM u_bednetmx WITH (NOLOCK)
  991. INNER JOIN u_bednet WITH (NOLOCK) ON u_bednet.bednetid = u_bednetmx.bednetid
  992. INNER JOIN (
  993. SELECT mtrlid
  994. FROM u_mattress_mx_mtrl WITH (NOLOCK)
  995. INNER JOIN u_mattress_formula WITH (NOLOCK) ON u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  996. WHERE u_mattress_formula.formulakind = 99
  997. AND u_mattress_mx_mtrl.mattressid = @mattressid
  998. AND u_mattress_mx_mtrl.mtrlid > 0
  999. ) v_mattress_mx_mtrl ON u_bednetmx.bednetid = v_mattress_mx_mtrl.mtrlid";
  1000. cmd.Parameters.Clear();
  1001. cmd.Parameters.AddWithValue("@mattressid", mx.mattressid);
  1002. using (var reader = cmd.ExecuteReader())
  1003. {
  1004. while (reader.Read())
  1005. {
  1006. decimal height = Convert.ToDecimal(reader["bednet_height"]);
  1007. if (height == mx.thickness)
  1008. {
  1009. bednetid = Convert.ToInt32(reader["bednetid"]);
  1010. spongeMtrlid = Convert.ToInt32(reader["sponge_mtrlid"]);
  1011. spongeTcMtrlid = Convert.ToInt32(reader["sponge_tc_mtrlid"]);
  1012. }
  1013. }
  1014. }
  1015. if (bednetid > 0)
  1016. {
  1017. var bednetHelper = HelperBase.GetHelper<BedNetHelper>(cmd);
  1018. var bednetQdList = bednetHelper.GetBedNetQingDan(bednetid);
  1019. if (bednetQdList.Any())
  1020. {
  1021. name_arr[0] = bednetQdList[0].pznamemx;
  1022. name_arr[0] += "丨erp编码:";
  1023. cmd.CommandText = @"SELECT u_mattress.erp_mtrlcode
  1024. FROM u_mattress_mx_mtrl WITH (NOLOCK)
  1025. INNER JOIN u_mattress_formula WITH (NOLOCK) ON u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  1026. INNER JOIN u_mattress WITH (NOLOCK) ON u_mattress.mattressid = u_mattress_mx_mtrl.mattressid
  1027. WHERE u_mattress_formula.formulakind = 99
  1028. AND u_mattress.bcptypeid <> 0
  1029. AND u_mattress_mx_mtrl.mtrlid = @bednetid";
  1030. cmd.Parameters.Clear();
  1031. cmd.Parameters.AddWithValue("@bednetid", bednetid);
  1032. using(var reader = cmd.ExecuteReader())
  1033. {
  1034. if (reader.Read())
  1035. {
  1036. name_arr[0] += Convert.ToString(reader["erp_mtrlcode"]);
  1037. }
  1038. }
  1039. }
  1040. }
  1041. if (FuncPowerHelper.CheckFuncPower(cmd, context.tokendata.userid, 98) && "super".Equals(context.tokendata.username.ToLower()))
  1042. {
  1043. interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}", 2, name_arr));
  1044. }
  1045. else
  1046. {
  1047. interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}", 1, name_arr));
  1048. }
  1049. interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}生产说明", 1, new string[] { "" }));
  1050. if (spongeMtrlid > 0) interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}包边海绵条", 1, new string[] { "" }));
  1051. if (spongeTcMtrlid > 0) interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}填充海绵条", 1, new string[] { "" }));
  1052. }
  1053. /// <summary>
  1054. /// 网面布料 / 打底无纺布 / 毡类 / 顶布 / 垫层
  1055. /// </summary>
  1056. /// <param name="mx"></param>
  1057. /// <param name="interfaceList"></param>
  1058. /// <param name="chastr"></param>
  1059. /// <param name="count"></param>
  1060. private void ProcessWangMianBLPz(u_mattress_mx_mtrl mx, List<u_mattress_interface> interfaceList, string chastr, string typename, int count)
  1061. {
  1062. var name_arr = new string[5];
  1063. var mtrlname_temp = mx.mtrlname;
  1064. var chastr_temp = string.Empty;
  1065. if ("顶布".Equals(typename) && count <= 1)
  1066. {
  1067. chastr_temp = $"{chastr}-{typename}";
  1068. }
  1069. else
  1070. {
  1071. chastr_temp = $"{chastr}-{typename}{count}";
  1072. }
  1073. if ((!mx.mtrlname.Contains("分") && mx.thickness > 0) || ("垫层".Equals(typename)))
  1074. {
  1075. mtrlname_temp = $"{mx.thickness.Value.ToString("#,##0.0#")}分{mx.mtrlname}";
  1076. }
  1077. name_arr[0] = mtrlname_temp;
  1078. interfaceList.Add(InserMattressInterfacePz("垫层", chastr_temp, 2, name_arr));
  1079. }
  1080. /// <summary>
  1081. /// 顶布裥棉
  1082. /// </summary>
  1083. /// <param name="mx"></param>
  1084. /// <param name="interfaceList"></param>
  1085. /// <param name="count"></param>
  1086. private void ProcessDingbuLianMianPz(u_mattress_mx_mtrl mx, List<u_mattress_interface> interfaceList, string chastr, int count)
  1087. {
  1088. string chastr_temp = string.Empty;
  1089. string ls_temp = "";
  1090. string[] name_arr = new string[5];
  1091. if ("顶布裥棉1".Equals(mx.mtrlname))
  1092. {
  1093. chastr_temp = $"{chastr}-顶布裥棉";
  1094. for (int i = 0; i < DingBuLianMian.GetLength(0); i++)
  1095. {
  1096. name_arr[i] = DingBuLianMian[0, i];
  1097. }
  1098. }
  1099. else if ("顶布裥棉2".Equals(mx.mtrlname))
  1100. {
  1101. chastr_temp = $"{chastr}-顶布裥棉2";
  1102. for (int i = 0; i < DingBuLianMian.GetLength(0); i++)
  1103. {
  1104. name_arr[i] = DingBuLianMian[1, i];
  1105. }
  1106. }
  1107. else if ("顶布裥棉3".Equals(mx.mtrlname))
  1108. {
  1109. chastr_temp = $"{chastr}-顶布裥棉3";
  1110. for (int i = 0; i < DingBuLianMian.GetLength(0); i++)
  1111. {
  1112. name_arr[i] = DingBuLianMian[2, i];
  1113. }
  1114. }
  1115. else if ("顶布裥棉4".Equals(mx.mtrlname))
  1116. {
  1117. chastr_temp = $"{chastr}-顶布裥棉4";
  1118. for (int i = 0; i < DingBuLianMian.GetLength(0); i++)
  1119. {
  1120. name_arr[i] = DingBuLianMian[3, i];
  1121. }
  1122. }
  1123. interfaceList.Add(InserMattressInterfacePz("垫层", chastr_temp, 2, name_arr));
  1124. }
  1125. private void AutoSetFormulaTypeTwoPz(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  1126. {
  1127. var nameSet = new HashSet<string>(new string[] {
  1128. "白色无字包角", "保用卡", "采购小标", "打钮钮扣", "打印小标", "合格证", "画纸", "角网+拉链",
  1129. "开箱刀+开箱说明", "开箱说明+开箱刀", "气钮", "吊标", "说明书", "斜标", "正标", "织唛",
  1130. "织唛斜标", "客供标", "空白牛皮纸包角", "空白珍珠包角"
  1131. });
  1132. // 按照nameSet排序
  1133. //Dictionary<string, int> orderDict = nameSet.Select((name, index) => new { Name = name, Index = index }).ToDictionary(x => x.Name, x => x.Index);
  1134. //var fuliaoList = mxlist.Where(t => t.formulatype == 2).OrderBy(t => orderDict.ContainsKey(t.mtrlname) ? orderDict[t.mtrlname] : int.MaxValue).ThenBy(t => !orderDict.ContainsKey(t.mtrlname) ? t.mtrlname : null).ToList();
  1135. var resultDict = new Dictionary<int, u_mattress_mx_mtrl>();
  1136. foreach (var item in mxlist.Where(t => t.formulatype == 2))
  1137. {
  1138. if (!resultDict.ContainsKey(item.mtrlid.Value))
  1139. {
  1140. resultDict.Add(item.mtrlid.Value, item);
  1141. }
  1142. else
  1143. {
  1144. resultDict[item.mtrlid.Value].qty += item.qty.Value;
  1145. }
  1146. }
  1147. var fuliaoList = new List<u_mattress_mx_mtrl>();
  1148. foreach (var kvp in resultDict)
  1149. {
  1150. fuliaoList.Add(kvp.Value);
  1151. }
  1152. //fuliaoList = fuliaoList.OrderBy(t => orderDict.ContainsKey(t.mtrlname) ? orderDict[t.mtrlname] : int.MaxValue)
  1153. // .ThenBy(t => !orderDict.ContainsKey(t.mtrlname) ? t.mtrlname : null)
  1154. // .ToList();
  1155. var extraSet = new HashSet<string>(new string[] { "采购小标", "打印小标", "合格证", "吊标", "斜标", "正标", "织唛", "织唛斜标", "客供标" });
  1156. var specialSet = new HashSet<string>(new string[] { "打钮钮扣", "气钮" });
  1157. foreach (var mx in fuliaoList)
  1158. {
  1159. if (mx.mtrlid > 0)
  1160. {
  1161. int cnt = Convert.ToInt32(Math.Abs(mx.qty.Value));
  1162. var mtrldef = Cache.GetData<u_mtrl_price, MtrlMapping>(mx.mtrlid.Value);
  1163. if(mtrldef != null) mx.erp_mtrlid = mtrldef.erp_mtrlid;
  1164. // 处理特殊辅料
  1165. if (specialSet.Any(x => mx.mtrlname.Contains(x)) || mtrldef.is_singleqty == 1)
  1166. {
  1167. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}", 1, new string[] { $"{cnt.ToString("#,##0.0#")}个" }));
  1168. continue; // 跳过后续的处理
  1169. }
  1170. // 处理其他辅料
  1171. if (nameSet.Contains(mx.mtrlname))
  1172. {
  1173. for (int i = 1; i <= cnt; i++)
  1174. {
  1175. // 添加辅料接口
  1176. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}", 1, new string[] { "" }));
  1177. // 如果是额外的辅料,添加位置接口
  1178. if (extraSet.Contains(mx.mtrlname))
  1179. {
  1180. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}位置", 0, new string[] { "" }));
  1181. }
  1182. }
  1183. }else if(mx.formulakind == 15 && !nameSet.Contains(mx.mtrlname))
  1184. {
  1185. for (int i = 1; i <= cnt; i++)
  1186. {
  1187. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}", 1, new string[] { "" }));
  1188. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}位置", 0, new string[] { "" }));
  1189. }
  1190. }
  1191. }
  1192. }
  1193. }
  1194. private void AutoSetFormulaTypeThreePz(u_mattress mattress, List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  1195. {
  1196. // 筛选 formulatype 为 3 的物料
  1197. var bzList = mxlist.Where(t => t.formulatype == 3).ToList();
  1198. var chastrDict = new Dictionary<int, string>
  1199. {
  1200. {16, "PE袋"},
  1201. {17, "外层PE"},
  1202. {18, "PVC"},
  1203. {19, "卷包包装"},
  1204. {20, "牛皮纸袋"},
  1205. {21, "蓝色PE护角"},
  1206. {22, "无纺布袋"},
  1207. {23, "牛皮袋护角"},
  1208. {24, "编织袋"},
  1209. {27, "拉手脚轮"},
  1210. {201, "无纺布护角"}
  1211. };
  1212. // 判断是否多物料
  1213. var formulaList = new List<u_mattress_formula>();
  1214. DbSqlHelper.Select(cmd, "u_mattress_formula", "formulatype = 3 AND if_mtrl = 2",null, "formulakind", 0,0, formulaList, null, "formulakind");
  1215. var countDict = new Dictionary<int, int>();
  1216. foreach (var formula in formulaList)
  1217. {
  1218. if (!countDict.ContainsKey(formula.formulakind.Value)) countDict.Add(formula.formulakind.Value, 1);
  1219. }
  1220. // 外观
  1221. interfaceList.Add(InserMattressInterfacePz("床垫", "包装方式", 1, new string[] { Enum.GetName(typeof(PackType), mattress.packtype) }));
  1222. if(mattress.packtype.Value == ((int)PackType.卷包))
  1223. {
  1224. // 卷包
  1225. interfaceList.Add(InserMattressInterfacePz("床垫", "卷包方式", 1, new string[] { "" }));
  1226. }
  1227. foreach (var mx in bzList)
  1228. {
  1229. if (mx.mtrlid > 0 && chastrDict.TryGetValue(mx.formulakind.GetValueOrDefault(), out var chastr))
  1230. {
  1231. var name_arr = new string[1];
  1232. if (mx.qty.HasValue && mx.qty.Value > 1)
  1233. {
  1234. name_arr[0] = $"{mx.qty.Value.ToString("#,##0.0#")}个{mx.mtrlname}";
  1235. }
  1236. else
  1237. {
  1238. name_arr[0] = mx.mtrlname;
  1239. }
  1240. if (countDict.ContainsKey(mx.formulakind.Value))
  1241. {
  1242. chastr += countDict[mx.formulakind.Value]++;
  1243. }
  1244. // 添加包装信息
  1245. interfaceList.Add(InserMattressInterfacePz("包装", chastr, 2, name_arr));
  1246. }
  1247. }
  1248. // 压包数量
  1249. interfaceList.Add(InserMattressInterfacePz("包装", "压包数量", 1, new string[] { $"{mattress.packqty.Value.ToString("#,##0.0#")}" }));
  1250. // 包装说明
  1251. interfaceList.Add(InserMattressInterfacePz("包装", "包装说明", 1, new string[] { "" }));
  1252. // 压包说明
  1253. if (mattress.packqty.HasValue && mattress.packqty.Value > 0) interfaceList.Add(InserMattressInterfacePz("包装", "压包说明", 1, new string[] { "" }));
  1254. // 卷包说明
  1255. if (mattress.diameter.HasValue && mattress.diameter.Value > 0) interfaceList.Add(InserMattressInterfacePz("包装", "卷包说明", 1, new string[] { "" }));
  1256. }
  1257. private void AutoSetFormulaType101Pz(u_mattress mattress, List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  1258. {
  1259. var powerDict = new Dictionary<string, int[]>()
  1260. {
  1261. {"面裥绵",new int[] { 0, 40, 50, 60, 70 } },
  1262. {"底裥绵",new int[] { 1, 41, 51, 61, 71 } },
  1263. {"普通大侧",new int[] { 2, 42, 52, 62, 72 } }
  1264. };
  1265. var chastrDict = new Dictionary<string, string[]>()
  1266. {
  1267. {"面裥绵",new string[] { "内布套-面层裥棉", "内布套-面层裥棉裥棉图案" } },
  1268. {"底裥绵",new string[] { "内布套-底层裥棉", "内布套-底层裥棉裥棉图案" } },
  1269. {"普通大侧",new string[] { "内布套-大侧裥棉", "内布套-大侧裥棉裥棉图案" } }
  1270. };
  1271. foreach (var item in powerDict)
  1272. {
  1273. var name_arr = new string[5];
  1274. foreach (var mx in mxlist)
  1275. {
  1276. SetFormulaTypeZeroPzName(mx, "内布套", item.Value, name_arr);
  1277. }
  1278. var sb = new StringBuilder();
  1279. foreach (var name2 in name_arr)
  1280. {
  1281. sb.Append(name2);
  1282. }
  1283. if (sb.Length > 0)
  1284. {
  1285. interfaceList.Add(InserMattressInterfacePz("内布套", chastrDict[item.Key][0], 2, name_arr));
  1286. interfaceList.Add(InserMattressInterfacePz("内布套", chastrDict[item.Key][1], 1, new string[] { "" }));
  1287. }
  1288. }
  1289. // 内布套-围边边带 / 拉链
  1290. foreach (var mx in mxlist)
  1291. {
  1292. if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 203)
  1293. {
  1294. interfaceList.Add(InserMattressInterfacePz("内布套", "内布套-围边边带", 2, new string[] { $"{mx.thickness.Value.ToString("#,##0.0#")}条共{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  1295. }
  1296. else if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 202)
  1297. {
  1298. interfaceList.Add(InserMattressInterfacePz("内布套", "内布套-拉链", 2, new string[] { $"{mx.thickness.Value.ToString("#,##0.0#")}条共{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  1299. }
  1300. }
  1301. var butaostring = new string[] { };
  1302. if (mattress.if_n_butao == 1)
  1303. {
  1304. butaostring = new string[] { $"内布套面层向大侧覆盖{mattress.s_cover_qty.Value.ToString("#,##0.0#")}CM、内布套大侧向底层覆盖{mattress.z_cover_qty.Value.ToString("#,##0.0#")}CM、内布套底层向大侧覆盖{mattress.x_cover_qty.Value.ToString("#,##0.0#")}CM" };
  1305. interfaceList.Add(InserMattressInterfacePz("内布套", "内布套做法说明", 1, butaostring));
  1306. }
  1307. }
  1308. #endregion
  1309. #region 导入清单方法
  1310. public List<u_mattress_interface_qd> RefreshMattressInterfaceQdList(int mattressid)
  1311. {
  1312. var qdList = new List<u_mattress_interface_qd>();
  1313. ImportMattressInterfaceQdList(mattressid, qdList);
  1314. MattressInterfaceFindERPPrdPf(qdList,null);
  1315. return qdList;
  1316. }
  1317. /// <summary>
  1318. /// wf_fine_erp_prdpf
  1319. /// </summary>
  1320. /// <param name="qdList"></param>
  1321. /// <param name="interfaceList"></param>
  1322. public void MattressInterfaceFindERPPrdPf(List<u_mattress_interface_qd> qdList,List<u_mattress_interface> interfaceList = null)
  1323. {
  1324. InterfaceFindERPPrdPf(qdList,interfaceList);
  1325. }
  1326. /// <summary>
  1327. /// 导入产品清单
  1328. /// </summary>
  1329. /// <param name="mattressid"></param>
  1330. /// <exception cref="LJCommonException"></exception>
  1331. public void ImportMattressInterfaceQdList(int mattressid, List<u_mattress_interface_qd> qdList)
  1332. {
  1333. if (mattressid <= 0)
  1334. {
  1335. throw new LJCommonException("床垫id有误");
  1336. }
  1337. var mattressHelper = GetHelper<MattressHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  1338. var mattress = mattressHelper.GetMattress(mattressid);
  1339. var mattress_type = new u_mattress_type() { mattresstypeid = mattress.mattresstypeid };
  1340. DbSqlHelper.SelectOne(cmd, mattress_type, "typename");
  1341. var mxlist = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype IN (0,1,2,3,99,104)" });
  1342. var mxlist_103 = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype = 103" });
  1343. var mxlist_101 = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype = 101" });
  1344. #region 面料类清单导入
  1345. AutoSetFormulaTypeZeroPrdPf(mxlist, qdList);
  1346. #endregion
  1347. #region 垫层类清单导入
  1348. AutoSetFormulaTypeOnePrdPf(mxlist, qdList);
  1349. #endregion
  1350. #region 辅料类清单导入
  1351. AutoSetFormulaTypeTwoPrfPf(mxlist, qdList);
  1352. #endregion
  1353. #region 包装类清单导入
  1354. AutoSetFormulaTypeThreePrdPf(mxlist, qdList);
  1355. #endregion
  1356. #region 内布套类清单导入
  1357. AutoSetFormulaType101PrdPf(mxlist_103, qdList);
  1358. #endregion
  1359. // 最后初始化interfaceList的printid
  1360. for (var i = 0; i < qdList.Count; i++)
  1361. {
  1362. qdList[i].printid = i + 1;
  1363. }
  1364. }
  1365. /// <summary>
  1366. /// 初始化清单信息
  1367. /// </summary>
  1368. /// <param name="itemname"></param>
  1369. /// <param name="bj_pzname"></param>
  1370. /// <param name="inputtype"></param>
  1371. /// <param name="names"></param>
  1372. /// <returns></returns>
  1373. public u_mattress_interface_qd InserMattressInterfacePrdPf(string itemname, string bj_pzname, string namemx, int mtrlid, decimal useqty, int formulaid = 0)
  1374. {
  1375. var _bcpcompare = new u_bcpcompare() { pzname = bj_pzname };
  1376. var _wip_type = "";
  1377. var _wrkgrpcode2 = "";
  1378. if (DbSqlHelper.SelectOne(cmd, _bcpcompare, "wip_type, wrkgrpcode2") == 1)
  1379. {
  1380. _wip_type = _bcpcompare.wip_type;
  1381. _wrkgrpcode2 = _bcpcompare.wrkgrpcode2;
  1382. }
  1383. var mattress_interface_qd = new u_mattress_interface_qd()
  1384. {
  1385. itemname = itemname,
  1386. bj_pzname = bj_pzname,
  1387. bj_pzname_mx = namemx,
  1388. mtrlid = mtrlid,
  1389. useqty = useqty,
  1390. formulaid = formulaid,
  1391. wip_type = _wip_type,
  1392. wrkgrpcode2 = _wrkgrpcode2
  1393. };
  1394. return mattress_interface_qd;
  1395. }
  1396. public u_mattress_interface_qd InserMattressInterfacePrdPf(string itemname, string bj_pzname, string namemx)
  1397. {
  1398. var mattress_interface_qd = new u_mattress_interface_qd()
  1399. {
  1400. itemname = itemname,
  1401. bj_pzname = bj_pzname,
  1402. bj_pzname_mx = namemx
  1403. };
  1404. return mattress_interface_qd;
  1405. }
  1406. private void AutoSetFormulaTypeZeroPrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1407. {
  1408. var powerDict = new Dictionary<string, int[]>()
  1409. {
  1410. {"面裥绵",new int[] { 0, 40, 50, 60, 70, 80 } },
  1411. {"底裥绵",new int[] { 1, 41, 51, 61, 71, 81 } },
  1412. {"顶布裥棉1",new int[] { 0, 40, 50, 60, 70, 80 } },
  1413. {"顶布裥棉2",new int[] { 0, 40, 50, 60, 70, 80 } },
  1414. {"普通大侧",new int[] { 2, 42, 52, 62, 72, 82 } },
  1415. {"上下拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  1416. {"上下拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  1417. {"上下拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  1418. {"左右拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  1419. {"左右拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  1420. {"左右拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  1421. {"小侧1_EMPTY",new int[] { 3, 43, 53, 63, 73, 83 } },
  1422. {"小侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  1423. {"小侧1-上下拼侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  1424. {"小侧1-上下拼侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  1425. {"小侧1-上下拼侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  1426. {"小侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  1427. {"小侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  1428. {"V侧1_EMPTY",new int[] { 4, 44, 54, 64, 74, 84 } },
  1429. {"V侧1",new int[] { 4, 44, 54, 64, 74, 84 } },
  1430. {"V侧2",new int[] { 4, 44, 54, 64, 74, 84 } },
  1431. {"V侧3",new int[] { 4, 44, 54, 64, 74, 84 } }
  1432. };
  1433. var chastrArrDict = new Dictionary<string, string[]>()
  1434. {
  1435. {"面裥绵",new string[] { "裥面", "面层裥棉", "面层裥面说明" } },
  1436. {"底裥绵",new string[] { "裥底", "底层裥棉", "底层裥棉说明" } },
  1437. {"顶布裥棉1",new string[] { "顶布裥棉", "顶布裥棉1" } },
  1438. {"顶布裥棉2",new string[] { "顶布裥棉", "顶布裥棉2" } },
  1439. {"普通大侧",new string[] { "大侧", "大侧裥棉"} },
  1440. {"上下拼侧1",new string[] {"大侧", "大侧-上下拼侧1"} },
  1441. {"上下拼侧2",new string[] { "大侧", "大侧-上下拼侧2" } },
  1442. {"上下拼侧3",new string[] { "大侧", "大侧-上下拼侧3" } },
  1443. {"左右拼侧1",new string[] { "大侧", "大侧-左右拼侧1"} },
  1444. {"左右拼侧2",new string[] { "大侧", "大侧-左右拼侧2"} },
  1445. {"左右拼侧3",new string[] { "大侧", "大侧-左右拼侧3" ,"大侧说明" } },
  1446. {"小侧1_EMPTY",new string[] { "小侧", "小侧1裥棉" } },
  1447. {"小侧1",new string[] { "小侧", "小侧1裥棉"} },
  1448. {"小侧1-上下拼侧1",new string[] { "小侧", "小侧1-上下拼侧1裥棉" } },
  1449. {"小侧1-上下拼侧2",new string[] { "小侧", "小侧1-上下拼侧2裥棉" } },
  1450. {"小侧1-上下拼侧3",new string[] { "小侧", "小侧1-上下拼侧3裥棉" } },
  1451. {"小侧2",new string[] { "小侧", "小侧2裥棉", "小侧2裥棉图案" } },
  1452. {"小侧3",new string[] { "小侧", "小侧3裥棉", "小侧3裥棉图案", "小侧说明" } },
  1453. {"V侧1_EMPTY",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  1454. {"V侧1",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  1455. {"V侧2",new string[] { "V侧", "V侧2裥棉", "V侧2裥棉图案" } },
  1456. {"V侧3",new string[] { "V侧", "V侧3裥棉", "V侧3裥棉图案", "V侧说明" } }
  1457. };
  1458. var extreDict = new HashSet<string>() { "小侧", "V侧" };
  1459. var jianmianList = mxlist.Where(t => t.formulatype == 0).ToList();
  1460. var isEnter = false;
  1461. #region wf_import_qingdan_prdpf
  1462. foreach (var item in powerDict)
  1463. {
  1464. // 保证清单列表类别一致,从面裥绵 -> V侧3
  1465. foreach (var mx in jianmianList)
  1466. {
  1467. if (mx.mtrlid > 0 && (item.Key.Equals(mx.chastr) || (string.IsNullOrEmpty(mx.chastr) && item.Key.Contains("_EMPTY"))) && item.Value.Contains(mx.formulakind.Value))
  1468. {
  1469. if (mx.formulakind == 0 || mx.formulakind == 1 || mx.formulakind == 2 || mx.formulakind == 3 || mx.formulakind == 4)
  1470. {
  1471. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "布料", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1472. }
  1473. if (mx.formulakind == 40 || mx.formulakind == 41 || mx.formulakind == 42 || mx.formulakind == 43 || mx.formulakind == 44)
  1474. {
  1475. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "喷胶棉", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1476. }
  1477. if (mx.formulakind == 50 || mx.formulakind == 51 || mx.formulakind == 52 || mx.formulakind == 53 || mx.formulakind == 54)
  1478. {
  1479. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "裥面海绵", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1480. }
  1481. if (mx.formulakind == 60 || mx.formulakind == 61 || mx.formulakind == 62 || mx.formulakind == 63 || mx.formulakind == 64)
  1482. {
  1483. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "无纺布", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1484. }
  1485. }
  1486. }
  1487. if(item.Key.Contains("小侧3") || item.Key.Contains("V侧3"))
  1488. {
  1489. var list = qdList.FindAll(t => extreDict.Contains(t.itemname)).ToList();
  1490. if(list.Any())
  1491. {
  1492. foreach (var name in chastrArrDict[item.Key])
  1493. {
  1494. if (name.Contains("说明"))
  1495. {
  1496. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], name, ""));
  1497. }
  1498. }
  1499. }
  1500. } else
  1501. {
  1502. foreach (var name in chastrArrDict[item.Key])
  1503. {
  1504. if (name.Contains("说明"))
  1505. {
  1506. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], name, ""));
  1507. }
  1508. }
  1509. }
  1510. }
  1511. #endregion
  1512. #region wf_import_qingdan_next 面料部分
  1513. // 按照 formulakind 分组
  1514. var grouped = jianmianList
  1515. .Where(t => t.formulakind >= 5 && t.formulakind <= 10)
  1516. .GroupBy(t => t.formulakind);
  1517. // 需要处理的组的名称与编号映射
  1518. var groupNames = new Dictionary<int, string>
  1519. {
  1520. { 5, "拉手" },
  1521. { 6, "刺绣" },
  1522. { 7, "大侧压压布" },
  1523. { 8, "大侧压边带" },
  1524. { 9, "大侧压织带" },
  1525. { 10, "大侧压上下压线" }
  1526. };
  1527. // 处理每一组
  1528. foreach (var group in grouped)
  1529. {
  1530. var formulakind = group.Key.Value;
  1531. var name = groupNames.ContainsKey(formulakind) ? groupNames[formulakind] : "未知组";
  1532. foreach (var mx in group)
  1533. {
  1534. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  1535. {
  1536. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺",$"{name}{group.ToList().IndexOf(mx) + 1}","",
  1537. mx.mtrlid.Value,
  1538. mx.useqty.Value
  1539. ));
  1540. }
  1541. }
  1542. }
  1543. // 统一添加固定项
  1544. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺", "拉手刺绣", ""));
  1545. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺", "拉手无纺布", ""));
  1546. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺", "侧刺绣做法", ""));
  1547. #endregion
  1548. }
  1549. private void AutoSetFormulaTypeOnePrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1550. {
  1551. var diancengList = mxlist.Where(t => t.formulatype == 1).ToList();
  1552. var kindDict = new Dictionary<int, string>()
  1553. {
  1554. { 32,"垫层" },
  1555. { 12,"顶布" },
  1556. { 13,"毡类" },
  1557. { 14,"打底无纺布" },
  1558. { 29,"网面布料" },
  1559. { 999,"床网" },
  1560. {1201,"顶布裥棉" }
  1561. };
  1562. var chastrSet = new HashSet<string>() { "大侧", "小侧1", "小侧2", "小侧3", "V侧1", "V侧2", "V侧3" };
  1563. var countDict = new Dictionary<string, int>();
  1564. foreach (var cha in chastrSet)
  1565. {
  1566. foreach (var kind in kindDict)
  1567. {
  1568. countDict.Add($"{cha}-{kind.Value}", 0);
  1569. }
  1570. }
  1571. foreach (var mx in diancengList)
  1572. {
  1573. var key = $"{mx.chastr}-{kindDict[mx.formulakind.Value]}";
  1574. if (mx.mtrlid > 0 && new int[] { 32, 12, 13, 14, 29 }.Contains(mx.formulakind.Value))
  1575. {
  1576. this.ProcessWangMianBLPrdPf(mx, qdList, mx.chastr, kindDict[mx.formulakind.Value], ++countDict[key]);
  1577. } else if (mx.formulakind == 999)
  1578. {
  1579. this.ProcessChuangWangPrdPf(mx, qdList, mx.chastr, ++countDict[key]);
  1580. } else if(mx.formulakind == 1201)
  1581. {
  1582. // 不需要操作
  1583. }
  1584. }
  1585. // 顶布裥面说明
  1586. qdList.Add(InserMattressInterfacePrdPf("顶布裥棉", "顶布裥面说明1", ""));
  1587. qdList.Add(InserMattressInterfacePrdPf("顶布裥棉", "顶布裥面说明2", ""));
  1588. }
  1589. /// <summary>
  1590. /// 床网
  1591. /// </summary>
  1592. /// <param name="mx"></param>
  1593. /// <param name="interfaceList"></param>
  1594. /// <param name="chastr"></param>
  1595. /// <param name="count"></param>
  1596. private void ProcessChuangWangPrdPf(u_mattress_mx_mtrl mx, List<u_mattress_interface_qd> qdList, string chastr, int count)
  1597. {
  1598. var namepz = string.Empty;
  1599. int bednetid = 0;
  1600. cmd.CommandText = @"SELECT u_bednetmx.bednet_height,u_bednetmx.bednetid
  1601. FROM u_bednetmx WITH (NOLOCK)
  1602. INNER JOIN (
  1603. SELECT mtrlid
  1604. FROM u_mattress_mx_mtrl WITH (NOLOCK)
  1605. INNER JOIN u_mattress_formula WITH (NOLOCK) ON u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  1606. WHERE u_mattress_formula.formulakind = 99
  1607. AND u_mattress_mx_mtrl.mattressid = @mattressid
  1608. AND u_mattress_mx_mtrl.mtrlid > 0
  1609. ) v_mattress_mx_mtrl ON u_bednetmx.bednetid = v_mattress_mx_mtrl.mtrlid";
  1610. cmd.Parameters.Clear();
  1611. cmd.Parameters.AddWithValue("@mattressid", mx.mattressid);
  1612. using (var reader = cmd.ExecuteReader())
  1613. {
  1614. while (reader.Read())
  1615. {
  1616. decimal height = Convert.ToDecimal(reader["bednet_height"]);
  1617. if (height == mx.thickness) bednetid = Convert.ToInt32(reader["bednetid"]);
  1618. }
  1619. }
  1620. if (bednetid > 0)
  1621. {
  1622. // 获取床网清单
  1623. var bednetList = new List<u_bednetmx>();
  1624. if (bednetList.Any())
  1625. {
  1626. var bednetHelper = HelperBase.GetHelper<BedNetHelper>(cmd);
  1627. var bednetQdList = bednetHelper.GetBedNetQingDan(bednetid);
  1628. if (bednetQdList.Any())
  1629. {
  1630. namepz = bednetQdList[0].pznamemx;
  1631. }
  1632. }
  1633. }
  1634. qdList.Add(InserMattressInterfacePrdPf("垫层", $"{chastr}-床网{count}", namepz, bednetid, mx.useqty.Value));
  1635. // 海绵条*4 2
  1636. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条1", ""));
  1637. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条2", ""));
  1638. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条3", ""));
  1639. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条4", ""));
  1640. }
  1641. /// <summary>
  1642. /// 网面布料 / 打底无纺布 / 毡类 / 顶布 / 垫层
  1643. /// </summary>
  1644. /// <param name="mx"></param>
  1645. /// <param name="interfaceList"></param>
  1646. /// <param name="chastr"></param>
  1647. /// <param name="count"></param>
  1648. private void ProcessWangMianBLPrdPf(u_mattress_mx_mtrl mx, List<u_mattress_interface_qd> qdList, string chastr, string typename, int count)
  1649. {
  1650. var mtrlname_temp = mx.mtrlname;
  1651. if ((!mx.mtrlname.Contains("分") && mx.thickness > 0) || ("垫层".Equals(typename)))
  1652. {
  1653. mtrlname_temp = $"{mx.thickness.Value.ToString("#,##0.0#")}分{mx.mtrlname}";
  1654. }
  1655. qdList.Add(InserMattressInterfacePrdPf("垫层", $"{chastr}-{typename}{count}", "",mx.mtrlid.Value,mx.useqty.Value));
  1656. }
  1657. private void AutoSetFormulaTypeTwoPrfPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1658. {
  1659. var fuliaoList = mxlist.Where(t => t.formulatype == 2).ToList();
  1660. var nameSet = new HashSet<string>(new string[] {
  1661. "保用卡", "采购小标", "打钮钮扣", "打印小标", "合格证", "画纸", "开箱说明+开箱刀", "吊标", "客供标",
  1662. "空白牛皮纸包角", "空白珍珠包角", "气钮","说明书","斜标","正标","织唛","织唛斜标"
  1663. });
  1664. var extraSet = new HashSet<string>(new string[] { "保用卡", "采购小标", "打钮钮扣", "打印小标", "合格证", "画纸", "开箱说明+开箱刀", "吊标", "客供标",
  1665. "空白牛皮纸包角", "空白珍珠包角", "气钮","说明书","斜标","正标","织唛","织唛斜标","角网+拉链","开箱刀+开箱说明" });
  1666. var specialSet = new HashSet<string>(new string[] { "打钮钮扣", "气钮" });
  1667. foreach (var mx in fuliaoList)
  1668. {
  1669. if (mx.mtrlid > 0)
  1670. {
  1671. int cnt = Convert.ToInt32(Math.Abs(mx.qty.Value));
  1672. var mtrldef = Cache.GetData<u_mtrl_price, MtrlMapping>(mx.mtrlid.Value);
  1673. // 处理特殊辅料
  1674. if (specialSet.Contains(mx.mtrlname) || (mtrldef != null && mtrldef.is_singleqty == 1))
  1675. {
  1676. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}", "", mx.mtrlid.Value, mx.useqty.Value));
  1677. continue; // 跳过后续的处理
  1678. }
  1679. // 处理其他辅料
  1680. if (nameSet.Contains(mx.mtrlname))
  1681. {
  1682. for (int i = 1; i <= cnt; i++)
  1683. {
  1684. // 添加辅料接口
  1685. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}{i}", "",mx.mtrlid.Value,mx.useqty.Value));
  1686. }
  1687. } else if(mx.formulakind == 15 && !extraSet.Contains(mx.mtrlname))
  1688. {
  1689. for (int i = 1; i <= cnt; i++)
  1690. {
  1691. // 添加辅料接口
  1692. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}{i}", "", mx.mtrlid.Value, mx.useqty.Value));
  1693. // 如果是额外的辅料,添加位置接口
  1694. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}{i}位置", "", mx.mtrlid.Value, mx.useqty.Value));
  1695. }
  1696. }
  1697. }
  1698. }
  1699. }
  1700. private void AutoSetFormulaTypeThreePrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1701. {
  1702. // 筛选 formulatype 为 3 的物料
  1703. var bzList = mxlist.Where(t => t.formulatype == 3).ToList();
  1704. var chastrDict = new Dictionary<int, string>
  1705. {
  1706. {16, "PE袋"},
  1707. {17, "外层PE"},
  1708. {18, "PVC"},
  1709. {19, "卷包包装"},
  1710. {20, "牛皮纸袋"},
  1711. {21, "蓝色PE护角"},
  1712. {22, "无纺布袋"},
  1713. {23, "牛皮袋护角"},
  1714. {24, "编织袋"},
  1715. {27, "拉手脚轮"},
  1716. {201, "无纺布护角"}
  1717. };
  1718. var countDict = new Dictionary<int, int>
  1719. {
  1720. {16, 0}
  1721. };
  1722. foreach (var mx in bzList)
  1723. {
  1724. if (mx.mtrlid > 0 && chastrDict.TryGetValue(mx.formulakind.GetValueOrDefault(), out var chastr))
  1725. {
  1726. var name_arr = new string[1];
  1727. if (mx.qty.HasValue && mx.qty.Value > 1)
  1728. {
  1729. name_arr[0] = $"{mx.qty.Value.ToString("#,##0.0#")}个{mx.mtrlname}";
  1730. }
  1731. else
  1732. {
  1733. name_arr[0] = mx.mtrlname;
  1734. }
  1735. if (countDict.ContainsKey(mx.formulakind.Value))
  1736. {
  1737. chastr += countDict[mx.formulakind.Value];
  1738. }
  1739. // 添加包装信息
  1740. qdList.Add(InserMattressInterfacePrdPf("包装", chastr,"",mx.mtrlid.Value,mx.useqty.Value));
  1741. }
  1742. }
  1743. // 包装说明
  1744. qdList.Add(InserMattressInterfacePrdPf("包装", "包装说明", ""));
  1745. // 车位说明
  1746. qdList.Add(InserMattressInterfacePrdPf("车位说明", "车位说明", ""));
  1747. }
  1748. private void AutoSetFormulaType101PrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1749. {
  1750. var powerDict = new Dictionary<string, int[]>()
  1751. {
  1752. {"面裥绵",new int[] { 0, 40, 50, 60, 70,80 } },
  1753. {"底裥绵",new int[] { 1, 41, 51, 61, 71 } },
  1754. {"普通大侧",new int[] { 2, 42, 52, 62, 72 } }
  1755. };
  1756. var chastrDict = new Dictionary<string, string[]>()
  1757. {
  1758. {"面裥绵",new string[] { "内布套-面层裥棉", "内布套-面层裥棉裥棉图案" } },
  1759. {"底裥绵",new string[] { "内布套-底层裥棉", "内布套-底层裥棉裥棉图案" } },
  1760. {"普通大侧",new string[] { "内布套-大侧裥棉", "内布套-大侧裥棉裥棉图案" } }
  1761. };
  1762. foreach (var item in powerDict)
  1763. {
  1764. var name_arr = new string[5];
  1765. foreach (var mx in mxlist)
  1766. {
  1767. if (mx.mtrlid > 0 && (item.Key.Equals(mx.chastr) || item.Key.Contains("_EMPTY")) && item.Value.Contains(mx.formulakind.Value))
  1768. {
  1769. if (mx.formulakind == 0 || mx.formulakind == 1 || mx.formulakind == 2 || mx.formulakind == 3)
  1770. {
  1771. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "布料", mx.mtrlid.Value, mx.useqty.Value));
  1772. }
  1773. if (mx.formulakind == 40 || mx.formulakind == 41 || mx.formulakind == 42 || mx.formulakind == 43)
  1774. {
  1775. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "喷胶棉", mx.mtrlid.Value, mx.useqty.Value));
  1776. }
  1777. if (mx.formulakind == 50 || mx.formulakind == 51 || mx.formulakind == 52 || mx.formulakind == 53)
  1778. {
  1779. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "裥面海绵", mx.mtrlid.Value, mx.useqty.Value));
  1780. }
  1781. if (mx.formulakind == 60 || mx.formulakind == 61 || mx.formulakind == 62 || mx.formulakind == 63)
  1782. {
  1783. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "无纺布", mx.mtrlid.Value, mx.useqty.Value));
  1784. }
  1785. }
  1786. }
  1787. }
  1788. // 内布套-围边边带 / 拉链
  1789. foreach (var mx in mxlist)
  1790. {
  1791. if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 203)
  1792. {
  1793. qdList.Add(InserMattressInterfacePrdPf("内布套", "内布套-围边边带", "围边",mx.mtrlid.Value,mx.useqty.Value));
  1794. }
  1795. else if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 202)
  1796. {
  1797. qdList.Add(InserMattressInterfacePrdPf("内布套", "内布套-拉链", "拉链", mx.mtrlid.Value, mx.useqty.Value));
  1798. }
  1799. }
  1800. }
  1801. #endregion
  1802. #region 床网清单
  1803. /// <summary>
  1804. /// 床垫接口-保存
  1805. /// </summary>
  1806. /// <param name="mattress"></param>
  1807. /// <param name="mxlist"></param>
  1808. /// <param name="qdlist"></param>
  1809. /// <exception cref="LJCommonException"></exception>
  1810. public void SaveBedNetInterface(u_bednet bednet, List<u_bednet_interface> mxlist, List<u_bednet_interface_qd> qdlist)
  1811. {
  1812. if (bednet.bednetid <= 0)
  1813. {
  1814. throw new LJCommonException("错误的床网id");
  1815. }
  1816. if (bednet.erp_mtrltypeid == null || bednet.erp_mtrltypeid <= 0)
  1817. {
  1818. throw new LJCommonException("请选择物料类别!");
  1819. }
  1820. if (bednet.erp_configcodetype == null || bednet.erp_configcodetype <= 0)
  1821. {
  1822. throw new LJCommonException("请选择配置类型!");
  1823. }
  1824. DbSqlHelper.Update(cmd, bednet, "erp_mtrlid,erp_mtrltypeid,erp_mtrlcode,erp_mtrlname,erp_mtrlmode,erp_mtrltype,erp_mtrlunit,erp_mtrlengname,erp_configcodetype,old_mtrlname");
  1825. // 保存接口数据
  1826. var bednetHelper = GetHelper<BedNetHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  1827. bednetHelper.SaveBedNetInterface(bednet.bednetid.Value, mxlist, qdlist);
  1828. }
  1829. public List<u_bednet_interface> GetBedNetInterfaceList(int bednetid)
  1830. {
  1831. var interfaceList = new List<u_bednet_interface>();
  1832. var selectStr = @"SELECT bednetid
  1833. ,printid
  1834. ,itemname
  1835. ,bj_pzname
  1836. ,bj_namemx
  1837. ,actual_size
  1838. ,erp_pzid
  1839. ,Space(200) AS erp_pzcode
  1840. ,Space(200) AS erp_pzname
  1841. ,bj_inputtype AS erp_inputtype
  1842. FROM u_bednet_interface";
  1843. DbSqlHelper.SelectJoin(cmd, selectStr, "bednetid = @bednetid", new Dictionary<string, object>() { { "@bednetid", bednetid } }, "printid", "bednetid,printid,itemname,bj_pzname,bj_namemx,actual_size,erp_pzid,ss_rate,ls_rate,bj_inputtype", 0, 0, interfaceList);
  1844. if (interfaceList.Count <= 0)
  1845. {
  1846. interfaceList = RefreshBedNetInterfaceList(bednetid);
  1847. }
  1848. else
  1849. {
  1850. BedNetInterfaceFindERPPz(bednetid,interfaceList);
  1851. }
  1852. return interfaceList;
  1853. }
  1854. public List<u_bednet_interface> RefreshBedNetInterfaceList(int bednetid)
  1855. {
  1856. var interfaceList = new List<u_bednet_interface>();
  1857. // 导入配置
  1858. ImportBedNetInterfaceList(bednetid, interfaceList);
  1859. BedNetInterfaceFindERPPz(bednetid, interfaceList);
  1860. return interfaceList;
  1861. }
  1862. public List<u_bednet_interface> RefreshBedNetInterfaceList(int bednetid,int configcodetype)
  1863. {
  1864. var interfaceList = new List<u_bednet_interface>();
  1865. // 导入配置
  1866. ImportBedNetInterfaceList(bednetid, interfaceList);
  1867. InterfaceFindERPPz(configcodetype, interfaceList);
  1868. return interfaceList;
  1869. }
  1870. public void ImportBedNetInterfaceList(int bednetid, List<u_bednet_interface> interfaceList)
  1871. {
  1872. if (bednetid <= 0)
  1873. {
  1874. throw new LJCommonException("床网id有误");
  1875. }
  1876. var bednetHelper = GetHelper<BedNetHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  1877. //var bednet = bednetHelper.GetBedNet(bednetid);
  1878. var qdlist = bednetHelper.GetBedNetQingDan(bednetid);
  1879. foreach(var qd in qdlist)
  1880. {
  1881. interfaceList.Add(InserBedNetInterfacePz("床网",qd.pzname,2,new string[] { qd.pznamemx }));
  1882. }
  1883. // 床网名称
  1884. // 床网类型 NOTES: 床网类型 袋装网需要区分x区
  1885. // 床网规格
  1886. // 床网排序
  1887. // 床网高度
  1888. // 弹簧线径/高度/口径/中心直径/圈数
  1889. // 多区弹簧1/线径/口径/中心直径/圈数
  1890. // 多区弹簧1排列数(长)
  1891. // 多区弹簧2/线径/口径/中心直径/圈数
  1892. // 多区弹簧2排列数(长)
  1893. // 多区弹簧3/线径/口径/中心直径/圈数
  1894. // 多区弹簧3排列数(长)
  1895. // 多区弹簧4/线径/口径/中心直径/圈数
  1896. // 多区弹簧4排列数(长)
  1897. // 多区弹簧5/线径/口径/中心直径/圈数
  1898. // 多区弹簧5排列数(长)
  1899. // 边铁条数
  1900. // 底面无纺布
  1901. // 入袋无纺布
  1902. // 上垫层物料
  1903. // 下垫层物料
  1904. // 四周加硬排数
  1905. // 四周加硬线径/高度/口径/中心直径/圈数
  1906. // 海绵包边物料
  1907. // 海绵包边物料厚度
  1908. // 填充海绵物料
  1909. // 填充包边物料厚度
  1910. // 封边物料
  1911. // 封边高度
  1912. // 胶条
  1913. // 包角
  1914. // 海绵打孔
  1915. // 加弹叉数量
  1916. // 15分布条
  1917. // 蛇线线径
  1918. // 四周口袋弹簧排数
  1919. // 四周口袋线径/高度/口径/中心直径/圈数
  1920. // 床网说明
  1921. // 包装方式
  1922. // 包装数量
  1923. // 包装材料
  1924. // 多区弹簧6/线径/口径/中心直径/圈数
  1925. // 多区弹簧7/线径/口径/中心直径/圈数
  1926. // 多区弹簧6排列数(长)
  1927. // 多区弹簧7排列数(长)
  1928. }
  1929. public void BedNetInterfaceFindERPPz(int bednetid, List<u_bednet_interface> interfaceList)
  1930. {
  1931. var bednet = new u_bednet() { bednetid = bednetid };
  1932. DbSqlHelper.SelectOne(cmd, bednet, "erp_configcodetype");
  1933. InterfaceFindERPPz(bednet.erp_configcodetype.Value, interfaceList);
  1934. }
  1935. public u_bednet_interface InserBedNetInterfacePz(string itemname, string bj_pzname, byte inputtype, string[] names)
  1936. {
  1937. return InserInterfacePz<u_bednet_interface>(itemname, bj_pzname, inputtype, names);
  1938. }
  1939. /// <summary>
  1940. /// 刷新床网产品配置清单
  1941. /// </summary>
  1942. /// <param name="bednetid"></param>
  1943. /// <returns></returns>
  1944. public List<u_bednet_interface_qd> RefreshBedNetInterfaceQdList(int bednetid)
  1945. {
  1946. var qdList = new List<u_bednet_interface_qd>();
  1947. ImportBedNetInterfaceQdList(bednetid, qdList);
  1948. InterfaceFindERPPrdPf<u_bednet_interface_qd, u_bednet_interface>(qdList);
  1949. return qdList;
  1950. }
  1951. /// <summary>
  1952. /// 导入产品清单
  1953. /// </summary>
  1954. /// <param name="bednetid"></param>
  1955. /// <exception cref="LJCommonException"></exception>
  1956. public void ImportBedNetInterfaceQdList(int bednetid, List<u_bednet_interface_qd> qdList)
  1957. {
  1958. if (bednetid <= 0)
  1959. {
  1960. throw new LJCommonException("床网id有误");
  1961. }
  1962. }
  1963. #endregion
  1964. #region 通用方法
  1965. /// <summary>
  1966. /// wf_fine_erp_prdpf
  1967. /// </summary>
  1968. /// <param name="qdList"></param>
  1969. /// <param name="interfaceList"></param>
  1970. public void InterfaceFindERPPrdPf<T, S>(List<T> qdList, List<S> interfaceList = null) where T : BaseInterfaceQd where S : BaseInterface
  1971. {
  1972. var mtrlidList = new List<int>();
  1973. foreach (var mx in qdList)
  1974. {
  1975. // 带出有设置 的erp_mtrlid
  1976. if (mx.erp_mtrlid == 0 && mx.mtrlid != null && mx.mtrlid > 0)
  1977. {
  1978. var mtrldef = new u_mtrl_price() { mtrlid = mx.mtrlid };
  1979. if (DbSqlHelper.SelectOne(cmd, mtrldef, "erp_mtrlid") == 1)
  1980. {
  1981. mx.erp_mtrlid = mtrldef.erp_mtrlid;
  1982. }
  1983. }
  1984. if (mx.erp_mtrlid > 0)
  1985. {
  1986. mtrlidList.Add(mx.erp_mtrlid.Value);
  1987. }
  1988. }
  1989. if (mtrlidList.Count > 0)
  1990. {
  1991. var erpHelper = HelperBase.GetHelper<ERPHelper>(null);
  1992. var total = 0;
  1993. var resultList = erpHelper.GetERPMtrldef(cmd, ref total, "", new L1Mtrldef(), 0, 0, 1, mtrlidList);
  1994. if (resultList != null && resultList.Any())
  1995. {
  1996. foreach (var mx in qdList)
  1997. {
  1998. var result = resultList.FirstOrDefault(o => o.mtrlid == mx.erp_mtrlid);
  1999. if (result != null)
  2000. {
  2001. mx.erp_mtrlcode = result.mtrlcode;
  2002. mx.erp_mtrlname = result.mtrlname;
  2003. mx.erp_mtrlmode = result.mtrlmode;
  2004. mx.erp_unit = result.unit;
  2005. mx.erp_mtrlengname = result.zxmtrlmode;
  2006. }
  2007. }
  2008. }
  2009. }
  2010. //更新 二级明细项目 需要产品配置列表,此部分由前端完成
  2011. if (interfaceList != null && interfaceList.Any())
  2012. {
  2013. // 使用 GroupBy 去重并选择第一个元素
  2014. var distinctList = interfaceList
  2015. .GroupBy(mb => mb.bj_pzname)
  2016. .Select(g => g.First())
  2017. .ToList();
  2018. Dictionary<string, S> interfaceDict = distinctList.ToDictionary(mb => mb.bj_pzname, mb => mb);
  2019. foreach (var mx in qdList)
  2020. {
  2021. if (interfaceDict.TryGetValue(mx.bj_pzname, out var mb))
  2022. {
  2023. mx.bj_pzname_mx_mx = mb.bj_namemx;
  2024. if (mx is u_mattress_interface_qd mattressMx && mb is u_mattress_interface mattressMx2)
  2025. {
  2026. if (mattressMx.ss_rate == 0) mattressMx.ss_rate = mattressMx2.ss_rate;
  2027. if (mattressMx.ls_rate == 0) mattressMx.ls_rate = mattressMx2.ls_rate;
  2028. }
  2029. }
  2030. }
  2031. }
  2032. }
  2033. /// <summary>
  2034. /// 初始化配置信息
  2035. /// </summary>
  2036. /// <param name="itemname"></param>
  2037. /// <param name="bj_pzname"></param>
  2038. /// <param name="inputtype"></param>
  2039. /// <param name="names"></param>
  2040. /// <returns></returns>
  2041. public T InserInterfacePz<T>(string itemname, string bj_pzname, byte inputtype, string[] names) where T : BaseInterface, new()
  2042. {
  2043. var mattress_interface = new T()
  2044. {
  2045. itemname = itemname,
  2046. bj_pzname = bj_pzname,
  2047. bj_inputtype = inputtype,
  2048. bj_namemx = names == null ? string.Empty : SetInterfacePzName(names)
  2049. };
  2050. return mattress_interface;
  2051. }
  2052. /// <summary>
  2053. /// 查询清单的配置
  2054. /// </summary>
  2055. /// <param name="configcodetype"></param>
  2056. /// <param name="interfaceList"></param>
  2057. public void InterfaceFindERPPz<T>(int configcodetype, List<T> interfaceList) where T : BaseInterface
  2058. {
  2059. var resultList = new List<erp_configure_code>();
  2060. var typeList = new List<erp_configure_code>();
  2061. // 特殊匹配林氏辅料
  2062. var ifLSAccessory = false;
  2063. foreach (var item in interfaceList)
  2064. {
  2065. typeList.Add(new erp_configure_code() { typeid = configcodetype, name = item.bj_pzname });
  2066. if (!ifLSAccessory && item.itemname == "辅料" && item.bj_pzname.Contains("林氏") && !item.bj_pzname.Contains("林氏定制正标"))
  2067. {
  2068. ifLSAccessory = true;
  2069. }
  2070. }
  2071. var configure_Type = new u_configure_type() { contfigtypeid = configcodetype };
  2072. if (DbSqlHelper.SelectOne(cmd, configure_Type, "contfigtypeid") == 1)
  2073. {
  2074. var names = new List<string>();
  2075. foreach (var item in typeList)
  2076. {
  2077. if (!names.Contains(item.name))
  2078. {
  2079. names.Add(item.name);
  2080. }
  2081. }
  2082. var whereStr = "";
  2083. if (ifLSAccessory)
  2084. {
  2085. whereStr = " OR u_configure_code.name like '%林氏辅料%' ";
  2086. }
  2087. // 查询核价系统的配置资料定义
  2088. cmd.CommandText = @"SELECT u_configure_code.pzid
  2089. ,u_configure_code.pzcode
  2090. ,u_configure_code.name
  2091. ,u_configure_code.inputtype
  2092. FROM u_configure_code
  2093. WHERE u_configure_code.typeid = @configcodetype
  2094. AND (u_configure_code.name IN " + ListEx.getString(names) + whereStr + " )";
  2095. cmd.Parameters.Clear();
  2096. cmd.Parameters.AddWithValue("@configcodetype", configcodetype);
  2097. using (var reader = cmd.ExecuteReader())
  2098. {
  2099. while (reader.Read())
  2100. {
  2101. var item = new erp_configure_code()
  2102. {
  2103. pzid = Convert.ToInt32(reader["pzid"]),
  2104. pzcode = Convert.ToString(reader["pzcode"]),
  2105. name = Convert.ToString(reader["name"]).Trim(),
  2106. inputtype = Convert.ToInt32(reader["inputtype"])
  2107. };
  2108. resultList.Add(item);
  2109. }
  2110. }
  2111. }
  2112. else
  2113. {
  2114. // 查询L1部件选配
  2115. var erpHelper = GetHelper<ERPHelper>(null);
  2116. var parameters = new JObject();
  2117. parameters.Add("typeList", JToken.FromObject(typeList));
  2118. resultList = erpHelper.GetERPList<erp_configure_code>("GetL1ConfigureCode", parameters);
  2119. }
  2120. var LSIndex = 0;
  2121. for (var i = 0; i < interfaceList.Count; i++)
  2122. {
  2123. interfaceList[i].printid = i + 1;
  2124. var matchState = false;
  2125. foreach (var result in resultList)
  2126. {
  2127. if (interfaceList[i].bj_pzname == result.name)
  2128. {
  2129. matchState = true;
  2130. if (result.pzid > 0)
  2131. {
  2132. interfaceList[i].erp_pzid = result.pzid;
  2133. interfaceList[i].erp_pzcode = result.pzcode;
  2134. interfaceList[i].erp_pzname = result.name;
  2135. }
  2136. //if (interfaceList[i].bj_inputtype != 2)
  2137. interfaceList[i].bj_inputtype = result.inputtype;
  2138. }
  2139. }
  2140. if (ifLSAccessory && !matchState && interfaceList[i].itemname == "辅料" && interfaceList[i].bj_pzname.Contains("林氏") && !interfaceList[i].bj_pzname.Contains("林氏定制正标"))
  2141. {
  2142. if (!interfaceList[i].bj_pzname.Contains("位置"))
  2143. {
  2144. LSIndex++;
  2145. }
  2146. foreach (var result in resultList)
  2147. {
  2148. var _pzname = string.Format("林氏辅料{0}{1}", LSIndex, interfaceList[i].bj_pzname.Contains("位置") ? "位置" : "");
  2149. if (result.name == _pzname)
  2150. {
  2151. matchState = true;
  2152. if (result.pzid > 0)
  2153. {
  2154. interfaceList[i].erp_pzid = result.pzid;
  2155. interfaceList[i].erp_pzcode = result.pzcode;
  2156. interfaceList[i].erp_pzname = result.name;
  2157. }
  2158. if (interfaceList[i].bj_inputtype != 2) interfaceList[i].bj_inputtype = result.inputtype;
  2159. }
  2160. }
  2161. }
  2162. }
  2163. }
  2164. /// <summary>
  2165. /// 用于 字符串 + 字符串格式
  2166. /// </summary>
  2167. /// <param name="currentString"></param>
  2168. /// <param name="newPart"></param>
  2169. /// <returns></returns>
  2170. private string AppendToString(string currentString, string newPart)
  2171. {
  2172. if (string.IsNullOrEmpty(currentString))
  2173. {
  2174. return newPart;
  2175. }
  2176. else
  2177. {
  2178. return currentString + " + " + newPart;
  2179. }
  2180. }
  2181. /// <summary>
  2182. /// 数量分割字符串
  2183. /// </summary>
  2184. /// <param name="name"></param>
  2185. /// <param name="qty"></param>
  2186. /// <returns></returns>
  2187. private string SplitNameCount(string name, int qty)
  2188. {
  2189. if (qty <= 1) return name;
  2190. var result = name;
  2191. result = AppendToString(result, SplitNameCount(name, --qty));
  2192. return result;
  2193. }
  2194. #endregion
  2195. #region 全局变量
  2196. // 储存顶布裥棉数据
  2197. private string[,] DingBuLianMian = new string[4,5];
  2198. private enum PackType
  2199. {
  2200. 压包 = 0,
  2201. 卷包,
  2202. 国内
  2203. }
  2204. private enum InputType
  2205. {
  2206. 选择 = 0,
  2207. 录入,
  2208. 带出
  2209. }
  2210. public static string BillKeyWord = BillNames.MattressInterface;
  2211. #endregion
  2212. }
  2213. }