/// <summary> /// 增加一条数据 /// </summary> public string Add(UFIDA.U8.UAP.CustomApp.ControlForm.Model._GiveBacks model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.GUIDHead != null) { strSql1.Append("GUIDHead,"); strSql2.Append("N'" + model.GUIDHead.ToString() + "',"); } if (model.cCode != null) { strSql1.Append("cCode,"); strSql2.Append("N'" + model.cCode + "',"); } if (model.SerialNo != null) { strSql1.Append("SerialNo,"); strSql2.Append("N'" + model.SerialNo + "',"); } if (model.Remark != null) { strSql1.Append("Remark,"); strSql2.Append("N'" + model.Remark + "',"); } if (model.RequisitionsiID != null) { strSql1.Append("RequisitionsiID,"); strSql2.Append("" + model.RequisitionsiID + ","); } if (model.Times != null) { strSql1.Append("Times,"); strSql2.Append("" + model.Times + ","); } strSql.Append("insert into _GiveBacks("); 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()); }
/// <summary> /// 更新一条数据 /// </summary> public string Update(UFIDA.U8.UAP.CustomApp.ControlForm.Model._GiveBacks model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update _GiveBacks set "); if (model.GUIDHead != null) { strSql.Append("GUIDHead=N'" + model.GUIDHead + "',"); } else { strSql.Append("GUIDHead= null ,"); } if (model.Remark != null) { strSql.Append("Remark=N'" + model.Remark + "',"); } else { strSql.Append("Remark= null ,"); } if (model.RequisitionsiID != null) { strSql.Append("RequisitionsiID=" + model.RequisitionsiID + ","); } else { strSql.Append("RequisitionsiID= null ,"); } if (model.Times != null) { strSql.Append("Times=" + model.Times + ","); } else { strSql.Append("Times= null ,"); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where iID=" + model.iID + ""); return(strSql.ToString()); }
private void btnOK_Click(object sender, EventArgs e) { try { if (!clsUserRight.chkRight(sUserID, 6010)) { throw new Exception("没有权限"); } if (gridView1.RowCount == 0) { throw new Exception("请输入表体"); } string sErr = ""; try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } int iCou = 0; SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString); conn.Open(); SqlTransaction tran = conn.BeginTransaction(); try { string sSerCode = txtCode.Text.Trim(); Model._GiveBack model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._GiveBack(); string sState = ""; string sSQL = "select * from _GiveBack where cCode = N'" + txtCode.Text.Trim() + "'"; DataTable dtTemp = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dtTemp != null && dtTemp.Rows.Count > 0) { if (dtTemp.Rows[0]["AuditUserName"].ToString().Trim() != "") { throw new Exception("单据已经审核,不能保存"); } } //新增 if (txtCode.Text.Trim() == "") { sState = "add"; model.CreateUserName = sUserName; model.CreateDate = DateTime.Today; long iCode = 0; sSQL = "select max(cCode) as cCode from [_GiveBack] where cCode like '111111%'"; sSQL = sSQL.Replace("111111", dtmCode.DateTime.ToString("yyMMdd")); DataTable dtCode = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dtCode == null && dtCode.Rows.Count == 0) { iCode = 1; } else { string s = dtCode.Rows[0]["cCode"].ToString().Trim(); if (s.Length > 6) { iCode = BaseFunction.ReturnLong(s.Substring(6)); } else { iCode = BaseFunction.ReturnLong(s); } iCode += 1; } string sCode = iCode.ToString().Trim(); while (sCode.Length < 4) { sCode = "0" + sCode; } sCode = dtmCode.DateTime.ToString("yyMMdd") + sCode; model.cCode = sCode; model.dDate = dtmCode.DateTime; if (lookUpEditPerson.EditValue != null) { model.Person = lookUpEditPerson.EditValue.ToString().Trim(); } if (lookUpEditDep.EditValue != null) { model.DepCode = lookUpEditDep.EditValue.ToString().Trim(); } model.Remark = txtRemark.Text.Trim(); model.CreateUserName = sUserName; model.CreateDate = DateTime.Now; DAL._GiveBack dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._GiveBack(); sSQL = dal.Add(model); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } else { sState = "edit"; model.cCode = txtCode.Text.Trim(); model.dDate = dtmCode.DateTime; model.Person = lookUpEditPerson.EditValue.ToString().Trim(); model.DepCode = lookUpEditDep.EditValue.ToString().Trim(); model.Remark = txtRemark.Text.Trim(); model.CreateUserName = txtCreateUserName.Text.Trim(); model.CreateDate = dtmCreate.DateTime; DAL._GiveBack dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._GiveBack(); sSQL = dal.Update(model); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } sSQL = "delete _GiveBacks where cCode = N'" + model.cCode + "'"; DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); for (int i = 0; i < gridView1.RowCount; i++) { if (gridView1.GetRowCellValue(i, gridColSerialNo).ToString().Trim() != "") { Model._GiveBacks models = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._GiveBacks(); models.cCode = model.cCode; models.SerialNo = gridView1.GetRowCellValue(i, gridColSerialNo).ToString().Trim(); models.Remark = gridView1.GetRowCellValue(i, gridColRemark).ToString().Trim(); models.RequisitionsiID = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridColRequisitionsiID)); sSQL = @" select * from _FrockClamp where SerialNo = N'111111' "; sSQL = sSQL.Replace("111111", models.SerialNo); DataTable dtTemp2 = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; long lTimes = BaseFunction.ReturnLong(dtTemp2.Rows[0]["Times"]); if (lTimes > 0) { long lTimesNow = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColTimes)); if (lTimesNow <= 0) { sErr = sErr + "行" + (i + 1).ToString() + "请输入使用次数"; continue; } models.Times = lTimesNow; } DAL._GiveBacks dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._GiveBacks(); sSQL = dals.Add(models); iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = "select iState from _FrockClamp where SerialNo = N'111111'"; sSQL = sSQL.Replace("111111", gridView1.GetRowCellValue(i, gridColSerialNo).ToString().Trim()); dtTemp = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dtTemp != null && BaseFunction.ReturnInt(dtTemp.Rows[0]["iState"]) == 2) { sSQL = "update _FrockClamp set iState = 1 where SerialNo = N'111111'"; sSQL = sSQL.Replace("111111", gridView1.GetRowCellValue(i, gridColSerialNo).ToString().Trim()); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } else { sErr = sErr + "行" + (i + 1).ToString() + "工装不是可用状态\n"; continue; } } } if (sErr.Length > 0) { throw new Exception(sErr); } if (iCou > 0) { tran.Commit(); MessageBox.Show("OK\n"); this.DialogResult = DialogResult.OK; } else { throw new Exception("no data"); } } catch (Exception ee) { tran.Rollback(); throw new Exception(ee.Message); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }