InterfaceHelper.cs 93 KB

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