InterfaceHelper.cs 81 KB

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