using DirectService.Tools; using JLHHJSvr.BLL; using JLHHJSvr.Com.Model; using JLHHJSvr.Excutor; using JLHHJSvr.LJException; using JLHHJSvr.Tools; using LJLib.DAL.SQL; using NPOI.SS.Formula.Functions; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Web; using static JLHHJSvr.Helper.CacheHelper; namespace JLHHJSvr.Helper { internal class SoftBedHelper : HelperBase { /// /// 获取软床报价单据 /// /// /// /// public u_softbed GetSoftBed(int billid,string fields = null) { fields = fields ?? @"softbed_id,softbed_code,softbed_relcode,softbed_name,deptid,create_date,create_emp,mtrlmode,mtrltype,has_headboard,has_nightstand,has_bedframe,is_template, template_id,template_code,template_name,commission,taxes,taxrate,other_rate,extras_cost,money_type,moneyrate,dscrp,costamt,nottax_factory_cost,nottax_dept_cost, dept_cost,foreign_cost,total_mtrl_cost,total_hr_cost,total_cost,version,flag,audit_date,audit_emp,update_date,update_emp"; var bill = new u_softbed() { softbed_id = billid }; if (DbSqlHelper.SelectOne(cmd, bill, fields) == 0) return null; return bill; } /// /// 获取软床报价单据明细 /// /// /// /// public List GetSoftBedMxList(int billid,string fields = null) { fields = fields ?? @"softbed_id,printid,formulaid,pzid,mtrlid,mtrlname,mtrlcode,mtrlmode,unit,has_type,allow_edit,cutting_length,cutting_width,cutting_qty, useqty,use_formula,use_formula_str,actual_useqty,loss_rate,price,price_formula,price_formula_str,cost_price,cost_amt,pzname,formulaname"; var mxlist = new List(); var selectStr = @"SELECT u_softbed_mx.softbed_id ,u_softbed_mx.printid ,u_softbed_mx.formulaid ,u_softbed_mx.pzid ,u_softbed_mx.mtrlid ,u_softbed_mx.mtrlname ,u_softbed_mx.mtrlcode ,u_softbed_mx.mtrlmode ,u_softbed_mx.unit ,u_softbed_mx.has_type ,u_softbed_mx.allow_edit ,u_softbed_mx.cutting_length ,u_softbed_mx.cutting_width ,u_softbed_mx.cutting_qty ,u_softbed_mx.useqty ,u_softbed_mx.use_formula ,u_softbed_mx.use_formula_str ,u_softbed_mx.actual_useqty ,u_softbed_mx.loss_rate ,u_softbed_mx.price ,u_softbed_mx.price_formula ,u_softbed_mx.price_formula_str ,u_softbed_mx.cost_price ,u_softbed_mx.cost_amt ,ISNULL(u_configure_code.name,'') AS pzname ,ISNULL(u_softbed_formula.formulaname,'') AS formulaname FROM u_softbed_mx LEFT JOIN u_configure_code ON u_softbed_mx.pzid = u_configure_code.pzid LEFT JOIN u_softbed_formula ON u_softbed_mx.formulaid = u_softbed_formula.formulaid "; DbSqlHelper.SelectJoin(cmd, selectStr, "softbed_id = @billid", new Dictionary() { { "@billid", billid } }, "has_type,printid", fields, 0, 0, mxlist); return mxlist; } public List GetChangeSoftBedMxList(int billid,List codeMxList) { var newList = new List(); var softbed = GetSoftBed(billid, "billid,softbed_code,has_headboard,has_nightstand,has_bedframe"); if (softbed == null) return newList; // 物料清单 var mxList = GetSoftBedMxList(billid); // 换料清单 var bomList = GetSoftBedMxBomList(codeMxList); // 排除不存在配置的物料 var skipList = new List(); var mxMtrlIds = mxList.Select(t => t.mtrlid).ToList(); if (mxMtrlIds.Count > 0) { cmd.CommandText = $@"SELECT mtrlid FROM u_configure_codemxbom WHERE mtrlid NOT IN {ListEx.getString(mxMtrlIds)}"; cmd.Parameters.Clear(); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { skipList.Add(Convert.ToInt32(reader["mtrlid"])); } } } foreach (var mx in mxList) { if(skipList.Contains(mx.mtrlid)) { mx.printid = newList.Count + 1; newList.Add(mx); continue; } if (mx.pzid > 0) { // 部件 var tmp_bomList = bomList.FindAll(t => t.has_type == mx.has_type && t.pzid == mx.pzid); if (tmp_bomList.Count > 0) { // add foreach (var temp in tmp_bomList) { if (temp.mtrlid == mx.mtrlid) { mx.printid = newList.Count + 1; newList.Add(mx); } else { temp.printid = newList.Count + 1; newList.Add(temp); } } } } else { // 非部件 string contfigtypename = string.Empty; string prefix = $"{softbed.softbed_code}|"; if (mx.has_type == 1) contfigtypename = $"{prefix}床头"; else if (mx.has_type == 2) contfigtypename = $"{prefix}床头柜"; else contfigtypename = $"{prefix}床架"; cmd.CommandText = @"SELECT u_configure_code.pzid FROM u_configure_codemxbom INNER JOIN u_configure_codemx ON u_configure_codemxbom.pzid = u_configure_codemx.pzid AND u_configure_codemxbom.printid = u_configure_codemx.printid INNER JOIN u_configure_code ON u_configure_codemx.pzid = u_configure_code.pzid INNER JOIN u_configure_type ON u_configure_code.typeid = u_configure_type.contfigtypeid WHERE u_configure_codemxbom.mtrlid = @mtrlid AND LTRIM(RTRIM(u_configure_type.contfigtypename)) = @contfigtypename"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@mtrlid",mx.mtrlid); cmd.Parameters.AddWithValue("@contfigtypename", contfigtypename); int pzid = 0, cnt = 0; using(var reader = cmd.ExecuteReader()) { while(reader.Read()) { pzid = Convert.ToInt32(reader["pzid"]); cnt++; } } if (pzid > 1) throw new LJCommonException($"换料失败,原因:{contfigtypename}的{mx.mtrlname}存在多个清单,但没有部件!"); var tmp_bomList = bomList.FindAll(t => t.pzid == pzid); if (tmp_bomList.Count > 0) { // add foreach (var temp in tmp_bomList) { if (temp.mtrlid == mx.mtrlid) { mx.printid = newList.Count + 1; newList.Add(mx); } else { temp.printid = newList.Count + 1; newList.Add(temp); } } } } } return newList; } /// /// 根据部件配置项值获取对应BOM明细 /// /// /// public List GetSoftBedMxBomList(List codeList) { var mxlist = new List(); foreach(var code in codeList) { var resultList = new List(); var outputFields = @"pzid,printid,pid,mtrlid,sonscale,sonscale_formula,mng_cost_rate,profit_rate,realqty,cost,cost_emp,cost_date,sonloss,sonloss_formula, sondecloss,sondecloss_formula,deptid_scll,default_length,default_width,default_qty,mtrlcode,mtrlname,mtrlmode,unit, mtrlsectype,zxmtrlmode,usermtrlmode,price"; var selectStr = @"SELECT u_configure_codemxbom.pzid ,u_configure_codemxbom.printid ,u_configure_codemxbom.pid ,u_configure_codemxbom.mtrlid ,u_configure_codemxbom.sonscale ,u_configure_codemxbom.sonscale_formula ,u_configure_codemxbom.mng_cost_rate ,u_configure_codemxbom.profit_rate ,u_configure_codemxbom.realqty ,u_configure_codemxbom.cost ,u_configure_codemxbom.cost_emp ,u_configure_codemxbom.cost_date ,u_configure_codemxbom.sonloss ,u_configure_codemxbom.sonloss_formula ,u_configure_codemxbom.sondecloss ,u_configure_codemxbom.sondecloss_formula ,u_configure_codemxbom.deptid_scll ,u_configure_codemxbom.default_length ,u_configure_codemxbom.default_width ,u_configure_codemxbom.default_qty ,u_mtrldef.mtrlcode ,u_mtrldef.mtrlname ,u_mtrldef.mtrlmode ,u_mtrldef.unit ,u_mtrldef.mtrlsectype ,u_mtrldef.zxmtrlmode ,u_mtrldef.usermtrlmode ,u_erpmtrl_price.price FROM u_configure_codemxbom INNER JOIN u_mtrldef ON u_configure_codemxbom.mtrlid = u_mtrldef.mtrlid LEFT OUTER JOIN u_erpmtrl_price ON u_configure_codemxbom.mtrlid = u_erpmtrl_price.mtrlid"; DbSqlHelper.SelectJoin(cmd,selectStr, "u_configure_codemxbom.pzid = @pzid AND u_configure_codemxbom.printid = @printid", new Dictionary() { { "@pzid", code.pzid }, { "@printid",code.printid} }, "u_configure_codemxbom.pid", outputFields, 0,0,resultList); foreach(var item in resultList) { mxlist.Add(InitSoftBedMxFromBom(item, code.has_type.Value)); } } return mxlist; } /// /// 初始化配置项值带出的BOM清单列表 /// /// /// public u_softbed_mx InitSoftBedMxFromBom(u_configure_codemxbom bomItem,byte has_type) { var mx = new u_softbed_mx() { pzid = bomItem.pzid, mtrlid = bomItem.mtrlid, mtrlname = bomItem.mtrlname, mtrlcode = bomItem.mtrlcode, mtrlmode = bomItem.mtrlmode, unit = bomItem.unit, allow_edit = 0, has_type = has_type, // 1-床头、2-床头柜、4-床架 cutting_length = bomItem.default_length, cutting_width = bomItem.default_width, cutting_qty = bomItem.default_qty, price = bomItem.price, price_formula = "", price_formula_str = "", useqty = bomItem.sonscale, use_formula = "", use_formula_str = "", actual_useqty = 0, loss_rate = bomItem.sonloss, cost_price = 0, cost_amt = 0 }; return mx; } /// /// 新建/修改 软床报价 /// /// /// public void SaveSoftBed(u_softbed softbed) { SaveCheck(softbed); // 初始化属性 AutoInit.AutoInitS(softbed); foreach(var mx in softbed.mxList) { AutoInit.AutoInitS(mx); } // 计算价格 CalCulateFormula(softbed); // var dtNow = context.opdate; var fields = @"softbed_relcode,softbed_name,deptid,mtrlmode,mtrltype,has_headboard,has_nightstand,has_bedframe,is_template, template_id,template_code,template_name,commission,taxes,taxrate,other_rate,extras_cost,money_type,moneyrate,dscrp,costamt,nottax_factory_cost,nottax_dept_cost, dept_cost,foreign_cost,total_mtrl_cost,total_hr_cost,total_cost,version"; var mx_fields = @"softbed_id,printid,pzid,formulaid,mtrlid,mtrlname,mtrlcode,mtrlmode,unit,has_type,allow_edit,cutting_length,cutting_width,cutting_qty, useqty,use_formula,use_formula_str,actual_useqty,loss_rate,price,price_formula,price_formula_str,cost_price,cost_amt"; if(softbed.softbed_id == 0) { // 新建 fields += ",softbed_id,softbed_code,create_date,create_emp"; softbed.softbed_id = BllHelper.GetID(cmd, "u_softbed"); softbed.create_date = dtNow; softbed.create_emp = context.tokendata.username; softbed.version = 1; if (string.IsNullOrEmpty(softbed.softbed_code)) { // 编号-年月日+流水 softbed.softbed_code = $"RC-{dtNow.ToString("yyyyMMdd")}{(softbed.softbed_id % 10000).ToString("D4")}"; } DbSqlHelper.Insert(cmd, "u_softbed", null, softbed, fields); } else { // 修改 softbed.update_date = dtNow; softbed.update_emp = context.tokendata.username; softbed.version++; fields += ",update_date,update_emp"; cmd.CommandText = @"DELETE FROM u_softbed_mx WHERE softbed_id = @softbed_id"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@softbed_id", softbed.softbed_id); cmd.ExecuteNonQuery(); DbSqlHelper.Update(cmd, "u_softbed", null, softbed, "softbed_id", fields); } for (int i = 0; i < softbed.mxList.Count; i++) { var mx = softbed.mxList[i]; mx.softbed_id = softbed.softbed_id; mx.printid = i + 1; DbSqlHelper.Insert(cmd, "u_softbed_mx", null, mx, mx_fields); } SaveSoftBedTemplate(softbed); } private void SaveCheck(u_softbed softbed) { if (softbed == null) throw new LJCommonException("软床报价保存失败,数据异常!"); if (softbed.is_template == 0 && (softbed.mxList == null || softbed.mxList.Count <= 0)) throw new LJCommonException("软床报价保存失败,明细内容为空!"); if(softbed.softbed_id > 0) { // 检测版本控制 var _softbed = GetSoftBed(softbed.softbed_id, "softbed_id,softbed_code,version,update_emp"); if (_softbed.version != softbed.version) throw new LJCommonException($"单据:{_softbed.softbed_code}已被{_softbed.update_emp}修改,请重新加载最新数据再操作!"); } } /// /// 新建软床报价模板 /// /// private void SaveSoftBedTemplate(u_softbed softbed) { if (softbed.is_template == 0) return; if(string.IsNullOrEmpty(softbed.softbed_code)) { throw new LJCommonException("报价未生成唯一码,无法生成模板配置"); } string prefix = $"{softbed.softbed_code}|"; var configureList = new List(); if(softbed.has_headboard == 1) { configureList.Add(new u_configure_type() { contfigtypeid = 0, contfigtypename = $"{prefix}床头", contfigtype = 0, usechflag = 1, flag = 0 }); } if(softbed.has_bedframe == 1) { configureList.Add(new u_configure_type() { contfigtypeid = 0, contfigtypename = $"{prefix}床架", contfigtype = 0, usechflag = 1, flag = 0 }); } if (softbed.has_nightstand == 1) { configureList.Add(new u_configure_type() { contfigtypeid = 0, contfigtypename = $"{prefix}床头柜", contfigtype = 0, usechflag = 1, flag = 0 }); } var baseInfoHelper = GetHelper(cmd, context); foreach(var configure in configureList) { // 判断是否已存在 cmd.CommandText = @"SELECT COUNT(*) FROM u_configure_type WHERE LTRIM(RTRIM(contfigtypename)) = @contfigtypename"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@contfigtypename", configure.contfigtypename); var cnt = Convert.ToInt32(cmd.ExecuteScalar()); if (cnt > 0) continue; baseInfoHelper.SaveConfigureType(configure); } // 生成标准选配项值ifdft if(softbed.codeMxList != null && softbed.codeMxList.Count > 0) { foreach (var codeMx in softbed.codeMxList) { if (codeMx.pzid == 0) continue; // 判断是否有标准 cmd.CommandText = @"SELECT COUNT(*) FROM u_configure_codemx WHERE pzid = @pzid AND printid = @printid AND ifdft = 1"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@pzid", codeMx.pzid); cmd.Parameters.AddWithValue("@printid", codeMx.printid); if(Convert.ToInt32(cmd.ExecuteScalar()) > 0) { cmd.CommandText = @"UPDATE u_configure_codemx SET ifdft = 0 WHERE pzid = @pzid AND printid = @printid AND ifdft = 1"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@pzid", codeMx.pzid); cmd.Parameters.AddWithValue("@printid", codeMx.printid); cmd.ExecuteNonQuery(); } codeMx.ifdft = 1; DbSqlHelper.Update(cmd, "u_configure_codemx", null, codeMx, "pzid,printid", "ifdft"); } } } /// /// 获取软床报价配置 /// /// /// /// public List GetSoftBedConfigureList(u_softbed softbed,List extraWheres) { var codeMxList = new List(); var selectStr = @"SELECT u_configure_codemx.pzid ,u_configure_codemx.printid ,u_configure_codemx.pzcodemx ,u_configure_codemx.namemx ,u_configure_code.name AS pzname ,u_configure_code.pzcode ,u_configure_code.inputtype ,LTRIM(RTRIM(u_configure_type.contfigtypename)) AS contfigtypename ,u_configure_code.typeid ,u_configure_codemx.ifdft FROM u_configure_codemx INNER JOIN u_configure_code ON u_configure_codemx.pzid = u_configure_code.pzid INNER JOIN u_configure_type ON u_configure_code.typeid = u_configure_type.contfigtypeid"; var whereList = new List(); var nameList = new List(); if (softbed.softbed_id > 0 || softbed.template_id > 0) { // 模版配置获取 int billid = softbed.softbed_id > 0 ? softbed.softbed_id : softbed.template_id; var _softbed = GetSoftBed(billid, "softbed_id,softbed_code,has_headboard,has_nightstand,has_bedframe"); string prefix = $"{_softbed.softbed_code}|"; if(_softbed.has_headboard == 1) { nameList.Add($"{prefix}床头"); } if (_softbed.has_nightstand == 1) { nameList.Add($"{prefix}床头柜"); } if (_softbed.has_bedframe == 1) { nameList.Add($"{prefix}床架"); } } if(nameList.Count > 0) { whereList.Add($"LTRIM(RTRIM(u_configure_type.contfigtypename)) IN {ListEx.getString(nameList)}"); } if(extraWheres != null && extraWheres.Count > 0) { whereList.AddRange(extraWheres); } DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), null, "typeid,pzid,printid", "typeid,pzid,printid,pzcodemx,namemx,pzname,pzcode,contfigtypename,ifdft", 0, 0, codeMxList); // 部件选配项 var codeMap = new Dictionary(); foreach(var codeMx in codeMxList) { int pzid = codeMx.pzid.Value; if (!codeMap.TryGetValue(pzid, out var config)) { config = new u_configure_code { pzid = pzid, name = codeMx.pzname, contfigtypename = codeMx.contfigtypename, pzcode = codeMx.pzcode, typeid = codeMx.typeid, codeMxList = new List() }; codeMap.Add(pzid, config); } config.codeMxList.Add(codeMx); } // 部件选配类型 var typeMap = new Dictionary(); foreach(var code in codeMap.Values.ToList()) { int typeid = code.typeid.Value; if (!typeMap.TryGetValue(typeid, out var config)) { config = new u_configure_type { contfigtypeid = typeid, contfigtypename = code.contfigtypename, codeList = new List() }; typeMap.Add(typeid, config); } config.codeList.Add(code); } return typeMap.Values.ToList(); } /// /// 复制软床报价 /// /// /// public void CopySoftBed(u_softbed softbed, out int newId) { var fields = @"mtrlmode,mtrltype,has_headboard,has_nightstand,has_bedframe,is_template, template_id,template_code,template_name,commission,taxes,taxrate,other_rate,extras_cost,moneyrate"; var softbed_copy = GetSoftBed(softbed.softbed_id, fields); // 判断copy_bedNet.bednetcode是否存在@@字符串,如果存在,则删除@@后面的字符串,包括@@ if (softbed_copy.softbed_code.IndexOf("@@") > -1) { softbed_copy.softbed_code = softbed_copy.softbed_code.Substring(softbed_copy.softbed_code.IndexOf("@@")); } softbed_copy.softbed_code += " @@"; softbed_copy.softbed_code += DateTime.Now.ToString("yyyMMdd_mmhhss"); softbed_copy.softbed_id = 0; SaveSoftBed(softbed_copy); newId = softbed_copy.softbed_id; } /// /// 删除软床报价 /// /// /// public void DeleteSoftBed(int billid) { var softbed = GetSoftBed(billid, "softbed_code,flag"); if (softbed == null) throw new LJCommonException($"单据不存在,请检查! billid:{billid}"); if (softbed.flag == 1) throw new LJCommonException($"单据:{softbed.softbed_code}已审核,无法删除!"); DbSqlHelper.Delete(cmd, softbed); } /// /// 审核软床报价 /// /// /// public void AuditSoftBed(int billid) { var softbed = GetSoftBed(billid, "softbed_code,flag"); if (softbed == null) throw new LJCommonException($"单据不存在,请检查! billid:{billid}"); if (softbed.flag == 1) throw new LJCommonException($"单据:{softbed.softbed_code}未撤审,无法审核!"); softbed.flag = 1; softbed.audit_date = context.opdate; softbed.audit_emp = context.tokendata.username; DbSqlHelper.Update(cmd, "u_softbed",null,softbed, "softbed_id", "flag,audit_date,audit_emp"); } /// /// 撤审软床报价 /// /// /// public void CAuditSoftBed(int billid) { var softbed = GetSoftBed(billid, "softbed_code,flag"); if (softbed == null) throw new LJCommonException($"单据不存在,请检查! billid:{billid}"); if (softbed.flag == 0) throw new LJCommonException($"单据:{softbed.softbed_code}未审核,无法撤审!"); softbed.flag = 0; softbed.audit_date = null; softbed.audit_emp = string.Empty; DbSqlHelper.Update(cmd, "u_softbed", null, softbed, "softbed_id", "flag,audit_date,audit_emp"); } public void CalCulateFormula(u_softbed softbed) { InitSoftBed(softbed); InitReplaceMents(softbed); decimal total_mtrl_cost = 0, total_hr_cost = 0; foreach (var mx in softbed.mxList) { InitMxReplaceMents(softbed, mx); formula.CalculateAll(); // 转换后的文本公式 mx.use_formula_str = formula.GetFormulaItem("【实际用量】").formula_transform; mx.price_formula_str = formula.GetFormulaItem("【成本单价】").formula_transform; // 成本单价 mx.cost_price = formula.GetFormulaItem("【成本单价】").value; // 实际用量 mx.actual_useqty = formula.GetFormulaItem("【实际用量】").value; // 成本金额 mx.cost_amt = formula.GetFormulaItem("【成本金额】").value; // 总材料成本 total_mtrl_cost += mx.cost_amt; // 总人力成本 total_hr_cost += 0; } softbed.total_mtrl_cost = total_mtrl_cost; softbed.total_hr_cost = total_hr_cost; softbed.total_cost = formula.GetFormulaItem("【车间成本】").value; softbed.nottax_factory_cost = formula.GetFormulaItem("【不含税出厂价】").value; softbed.nottax_dept_cost = formula.GetFormulaItem("【部门不含税价】").value; softbed.dept_cost = formula.GetFormulaItem("【部门含税价】").value; softbed.taxes = formula.GetFormulaItem("【税金】").value; softbed.foreign_cost = formula.GetFormulaItem("【外币价】").value; //formula.CalculateAll(); } private void InitSoftBed(u_softbed softbed) { var dept = Cache.GetData(softbed.deptid); // softbed.dept_profitrate = dept.profitrate; // softbed.moneyrate = softbed.moneyrate <= 0 ? 1 : softbed.moneyrate; softbed.commission = softbed.commission <= 0 ? 1 : softbed.commission; softbed.taxrate = softbed.taxrate <= 0 ? 1 : softbed.taxrate; softbed.other_rate = softbed.other_rate <= 0 ? 1 : softbed.other_rate; softbed.dept_profitrate = softbed.dept_profitrate <= 0 ? 1 : softbed.dept_profitrate; // 检查佣金是否小于1 if (softbed.commission < 1) { throw new LJCommonException("佣金点数不能小于1!"); } // 检查税率是否小于1 if (softbed.taxrate < 1) { throw new LJCommonException("税率不能小于1!"); } // 检查额外点数是否小于1 if (softbed.other_rate < 1) { throw new LJCommonException("税率不能小于1!"); } // 检查部门利润率是否为0 if (softbed.dept_profitrate == 0) { throw new LJCommonException("部门利润率不能为0!"); } if(softbed.is_template == 1) { // 使用模板报价 softbed.template_id = 0; softbed.template_code = string.Empty; softbed.template_name = string.Empty; } } private void InitReplaceMents(u_softbed softbed) { // 常量变量 formula.AddFormulaItem("【部门利润率】", softbed.dept_profitrate); formula.AddFormulaItem("【佣金点数】", softbed.commission); formula.AddFormulaItem("【额外点数】", softbed.other_rate); formula.AddFormulaItem("【额外费用】", softbed.extras_cost); formula.AddFormulaItem("【汇率】", softbed.moneyrate); formula.AddFormulaItem("【税率】", softbed.taxrate); formula.AddFormulaItem("【工厂利润率】", 1); formula.AddFormulaItem("【FOB】", 0); formula.AddFormulaItem("【外销加点】", 0); formula.AddFormulaItem("【总材料成本】", softbed.total_mtrl_cost); formula.AddFormulaItem("【总人力成本】", softbed.total_hr_cost); // 公式变量 formula.AddFormulaItem("【不含税出厂价】", "【车间成本】*(【工厂利润率】+【外销加点】)"); formula.AddFormulaItem("【部门不含税价】", "【不含税出厂价】/【部门利润率】/( 1 - (【佣金点数】- 1))*【额外点数】+【FOB】"); formula.AddFormulaItem("【部门含税价】", "【部门不含税价】*【税率】"); formula.AddFormulaItem("【税金】", "【部门不含税价】* (【税率】-1)"); formula.AddFormulaItem("【外币价】", "【部门含税价】/【汇率】"); } private void InitMxReplaceMents(u_softbed softbed,u_softbed_mx mx) { // 默认公式变量 formula.AddFormulaItem("【车间成本】", "【总材料成本】 + 【总人力成本】 + 【额外费用】"); formula.AddFormulaItem("【成本单价】", "【材料单价】*1"); formula.AddFormulaItem("【实际用量】", "【用料量】*(1 + 【损耗率】)"); formula.AddFormulaItem("【成本金额】", "【实际用量】 * 【成本单价】"); // 常量变量 formula.AddFormulaItem("【下料长】", mx.cutting_length); formula.AddFormulaItem("【下料宽】", mx.cutting_width); formula.AddFormulaItem("【下料数量】", mx.cutting_qty); formula.AddFormulaItem("【用料量】", mx.useqty); formula.AddFormulaItem("【损耗率】", mx.loss_rate); formula.AddFormulaItem("【材料单价】", mx.price); if(mx.formulaid > 0) { cmd.CommandText = @"SELECT u_softbed_formula.formulaid ,u_softbed_formula.formulaname ,u_softbed_formula.use_formula ,u_softbed_formula.price_formula FROM u_softbed_formula WHERE formulaid = @formulaid"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@formulaid", mx.formulaid); using(var reader = cmd.ExecuteReader()) { if(reader.Read()) { formula.AddFormulaItem("【实际用量】", Convert.ToString(reader["use_formula"])); formula.AddFormulaItem("【成本单价】", Convert.ToString(reader["price_formula"])); } } } } #region 通用公式 private CalculateFormula formula = new CalculateFormula(); #endregion } }