private void InitData(int id) { EtNet_BLL.ProductManager proBLL = new EtNet_BLL.ProductManager(); EtNet_Models.Product proModel = proBLL.GetModel(id); txtBrief.Value = Server.UrlDecode(proModel.Brief); txtMark.Value = proModel.Remark; txtName.Value = proModel.ProdName; chkMain.Checked = proModel.FlagMain; EtNet_BLL.ProductTypeManager proType = new EtNet_BLL.ProductTypeManager(); txtType.Value = proType.GetModel(proModel.ProdTypeID).ProdTypeName; }
//添加项目 private bool AddProd(int id) { EtNet_BLL.ProductManager proBLL = new EtNet_BLL.ProductManager(); EtNet_Models.Product proModel = new EtNet_Models.Product(); proModel = proBLL.GetModel(id); proModel.Brief = hidHtml.Value; proModel.FlagMain = chkMain.Checked; proModel.ProdName = txtName.Value; proModel.Remark = txtMark.Value; try { return(proBLL.Update(proModel)); } catch { return(false); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(EtNet_Models.Product model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Product set "); strSql.Append("ProdNo=@ProdNo,"); strSql.Append("ProdName=@ProdName,"); strSql.Append("ProdTypeID=@ProdTypeID,"); strSql.Append("Brief=@Brief,"); strSql.Append("FlagMain=@FlagMain,"); strSql.Append("Remark=@Remark"); strSql.Append(" where ProdID=@ProdID"); SqlParameter[] parameters = { new SqlParameter("@ProdNo", SqlDbType.NVarChar, 30), new SqlParameter("@ProdName", SqlDbType.NVarChar, 50), new SqlParameter("@ProdTypeID", SqlDbType.Char, 32), new SqlParameter("@Brief", SqlDbType.NText), new SqlParameter("@FlagMain", SqlDbType.Bit, 1), new SqlParameter("@Remark", SqlDbType.NText), new SqlParameter("@ProdID", SqlDbType.Int, 4) }; parameters[0].Value = model.ProdNo; parameters[1].Value = model.ProdName; parameters[2].Value = model.ProdTypeID; parameters[3].Value = model.Brief; parameters[4].Value = model.FlagMain; parameters[5].Value = model.Remark; parameters[6].Value = model.ProdID; int rows = DBHelper.ExecuteCommand(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public object Add(EtNet_Models.Product model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Product("); strSql.Append("ProdNo,ProdName,ProdTypeID,Brief,FlagMain,Remark)"); strSql.Append(" values ("); strSql.Append("@ProdNo,@ProdName,@ProdTypeID,@Brief,@FlagMain,@Remark)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ProdNo", SqlDbType.NVarChar, 30), new SqlParameter("@ProdName", SqlDbType.NVarChar, 50), new SqlParameter("@ProdTypeID", SqlDbType.Char, 32), new SqlParameter("@Brief", SqlDbType.NText), new SqlParameter("@FlagMain", SqlDbType.Bit, 1), new SqlParameter("@Remark", SqlDbType.NText) }; parameters[0].Value = model.ProdNo; parameters[1].Value = model.ProdName; parameters[2].Value = model.ProdTypeID; parameters[3].Value = model.Brief; parameters[4].Value = model.FlagMain; parameters[5].Value = model.Remark; object obj = DBHelper.ExecuteScalar(strSql.ToString(), parameters); if (obj == null) { return(null); } else { return(obj); } }
/// <summary> /// 得到一个对象实体 /// </summary> public EtNet_Models.Product GetModel(int ProdID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ProdID,ProdNo,ProdName,ProdTypeID,Brief,PremiumRate,FlagMain,Remark,CommRate,ProcRate from Product "); strSql.Append(" where ProdID=@ProdID"); SqlParameter[] parameters = { new SqlParameter("@ProdID", SqlDbType.Int, 4) }; parameters[0].Value = ProdID; EtNet_Models.Product model = new EtNet_Models.Product(); DataTable ds = DBHelper.GetDataSet(strSql.ToString(), parameters); if (ds.Rows.Count > 0) { if (ds.Rows[0]["ProdID"] != null && ds.Rows[0]["ProdID"].ToString() != "") { model.ProdID = int.Parse(ds.Rows[0]["ProdID"].ToString()); } if (ds.Rows[0]["ProdNo"] != null && ds.Rows[0]["ProdNo"].ToString() != "") { model.ProdNo = ds.Rows[0]["ProdNo"].ToString(); } if (ds.Rows[0]["ProdName"] != null && ds.Rows[0]["ProdName"].ToString() != "") { model.ProdName = ds.Rows[0]["ProdName"].ToString(); } if (ds.Rows[0]["ProdTypeID"] != null && ds.Rows[0]["ProdTypeID"].ToString() != "") { model.ProdTypeID = ds.Rows[0]["ProdTypeID"].ToString(); } if (ds.Rows[0]["Brief"] != null && ds.Rows[0]["Brief"].ToString() != "") { model.Brief = ds.Rows[0]["Brief"].ToString(); } if (ds.Rows[0]["PremiumRate"] != null && ds.Rows[0]["PremiumRate"].ToString() != "") { model.PremiumRate = decimal.Parse(ds.Rows[0]["PremiumRate"].ToString()); } if (ds.Rows[0]["FlagMain"] != null && ds.Rows[0]["FlagMain"].ToString() != "") { if ((ds.Rows[0]["FlagMain"].ToString() == "1") || (ds.Rows[0]["FlagMain"].ToString().ToLower() == "true")) { model.FlagMain = true; } else { model.FlagMain = false; } } if (ds.Rows[0]["Remark"] != null && ds.Rows[0]["Remark"].ToString() != "") { model.Remark = ds.Rows[0]["Remark"].ToString(); } if (ds.Rows[0]["CommRate"] != null && ds.Rows[0]["CommRate"].ToString() != "") { model.CommRate = decimal.Parse(ds.Rows[0]["CommRate"].ToString()); } if (ds.Rows[0]["ProcRate"] != null && ds.Rows[0]["ProcRate"].ToString() != "") { model.ProcRate = decimal.Parse(ds.Rows[0]["ProcRate"].ToString()); } return(model); } else { return(null); } }