/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(BArriveBillData model) { StringBuilder strSql = new StringBuilder(); strSql.Append("set nocount on; "); strSql.Append("insert into BArriveBill("); strSql.Append(@"billNo,custNo,arriveDt,isrtEmpId,isrtDt,updtEmpId,updtDt,commitEmpId,commitDt,instantState)"); strSql.Append(" values ("); strSql.Append(@"@billNo,@custNo,@arriveDt,@isrtEmpId,@isrtDt,@updtEmpId,@updtDt,@commitEmpId,@commitDt,@instantState)"); strSql.Append("; select @@identity; set nocount off; "); SqlParameter[] parameters = { new SqlParameter("@billNo", SqlDbType.VarChar,20), new SqlParameter("@custNo", SqlDbType.VarChar,20), new SqlParameter("@arriveDt", SqlDbType.DateTime), new SqlParameter("@isrtEmpId", SqlDbType.Int), new SqlParameter("@isrtDt", SqlDbType.DateTime), new SqlParameter("@updtEmpId", SqlDbType.Int), new SqlParameter("@updtDt", SqlDbType.DateTime), new SqlParameter("@commitEmpId", SqlDbType.Int), new SqlParameter("@commitDt", SqlDbType.DateTime), new SqlParameter("@instantState", SqlDbType.NVarChar,20) }; parameters[0].Value = model.billNo; parameters[1].Value = model.custNo; parameters[2].Value = model.arriveDt == string.Empty ? null : model.arriveDt; parameters[3].Value = model.isrtEmpId; parameters[4].Value = model.isrtDt == string.Empty ? null : model.isrtDt; parameters[5].Value = model.updtEmpId; parameters[6].Value = model.updtDt == string.Empty ? null : model.updtDt; parameters[7].Value = model.commitEmpId; parameters[8].Value = model.commitDt == string.Empty ? null : model.commitDt; parameters[9].Value = model.instantState; int id = 0; try { object ret = SqlHelper.ExecuteScalar(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ret != null && ret != DBNull.Value) { id = Convert.ToInt32(ret); } } catch (Exception ex) { throw ex; } return id; }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(BArriveBillData model) { bool ret = false; StringBuilder strSql = new StringBuilder(); strSql.Append("update BArriveBill set "); strSql.Append("billNo=@billNo,"); strSql.Append("custNo=@custNo,"); strSql.Append("arriveDt=@arriveDt,"); strSql.Append("isrtEmpId=@isrtEmpId,"); strSql.Append("isrtDt=@isrtDt,"); strSql.Append("updtEmpId=@updtEmpId,"); strSql.Append("updtDt=@updtDt,"); strSql.Append("commitEmpId=@commitEmpId,"); strSql.Append("commitDt=@commitDt,"); strSql.Append("instantState=@instantState"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int), new SqlParameter("@billNo", SqlDbType.VarChar,20), new SqlParameter("@custNo", SqlDbType.VarChar,20), new SqlParameter("@arriveDt", SqlDbType.DateTime), new SqlParameter("@isrtEmpId", SqlDbType.Int), new SqlParameter("@isrtDt", SqlDbType.DateTime), new SqlParameter("@updtEmpId", SqlDbType.Int), new SqlParameter("@updtDt", SqlDbType.DateTime), new SqlParameter("@commitEmpId", SqlDbType.Int), new SqlParameter("@commitDt", SqlDbType.DateTime), new SqlParameter("@instantState", SqlDbType.NVarChar,20) }; parameters[0].Value = model.id; parameters[1].Value = model.billNo; parameters[2].Value = model.custNo; parameters[3].Value = model.arriveDt == string.Empty ? null : model.arriveDt; parameters[4].Value = model.isrtEmpId; parameters[5].Value = model.isrtDt == string.Empty ? null : model.isrtDt; parameters[6].Value = model.updtEmpId; parameters[7].Value = model.updtDt == string.Empty ? null : model.updtDt; parameters[8].Value = model.commitEmpId; parameters[9].Value = model.commitDt == string.Empty ? null : model.commitDt; parameters[10].Value = model.instantState; try { SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); ret = true; } catch (Exception ex) { throw ex; } return ret; }
//***************************************************************************** //do it later do it later do it later //***************************************************************************** /// <summary> /// 得到一个model /// </summary> /// <param name="id">主键值</param> /// <returns>model</returns> public BArriveBillData GetModel(string arrangeBillNo) { StringBuilder strSql = new StringBuilder(); strSql.Append(@"select id,billNo,custNo,arriveDt,isrtEmpId,isrtDt,updtEmpId,updtDt,commitEmpId,commitDt,instantState from BArriveBill"); strSql.Append(" where billNo = @billNo "); SqlParameter[] parameters = { new SqlParameter("@billNo", SqlDbType.VarChar,50) }; parameters[0].Value = arrangeBillNo; BArriveBillData model = new BArriveBillData(); DataSet ds = SqlHelper.ExecuteDataset(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { DataRow row = ds.Tables[0].Rows[0]; if (row["id"] != DBNull.Value) { model.id = Convert.ToInt32(row["id"]); } if (row["billNo"] != DBNull.Value) { model.billNo = Convert.ToString(row["billNo"]); } if (row["custNo"] != DBNull.Value) { model.custNo = Convert.ToString(row["custNo"]); } if (row["arriveDt"] != DBNull.Value) { model.arriveDt = Convert.ToString(row["arriveDt"]); } if (row["isrtEmpId"] != DBNull.Value) { model.isrtEmpId = Convert.ToInt32(row["isrtEmpId"]); } if (row["isrtDt"] != DBNull.Value) { model.isrtDt = Convert.ToString(row["isrtDt"]); } if (row["updtEmpId"] != DBNull.Value) { model.updtEmpId = Convert.ToInt32(row["updtEmpId"]); } if (row["updtDt"] != DBNull.Value) { model.updtDt = Convert.ToString(row["updtDt"]); } if (row["commitEmpId"] != DBNull.Value) { model.commitEmpId = Convert.ToInt32(row["commitEmpId"]); } if (row["commitDt"] != DBNull.Value) { model.commitDt = Convert.ToString(row["commitDt"]); } if (row["instantState"] != DBNull.Value) { model.instantState = Convert.ToString(row["instantState"]); } return model; } else { return null; } }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(BArriveBillData model) { return this.arriveBillDB.ModifyRecord(model); }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(BArriveBillData model) { return this.arriveBillDB.AddRecord(model); }
/// <summary> /// 更新一条"到货单"信息 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(BArriveBillData model) { bool ret = false; SqlTransaction trans = null; try { if (this.transaction == null) { trans = this.connection.BeginTransaction("TransModify"); this.arriveBillBB.Transaction = trans; this.errorDiaryBB.Transaction = trans; this.operatDiaryBB.Transaction = trans; } this.arriveBillBB.ModifyRecord(model); SOperatDiaryData operatDiaryData = new SOperatDiaryData(); operatDiaryData.empId = this.empId; operatDiaryData.functionId = ""; operatDiaryData.recordId = model.id.ToString(); operatDiaryData.operateContent = "到货单修改一条id为“" + model.id.ToString() + "”的记录"; this.operatDiaryBB.AddRecord(operatDiaryData); if (this.transaction == null) trans.Commit(); ret = true; } catch (Exception ex) { if (this.transaction == null) trans.Rollback("TransModify"); SErrorDiaryData errorDiaryData = new SErrorDiaryData(); errorDiaryData.empId = this.empId; errorDiaryData.functionId = ""; errorDiaryData.errorText = "到货单修改记录“" + model.id.ToString() + "”时报错:" + ex.Message; this.errorDiaryBB.AddRecord(errorDiaryData); throw ex; } finally { } return ret; }
/// <summary> /// 增加一条"到货单"信息 /// </summary> /// <param name="model">model</param> public int AddRecord(BArriveBillData model) { int id = 0; SqlTransaction trans = null; try { if (this.transaction == null) { trans = this.connection.BeginTransaction("TransAdd"); this.arriveBillBB.Transaction = trans; this.errorDiaryBB.Transaction = trans; this.operatDiaryBB.Transaction = trans; } id = this.arriveBillBB.AddRecord(model); SOperatDiaryData operatDiaryData = new SOperatDiaryData(); operatDiaryData.empId = this.empId; operatDiaryData.functionId = ""; operatDiaryData.recordId = id.ToString(); operatDiaryData.operateContent = "到货单增加一条id为“" + id.ToString() + "”的记录"; this.operatDiaryBB.AddRecord(operatDiaryData); if (this.transaction == null) trans.Commit(); } catch (Exception ex) { if (this.transaction == null) trans.Rollback("TransAdd"); SErrorDiaryData errorDiaryData = new SErrorDiaryData(); errorDiaryData.empId = this.empId; errorDiaryData.functionId = ""; errorDiaryData.errorText = "到货单增加记录时报错:" + ex.Message; this.errorDiaryBB.AddRecord(errorDiaryData); throw ex; } finally { } return id; }