public ActionResult DeletePackage() { if (!AppData.IsManagerLogin) { return(Json(new { success = false, msg = "您未登录后台或会话已过期" })); } if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 903)) { return(Json(new { success = false, msg = "您没有执行该操作的权限" })); } Validation vld = new Validation(); int packageID = vld.GetInt("id"); PackageBLL packageBLL = new PackageBLL(); PackageObj packageObj = packageBLL.GetPackageByID(packageID); if (packageObj == null) { return(Json(new { success = false, msg = "该套餐不存在" })); } packageBLL.DeletePackage(packageID); return(Json(new { success = true })); }
public ActionResult Package(int id) { PackageBLL packageBLL = new PackageBLL(); ViewBag.allCates = packageBLL.GetPackageCates(); PackageObj packageObj = packageBLL.GetPackageByID(id); ViewBag.package = packageObj; return(View()); }
public void AddPackage(PackageObj packageObj) { using (helper = new SqlHelper()) { helper.BeginTran(); var id = helper.AddOutputParameter("@PackageID"); helper.AddIntParameter("@CategoryID", packageObj.CategoryID); helper.AddStringParameter("@PackageName", 500, packageObj.PackageName); helper.AddStringParameter("@Code", 100, packageObj.Code); helper.AddIntParameter("@SaleNum", packageObj.SaleNum); helper.AddTextParameter("@Memo", packageObj.Memo); helper.AddTextParameter("@Intro", packageObj.Intro); helper.AddStringParameter("@Material", 200, packageObj.Material); helper.AddIntParameter("@BuildingID", packageObj.BuildingID); helper.ExecuteNonQuery("insert into Package (CategoryID,PackageName,Code,SaleNum,Memo,Intro,Material,BuildingID) values (@CategoryID,@PackageName,@Code,@SaleNum,@Memo,@Intro,@Material,@BuildingID) select @PackageID=@@IDENTITY", CommandType.Text); packageObj.PackageID = (int)id.Value; if (packageObj.Pictures != null) { PackagePictureObj productPicture; for (int i = 0; i < packageObj.Pictures.Count; i++) { helper.ClearParameters(); productPicture = packageObj.Pictures[i]; helper.AddIntParameter("@PictureID", productPicture.PictureID); helper.AddIntParameter("@PackageID", packageObj.PackageID); helper.ExecuteNonQuery("update PackagePictures set PackageID=@PackageID where PictureID=@PictureID", CommandType.Text); } } for (int i = 0; i < packageObj.Categories.Count; i++) { helper.ClearParameters(); helper.AddIntParameter("@PackageID", packageObj.PackageID); helper.AddIntParameter("@CategoryID", packageObj.Categories[i]); helper.ExecuteNonQuery("insert into LPackageCate (PackageID,CategoryID) values (@PackageID,@CategoryID)", CommandType.Text); } helper.CommitTran(); } }
public void ModifyPackage(PackageObj packageObj) { using (helper = new SqlHelper()) { helper.BeginTran(); helper.AddIntParameter("@PackageID", packageObj.PackageID); helper.AddIntParameter("@CategoryID", packageObj.CategoryID); helper.AddStringParameter("@PackageName", 500, packageObj.PackageName); helper.AddStringParameter("@Code", 100, packageObj.Code); helper.AddIntParameter("@SaleNum", packageObj.SaleNum); helper.AddTextParameter("@Memo", packageObj.Memo); helper.AddTextParameter("@Intro", packageObj.Intro); helper.AddStringParameter("@Material", 200, packageObj.Material); helper.AddIntParameter("@BuildingID", packageObj.BuildingID); helper.ExecuteNonQuery("update Package set CategoryID=@CategoryID,PackageName=@PackageName,Code=@Code,SaleNum=@SaleNum,Memo=@Memo,Intro=@Intro,Material=@Material,BuildingID=@BuildingID where PackageID=@PackageID", CommandType.Text); if (packageObj.Pictures != null) { PackagePictureObj picture; for (int i = 0; i < packageObj.Pictures.Count; i++) { helper.ClearParameters(); picture = packageObj.Pictures[i]; helper.AddIntParameter("@PictureID", picture.PictureID); helper.AddIntParameter("@PackageID", packageObj.PackageID); helper.ExecuteNonQuery("update PackagePictures set PackageID=@PackageID where PictureID=@PictureID", CommandType.Text); } } helper.ExecuteNonQuery("delete from LPackageCate where PackageID=@PackageID", CommandType.Text); for (int i = 0; i < packageObj.Categories.Count; i++) { helper.ClearParameters(); helper.AddIntParameter("@PackageID", packageObj.PackageID); helper.AddIntParameter("@CategoryID", packageObj.Categories[i]); helper.ExecuteNonQuery("insert into LPackageCate (PackageID,CategoryID) values (@PackageID,@CategoryID)", CommandType.Text); } helper.CommitTran(); } }
public PackageObj GetPackageByID(int packageID) { using (helper = new SqlHelper()) { helper.AddIntParameter("@PackageID", packageID); PackageObj packageObj; SqlDataReader dr; using (dr = helper.ExecuteReader("select CategoryID,PackageName,Code,SaleNum,Memo,Intro,Material,a.BuildingID,PackageBuilding.RegionID,Region.CityID,City.ProvinceID from Package a left join PackageBuilding on a.BuildingID=PackageBuilding.BuildingID left join Region on PackageBuilding.RegionID=Region.RegionID left join City on City.CityID=Region.CityID left join Province on City.ProvinceID=Province.ProvinceID where PackageID=@PackageID", CommandType.Text)) { if (dr.HasRows && dr.Read()) { packageObj = new PackageObj(); packageObj.PackageID = packageID; packageObj.CategoryID = dr[0] == DBNull.Value ? 0 : (int)dr[0]; packageObj.PackageName = dr[1] == DBNull.Value ? null : (string)dr[1]; packageObj.Code = dr[2] == DBNull.Value ? null : (string)dr[2]; packageObj.SaleNum = dr[3] == DBNull.Value ? 0 : (int)dr[3]; packageObj.Memo = dr[4] == DBNull.Value ? null : (string)dr[4]; packageObj.Intro = dr[5] == DBNull.Value ? null : (string)dr[5]; packageObj.Material = dr[6] == DBNull.Value ? null : (string)dr[6]; packageObj.BuildingID = dr[7] == DBNull.Value ? 0 : (int)dr[7]; packageObj.RegionID = dr[8] == DBNull.Value ? 0 : (int)dr[8]; packageObj.CityID = dr[9] == DBNull.Value ? 0 : (int)dr[9]; packageObj.ProvinceID = dr[10] == DBNull.Value ? 0 : (int)dr[10]; } else { packageObj = null; } } if (packageObj != null) { using (dr = helper.ExecuteReader("select PictureID,PackageID,SavePath,Url,PictureDesc from PackagePictures where PackageID=@PackageID", CommandType.Text)) { if (dr.HasRows) { PackagePictureObj picture; packageObj.Pictures = new List <PackagePictureObj>(); while (dr.Read()) { picture = new PackagePictureObj(); picture.PictureID = (int)dr[0]; picture.PackageID = (int)dr[1]; picture.SavePath = dr[2] == DBNull.Value ? null : (string)dr[2]; picture.Url = dr[3] == DBNull.Value ? null : (string)dr[3]; picture.PictureDesc = dr[4] == DBNull.Value ? null : (string)dr[4]; packageObj.Pictures.Add(picture); } } } } using (dr = helper.ExecuteReader("select CategoryID from LPackageCate where PackageID=@PackageID", CommandType.Text)) { if (dr.HasRows) { packageObj.Categories = new List <int>(); while (dr.Read()) { packageObj.Categories.Add((int)dr[0]); } } } return(packageObj); } }
public void ModifyPackage(PackageObj packageObj) { dal.ModifyPackage(packageObj); }
public void AddPackage(PackageObj packageObj) { dal.AddPackage(packageObj); }
public ActionResult ModifyPackage() { if (Request.HttpMethod == "POST") { if (!AppData.IsManagerLogin) { return(Json(new { success = false, msg = "您未登录后台或会话已过期" })); } if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 902)) { return(Json(new { success = false, msg = "您没有执行该操作的权限" })); } Validation vld = new Validation(); int packageID = vld.GetInt("id"); PackageBLL packageBLL = new PackageBLL(); PackageObj packageObj = packageBLL.GetPackageByID(packageID); if (packageObj == null) { return(Json(new { success = false, msg = "该套餐不存在" })); } string sCategoryIDs = vld.Get("categoryIDs", false, "请至少选择一个类别", regex: @"^\d+(,\d+)*$", regexText: "类别参数错误"); IList <int> categoryIDs; if (string.IsNullOrEmpty(sCategoryIDs)) { categoryIDs = null; } else { string[] aCategoryIDs = sCategoryIDs.Split(','); categoryIDs = new List <int>(); for (int i = 0; i < aCategoryIDs.Length; i++) { categoryIDs.Add(int.Parse(aCategoryIDs[i])); } } packageObj.CategoryID = categoryIDs[0]; packageObj.Categories = categoryIDs; packageObj.BuildingID = vld.GetInt("buildingID", false, "请填写楼盘"); packageObj.Code = vld.Get("code", false, "请填写货号"); packageObj.Intro = HttpUtility.UrlDecode(vld.Get("intro"), Encoding.UTF8); packageObj.Memo = vld.Get("memo"); packageObj.PackageName = vld.Get("name", false, "请填写名称"); packageObj.Material = vld.Get("material"); string strPics = vld.Get("pics", false, "请上传商品图片", @"\d+(,\d+)*", "参数错误"); if (vld.HasError) { return(Json(new { success = false, msg = vld.GetError() })); } string[] pics = strPics.Split(','); PackagePictureObj pictureObj; packageObj.Pictures = new List <PackagePictureObj>(); for (int i = 0; i < pics.Length; i++) { pictureObj = new PackagePictureObj(); pictureObj.PictureID = int.Parse(pics[i]); packageObj.Pictures.Add(pictureObj); } packageBLL.ModifyPackage(packageObj); return(Json(new { success = true })); } else { if (!AppData.IsManagerLogin) { return(Redirect("/Manage/Error/1.html")); } if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 902)) { return(Redirect("/Manage/Error/2.html")); } ViewBag.mediaServer = Config.MediaServer; return(View()); } }