/// <summary> /// 增加一条数据 /// </summary> public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model._InvProcess model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.cInvCode != null) { strSql1.Append("cInvCode,"); strSql2.Append("'" + model.cInvCode + "',"); } if (model.ProcessRow != null) { strSql1.Append("ProcessRow,"); strSql2.Append("'" + model.ProcessRow + "',"); } if (model.ProcessNo != null) { strSql1.Append("ProcessNo,"); strSql2.Append("'" + model.ProcessNo + "',"); } if (model.Remark != null) { strSql1.Append("Remark,"); strSql2.Append("'" + model.Remark + "',"); } if (model.CreateUid != null) { strSql1.Append("CreateUid,"); strSql2.Append("'" + model.CreateUid + "',"); } if (model.CreateDate != null) { strSql1.Append("CreateDate,"); strSql2.Append("'" + model.CreateDate + "',"); } strSql.Append("insert into _InvProcess("); 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 sInvCode = btnTxtInvCode.Text.Trim(); if (sInvCode == "" || lookUpEditInvName.EditValue == null) { throw new Exception("Please set Item Code"); } 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")); sSQL = "delete [dbo].[_InvProcess] where [cInvCode] = '" + sInvCode + "' "; DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); for (int i = 0; i < gridView1.RowCount; i++) { if (gridView1.GetRowCellValue(i, gridColProcessNo).ToString().Trim() == "") { continue; } Model._InvProcess model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._InvProcess(); model.cInvCode = sInvCode; model.ProcessNo = gridView1.GetRowCellValue(i, gridColProcessNo).ToString().Trim(); if (model.ProcessNo == "") { sErr = sErr + "Row " + (i + 1).ToString() + " error Please set Porcess\n"; continue; } if (gridView1.GetRowCellValue(i, gridColProcessRow).ToString().Trim() == "") { sErr = sErr + "Row " + (i + 1).ToString() + " error Please set PorcessRow\n"; continue; } model.ProcessRow = gridView1.GetRowCellValue(i, gridColProcessRow).ToString().Trim(); model.Remark = gridView1.GetRowCellValue(i, gridColRemark).ToString().Trim(); model.CreateUid = sUserID; model.CreateDate = dNowDate; DAL._InvProcess dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._InvProcess(); sSQL = dal.Add(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); } }