InterfaceHelper.cs 84 KB

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