public List <BrandProductInfo> GetList(string sqlWhere, params SqlParameter[] cmdParms) { string cmdText = @"select ProductId,BrandId from BrandProduct"; if (!string.IsNullOrEmpty(sqlWhere)) { cmdText += " where 1=1 " + sqlWhere; } List <BrandProductInfo> list = new List <BrandProductInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText, cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { BrandProductInfo model = new BrandProductInfo(); model.ProductId = reader.GetGuid(0); model.BrandId = reader.GetGuid(1); list.Add(model); } } } return(list); }
public List <BrandProductInfo> GetList() { string cmdText = @"select ProductId,BrandId from BrandProduct order by ProductId " ; List <BrandProductInfo> list = new List <BrandProductInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText)) { if (reader != null && reader.HasRows) { while (reader.Read()) { BrandProductInfo model = new BrandProductInfo(); model.ProductId = reader.GetGuid(0); model.BrandId = reader.GetGuid(1); list.Add(model); } } } return(list); }
public List <BrandProductInfo> GetList(int pageIndex, int pageSize, string sqlWhere, params SqlParameter[] cmdParms) { int startIndex = (pageIndex - 1) * pageSize + 1; int endIndex = pageIndex * pageSize; string cmdText = @"select * from(select row_number() over(order by ProductId) as RowNumber, ProductId,BrandId from BrandProduct" ; if (!string.IsNullOrEmpty(sqlWhere)) { cmdText += " where 1=1 " + sqlWhere; } cmdText += ")as objTable where RowNumber between " + startIndex + " and " + endIndex + " "; List <BrandProductInfo> list = new List <BrandProductInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText, cmdParms)) { if (reader != null && reader.HasRows) { while (reader.Read()) { BrandProductInfo model = new BrandProductInfo(); model.ProductId = reader.GetGuid(1); model.BrandId = reader.GetGuid(2); list.Add(model); } } } return(list); }
public BrandProductInfo GetModel(object ProductId) { BrandProductInfo model = null; string cmdText = @"select top 1 ProductId,BrandId from BrandProduct where ProductId = @ProductId " ; SqlParameter parm = new SqlParameter("@ProductId", SqlDbType.UniqueIdentifier); parm.Value = Guid.Parse(ProductId.ToString()); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText, parm)) { if (reader != null) { while (reader.Read()) { model = new BrandProductInfo(); model.ProductId = reader.GetGuid(0); model.BrandId = reader.GetGuid(1); } } } return(model); }
public int Update(BrandProductInfo model) { string cmdText = @"update BrandProduct set BrandId = @BrandId where ProductId = @ProductId" ; SqlParameter[] parms = { new SqlParameter("@ProductId", SqlDbType.UniqueIdentifier), new SqlParameter("@BrandId", SqlDbType.UniqueIdentifier) }; parms[0].Value = model.ProductId; parms[1].Value = model.BrandId; return(SqlHelper.ExecuteNonQuery(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText, parms)); }
public int Insert(BrandProductInfo model) { string cmdText = @"insert into BrandProduct (BrandId,ProductId) values (@BrandId,@ProductId) " ; SqlParameter[] parms = { new SqlParameter("@BrandId", SqlDbType.UniqueIdentifier), new SqlParameter("@ProductId", SqlDbType.UniqueIdentifier) }; parms[0].Value = model.BrandId; parms[1].Value = model.ProductId; return(SqlHelper.ExecuteNonQuery(SqlHelper.HnztcShopDbConnString, CommandType.Text, cmdText, parms)); }
private void SaveProduct(HttpContext context) { string Id = context.Request.Form["ctl00$cphMain$hId"].Trim(); string sProductName = context.Request.Form["ctl00$cphMain$txtProductName"].Trim(); string sSubTitle = context.Request.Form["ctl00$cphMain$txtSubTitle"].Trim(); decimal dOriginalPrice = 0; decimal dProductPrice = 0; float discount = 0; decimal.TryParse(context.Request.Form["ctl00$cphMain$txtOriginalPrice"].Trim(), out dOriginalPrice); decimal.TryParse(context.Request.Form["ctl00$cphMain$txtProductPrice"].Trim(), out dProductPrice); float.TryParse(context.Request.Form["ctl00$cphMain$txtDiscount"].Trim(), out discount); string sDiscountDescri = context.Request.Form["ctl00$cphMain$txtDiscountDescri"].Trim(); int stockNum = 0; int.TryParse(context.Request.Form["ctl00$cphMain$txtStockNum"].Trim(), out stockNum); string sProductPictureId = context.Request.Form["productPictureId"].Trim(); Guid productPictureId = Guid.Empty; Guid.TryParse(sProductPictureId, out productPictureId); string sCategoryId = context.Request.Form["categoryId"].Trim(); Guid categoryId = Guid.Empty; Guid.TryParse(sCategoryId, out categoryId); string sBrandId = context.Request.Form["brandId"].Trim(); Guid brandId = Guid.Empty; Guid.TryParse(sBrandId, out brandId); Guid customMenuId = Guid.Empty; Guid.TryParse(context.Request.Form["customMenuId"].Trim(), out customMenuId); string sOtherPicture = context.Request.Form["otherPic"].Trim(); string sSizeItem = context.Request.Form["sizeItem"].Trim(); string sSizePicture = context.Request.Form["sizePicture"].Trim(); string sPayOption = ""; string content = context.Request.Form["txtContent"].Trim(); content = HttpUtility.HtmlDecode(content); Guid gId = Guid.Empty; if (Id != "") { Guid.TryParse(Id, out gId); } ProductInfo model = new ProductInfo(); model.Id = gId; model.UserId = WebCommon.GetUserId(); model.LastUpdatedDate = DateTime.Now; model.ProductName = sProductName; model.SubTitle = sSubTitle; model.OriginalPrice = dOriginalPrice; model.ProductPrice = dProductPrice; model.Discount = discount; model.DiscountDescri = sDiscountDescri; model.ProductPictureId = productPictureId; model.StockNum = stockNum; model.CustomMenuId = customMenuId; Product bll = new Product(); ProductItem piBll = new ProductItem(); CategoryProduct cpBll = new CategoryProduct(); BrandProduct bpBll = new BrandProduct(); ProductItemInfo piModel = new ProductItemInfo(); piModel.OtherPicture = sOtherPicture; piModel.SizeItem = sSizeItem; piModel.SizePicture = sSizePicture; piModel.PayOption = sPayOption; piModel.CustomAttr = string.Empty; piModel.Descr = content; piModel.ProductId = gId; int effect = -1; if (!gId.Equals(Guid.Empty)) { bll.Update(model); piBll.Update(piModel); CategoryProductInfo cpModel = cpBll.GetModel(gId); BrandProductInfo bpModel = bpBll.GetModel(gId); #region 所属分类 if (!categoryId.Equals(Guid.Empty)) { if (cpModel == null) { cpModel = new CategoryProductInfo(); cpModel.ProductId = gId; cpModel.CategoryId = categoryId; cpBll.Insert(cpModel); } else { if (!cpModel.CategoryId.Equals(categoryId)) { cpModel.CategoryId = categoryId; cpBll.Update(cpModel); } } } else { if (cpModel != null) { cpBll.Delete(gId, cpModel.CategoryId); } } #endregion #region 所属品牌 if (!brandId.Equals(Guid.Empty)) { if (bpModel == null) { bpModel = new BrandProductInfo(); bpModel.ProductId = gId; bpModel.BrandId = brandId; bpBll.Insert(bpModel); } else { if (!bpModel.BrandId.Equals(brandId)) { bpModel.BrandId = brandId; bpBll.Update(bpModel); } } } else { if (bpModel != null) { bpBll.Delete(gId, bpModel.BrandId); } } #endregion effect = 1; } else { using (TransactionScope scope = new TransactionScope()) { Guid productId = bll.Insert(model); piModel.ProductId = productId; piBll.Insert(piModel); if (!categoryId.Equals(Guid.Empty)) { CategoryProductInfo cpModel = new CategoryProductInfo(); cpModel.CategoryId = categoryId; cpModel.ProductId = productId; cpBll.Insert(cpModel); } if (!brandId.Equals(Guid.Empty)) { BrandProductInfo bpModel = new BrandProductInfo(); bpModel.BrandId = brandId; bpModel.ProductId = productId; bpBll.Insert(bpModel); } effect = 1; scope.Complete(); } } if (effect != 1) { context.Response.Write("{\"success\": false,\"message\": \"操作失败,请正确输入\"}"); return; } context.Response.Write("{\"success\": true,\"message\": \"操作成功\"}"); }
/// <summary> /// 修改数据 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Update(BrandProductInfo model) { return(dal.Update(model)); }
/// <summary> /// 添加数据到数据库 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Insert(BrandProductInfo model) { return(dal.Insert(model)); }