/// <summary> /// 增加一条数据 /// </summary> public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model._SystemSet model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.cSTCode != null) { strSql1.Append("cSTCode,"); strSql2.Append("'" + model.cSTCode + "',"); } if (model.cWhCode != null) { strSql1.Append("cWhCode,"); strSql2.Append("'" + model.cWhCode + "',"); } if (model.cRdCode != null) { strSql1.Append("cRdCode,"); strSql2.Append("'" + model.cRdCode + "',"); } if (model.SAPCode != null) { strSql1.Append("SAPCode,"); strSql2.Append("'" + model.SAPCode + "',"); } if (model.SAPWorkCenter != null) { strSql1.Append("SAPWorkCenter,"); strSql2.Append("'" + model.SAPWorkCenter + "',"); } if (model.InternalOrder != null) { strSql1.Append("InternalOrder,"); strSql2.Append("'" + model.InternalOrder + "',"); } if (model.Remark != null) { strSql1.Append("Remark,"); strSql2.Append("'" + model.Remark + "',"); } if (model.CreaterUid != null) { strSql1.Append("CreaterUid,"); strSql2.Append("'" + model.CreaterUid + "',"); } if (model.CreaterDate != null) { strSql1.Append("CreaterDate,"); strSql2.Append("'" + model.CreaterDate + "',"); } strSql.Append("insert into _SystemSet("); 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) { string sErr = ""; int iCount = 0; try { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } 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++) { string sState = gridView1.GetRowCellValue(i, gridColiState).ToString().Trim(); if (sState == "") { continue; } UFIDA.U8.UAP.CustomApp.ControlForm.Model._SystemSet model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._SystemSet(); model.cSTCode = gridView1.GetRowCellValue(i, gridColcSTCode).ToString().Trim(); model.cWhCode = gridView1.GetRowCellValue(i, gridColcWhCode).ToString().Trim(); model.cRdCode = gridView1.GetRowCellValue(i, gridColcRdCode).ToString().Trim(); model.SAPCode = gridView1.GetRowCellValue(i, gridColSAPCode).ToString().Trim(); model.SAPWorkCenter = gridView1.GetRowCellValue(i, gridColSAPWorkCenter).ToString().Trim(); model.InternalOrder = gridView1.GetRowCellValue(i, gridColInternalOrder).ToString().Trim(); model.Remark = gridView1.GetRowCellValue(i, gridColRemark).ToString().Trim(); model.CreaterUid = sUserName; model.CreaterDate = dNowDate; UFIDA.U8.UAP.CustomApp.ControlForm.DAL._SystemSet dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._SystemSet(); sSQL = dal.Exists(model.cSTCode); bool b = DbHelperSQL.Exists(tran, sSQL); if (b) { sSQL = dal.Update(model); iCount = iCount + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } else { 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); } }
/// <summary> /// 更新一条数据 /// </summary> public string Update(UFIDA.U8.UAP.CustomApp.ControlForm.Model._SystemSet model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update _SystemSet set "); if (model.cWhCode != null) { strSql.Append("cWhCode='" + model.cWhCode + "',"); } else { strSql.Append("cWhCode= null ,"); } if (model.cRdCode != null) { strSql.Append("cRdCode='" + model.cRdCode + "',"); } else { strSql.Append("cRdCode= null ,"); } if (model.SAPCode != null) { strSql.Append("SAPCode='" + model.SAPCode + "',"); } else { strSql.Append("SAPCode= null ,"); } if (model.SAPWorkCenter != null) { strSql.Append("SAPWorkCenter='" + model.SAPWorkCenter + "',"); } else { strSql.Append("SAPWorkCenter= null ,"); } if (model.InternalOrder != null) { strSql.Append("InternalOrder='" + model.InternalOrder + "',"); } else { strSql.Append("InternalOrder= null ,"); } if (model.Remark != null) { strSql.Append("Remark='" + model.Remark + "',"); } else { strSql.Append("Remark= null ,"); } if (model.CreaterUid != null) { strSql.Append("CreaterUid='" + model.CreaterUid + "',"); } else { strSql.Append("CreaterUid= null ,"); } if (model.CreaterDate != null) { strSql.Append("CreaterDate='" + model.CreaterDate + "',"); } else { strSql.Append("CreaterDate= null ,"); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where cSTCode='" + model.cSTCode + "' "); return(strSql.ToString()); }