- private void SaveData()
- {
- //Id,sno,bookName
- string strSql = string.Empty;
- // 删除现有数据
- List<int> deletedRows = Grid1.GetDeletedList();
- foreach (int rowIndex in deletedRows)
- {
- string id = "0";
- if (Grid1.DataKeys[rowIndex][0] != null)
- id = Grid1.DataKeys[rowIndex][0].ToString();
- strSql += "delete from BookSell where ID='" + id + "'; ";
- }
- // 修改的现有数据
- Dictionary<int, Dictionary<string, object>> modifiedDict = Grid1.GetModifiedDict();
- foreach (int rowIndex in modifiedDict.Keys)
- {
- string id = "0";
- if (Grid1.DataKeys[rowIndex][0] != null)
- id = Grid1.DataKeys[rowIndex][0].ToString();
- Dictionary<string, object> rowDict = modifiedDict[rowIndex];
- string upField = string.Empty;
- #region 更新字段设置
- // 执行编辑
- if (rowDict.ContainsKey("zxEditor"))
- {
- upField += " zxEditor='" + rowDict["zxEditor"] + "',";
- }
- // 序号
- if (rowDict.ContainsKey("SNO"))
- {
- upField += " SNO='" + rowDict["SNO"] + "',";
- }
- // 书名
- if (rowDict.ContainsKey("bookName"))
- {
- upField += " bookName='" + rowDict["bookName"] + "',";
- }
- // 类型
- if (rowDict.ContainsKey("itype"))
- {
- upField += " itype='" + rowDict["itype"] + "',";
- }
- // 定价
- if (rowDict.ContainsKey("price"))
- {
- upField += " price='" + rowDict["price"] + "',";
- }
- // 印数
- if (rowDict.ContainsKey("yinCount"))
- {
- upField += " yinCount='" + rowDict["yinCount"] + "',";
- }
- // 出版时间
- if (rowDict.ContainsKey("cbTime"))
- {
- upField += " cbTime='" + rowDict["cbTime"] + "',";
- }
- // 进度
- if (rowDict.ContainsKey("step"))
- {
- upField += " step='" + rowDict["step"] + "',";
- }
- // 销售册数
- if (rowDict.ContainsKey("SellCount"))
- {
- upField += " SellCount='" + rowDict["SellCount"] + "',";
- }
- // 经销商
- if (rowDict.ContainsKey("jxs"))
- {
- upField += " jxs='" + rowDict["jxs"] + "',";
- }
- // 银行
- if (rowDict.ContainsKey("bank"))
- {
- upField += " bank='" + rowDict["bank"] + "',";
- }
- // 回款(实洋)
- if (rowDict.ContainsKey("hk"))
- {
- upField += " hk='" + rowDict["hk"] + "',";
- }
- // 回款时间
- if (rowDict.ContainsKey("hkTime"))
- {
- upField += " hkTime='" + rowDict["hkTime"] + "',";
- }
- // 薪酬
- if (rowDict.ContainsKey("Amt"))
- {
- upField += " Amt='" + rowDict["Amt"] + "',";
- }
- upField = upField.TrimEnd(',');
- #endregion
- if (!string.IsNullOrWhiteSpace(upField))
- {
- strSql += "update BookSell set " + upField + " where ID='" + id + "';";
- }
- }
- // 新增数据
- List<Dictionary<string, object>> newAddedList = Grid1.GetNewAddedList();
- for (int i = 0; i < newAddedList.Count; i++)
- {
- string insertStr = "INSERT INTO [BookSell]([SNO],[bookName],[yinCount],[zxEditor],[itype],[step],[cbTime],[price],[SellCount],[jxs],[bank],[hk],[hkTime],[Amt]) VALUES( ";
- Dictionary<string, object> rowDict = newAddedList[i];
- insertStr += "'" + rowDict["SNO"] + "','" + rowDict["bookName"] + "','" + rowDict["yinCount"] + "','" + rowDict["zxEditor"] + "','" + rowDict["itype"] + "','" + rowDict["step"] + "','" + rowDict["cbTime"] + "','" + rowDict["price"] + "','" + rowDict["SellCount"] + "','" + rowDict["jxs"] + "','" + rowDict["bank"] + "','" + rowDict["hk"] + "','" + rowDict["hkTime"] + "','" + rowDict["Amt"] + "'";
- insertStr += ");";
- strSql += insertStr;
- }
- if (!string.IsNullOrWhiteSpace(strSql))
- Maticsoft.DBUtility.DbHelperSQL.ExecuteSql(strSql);
- BindGrid(0);
- }
复制代码
|