/// <summary> /// 更新一条数据 /// </summary> public string Update(UFIDA.U8.UAP.CustomApp.ControlForm.Model._ActionFCost model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update _ActionFCost set "); if (model.Labour != null) { strSql.Append("Labour=" + model.Labour + ","); } else { strSql.Append("Labour= null ,"); } if (model.Process != null) { strSql.Append("Process=" + model.Process + ","); } else { strSql.Append("Process= null ,"); } if (model.PlatingCost != null) { strSql.Append("PlatingCost=" + model.PlatingCost + ","); } else { strSql.Append("PlatingCost= null ,"); } if (model.Part != null) { strSql.Append("Part=" + model.Part + ","); } else { strSql.Append("Part= null ,"); } if (model.MANHOUR != null) { strSql.Append("MANHOUR=" + model.MANHOUR + ","); } else { strSql.Append("MANHOUR= null ,"); } if (model.cCusCode != null) { strSql.Append("cCusCode='" + model.cCusCode + "',"); } else { strSql.Append("cCusCode= null ,"); } if (model.cInvCode != null) { strSql.Append("cInvCode='" + model.cInvCode + "',"); } else { strSql.Append("cInvCode= null ,"); } if (model.ActionCode != null) { strSql.Append("ActionCode='" + model.ActionCode + "',"); } else { strSql.Append("ActionCode= null ,"); } if (model.dtmStart != null) { strSql.Append("dtmStart='" + model.dtmStart + "',"); } else { strSql.Append("dtmStart= null ,"); } if (model.dtmEnd != null && model.dtmEnd > Convert.ToDateTime("2000-01-01")) { strSql.Append("dtmEnd='" + model.dtmEnd + "',"); } else { strSql.Append("dtmEnd= null ,"); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where iID=" + model.iID + ""); return(strSql.ToString()); }
private void btnSave_Click(object sender, EventArgs e) { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } try { string sErr = ""; 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; } string sActionCode = gridView1.GetRowCellDisplayText(i, gridColActionCode).ToString().Trim(); string sInvCode = gridView1.GetRowCellDisplayText(i, gridColcInvCode).ToString().Trim(); string sCusCode = gridView1.GetRowCellDisplayText(i, gridColcCusCode).ToString().Trim(); if (sActionCode == "" && sInvCode == "" && sCusCode == "") { continue; } if (sActionCode != "" || sInvCode != "" || sCusCode != "") { if (sActionCode == "") { sErr = sErr + "Row " + (i + 1).ToString() + " Action Code err\n"; continue; } if (sInvCode == "") { sErr = sErr + "Row " + (i + 1).ToString() + " Part no err\n"; continue; } if (sCusCode == "") { sErr = sErr + "Row " + (i + 1).ToString() + " Customer Code err\n"; continue; } } Model._ActionFCost mod = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._ActionFCost(); mod.cCusCode = gridView1.GetRowCellValue(i, gridColcCusCode).ToString().Trim(); mod.cInvCode = sInvCode; mod.ActionCode = sActionCode; mod.MANHOUR = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColMANHOUR), 2); mod.Labour = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColLabour), 2); mod.Process = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColProcess), 2); mod.PlatingCost = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColPlatingCost), 2); mod.Part = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColPart), 2); mod.dtmStart = BaseFunction.ReturnDate(gridView1.GetRowCellValue(i, gridColdtmStart)); //if (mod.dtmStart < BaseFunction.ReturnDate(sLogDate)) //{ // sErr = sErr + "Row " + (i + 1).ToString() + " Start Date err\n"; // continue; //} mod.iID = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColiID)); string sSQL = ""; if (sStatus == "add") { try { //更新上一次的结束日期 sSQL = @" update _ActionFCost set dtmEnd = '{0}' where iID in ( select max(iID) from _ActionFCost where cCusCode = '{1}' and cInvCode = '{2}' and ActionCode = '{3}') "; sSQL = string.Format(sSQL, mod.dtmStart.AddDays(-1), mod.cCusCode, mod.cInvCode, mod.ActionCode); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); DAL._ActionFCost dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._ActionFCost(); sSQL = dal.Add(mod); iCou += DbHelperSQL.ExecuteSql(sSQL); } catch (Exception ee) { sErr = sErr + "Row " + (i + 1).ToString() + " " + ee.Message + " err\n"; continue; } } if (sStatus == "edit") { try { DAL._ActionFCost dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._ActionFCost(); sSQL = dal.Update(mod); iCou += DbHelperSQL.ExecuteSql(sSQL); } catch (Exception ee) { sErr = sErr + "Row " + (i + 1).ToString() + " " + ee.Message + " err\n"; continue; } } } if (sErr.Length > 0) { throw new Exception(sErr); } if (iCou > 0) { tran.Commit(); MessageBox.Show("OK"); GetGrid(); } } catch (Exception ee) { tran.Rollback(); throw new Exception(ee.Message); } } catch (Exception ee) { FrmMsgBox frm = new FrmMsgBox(); frm.richTextBox1.Text = ee.Message; frm.ShowDialog(); } }
/// <summary> /// 增加一条数据 /// </summary> public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model._ActionFCost 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.ActionCode != null) { strSql1.Append("ActionCode,"); strSql2.Append("'" + model.ActionCode + "',"); } if (model.MANHOUR != null) { strSql1.Append("MANHOUR,"); strSql2.Append("'" + model.MANHOUR + "',"); } if (model.Labour != null) { strSql1.Append("Labour,"); strSql2.Append("" + model.Labour + ","); } if (model.Process != null) { strSql1.Append("Process,"); strSql2.Append("" + model.Process + ","); } if (model.PlatingCost != null) { strSql1.Append("PlatingCost,"); strSql2.Append("" + model.PlatingCost + ","); } if (model.Part != null) { strSql1.Append("Part,"); strSql2.Append("" + model.Part + ","); } if (model.cInvCode != null) { strSql1.Append("cCusCode,"); strSql2.Append("'" + model.cCusCode + "',"); } if (model.dtmStart != null) { strSql1.Append("dtmStart,"); strSql2.Append("'" + model.dtmStart + "',"); } if (model.dtmEnd != null && model.dtmEnd > Convert.ToDateTime("2000-01-01")) { strSql1.Append("dtmEnd,"); strSql2.Append("'" + model.dtmEnd + "',"); } strSql.Append("insert into _ActionFCost("); 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()); }