BedNetHelper.cs 135 KB

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