InterfaceHelper.cs 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770
  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)" });
  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_103, 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. DbSqlHelper.SelectOne(cmd, mattress, "erp_configcodetype");
  281. if (configcodetype != 0)
  282. {
  283. mattress.erp_configcodetype = configcodetype;
  284. }
  285. MattressInterfaceFindERPPz(mattress, interfaceList);
  286. }
  287. public void MattressInterfaceFindERPPz(u_mattress mattress,List<u_mattress_interface> interfaceList)
  288. {
  289. var resultList = new List<erp_configure_code>();
  290. var typeList = new List<erp_configure_code>();
  291. foreach (var item in interfaceList)
  292. {
  293. typeList.Add(new erp_configure_code() { typeid = mattress.erp_configcodetype, name = item.bj_pzname });
  294. }
  295. var configure_Type = new u_configure_type() { contfigtypeid = mattress.erp_configcodetype };
  296. if (DbSqlHelper.SelectOne(cmd, configure_Type, "contfigtypeid") == 1)
  297. {
  298. var names = new List<string>();
  299. foreach (var item in typeList)
  300. {
  301. if (!names.Contains(item.name))
  302. {
  303. names.Add(item.name);
  304. }
  305. }
  306. // 查询核价系统的配置资料定义
  307. cmd.CommandText = @"SELECT u_configure_code.pzid
  308. ,u_configure_code.pzcode
  309. ,u_configure_code.name
  310. ,u_configure_code.inputtype
  311. FROM u_configure_code
  312. WHERE u_configure_code.typeid = @configcodetype
  313. AND u_configure_code.name IN " + ListEx.getString(names) ;
  314. cmd.Parameters.Clear();
  315. cmd.Parameters.AddWithValue("@configcodetype", mattress.erp_configcodetype);
  316. using (var reader = cmd.ExecuteReader())
  317. {
  318. while (reader.Read())
  319. {
  320. var item = new erp_configure_code()
  321. {
  322. pzid = Convert.ToInt32(reader["pzid"]),
  323. pzcode = Convert.ToString(reader["pzcode"]),
  324. name = Convert.ToString(reader["name"]).Trim(),
  325. inputtype = Convert.ToInt32(reader["inputtype"])
  326. };
  327. resultList.Add(item);
  328. }
  329. }
  330. }
  331. else
  332. {
  333. // 查询L1部件选配
  334. var erpHelper = HelperBase.GetHelper<ERPHelper>(null);
  335. var parameters = new JObject();
  336. parameters.Add("typeList", JToken.FromObject(typeList));
  337. resultList = erpHelper.GetERPList<erp_configure_code>("GetL1ConfigureCode", parameters);
  338. }
  339. for (var i = 0; i < interfaceList.Count; i++)
  340. {
  341. interfaceList[i].printid = i + 1;
  342. foreach (var result in resultList)
  343. {
  344. if (interfaceList[i].bj_pzname == result.name)
  345. {
  346. if (result.pzid > 0)
  347. {
  348. interfaceList[i].erp_pzid = result.pzid;
  349. interfaceList[i].erp_pzcode = result.pzcode;
  350. interfaceList[i].erp_pzname = result.name;
  351. }
  352. if (interfaceList[i].bj_inputtype != 2) interfaceList[i].bj_inputtype = result.inputtype;
  353. }
  354. }
  355. }
  356. }
  357. /// <summary>
  358. /// 初始化配置信息
  359. /// </summary>
  360. /// <param name="itemname"></param>
  361. /// <param name="bj_pzname"></param>
  362. /// <param name="inputtype"></param>
  363. /// <param name="names"></param>
  364. /// <returns></returns>
  365. public u_mattress_interface InserMattressInterfacePz(string itemname, string bj_pzname, byte inputtype, string[] names)
  366. {
  367. var mattress_interface = new u_mattress_interface()
  368. {
  369. itemname = itemname,
  370. bj_pzname = bj_pzname,
  371. bj_inputtype = inputtype,
  372. bj_namemx = names == null ? string.Empty : SetInterfacePzName(names)
  373. };
  374. return mattress_interface;
  375. }
  376. private string SetInterfacePzName(string[] names)
  377. {
  378. var result = string.Empty;
  379. foreach (var name in names)
  380. {
  381. if (string.IsNullOrEmpty(name)) continue;
  382. result = AppendToString(result, name);
  383. }
  384. return result;
  385. }
  386. private void AutoSetFormulaTypeZeroPz(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  387. {
  388. var powerDict = new Dictionary<string, int[]>()
  389. {
  390. {"面裥绵",new int[] { 0, 40, 50, 60, 70, 80 } },
  391. {"底裥绵",new int[] { 1, 41, 51, 61, 71, 81 } },
  392. {"顶布裥棉1",new int[] { 0, 40, 50, 60, 70, 80 } },
  393. {"顶布裥棉2",new int[] { 0, 40, 50, 60, 70, 80 } },
  394. {"顶布裥棉3",new int[] { 0, 40, 50, 60, 70, 80 } },
  395. {"顶布裥棉4",new int[] { 0, 40, 50, 60, 70, 80 } },
  396. {"普通大侧",new int[] { 2, 42, 52, 62, 72, 82 } },
  397. {"上下拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  398. {"上下拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  399. {"上下拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  400. {"左右拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  401. {"左右拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  402. {"左右拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  403. {"小侧1_EMPTY",new int[] { 3, 43, 53, 63, 73, 83 } },
  404. {"小侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  405. {"小侧1-上下拼侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  406. {"小侧1-上下拼侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  407. {"小侧1-上下拼侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  408. {"小侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  409. {"小侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  410. {"V侧1_EMPTY",new int[] { 4, 44, 54, 64, 74, 84 } },
  411. {"V侧1",new int[] { 4, 44, 54, 64, 74, 84 } }
  412. };
  413. var chastrArrDict = new Dictionary<string, string[]>()
  414. {
  415. {"面裥绵",new string[] { "裥面", "面层裥棉", "面层裥棉图案", "面层裥面说明" } },
  416. {"底裥绵",new string[] { "裥底", "底层裥棉", "底层裥棉图案", "底层裥棉说明" } },
  417. {"顶布裥棉1",new string[] { "顶布裥棉", "", "顶布裥棉1图案", "顶布裥棉1说明" } },
  418. {"顶布裥棉2",new string[] { "顶布裥棉", "", "顶布裥棉2图案", "顶布裥棉2说明" } },
  419. {"顶布裥棉3",new string[] { "顶布裥棉", "", "顶布裥棉3图案", "顶布裥棉3说明" } },
  420. {"顶布裥棉4",new string[] { "顶布裥棉","", "顶布裥棉4图案", "顶布裥棉4说明" } },
  421. {"普通大侧",new string[] { "大侧", "大侧裥棉", "大侧裥棉图案" } },
  422. {"上下拼侧1",new string[] {"大侧", "大侧-上下拼侧1", "大侧-上下拼侧1", "大侧-上下拼侧1高度"} },
  423. {"上下拼侧2",new string[] { "大侧", "大侧-上下拼侧2", "大侧-上下拼侧2", "大侧-上下拼侧2高度" } },
  424. {"上下拼侧3",new string[] { "大侧", "大侧-上下拼侧3", "大侧-上下拼侧3", "大侧-上下拼侧3高度" } },
  425. {"左右拼侧1",new string[] { "大侧", "大侧-左右拼侧1", "大侧-左右拼侧1裥棉图案", "大侧-左右拼侧1长度" } },
  426. {"左右拼侧2",new string[] { "大侧", "大侧-左右拼侧2", "大侧-左右拼侧2裥棉图案", "大侧-左右拼侧2长度" } },
  427. {"左右拼侧3",new string[] { "大侧", "大侧-左右拼侧3", "大侧-左右拼侧3裥棉图案", "大侧-左右拼侧3长度", "大侧说明" } },
  428. {"小侧1_EMPTY",new string[] { "小侧", "小侧1裥棉", "小侧1裥棉图案" } },
  429. {"小侧1",new string[] { "小侧", "小侧1裥棉", "小侧1裥棉图案" } },
  430. {"小侧1-上下拼侧1",new string[] { "小侧", "小侧1-上下拼侧1裥棉", "小侧1-上下拼侧1裥棉图案" } },
  431. {"小侧1-上下拼侧2",new string[] { "小侧", "小侧1-上下拼侧2裥棉", "小侧1-上下拼侧2裥棉图案" } },
  432. {"小侧1-上下拼侧3",new string[] { "小侧", "小侧1-上下拼侧3裥棉", "小侧1-上下拼侧3裥棉图案" } },
  433. {"小侧2",new string[] { "小侧", "小侧2裥棉", "小侧2裥棉图案" } },
  434. {"小侧3",new string[] { "小侧", "小侧3裥棉", "小侧3裥棉图案", "小侧说明" } },
  435. {"V侧1_EMPTY",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  436. {"V侧1",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  437. {"V侧2",new string[] { "V侧", "V侧2裥棉", "V侧2裥棉图案" } },
  438. {"V侧3",new string[] { "V侧", "V侧3裥棉", "V侧3裥棉图案", "V侧说明" } }
  439. };
  440. var jianmianList = mxlist.Where(t => t.formulatype == 0).ToList();
  441. #region wf_import_qingdan + wf_import_qingdan_1 面料部分
  442. foreach (var item in powerDict)
  443. {
  444. SetFormulaTypeZeroPz(jianmianList, interfaceList, item.Value, item.Key, chastrArrDict[item.Key]);
  445. }
  446. #endregion
  447. #region wf_import_qingdan_next 面料部分
  448. // 拉手
  449. var lashouList = jianmianList.Where(t => t.formulakind == 5).ToList();
  450. for (int i = 0; i < lashouList.Count; i++)
  451. {
  452. var mx = lashouList[i];
  453. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  454. {
  455. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"拉手{i + 1}做法", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}只{mx.mtrlname}" }));
  456. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"拉手{i + 1}刺绣", 0, new string[] { "" }));
  457. }
  458. }
  459. // 刺绣
  460. var cixiuList = jianmianList.Where(t => t.formulakind == 6).ToList();
  461. var ls_temp_cnt = 0;
  462. for (int i = 0; i < cixiuList.Count; i++)
  463. {
  464. var mx = cixiuList[i];
  465. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  466. {
  467. for (int k = 0; k < mx.qty; k++)
  468. {
  469. ls_temp_cnt++;
  470. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"侧刺绣{ls_temp_cnt}做法", 1, new string[] { "" }));
  471. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"侧刺绣{ls_temp_cnt}位置", 0, new string[] { "" }));
  472. }
  473. }
  474. }
  475. // 大侧压压布
  476. var dcyybList = jianmianList.Where(t => t.formulakind == 7).ToList();
  477. for (int i = 0; i < dcyybList.Count; i++)
  478. {
  479. var mx = dcyybList[i];
  480. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  481. {
  482. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"大侧压压布{i + 1}", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  483. }
  484. }
  485. // 大侧压边带
  486. var dcybdList = jianmianList.Where(t => t.formulakind == 8).ToList();
  487. for (int i = 0; i < dcybdList.Count; i++)
  488. {
  489. var mx = dcybdList[i];
  490. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  491. {
  492. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"大侧压边带{i + 1}", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  493. }
  494. }
  495. // 大侧压织带
  496. var dcyzdList = jianmianList.Where(t => t.formulakind == 9).ToList();
  497. for (int i = 0; i < dcyzdList.Count; i++)
  498. {
  499. var mx = dcyzdList[i];
  500. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  501. {
  502. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"大侧压织带{i + 1}", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  503. }
  504. }
  505. // 大侧压上下压线
  506. var dcysxyxList = jianmianList.Where(t => t.formulakind == 10).ToList();
  507. for (int i = 0; i < dcysxyxList.Count; i++)
  508. {
  509. var mx = dcysxyxList[i];
  510. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  511. {
  512. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"大侧压上下压线{i + 1}", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  513. }
  514. }
  515. // 车花边
  516. var chbList = jianmianList.Where(t => t.formulakind == 205).ToList();
  517. for (int i = 0; i < chbList.Count; i++)
  518. {
  519. var mx = chbList[i];
  520. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  521. {
  522. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", "车花边", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  523. }
  524. }
  525. // 防火线
  526. var fhxList = jianmianList.Where(t => t.formulakind == 30).ToList();
  527. for (int i = 0; i < fhxList.Count; i++)
  528. {
  529. var mx = fhxList[i];
  530. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  531. {
  532. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", "防火线", 1, new string[] { mx.mtrlname }));
  533. }
  534. }
  535. // 拉链
  536. var llList = jianmianList.Where(t => t.formulakind == 202 && string.IsNullOrEmpty(t.chastr) && t.mtrlid > 0).ToList();
  537. for (int i = 0; i < llList.Count; i++)
  538. {
  539. var mx = llList[i];
  540. if (llList.Count > 1)
  541. {
  542. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", "拉链" + (i+1), 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  543. }
  544. else
  545. {
  546. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", "拉链", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  547. }
  548. }
  549. #endregion
  550. }
  551. private void SetFormulaTypeZeroPz(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList, int[] powerArr, string key, string[] chastrArr)
  552. {
  553. var mianList1 = new HashSet<string> { "面裥绵", "底裥绵" };
  554. var mianList2 = new string[4] { "顶布裥棉1", "顶布裥棉2", "顶布裥棉3", "顶布裥棉4" };
  555. var mianList3 = new HashSet<string> { "普通大侧", "上下拼侧1", "上下拼侧2", "上下拼侧3", "左右拼侧1", "左右拼侧2", "左右拼侧3", "小侧1", "小侧2", "小侧3" };
  556. //var mianList4 = new HashSet<string> { "小侧1", "小侧2", "小侧3" };
  557. var name_arr = new string[5];
  558. foreach (var mx in mxlist)
  559. {
  560. SetFormulaTypeZeroPzName(mx, key, powerArr, name_arr);
  561. }
  562. if (mianList2.Contains(key))
  563. {
  564. for (int i = 0; i < mianList2.Length; i++)
  565. {
  566. DingBuLianMian.SetValue(name_arr[i], i, 0);
  567. }
  568. }
  569. //if (mianList4.Contains(key))
  570. //{
  571. // var _index = 0;
  572. // Regex regex = new Regex(@"\d+");
  573. // Match match = regex.Match(key);
  574. // _index = Convert.ToInt32(match.Value) - 1;
  575. // for (int i = 0; i < mianList4.Count; i++)
  576. // {
  577. // XiaoCePeizhi.SetValue(name_arr[i], i, _index);
  578. // }
  579. //}
  580. var sb = new StringBuilder();
  581. foreach (var name2 in name_arr)
  582. {
  583. sb.Append(name2);
  584. }
  585. bool ifchastr3 = false;
  586. if (sb.Length > 0)
  587. {
  588. if (!string.IsNullOrEmpty(chastrArr[1])) interfaceList.Add(InserMattressInterfacePz(chastrArr[0], chastrArr[1], 2, name_arr));
  589. interfaceList.Add(InserMattressInterfacePz(chastrArr[0], chastrArr[2], 1, new string[] { "" }));
  590. if (chastrArr.Length > 3)
  591. {
  592. if (chastrArr[3].Contains("说明")) ifchastr3 = true;
  593. interfaceList.Add(InserMattressInterfacePz(chastrArr[0], chastrArr[3], 1, new string[] { "" }));
  594. }
  595. }
  596. foreach (var name in chastrArr)
  597. {
  598. if (string.IsNullOrEmpty(name)) continue;
  599. if (name.Contains("说明") && !ifchastr3)
  600. {
  601. interfaceList.Add(InserMattressInterfacePz(chastrArr[0], name, 1, new string[] { "" }));
  602. }
  603. }
  604. }
  605. //private bool ifHasXiaoceMtrl()
  606. //{
  607. // bool hasVal = false;
  608. // for (int i = 0; i < XiaoCePeizhi.GetLength(0); i++)
  609. // {
  610. // for (int j = 0; j < XiaoCePeizhi.GetLength(1); j++)
  611. // {
  612. // if (!string.IsNullOrEmpty(XiaoCePeizhi[i, j]))
  613. // {
  614. // hasVal = true;
  615. // break;
  616. // }
  617. // }
  618. // if (hasVal)
  619. // {
  620. // break;
  621. // }
  622. // }
  623. // return hasVal;
  624. //}
  625. private void SetFormulaTypeZeroPzName(u_mattress_mx_mtrl mx, string key, int[] powerArr, string[] name_arr)
  626. {
  627. if (key.Contains("_EMPTY")) key = "";
  628. if (mx.mtrlid > 0 && key.Equals(mx.chastr) && powerArr.Contains(mx.formulakind.Value))
  629. {
  630. if (mx.formulakind == 0 || mx.formulakind == 1 || mx.formulakind == 2 || mx.formulakind == 3 || mx.formulakind == 4)
  631. {
  632. name_arr[0] = AppendToString(name_arr[0], SplitNameCount(mx.mtrlname, Convert.ToInt32(mx.qty.Value)));
  633. }
  634. if (mx.formulakind == 40 || mx.formulakind == 41 || mx.formulakind == 42 || mx.formulakind == 43 || mx.formulakind == 44)
  635. {
  636. name_arr[1] = AppendToString(name_arr[1], SplitNameCount(mx.mtrlname, Convert.ToInt32(mx.qty.Value)));
  637. }
  638. if (mx.formulakind == 50 || mx.formulakind == 51 || mx.formulakind == 52 || mx.formulakind == 53 || mx.formulakind == 54)
  639. {
  640. var mtrlname_temp = mx.mtrlname;
  641. if (!(mx.mtrlname.IndexOf("分") > -1 && mx.thickness == 0 || mx.if_inputqty == 1))
  642. {
  643. mtrlname_temp = $"{mx.thickness.Value.ToString("#,##0.0#")}分{mx.mtrlname}";
  644. }
  645. name_arr[2] = AppendToString(name_arr[2], SplitNameCount(mtrlname_temp, Convert.ToInt32(mx.qty.Value)));
  646. }
  647. if (mx.formulakind == 60 || mx.formulakind == 61 || mx.formulakind == 62 || mx.formulakind == 63 || mx.formulakind == 64)
  648. {
  649. name_arr[3] = AppendToString(name_arr[3], SplitNameCount(mx.mtrlname, Convert.ToInt32(mx.qty.Value)));
  650. }
  651. if (mx.formulakind == 80 || mx.formulakind == 81 || mx.formulakind == 84)
  652. {
  653. name_arr[0] = AppendToString(name_arr[0], mx.mtrlname);
  654. }
  655. }
  656. }
  657. private void AutoSetFormulaTypeOnePz(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  658. {
  659. var diancengList = mxlist.Where(t => t.formulatype == 1).ToList();
  660. var kindDict = new Dictionary<int, string>()
  661. {
  662. { 32,"垫层" },
  663. { 12,"顶布" },
  664. { 13,"毡类" },
  665. { 14,"打底无纺布" },
  666. { 29,"网面布料" },
  667. { 999,"床网" },
  668. { 1201,"顶布裥棉" },
  669. };
  670. var chastrSet = new HashSet<string>() { "大侧", "小侧1", "小侧2", "小侧3", "V侧1", "V侧2", "V侧3" };
  671. var countDict = new Dictionary<string, int>();
  672. foreach (var cha in chastrSet)
  673. {
  674. foreach (var kind in kindDict)
  675. {
  676. countDict.Add($"{cha}-{kind.Value}", 0);
  677. }
  678. }
  679. foreach (var mx in diancengList)
  680. {
  681. var key = $"{mx.chastr}-{kindDict[mx.formulakind.Value]}";
  682. if (mx.formulakind == 999)
  683. {
  684. this.ProcessChuangWangPz(mx, interfaceList, mx.chastr, ++countDict[key]);
  685. }
  686. else if (mx.mtrlid > 0 && mx.formulakind == 1201)
  687. {
  688. this.ProcessDingbuLianMianPz(mx, interfaceList, mx.chastr, ++countDict[key]);
  689. }
  690. else if (mx.mtrlid > 0 && new int[] { 32, 12, 13, 14, 29 }.Contains(mx.formulakind.Value))
  691. {
  692. this.ProcessWangMianBLPz(mx, interfaceList, mx.chastr, kindDict[mx.formulakind.Value], ++countDict[key]);
  693. }
  694. }
  695. if (countDict["大侧-垫层"] > 0)
  696. {
  697. interfaceList.Add(InserMattressInterfacePz("垫层", "大侧垫层生产说明", 1, new string[1]));
  698. }
  699. if (countDict["小侧1-垫层"] > 0)
  700. {
  701. interfaceList.Add(InserMattressInterfacePz("垫层", "小侧垫层生产说明", 1, new string[1]));
  702. }
  703. if (countDict["V侧1-垫层"] > 0)
  704. {
  705. interfaceList.Add(InserMattressInterfacePz("垫层", "V侧垫层生产说明", 1, new string[1]));
  706. }
  707. }
  708. /// <summary>
  709. /// 床网
  710. /// </summary>
  711. /// <param name="mx"></param>
  712. /// <param name="interfaceList"></param>
  713. /// <param name="chastr"></param>
  714. /// <param name="count"></param>
  715. private void ProcessChuangWangPz(u_mattress_mx_mtrl mx, List<u_mattress_interface> interfaceList, string chastr, int count)
  716. {
  717. var name_arr = new string[5];
  718. int bednetid = 0;
  719. int spongeMtrlid = 0; // 是否有海绵包边物料
  720. cmd.CommandText = @"SELECT u_bednetmx.bednet_height,u_bednetmx.bednetid,u_bednet.sponge_mtrlid
  721. FROM u_bednetmx
  722. LEFT OUTER JOIN u_bednet ON u_bednet.bednetid = u_bednetmx.bednetid
  723. INNER JOIN (
  724. SELECT mtrlid
  725. FROM u_mattress_mx_mtrl
  726. INNER JOIN u_mattress_formula ON u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  727. WHERE u_mattress_formula.formulakind = 99
  728. AND u_mattress_mx_mtrl.mattressid = @mattressid
  729. AND u_mattress_mx_mtrl.mtrlid > 0
  730. ) v_mattress_mx_mtrl ON u_bednetmx.bednetid = v_mattress_mx_mtrl.mtrlid";
  731. cmd.Parameters.Clear();
  732. cmd.Parameters.AddWithValue("@mattressid", mx.mattressid);
  733. using (var reader = cmd.ExecuteReader())
  734. {
  735. while (reader.Read())
  736. {
  737. decimal height = Convert.ToDecimal(reader["bednet_height"]);
  738. if (height == mx.thickness)
  739. {
  740. bednetid = Convert.ToInt32(reader["bednetid"]);
  741. spongeMtrlid = Convert.ToInt32(reader["sponge_mtrlid"]);
  742. }
  743. }
  744. }
  745. if (bednetid > 0)
  746. {
  747. var bednetHelper = HelperBase.GetHelper<BedNetHelper>(cmd);
  748. var bednetQdList = bednetHelper.GetBedNetQingDan(bednetid);
  749. if (bednetQdList.Any())
  750. {
  751. name_arr[0] = bednetQdList[0].pznamemx;
  752. name_arr[0] += "丨erp编码:";
  753. cmd.CommandText = @"SELECT u_mattress.erp_mtrlcode
  754. FROM u_mattress_mx_mtrl
  755. INNER JOIN u_mattress_formula ON u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  756. INNER JOIN u_mattress ON u_mattress.mattressid = u_mattress_mx_mtrl.mattressid
  757. WHERE u_mattress_formula.formulakind = 99
  758. AND u_mattress.bcptypeid <> 0
  759. AND u_mattress_mx_mtrl.mtrlid = @bednetid";
  760. cmd.Parameters.Clear();
  761. cmd.Parameters.AddWithValue("@bednetid", bednetid);
  762. using(var reader = cmd.ExecuteReader())
  763. {
  764. if (reader.Read())
  765. {
  766. name_arr[0] += Convert.ToString(reader["erp_mtrlcode"]);
  767. }
  768. }
  769. }
  770. }
  771. if (FuncPowerHelper.CheckFuncPower(cmd, context.tokendata.userid, 98) && "super".Equals(context.tokendata.username.ToLower()))
  772. {
  773. interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}", 2, name_arr));
  774. }
  775. else
  776. {
  777. interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}", 1, name_arr));
  778. }
  779. interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}生产说明", 1, new string[] { "" }));
  780. if (spongeMtrlid > 0) interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}包边海绵条", 1, new string[] { "" }));
  781. }
  782. /// <summary>
  783. /// 网面布料 / 打底无纺布 / 毡类 / 顶布 / 垫层
  784. /// </summary>
  785. /// <param name="mx"></param>
  786. /// <param name="interfaceList"></param>
  787. /// <param name="chastr"></param>
  788. /// <param name="count"></param>
  789. private void ProcessWangMianBLPz(u_mattress_mx_mtrl mx, List<u_mattress_interface> interfaceList, string chastr, string typename, int count)
  790. {
  791. var name_arr = new string[5];
  792. var mtrlname_temp = mx.mtrlname;
  793. var chastr_temp = string.Empty;
  794. if ("顶布".Equals(typename) && count <= 1)
  795. {
  796. chastr_temp = $"{chastr}-{typename}";
  797. }
  798. else
  799. {
  800. chastr_temp = $"{chastr}-{typename}{count}";
  801. }
  802. if ((!mx.mtrlname.Contains("分") && mx.thickness > 0) || ("垫层".Equals(typename)))
  803. {
  804. mtrlname_temp = $"{mx.thickness.Value.ToString("#,##0.0#")}分{mx.mtrlname}";
  805. }
  806. name_arr[0] = mtrlname_temp;
  807. interfaceList.Add(InserMattressInterfacePz("垫层", chastr_temp, 2, name_arr));
  808. }
  809. /// <summary>
  810. /// 顶布裥棉
  811. /// </summary>
  812. /// <param name="mx"></param>
  813. /// <param name="interfaceList"></param>
  814. /// <param name="count"></param>
  815. private void ProcessDingbuLianMianPz(u_mattress_mx_mtrl mx, List<u_mattress_interface> interfaceList, string chastr, int count)
  816. {
  817. string chastr_temp = string.Empty;
  818. string ls_temp = "";
  819. string[] name_arr = new string[5];
  820. if ("顶布裥棉1".Equals(mx.mtrlname))
  821. {
  822. chastr_temp = $"{chastr}-顶布裥棉";
  823. for (int i = 0; i < DingBuLianMian.GetLength(0); i++)
  824. {
  825. name_arr[i] = DingBuLianMian[0, i];
  826. }
  827. }
  828. else if ("顶布裥棉2".Equals(mx.mtrlname))
  829. {
  830. chastr_temp = $"{chastr}-顶布裥棉2";
  831. for (int i = 0; i < DingBuLianMian.GetLength(0); i++)
  832. {
  833. name_arr[i] = DingBuLianMian[1, i];
  834. }
  835. }
  836. else if ("顶布裥棉3".Equals(mx.mtrlname))
  837. {
  838. chastr_temp = $"{chastr}-顶布裥棉3";
  839. for (int i = 0; i < DingBuLianMian.GetLength(0); i++)
  840. {
  841. name_arr[i] = DingBuLianMian[2, i];
  842. }
  843. }
  844. else if ("顶布裥棉4".Equals(mx.mtrlname))
  845. {
  846. chastr_temp = $"{chastr}-顶布裥棉4";
  847. for (int i = 0; i < DingBuLianMian.GetLength(0); i++)
  848. {
  849. name_arr[i] = DingBuLianMian[3, i];
  850. }
  851. }
  852. interfaceList.Add(InserMattressInterfacePz("垫层", chastr_temp, 2, name_arr));
  853. }
  854. private void AutoSetFormulaTypeTwoPz(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  855. {
  856. var nameSet = new HashSet<string>(new string[] {
  857. "白色无字包角", "保用卡", "采购小标", "打钮钮扣", "打印小标", "合格证", "画纸", "角网+拉链",
  858. "开箱刀+开箱说明", "开箱说明+开箱刀", "气钮", "吊标", "说明书", "斜标", "正标", "织唛",
  859. "织唛斜标", "客供标", "空白牛皮纸包角", "空白珍珠包角"
  860. });
  861. // 按照nameSet排序
  862. Dictionary<string, int> orderDict = nameSet.Select((name, index) => new { Name = name, Index = index }).ToDictionary(x => x.Name, x => x.Index);
  863. 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();
  864. var extraSet = new HashSet<string>(new string[] { "采购小标", "打印小标", "合格证", "吊标", "斜标", "正标", "织唛", "织唛斜标", "客供标" });
  865. var specialSet = new HashSet<string>(new string[] { "打钮钮扣", "气钮" });
  866. foreach (var mx in fuliaoList)
  867. {
  868. if (mx.mtrlid > 0)
  869. {
  870. int cnt = Convert.ToInt32(Math.Abs(mx.qty.Value));
  871. var mtrldef = new u_mtrl_price() { mtrlid = mx.mtrlid };
  872. if (DbSqlHelper.SelectOne(cmd, mtrldef, "erp_mtrlid") == 1)
  873. {
  874. mx.erp_mtrlid = mtrldef.erp_mtrlid;
  875. }
  876. // 处理特殊辅料
  877. if (specialSet.Contains(mx.mtrlname))
  878. {
  879. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}", 1, new string[] { $"{cnt.ToString("#,##0.0#")}个" }));
  880. continue; // 跳过后续的处理
  881. }
  882. // 处理其他辅料
  883. if (nameSet.Contains(mx.mtrlname))
  884. {
  885. for (int i = 1; i <= cnt; i++)
  886. {
  887. // 添加辅料接口
  888. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}", 1, new string[] { "" }));
  889. // 如果是额外的辅料,添加位置接口
  890. if (extraSet.Contains(mx.mtrlname))
  891. {
  892. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}位置", 0, new string[] { "" }));
  893. }
  894. }
  895. }else if(mx.formulakind == 15 && !nameSet.Contains(mx.mtrlname))
  896. {
  897. for (int i = 1; i <= cnt; i++)
  898. {
  899. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}", 1, new string[] { "" }));
  900. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}位置", 0, new string[] { "" }));
  901. }
  902. }
  903. }
  904. }
  905. }
  906. private void AutoSetFormulaTypeThreePz(u_mattress mattress, List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  907. {
  908. // 筛选 formulatype 为 3 的物料
  909. var bzList = mxlist.Where(t => t.formulatype == 3).ToList();
  910. var chastrDict = new Dictionary<int, string>
  911. {
  912. {16, "PE袋"},
  913. {17, "外层PE"},
  914. {18, "PVC"},
  915. {19, "卷包包装"},
  916. {20, "牛皮纸袋"},
  917. {21, "蓝色PE护角"},
  918. {22, "无纺布袋"},
  919. {23, "牛皮袋护角"},
  920. {24, "编织袋"},
  921. {27, "拉手脚轮"},
  922. {201, "无纺布护角"}
  923. };
  924. var countDict = new Dictionary<int, int>
  925. {
  926. {16, 1}
  927. };
  928. // 外观
  929. interfaceList.Add(InserMattressInterfacePz("床垫", "包装方式", 1, new string[] { Enum.GetName(typeof(PackType), mattress.packtype) }));
  930. foreach (var mx in bzList)
  931. {
  932. if (mx.mtrlid > 0 && chastrDict.TryGetValue(mx.formulakind.GetValueOrDefault(), out var chastr))
  933. {
  934. var name_arr = new string[1];
  935. if (mx.qty.HasValue && mx.qty.Value > 1)
  936. {
  937. name_arr[0] = $"{mx.qty.Value.ToString("#,##0.0#")}个{mx.mtrlname}";
  938. }
  939. else
  940. {
  941. name_arr[0] = mx.mtrlname;
  942. }
  943. if (countDict.ContainsKey(mx.formulakind.Value))
  944. {
  945. chastr += countDict[mx.formulakind.Value];
  946. }
  947. // 添加包装信息
  948. interfaceList.Add(InserMattressInterfacePz("包装", chastr, 2, name_arr));
  949. }
  950. }
  951. // 压包数量
  952. interfaceList.Add(InserMattressInterfacePz("包装", "压包数量", 1, new string[] { $"{mattress.packqty.Value.ToString("#,##0.0#")}" }));
  953. // 包装说明
  954. interfaceList.Add(InserMattressInterfacePz("包装", "包装说明", 1, new string[] { "" }));
  955. // 压包说明
  956. if (mattress.packqty.HasValue && mattress.packqty.Value > 0) interfaceList.Add(InserMattressInterfacePz("包装", "压包说明", 1, new string[] { "" }));
  957. // 卷包说明
  958. if (mattress.diameter.HasValue && mattress.diameter.Value > 0) interfaceList.Add(InserMattressInterfacePz("包装", "卷包说明", 1, new string[] { "" }));
  959. }
  960. private void AutoSetFormulaType101Pz(u_mattress mattress, List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  961. {
  962. var powerDict = new Dictionary<string, int[]>()
  963. {
  964. {"面裥绵",new int[] { 0, 40, 50, 60, 70 } },
  965. {"底裥绵",new int[] { 1, 41, 51, 61, 71 } },
  966. {"普通大侧",new int[] { 2, 42, 52, 62, 72 } }
  967. };
  968. var chastrDict = new Dictionary<string, string[]>()
  969. {
  970. {"面裥绵",new string[] { "内布套-面层裥棉", "内布套-面层裥棉裥棉图案" } },
  971. {"底裥绵",new string[] { "内布套-底层裥棉", "内布套-底层裥棉裥棉图案" } },
  972. {"普通大侧",new string[] { "内布套-大侧裥棉", "内布套-大侧裥棉裥棉图案" } }
  973. };
  974. foreach (var item in powerDict)
  975. {
  976. var name_arr = new string[5];
  977. foreach (var mx in mxlist)
  978. {
  979. SetFormulaTypeZeroPzName(mx, "内布套", item.Value, name_arr);
  980. }
  981. var sb = new StringBuilder();
  982. foreach (var name2 in name_arr)
  983. {
  984. sb.Append(name2);
  985. }
  986. if (sb.Length > 0)
  987. {
  988. interfaceList.Add(InserMattressInterfacePz("内布套", chastrDict[item.Key][0], 2, name_arr));
  989. interfaceList.Add(InserMattressInterfacePz("内布套", chastrDict[item.Key][1], 1, new string[] { "" }));
  990. }
  991. }
  992. // 内布套-围边边带 / 拉链
  993. foreach (var mx in mxlist)
  994. {
  995. if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 203)
  996. {
  997. interfaceList.Add(InserMattressInterfacePz("内布套", "内布套-围边边带", 2, new string[] { $"{mx.thickness.Value.ToString("#,##0.0#")}条共{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  998. }
  999. else if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 202)
  1000. {
  1001. interfaceList.Add(InserMattressInterfacePz("内布套", "内布套-拉链", 2, new string[] { $"{mx.thickness.Value.ToString("#,##0.0#")}条共{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  1002. }
  1003. }
  1004. var butaostring = new string[] { };
  1005. if (mattress.if_n_butao == 1)
  1006. {
  1007. 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" };
  1008. interfaceList.Add(InserMattressInterfacePz("内布套", "内布套做法说明", 1, butaostring));
  1009. }
  1010. }
  1011. #endregion
  1012. #region 导入清单方法
  1013. public List<u_mattress_interface_qd> RefreshMattressInterfaceQdList(int mattressid)
  1014. {
  1015. var qdList = new List<u_mattress_interface_qd>();
  1016. ImportMattressInterfaceQdList(mattressid, qdList);
  1017. MattressInterfaceFindERPPrdPf(qdList,null);
  1018. return qdList;
  1019. }
  1020. /// <summary>
  1021. /// wf_fine_erp_prdpf
  1022. /// </summary>
  1023. /// <param name="qdList"></param>
  1024. /// <param name="interfaceList"></param>
  1025. public void MattressInterfaceFindERPPrdPf(List<u_mattress_interface_qd> qdList,List<u_mattress_interface> interfaceList = null)
  1026. {
  1027. var mtrlidList = new List<int>();
  1028. foreach (var mx in qdList)
  1029. {
  1030. // 带出有设置 的erp_mtrlid
  1031. if (mx.erp_mtrlid == 0 && mx.mtrlid != null && mx.mtrlid > 0)
  1032. {
  1033. var mtrldef = new u_mtrl_price() { mtrlid = mx.mtrlid };
  1034. if (DbSqlHelper.SelectOne(cmd, mtrldef, "erp_mtrlid") == 1)
  1035. {
  1036. mx.erp_mtrlid = mtrldef.erp_mtrlid;
  1037. }
  1038. }
  1039. //
  1040. if (mx.erp_mtrlid > 0)
  1041. {
  1042. mtrlidList.Add(mx.erp_mtrlid.Value);
  1043. }
  1044. }
  1045. if (mtrlidList.Count > 0)
  1046. {
  1047. var erpHelper = HelperBase.GetHelper<ERPHelper>(null);
  1048. //var parameters = new JObject();
  1049. //parameters.Add("mtrlids", JToken.FromObject(mtrlidList));
  1050. //var resultList = erpHelper.GetERPList<erp_mtrldef>("GetL1Mtrldef", parameters);
  1051. var total = 0;
  1052. var resultList = erpHelper.GetERPMtrldef(cmd, ref total, "", new L1Mtrldef(), 0, 0, 1, mtrlidList);
  1053. if (resultList != null && resultList.Any())
  1054. {
  1055. foreach (var mx in qdList)
  1056. {
  1057. var result = resultList.FirstOrDefault(o => o.mtrlid == mx.erp_mtrlid);
  1058. if (result != null)
  1059. {
  1060. mx.erp_mtrlcode = result.mtrlcode;
  1061. mx.erp_mtrlname = result.mtrlname;
  1062. mx.erp_mtrlmode = result.mtrlmode;
  1063. mx.erp_unit = result.unit;
  1064. mx.erp_mtrlengname = result.zxmtrlmode;
  1065. }
  1066. }
  1067. }
  1068. }
  1069. //更新 二级明细项目 需要产品配置列表,此部分由前端完成
  1070. if (interfaceList != null && interfaceList.Any())
  1071. {
  1072. // 使用 GroupBy 去重并选择第一个元素
  1073. var distinctList = interfaceList
  1074. .GroupBy(mb => mb.bj_pzname)
  1075. .Select(g => g.First())
  1076. .ToList();
  1077. Dictionary<string, u_mattress_interface> interfaceDict = distinctList.ToDictionary(mb => mb.bj_pzname, mb => mb);
  1078. foreach (var mx in qdList)
  1079. {
  1080. if (interfaceDict.TryGetValue(mx.bj_pzname, out var mb))
  1081. {
  1082. mx.bj_pzname_mx_mx = mb.bj_namemx;
  1083. if (mx.ss_rate == 0) mx.ss_rate = mb.ss_rate;
  1084. if (mx.ls_rate == 0) mx.ls_rate = mb.ls_rate;
  1085. }
  1086. }
  1087. }
  1088. }
  1089. /// <summary>
  1090. /// 导入产品清单
  1091. /// </summary>
  1092. /// <param name="mattressid"></param>
  1093. /// <exception cref="LJCommonException"></exception>
  1094. public void ImportMattressInterfaceQdList(int mattressid, List<u_mattress_interface_qd> qdList)
  1095. {
  1096. if (mattressid <= 0)
  1097. {
  1098. throw new LJCommonException("床垫id有误");
  1099. }
  1100. var mattressHelper = GetHelper<MattressHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  1101. var mattress = mattressHelper.GetMattress(mattressid);
  1102. var mattress_type = new u_mattress_type() { mattresstypeid = mattress.mattresstypeid };
  1103. DbSqlHelper.SelectOne(cmd, mattress_type, "typename");
  1104. var mxlist = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype IN (0,1,2,3,99,104)" });
  1105. var mxlist_103 = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype = 103" });
  1106. var mxlist_101 = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype = 101" });
  1107. #region 面料类清单导入
  1108. AutoSetFormulaTypeZeroPrdPf(mxlist, qdList);
  1109. #endregion
  1110. #region 垫层类清单导入
  1111. AutoSetFormulaTypeOnePrdPf(mxlist, qdList);
  1112. #endregion
  1113. #region 辅料类清单导入
  1114. AutoSetFormulaTypeTwoPrfPf(mxlist, qdList);
  1115. #endregion
  1116. #region 包装类清单导入
  1117. AutoSetFormulaTypeThreePrdPf(mxlist, qdList);
  1118. #endregion
  1119. #region 内布套类清单导入
  1120. AutoSetFormulaType101PrdPf(mxlist_103, qdList);
  1121. #endregion
  1122. // 最后初始化interfaceList的printid
  1123. for (var i = 0; i < qdList.Count; i++)
  1124. {
  1125. qdList[i].printid = i + 1;
  1126. }
  1127. }
  1128. /// <summary>
  1129. /// 初始化清单信息
  1130. /// </summary>
  1131. /// <param name="itemname"></param>
  1132. /// <param name="bj_pzname"></param>
  1133. /// <param name="inputtype"></param>
  1134. /// <param name="names"></param>
  1135. /// <returns></returns>
  1136. public u_mattress_interface_qd InserMattressInterfacePrdPf(string itemname, string bj_pzname, string namemx, int mtrlid, decimal useqty, int formulaid = 0)
  1137. {
  1138. var _bcpcompare = new u_bcpcompare() { pzname = bj_pzname };
  1139. var _wip_type = "";
  1140. var _wrkgrpcode2 = "";
  1141. if (DbSqlHelper.SelectOne(cmd, _bcpcompare, "wip_type, wrkgrpcode2") == 1)
  1142. {
  1143. _wip_type = _bcpcompare.wip_type;
  1144. _wrkgrpcode2 = _bcpcompare.wrkgrpcode2;
  1145. }
  1146. var mattress_interface_qd = new u_mattress_interface_qd()
  1147. {
  1148. itemname = itemname,
  1149. bj_pzname = bj_pzname,
  1150. bj_pzname_mx = namemx,
  1151. mtrlid = mtrlid,
  1152. useqty = useqty,
  1153. formulaid = formulaid,
  1154. wip_type = _wip_type,
  1155. wrkgrpcode2 = _wrkgrpcode2
  1156. };
  1157. return mattress_interface_qd;
  1158. }
  1159. public u_mattress_interface_qd InserMattressInterfacePrdPf(string itemname, string bj_pzname, string namemx)
  1160. {
  1161. var mattress_interface_qd = new u_mattress_interface_qd()
  1162. {
  1163. itemname = itemname,
  1164. bj_pzname = bj_pzname,
  1165. bj_pzname_mx = namemx
  1166. };
  1167. return mattress_interface_qd;
  1168. }
  1169. private void AutoSetFormulaTypeZeroPrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1170. {
  1171. var powerDict = new Dictionary<string, int[]>()
  1172. {
  1173. {"面裥绵",new int[] { 0, 40, 50, 60, 70, 80 } },
  1174. {"底裥绵",new int[] { 1, 41, 51, 61, 71, 81 } },
  1175. {"顶布裥棉1",new int[] { 0, 40, 50, 60, 70, 80 } },
  1176. {"顶布裥棉2",new int[] { 0, 40, 50, 60, 70, 80 } },
  1177. {"普通大侧",new int[] { 2, 42, 52, 62, 72, 82 } },
  1178. {"上下拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  1179. {"上下拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  1180. {"上下拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  1181. {"左右拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  1182. {"左右拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  1183. {"左右拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  1184. {"小侧1_EMPTY",new int[] { 3, 43, 53, 63, 73, 83 } },
  1185. {"小侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  1186. {"小侧1-上下拼侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  1187. {"小侧1-上下拼侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  1188. {"小侧1-上下拼侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  1189. {"小侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  1190. {"小侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  1191. {"V侧1_EMPTY",new int[] { 4, 44, 54, 64, 74, 84 } },
  1192. {"V侧1",new int[] { 4, 44, 54, 64, 74, 84 } }
  1193. };
  1194. var chastrArrDict = new Dictionary<string, string[]>()
  1195. {
  1196. {"面裥绵",new string[] { "裥面", "面层裥棉", "面层裥面说明" } },
  1197. {"底裥绵",new string[] { "裥底", "底层裥棉", "底层裥棉说明" } },
  1198. {"顶布裥棉1",new string[] { "顶布裥棉", "顶布裥棉1" } },
  1199. {"顶布裥棉2",new string[] { "顶布裥棉", "顶布裥棉2" } },
  1200. {"普通大侧",new string[] { "大侧", "大侧裥棉"} },
  1201. {"上下拼侧1",new string[] {"大侧", "大侧-上下拼侧1"} },
  1202. {"上下拼侧2",new string[] { "大侧", "大侧-上下拼侧2" } },
  1203. {"上下拼侧3",new string[] { "大侧", "大侧-上下拼侧3" } },
  1204. {"左右拼侧1",new string[] { "大侧", "大侧-左右拼侧1"} },
  1205. {"左右拼侧2",new string[] { "大侧", "大侧-左右拼侧2"} },
  1206. {"左右拼侧3",new string[] { "大侧", "大侧-左右拼侧3" ,"大侧说明" } },
  1207. {"小侧1_EMPTY",new string[] { "小侧", "小侧1裥棉" } },
  1208. {"小侧1",new string[] { "小侧", "小侧1裥棉"} },
  1209. {"小侧1-上下拼侧1",new string[] { "小侧", "小侧1-上下拼侧1裥棉" } },
  1210. {"小侧1-上下拼侧2",new string[] { "小侧", "小侧1-上下拼侧2裥棉" } },
  1211. {"小侧1-上下拼侧3",new string[] { "小侧", "小侧1-上下拼侧3裥棉" } },
  1212. {"小侧2",new string[] { "小侧", "小侧2裥棉", "小侧2裥棉图案" } },
  1213. {"小侧3",new string[] { "小侧", "小侧3裥棉", "小侧3裥棉图案", "小侧说明" } },
  1214. {"V侧1_EMPTY",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  1215. {"V侧1",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  1216. {"V侧2",new string[] { "V侧", "V侧2裥棉", "V侧2裥棉图案" } },
  1217. {"V侧3",new string[] { "V侧", "V侧3裥棉", "V侧3裥棉图案", "V侧说明" } }
  1218. };
  1219. var extreDict = new HashSet<string>() { "小侧", "V侧" };
  1220. var jianmianList = mxlist.Where(t => t.formulatype == 0).ToList();
  1221. var isEnter = false;
  1222. #region wf_import_qingdan_prdpf
  1223. foreach (var item in powerDict)
  1224. {
  1225. // 保证清单列表类别一致,从面裥绵 -> V侧3
  1226. foreach (var mx in jianmianList)
  1227. {
  1228. if (mx.mtrlid > 0 && (item.Key.Equals(mx.chastr) || item.Key.Contains("_EMPTY")) && item.Value.Contains(mx.formulakind.Value))
  1229. {
  1230. if (mx.formulakind == 0 || mx.formulakind == 1 || mx.formulakind == 2 || mx.formulakind == 3)
  1231. {
  1232. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "布料", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1233. }
  1234. if (mx.formulakind == 40 || mx.formulakind == 41 || mx.formulakind == 42 || mx.formulakind == 43)
  1235. {
  1236. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "喷胶棉", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1237. }
  1238. if (mx.formulakind == 50 || mx.formulakind == 51 || mx.formulakind == 52 || mx.formulakind == 53)
  1239. {
  1240. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "裥面海绵", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1241. }
  1242. if (mx.formulakind == 60 || mx.formulakind == 61 || mx.formulakind == 62 || mx.formulakind == 63)
  1243. {
  1244. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "无纺布", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1245. }
  1246. }
  1247. }
  1248. if(item.Key.Contains("小侧3") || item.Key.Contains("V侧3"))
  1249. {
  1250. var list = qdList.FindAll(t => extreDict.Contains(t.itemname)).ToList();
  1251. if(list.Any())
  1252. {
  1253. foreach (var name in chastrArrDict[item.Key])
  1254. {
  1255. if (name.Contains("说明"))
  1256. {
  1257. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], name, ""));
  1258. }
  1259. }
  1260. }
  1261. } else
  1262. {
  1263. foreach (var name in chastrArrDict[item.Key])
  1264. {
  1265. if (name.Contains("说明"))
  1266. {
  1267. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], name, ""));
  1268. }
  1269. }
  1270. }
  1271. }
  1272. #endregion
  1273. #region wf_import_qingdan_next 面料部分
  1274. // 按照 formulakind 分组
  1275. var grouped = jianmianList
  1276. .Where(t => t.formulakind >= 5 && t.formulakind <= 10)
  1277. .GroupBy(t => t.formulakind);
  1278. // 需要处理的组的名称与编号映射
  1279. var groupNames = new Dictionary<int, string>
  1280. {
  1281. { 5, "拉手" },
  1282. { 6, "刺绣" },
  1283. { 7, "大侧压压布" },
  1284. { 8, "大侧压边带" },
  1285. { 9, "大侧压织带" },
  1286. { 10, "大侧压上下压线" }
  1287. };
  1288. // 处理每一组
  1289. foreach (var group in grouped)
  1290. {
  1291. var formulakind = group.Key.Value;
  1292. var name = groupNames.ContainsKey(formulakind) ? groupNames[formulakind] : "未知组";
  1293. foreach (var mx in group)
  1294. {
  1295. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  1296. {
  1297. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺",$"{name}{group.ToList().IndexOf(mx) + 1}","",
  1298. mx.mtrlid.Value,
  1299. mx.useqty.Value
  1300. ));
  1301. }
  1302. }
  1303. }
  1304. // 统一添加固定项
  1305. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺", "拉手刺绣", ""));
  1306. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺", "拉手无纺布", ""));
  1307. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺", "侧刺绣做法", ""));
  1308. #endregion
  1309. }
  1310. private void AutoSetFormulaTypeOnePrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1311. {
  1312. var diancengList = mxlist.Where(t => t.formulatype == 1).ToList();
  1313. var kindDict = new Dictionary<int, string>()
  1314. {
  1315. { 32,"垫层" },
  1316. { 12,"顶布" },
  1317. { 13,"毡类" },
  1318. { 14,"打底无纺布" },
  1319. { 29,"网面布料" },
  1320. { 999,"床网" },
  1321. {1201,"顶布裥棉" }
  1322. };
  1323. var chastrSet = new HashSet<string>() { "大侧", "小侧1", "小侧2", "小侧3", "V侧1", "V侧2", "V侧3" };
  1324. var countDict = new Dictionary<string, int>();
  1325. foreach (var cha in chastrSet)
  1326. {
  1327. foreach (var kind in kindDict)
  1328. {
  1329. countDict.Add($"{cha}-{kind.Value}", 0);
  1330. }
  1331. }
  1332. foreach (var mx in diancengList)
  1333. {
  1334. var key = $"{mx.chastr}-{kindDict[mx.formulakind.Value]}";
  1335. if (mx.mtrlid > 0 && new int[] { 32, 12, 13, 14, 29 }.Contains(mx.formulakind.Value))
  1336. {
  1337. this.ProcessWangMianBLPrdPf(mx, qdList, mx.chastr, kindDict[mx.formulakind.Value], ++countDict[key]);
  1338. } else if (mx.formulakind == 999)
  1339. {
  1340. this.ProcessChuangWangPrdPf(mx, qdList, mx.chastr, ++countDict[key]);
  1341. } else if(mx.formulakind == 1201)
  1342. {
  1343. // 不需要操作
  1344. }
  1345. }
  1346. // 顶布裥面说明
  1347. qdList.Add(InserMattressInterfacePrdPf("顶布裥棉", "顶布裥面说明1", ""));
  1348. qdList.Add(InserMattressInterfacePrdPf("顶布裥棉", "顶布裥面说明2", ""));
  1349. }
  1350. /// <summary>
  1351. /// 床网
  1352. /// </summary>
  1353. /// <param name="mx"></param>
  1354. /// <param name="interfaceList"></param>
  1355. /// <param name="chastr"></param>
  1356. /// <param name="count"></param>
  1357. private void ProcessChuangWangPrdPf(u_mattress_mx_mtrl mx, List<u_mattress_interface_qd> qdList, string chastr, int count)
  1358. {
  1359. var namepz = string.Empty;
  1360. int bednetid = 0;
  1361. cmd.CommandText = @"SELECT u_bednetmx.bednet_height,u_bednetmx.bednetid
  1362. FROM u_bednetmx
  1363. INNER JOIN (
  1364. SELECT mtrlid
  1365. FROM u_mattress_mx_mtrl
  1366. INNER JOIN u_mattress_formula ON u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  1367. WHERE u_mattress_formula.formulakind = 99
  1368. AND u_mattress_mx_mtrl.mattressid = @mattressid
  1369. AND u_mattress_mx_mtrl.mtrlid > 0
  1370. ) v_mattress_mx_mtrl ON u_bednetmx.bednetid = v_mattress_mx_mtrl.mtrlid";
  1371. cmd.Parameters.Clear();
  1372. cmd.Parameters.AddWithValue("@mattressid", mx.mattressid);
  1373. using (var reader = cmd.ExecuteReader())
  1374. {
  1375. while (reader.Read())
  1376. {
  1377. decimal height = Convert.ToDecimal(reader["bednet_height"]);
  1378. if (height == mx.thickness) bednetid = Convert.ToInt32(reader["bednetid"]);
  1379. }
  1380. }
  1381. if (bednetid > 0)
  1382. {
  1383. // 获取床网清单
  1384. var bednetList = new List<u_bednetmx>();
  1385. if (bednetList.Any())
  1386. {
  1387. var bednetHelper = HelperBase.GetHelper<BedNetHelper>(cmd);
  1388. var bednetQdList = bednetHelper.GetBedNetQingDan(bednetid);
  1389. if (bednetQdList.Any())
  1390. {
  1391. namepz = bednetQdList[0].pznamemx;
  1392. }
  1393. }
  1394. }
  1395. qdList.Add(InserMattressInterfacePrdPf("垫层", $"{chastr}-床网{count}", namepz, mx.mtrlid.Value, mx.useqty.Value));
  1396. // 海绵条*4 2
  1397. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条1", ""));
  1398. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条2", ""));
  1399. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条3", ""));
  1400. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条4", ""));
  1401. }
  1402. /// <summary>
  1403. /// 网面布料 / 打底无纺布 / 毡类 / 顶布 / 垫层
  1404. /// </summary>
  1405. /// <param name="mx"></param>
  1406. /// <param name="interfaceList"></param>
  1407. /// <param name="chastr"></param>
  1408. /// <param name="count"></param>
  1409. private void ProcessWangMianBLPrdPf(u_mattress_mx_mtrl mx, List<u_mattress_interface_qd> qdList, string chastr, string typename, int count)
  1410. {
  1411. var mtrlname_temp = mx.mtrlname;
  1412. if ((!mx.mtrlname.Contains("分") && mx.thickness > 0) || ("垫层".Equals(typename)))
  1413. {
  1414. mtrlname_temp = $"{mx.thickness.Value.ToString("#,##0.0#")}分{mx.mtrlname}";
  1415. }
  1416. qdList.Add(InserMattressInterfacePrdPf("垫层", $"{chastr}-{typename}{count}", "",mx.mtrlid.Value,mx.useqty.Value));
  1417. }
  1418. private void AutoSetFormulaTypeTwoPrfPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1419. {
  1420. var fuliaoList = mxlist.Where(t => t.formulatype == 2).ToList();
  1421. var nameSet = new HashSet<string>(new string[] {
  1422. "保用卡", "采购小标", "打钮钮扣", "打印小标", "合格证", "画纸", "开箱说明+开箱刀", "吊标", "客供标",
  1423. "空白牛皮纸包角", "空白珍珠包角", "气钮","说明书","斜标","正标","织唛","织唛斜标"
  1424. });
  1425. var extraSet = new HashSet<string>(new string[] { "保用卡", "采购小标", "打钮钮扣", "打印小标", "合格证", "画纸", "开箱说明+开箱刀", "吊标", "客供标",
  1426. "空白牛皮纸包角", "空白珍珠包角", "气钮","说明书","斜标","正标","织唛","织唛斜标","角网+拉链","开箱刀+开箱说明" });
  1427. var specialSet = new HashSet<string>(new string[] { "打钮钮扣", "气钮" });
  1428. foreach (var mx in fuliaoList)
  1429. {
  1430. if (mx.mtrlid > 0)
  1431. {
  1432. int cnt = Convert.ToInt32(Math.Abs(mx.qty.Value));
  1433. // 处理特殊辅料
  1434. if (specialSet.Contains(mx.mtrlname))
  1435. {
  1436. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}", "", mx.mtrlid.Value, mx.useqty.Value));
  1437. continue; // 跳过后续的处理
  1438. }
  1439. // 处理其他辅料
  1440. if (nameSet.Contains(mx.mtrlname))
  1441. {
  1442. for (int i = 1; i <= cnt; i++)
  1443. {
  1444. // 添加辅料接口
  1445. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}{i}", "",mx.mtrlid.Value,mx.useqty.Value));
  1446. }
  1447. } else if(mx.formulakind == 15 && !extraSet.Contains(mx.mtrlname))
  1448. {
  1449. for (int i = 1; i <= cnt; i++)
  1450. {
  1451. // 添加辅料接口
  1452. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}{i}", "", mx.mtrlid.Value, mx.useqty.Value));
  1453. // 如果是额外的辅料,添加位置接口
  1454. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}{i}位置", "", mx.mtrlid.Value, mx.useqty.Value));
  1455. }
  1456. }
  1457. }
  1458. }
  1459. }
  1460. private void AutoSetFormulaTypeThreePrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1461. {
  1462. // 筛选 formulatype 为 3 的物料
  1463. var bzList = mxlist.Where(t => t.formulatype == 3).ToList();
  1464. var chastrDict = new Dictionary<int, string>
  1465. {
  1466. {16, "PE袋"},
  1467. {17, "外层PE"},
  1468. {18, "PVC"},
  1469. {19, "卷包包装"},
  1470. {20, "牛皮纸袋"},
  1471. {21, "蓝色PE护角"},
  1472. {22, "无纺布袋"},
  1473. {23, "牛皮袋护角"},
  1474. {24, "编织袋"},
  1475. {27, "拉手脚轮"},
  1476. {201, "无纺布护角"}
  1477. };
  1478. var countDict = new Dictionary<int, int>
  1479. {
  1480. {16, 0}
  1481. };
  1482. foreach (var mx in bzList)
  1483. {
  1484. if (mx.mtrlid > 0 && chastrDict.TryGetValue(mx.formulakind.GetValueOrDefault(), out var chastr))
  1485. {
  1486. var name_arr = new string[1];
  1487. if (mx.qty.HasValue && mx.qty.Value > 1)
  1488. {
  1489. name_arr[0] = $"{mx.qty.Value.ToString("#,##0.0#")}个{mx.mtrlname}";
  1490. }
  1491. else
  1492. {
  1493. name_arr[0] = mx.mtrlname;
  1494. }
  1495. if (countDict.ContainsKey(mx.formulakind.Value))
  1496. {
  1497. chastr += countDict[mx.formulakind.Value];
  1498. }
  1499. // 添加包装信息
  1500. qdList.Add(InserMattressInterfacePrdPf("包装", chastr,"",mx.mtrlid.Value,mx.useqty.Value));
  1501. }
  1502. }
  1503. // 包装说明
  1504. qdList.Add(InserMattressInterfacePrdPf("包装", "包装说明", ""));
  1505. // 车位说明
  1506. qdList.Add(InserMattressInterfacePrdPf("车位说明", "车位说明", ""));
  1507. }
  1508. private void AutoSetFormulaType101PrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1509. {
  1510. var powerDict = new Dictionary<string, int[]>()
  1511. {
  1512. {"面裥绵",new int[] { 0, 40, 50, 60, 70,80 } },
  1513. {"底裥绵",new int[] { 1, 41, 51, 61, 71 } },
  1514. {"普通大侧",new int[] { 2, 42, 52, 62, 72 } }
  1515. };
  1516. var chastrDict = new Dictionary<string, string[]>()
  1517. {
  1518. {"面裥绵",new string[] { "内布套-面层裥棉", "内布套-面层裥棉裥棉图案" } },
  1519. {"底裥绵",new string[] { "内布套-底层裥棉", "内布套-底层裥棉裥棉图案" } },
  1520. {"普通大侧",new string[] { "内布套-大侧裥棉", "内布套-大侧裥棉裥棉图案" } }
  1521. };
  1522. foreach (var item in powerDict)
  1523. {
  1524. var name_arr = new string[5];
  1525. foreach (var mx in mxlist)
  1526. {
  1527. if (mx.mtrlid > 0 && (item.Key.Equals(mx.chastr) || item.Key.Contains("_EMPTY")) && item.Value.Contains(mx.formulakind.Value))
  1528. {
  1529. if (mx.formulakind == 0 || mx.formulakind == 1 || mx.formulakind == 2 || mx.formulakind == 3)
  1530. {
  1531. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "布料", mx.mtrlid.Value, mx.useqty.Value));
  1532. }
  1533. if (mx.formulakind == 40 || mx.formulakind == 41 || mx.formulakind == 42 || mx.formulakind == 43)
  1534. {
  1535. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "喷胶棉", mx.mtrlid.Value, mx.useqty.Value));
  1536. }
  1537. if (mx.formulakind == 50 || mx.formulakind == 51 || mx.formulakind == 52 || mx.formulakind == 53)
  1538. {
  1539. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "裥面海绵", mx.mtrlid.Value, mx.useqty.Value));
  1540. }
  1541. if (mx.formulakind == 60 || mx.formulakind == 61 || mx.formulakind == 62 || mx.formulakind == 63)
  1542. {
  1543. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "无纺布", mx.mtrlid.Value, mx.useqty.Value));
  1544. }
  1545. }
  1546. }
  1547. }
  1548. // 内布套-围边边带 / 拉链
  1549. foreach (var mx in mxlist)
  1550. {
  1551. if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 203)
  1552. {
  1553. qdList.Add(InserMattressInterfacePrdPf("内布套", "内布套-围边边带", "围边",mx.mtrlid.Value,mx.useqty.Value));
  1554. }
  1555. else if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 202)
  1556. {
  1557. qdList.Add(InserMattressInterfacePrdPf("内布套", "内布套-拉链", "拉链", mx.mtrlid.Value, mx.useqty.Value));
  1558. }
  1559. }
  1560. }
  1561. #endregion
  1562. #region 通用方法
  1563. /// <summary>
  1564. /// 用于 字符串 + 字符串格式
  1565. /// </summary>
  1566. /// <param name="currentString"></param>
  1567. /// <param name="newPart"></param>
  1568. /// <returns></returns>
  1569. private string AppendToString(string currentString, string newPart)
  1570. {
  1571. if (string.IsNullOrEmpty(currentString))
  1572. {
  1573. return newPart;
  1574. }
  1575. else
  1576. {
  1577. return currentString + " + " + newPart;
  1578. }
  1579. }
  1580. /// <summary>
  1581. /// 数量分割字符串
  1582. /// </summary>
  1583. /// <param name="name"></param>
  1584. /// <param name="qty"></param>
  1585. /// <returns></returns>
  1586. private string SplitNameCount(string name, int qty)
  1587. {
  1588. if (qty <= 1) return name;
  1589. var result = name;
  1590. result = AppendToString(result, SplitNameCount(name, --qty));
  1591. return result;
  1592. }
  1593. #endregion
  1594. #region 全局变量
  1595. // 储存顶布裥棉数据
  1596. private string[,] DingBuLianMian = new string[4,5];
  1597. private enum PackType
  1598. {
  1599. 压包 = 0,
  1600. 卷包,
  1601. 国内
  1602. }
  1603. #endregion
  1604. }
  1605. }