/// <summary> /// 更新一条数据 /// </summary> public string Update(UFIDA.U8.UAP.CustomApp.ControlForm.Model._DefectForOQC model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update _DefectForOQC set "); if (model.cInvCode != null) { strSql.Append("cInvCode='" + model.cInvCode + "',"); } else { strSql.Append("cInvCode= null ,"); } if (model.cWhCode != null) { strSql.Append("cWhCode='" + model.cWhCode + "',"); } else { strSql.Append("cWhCode= null ,"); } if (model.DefectCode != null) { strSql.Append("DefectCode='" + model.DefectCode + "',"); } else { strSql.Append("DefectCode= null ,"); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where iID=" + model.iID + ""); return(strSql.ToString()); }
/// <summary> /// 增加一条数据 /// </summary> public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model._DefectForOQC 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.DefectCode != null) { strSql1.Append("DefectCode,"); strSql2.Append("'" + model.DefectCode + "',"); } if (model.cWhCode != null) { strSql1.Append("cWhCode,"); strSql2.Append("'" + model.cWhCode + "',"); } strSql.Append("insert into _DefectForOQC("); 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) { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } try { int iCou = 0; SqlConnection conn = new SqlConnection(Conn); conn.Open(); SqlTransaction tran = conn.BeginTransaction(); try { for (int i = 0; i < gridView1.RowCount; i++) { string sStatus = gridView1.GetRowCellValue(i, gridColsStatus).ToString().Trim().ToLower(); if (sStatus == "") { continue; } if (gridView1.GetRowCellValue(i, gridColcInvCode).ToString().Trim() == "") { continue; } if (gridView1.GetRowCellValue(i, gridColDefectCode).ToString().Trim() == "") { continue; } Model._DefectForOQC mod = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._DefectForOQC(); mod.DefectCode = gridView1.GetRowCellValue(i, gridColDefectCode).ToString().Trim(); mod.cInvCode = gridView1.GetRowCellValue(i, gridColcInvCode).ToString().Trim(); mod.iID = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridColiID)); mod.cWhCode = gridView1.GetRowCellValue(i, gridColcWhCode).ToString().Trim(); string sSQL = ""; if (sStatus == "add") { DAL._DefectForOQC dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._DefectForOQC(); sSQL = dal.Add(mod); iCou += DbHelperSQL.ExecuteSql(sSQL); } if (sStatus == "edit") { DAL._DefectForOQC dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._DefectForOQC(); sSQL = dal.Update(mod); iCou += DbHelperSQL.ExecuteSql(sSQL); } } if (iCou > 0) { tran.Commit(); MessageBox.Show("OK"); GetGrid(); } } catch (Exception ee) { tran.Rollback(); throw new Exception(ee.Message); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }