BedNetHelper.cs 82 KB

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