【031】DataGrid删除跟批量修改行不重新计算合计
侧边栏壁纸
  • 累计撰写 60 篇文章
  • 累计收到 2 条评论

【031】DataGrid删除跟批量修改行不重新计算合计

秋驰雪隙
2025-04-08 / 0 评论 / 7 阅读 / 正在检测是否收录...
在开启列表复选框的时候,删除行跟批量修改合计列的值都不会自动更新合计,需要编写客户端事件监控,手动重新计算合计并赋值
public void AfterCreateChildControls()
{
    OnBatchModifyCallBack();
    OnAfterRowDeletedCallBack();
}

// 批量修改事件
private void OnBatchModifyCallBack()
{
    AssociationControl assocControl = new AssociationControl();//交互关联控件实例
    assocControl.SourceServerControl = this.DataGrid8;//触发源控件
    assocControl.SourceControl.EventName = "OnBatchModify"; // 触发事件
    ClientCallBackFrm cbf = new ClientCallBackFrm();
    cbf.DoCustomerAction += new ClientCallBackFrm.ActionCustomer(OnAfterRowDeletedOrBatchModify);//定义服务器端的处理方法
    cbf.ParameterControls.Add(this.DataGrid8); //添加传送到服务器端的控件值
    cbf.Add(assocControl);
    this.Controls.Add(cbf);
}

// 删除行之后的事件
private void OnAfterRowDeletedCallBack()
{
    AssociationControl assocControl = new AssociationControl();//交互关联控件实例
    assocControl.SourceServerControl = this.DataGrid8;//触发源控件
    assocControl.SourceControl.EventName = "OnAfterRowDeleted"; // 触发事件
    ClientCallBackFrm cbf = new ClientCallBackFrm();
    cbf.DoCustomerAction += new ClientCallBackFrm.ActionCustomer(OnAfterRowDeletedOrBatchModify);//定义服务器端的处理方法
    cbf.ParameterControls.Add(this.DataGrid8); //添加传送到服务器端的控件值
    cbf.Add(assocControl);
    this.Controls.Add(cbf);
}

private object OnAfterRowDeletedOrBatchModify(CustomerActionEventArgs args)
{
    UFWebClientGridAdapter grid = new UFWebClientGridAdapter(this.DataGrid8); // 列表
    ArrayList list = (ArrayList)args.ArgsHash[this.DataGrid8.ClientID];
    HashSet<string> sumField = new HashSet<string>();
    Dictionary<string, decimal> dicTotalValve = new Dictionary<string, decimal>();
    var dataGrid = this.DataGrid8 as UFGrid;
    // 从当前的DataGrid中把合计列存到集合与字典,并初始化字典的合计值=0
    for (int i = 0; i < dataGrid.ColumnCollection.Count; i++)
    {
        if (dataGrid.ColumnCollection[i].HasSum)
        {
            sumField.Add(dataGrid.ColumnCollection[i].FieldId);
            dicTotalValve.Add(dataGrid.ColumnCollection[i].FieldId, 0);
        }
    }
    
    decimal num;
    foreach (Hashtable hashT in list)
    {
        // 循环累加需要合计的列的值
        foreach (string colName in sumField)
        {
            decimal.TryParse(hashT[colName].ToString(), out num);
            dicTotalValve[colName] += num;
        }
    }
    foreach (string colName in dicTotalValve.Keys)
    {
        args.ArgsResult.Add(grid.ClientInstanceWithSetTotalValue(colName, dicTotalValve[colName].ToString()));
    }
    return args;
}

合计刷新之后,点击放弃,合计列的值还是上一次的缓存

public void AfterUIModelBinding()
{
    ((UFWebDataGridAdapter)this.DataGrid8).ClearTotalValue(); // 清除所有列的合计值
    ((UFWebDataGridAdapter)this.DataGrid8).ResetSumData = true; // 刷新合计列的值
}
0

评论 (0)

取消