/// <summary> /// 更新一条数据 /// </summary> public string Update(UFIDA.U8.UAP.CustomApp.ControlForm.Model._AQLLevelMap model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update _AQLLevelMap set "); if (model.Accept != null) { strSql.Append("Accept=" + model.Accept + ","); } else { strSql.Append("Accept= null ,"); } if (model.Reject != null) { strSql.Append("Reject=" + model.Reject + ","); } else { strSql.Append("Reject= null ,"); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where CodeLetter='" + model.CodeLetter + "' and AQLLevel=" + model.AQLLevel + " "); return(strSql.ToString()); }
/// <summary> /// 增加一条数据 /// </summary> public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model._AQLLevelMap model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.CodeLetter != null) { strSql1.Append("CodeLetter,"); strSql2.Append("'" + model.CodeLetter + "',"); } if (model.AQLLevel != null) { strSql1.Append("AQLLevel,"); strSql2.Append("" + model.AQLLevel + ","); } if (model.Accept != null) { strSql1.Append("Accept,"); strSql2.Append("" + model.Accept + ","); } if (model.Reject != null) { strSql1.Append("Reject,"); strSql2.Append("" + model.Reject + ","); } strSql.Append("insert into _AQLLevelMap("); strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); strSql.Append(")"); 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; } Model._AQLLevelMap mod = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._AQLLevelMap(); mod.CodeLetter = gridView1.GetRowCellValue(i, gridColCodeLetter).ToString().Trim(); mod.AQLLevel = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColAQLLevel).ToString().Trim()); mod.Accept = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColAccept)); mod.Reject = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColReject)); mod.iID = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColiID)); string sSQL = ""; if (sStatus == "add") { DAL._AQLLevelMap dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._AQLLevelMap(); sSQL = dal.Add(mod); iCou += DbHelperSQL.ExecuteSql(sSQL); } if (sStatus == "edit") { DAL._AQLLevelMap dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._AQLLevelMap(); sSQL = dal.Update(mod); iCou += DbHelperSQL.ExecuteSql(sSQL); } } if (iCou > 0) { tran.Commit(); MessageBox.Show("OK"); } SetBtnEnable(true); } catch (Exception ee) { tran.Rollback(); throw new Exception(ee.Message); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }