protected void Button2_Click(object sender, EventArgs e) { if (Grid1.GetModifiedData().Count == 0) { //labResult.Text = ""; //ShowNotify("表格数据没有变化!"); Alert.ShowInTop("表格内没有数据!"); return; } // 复制原始表格的结构 DataTable newTable = GetSourceData().Clone(); DataRow newRow; int rowIndex = 0; JArray mergedData = Grid1.GetMergedData(); foreach (JObject mergedRow in mergedData) { JObject values = mergedRow.Value <JObject>("values"); newRow = newTable.NewRow(); newRow[0] = rowIndex; newRow[1] = values.Value <string>("设备编号"); string ss = values.Value <string>("设备编号"); if (ss == "" || ss == null) { Alert.ShowInTop("请填写完整数据"); return; } newRow[2] = values.Value <string>("重点设备"); newRow[3] = values.Value <string>("设备名称"); } }
protected void Grid1_AfterEdit(object sender, GridAfterEditEventArgs e) { // 当前选中的单元格 string[] selectedCell = Grid1.SelectedCell; Dictionary <int, Dictionary <string, object> > modifiedDict = Grid1.GetModifiedDict(); foreach (int rowIndex in modifiedDict.Keys) { int rowID = Convert.ToInt32(Grid1.DataKeys[rowIndex][0]); DataRow row = FindRowByID(rowID); UpdateDataRow(modifiedDict[rowIndex], row); } // 数据绑定时,会清空选中的行和选中的单元格 BindGrid(); labResult.Text = String.Format("用户修改的数据:<pre>{0}</pre>", Grid1.GetModifiedData().ToString(Newtonsoft.Json.Formatting.Indented)); if (selectedCell != null) { // 重新选中之前的单元格 PageContext.RegisterStartupScript(String.Format("F('{0}').f_selectCell('{1}','{2}');", Grid1.ClientID, selectedCell[0], selectedCell[1])); } }
protected void btnSave_Click(object sender, EventArgs e) { try { if (Grid1.GetModifiedData().Count == 0 && Grid1.GetNewAddedList().Count == 0) { Alert.Show("表格数据没有变化!"); return; } ArrayList al = new ArrayList(); string sql = "", s = ""; // 新增数据 List <Dictionary <string, object> > newAddedList = Grid1.GetNewAddedList(); for (int i = 0; i < newAddedList.Count; i++) { sql = "insert into rlitems(itemno,itemname,Spec,Material,Price,SupplierId,UnitWeight,ProcessCost,ProcessCostType,SurfaceDeal,BaseNum,Sclass,WorkShop,MainFrom,StoreHouse,ProUsingQuantity,ZongCheng) values('" + newAddedList[i]["ItemNo"].ToString() + "','" + newAddedList[i]["ItemName"].ToString() + "','" + newAddedList[i]["Spec"].ToString() + "','" + newAddedList[i]["Material"].ToString() + "'," + newAddedList[i]["Price"].ToString() + "," + newAddedList[i]["SupplierId"].ToString() + "," + newAddedList[i]["UnitWeight"].ToString() + "," + newAddedList[i]["ProcessCost"].ToString() + ",'" + newAddedList[i]["ProcessCostType"].ToString() + "','" + newAddedList[i]["SurfaceDeal"].ToString() + "'," + newAddedList[i]["BaseNum"].ToString() + ",'" + newAddedList[i]["Sclass"].ToString() + "','" + newAddedList[i]["WorkShop"].ToString() + "','" + newAddedList[i]["MainFrom"].ToString() + "','" + newAddedList[i]["StoreHouse"].ToString() + "'," + newAddedList[i]["ProUsingQuantity"].ToString() + ",'" + newAddedList[i]["ZongCheng"].ToString() + "')"; log.Info("sql add item:" + sql); al.Add(sql); } //Alert.Show(s); //return; //s = ""; // 修改的现有数据 Dictionary <int, Dictionary <string, object> > modifiedDict = Grid1.GetModifiedDict(); SQLHelper.DbHelperSQL.SetConnectionString(""); foreach (int rowIndex in modifiedDict.Keys) { sql = "update rlitems set "; for (int i = 0; i < Grid1.Columns.Count; i++) { if (modifiedDict[rowIndex].ContainsKey(Grid1.Columns[i].ColumnID)) { sql += Grid1.Columns[i].ColumnID + "='" + modifiedDict[rowIndex][Grid1.Columns[i].ColumnID].ToString() + "',"; } } sql = sql.TrimEnd(new char[] { ',' }); sql += " where sn=" + Grid1.DataKeys[rowIndex][0]; s += sql + "------"; al.Add(sql); } SQLHelper.DbHelperSQL.SetConnectionString(""); if (SQLHelper.DbHelperSQL.ExecuteSqlTran(al)) { Alert.Show("保存成功"); BindGrid(); } else { Alert.Show("保存失败"); } } catch (Exception ee) { Alert.Show(ee.Message); } }
protected void Button2_Click(object sender, EventArgs e) { Dictionary <int, Dictionary <string, string> > modifiedDict = Grid1.GetModifiedDict(); for (int i = 0, count = Grid1.Rows.Count; i < count; i++) { if (modifiedDict.ContainsKey(i)) { Dictionary <string, string> rowDict = modifiedDict[i]; // 更新数据源 DataTable table = GetSourceData(); DataRow rowData = table.Rows[i]; // 姓名 if (rowDict.ContainsKey("Name")) { rowData["Name"] = rowDict["Name"]; } // 性别 if (rowDict.ContainsKey("Gender")) { rowData["Gender"] = Convert.ToInt32(rowDict["Gender"]); } // 入学年份 if (rowDict.ContainsKey("EntranceYear")) { rowData["EntranceYear"] = rowDict["EntranceYear"]; } // 入学日期 if (rowDict.ContainsKey("EntranceDate")) { rowData["EntranceDate"] = DateTime.Parse(rowDict["EntranceDate"]).ToString("yyyy-MM-dd"); } // 是否在校 if (rowDict.ContainsKey("AtSchool")) { rowData["AtSchool"] = Convert.ToBoolean(rowDict["AtSchool"]); } // 所学专业 if (rowDict.ContainsKey("Major")) { rowData["Major"] = rowDict["Major"]; } } } labResult.Text = "用户修改的数据:" + Grid1.GetModifiedData().ToString(Newtonsoft.Json.Formatting.None); BindGrid(); Alert.Show("数据保存成功!(表格数据已重新绑定)"); }
protected void Button2_Click(object sender, EventArgs e) { // 修改的现有数据 Dictionary <int, Dictionary <string, object> > modifiedDict = Grid1.GetModifiedDict(); foreach (int rowIndex in modifiedDict.Keys) { int rowID = Convert.ToInt32(Grid1.DataKeys[rowIndex][0]); DataRow row = FindRowByID(rowID); UpdateDataRow(modifiedDict[rowIndex], row); } // 删除现有数据 List <int> deletedRows = Grid1.GetDeletedList(); foreach (int rowIndex in deletedRows) { int rowID = Convert.ToInt32(Grid1.DataKeys[rowIndex][0]); DeleteRowByID(rowID); } // 新增数据 List <Dictionary <string, object> > newAddedList = Grid1.GetNewAddedList(); DataTable table = GetSourceData(); if (AppendToEnd) { for (int i = 0; i < newAddedList.Count; i++) { DataRow rowData = CreateNewData(table, newAddedList[i]); table.Rows.Add(rowData); } } else { for (int i = newAddedList.Count - 1; i >= 0; i--) { DataRow rowData = CreateNewData(table, newAddedList[i]); table.Rows.InsertAt(rowData, 0); } } labResult.Text = String.Format("修改的数据:<pre>{0}</pre>", Grid1.GetModifiedData().ToString(Newtonsoft.Json.Formatting.Indented)); BindGrid(); ShowNotify("数据保存成功!(表格数据已重新绑定)"); }
protected void Grid1_AfterEdit(object sender, GridAfterEditEventArgs e) { Dictionary <int, Dictionary <string, string> > modifiedDict = Grid1.GetModifiedDict(); int rowID = Convert.ToInt32(Grid1.DataKeys[e.RowIndex][0]); DataRow row = FindRowByID(rowID); UpdateDataRow(modifiedDict[e.RowIndex], row); BindGrid(); labResult.Text = "用户修改的数据:" + Grid1.GetModifiedData().ToString(Newtonsoft.Json.Formatting.None); Alert.Show("数据保存成功!(表格数据已重新绑定)"); }
protected void Button2_Click(object sender, EventArgs e) { Dictionary <int, Dictionary <string, string> > modifiedDict = Grid1.GetModifiedDict(); foreach (int rowIndex in modifiedDict.Keys) { int rowID = Convert.ToInt32(Grid1.DataKeys[rowIndex][0]); DataRow row = FindRowByID(rowID); UpdateDataRow(modifiedDict[rowIndex], row); } BindGrid(); labResult.Text = "用户修改的数据:" + Grid1.GetModifiedData().ToString(Newtonsoft.Json.Formatting.None); Alert.Show("数据保存成功!(表格数据已重新绑定)"); }
protected void Grid1_AfterEdit(object sender, GridAfterEditEventArgs e) { Dictionary <int, Dictionary <string, object> > modifiedDict = Grid1.GetModifiedDict(); foreach (int rowIndex in modifiedDict.Keys) { int rowID = Convert.ToInt32(Grid1.DataKeys[rowIndex][0]); DataRow row = FindRowByID(rowID); UpdateDataRow(modifiedDict[rowIndex], row); } BindGrid(); labResult.Text = String.Format("用户修改的数据:<pre>{0}</pre>", Grid1.GetModifiedData().ToString(Newtonsoft.Json.Formatting.Indented)); Alert.Show("数据保存成功!(表格数据已重新绑定)"); }
protected void Button2_Click(object sender, EventArgs e) { if (Grid1.GetModifiedData().Count == 0) { Alert.Show("表格数据没有变化!"); return; } // 复制原始表格的结构 DataTable newTable = GetSourceData().Clone(); DataRow newRow; JArray mergedData = Grid1.GetMergedData(); foreach (JObject mergedRow in mergedData) { string status = mergedRow.Value <string>("status"); int rowIndex = mergedRow.Value <int>("index"); JObject values = mergedRow.Value <JObject>("values"); newRow = newTable.NewRow(); newRow[0] = rowIndex; // 将行标识符设置为行索引号 newRow[1] = values.Value <string>("Name"); newRow[2] = values.Value <int>("EntranceYear"); newRow[3] = values.Value <bool>("AtSchool"); newRow[4] = values.Value <string>("Major"); newRow[5] = values.Value <int>("Gender"); newRow[6] = values.Value <string>("EntranceDate"); newTable.Rows.Add(newRow); } // 更新数据源 Session[KEY_FOR_DATASOURCE_SESSION] = newTable; labResult.Text = String.Format("用户修改的数据:<pre>{0}</pre>", Grid1.GetModifiedData().ToString(Newtonsoft.Json.Formatting.Indented)); BindGrid(); Alert.Show("数据保存成功!(表格数据已重新绑定)"); }
protected void btnSave_Click(object sender, EventArgs e) { try { if (Grid1.GetModifiedData().Count == 0 && Grid1.GetNewAddedList().Count == 0) { Alert.Show("表格数据没有变化!"); return; } ArrayList al = new ArrayList(); string sql = "", s = ""; // 新增数据 List <Dictionary <string, object> > newAddedList = Grid1.GetNewAddedList(); for (int i = 0; i < newAddedList.Count; i++) { //s += newAddedList[i]["ItemNo"].ToString() + "----" + newAddedList[i]["Name"].ToString() + "----" + newAddedList[i]["Spec"].ToString() + "----" + newAddedList[i]["MaterialNo"].ToString() + "----" + newAddedList[i]["ItemColor"].ToString(); sql = "insert into OrderHeader(OrderNo,ClientOrderNo,LotNo,ClientCode,RecOrderPerson,RecOrderDate,SendOrderDate,OutGoodsDate,Inputer,InputerDate) values('" + newAddedList[i]["OrderNo"].ToString() + "','" + newAddedList[i]["ClientOrderNo"].ToString() + "','" + newAddedList[i]["LotNo"].ToString() + "','" + newAddedList[i]["ClientCode"].ToString() + "','" + newAddedList[i]["RecOrderPerson"].ToString() + "','" + newAddedList[i]["RecOrderDate"].ToString() + "','" + newAddedList[i]["SendOrderDate"].ToString() + "','" + newAddedList[i]["OutGoodsDate"].ToString() + "','" + newAddedList[i]["Inputer"].ToString() + "','" + newAddedList[i]["InputerDate"].ToString() + "')"; s += sql + "---"; al.Add(sql); } //Alert.Show(s); //return; //s = ""; // 修改的现有数据 Dictionary <int, Dictionary <string, object> > modifiedDict = Grid1.GetModifiedDict(); SQLHelper.DbHelperSQL.SetConnectionString(""); foreach (int rowIndex in modifiedDict.Keys) { sql = "update OrderHeader set "; for (int i = 0; i < Grid1.Columns.Count; i++) { if (modifiedDict[rowIndex].ContainsKey(Grid1.Columns[i].ColumnID)) { sql += Grid1.Columns[i].ColumnID + "='" + modifiedDict[rowIndex][Grid1.Columns[i].ColumnID].ToString() + "',"; } } sql = sql.TrimEnd(new char[] { ',' }); sql += " where sn=" + Grid1.DataKeys[rowIndex][0]; s += sql + "------"; al.Add(sql); } //al.Add(sql); SQLHelper.DbHelperSQL.SetConnectionString(""); if (SQLHelper.DbHelperSQL.ExecuteSqlTran(al)) { Alert.Show("保存成功"); BindGrid(); } else { Alert.Show("保存失败"); } } catch (Exception ee) { Alert.Show(ee.Message); } }
protected void btnSave_Click(object sender, EventArgs e) { try { if (Grid1.GetModifiedData().Count == 0 && Grid1.GetNewAddedList().Count == 0) { Alert.Show("表格数据没有变化!"); return; } ArrayList al = new ArrayList(); string sql = "", s = ""; // 新增数据 SQLHelper.DbHelperSQL.SetConnectionString(""); List <Dictionary <string, object> > newAddedList = Grid1.GetNewAddedList(); string lastcode = "", lastname = ""; for (int i = 0; i < newAddedList.Count; i++) { if (lastcode == newAddedList[i]["ClassCode"].ToString() || lastname == newAddedList[i]["ClassName"].ToString()) { Alert.Show("第" + (i + 1) + "行已经存在相同的分类代码或分类名称,请更改"); return; } else { sql = "select count(*) from GoodsClass where ClassCode='" + newAddedList[i]["ClassCode"].ToString() + "' or ClassName='" + newAddedList[i]["ClassName"].ToString() + "'"; if (int.Parse(SQLHelper.DbHelperSQL.GetSingle(sql, 30)) > 0) { Alert.Show("第" + (i + 1) + "行已经存在相同的分类代码或分类名称,请更改"); return; } } lastcode = newAddedList[i]["ClassCode"].ToString(); lastname = newAddedList[i]["ClassName"].ToString(); sql = "insert into GoodsClass(ClassCode,ClassName,SortIndex) values('" + newAddedList[i]["ClassCode"].ToString() + "','" + newAddedList[i]["ClassName"].ToString() + "'," + newAddedList[i]["SortIndex"].ToString() + ")"; log.Info("sql add GoodsClass:" + sql); al.Add(sql); } //Alert.Show(s); //return; //s = ""; // 修改的现有数据 Dictionary <int, Dictionary <string, object> > modifiedDict = Grid1.GetModifiedDict(); foreach (int rowIndex in modifiedDict.Keys) { sql = "update GoodsClass set "; for (int i = 0; i < Grid1.Columns.Count; i++) { if (modifiedDict[rowIndex].ContainsKey(Grid1.Columns[i].ColumnID)) { sql += Grid1.Columns[i].ColumnID + "='" + modifiedDict[rowIndex][Grid1.Columns[i].ColumnID].ToString() + "',"; } } sql = sql.TrimEnd(new char[] { ',' }); sql += " where sn=" + Grid1.DataKeys[rowIndex][0]; al.Add(sql); } SQLHelper.DbHelperSQL.SetConnectionString(""); if (SQLHelper.DbHelperSQL.ExecuteSqlTran(al)) { Alert.Show("保存成功"); BindGrid(); } else { Alert.Show("保存失败"); } } catch (Exception ee) { Alert.Show(ee.Message); } }
protected void btnSave2_Click(object sender, EventArgs e) { try { if (Grid1.GetModifiedData().Count == 0 && Grid1.GetNewAddedList().Count == 0) { Alert.Show("表格数据没有变化!"); return; } ArrayList al = new ArrayList(); string sql = "", s = ""; if (Grid1.GetNewAddedList().Count != 0) { // 新增数据 List <Dictionary <string, object> > newAddedList = Grid1.GetNewAddedList(); for (int i = 0; i < newAddedList.Count; i++) { //s += newAddedList[i]["ItemNo"].ToString() + "----" + newAddedList[i]["Name"].ToString() + "----" + newAddedList[i]["Spec"].ToString() + "----" + newAddedList[i]["MaterialNo"].ToString() + "----" + newAddedList[i]["ItemColor"].ToString(); sql = "insert into AllItem(ItemNo,Name,Spec,MaterialNo,ItemColor,AddReserve1,ClassName) values('" + newAddedList[i]["ItemNo"].ToString() + "','" + newAddedList[i]["Name"].ToString() + "','" + newAddedList[i]["Spec"].ToString() + "','" + newAddedList[i]["MaterialNo"].ToString() + "','" + newAddedList[i]["ItemColor"].ToString() + "','" + newAddedList[i]["AddReserve1"].ToString() + "','" + newAddedList[i]["ClassName"].ToString() + "')"; s += sql + "---"; al.Add(sql); } } //Alert.Show(s); //return; //s = ""; if (Grid1.GetModifiedData().Count != 0) { // 修改的现有数据 Dictionary <int, Dictionary <string, object> > modifiedDict = Grid1.GetModifiedDict(); SQLHelper.DbHelperSQL.SetConnectionString(""); foreach (int rowIndex in modifiedDict.Keys) { sql = "update AllItem set "; for (int i = 0; i < Grid1.Columns.Count; i++) { if (modifiedDict[rowIndex].ContainsKey(Grid1.Columns[i].ColumnID)) { sql += Grid1.Columns[i].ColumnID + "='" + modifiedDict[rowIndex][Grid1.Columns[i].ColumnID].ToString() + "',"; } } sql = sql.TrimEnd(new char[] { ',' }); sql += " where sn=" + Grid1.DataKeys[rowIndex][0]; //s += sql + "------"; al.Add(sql); } } //al.Add(sql); //sql = "update AllItem set ItemNo='" + modifiedDict[rowIndex]["ItemNo"].ToString() + "',Name='" + modifiedDict[rowIndex]["Name"].ToString() + "',Spec='" + modifiedDict[rowIndex]["Spec"].ToString() + "',MaterialNo='" + modifiedDict[rowIndex]["MaterialNo"].ToString() + "',ItemColor='" + modifiedDict[rowIndex]["ItemColor"].ToString() + "',AddReserve1='" + modifiedDict[rowIndex]["AddReserve1"].ToString() + "',ClassName='" + modifiedDict[rowIndex]["ClassName"].ToString() + "' where sn=" + GetSelectedDataKeyID(Grid1); //Alert.Show(s); SQLHelper.DbHelperSQL.SetConnectionString(""); if (SQLHelper.DbHelperSQL.ExecuteSqlTran(al)) { Alert.Show("保存成功"); BindGrid(); } else { Alert.Show("保存失败"); } } catch (Exception ee) { Alert.Show(ee.Message); } }
protected void btnSave_Click(object sender, EventArgs e) { try { if (Grid1.GetModifiedData().Count == 0 && Grid1.GetNewAddedList().Count == 0) { Alert.Show("表格数据没有变化!"); return; } ArrayList al = new ArrayList(); string sql = "", s = ""; // 新增数据 //List<Dictionary<string, object>> newAddedList = Grid1.GetNewAddedList(); //for (int i = 0; i < newAddedList.Count; i++) //{ // //s += newAddedList[i]["ItemNo"].ToString() + "----" + newAddedList[i]["Name"].ToString() + "----" + newAddedList[i]["Spec"].ToString() + "----" + newAddedList[i]["MaterialNo"].ToString() + "----" + newAddedList[i]["ItemColor"].ToString(); // sql = "insert into AllItem(ItemNo,Name,Spec,MaterialNo,ItemColor,AddReserve1,ClassName) values('" + newAddedList[i]["ItemNo"].ToString() + "','" + newAddedList[i]["Name"].ToString() + "','" + newAddedList[i]["Spec"].ToString() + "','" + newAddedList[i]["MaterialNo"].ToString() + "','" + newAddedList[i]["ItemColor"].ToString() + "','" + newAddedList[i]["AddReserve1"].ToString() + "','" + newAddedList[i]["ClassName"].ToString() + "')"; // s += sql + "---"; // al.Add(sql); //} //Alert.Show(s); //return; //s = ""; // 修改的现有数据 Dictionary <int, Dictionary <string, object> > modifiedDict = Grid1.GetModifiedDict(); SQLHelper.DbHelperSQL.SetConnectionString(""); foreach (int rowIndex in modifiedDict.Keys) { sql = "update Instruction set "; for (int i = 0; i < Grid1.Columns.Count; i++) { if (modifiedDict[rowIndex].ContainsKey(Grid1.Columns[i].ColumnID)) { sql += Grid1.Columns[i].ColumnID + "='" + modifiedDict[rowIndex][Grid1.Columns[i].ColumnID].ToString() + "',"; } } //sql = sql.TrimEnd(new char[] { ',' }); sql += "ConfirmDate=getdate() where sn=" + Grid1.DataKeys[rowIndex][0]; al.Add(sql); sql = "select case when (select COUNT(*) from Instruction where OdtSN = " + Grid1.Rows[rowIndex].Values[21].ToString() + " and OrderNo = '" + Grid1.Rows[rowIndex].Values[1].ToString() + "') >= (select COUNT(*) from BomDetail where FSN = (select SN from BomHeader where OdtSN = " + Grid1.Rows[rowIndex].Values[21].ToString() + " and OrderNo = '" + Grid1.Rows[rowIndex].Values[1].ToString() + "')) then 1 else 0 end "; if (SQLHelper.DbHelperSQL.GetSingle(sql, 30) == "1") { sql = "update OrderDetail set isconfirm=1 where SN = " + Grid1.Rows[rowIndex].Values[21].ToString() + " and OrderNo = '" + Grid1.Rows[rowIndex].Values[1].ToString() + "'"; al.Add(sql); //Alert.Show(sql); } } SQLHelper.DbHelperSQL.SetConnectionString(""); if (SQLHelper.DbHelperSQL.ExecuteSqlTran(al)) { Alert.Show("保存成功"); BindGrid(); } else { Alert.Show("保存失败"); } } catch (Exception ee) { Alert.Show(ee.Message); } }