BedNetHelper.cs 122 KB

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