protected void btnSubmit_Click(object sender, EventArgs e) { if (RowIndex == -1) { DataRowEntity modelDR = new DataRowEntity { Columns = Table.UserColumns.Select(info => info.Name).ToArray(), Contents = new object[Table.UserColumns.Count] }; for (int i = 0; i < Table.UserColumns.Count; i++) { modelDR.Contents[i] = Request.Form["txt" + Table.UserColumns[i].Name]; } DataRowManage.Create(Table, modelDR); JScript.ResponseScript(this, "alert('添加成功!');location=location.href"); } else { DataRowEntity modelDR = new DataRowEntity { Columns = Table.UserColumns.Select(info => info.Name).ToArray(), Contents = new object[Table.UserColumns.Count] }; for (int i = 0; i < Table.UserColumns.Count; i++) { modelDR.Contents[i] = Request.Form["txt" + Table.UserColumns[i].Name]; } DataRowManage.Update(Table, modelDR, new DataWhereEntity[] { new DataWhereEntity { ColumnName = "RowIndex", Predicate = info => Convert.ToInt32(info) == RowIndex } } ); JScript.ResponseScript(this, "alert('更新成功!');location=location.href"); } }
/// <summary> /// 创建 /// </summary> public static void Create(DataTableEntity modelDT, DataRowEntity modelDR) { int RowIndex = DataContentManage.GetFirstEmpty(modelDT).GetRowIndex(); for (int i = 0; i < modelDR.Columns.Length; i++) { DataContentManage.Create( modelDT.Columns.Where(info => info.Name == modelDR.Columns[i]).First(), new DataContentEntity { Content = modelDR.Contents[i] }, RowIndex); } DataContentManage.Create(modelDT.Columns[0], new DataContentEntity { Content = 1 }, RowIndex); }
/// <summary> /// 修改 /// </summary> public static void Update(DataTableEntity modelDT, DataRowEntity modelDR, DataWhereEntity[] where = null) { int[] arrDC = ReadRowIndexList(modelDT, where).ToArray(); string[] Columns = modelDT.UserColumns.Select(info => info.Name).ToArray(); //以列为维度遍历取值 object[,] arrContent = new object[arrDC.Count(), Columns.Length]; for (int i = 0; i < modelDR.Columns.Length; i++) { //列需要修改 DataColumnEntity modelDC = DataColumnManage.Read(modelDT, new DataColumnEntity { Name = modelDR.Columns[i] }); for (int j = 0; j < arrDC.Length; j++) { DataContentEntity modelDContent = DataContentManage.GetContent(modelDC, arrDC[j]); modelDContent.Content = modelDR.Contents[i]; DataContentManage.Update(modelDContent); } } }