InterfaceHelper.cs 82 KB

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