BedNetHelper.cs 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909
  1. using CSUST.Data.Expr;
  2. using DirectService.Tools;
  3. using JLHHJSvr.BLL;
  4. using JLHHJSvr.Com.Model;
  5. using JLHHJSvr.LJException;
  6. using JLHHJSvr.LJFramework.Tools;
  7. using LJLib.DAL.SQL;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data.SqlClient;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Text.RegularExpressions;
  14. using System.Threading.Tasks;
  15. namespace JLHHJSvr.Helper
  16. {
  17. internal class BedNetHelper : HelperBase
  18. {
  19. private Dictionary<string, object> replacements = new Dictionary<string, object>();
  20. /// <summary>
  21. /// 默认展示公式
  22. /// </summary>
  23. private Dictionary<string, formulaItem> formula_replacements = new Dictionary<string, formulaItem>();
  24. /// <summary>
  25. /// 隐藏公式
  26. /// </summary>
  27. private Dictionary<string, formulaItem> formula_replacements_hide = new Dictionary<string, formulaItem>();
  28. /// <summary>
  29. /// 详细展示公式
  30. /// </summary>
  31. private Dictionary<string, formulaItem> formula_replacements_mx = new Dictionary<string, formulaItem>();
  32. /// <summary>
  33. /// 重量展示公式
  34. /// </summary>
  35. private Dictionary<string, formulaItem> formula_replacements_weight = new Dictionary<string, formulaItem>();
  36. public sealed class formulaItem
  37. {
  38. public string value { get; set; }
  39. public int? ifnotreplace { get; set; }
  40. }
  41. public List<replacement> Replacements
  42. {
  43. get
  44. {
  45. var res = new List<replacement>();
  46. foreach (var item in replacements)
  47. {
  48. res.Add(new replacement { label = item.Key, value = item.Value, type = 0 });
  49. }
  50. return res;
  51. }
  52. }
  53. public List<replacement> FormulaReplacements
  54. {
  55. get {
  56. var res = new List<replacement>();
  57. foreach (var item in formula_replacements)
  58. {
  59. res.Add(new replacement { label = item.Key, value = item.Value.value, type = 0, ifnotreplace = item.Value.ifnotreplace});
  60. }
  61. foreach (var item in formula_replacements_hide)
  62. {
  63. res.Add(new replacement { label = item.Key, value = item.Value.value, type = 1, ifnotreplace = item.Value.ifnotreplace });
  64. }
  65. foreach (var item in formula_replacements_mx)
  66. {
  67. res.Add(new replacement { label = item.Key, value = item.Value.value, type = 2, ifnotreplace = item.Value.ifnotreplace });
  68. }
  69. foreach (var item in formula_replacements_weight)
  70. {
  71. res.Add(new replacement { label = item.Key, value = item.Value.value, type = 3, ifnotreplace = item.Value.ifnotreplace });
  72. }
  73. return res;
  74. }
  75. }
  76. public void CalCulateFormula(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  77. {
  78. InitBedNet(bednet);
  79. InitReplaceMents(bednet);
  80. CulcalateCost(bednet, mxlist, springList);
  81. CulcalateWeight(bednet, mxlist, springList);
  82. }
  83. private void CulcalateCost(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  84. {
  85. bednet.spring_mtrl_cost = 0;
  86. bednet.spring_hr_cost = 0;
  87. bednet.snake_wire_mtrl_cost = 0;
  88. bednet.pocket_around_spring_cost = 0;
  89. bednet.pocket_around_fabrics_cost = 0;
  90. bednet.hard_around_mtrl_cost = 0;
  91. bednet.hard_around_hr_cost = 0;
  92. bednet.fabrics1_mtrl_cost = 0;
  93. bednet.glue_mtrl_cost = 0;
  94. bednet.fabrics2_mtrl_cost = 0;
  95. bednet.side_iron_hr_cost = 0;
  96. bednet.side_iron_mtrl_cost = 0;
  97. bednet.cnail_mtrl_cost = 0;
  98. bednet.cnail_hr_cost = 0;
  99. bednet.sponge_mtrl_cost = 0;
  100. bednet.sponge_hr_cost = 0;
  101. bednet.sponge_mtrl_tc_cost = 0;
  102. bednet.edge_mtrl_cost = 0;
  103. bednet.edge_hr_cost = 0;
  104. bednet.fork_mtrl_cost = 0;
  105. bednet.fork_hr_cost = 0;
  106. bednet.rsorwa_mtrl_cost = 0;
  107. bednet.rsorwa_hr_cost = 0;
  108. bednet.sponge_drilling_hr_cost = 0;
  109. bednet.felt_mtrl_cost = 0;
  110. bednet.felt_mtrl_x_cost = 0;
  111. bednet.felt_hr_cost = 0;
  112. bednet.felt_hr_x_cost = 0;
  113. bednet.packet_mtrl_cost = 0;
  114. bednet.packet_hr_cost = 0;
  115. foreach (var mx in mxlist)
  116. {
  117. var spring = new u_spring() { springid = mx.springid };
  118. DbSqlHelper.SelectOne(cmd, spring, "line_diameter,gram_weight,height,center_diameter");
  119. // 处理相同公式部分
  120. InitMxReplaceMents(bednet, mx, spring);
  121. //计算 弹簧材料总成本
  122. #region 计算 弹簧材料总成本 开始
  123. if (!string.IsNullOrEmpty(bednet.spring_mtrl_formula))
  124. {
  125. mx.spring_mtrl_cost_replace_formula = bednet.spring_mtrl_formula;
  126. if (mx.if_part == 0)
  127. {
  128. //单分区
  129. //考虑 四周加硬和四周口袋 扣减 排列数情况
  130. if (mx.if_hard_around == 1)
  131. {
  132. decimal hard_around_row = mx.hard_around_row.Value;
  133. if (bednet.typename.IndexOf("袋装", StringComparison.Ordinal) >= 0) hard_around_row *= 2;
  134. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧排列个数-宽】", $"(【弹簧排列个数-宽】 - {hard_around_row})");
  135. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧计算个数(宽)】", $"(【弹簧计算个数(宽)】 - {hard_around_row})");
  136. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧排列个数-长】", $"(【弹簧排列个数-长】 - {hard_around_row})");
  137. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧计算个数(长)】", $"(【弹簧计算个数(长)】 - {hard_around_row})");
  138. }
  139. if (mx.if_pocket_around == 1)
  140. {
  141. decimal pocket_around_row = mx.pocket_around_row.Value;
  142. if (bednet.typename.IndexOf("袋装", StringComparison.Ordinal) >= 0) pocket_around_row *= 2;
  143. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧排列个数-宽】", $"(【弹簧排列个数-宽】 - {pocket_around_row})");
  144. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧计算个数(宽)】", $"(【弹簧计算个数(宽)】 - {pocket_around_row})");
  145. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧排列个数-长】", $"(【弹簧排列个数-长】 - {pocket_around_row})");
  146. mx.spring_mtrl_cost_replace_formula = mx.spring_mtrl_cost_replace_formula.Replace("【弹簧计算个数(长)】", $"(【弹簧计算个数(长)】 - {pocket_around_row})");
  147. }
  148. mx.spring_mtrl_cost = Calculate(mx.spring_mtrl_cost_replace_formula, "弹簧材料总成本").DecimalValue;
  149. bednet.spring_mtrl_cost += mx.spring_mtrl_cost;
  150. }
  151. else
  152. {
  153. mx.spring_mtrl_cost = 0;
  154. //多分区
  155. foreach (var springItem in springList)
  156. {
  157. springItem.spring_mtrl_cost_replace_formula = bednet.spring_mtrl_formula;
  158. CalSpringMtrlCol(bednet, mx, springItem);
  159. springItem.spring_mtrl_cost = Calculate(springItem.spring_mtrl_cost_replace_formula, "弹簧材料总成本").DecimalValue;
  160. mx.spring_mtrl_cost += springItem.spring_mtrl_cost;
  161. bednet.spring_mtrl_cost += springItem.spring_mtrl_cost;
  162. }
  163. }
  164. AddKeyValue("弹簧排列个数-宽", mx.spring_qty_width);
  165. AddKeyValue("弹簧排列个数-长", mx.spring_qty_length);
  166. AddKeyValue("弹簧计算个数(宽)", mx.spring_qty_width);
  167. AddKeyValue("弹簧计算个数(长)", mx.spring_qty_length);
  168. AddKeyValue("弹簧材料总成本", bednet.spring_mtrl_cost);
  169. AddFormulaMxKeyValue("【弹簧材料总成本】", bednet.spring_mtrl_formula, true, 1);
  170. }
  171. #endregion 计算 弹簧材料总成本 结束
  172. #region 计算 弹簧人工总成本 开始
  173. if (!string.IsNullOrEmpty(bednet.spring_hr_formula))
  174. {
  175. mx.spring_hr_cost_replace_formula = bednet.spring_hr_formula;
  176. mx.spring_hr_cost = Calculate(mx.spring_hr_cost_replace_formula, "弹簧总人工成本").DecimalValue;
  177. bednet.spring_hr_cost += mx.spring_hr_cost;
  178. AddKeyValue("弹簧总人工成本", bednet.spring_hr_cost);
  179. AddFormulaMxKeyValue("【弹簧总人工成本】", bednet.spring_hr_formula, true, 1);
  180. }
  181. #endregion 计算 弹簧人工总成本 结束
  182. #region 计算 蛇线材料成本 开始
  183. if (!string.IsNullOrEmpty(bednet.spring_hr_formula))
  184. {
  185. bednet.snake_wire_mtrl_cost_replace_formula = bednet.snake_wire_mtrl_formula;
  186. CalSnakeCol(bednet,spring);
  187. bednet.snake_wire_mtrl_cost += Calculate(bednet.snake_wire_mtrl_cost_replace_formula, "蛇线材料成本").DecimalValue;
  188. AddKeyValue("蛇线材料成本", bednet.snake_wire_mtrl_cost);
  189. AddFormulaMxKeyValue("【蛇线材料成本】", bednet.snake_wire_mtrl_formula);
  190. }
  191. #endregion 计算 蛇线材料成本 结束
  192. #region 计算 四周口袋弹簧成本 开始
  193. if (!string.IsNullOrEmpty(bednet.pocket_around_spring_formula) && mx.if_pocket_around > 0)
  194. {
  195. mx.pocket_around_spring_cost_replace_formula = bednet.pocket_around_spring_formula;
  196. mx.pocket_around_spring_cost = Calculate(mx.pocket_around_spring_cost_replace_formula, "四周口袋弹簧成本").DecimalValue;
  197. bednet.pocket_around_spring_cost += mx.pocket_around_spring_cost;
  198. AddKeyValue("四周口袋弹簧成本", bednet.pocket_around_spring_cost);
  199. AddFormulaMxKeyValue("【四周口袋弹簧成本】", bednet.pocket_around_spring_formula);
  200. }
  201. #endregion 计算 四周口袋弹簧成本 结束
  202. #region 计算 四周口袋无纺布成本 开始
  203. if (!string.IsNullOrEmpty(bednet.pocket_around_fabrics_formula) && mx.if_pocket_around > 0)
  204. {
  205. mx.pocket_around_fabrics_cost_replace_formula = bednet.pocket_around_fabrics_formula;
  206. mx.pocket_around_fabrics_cost = Calculate(mx.pocket_around_fabrics_cost_replace_formula, "四周口袋无纺布成本").DecimalValue;
  207. bednet.pocket_around_fabrics_cost += mx.pocket_around_fabrics_cost;
  208. AddKeyValue("四周口袋无纺布成本", bednet.pocket_around_fabrics_cost);
  209. AddFormulaMxKeyValue("【四周口袋无纺布成本】", bednet.pocket_around_fabrics_formula);
  210. }
  211. #endregion 计算 四周口袋无纺布成本 结束
  212. #region 计算 四周加硬材料成本 开始
  213. if (!string.IsNullOrEmpty(bednet.hard_around_mtrl_formula) && mx.if_hard_around > 0)
  214. {
  215. mx.hard_around_mtrl_cost_replace_formula = bednet.hard_around_mtrl_formula;
  216. mx.hard_around_mtrl_cost = Calculate(mx.hard_around_mtrl_cost_replace_formula, "四周加硬材料成本").DecimalValue;
  217. bednet.hard_around_mtrl_cost += mx.hard_around_mtrl_cost;
  218. AddKeyValue("四周加硬材料成本", bednet.hard_around_mtrl_cost);
  219. AddFormulaMxKeyValue("【四周加硬材料成本】", bednet.hard_around_mtrl_formula);
  220. }
  221. #endregion 计算 四周加硬材料成本 结束
  222. #region 计算 四周加硬人力成本 开始
  223. if (!string.IsNullOrEmpty(bednet.hard_around_hr_formula) && mx.if_hard_around > 0)
  224. {
  225. mx.hard_around_hr_cost_replace_formula = bednet.hard_around_hr_formula;
  226. mx.hard_around_hr_cost = Calculate(mx.hard_around_hr_cost_replace_formula, "四周加硬人力成本").DecimalValue;
  227. bednet.hard_around_hr_cost += mx.hard_around_hr_cost;
  228. AddKeyValue("四周加硬人力成本", bednet.hard_around_hr_cost);
  229. AddFormulaMxKeyValue("【四周加硬人力成本】", bednet.hard_around_hr_formula);
  230. }
  231. #endregion 计算 四周加硬人力成本 结束
  232. #region 计算 入袋无纺布材料成本 开始
  233. if (!string.IsNullOrEmpty(bednet.hard_around_hr_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics1_mtrlid > 0)
  234. {
  235. mx.fabrics1_mtrl_cost_replace_formula = bednet.fabrics1_mtrl_formula;
  236. CalSpringMtrlCol2(bednet, mx, springList, "入袋无纺布");
  237. mx.fabrics1_mtrl_cost = Calculate(mx.fabrics1_mtrl_cost_replace_formula, "入袋无纺布材料成本").DecimalValue;
  238. bednet.fabrics1_mtrl_cost += mx.fabrics1_mtrl_cost;
  239. AddKeyValue("入袋无纺布材料成本", bednet.fabrics1_mtrl_cost);
  240. AddFormulaMxKeyValue("【入袋无纺布材料成本】", bednet.fabrics1_mtrl_formula);
  241. }
  242. #endregion 计算 入袋无纺布材料成本 结束
  243. #region 计算 胶水材料成本 开始
  244. if (!string.IsNullOrEmpty(bednet.glue_mtrl_formula))
  245. {
  246. mx.glue_mtrl_cost_replace_formula = bednet.glue_mtrl_formula;
  247. bednet.glue_mtrl_cost += Calculate(mx.glue_mtrl_cost_replace_formula, "胶水材料成本").DecimalValue;
  248. AddKeyValue("胶水材料成本", bednet.glue_mtrl_cost);
  249. AddFormulaMxKeyValue("【胶水材料成本】", bednet.glue_mtrl_formula);
  250. }
  251. #endregion 计算 胶水材料成本 结束
  252. #region 计算 底面无纺布材料成本 开始
  253. if (!string.IsNullOrEmpty(bednet.hard_around_hr_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics2_mtrlid > 0)
  254. {
  255. mx.fabrics2_mtrl_cost_replace_formula = bednet.fabrics2_mtrl_formula;
  256. CalSpringMtrlCol2(bednet, mx, springList, "底面无纺布");
  257. mx.fabrics2_mtrl_cost = Calculate(mx.fabrics2_mtrl_cost_replace_formula, "底面无纺布材料成本").DecimalValue;
  258. bednet.fabrics2_mtrl_cost += mx.fabrics2_mtrl_cost;
  259. AddKeyValue("底面无纺布材料成本", bednet.fabrics2_mtrl_cost);
  260. AddFormulaMxKeyValue("【底面无纺布材料成本】", bednet.fabrics2_mtrl_formula);
  261. }
  262. #endregion 计算 底面无纺布材料成本 结束
  263. #region 计算 边铁人力成本 开始
  264. if (!string.IsNullOrEmpty(bednet.side_iron_hr_formula) && bednet.if_side_iron == 1 && mx.if_side_iron > 0)
  265. {
  266. mx.side_iron_hr_cost_replace_formula = bednet.side_iron_hr_formula;
  267. mx.side_iron_hr_cost = Calculate(mx.side_iron_hr_cost_replace_formula, "边铁人力成本").DecimalValue;
  268. bednet.side_iron_hr_cost += mx.side_iron_hr_cost;
  269. AddKeyValue("边铁人力成本", bednet.side_iron_hr_cost);
  270. AddFormulaMxKeyValue("【边铁人力成本】", bednet.side_iron_hr_formula);
  271. }
  272. #endregion 计算 边铁人力成本 结束
  273. #region 计算 边铁材料成本 开始
  274. if (!string.IsNullOrEmpty(bednet.side_iron_mtrl_formula) && bednet.if_side_iron == 1 && mx.if_side_iron > 0)
  275. {
  276. mx.side_iron_mtrl_cost_replace_formula = bednet.side_iron_mtrl_formula;
  277. mx.side_iron_mtrl_cost = Calculate(mx.side_iron_mtrl_cost_replace_formula, "边铁材料成本").DecimalValue;
  278. bednet.side_iron_mtrl_cost += mx.side_iron_mtrl_cost;
  279. AddKeyValue("边铁材料成本", bednet.side_iron_mtrl_cost);
  280. AddFormulaMxKeyValue("【边铁材料成本】", bednet.side_iron_mtrl_formula);
  281. }
  282. #endregion 计算 边铁材料成本 结束
  283. #region 计算 C钉/夹码材料 开始
  284. if (!string.IsNullOrEmpty(bednet.cnail_mtrl_formula))
  285. {
  286. mx.cnail_mtrl_cost_replace_formula = bednet.cnail_mtrl_formula;
  287. mx.cnail_mtrl_cost = Calculate(mx.cnail_mtrl_cost_replace_formula, "C钉/夹码材料成本").DecimalValue;
  288. bednet.cnail_mtrl_cost += mx.cnail_mtrl_cost;
  289. AddKeyValue("C钉/夹码材料成本", bednet.cnail_mtrl_cost);
  290. AddFormulaMxKeyValue("【C钉/夹码材料成本】", bednet.cnail_mtrl_formula);
  291. }
  292. #endregion 计算 C钉/夹码材料 结束
  293. #region 计算 C钉/夹码人力成本 开始
  294. if (!string.IsNullOrEmpty(bednet.cnail_hr_formula))
  295. {
  296. mx.cnail_hr_cost_replace_formula = bednet.cnail_hr_formula;
  297. mx.cnail_hr_cost = Calculate(mx.cnail_hr_cost_replace_formula, "C钉/夹码人力成本").DecimalValue;
  298. bednet.cnail_hr_cost += mx.cnail_hr_cost;
  299. AddKeyValue("C钉/夹码人力成本", bednet.cnail_hr_cost);
  300. AddFormulaMxKeyValue("【C钉/夹码人力成本】", bednet.cnail_hr_formula);
  301. }
  302. #endregion 计算 C钉/夹码人力成本 结束
  303. #region 计算 海绵包边材料成本 开始
  304. if (!string.IsNullOrEmpty(bednet.sponge_mtrl_formula) && bednet.sponge_mtrlid > 0)
  305. {
  306. bednet.sponge_mtrl_cost_replace_formula = bednet.sponge_mtrl_formula;
  307. CalSpringMtrlCol2(bednet, mx, springList, "海绵包边");
  308. bednet.sponge_mtrl_cost += Calculate(bednet.sponge_mtrl_cost_replace_formula, "海绵包边材料成本").DecimalValue;
  309. AddKeyValue("海绵包边材料成本", bednet.sponge_mtrl_cost);
  310. AddFormulaMxKeyValue("【海绵包边材料成本】", bednet.sponge_mtrl_formula);
  311. }
  312. #endregion 计算 海绵包边材料成本 结束
  313. #region 计算 海绵包边人力成本 开始
  314. if (!string.IsNullOrEmpty(bednet.sponge_hr_formula) && bednet.sponge_mtrlid > 0)
  315. {
  316. bednet.sponge_hr_cost_replace_formula = bednet.sponge_hr_formula;
  317. bednet.sponge_hr_cost += Calculate(bednet.sponge_hr_cost_replace_formula, "海绵包边人力成本").DecimalValue;
  318. AddKeyValue("海绵包边人力成本", bednet.sponge_hr_cost);
  319. AddFormulaMxKeyValue("【海绵包边人力成本】", bednet.sponge_hr_formula);
  320. }
  321. #endregion 计算 海绵包边人力成本 结束
  322. #region 计算 填充海绵成本 开始
  323. if (!string.IsNullOrEmpty(bednet.sponge_mtrl_tc_formula) && bednet.sponge_tc_mtrlid > 0)
  324. {
  325. bednet.sponge_mtrl_tc_cost_replace_formula = bednet.sponge_mtrl_tc_formula;
  326. CalSpringMtrlCol2(bednet, mx, springList, "填充海绵");
  327. bednet.sponge_mtrl_tc_cost += Calculate(bednet.sponge_mtrl_tc_cost_replace_formula, "填充海绵成本").DecimalValue;
  328. AddKeyValue("填充海绵成本", bednet.sponge_mtrl_tc_cost);
  329. AddFormulaMxKeyValue("【填充海绵成本】", bednet.sponge_mtrl_tc_formula);
  330. }
  331. #endregion 计算 填充海绵成本 结束
  332. #region 计算 封边材料成本 开始
  333. if (!string.IsNullOrEmpty(bednet.edge_mtrl_formula) && bednet.edge_mtrlid > 0)
  334. {
  335. bednet.edge_mtrl_cost_replace_formula = bednet.edge_mtrl_formula;
  336. CalSpringMtrlCol2(bednet, mx, springList, "封边");
  337. bednet.edge_mtrl_cost += Calculate(bednet.edge_mtrl_cost_replace_formula, "封边材料成本").DecimalValue;
  338. AddKeyValue("封边材料成本", bednet.edge_mtrl_cost);
  339. AddFormulaMxKeyValue("【封边材料成本】", bednet.edge_mtrl_formula);
  340. }
  341. #endregion 计算 封边材料成本 结束
  342. #region 计算 封边人力成本 开始
  343. if (!string.IsNullOrEmpty(bednet.edge_hr_formula) && bednet.edge_mtrlid > 0)
  344. {
  345. bednet.edge_hr_cost_replace_formula = bednet.edge_hr_formula;
  346. bednet.edge_hr_cost += Calculate(bednet.edge_hr_cost_replace_formula, "封边人力成本").DecimalValue;
  347. AddKeyValue("封边人力成本", bednet.edge_hr_cost);
  348. AddFormulaMxKeyValue("【封边人力成本】", bednet.edge_hr_formula);
  349. }
  350. #endregion 计算 封边人力成本 结束
  351. #region 计算 弹叉材料成本 开始
  352. if (!string.IsNullOrEmpty(bednet.fork_mtrl_formula) && bednet.fork_qty > 0)
  353. {
  354. bednet.fork_mtrl_cost_replace_formula = bednet.fork_mtrl_formula;
  355. bednet.fork_mtrl_cost += Calculate(bednet.fork_mtrl_cost_replace_formula, "弹叉材料成本").DecimalValue;
  356. AddKeyValue("弹叉材料成本", bednet.fork_mtrl_cost);
  357. AddFormulaMxKeyValue("【弹叉材料成本】", bednet.fork_mtrl_formula);
  358. }
  359. #endregion 计算 弹叉材料成本 结束
  360. #region 计算 弹叉人力成本 开始
  361. if (!string.IsNullOrEmpty(bednet.fork_hr_formula) && bednet.fork_qty > 0)
  362. {
  363. bednet.fork_hr_cost_replace_formula = bednet.fork_hr_formula;
  364. bednet.fork_hr_cost += Calculate(bednet.fork_hr_cost_replace_formula, "弹叉人力成本").DecimalValue;
  365. AddKeyValue("弹叉人力成本", bednet.fork_hr_cost);
  366. AddFormulaMxKeyValue("【弹叉人力成本】", bednet.fork_hr_formula);
  367. }
  368. #endregion 计算 弹叉人力成本 结束
  369. #region 计算 胶条/包角材料成本 开始
  370. if (!string.IsNullOrEmpty(bednet.rsorwa_mtrl_formula) && bednet.if_rsorwa == 1)
  371. {
  372. bednet.rsorwa_mtrl_cost_replace_formula = bednet.rsorwa_mtrl_formula;
  373. bednet.rsorwa_mtrl_cost += Calculate(bednet.rsorwa_mtrl_cost_replace_formula, "胶条/包角材料成本").DecimalValue;
  374. AddKeyValue("胶条/包角材料成本", bednet.rsorwa_mtrl_cost);
  375. AddFormulaMxKeyValue("【胶条/包角材料成本】", bednet.rsorwa_mtrl_formula);
  376. }
  377. #endregion 计算 胶条/包角材料成本 结束
  378. #region 计算 胶条/包角人力成本 开始
  379. if (!string.IsNullOrEmpty(bednet.rsorwa_hr_formula) && bednet.if_rsorwa == 1)
  380. {
  381. bednet.rsorwa_hr_cost_replace_formula = bednet.rsorwa_hr_formula;
  382. bednet.rsorwa_hr_cost += Calculate(bednet.rsorwa_hr_cost_replace_formula, "胶条/包角人力成本").DecimalValue;
  383. AddKeyValue("胶条/包角人力成本", bednet.rsorwa_hr_cost);
  384. AddFormulaMxKeyValue("【胶条/包角人力成本】", bednet.rsorwa_hr_formula);
  385. }
  386. #endregion 计算 胶条/包角人力成本 结束
  387. #region 计算 海绵打孔人力成本 开始
  388. if (!string.IsNullOrEmpty(bednet.sponge_drilling_hr_formula) && bednet.if_sponge_drilling == 1)
  389. {
  390. bednet.sponge_drilling_hr_cost_replace_formula = bednet.sponge_drilling_hr_formula;
  391. bednet.sponge_drilling_hr_cost += Calculate(bednet.sponge_drilling_hr_cost_replace_formula, "海绵打孔人力成本").DecimalValue;
  392. AddKeyValue("海绵打孔人力成本", bednet.sponge_drilling_hr_cost);
  393. AddFormulaMxKeyValue("【海绵打孔人力成本】", bednet.sponge_drilling_hr_formula);
  394. }
  395. #endregion 计算 海绵打孔人力成本 结束
  396. #region 计算 上垫层物料成本 开始
  397. if (!string.IsNullOrEmpty(bednet.felt_mtrl_formula) && bednet.felt_qty > 0)
  398. {
  399. bednet.felt_mtrl_cost_replace_formula = bednet.felt_mtrl_formula;
  400. CalSpringMtrlCol2(bednet, mx, springList, "上垫层");
  401. bednet.felt_mtrl_cost += Calculate(bednet.felt_mtrl_cost_replace_formula, "上垫层物料成本").DecimalValue;
  402. AddKeyValue("上垫层物料成本", bednet.felt_mtrl_cost);
  403. AddFormulaMxKeyValue("【上垫层物料成本】", bednet.felt_mtrl_formula);
  404. }
  405. #endregion 计算 上垫层物料成本 结束
  406. #region 计算 下垫层物料成本 开始
  407. if (!string.IsNullOrEmpty(bednet.felt_mtrl_formula) && bednet.felt_x_qty > 0)
  408. {
  409. bednet.felt_mtrl_x_cost_replace_formula = bednet.felt_mtrl_formula;
  410. CalSpringMtrlCol2(bednet, mx, springList, "下垫层");
  411. bednet.felt_mtrl_x_cost += Calculate(bednet.felt_mtrl_x_cost_replace_formula, "下垫层物料成本").DecimalValue;
  412. AddKeyValue("下垫层物料成本", bednet.felt_mtrl_x_cost);
  413. AddFormulaMxKeyValue("【下垫层物料成本】", bednet.felt_mtrl_formula);
  414. }
  415. #endregion 计算 下垫层物料成本 结束
  416. #region 计算 上垫层人力成本 开始
  417. if (!string.IsNullOrEmpty(bednet.felt_hr_formula) && bednet.felt_qty > 0)
  418. {
  419. bednet.felt_hr_cost_replace_formula = bednet.felt_hr_formula;
  420. bednet.felt_hr_cost += Calculate(bednet.felt_hr_cost_replace_formula, "上垫层人力成本").DecimalValue;
  421. AddKeyValue("上垫层人力成本", bednet.felt_hr_cost);
  422. AddFormulaMxKeyValue("【上垫层人力成本】", bednet.felt_hr_formula);
  423. }
  424. #endregion 计算 上垫层人力成本 结束
  425. #region 计算 下垫层人力成本 开始
  426. if (!string.IsNullOrEmpty(bednet.felt_hr_formula) && bednet.felt_x_qty > 0)
  427. {
  428. bednet.felt_hr_x_cost_replace_formula = bednet.felt_hr_formula;
  429. CalSpringMtrlCol2(bednet, mx, springList, "下垫层");
  430. bednet.felt_hr_x_cost += Calculate(bednet.felt_hr_x_cost_replace_formula, "下垫层人力成本").DecimalValue;
  431. AddKeyValue("下垫层人力成本", bednet.felt_hr_x_cost);
  432. AddFormulaMxKeyValue("【下垫层人力成本】", bednet.felt_hr_formula);
  433. }
  434. #endregion 计算 下垫层人力成本 结束
  435. #region 计算 包装总成本 开始
  436. if (!string.IsNullOrEmpty(bednet.packet_mtrl_formula) && !string.IsNullOrEmpty(bednet.packtype))
  437. {
  438. bednet.packet_mtrl_cost_replace_formula = bednet.packet_mtrl_formula;
  439. bool sqlCal = !string.IsNullOrEmpty(bednet.packet_mtrl_formula) && bednet.packet_mtrl_formula.Substring(0, 2) == "@@";
  440. bednet.packet_mtrl_cost_replace_formula = bednet.packet_mtrl_cost_replace_formula.Replace("@@", "");
  441. if(sqlCal) bednet.packet_mtrl_cost += Convert.ToDecimal(SqlCalculate(bednet.packet_mtrl_cost_replace_formula, "包装总成本"));
  442. else bednet.packet_mtrl_cost += Calculate(bednet.packet_mtrl_cost_replace_formula, "包装总成本").DecimalValue;
  443. AddKeyValue("包装总成本", bednet.packet_mtrl_cost);
  444. AddFormulaMxKeyValue("【包装总成本】", bednet.packet_mtrl_formula);
  445. }
  446. #endregion 计算 包装总成本 结束
  447. #region 计算 包装人工成本 开始
  448. if (!string.IsNullOrEmpty(bednet.packet_hr_formula) && !string.IsNullOrEmpty(bednet.packtype))
  449. {
  450. bednet.packet_hr_cost_replace_formula = bednet.packet_hr_formula;
  451. bool sqlCal = !string.IsNullOrEmpty(bednet.packet_hr_formula) && bednet.packet_hr_formula.Substring(0, 2) == "@@";
  452. bednet.packet_hr_cost_replace_formula = bednet.packet_hr_cost_replace_formula.Replace("@@", "");
  453. if (sqlCal) bednet.packet_hr_cost += Convert.ToDecimal(SqlCalculate(bednet.packet_hr_cost_replace_formula, "包装人工成本"));
  454. else bednet.packet_hr_cost += Calculate(bednet.packet_hr_cost_replace_formula, "包装人工成本").DecimalValue;
  455. AddKeyValue("包装人工成本", bednet.packet_hr_cost);
  456. AddFormulaMxKeyValue("【包装人工成本】", bednet.packet_hr_formula);
  457. }
  458. #endregion 计算 包装人工成本 结束
  459. //有外销的 工厂利润率 增加 0.06
  460. if (bednet.ifsaleout == 1)
  461. {
  462. bednet.sale_point = 0.06M;
  463. }
  464. AddKeyValue("外销加点", bednet.sale_point);
  465. }
  466. // 计算总材料成本 total_mtrl_cost
  467. bednet.total_mtrl_cost = new decimal[]
  468. {
  469. bednet.spring_mtrl_cost.Value,
  470. bednet.snake_wire_mtrl_cost.Value,
  471. bednet.pocket_around_spring_cost.Value,
  472. bednet.pocket_around_fabrics_cost.Value,
  473. bednet.hard_around_mtrl_cost.Value,
  474. bednet.glue_mtrl_cost.Value,
  475. bednet.fabrics1_mtrl_cost.Value,
  476. bednet.fabrics2_mtrl_cost.Value,
  477. bednet.side_iron_mtrl_cost.Value,
  478. bednet.cnail_mtrl_cost.Value,
  479. bednet.sponge_mtrl_cost.Value,
  480. bednet.sponge_mtrl_tc_cost.Value,
  481. bednet.edge_mtrl_cost.Value,
  482. bednet.fork_mtrl_cost.Value,
  483. bednet.rsorwa_mtrl_cost.Value,
  484. bednet.felt_mtrl_cost.Value,
  485. bednet.felt_mtrl_x_cost.Value,
  486. bednet.packet_mtrl_cost.Value
  487. }.Sum();
  488. AddKeyValue("总材料成本", bednet.total_mtrl_cost);
  489. // 计算总人力成本 total_mtrl_cost
  490. bednet.total_hr_cost = new decimal[]
  491. {
  492. bednet.spring_hr_cost.Value,
  493. bednet.hard_around_hr_cost.Value,
  494. bednet.side_iron_hr_cost.Value,
  495. bednet.cnail_hr_cost.Value,
  496. bednet.sponge_hr_cost.Value,
  497. bednet.edge_hr_cost.Value,
  498. bednet.fork_hr_cost.Value,
  499. bednet.rsorwa_hr_cost.Value,
  500. bednet.felt_hr_cost.Value,
  501. bednet.felt_hr_x_cost.Value,
  502. bednet.packet_hr_cost.Value,
  503. bednet.sponge_drilling_hr_cost.Value
  504. }.Sum();
  505. AddKeyValue("总人力成本", bednet.total_hr_cost);
  506. //
  507. AddKeyValue("额外费用", 0);
  508. AddKeyValue("FOB", 0);
  509. //1.总成本=总材料成本+总人力成本+ 额外费用
  510. //bednet.total_cost = bednet.total_mtrl_cost + bednet.total_hr_cost + bednet.total_fees_cost;
  511. bednet.total_cost = CalculateVarFormula("总成本").DecimalValue;
  512. AddKeyValue("总成本", bednet.total_cost);
  513. //2-不含税出厂价=总成本* ( 工厂利润率 + 外销加点 )
  514. //bednet.nottax_factory_cost = bednet.total_cost * (bednet.profitrate + bednet.sale_point);
  515. bednet.nottax_factory_cost = CalculateVarFormula("不含税出厂价").DecimalValue;
  516. AddKeyValue("不含税出厂价", bednet.nottax_factory_cost);
  517. // 3 - 部门不含税价 = 不含税出厂价 / 部门利润率 * 佣金点数 * 额外点数 + fob
  518. //bednet.nottax_dept_cost = bednet.nottax_factory_cost / bednet.dept_profitrate / (1 - (bednet.commission - 1)) * bednet.other_rate + bednet.fob;
  519. bednet.nottax_dept_cost = CalculateVarFormula("部门不含税价").DecimalValue;
  520. AddKeyValue("部门不含税价", bednet.nottax_dept_cost);
  521. // 4 - 税金 = (部门不含税价 * 税率 - 1)
  522. //bednet.taxes = bednet.nottax_dept_cost * (bednet.taxrate - 1);
  523. bednet.taxes = CalculateVarFormula("税金").DecimalValue;
  524. AddKeyValue("税金", bednet.taxes);
  525. // 5 - 部门含税价 = 部门不含税价 * 税率
  526. //bednet.dept_cost = bednet.nottax_dept_cost * bednet.taxrate;
  527. bednet.dept_cost = CalculateVarFormula("部门含税价").DecimalValue;
  528. AddKeyValue("部门含税价", bednet.dept_cost);
  529. // 6 - 外币价 = 部门含税价 / 汇率
  530. //if (bednet.moneyrate != 0)
  531. //{
  532. // bednet.foreign_cost = bednet.dept_cost / bednet.moneyrate;
  533. //}
  534. bednet.foreign_cost = CalculateVarFormula("外币价").DecimalValue;
  535. AddKeyValue("外币价", bednet.foreign_cost);
  536. decimal computed_plan = bednet.total_cost.Value - bednet.sponge_mtrl_cost.Value - bednet.felt_mtrl_cost.Value - bednet.felt_mtrl_x_cost.Value - bednet.packet_mtrl_cost.Value - bednet.packet_hr_cost.Value;
  537. AddKeyValue("计划价", computed_plan);
  538. }
  539. private void CulcalateWeight(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  540. {
  541. bednet.spring_weight_qty = 0;
  542. bednet.side_iron_weight_qty = 0;
  543. bednet.hard_around_weight_qty = 0;
  544. bednet.fabrics1_weight_qty = 0;
  545. bednet.fabrics2_weight_qty = 0;
  546. bednet.felt_weight_qty = 0;
  547. bednet.cnail_weight_qty = 0;
  548. bednet.sponge_weight_tc_qty = 0;
  549. bednet.sponge_weight_qty = 0;
  550. bednet.edge_weight_qty = 0;
  551. bednet.fork_weight_qty = 0;
  552. foreach (var mx in mxlist)
  553. {
  554. #region 计算 钢丝重量 开始
  555. if (!string.IsNullOrEmpty(bednet.spring_weight_formula))
  556. {
  557. mx.spring_weight_replace_formula = bednet.spring_weight_formula;
  558. if (mx.if_part == 0)
  559. {
  560. //单分区
  561. bednet.spring_weight_qty += Calculate(mx.spring_weight_replace_formula, "钢丝重量").DecimalValue;
  562. }
  563. else
  564. {
  565. //多分区
  566. foreach (var springItem in springList)
  567. {
  568. springItem.spring_weight_replace_formula = bednet.spring_weight_formula;
  569. CalSpringMtrlCol(bednet, mx, springItem);
  570. bednet.spring_weight_qty += Calculate(springItem.spring_weight_replace_formula, "钢丝重量").DecimalValue;
  571. }
  572. }
  573. AddKeyValue("弹簧排列个数-宽", mx.spring_qty_width);
  574. AddKeyValue("弹簧排列个数-长", mx.spring_qty_length);
  575. AddKeyValue("弹簧计算个数(宽)", mx.spring_qty_width);
  576. AddKeyValue("弹簧计算个数(长)", mx.spring_qty_length);
  577. AddKeyValue("钢丝重量", bednet.spring_weight_qty);
  578. AddFormulaWeightKeyValue("【钢丝重量】", bednet.spring_weight_formula, true, 1);
  579. }
  580. #endregion 计算 钢丝重量 结束
  581. #region 计算 边铁重量 开始
  582. if (!string.IsNullOrEmpty(bednet.side_iron_weight_formula) && bednet.if_side_iron == 1 && mx.if_side_iron > 0)
  583. {
  584. bednet.side_iron_weight_replace_formula = bednet.side_iron_weight_formula;
  585. bednet.side_iron_weight_qty += Calculate(bednet.side_iron_weight_replace_formula, "边铁重量").DecimalValue;
  586. AddKeyValue("边铁重量", bednet.side_iron_weight_qty);
  587. AddFormulaWeightKeyValue("【边铁重量】", bednet.side_iron_weight_formula);
  588. }
  589. #endregion 计算 边铁重量 结束
  590. #region 计算 四周加硬重量 开始
  591. if (!string.IsNullOrEmpty(bednet.hard_around_weight_formula) && mx.if_hard_around > 0)
  592. {
  593. bednet.hard_around_weight_replace_formula = bednet.hard_around_weight_formula;
  594. bednet.hard_around_weight_qty += Calculate(bednet.hard_around_weight_replace_formula, "四周加硬重量").DecimalValue;
  595. AddKeyValue("四周加硬重量", bednet.hard_around_weight_qty);
  596. AddFormulaWeightKeyValue("【四周加硬重量】", bednet.hard_around_weight_formula);
  597. }
  598. #endregion 计算 四周加硬重量 结束
  599. #region 计算 入袋无纺布重量 开始
  600. if (!string.IsNullOrEmpty(bednet.fabrics1_weight_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics1_mtrlid > 0)
  601. {
  602. bednet.fabrics1_weight_replace_formula = bednet.fabrics1_weight_formula;
  603. bednet.fabrics1_weight_qty += Calculate(bednet.fabrics1_weight_replace_formula, "入袋无纺布重量").DecimalValue;
  604. AddKeyValue("入袋无纺布重量", bednet.fabrics1_weight_qty);
  605. AddFormulaWeightKeyValue("【入袋无纺布重量】", bednet.fabrics1_weight_formula);
  606. }
  607. #endregion 计算 入袋无纺布重量 结束
  608. #region 计算 面底无纺布重量 开始
  609. if (!string.IsNullOrEmpty(bednet.fabrics2_weight_formula) && bednet.typename.IndexOf("袋装网") > -1 && mx.fabrics2_mtrlid > 0)
  610. {
  611. bednet.fabrics2_weight_replace_formula = bednet.fabrics2_weight_formula;
  612. bednet.fabrics2_weight_qty += Calculate(bednet.fabrics2_weight_replace_formula, "面底无纺布重量").DecimalValue;
  613. AddKeyValue("面底无纺布重量", bednet.fabrics2_weight_qty);
  614. AddFormulaWeightKeyValue("【面底无纺布重量】", bednet.fabrics2_weight_formula);
  615. }
  616. #endregion 计算 面底无纺布重量 结束
  617. #region 计算 上垫层重量 开始
  618. string felt_weight_formula_replace_formula = "";
  619. if (!string.IsNullOrEmpty(bednet.felt_mtrl_formula) && bednet.felt_qty > 0)
  620. {
  621. felt_weight_formula_replace_formula = bednet.felt_weight_formula;
  622. CalSpringMtrlCol2(bednet, mx, springList, "上垫层");
  623. bednet.felt_weight_qty += Calculate(felt_weight_formula_replace_formula, "上/下垫层重量").DecimalValue;
  624. AddKeyValue("上/下垫层重量", bednet.felt_weight_qty);
  625. AddFormulaWeightKeyValue("【上/下垫层重量】", bednet.felt_weight_formula);
  626. }
  627. #endregion 计算 上垫层重量 结束
  628. #region 计算 下垫层重量 开始
  629. string felt_x_weight_formula_replace_formula = "";
  630. if (!string.IsNullOrEmpty(bednet.felt_weight_formula) && bednet.felt_x_qty > 0)
  631. {
  632. felt_x_weight_formula_replace_formula = bednet.felt_weight_formula;
  633. CalSpringMtrlCol2(bednet, mx, springList, "下垫层");
  634. bednet.felt_weight_qty += Calculate(felt_x_weight_formula_replace_formula, "上/下垫层重量").DecimalValue;
  635. AddKeyValue("上/下垫层重量", bednet.felt_weight_qty);
  636. AddFormulaWeightKeyValue("【上/下垫层重量】", bednet.felt_weight_formula);
  637. }
  638. bednet.felt_weight_replace_formula += felt_weight_formula_replace_formula;
  639. bednet.felt_weight_replace_formula += Environment.NewLine;
  640. bednet.felt_weight_replace_formula += felt_x_weight_formula_replace_formula;
  641. #endregion 计算 下垫层重量 结束
  642. #region 计算 C钉/夹码重量 开始
  643. if (!string.IsNullOrEmpty(bednet.cnail_weight_formula))
  644. {
  645. bednet.cnail_weight_replace_formula = bednet.cnail_weight_formula;
  646. bednet.cnail_weight_qty += Calculate(bednet.cnail_weight_replace_formula, "C钉/夹码重量").DecimalValue;
  647. AddKeyValue("C钉/夹码重量", bednet.cnail_weight_qty);
  648. AddFormulaWeightKeyValue("【C钉/夹码重量】", bednet.cnail_weight_formula);
  649. }
  650. #endregion 计算 C钉/夹码重量 结束
  651. #region 计算 海绵包边重量 开始
  652. if (!string.IsNullOrEmpty(bednet.sponge_weight_formula) && bednet.sponge_mtrlid > 0)
  653. {
  654. bednet.sponge_weight_replace_formula = bednet.sponge_weight_formula;
  655. bednet.sponge_weight_qty += Calculate(bednet.sponge_weight_replace_formula, "海绵包边重量").DecimalValue;
  656. AddKeyValue("海绵包边重量", bednet.sponge_weight_qty);
  657. AddFormulaWeightKeyValue("【海绵包边重量】", bednet.sponge_weight_formula);
  658. }
  659. #endregion 计算 海绵包边重量 结束
  660. #region 计算 填充海绵重量 开始
  661. if (!string.IsNullOrEmpty(bednet.sponge_weight_tc_formula) && bednet.sponge_tc_mtrlid > 0)
  662. {
  663. bednet.sponge_weight_tc_replace_formula = bednet.sponge_weight_tc_formula;
  664. CalSpringMtrlCol2(bednet, mx, springList, "填充海绵");
  665. bednet.sponge_weight_tc_qty += Calculate(bednet.sponge_weight_tc_replace_formula, "填充海绵重量").DecimalValue;
  666. AddKeyValue("填充海绵重量", bednet.sponge_weight_tc_qty);
  667. AddFormulaWeightKeyValue("【填充海绵重量】", bednet.sponge_weight_tc_formula);
  668. }
  669. #endregion 计算 填充海绵重量 结束
  670. #region 计算 封边材料重量 开始
  671. if (!string.IsNullOrEmpty(bednet.edge_weight_formula) && bednet.edge_mtrlid > 0)
  672. {
  673. bednet.edge_weight_replace_formula = bednet.edge_weight_formula;
  674. CalSpringMtrlCol2(bednet, mx, springList, "封边");
  675. bednet.edge_weight_qty += Calculate(bednet.edge_weight_replace_formula, "封边材料重量").DecimalValue;
  676. AddKeyValue("封边材料重量", bednet.edge_weight_qty);
  677. AddFormulaWeightKeyValue("【封边材料重量】", bednet.edge_weight_formula);
  678. }
  679. #endregion 计算 封边材料重量 结束
  680. #region 计算 弹叉材料重量 开始
  681. if (!string.IsNullOrEmpty(bednet.fork_weight_formula) && bednet.fork_qty > 0)
  682. {
  683. bednet.fork_weight_replace_formula = bednet.fork_weight_formula;
  684. bednet.fork_weight_qty += Calculate(bednet.fork_weight_replace_formula, "弹叉材料重量").DecimalValue;
  685. AddKeyValue("弹叉材料重量", bednet.fork_weight_qty);
  686. AddFormulaWeightKeyValue("【弹叉材料重量】", bednet.fork_weight_formula);
  687. }
  688. #endregion 计算 弹叉材料重量 结束
  689. }
  690. // 计算总材料成本 total_mtrl_cost
  691. bednet.sum_weight = new decimal[]
  692. {
  693. bednet.spring_weight_qty.Value,
  694. bednet.side_iron_weight_qty.Value,
  695. bednet.hard_around_weight_qty.Value,
  696. bednet.fabrics1_weight_qty.Value,
  697. bednet.fabrics2_weight_qty.Value,
  698. bednet.felt_weight_qty.Value,
  699. bednet.cnail_weight_qty.Value,
  700. bednet.sponge_weight_qty.Value,
  701. bednet.sponge_weight_tc_qty.Value,
  702. bednet.edge_weight_qty.Value,
  703. bednet.fork_weight_qty.Value
  704. }.Sum();
  705. AddKeyValue("总重量", bednet.sum_weight);
  706. AddFormulaHideKeyValue("【总重量】", "【钢丝重量】+【边铁重量】+【四周加硬重量】+【入袋无纺布重量】+【面底无纺布重量】+【上/下垫层重量】+【C钉/夹码重量】+【海绵包边重量】+【填充海绵重量】+【封边材料重量】+【弹叉材料重量】");
  707. }
  708. private void InitBedNet(u_bednet bednet)
  709. {
  710. var dept = new u_dept() { deptid = bednet.deptid.Value };
  711. DbSqlHelper.SelectOne(cmd, dept, "pricelistid,profitrate,moneyrate,discount");
  712. //var profirate = new u_factory_profitrate() { deptid = bednet.deptid, bednettypeid_mattresstypeid = bednet.bednettypeid, bednet_or_mattress = 0 };
  713. //DbSqlHelper.SelectOne(cmd, profirate, "profitrate");
  714. decimal profitrate = 0;
  715. cmd.CommandText = @"SELECT profitrate FROM u_factory_profitrate
  716. WHERE deptid = @deptid
  717. AND bednettypeid_mattresstypeid = @bednettypeid_mattresstypeid
  718. AND bednet_or_mattress = 0";
  719. cmd.Parameters.Clear();
  720. cmd.Parameters.AddWithValue("@deptid", bednet.deptid);
  721. cmd.Parameters.AddWithValue("@bednettypeid_mattresstypeid", bednet.bednettypeid);
  722. using (var reader = cmd.ExecuteReader())
  723. {
  724. if (reader.Read())
  725. {
  726. profitrate = Convert.ToDecimal(reader["profitrate"]);
  727. }
  728. }
  729. var bednetType = new u_bednet_type() { bednettypeid = bednet.bednettypeid };
  730. DbSqlHelper.SelectOne(cmd, bednetType, "typename");
  731. bednet.pricelistid = dept.pricelistid;
  732. bednet.typename = bednetType.typename;
  733. bednet.profitrate = profitrate;
  734. bednet.dept_profitrate = dept.profitrate;
  735. bednet.moneyrate = bednet.moneyrate ?? 1;
  736. bednet.commission = bednet.commission ?? 1;
  737. bednet.taxrate = bednet.taxrate ?? 1;
  738. bednet.other_rate = bednet.other_rate ?? 1;
  739. bednet.dept_profitrate = bednet.dept_profitrate ?? 0;
  740. // 检查佣金是否小于1
  741. if (bednet.commission < 1)
  742. {
  743. throw new LJCommonException("佣金点数不能小于1!");
  744. }
  745. // 检查税率是否小于1
  746. if (bednet.taxrate < 1)
  747. {
  748. throw new LJCommonException("税率不能小于1!");
  749. }
  750. // 检查额外点数是否小于1
  751. if (bednet.other_rate < 1)
  752. {
  753. throw new LJCommonException("税率不能小于1!");
  754. }
  755. // 检查部门利润率是否为0
  756. if (bednet.dept_profitrate == 0)
  757. {
  758. throw new LJCommonException("部门利润率不能为0!");
  759. }
  760. }
  761. private void InitReplaceMents(u_bednet bednet)
  762. {
  763. replacements.Clear();
  764. var bednetVarList = new List<u_bednet_var>();
  765. var selectStr = @"SELECT u_bednet_varmx.varid AS varid
  766. ,varkind
  767. ,varcode
  768. ,varname
  769. ,varclass
  770. ,vartype
  771. ,varunit
  772. ,u_bednet_varmx.varvalue AS varvalue
  773. FROM u_bednet_var
  774. INNER JOIN u_bednet_varmx ON u_bednet_varmx.varid = u_bednet_var.varid";
  775. var whereList = new List<string>();
  776. whereList.Add("u_bednet_var.varclass < 2");
  777. whereList.Add("u_bednet_var.varkind = @varkind");
  778. whereList.Add("u_bednet_varmx.pricelistid = @pricelistid");
  779. whereList.Add(@"(u_bednet_var.varclass = 1
  780. AND (
  781. u_bednet_varmx.bednettypeid = @bednettypeid
  782. OR @bednettypeid = 0
  783. )
  784. )
  785. OR (u_bednet_var.varclass = 0)");
  786. var param = new Dictionary<string, object>();
  787. param.Add("@varkind", 0);
  788. param.Add("@pricelistid", bednet.pricelistid);
  789. param.Add("@bednettypeid", bednet.bednettypeid);
  790. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "varid", "varid,varkind,varcode,varname,varclass,vartype,varunit,varvalue", 0, 0, bednetVarList);
  791. AddKeyValue("床垫宽", bednet.mattress_width);
  792. AddKeyValue("床垫长", bednet.mattress_length);
  793. AddKeyValue("床垫高", bednet.mattress_height);
  794. AddKeyValue("双簧", bednet.if_doublespring);
  795. AddKeyValue("弹叉数量", bednet.fork_qty);
  796. AddKeyValue("包装方式", bednet.packtype);
  797. AddKeyValue("包装数量", bednet.packqty);
  798. AddKeyValue("运输方式", bednet.transport_type);
  799. AddKeyValue("包装材料", bednet.packmtrl);
  800. AddKeyValue("床网类别", bednet.typename);
  801. AddKeyValue("工厂利润率", bednet.profitrate);
  802. AddKeyValue("部门利润率", bednet.dept_profitrate);
  803. AddKeyValue("佣金点数", bednet.commission);
  804. AddKeyValue("额外点数", bednet.other_rate);
  805. AddKeyValue("额外费用", bednet.extras_cost);
  806. AddKeyValue("汇率", bednet.moneyrate);
  807. AddKeyValue("税率", bednet.taxrate);
  808. // 公式
  809. AddFormulaKeyValue("【总成本】", "【总材料成本】+【总人力成本】+ 【额外费用】");
  810. AddFormulaKeyValue("【不含税出厂价】", "【总成本】*(【工厂利润率】+【外销加点】)");
  811. AddFormulaKeyValue("【部门不含税价】", "【不含税出厂价】/【部门利润率】/( 1 - (【佣金点数】- 1))*【额外点数】+【FOB】");
  812. AddFormulaKeyValue("【税金】", "【部门不含税价】* (【税率】-1)");
  813. AddFormulaKeyValue("【部门含税价】", "【部门不含税价】*【税率】");
  814. AddFormulaKeyValue("【外币价】", "【部门含税价】/【汇率】");
  815. AddFormulaKeyValue("【计划价】", "【总成本】 - 【海绵包边材料成本】 - 【上垫层物料成本】 - 【下垫层物料成本】 - 【包装总成本】 - 【包装人工成本】");
  816. AddFormulaHideKeyValue("【总材料成本】", "【弹簧材料总成本】+【蛇线材料成本】+【四周口袋弹簧成本】+【四周口袋无纺布成本】+【四周加硬材料成本】+【胶水材料成本】+【入袋无纺布材料成本】+【底面无纺布材料成本】+【边铁材料成本】+【C钉/夹码材料成本】+【海绵包边材料成本】+【填充海绵成本】+【封边材料成本】+【弹叉材料成本】+【胶条/包角材料成本】+【上垫层物料成本】+【下垫层物料成本】+【包装总成本】");
  817. AddFormulaHideKeyValue("【总人力成本】", "【弹簧总人工成本】+【四周加硬人力成本】+【边铁人力成本】+【C钉/夹码人力成本】+【海绵包边人力成本】+【封边人力成本】+【弹叉人力成本】+【胶条/包角人力成本】+【上垫层人力成本】+【下垫层人力成本】+【包装人工成本】+【海绵打孔人力成本】");
  818. foreach (var netvar in bednetVarList)
  819. {
  820. AddKeyValue(netvar.varname, netvar.varvalue);
  821. }
  822. selectStr = @"SELECT varid
  823. ,varkind
  824. ,varcode
  825. ,varname
  826. ,varclass
  827. ,vartype
  828. ,varunit
  829. ,formula
  830. FROM u_bednet_var";
  831. bednetVarList = new List<u_bednet_var>();
  832. whereList = new List<string>();
  833. whereList.Add("u_bednet_var.varkind = @varkind");
  834. whereList.Add("u_bednet_var.varclass = @varclass");
  835. param = new Dictionary<string, object>();
  836. param.Add("@varkind", 0);
  837. param.Add("@varclass", 2);
  838. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "varid", "varid,varkind,varcode,varname,varclass,vartype,varunit,formula", 0, 0, bednetVarList);
  839. // 添加替换公式变量
  840. foreach (var netvar in bednetVarList)
  841. {
  842. AddFormulaKeyValue(netvar.varname, netvar.formula);
  843. }
  844. }
  845. private void InitMxReplaceMents(u_bednet bednet,u_bednetmx mx, u_spring spring)
  846. {
  847. AddKeyValue("弹簧排列个数-宽", mx.spring_qty_width);
  848. AddKeyValue("弹簧排列个数-长", mx.spring_qty_length);
  849. AddKeyValue("弹簧计算个数(宽)", mx.spring_qty_width);
  850. AddKeyValue("弹簧计算个数(长)", mx.spring_qty_length);
  851. AddKeyValue("边铁条数", mx.side_iron_qty);
  852. AddKeyValue("条数", mx.side_iron_qty);
  853. AddKeyValue("四周口袋-排数", mx.pocket_around_row);
  854. AddKeyValue("四周口袋", mx.if_pocket_around);
  855. AddKeyValue("四周加硬-排数", mx.hard_around_row);
  856. AddKeyValue("四周加硬", mx.if_hard_around);
  857. spring.gram_weight /= 1000;
  858. if (spring.gram_weight > 0)
  859. {
  860. AddKeyValue("弹簧重/个", spring.gram_weight);
  861. AddKeyValue("弹簧重", spring.gram_weight);
  862. AddKeyValue("弹簧克重", spring.gram_weight * 1000);
  863. }
  864. if (mx.bednet_height > 0)
  865. {
  866. AddKeyValue("床网高", mx.bednet_height);
  867. }
  868. if (spring.height > 0)
  869. {
  870. AddKeyValue("口袋弹簧高度", spring.height);
  871. }
  872. if (spring.center_diameter > 0)
  873. {
  874. AddKeyValue("口袋弹簧心径", spring.center_diameter);
  875. }
  876. if (spring.line_diameter == null)
  877. {
  878. spring.line_diameter = 0;
  879. }
  880. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  881. FROM u_mtrl_price_pricelist
  882. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  883. WHERE cast(u_mtrl_price.name AS DECIMAL(18, 5)) = @line_diameter
  884. AND u_mtrl_price.mtrltype = 0
  885. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  886. cmd.Parameters.Clear();
  887. cmd.Parameters.AddWithValue("@line_diameter", spring.line_diameter);
  888. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  889. decimal price = 0;
  890. using (var reader = cmd.ExecuteReader())
  891. {
  892. if (reader.Read())
  893. {
  894. price = Convert.ToDecimal(reader["price"]);
  895. price /= 1000;
  896. }
  897. }
  898. if (price > 0)
  899. {
  900. AddKeyValue("加硬弹簧单价", price);
  901. AddKeyValue("口袋弹簧单价", price);
  902. AddKeyValue("弹簧单价", price);
  903. }
  904. }
  905. /// <summary>
  906. /// 用于床网报价 弹簧材料总成本 弹簧人工总成本
  907. /// </summary>
  908. /// <param name="cmd"></param>
  909. /// <param name="dept"></param>
  910. /// <param name="mx"></param>
  911. /// <param name="mx2"></param>
  912. private void CalSpringMtrlCol(u_bednet bednet, u_bednetmx mx, u_bednetmx_spring mx2)
  913. {
  914. AddKeyValue("弹簧排列个数-宽", mx2.spring_qty_width);
  915. AddKeyValue("弹簧排列个数-长", mx2.spring_qty_length);
  916. AddKeyValue("弹簧计算个数(宽)", mx2.spring_qty_width);
  917. AddKeyValue("弹簧计算个数(长)", mx2.spring_qty_length);
  918. AddKeyValue("边铁条数", mx.side_iron_qty);
  919. AddKeyValue("条数", mx.side_iron_qty);
  920. var spring = new u_spring() { springid = mx2.springid };
  921. DbSqlHelper.SelectOne(cmd, spring, "line_diameter,gram_weight");
  922. spring.gram_weight /= 1000;
  923. if (spring.gram_weight > 0)
  924. {
  925. AddKeyValue("弹簧重/个", spring.gram_weight);
  926. AddKeyValue("弹簧重", spring.gram_weight);
  927. }
  928. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  929. FROM u_mtrl_price_pricelist
  930. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  931. WHERE cast(u_mtrl_price.name AS DECIMAL(18, 5)) = @line_diameter
  932. AND u_mtrl_price.mtrltype = 0
  933. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  934. cmd.Parameters.Clear();
  935. cmd.Parameters.AddWithValue("@line_diameter", spring.line_diameter);
  936. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  937. decimal price = 0;
  938. using (var reader = cmd.ExecuteReader())
  939. {
  940. if (reader.Read())
  941. {
  942. price = Convert.ToDecimal(reader["price"]);
  943. price /= 1000;
  944. }
  945. }
  946. if (price > 0)
  947. {
  948. AddKeyValue("弹簧单价", price);
  949. }
  950. }
  951. /// <summary>
  952. /// 代码对照wf_replace_var_dw2
  953. /// </summary>
  954. /// <param name="cmd"></param>
  955. /// <param name="mx"></param>
  956. private void CalSpringMtrlCol2(u_bednet bednet, u_bednetmx mx, List<u_bednetmx_spring> springList, string type)
  957. {
  958. var spring = new u_spring() { springid = mx.springid };
  959. DbSqlHelper.SelectOne(cmd, spring, "line_diameter,gram_weight,center_diameter");
  960. #region 计算 底面无纺布 开始
  961. //计算 上下无纺布方数 =(B4+C4)*(B4+D4)/10000
  962. if ("底面无纺布".Equals(type) && mx.fabrics2_mtrlid > 0)
  963. {
  964. decimal fabrics = (decimal)((mx.bednet_height.Value + bednet.mattress_width.Value) * (mx.bednet_height.Value + bednet.mattress_length.Value)) / 10000;
  965. AddKeyValue("上下无纺布方数", fabrics);
  966. decimal fabrics_price = getMtrlPrice(2, bednet.pricelistid.Value, mx.fabrics2_mtrlid.Value);
  967. if (fabrics_price > 0) AddKeyValue("无纺布单价", fabrics_price);
  968. }
  969. #endregion 计算 底面无纺布 结束
  970. #region 计算 入袋无纺布 开始
  971. //计算 入袋无纺布方数 = (B4+I4+2)*((I4*3.14)+1)/10000
  972. if ("入袋无纺布".Equals(type) && mx.fabrics1_mtrlid > 0)
  973. {
  974. var _springid = mx.springid;
  975. if (_springid == 0 && springList.Count > 0)
  976. {
  977. _springid = springList[0].springid;
  978. }
  979. var _spring = new u_spring() { springid = _springid };
  980. DbSqlHelper.SelectOne(cmd, _spring, "line_diameter,gram_weight,center_diameter");
  981. spring.center_diameter = _spring.center_diameter == null ? 0 : _spring.center_diameter;
  982. decimal fabrics = (decimal)((mx.bednet_height.Value + _spring.center_diameter.Value + 2) * (_spring.center_diameter.Value * (decimal)3.14 + 1)) / 10000;
  983. AddKeyValue("入袋无纺布方数", fabrics);
  984. decimal fabrics_price = getMtrlPrice(2, bednet.pricelistid.Value, mx.fabrics1_mtrlid.Value);
  985. if (fabrics_price > 0) AddKeyValue("无纺布单价", fabrics_price);
  986. }
  987. #endregion 计算 入袋无纺布 结束
  988. #region 计算 四周加硬弹簧 开始
  989. // 主要是要替换 【弹簧克重】 【弹簧单价】
  990. // 因相同部分已存在,不需要后续
  991. #endregion 计算 四周加硬弹簧 结束
  992. #region 计算 海绵包边 开始
  993. if ("海绵包边".Equals(type) && bednet.sponge_thickness.Value > 0 && bednet.sponge_mtrlid.Value > 0)
  994. {
  995. var mtrl_price = new u_mtrl_price() { mtrlid = bednet.sponge_mtrlid };
  996. DbSqlHelper.SelectOne(cmd, mtrl_price, "name");
  997. AddKeyValue("物料名称", mtrl_price.name);
  998. AddKeyValue("裥棉厚度", bednet.sponge_thickness.Value);
  999. AddKeyValue("海绵厚度", bednet.sponge_thickness.Value);
  1000. if (bednet.sponge_height.Value > 0)
  1001. {
  1002. AddKeyValue("海绵高", bednet.sponge_height.Value);
  1003. }
  1004. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1005. FROM u_mtrl_price_pricelist
  1006. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1007. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1008. cmd.Parameters.Clear();
  1009. cmd.Parameters.AddWithValue("@mtrlid", bednet.sponge_mtrlid);
  1010. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1011. using (var reader = cmd.ExecuteReader())
  1012. {
  1013. if (reader.Read())
  1014. {
  1015. decimal sponge_price = Convert.ToDecimal(reader["price"]);
  1016. AddKeyValue("裥棉单价", sponge_price);
  1017. AddKeyValue("海绵单价", sponge_price);
  1018. }
  1019. }
  1020. }
  1021. #endregion 计算 海绵包边 结束
  1022. #region 计算 填充海绵 开始
  1023. if ("填充海绵".Equals(type) && bednet.sponge_tc_thickness.Value > 0 && bednet.sponge_tc_mtrlid.Value > 0)
  1024. {
  1025. var mtrl_price = new u_mtrl_price() { mtrlid = bednet.sponge_tc_mtrlid };
  1026. DbSqlHelper.SelectOne(cmd, mtrl_price, "name");
  1027. AddKeyValue("物料名称", mtrl_price.name);
  1028. AddKeyValue("裥棉厚度", bednet.sponge_tc_thickness.Value);
  1029. AddKeyValue("海绵厚度", bednet.sponge_tc_thickness.Value);
  1030. if (bednet.sponge_tc_height.Value > 0)
  1031. {
  1032. AddKeyValue("海绵高", bednet.sponge_tc_height.Value);
  1033. }
  1034. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1035. FROM u_mtrl_price_pricelist
  1036. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1037. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1038. cmd.Parameters.Clear();
  1039. cmd.Parameters.AddWithValue("@mtrlid", bednet.sponge_tc_mtrlid);
  1040. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1041. using (var reader = cmd.ExecuteReader())
  1042. {
  1043. if (reader.Read())
  1044. {
  1045. decimal sponge_price = Convert.ToDecimal(reader["price"]);
  1046. AddKeyValue("裥棉单价", sponge_price);
  1047. AddKeyValue("海绵单价", sponge_price);
  1048. }
  1049. }
  1050. }
  1051. #endregion 计算 填充海绵 结束
  1052. #region 计算 封边 开始
  1053. if ("封边".Equals(type) && bednet.edge_mtrlid > 0)
  1054. {
  1055. AddKeyValue("有边铁", mx.if_side_iron);
  1056. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1057. ,u_mtrl_price.gram_weight
  1058. FROM u_mtrl_price_pricelist
  1059. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1060. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1061. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1062. cmd.Parameters.Clear();
  1063. cmd.Parameters.AddWithValue("@mtrlid", bednet.edge_mtrlid);
  1064. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1065. using (var reader = cmd.ExecuteReader())
  1066. {
  1067. if (reader.Read())
  1068. {
  1069. decimal edge_price = Convert.ToDecimal(reader["price"]);
  1070. decimal edge_weight = Convert.ToDecimal(reader["gram_weight"]);
  1071. if (edge_price > 0) AddKeyValue("毡单价", edge_price);
  1072. if (edge_weight > 0) AddKeyValue("毡克重", edge_weight);
  1073. }
  1074. }
  1075. if (bednet.edge_height > 0) AddKeyValue("封边高", bednet.edge_height);
  1076. }
  1077. #endregion 计算 封边 结束
  1078. #region 计算 上垫层 开始
  1079. if ("上垫层".Equals(type) && bednet.felt_mtrlid > 0)
  1080. {
  1081. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1082. ,u_mtrl_price.gram_weight
  1083. FROM u_mtrl_price_pricelist
  1084. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1085. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1086. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1087. cmd.Parameters.Clear();
  1088. cmd.Parameters.AddWithValue("@mtrlid", bednet.felt_mtrlid);
  1089. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1090. using (var reader = cmd.ExecuteReader())
  1091. {
  1092. if (reader.Read())
  1093. {
  1094. decimal felt_price = Convert.ToDecimal(reader["price"]);
  1095. decimal felt_weight = Convert.ToDecimal(reader["gram_weight"]);
  1096. if (felt_price > 0) AddKeyValue("垫层物料单价", felt_price);
  1097. if (felt_weight > 0) AddKeyValue("垫层物料克重", felt_weight);
  1098. }
  1099. }
  1100. if (bednet.felt_qty > 0) AddKeyValue("垫层物料数量", bednet.felt_qty);
  1101. }
  1102. #endregion 计算 上垫层 结束
  1103. #region 计算 下垫层 开始
  1104. if ("下垫层".Equals(type) && bednet.felt_x_mtrlid > 0)
  1105. {
  1106. cmd.CommandText = @"SELECT isnull(u_mtrl_price_pricelist.price, 0) AS price
  1107. ,u_mtrl_price.gram_weight
  1108. FROM u_mtrl_price_pricelist
  1109. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1110. WHERE u_mtrl_price_pricelist.mtrlid = @mtrlid
  1111. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1112. cmd.Parameters.Clear();
  1113. cmd.Parameters.AddWithValue("@mtrlid", bednet.felt_x_mtrlid);
  1114. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1115. using (var reader = cmd.ExecuteReader())
  1116. {
  1117. if (reader.Read())
  1118. {
  1119. decimal felt_price = Convert.ToDecimal(reader["price"]);
  1120. decimal felt_weight = Convert.ToDecimal(reader["gram_weight"]);
  1121. if (felt_price > 0) AddKeyValue("垫层物料单价", felt_price);
  1122. if (felt_weight > 0) AddKeyValue("垫层物料克重", felt_weight);
  1123. }
  1124. }
  1125. if (bednet.felt_x_qty > 0) AddKeyValue("垫层物料数量", bednet.felt_x_qty);
  1126. }
  1127. #endregion 计算 下垫层 结束
  1128. }
  1129. private void CalSnakeCol(u_bednet bednet,u_spring spring)
  1130. {
  1131. #region 替换蛇线单价 snake_wire_diameter
  1132. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  1133. FROM u_mtrl_price_pricelist
  1134. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1135. WHERE cast(u_mtrl_price.name AS DECIMAL(18, 5)) = @line_diameter
  1136. AND u_mtrl_price.mtrltype = 0
  1137. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1138. cmd.Parameters.Clear();
  1139. cmd.Parameters.AddWithValue("@line_diameter", spring.line_diameter);
  1140. cmd.Parameters.AddWithValue("@pricelistid", bednet.pricelistid);
  1141. decimal price = 0;
  1142. using (var reader = cmd.ExecuteReader())
  1143. {
  1144. if (reader.Read())
  1145. {
  1146. price = Convert.ToDecimal(reader["price"]);
  1147. price /= 1000;
  1148. }
  1149. }
  1150. if (price > 0)
  1151. {
  1152. AddKeyValue("蛇线单价", price);
  1153. }
  1154. #endregion
  1155. }
  1156. private decimal getMtrlPrice(int mtrltype, int pricelistid, int mtrlid)
  1157. {
  1158. decimal price = 0;
  1159. cmd.CommandText = @"SELECT TOP 1 isnull(u_mtrl_price_pricelist.price, 0) AS price
  1160. FROM u_mtrl_price_pricelist
  1161. INNER JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mtrl_price_pricelist.mtrlid
  1162. WHERE u_mtrl_price.mtrlid = @mtrlid
  1163. AND u_mtrl_price.mtrltype = @mtrltype
  1164. AND u_mtrl_price_pricelist.pricelistid = @pricelistid";
  1165. cmd.Parameters.Clear();
  1166. cmd.Parameters.AddWithValue("@mtrlid", mtrlid);
  1167. cmd.Parameters.AddWithValue("@mtrltype", mtrltype);
  1168. cmd.Parameters.AddWithValue("@pricelistid", pricelistid);
  1169. using (var reader = cmd.ExecuteReader())
  1170. {
  1171. if (reader.Read())
  1172. {
  1173. price = Convert.ToDecimal(reader["price"]);
  1174. //price /= 1000;
  1175. }
  1176. }
  1177. return price;
  1178. }
  1179. private string ConvertToEnglishSymbols(string input)
  1180. {
  1181. input = input.Replace("(", "(")
  1182. .Replace(")", ")")
  1183. .Replace(",", ",")
  1184. .Replace("。", ".")
  1185. .Replace(":", ":")
  1186. .Replace(";", ";")
  1187. .Replace("“", "\"")
  1188. .Replace("”", "\"")
  1189. .Replace("‘", "'")
  1190. .Replace("’", "'");
  1191. return input;
  1192. }
  1193. private void AddKeyValue(string key, object value, bool isReplace = true)
  1194. {
  1195. key = $"【{key}】";
  1196. if (!replacements.ContainsKey(key))
  1197. {
  1198. replacements.Add(key, value);
  1199. }
  1200. else if (isReplace)
  1201. {
  1202. replacements[key] = value;
  1203. }
  1204. }
  1205. private void AddFormulaKeyValue(string key, string value, bool isReplace = true, int ifnotreplace = 0)
  1206. {
  1207. var formulaItem = new formulaItem()
  1208. {
  1209. value = value,
  1210. ifnotreplace = ifnotreplace
  1211. };
  1212. if (!formula_replacements.ContainsKey(key))
  1213. {
  1214. formula_replacements.Add(key, formulaItem);
  1215. }
  1216. else if (isReplace)
  1217. {
  1218. formula_replacements[key] = formulaItem;
  1219. }
  1220. }
  1221. /// <summary>
  1222. /// 记录隐藏公式
  1223. /// </summary>
  1224. /// <param name="key"></param>
  1225. /// <param name="value"></param>
  1226. /// <param name="isReplace"></param>
  1227. private void AddFormulaHideKeyValue(string key, string value, bool isReplace = true, int ifnotreplace = 0)
  1228. {
  1229. var formulaItem = new formulaItem()
  1230. {
  1231. value = value,
  1232. ifnotreplace = ifnotreplace
  1233. };
  1234. if (!formula_replacements_hide.ContainsKey(key))
  1235. {
  1236. formula_replacements_hide.Add(key, formulaItem);
  1237. }
  1238. else if (isReplace)
  1239. {
  1240. formula_replacements_hide[key] = formulaItem;
  1241. }
  1242. }
  1243. /// <summary>
  1244. /// 记录详细公式
  1245. /// </summary>
  1246. /// <param name="key"></param>
  1247. /// <param name="value"></param>
  1248. /// <param name="isReplace"></param>
  1249. private void AddFormulaMxKeyValue(string key, string value, bool isReplace = true, int ifnotreplace = 0)
  1250. {
  1251. var formulaItem = new formulaItem()
  1252. {
  1253. value = value,
  1254. ifnotreplace = ifnotreplace
  1255. };
  1256. if (!formula_replacements_mx.ContainsKey(key))
  1257. {
  1258. formula_replacements_mx.Add(key, formulaItem);
  1259. }
  1260. else if (isReplace)
  1261. {
  1262. formula_replacements_mx[key] = formulaItem;
  1263. }
  1264. }
  1265. /// <summary>
  1266. /// 记录重量公式
  1267. /// </summary>
  1268. /// <param name="key"></param>
  1269. /// <param name="value"></param>
  1270. /// <param name="isReplace"></param>
  1271. private void AddFormulaWeightKeyValue(string key, string value, bool isReplace = true, int ifnotreplace = 0)
  1272. {
  1273. var formulaItem = new formulaItem()
  1274. {
  1275. value = value,
  1276. ifnotreplace = ifnotreplace
  1277. };
  1278. if (!formula_replacements_weight.ContainsKey(key))
  1279. {
  1280. formula_replacements_weight.Add(key, formulaItem);
  1281. }
  1282. else if (isReplace)
  1283. {
  1284. formula_replacements_weight[key] = formulaItem;
  1285. }
  1286. }
  1287. private string ReplaceWith(string input, string oldValue, string newValue)
  1288. {
  1289. return input.Replace(oldValue, newValue);
  1290. }
  1291. private TData CalculateVarFormula(string varname)
  1292. {
  1293. varname = $"【{varname}】";
  1294. if (!formula_replacements.ContainsKey(varname)) return null;
  1295. return Calculate(formula_replacements[varname].value, varname);
  1296. }
  1297. private void FormatExpression(ref string expression)
  1298. {
  1299. expression = ConvertToEnglishSymbols(expression);
  1300. // 定义正则表达式模式,匹配包含【】的内容
  1301. string pattern = @"【(.*?)】";
  1302. // 创建正则表达式对象
  1303. Regex regex = new Regex(pattern);
  1304. // 使用正则表达式匹配输入字符串
  1305. MatchCollection matches = regex.Matches(expression);
  1306. var new_replacements = new Dictionary<string, object>();
  1307. foreach (Match match in matches)
  1308. {
  1309. if (replacements.TryGetValue(match.Value, out object value2))
  1310. {
  1311. new_replacements[match.Value] = value2;
  1312. }
  1313. }
  1314. foreach (var replacement in new_replacements)
  1315. {
  1316. expression = expression.Replace(replacement.Key, Convert.ToString(replacement.Value));
  1317. }
  1318. }
  1319. private TData Calculate(string expression,string name = "")
  1320. {
  1321. FormatExpression(ref expression);
  1322. try
  1323. {
  1324. return LJExprParser.Parse(expression).Result;
  1325. } catch (Exception ex)
  1326. {
  1327. throw new LJCommonException($"计算{name}公式错误!expression: {expression},exception: {ex.Message}");
  1328. }
  1329. }
  1330. public static bool IsNumber(string input)
  1331. {
  1332. // 正则表达式匹配数字,包括正负号和小数点
  1333. string pattern = @"^[+-]?(\d+(\.\d*)?|\.\d+)$";
  1334. return Regex.IsMatch(input, pattern);
  1335. }
  1336. private object SqlCalculate(string expression, string name = "")
  1337. {
  1338. expression = ConvertToEnglishSymbols(expression);
  1339. expression = ReplaceWith(expression, "@@", "");
  1340. // 定义正则表达式模式,匹配包含【】的内容
  1341. string pattern = @"【(.*?)】";
  1342. // 创建正则表达式对象
  1343. Regex regex = new Regex(pattern);
  1344. // 使用正则表达式匹配输入字符串
  1345. MatchCollection matches = regex.Matches(expression);
  1346. var new_formula_replacements = new Dictionary<string, string>();
  1347. var new_replacements = new Dictionary<string, object>();
  1348. foreach (Match match in matches)
  1349. {
  1350. // 检查原始字典中是否存在该键,并添加到新字典中
  1351. if (formula_replacements.TryGetValue(match.Value, out formulaItem item))
  1352. {
  1353. new_formula_replacements[match.Value] = item.value;
  1354. }
  1355. if (replacements.TryGetValue(match.Value, out object value2))
  1356. {
  1357. new_replacements[match.Value] = value2;
  1358. }
  1359. }
  1360. foreach (var replacement in new_formula_replacements)
  1361. {
  1362. expression = expression.Replace(replacement.Key, replacement.Value);
  1363. }
  1364. foreach (var replacement in new_replacements)
  1365. {
  1366. var _rep = Convert.ToString(replacement.Value);
  1367. if (!IsNumber(_rep))
  1368. {
  1369. _rep = "'" + _rep + "'";
  1370. }
  1371. expression = expression.Replace(replacement.Key, " " + _rep);
  1372. }
  1373. try
  1374. {
  1375. cmd.CommandText = $@"{expression}";
  1376. cmd.Parameters.Clear();
  1377. return cmd.ExecuteScalar();
  1378. }
  1379. catch (Exception ex)
  1380. {
  1381. throw new LJCommonException($"计算{name}公式错误!expression: {expression},exception: {ex.Message}");
  1382. }
  1383. }
  1384. public u_bednet GetBedNet(int bednetid)
  1385. {
  1386. var bednet = new u_bednet() { bednetid = bednetid };
  1387. var outputFields = @"bednetid,deptid,bednettypeid,mattress_width,mattress_length,mattress_height,if_doublenet,if_doublespring,snake_wire_diameter,
  1388. snake_wire_mtrl_formula,snake_wire_mtrl_cost,pocket_around_spring_formula,pocket_around_spring_cost,pocket_around_fabrics_formula,
  1389. pocket_around_fabrics_cost,hard_around_mtrl_formula,hard_around_mtrl_cost,hard_around_hr_formula,hard_around_hr_cost,
  1390. spring_mtrl_cost,spring_hr_cost,glue_price,glue_mtrl_formula,glue_mtrl_cost,fabrics1_mtrl_formula,fabrics1_mtrl_cost,
  1391. fabrics2_mtrl_formula,fabrics2_mtrl_cost,if_side_iron,side_iron_lossrate,side_iron_price,side_iron_mtrl_formula,
  1392. side_iron_mtrl_cost,side_iron_hr_formula,side_iron_hr_cost,cnail_price,cnail_mtrl_formula,cnail_mtrl_cost,cnail_hr_formula,
  1393. cnail_hr_cost,sponge_mtrlid,sponge_thickness,sponge_price,sponge_mtrl_formula,sponge_mtrl_cost,sponge_hr_formula,
  1394. sponge_hr_cost,edge_mtrlid,edge_price,edge_mtrl_formula,edge_mtrl_cost,edge_hr_formula,edge_hr_cost,fork_qty,fork_price,
  1395. fork_mtrl_formula,fork_mtrl_cost,fork_hr_formula,fork_hr_cost,if_rsORwa,rsORwa_price,rsORwa_mtrl_formula,rsORwa_mtrl_cost,
  1396. rsORwa_hr_formula,rsORwa_hr_cost,if_sponge_drilling,sponge_drilling_hr_formula,sponge_drilling_hr_cost,total_hr_cost,
  1397. total_mtrl_cost,total_fees_cost,total_cost,createtime,createby,bednetcode,bednetname,spring_mtrl_formula,spring_hr_formula,
  1398. sponge_mtrl_cost_replace_formula,sponge_hr_cost_replace_formula,edge_mtrl_cost_replace_formula,edge_hr_cost_replace_formula,
  1399. fork_mtrl_cost_replace_formula,fork_hr_cost_replace_formula,rsORwa_mtrl_cost_replace_formula,rsORwa_hr_cost_replace_formula,
  1400. sponge_drilling_hr_cost_replace_formula,snake_wire_mtrl_cost_replace_formula,flag,taxrate,taxes,commissionrate,commission,fob,
  1401. profitrate,nottax_factory_cost,nottax_dept_cost,dept_cost,foreign_cost,extras_cost,dept_profitrate,moneyrate,temp_flag,felt_mtrlid,
  1402. felt_qty,felt_price,felt_dscrp,felt_mtrl_formula,felt_mtrl_cost,felt_hr_formula,felt_hr_cost,felt_mtrl_cost_replace_formula,
  1403. felt_hr_cost_replace_formula,extras_cost_dscrp,iffork,ifsaleout,autotype,felt_mtrl_x_cost,felt_hr_x_cost,felt_x_qty,
  1404. felt_mtrl_x_cost_replace_formula,felt_hr_x_cost_replace_formula,felt_x_mtrlid,sale_point,packtype,packqty,other_rate,
  1405. transport_type,packmtrl,packet_mtrl_formula,packet_hr_formula,packet_mtrl_cost,packet_hr_cost,packet_mtrl_cost_replace_formula,
  1406. packet_hr_cost_replace_formula,sponge_height,edge_height,sponge_tc_thickness,sponge_tc_height,sponge_tc_mtrlid,sponge_mtrl_tc_cost,
  1407. sponge_mtrl_tc_formula,sponge_mtrl_tc_cost_replace_formula,sum_weight,spring_weight,snake_weight,side_weight,duo_qv_str,
  1408. spring_weight_formula,side_iron_weight_formula,hard_around_weight_formula,fabrics1_weight_formula,fabrics2_weight_formula,
  1409. felt_weight_formula,cnail_weight_formula,sponge_weight_formula,sponge_weight_tc_formula,edge_weight_formula,fork_weight_formula,
  1410. spring_weight_replace_formula,side_iron_weight_replace_formula,hard_around_weight_replace_formula,fabrics1_weight_replace_formula,
  1411. fabrics2_weight_replace_formula,felt_weight_replace_formula,cnail_weight_replace_formula,sponge_weight_replace_formula,
  1412. sponge_weight_tc_replace_formula,edge_weight_replace_formula,fork_weight_replace_formula,spring_weight_qty,
  1413. side_iron_weight_qty,hard_around_weight_qty,fabrics1_weight_qty,fabrics2_weight_qty,felt_weight_qty,
  1414. cnail_weight_qty,sponge_weight_qty,sponge_weight_tc_qty,edge_weight_qty,fork_weight_qty,if_jb";
  1415. DbSqlHelper.SelectOne(cmd, bednet, outputFields);
  1416. return bednet;
  1417. }
  1418. public List<u_bednetmx_spring> GetBedNetSpringList(int bednetid)
  1419. {
  1420. var springList = new List<u_bednetmx_spring>();
  1421. var outputFields = @"bednetmx_partid,bednetmxid,springid,spring_qty_width,spring_qty_length,fabrics1_mtrl_cost,spring_mtrl_cost,spring_hr_cost,spring_mtrl_cost_replace_formula,spring_hr_cost_replace_formula,spring_weight_replace_formula";
  1422. var selectStr = @"SELECT bednetmx_partid
  1423. ,u_bednetmx_spring.bednetmxid AS bednetmxid
  1424. ,u_bednetmx_spring.springid AS springid
  1425. ,u_bednetmx_spring.spring_qty_width AS spring_qty_width
  1426. ,u_bednetmx_spring.spring_qty_length AS spring_qty_length
  1427. ,u_bednetmx_spring.fabrics1_mtrl_cost AS fabrics1_mtrl_cost
  1428. ,u_bednetmx_spring.spring_mtrl_cost AS spring_mtrl_cost
  1429. ,u_bednetmx_spring.spring_hr_cost AS spring_hr_cost
  1430. ,u_bednetmx_spring.spring_mtrl_cost_replace_formula AS spring_mtrl_cost_replace_formula
  1431. ,u_bednetmx_spring.spring_hr_cost_replace_formula AS spring_hr_cost_replace_formula
  1432. ,u_bednetmx_spring.spring_weight_replace_formula AS spring_weight_replace_formula
  1433. FROM u_bednetmx_spring
  1434. INNER JOIN u_bednetmx ON u_bednetmx.bednetmxid = u_bednetmx_spring.bednetmxid";
  1435. DbSqlHelper.SelectJoin(cmd,selectStr, "u_bednetmx.bednetid = @bednetid",new Dictionary<string, object>() { { "@bednetid",bednetid } }, "bednetmx_partid",outputFields,0,0,springList);
  1436. return springList;
  1437. }
  1438. public List<u_bednetmx_mtrl> GetBedNetMxMtrlList(int bednetid)
  1439. {
  1440. var mxList = new List<u_bednetmx_mtrl>();
  1441. var outputFields = @"bednetmtrlid,bednetid,formulakind,formula,mtrlid,price,gram_weight,cloth_width,if_inputqty,qty,costamt,if_success,replace_formula,priceunit,shrinkage";
  1442. var selectStr = @"SELECT u_bednetmx_mtrl.bednetmtrlid AS bednetmtrlid
  1443. ,u_bednetmx_mtrl.bednetid AS bednetid
  1444. ,u_bednetmx_mtrl.formulakind AS formulakind
  1445. ,u_bednetmx_mtrl.formula AS formula
  1446. ,u_bednetmx_mtrl.mtrlid
  1447. ,u_bednetmx_mtrl.price
  1448. ,u_bednetmx_mtrl.gram_weight
  1449. ,u_bednetmx_mtrl.cloth_width
  1450. ,u_bednetmx_mtrl.if_inputqty
  1451. ,u_bednetmx_mtrl.qty
  1452. ,u_bednetmx_mtrl.costamt
  1453. ,u_bednetmx_mtrl.if_success
  1454. ,u_bednetmx_mtrl.replace_formula
  1455. ,u_bednetmx_mtrl.priceunit
  1456. ,u_bednetmx_mtrl.shrinkage
  1457. FROM u_bednetmx_mtrl";
  1458. DbSqlHelper.SelectJoin(cmd, selectStr, "u_bednetmx_mtrl.bednetid = @bednetid", new Dictionary<string, object>() { { "@bednetid", bednetid } }, "bednetmtrlid", outputFields, 0, 0, mxList);
  1459. return mxList;
  1460. }
  1461. public List<u_bednetmx> GetBedNetMxList(int bednetid)
  1462. {
  1463. var mxList = new List<u_bednetmx>();
  1464. var outputFields = @"bednetmxid,bednetid,spring_qty_width,spring_qty_length,bednet_height,wire_mtrlid,springid,if_part,if_15strip,if_pocket_around,
  1465. pocket_around_springid,pocket_around_row,pocket_around_wire_price,pocket_around_spring_cost,pocket_around_fabrics_cost,
  1466. if_hard_around,hard_around_springid,hard_around_row,hard_around_wire_price,hard_around_mtrl_cost,hard_around_hr_cost,
  1467. fabrics1_mtrlid,fabrics1_price,fabrics1_mtrl_cost,fabrics2_mtrlid,fabrics2_price,fabrics2_mtrl_cost,if_side_iron,
  1468. side_iron_qty,side_iron_mtrl_cost,side_iron_hr_cost,pocket_around_spring_cost_replace_formula,pocket_around_fabrics_cost_replace_formula,
  1469. hard_around_mtrl_cost_replace_formula,hard_around_hr_cost_replace_formula,fabrics1_mtrl_cost_replace_formula,
  1470. fabrics2_mtrl_cost_replace_formula,side_iron_mtrl_cost_replace_formula,side_iron_hr_cost_replace_formula,
  1471. cnail_mtrl_cost_replace_formula,cnail_mtrl_cost,cnail_hr_cost_replace_formula,cnail_hr_cost,
  1472. glue_mtrl_cost_replace_formula,glue_mtrl_cost,spring_mtrl_cost,spring_hr_cost,spring_mtrl_cost_replace_formula,
  1473. spring_hr_cost_replace_formula,if_show,spring_weight_replace_formula";
  1474. var selectStr = @"SELECT bednetmxid
  1475. ,bednetid
  1476. ,spring_qty_width
  1477. ,spring_qty_length
  1478. ,bednet_height
  1479. ,wire_mtrlid
  1480. ,springid
  1481. ,if_part
  1482. ,if_15strip
  1483. ,if_pocket_around
  1484. ,pocket_around_springid
  1485. ,pocket_around_row
  1486. ,pocket_around_wire_price
  1487. ,pocket_around_spring_cost
  1488. ,pocket_around_fabrics_cost
  1489. ,if_hard_around
  1490. ,hard_around_springid
  1491. ,hard_around_row
  1492. ,hard_around_wire_price
  1493. ,hard_around_mtrl_cost
  1494. ,hard_around_hr_cost
  1495. ,fabrics1_mtrlid
  1496. ,fabrics1_price
  1497. ,fabrics1_mtrl_cost
  1498. ,fabrics2_mtrlid
  1499. ,fabrics2_price
  1500. ,fabrics2_mtrl_cost
  1501. ,if_side_iron
  1502. ,side_iron_qty
  1503. ,side_iron_mtrl_cost
  1504. ,side_iron_hr_cost
  1505. ,pocket_around_spring_cost_replace_formula
  1506. ,pocket_around_fabrics_cost_replace_formula
  1507. ,hard_around_mtrl_cost_replace_formula
  1508. ,hard_around_hr_cost_replace_formula
  1509. ,fabrics1_mtrl_cost_replace_formula
  1510. ,fabrics2_mtrl_cost_replace_formula
  1511. ,side_iron_mtrl_cost_replace_formula
  1512. ,side_iron_hr_cost_replace_formula
  1513. ,cnail_mtrl_cost_replace_formula
  1514. ,cnail_mtrl_cost
  1515. ,cnail_hr_cost_replace_formula
  1516. ,cnail_hr_cost
  1517. ,glue_mtrl_cost_replace_formula
  1518. ,glue_mtrl_cost
  1519. ,spring_mtrl_cost
  1520. ,spring_hr_cost
  1521. ,spring_mtrl_cost_replace_formula
  1522. ,spring_hr_cost_replace_formula
  1523. ,1 AS if_show
  1524. ,spring_weight_replace_formula
  1525. FROM u_bednetmx";
  1526. DbSqlHelper.SelectJoin(cmd, selectStr, "u_bednetmx.bednetid = @bednetid", new Dictionary<string, object>() { { "@bednetid", bednetid } }, "bednetmxid", outputFields, 0, 0, mxList);
  1527. return mxList;
  1528. }
  1529. public void SaveBedNet(u_bednet bednet, List<u_bednetmx> mxlist, List<u_bednetmx_spring> springList)
  1530. {
  1531. var dtNow = DateTime.Now;
  1532. var fields = @"deptid,bednettypeid,mattress_width,mattress_length,mattress_height,if_doublenet,if_doublespring,snake_wire_diameter,
  1533. snake_wire_mtrl_formula,snake_wire_mtrl_cost,pocket_around_spring_formula,pocket_around_spring_cost,
  1534. pocket_around_fabrics_formula,pocket_around_fabrics_cost,hard_around_mtrl_formula,hard_around_mtrl_cost,
  1535. hard_around_hr_formula,hard_around_hr_cost,spring_mtrl_cost,spring_hr_cost,glue_price,glue_mtrl_formula,
  1536. glue_mtrl_cost,fabrics1_mtrl_formula,fabrics1_mtrl_cost,fabrics2_mtrl_formula,fabrics2_mtrl_cost,
  1537. if_side_iron,side_iron_lossrate,side_iron_price,side_iron_mtrl_formula,side_iron_mtrl_cost,side_iron_hr_formula,
  1538. side_iron_hr_cost,cnail_price,cnail_mtrl_formula,cnail_mtrl_cost,cnail_hr_formula,cnail_hr_cost,sponge_mtrlid,
  1539. sponge_thickness,sponge_price,sponge_mtrl_formula,sponge_mtrl_cost,sponge_hr_formula,sponge_hr_cost,edge_mtrlid,
  1540. edge_price,edge_mtrl_formula,edge_mtrl_cost,edge_hr_formula,edge_hr_cost,fork_qty,fork_price,fork_mtrl_formula,
  1541. fork_mtrl_cost,fork_hr_formula,fork_hr_cost,if_rsORwa,rsORwa_price,rsORwa_mtrl_formula,rsORwa_mtrl_cost,rsORwa_hr_formula,
  1542. rsORwa_hr_cost,if_sponge_drilling,sponge_drilling_hr_formula,sponge_drilling_hr_cost,total_hr_cost,total_mtrl_cost,
  1543. total_fees_cost,total_cost,createtime,createby,bednetname,spring_mtrl_formula,spring_hr_formula,
  1544. sponge_mtrl_cost_replace_formula,sponge_hr_cost_replace_formula,edge_mtrl_cost_replace_formula,edge_hr_cost_replace_formula,
  1545. fork_mtrl_cost_replace_formula,fork_hr_cost_replace_formula,rsORwa_mtrl_cost_replace_formula,rsORwa_hr_cost_replace_formula,
  1546. sponge_drilling_hr_cost_replace_formula,snake_wire_mtrl_cost_replace_formula,taxrate,taxes,commissionrate,commission,fob,
  1547. profitrate,nottax_factory_cost,nottax_dept_cost,dept_cost,foreign_cost,extras_cost,dept_profitrate,moneyrate,temp_flag,
  1548. felt_mtrlid,felt_qty,felt_price,felt_dscrp,felt_mtrl_formula,felt_mtrl_cost,felt_hr_formula,felt_hr_cost,
  1549. felt_mtrl_cost_replace_formula,felt_hr_cost_replace_formula,extras_cost_dscrp,iffork,ifsaleout,autotype,
  1550. felt_mtrl_x_cost,felt_hr_x_cost,felt_x_qty,felt_mtrl_x_cost_replace_formula,felt_hr_x_cost_replace_formula,
  1551. felt_x_mtrlid,sale_point,packtype,packqty,other_rate,transport_type,packmtrl,packet_mtrl_formula,
  1552. packet_hr_formula,packet_mtrl_cost,packet_hr_cost,packet_mtrl_cost_replace_formula,packet_hr_cost_replace_formula,
  1553. sponge_height,edge_height,sponge_tc_thickness,sponge_tc_height,sponge_tc_mtrlid,sponge_mtrl_tc_formula,
  1554. sponge_mtrl_tc_cost,sponge_mtrl_tc_cost_replace_formula,duo_qv_str,spring_weight_formula,side_iron_weight_formula,
  1555. hard_around_weight_formula,fabrics1_weight_formula,fabrics2_weight_formula,felt_weight_formula,cnail_weight_formula,
  1556. sponge_weight_formula,sponge_weight_tc_formula,edge_weight_formula,fork_weight_formula,spring_weight_replace_formula,
  1557. side_iron_weight_replace_formula,hard_around_weight_replace_formula,fabrics1_weight_replace_formula,
  1558. fabrics2_weight_replace_formula,felt_weight_replace_formula,cnail_weight_replace_formula,sponge_weight_replace_formula,
  1559. sponge_weight_tc_replace_formula,edge_weight_replace_formula,fork_weight_replace_formula,spring_weight_qty,
  1560. side_iron_weight_qty,hard_around_weight_qty,fabrics1_weight_qty,fabrics2_weight_qty,felt_weight_qty,cnail_weight_qty,
  1561. sponge_weight_qty,sponge_weight_tc_qty,edge_weight_qty,fork_weight_qty,sum_weight,if_jb";
  1562. var fieldsMx = @"bednetmxid,bednetid,spring_qty_width,spring_qty_length,bednet_height,wire_mtrlid,springid,if_part,if_15strip,
  1563. if_pocket_around,pocket_around_springid,pocket_around_row,pocket_around_wire_price,pocket_around_spring_cost,
  1564. pocket_around_fabrics_cost,if_hard_around,hard_around_springid,hard_around_row,hard_around_wire_price,
  1565. hard_around_mtrl_cost,hard_around_hr_cost,fabrics1_mtrlid,fabrics1_price,fabrics1_mtrl_cost,fabrics2_mtrlid,
  1566. fabrics2_price,fabrics2_mtrl_cost,if_side_iron,side_iron_qty,side_iron_mtrl_cost,side_iron_hr_cost,
  1567. pocket_around_spring_cost_replace_formula,pocket_around_fabrics_cost_replace_formula,hard_around_mtrl_cost_replace_formula,
  1568. hard_around_hr_cost_replace_formula,fabrics1_mtrl_cost_replace_formula,fabrics2_mtrl_cost_replace_formula,
  1569. side_iron_mtrl_cost_replace_formula,side_iron_hr_cost_replace_formula,cnail_mtrl_cost_replace_formula,cnail_mtrl_cost,
  1570. cnail_hr_cost_replace_formula,cnail_hr_cost,glue_mtrl_cost_replace_formula,glue_mtrl_cost,spring_mtrl_cost,spring_hr_cost,
  1571. spring_mtrl_cost_replace_formula,spring_hr_cost_replace_formula,spring_weight_replace_formula";
  1572. var fieldsMx_spring = @"bednetmx_partid,bednetmxid,springid,spring_qty_width,spring_qty_length,fabrics1_mtrl_cost,spring_mtrl_cost,
  1573. spring_hr_cost,spring_mtrl_cost_replace_formula,spring_hr_cost_replace_formula,spring_weight_replace_formula";
  1574. if (bednet.bednetid <= 0)
  1575. {
  1576. //新建
  1577. fields += ",bednetid,bednetcode";
  1578. bednet.bednetid = BllHelper.GetID(cmd, "u_bednet");
  1579. bednet.createtime = dtNow;
  1580. bednet.createby = context.tokendata.username;
  1581. if(string.IsNullOrEmpty(bednet.bednetcode))
  1582. {
  1583. var nettype = new u_bednet_type() { bednettypeid = bednet.bednettypeid };
  1584. DbSqlHelper.SelectOne(cmd, nettype, "typecode");
  1585. // 编号-年月日+流水
  1586. bednet.bednetcode = $"{nettype.typecode}-{dtNow.ToString("yyyyMMdd")}{(bednet.bednetid.Value % 10000).ToString("D4")}";
  1587. }
  1588. DbSqlHelper.Insert(cmd, "u_bednet", null, bednet, fields);
  1589. }
  1590. else
  1591. {
  1592. //修改
  1593. foreach (var mx in mxlist)
  1594. {
  1595. cmd.CommandText = @"DELETE FROM u_bednetmx_spring WHERE bednetmxid = @bednetmxid";
  1596. cmd.Parameters.Clear();
  1597. cmd.Parameters.AddWithValue("@bednetmxid", mx.bednetmxid);
  1598. cmd.ExecuteNonQuery();
  1599. }
  1600. cmd.CommandText = @"DELETE FROM u_bednetmx WHERE bednetid = @bednetid";
  1601. cmd.Parameters.Clear();
  1602. cmd.Parameters.AddWithValue("@bednetid", bednet.bednetid);
  1603. cmd.ExecuteNonQuery();
  1604. DbSqlHelper.Update(cmd, "u_bednet", null, bednet, "bednetid", fields);
  1605. }
  1606. foreach (var mx in mxlist)
  1607. {
  1608. mx.bednetid = bednet.bednetid;
  1609. mx.bednetmxid = BllHelper.GetID(cmd, "u_bednetmx");
  1610. DbSqlHelper.Insert(cmd, "u_bednetmx", null, mx, fieldsMx);
  1611. if (springList != null && springList.Any())
  1612. {
  1613. foreach (var spring in springList)
  1614. {
  1615. spring.bednetmxid = mx.bednetmxid;
  1616. spring.bednetmx_partid = BllHelper.GetID(cmd, "u_bednetmx_spring");
  1617. DbSqlHelper.Insert(cmd, "u_bednetmx_spring", null, spring, fieldsMx_spring);
  1618. }
  1619. }
  1620. }
  1621. var hisprice = new u_his_price
  1622. {
  1623. bednetid_mattressid = bednet.bednetid,
  1624. typeid = 0,
  1625. cmpdate = dtNow,
  1626. cmpemp = context.tokendata.username,
  1627. nottax_dept_cost = bednet.nottax_dept_cost,
  1628. dept_cost = bednet.dept_cost,
  1629. foreign_cost = bednet.foreign_cost
  1630. };
  1631. var fieldsHs = "bednetid_mattressid, typeid, cmpdate, cmpemp, nottax_dept_cost, dept_cost, foreign_cost";
  1632. DbSqlHelper.Insert(cmd, "u_his_price", null, hisprice, fieldsHs);
  1633. }
  1634. public void CopyBedNet(u_bednet bednet,u_bednetmx bednetmx,out int newId)
  1635. {
  1636. var bedNet_copy = GetBedNet(bednet.bednetid.Value);
  1637. var bedNetMxList = GetBedNetMxList(bednet.bednetid.Value);
  1638. var springList = GetBedNetSpringList(bednet.bednetid.Value);
  1639. // 判断copy_bedNet.bednetcode是否存在@@字符串,如果存在,则删除@@后面的字符串,包括@@
  1640. if (bedNet_copy.bednetcode.IndexOf("@@") > -1)
  1641. {
  1642. bedNet_copy.bednetcode = bedNet_copy.bednetcode.Substring(bedNet_copy.bednetcode.IndexOf("@@"));
  1643. }
  1644. bedNet_copy.bednetcode += " @@";
  1645. bedNet_copy.bednetcode += DateTime.Now.ToString("yyyMMdd_mmhhss");
  1646. bedNet_copy.bednetid = 0;
  1647. bedNet_copy.mattress_width = bednet.mattress_width;
  1648. bedNet_copy.mattress_length = bednet.mattress_length;
  1649. foreach(var mx in bedNetMxList)
  1650. {
  1651. if(bednetmx.spring_qty_width > 0 && bednetmx.spring_qty_length > 0)
  1652. {
  1653. mx.spring_qty_length = bednetmx.spring_qty_length;
  1654. mx.spring_qty_width = bednetmx.spring_qty_width;
  1655. }
  1656. }
  1657. SaveBedNet(bedNet_copy, bedNetMxList, springList);
  1658. newId = bedNet_copy.bednetid.Value;
  1659. }
  1660. }
  1661. }