需求:
现需要将包装成本纳入单个成品生产成本中。
方案:
利用公式,替换其中的规格来达到自动计算的目的。
首先确定公式,然后将公式写入公式维护表中, 便于引用。
选择类型的时候将该类需要的公式数据库取出绑定下拉
protected void etxt_mType2_Blur(object sender, EventArgs e)
{
string strmname = promat_name.Text.Trim();
if (new pd_productdesign().isExistdata("pd_formula", "type", strmname, "ID") != "")
{
BindDDL(dp_formula, "select ID,content from pd_formula where type = '" + strmname + "'");
}
}
除了规格填写框之外,需要增加将尺寸转换为价格的系数填写框,例如每平方厘米的价格
判断公式所需的条件是否填写完全
替换公式中的对应数据
自动计算偶皮
protected void letxt_quantity_Blur(object sender, EventArgs e)
{
string strchang = letxt_chang.Text.Trim();
string strkuan = letxt_kuan.Text.Trim();
string strgao = letxt_gao.Text.Trim();
string quantity = letxt_packingquantity.Text.Trim();
if (strchang != "" && strkuan != "" && strgao != "")
{
letxt_volume.Text = Math.Round(ConvertEx.ToDecimal(strchang) * ConvertEx.ToDecimal(strkuan) * ConvertEx.ToDecimal(strgao), 5).ToString();
promat_specification.Text = strchang + "*" + strkuan + "*" + strgao;
}
if (promat_name.Text.Contains("隔板") && strchang != "" && strkuan != "")
{
promat_specification.Text = strchang + "*" + strkuan;
}
#region 包装单价计算
string strformula = dp_formula.SelectedText;
if (strformula != "" && strformula != null && strformula != "请选择")
{
string strxishu1 = letxt_xishu1.Text;
// string strxishu2 = letxt_xishu2.Text;
//string strxishu3 = letxt_xishu3.Text;
if (strformula.Contains("长"))
{
if (strchang == "")
{
ShowNotify("长为空!");
return;
}
}
if (strformula.Contains("宽"))
{
if (strkuan == "")
{
ShowNotify("宽为空!");
return;
}
}
if (strformula.Contains("高"))
{
if (strgao == "")
{
ShowNotify("高为空!");
return;
}
}
if (strformula.Contains("装箱数量"))
{
if (quantity == "")
{
ShowNotify("装箱数量为空!");
return;
}
}
strformula = strformula.Replace("长", strchang).Replace("宽", strkuan).Replace("高", strgao).Replace("装箱数量", quantity);
var price = new System.Data.DataTable().Compute(strformula, "");
decimal price2 = Math.Round(ConvertEx.ToDecimal(price), 2);
promat_univalence.Text = price2.ToString();
}
else
{
ShowNotify("计算公式无内容!");
}
#endregion
}
优势:简单直接,利于多个公式的选择及维护
劣势:需要和输入框一对一配对,一旦公式中的参数个数改变,需要重新配置输入框