主从表界面自动计算明细表合计汇总金额数量
主从表界面自动计算明细表合计汇总金额数量
扫一扫加微信
分为两个部分:
1. 修改明细表的【单价】、【数量】列,自动计算金额。
2. 自动计算主表的合计金额(TotalAmount)
绑定明细表格的CellValueChanged事件:
C# Code:
gvDetail.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(OnCellValueChanged); //表格值改变
//来源:C/S框架网 | www.csframework.com | QQ:23404761
//来源:C/S框架网 | www.csframework.com | QQ:23404761
C# Code:
private void OnCellValueChanged(object sender, CellValueChangedEventArgs e)
{
//用户修改了单价、数量列
if ((e.Column == colD_Price) || (e.Column == colD_Quantity))
{
this.UpdateDetailAmount();
}
}
/// <summary>
/// 当用户修改单价/数量列, 自动计算采购金额
/// </summary>
private void UpdateDetailAmount()
{
decimal price = ConvertEx.ToDecimal(gvDetail.GetDataRow(gvDetail.FocusedRowHandle)[tb_POs.Price]);//单价
decimal quantity = ConvertEx.ToDecimal(gvDetail.GetDataRow(gvDetail.FocusedRowHandle)[tb_POs.Quantity]);//数量
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:23404761
private void OnCellValueChanged(object sender, CellValueChangedEventArgs e)
{
//用户修改了单价、数量列
if ((e.Column == colD_Price) || (e.Column == colD_Quantity))
{
this.UpdateDetailAmount();
}
}
/// <summary>
/// 当用户修改单价/数量列, 自动计算采购金额
/// </summary>
private void UpdateDetailAmount()
{
decimal price = ConvertEx.ToDecimal(gvDetail.GetDataRow(gvDetail.FocusedRowHandle)[tb_POs.Price]);//单价
decimal quantity = ConvertEx.ToDecimal(gvDetail.GetDataRow(gvDetail.FocusedRowHandle)[tb_POs.Quantity]);//数量
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:23404761
SetEditorBindingValue 方法是给主表的txtTotalAmount文本框赋值。框架基类自带的方法。
扫一扫加微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网