InterfaceHelper.cs 91 KB

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