/// <summary> /// 增加一条数据 /// </summary> public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model._PurchaseSet model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.ReasonCode != null) { strSql1.Append("ReasonCode,"); strSql2.Append("'" + model.ReasonCode + "',"); } if (model.Description != null) { strSql1.Append("Description,"); strSql2.Append("'" + model.Description + "',"); } if (model.CostCenter != null) { strSql1.Append("CostCenter,"); strSql2.Append("'" + model.CostCenter + "',"); } if (model.CostCentreDescription != null) { strSql1.Append("CostCentreDescription,"); strSql2.Append("'" + model.CostCentreDescription + "',"); } if (model.GLAccountCode != null) { strSql1.Append("GLAccountCode,"); strSql2.Append("'" + model.GLAccountCode + "',"); } if (model.GLAccountDescription != null) { strSql1.Append("GLAccountDescription,"); strSql2.Append("'" + model.GLAccountDescription + "',"); } if (model.InternalOrder != null) { strSql1.Append("InternalOrder,"); strSql2.Append("'" + model.InternalOrder + "',"); } if (model.Headtext != null) { strSql1.Append("Headtext,"); strSql2.Append("'" + model.Headtext + "',"); } if (model.Reasonname != null) { strSql1.Append("Reasonname,"); strSql2.Append("'" + model.Reasonname + "',"); } if (model.Creater != null) { strSql1.Append("Creater,"); strSql2.Append("'" + model.Creater + "',"); } if (model.CreateDate != null) { strSql1.Append("CreateDate,"); strSql2.Append("'" + model.CreateDate + "',"); } strSql.Append("insert into _PurchaseSet("); strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); strSql.Append(")"); strSql.Append(";select @@IDENTITY"); return(strSql.ToString()); }
private void btnSave_Click(object sender, EventArgs e) { string sErr = ""; int iCount = 0; try { gridView1.PostEditor(); SqlConnection conn = new SqlConnection(Conn); conn.Open(); SqlTransaction tran = conn.BeginTransaction(); try { string sSQL = "select getdate()"; DateTime dNow = BaseFunction.ReturnDate(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]); DateTime dNowDate = BaseFunction.ReturnDate(dNow.ToString("yyyy-MM-dd")); for (int i = 0; i < gridView1.RowCount; i++) { int iID = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridColiID)); string iState = gridView1.GetRowCellValue(i, gridColiState).ToString().Trim(); if (iState == "") { continue; } Model._PurchaseSet model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._PurchaseSet(); model.ReasonCode = gridView1.GetRowCellValue(i, gridColReasonCode).ToString().Trim(); model.CostCenter = gridView1.GetRowCellValue(i, gridColCostCenter).ToString().Trim(); model.Description = gridView1.GetRowCellValue(i, gridColDescription).ToString().Trim(); model.CostCentreDescription = gridView1.GetRowCellValue(i, gridColCostCentreDescription).ToString().Trim(); model.GLAccountDescription = gridView1.GetRowCellValue(i, gridColGLAccountDescription).ToString().Trim(); model.GLAccountCode = gridView1.GetRowCellValue(i, gridColGLAccountCode).ToString().Trim(); model.iID = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridColiID)); model.Headtext = gridView1.GetRowCellValue(i, gridColHeadtext).ToString().Trim(); model.Reasonname = gridView1.GetRowCellValue(i, gridColReasonname).ToString().Trim(); model.InternalOrder = gridView1.GetRowCellValue(i, gridColInternalOrder).ToString().Trim(); if (iID == 0) { model.Creater = sUserID; model.CreateDate = dNowDate; DAL._PurchaseSet dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._PurchaseSet(); sSQL = dal.Add(model); iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } else { model.Creater = gridView1.GetRowCellValue(i, gridColCreateUid).ToString().Trim(); model.CreateDate = BaseFunction.ReturnDate(gridView1.GetRowCellValue(i, gridColCreateDate)); DAL._PurchaseSet dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._PurchaseSet(); sSQL = dal.Update(model); iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } } if (sErr != "") { throw new Exception(sErr); } if (iCount > 0) { tran.Commit(); MessageBox.Show("OK"); GetGrid(); } else { throw new Exception("no data"); } } catch (Exception ee) { tran.Rollback(); throw new Exception(ee.Message); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }
/// <summary> /// 更新一条数据 /// </summary> public string Update(UFIDA.U8.UAP.CustomApp.ControlForm.Model._PurchaseSet model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update _PurchaseSet set "); if (model.Description != null) { strSql.Append("Description='" + model.Description + "',"); } else { strSql.Append("Description= null ,"); } if (model.CostCenter != null) { strSql.Append("CostCenter='" + model.CostCenter + "',"); } else { strSql.Append("CostCenter= null ,"); } if (model.CostCentreDescription != null) { strSql.Append("CostCentreDescription='" + model.CostCentreDescription + "',"); } else { strSql.Append("CostCentreDescription= null ,"); } if (model.GLAccountCode != null) { strSql.Append("GLAccountCode='" + model.GLAccountCode + "',"); } else { strSql.Append("GLAccountCode= null ,"); } if (model.GLAccountDescription != null) { strSql.Append("GLAccountDescription='" + model.GLAccountDescription + "',"); } else { strSql.Append("GLAccountDescription= null ,"); } if (model.InternalOrder != null) { strSql.Append("InternalOrder='" + model.InternalOrder + "',"); } else { strSql.Append("InternalOrder= null ,"); } if (model.Headtext != null) { strSql.Append("Headtext='" + model.Headtext + "',"); } else { strSql.Append("Headtext= null ,"); } if (model.Reasonname != null) { strSql.Append("Reasonname='" + model.Reasonname + "',"); } else { strSql.Append("Reasonname= null ,"); } if (model.Creater != null) { strSql.Append("Creater='" + model.Creater + "',"); } else { strSql.Append("Creater= null ,"); } if (model.CreateDate != null) { strSql.Append("CreateDate='" + model.CreateDate + "',"); } else { strSql.Append("CreateDate= null ,"); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where iID=" + model.iID + ""); return(strSql.ToString()); }