/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(BCheckDetailData model) { StringBuilder strSql = new StringBuilder(); strSql.Append("set nocount on; "); strSql.Append("insert into BCheckDetail("); strSql.Append(@"checkBillId,checkDetailId,openBoxNum,checkNum)"); strSql.Append(" values ("); strSql.Append(@"@checkBillId,@checkDetailId,@openBoxNum,@checkNum)"); strSql.Append("; select @@identity; set nocount off; "); SqlParameter[] parameters = { new SqlParameter("@checkBillId", SqlDbType.Int), new SqlParameter("@checkDetailId", SqlDbType.Int), new SqlParameter("@openBoxNum", SqlDbType.Float), new SqlParameter("@checkNum", SqlDbType.Float) }; parameters[0].Value = model.checkBillId; parameters[1].Value = model.checkDetailId; parameters[2].Value = model.openBoxNum; parameters[3].Value = model.checkNum; 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(BCheckDetailData model) { return this.checkDetailDB.ModifyRecord(model); }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">model</param> public int AddRecord(BCheckDetailData model) { return this.checkDetailDB.AddRecord(model); }
/// <summary> /// 保存工作,返回明细表基本信息 /// </summary> /// <returns></returns> private List<BCheckDetailData> SetDetailApplyBillModel() { BCheckDetailBB checkDetailBB = new BCheckDetailBB(); try { List<BCheckDetailData> list = new List<BCheckDetailData>(); foreach (DataRow dr in this.DtResult.Rows) { BCheckDetailData model = new BCheckDetailData(); int detailId = Convert.ToInt32(dr["BCheckDetailID"]);//表BCheckDetail的ID //修改行 if (detailId > 0) { model = checkDetailBB.GetModel(detailId); } //删除已有数据 if (detailId > 0 && dr["isdel"].ToString() == "1") { model.checkBillId = -1; } //赋值,将新增的和修改的明细项,增加到list if ((detailId == 0 && dr["isdel"].ToString() == "0") || detailId > 0) { model.id = detailId;//检测单明细ID if (HS.Function.CommFunction.IsInt(dr["checkDetailId"].ToString())) { model.checkDetailId = Convert.ToInt32(dr["checkDetailId"]);//检测标准ID } //开箱数量 if (dr["openBoxNum"] != DBNull.Value) { model.openBoxNum = Convert.ToDouble(dr["openBoxNum"]); } else { model.openBoxNum = 0; } //检测数量 if (dr["checkNum"] != DBNull.Value) { model.checkNum = Convert.ToDouble(dr["checkNum"]); } else { model.checkNum = 0; } list.Add(model); } } return list; } finally { checkDetailBB.Dispose(); } }
/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">model</param> public bool ModifyRecord(BCheckDetailData model) { bool ret = false; StringBuilder strSql = new StringBuilder(); strSql.Append("update BCheckDetail set "); strSql.Append("checkBillId=@checkBillId,"); strSql.Append("checkDetailId=@checkDetailId,"); strSql.Append("openBoxNum=@openBoxNum,"); strSql.Append("checkNum=@checkNum"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int), new SqlParameter("@checkBillId", SqlDbType.Int), new SqlParameter("@checkDetailId", SqlDbType.Int), new SqlParameter("@openBoxNum", SqlDbType.Float), new SqlParameter("@checkNum", SqlDbType.Float) }; parameters[0].Value = model.id; parameters[1].Value = model.checkBillId; parameters[2].Value = model.checkDetailId; parameters[3].Value = model.openBoxNum; parameters[4].Value = model.checkNum; try { SqlHelper.ExecuteNonQuery(this.connection, this.transaction, CommandType.Text, strSql.ToString(), parameters); ret = true; } catch (Exception ex) { throw ex; } return ret; }
/// <summary> /// 得到一个model /// </summary> /// <param name="id">主键值</param> /// <returns>model</returns> public BCheckDetailData GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append(@"select id,checkBillId,checkDetailId,openBoxNum,checkNum from BCheckDetail"); strSql.Append(" where id = @id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int) }; parameters[0].Value = id; BCheckDetailData model = new BCheckDetailData(); 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["checkBillId"] != DBNull.Value) { model.checkBillId = Convert.ToInt32(row["checkBillId"]); } if (row["checkDetailId"] != DBNull.Value) { model.checkDetailId = Convert.ToInt32(row["checkDetailId"]); } if (row["openBoxNum"] != DBNull.Value) { model.openBoxNum = Convert.ToDouble(row["openBoxNum"]); } if (row["checkNum"] != DBNull.Value) { model.checkNum = Convert.ToDouble(row["checkNum"]); } return model; } else { return null; } }