⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addshop.aspx.cs

📁 易想商城系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
                    //}
                }
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string path = ConfigurationManager.AppSettings["ShopRoot"].ToString();
            path = path.StartsWith("/") ? path : ("/" + path);
            path = path.EndsWith("/") ? (path + TextBox1.Text.Trim()) : (path + "/" + TextBox1.Text.Trim());
            string DicPath = Server.MapPath("~") + path;

            if (!Directory.Exists(DicPath))//如果指定的文件夹不存在,就创建它
                Directory.CreateDirectory(DicPath);
            string path1 = DicPath.EndsWith("/") ? DicPath + "ShopSign" : DicPath + "/ShopSign";
            string path2 = DicPath.EndsWith("/") ? DicPath + "AttestationPic" : DicPath + "/AttestationPic";
            if (!Directory.Exists(path1))
                Directory.CreateDirectory(path1);
            if (!Directory.Exists(path2))
                Directory.CreateDirectory(path2);


            
          
            int id = GetID((Button)sender);

            DateTime startDateTime = DateTime.Now;
            //if (Panel1.Visible)
            //{
            //    int ii = startDateTime.CompareTo(dpStart.Date);
            //    if (ii < 0)
            //    {
            //        startDateTime = dpStart.Date;
            //    }
            //}
            //else
            //{
            //    startDateTime = String.IsNullOrEmpty(StartTime.Value) ? DateTime.Now : Convert.ToDateTime(StartTime.Value);
            //}
            #region 图片上传
            string imgAddr1 = "", imgAddr2 = "";
            if (FileUpload1.HasFile)
            {
                //删除已经存在的文件
                foreach (string file in Directory.GetFileSystemEntries(path1))
                {
                    if (File.Exists(file))
                        File.Delete(file); //直接删除其中的文件 
                }
                //会员路径
                string fileUpPath =path.EndsWith("/") ? path + "ShopSign" : path + "/ShopSign";//ConfigurationSettings.AppSettings["memberImgFile"].ToString();
                string imgPre = ConfigurationSettings.AppSettings["imgFilePre"].ToString();
                imgAddr1 = YXShop.DBUtility.UploadFile.UploadPicFile(FileUpload1, fileUpPath, imgPre);
                if (imgAddr1.StartsWith("error"))
                {
                    YXShop.Common.alert.Show(this, imgAddr1.Replace("error:", ""));
                    return;
                }
            }
            if (FileUpload2.HasFile)
            {
                //删除已经存在的文件
                foreach (string file in Directory.GetFileSystemEntries(path2))
                {
                    if (File.Exists(file))
                        File.Delete(file); //直接删除其中的文件 
                }
                string fileUpPath = path.EndsWith("/") ? path + "AttestationPic" : path + "/AttestationPic";  //ConfigurationSettings.AppSettings["memberImgFile"].ToString();
                string imgPre = ConfigurationSettings.AppSettings["imgFilePre"].ToString();
                imgAddr2 = YXShop.DBUtility.UploadFile.UploadPicFile(FileUpload2, fileUpPath, imgPre);
                if (imgAddr2.StartsWith("error"))
                {
                    YXShop.Common.alert.Show(this, imgAddr1.Replace("error:", ""));
                    return;
                }
            }
            #endregion

            #region 参数配置

            int shopRank = 0, addDay = 0;
            string[] arr = RadioButtonList1.SelectedValue.Split(',');
            if (arr.Length == 2)
            {
                shopRank = YXShop.Common.WebUtility.isNumeric(arr[0]) ? Convert.ToInt32(arr[0]) : 0;
                addDay = YXShop.Common.WebUtility.isNumeric(arr[1]) ? Convert.ToInt32(arr[1]) : 0;
            }
            YXShop.Model.YXShop_Shop sModel = new YXShop.Model.YXShop_Shop();
            sModel.UID = Convert.ToInt32(Session["MemberID"]);
            sModel.ShopName = YXShop.Common.WebUtility.replaceStr(TextBox1.Text);
            sModel.ShopType = YXShop.Common.WebUtility.isNumeric(DropDownList2.SelectedValue) ? Convert.ToInt32(DropDownList2.SelectedValue) : 0;
            sModel.Categories = YXShop.Common.WebUtility.isNumeric(DropDownList3.SelectedValue) ? Convert.ToInt32(DropDownList3.SelectedValue) : 0;
            sModel.ShopRank = shopRank;
            sModel.Affiche = "";
            sModel.Discription = TextBox3.Text;
            sModel.StartDate = startDateTime;
            sModel.EndDate = Convert.ToDateTime(sModel.StartDate).AddDays(addDay);//结束时间
            sModel.State = 0;
            sModel.ShopSign = String.IsNullOrEmpty(imgUrlHid1.Value) ? imgAddr1 : imgUrlHid1.Value;
            sModel.ShopStyle = YXShop.Common.WebUtility.isNumeric(TextBox4.Text) ? Convert.ToInt32(TextBox4.Text) : 0;
            sModel.TWODomainName = TextBox2.Text;
            sModel.AttestationPic = String.IsNullOrEmpty(imgUrlHid2.Value) ? imgAddr2 : imgUrlHid2.Value;
            sModel.AttestationState = 0;
            sModel.PrestigeRank = 0;
            sModel.VisitNo = 0;
            sModel.Attribute = "0,0,0,0,0,0";
            sModel.AddTime = String.IsNullOrEmpty(AddTime.Value) ? DateTime.Now : Convert.ToDateTime(AddTime.Value);
            sModel.UpDateTime = DateTime.Now;
            sModel.ShopState = 0;
            sModel.ShopNum = GetUniqueID(Convert.ToInt32(sModel.UID));
            #endregion
            bool isUserIn = CheckUID(Convert.ToInt32(sModel.UID));
            if (id > 0 && isUserIn)
            {//update
                try
                {
                    sModel.SID = id;
                    sBll.Amend(sModel);
                    bp.PageRight("店铺信息已经更新!<font color=\"red\">现在就跳转到用户首页!</font></a></li>", "MemberCenter.aspx");
                }
                catch { }
            }
            else
            {//create
                if (CheckShopName(YXShop.Common.WebUtility.replaceStr(TextBox1.Text.Trim())))
                {
                    try
                    {
                        sBll.Create(sModel);
                        YXShop.BLL.UserCommon ucBll = new YXShop.BLL.UserCommon();
                        YXShop.Model.UserCommon ucModel = ucBll.GetId(Convert.ToInt32(sModel.UID));
                        if (ucModel != null)
                        {
                            ucModel.UserType = 2;
                            try
                            {
                                ucBll.Amend(ucModel);
                                bp.PageRight("店铺创建成功!<font color=\"red\">现在就跳回用户首页!</font></a></li>", "MemberCenter.aspx");
                            }
                            catch 
                            { 
                            }
                        }
                        else 
                        {
                            //用户不存在
                        }
                    }
                    catch { }
                }
                else
                {
                    //该店铺名称已经存在
                    bp.PageError("该店铺已经存在!<font color=\"red\">返回重新填写店铺信息!</font></a></li>", "AddShop.aspx");
                }
            }

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="btn"></param>
        /// <returns></returns>
        private int GetID(Button btn)
        {
            int reInt = 0;
            if (YXShop.Common.WebUtility.isNumeric(btn.CommandArgument))
                reInt = Convert.ToInt32(btn.CommandArgument);
            return reInt;
        }
        /// <summary>
        /// 检查店铺名称
        /// </summary>
        /// <param name="shopName"></param>
        /// <returns>存在就返回false,表示不能用,否则返回true</returns>
        private bool CheckShopName(string shopName)
        {
            List<YXShop.Model.YXShop_Shop> sList = sBll.GetListByColumn("ShopName", shopName);
            if (sList.Count > 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        private bool CheckUID(int uid)
        {
            List<YXShop.Model.YXShop_Shop> sList = sBll.GetListByColumn("UID", uid);
            if (sList.Count > 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="name"></param>
        /// <returns>存在就返回false,表示不能用,否则返回true</returns>
        private bool CheckName(string name)
        {
            List<YXShop.Model.YXShop_Shop> sList = sBll.GetListByColumn("TWODomainName", name);
            if (sList.Count > 0)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        private string GetUniqueID(int uid) 
        {
            int len = uid.ToString().Length;
            string pre="";
            for (int i = 0; i < 6 - len; i++) 
            {
                pre += "0";
            }
            return pre + uid.ToString();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -