コード例 #1
0
        public void ModifyPicture(PackagePictureObj packagePictureObj)
        {
            using (helper = new SqlHelper())
            {
                string sql = "update PackagePictures set PackageID=@PackageID,PictureDesc=@PictureDesc,SavePath=@SavePath,Url=@Url where PictureID=@PictureID";
                helper.AddIntParameter("@PictureID", packagePictureObj.PictureID);
                helper.AddIntParameter("@PackageID", packagePictureObj.PackageID);
                helper.AddStringParameter("@SavePath", 200, packagePictureObj.SavePath);
                helper.AddStringParameter("@PictureDesc", 200, packagePictureObj.PictureDesc);
                helper.AddStringParameter("@Url", 200, packagePictureObj.Url);

                helper.ExecuteNonQuery(sql, CommandType.Text);
            }
        }
コード例 #2
0
        public void AddPicture(PackagePictureObj packagePictureObj)
        {
            using (helper = new SqlHelper())
            {
                string       sql        = "insert into PackagePictures (PackageID,SavePath,Url,PictureDesc) values (@PackageID,@SavePath,@Url,@PictureDesc) select @PictureID=@@IDENTITY";
                SqlParameter picIDParam = helper.AddOutputParameter("@PictureID");
                helper.AddIntParameter("@PackageID", packagePictureObj.PackageID);
                helper.AddStringParameter("@SavePath", 200, packagePictureObj.SavePath);
                helper.AddStringParameter("@PictureDesc", 200, packagePictureObj.PictureDesc);
                helper.AddStringParameter("@Url", 200, packagePictureObj.Url);

                helper.ExecuteNonQuery(sql, CommandType.Text);
                packagePictureObj.PictureID = (int)picIDParam.Value;
            }
        }
コード例 #3
0
        public PackagePictureObj GetPictureByID(int pictureID)
        {
            using (helper = new SqlHelper())
            {
                helper.AddIntParameter("@PictureID", pictureID);

                string sql = "select PictureID,PackageID,SavePath,Url,PictureDesc from PackagePictures where PictureID=@PictureID";
                using (SqlDataReader dr = helper.ExecuteReader(sql, CommandType.Text))
                {
                    if (dr.HasRows && dr.Read())
                    {
                        PackagePictureObj 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];
                        return(picture);
                    }
                    return(null);
                }
            }
        }
コード例 #4
0
        public ActionResult DeletePackagePic(int pictureID)
        {
            if (!AppData.IsManagerLogin)
            {
                return(Json(new { success = false, msg = "您未登录后台或会话已过期" }));
            }
            if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 9))
            {
                return(Json(new { success = false, msg = "您没有执行该操作的权限" }));
            }

            PackageBLL        packageBLL        = new PackageBLL();
            PackagePictureObj packagePictureObj = packageBLL.GetPictureByID(pictureID);

            if (packagePictureObj == null)
            {
                return(Json(new { success = false, msg = "图片不存在" }));
            }

            System.IO.File.Delete(Config.MediaPath + packagePictureObj.SavePath);
            packageBLL.DeletePicture(pictureID);
            return(Json(new { success = true }));
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
ファイル: PackageBLL.cs プロジェクト: sorrymeika/Gllo
 public void ModifyPicture(PackagePictureObj packagePictureObj)
 {
     dal.ModifyPicture(packagePictureObj);
 }
コード例 #7
0
ファイル: PackageBLL.cs プロジェクト: sorrymeika/Gllo
 public void AddPicture(PackagePictureObj packagePictureObj)
 {
     dal.AddPicture(packagePictureObj);
 }
コード例 #8
0
        public ActionResult InsertPackagePic()
        {
            ViewBag.success = false;
            if (!AppData.IsManagerLogin)
            {
                ViewBag.msg = "抱歉,您未登录后台或会话已过期!";
                return(View());
            }
            if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 9))
            {
                ViewBag.msg = "抱歉,您没有执行该操作的权限!";
                return(View());
            }

            Validation vld   = new Validation();
            int        picID = vld.GetInt("id");
            string     desc  = vld.Get("desc");

            HttpPostedFileBase pic = Request.Files.Count == 0 ? null : Request.Files[0];

            if (pic != null && !string.IsNullOrEmpty(pic.FileName))
            {
                string ext = Path.GetExtension(pic.FileName);
                if (!Regex.IsMatch(ext, @"^\.(gif|jpg|jpeg|png)$", RegexOptions.IgnoreCase))
                {
                    ViewBag.msg = "上传的图片格式不合要求,请上传gif,png,jpg格式的图片";
                    return(View());
                }

                string dirPath = Config.MediaPath + @"\Package";
                if (!Directory.Exists(dirPath))
                {
                    Directory.CreateDirectory(dirPath);
                }

                string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff") + ext;
                string savePath    = Path.Combine(dirPath, newFileName);

                PackagePictureObj packagePictureObj;
                PackageBLL        packageBLL = new PackageBLL();
                if (picID == 0)
                {
                    packagePictureObj             = new PackagePictureObj();
                    packagePictureObj.PackageID   = string.IsNullOrEmpty(Request.Form["packageID"]) ? 0 : int.Parse(Request.Form["packageID"]);
                    packagePictureObj.SavePath    = @"\Package\" + newFileName;
                    packagePictureObj.Url         = "/Package/" + newFileName;
                    packagePictureObj.PictureDesc = desc;

                    packageBLL.AddPicture(packagePictureObj);
                }
                else
                {
                    packagePictureObj = packageBLL.GetPictureByID(picID);
                    System.IO.File.Delete(Config.MediaPath + packagePictureObj.SavePath);
                    packagePictureObj.SavePath    = @"\Package\" + newFileName;
                    packagePictureObj.Url         = "/Package/" + newFileName;
                    packagePictureObj.PictureDesc = desc;
                    packageBLL.ModifyPicture(packagePictureObj);
                }
                ViewBag.picId = packagePictureObj.PictureID;

                pic.SaveAs(savePath);

                ViewBag.success = true;
                return(View());
            }
            else if (picID == 0)
            {
                ViewBag.msg = "请上传套餐图片!";
                return(View());
            }
            else
            {
                ViewBag.picId   = picID;
                ViewBag.success = true;
                return(View());
            }
        }
コード例 #9
0
        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());
            }
        }