FineUI 官方论坛
标题: 代码贡献:使用EF或Linq进行表格Grid的单元格编辑的代码 [打印本页]
作者: Stark11 时间: 2019-5-13 21:48
标题: 代码贡献:使用EF或Linq进行表格Grid的单元格编辑的代码
在FineUIPro 社区里获取资料有一段时间了,现在也为社区做点奉献,给出官网示例没有的代码,请多多批评指教。
-------------------------------------
代码贡献:使用EF或Linq进行表格Grid的单元格编辑的代码,参考网友代码修改而成,祝FineUIPro越来越好!
private void SaveBomChild()
{
//新增子件数据
List<Dictionary<string, object>> newAddedList = Grid1.GetNewAddedList();
int sortindex = MpsBomHelper.GetBomChildSortIndexMax(tbxBomID.Text.Trim());
if (newAddedList.Count > 0)
{
foreach (var dic in newAddedList)
{
dtMpsBomChild item = new dtMpsBomChild();
item.BomID = tbxBomID.Text.Trim();
item.SortIndex = sortindex;
item.MateID = dic["MateID"].ToString();
item.BomChildType = dic["BomChildType"].ToString();
item.BomChildNum = Convert.ToDecimal(dic["BomChildNum"].ToString());
item.BomBaseNum = Convert.ToDecimal(dic["BomBaseNum"].ToString());
item.Remark = dic["Remark"].ToString();
sortindex += 1;
DB.dtMpsBomChild.Add(item);
}
}
}
private void UpdateBomChild()
{
//修改子件数据
Dictionary<int, Dictionary<string, object>> modifiedDict = Grid1.GetModifiedDict();
if (modifiedDict.Count > 0)
{
dtMpsBomChild item = new dtMpsBomChild();
foreach (var one in modifiedDict)
{
int rowIndex = one.Key; //DataKeys数组的序号 [one.Key]
int rowid = Convert.ToInt32(Grid1.DataKeys[rowIndex][0]);
Dictionary<string, object> dic = one.Value;
item = DB.dtMpsBomChild.Find(rowid);
if (dic.ContainsKey("SortIndex")) item.SortIndex = Convert.ToInt32(dic["SortIndex"].ToString());
if (dic.ContainsKey("MateID")) item.MateID = dic["MateID"].ToString();
if (dic.ContainsKey("BomChildType")) item.BomChildType = dic["BomChildType"].ToString();
if (dic.ContainsKey("BomChildNum")) item.BomChildNum = Convert.ToDecimal(dic["BomChildNum"].ToString());
if (dic.ContainsKey("BomBaseNum")) item.BomBaseNum = Convert.ToDecimal(dic["BomBaseNum"].ToString());
if (dic.ContainsKey("Remark")) item.Remark = dic["Remark"].ToString();
}
}
}
private void DeleteBomChild()
{
//删除子件数据
List<int> deletedRows = Grid1.GetDeletedList();
if (deletedRows.Count > 0)
{
foreach (int rowIndex in deletedRows)
{
int rowid = Convert.ToInt32(Grid1.DataKeys[rowIndex][0]);
DB.dtMpsBomChild.Where(c => c.ID == rowid).Delete();
}
}
}
作者: aqsoft 时间: 2019-5-21 17:21
内部赋值完全可以用反射处理,你这样太麻烦了
欢迎光临 FineUI 官方论坛 (https://fineui.com/BBS/) |
Powered by Discuz! X3.4 |