取消UpdateTotalAmount方法及改变编程方式
取消UpdateTotalAmount方法及改变编程方式
请按照此文章进行改进:
修改单价/数量列, 自动计算金额
http://www.csframework.com/archive/9/arc-9-20141230-2172.htm
删除UpdateTotalAmount方法及相关代码!
如 frmSO, 销售订单界面修改后的代码:
扫一扫加作者微信
请按照此文章进行改进:
修改单价/数量列, 自动计算金额
http://www.csframework.com/archive/9/arc-9-20141230-2172.htm
删除UpdateTotalAmount方法及相关代码!
如 frmSO, 销售订单界面修改后的代码:
C# Code:
private void OnCellValueChanged(object sender, CellValueChangedEventArgs e)
{
//只要单价和数量栏位改动重新计算金额
if ((e.Column == colD_Price) || (e.Column == colD_Qty))
{
this.UpdateDetailAmount();//重新计算金额
}
}
/// <summary>
/// 当用户修改单价/数量列, 自动计算采购金额
/// </summary>
private void UpdateDetailAmount()
{
decimal price = ConvertEx.ToDecimal(gvDetail.GetDataRow(gvDetail.FocusedRowHandle)[tb_SOs.Price]);//单价
decimal quantity = ConvertEx.ToDecimal(gvDetail.GetDataRow(gvDetail.FocusedRowHandle)[tb_SOs.Qty]);//数量
decimal amt = Math.Round(price * quantity, 2, MidpointRounding.ToEven);//金额=数量*单价
//计算本产品的采购金额
gvDetail.SetFocusedRowCellValue(colD_Amount, amt);
gvDetail.UpdateCurrentRow();//更新当前资料行
gvDetail.UpdateTotalSummary();//更新合计
//更新主表的合计金额
decimal totalAmt = ConvertEx.ToDecimal(colD_Amount.SummaryItem.SummaryValue);
this.SetEditorBindingValue(txtAmount, totalAmt, true);
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
private void OnCellValueChanged(object sender, CellValueChangedEventArgs e)
{
//只要单价和数量栏位改动重新计算金额
if ((e.Column == colD_Price) || (e.Column == colD_Qty))
{
this.UpdateDetailAmount();//重新计算金额
}
}
/// <summary>
/// 当用户修改单价/数量列, 自动计算采购金额
/// </summary>
private void UpdateDetailAmount()
{
decimal price = ConvertEx.ToDecimal(gvDetail.GetDataRow(gvDetail.FocusedRowHandle)[tb_SOs.Price]);//单价
decimal quantity = ConvertEx.ToDecimal(gvDetail.GetDataRow(gvDetail.FocusedRowHandle)[tb_SOs.Qty]);//数量
decimal amt = Math.Round(price * quantity, 2, MidpointRounding.ToEven);//金额=数量*单价
//计算本产品的采购金额
gvDetail.SetFocusedRowCellValue(colD_Amount, amt);
gvDetail.UpdateCurrentRow();//更新当前资料行
gvDetail.UpdateTotalSummary();//更新合计
//更新主表的合计金额
decimal totalAmt = ConvertEx.ToDecimal(colD_Amount.SummaryItem.SummaryValue);
this.SetEditorBindingValue(txtAmount, totalAmt, true);
}
//来源:C/S框架网(www.csframework.com) QQ:1980854898
扫一扫加作者微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网