Exemplo n.º 1
0
 ECommerce.CM.DAL.CMColumn cDAL = new ECommerce.CM.DAL.CMColumn(); //创建商品分类DAL对象
 protected void Page_Load(object sender, EventArgs e)
 {
     //VerifyPage("", false);
     if (!IsPostBack)
     {
         ColId      = Request.QueryString["ColId"] == null ? "" : Request.QueryString["ColId"];     //获取商品分类Id
         prParentId = Request.QueryString["PTColId"] == null ? "" : Request.QueryString["PTColId"]; //获取添加子商品分类Id
         if (!string.IsNullOrEmpty(ColId))                                                          //判断商品分类Id是否为空
         {
             //this.lblColName.Text = "修改栏目信息";
             ECommerce.CM.Model.CMColumn cModel = cDAL.GetModel(Convert.ToInt32(ColId)); //通过商品分类Id查询商品分类信息
             if (cModel != null)                                                         //判断商品分类对象是否为空
             {
                 this.txtColName.Value = cModel.ColName;                                 //给商品分类名称文本框赋值
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 保存方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            #region 获取字段值并赋给变量
            string title       = txtTitle.Value.Trim();       //标题
            string col         = ddlColumn.SelectedValue;     //栏目
            string type        = ddlType.SelectedValue;       //类型
            string author      = txtAuthor.Value.Trim();      //作者
            string from        = txtFrom.Value.Trim();        //来源
            string description = tarDescription.Value.Trim(); //导读
            string content     = tarContent.Value.Trim();     //详细内容
            bool   isTop       = rboIsTopTrue.Checked;        //是否置顶
            string displayTime = txtDisplayTime.Value;        //显示时长
            #endregion
            #region  验证输入内容
            if (string.IsNullOrEmpty(title))
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入标题');</script>");
                txtTitle.Focus();
                return;
            }
            if (string.IsNullOrEmpty(col) || col == "0") //判断栏目
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择栏目');</script>");
                ddlColumn.Focus();
                return;
            }
            if (string.IsNullOrEmpty(type) || type == "0") //判断类型
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择类型');</script>");
                ddlType.Focus();
                return;
            }
            //if (string.IsNullOrEmpty(author)) //判断库存是否为空
            //{
            //    Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入作者');</script>");
            //    txtAuthor.Focus();
            //    return;
            //}
            //if (string.IsNullOrEmpty(from)) //判断库存是否为空
            //{
            //    Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入来源');</script>");
            //    txtFrom.Focus();
            //    return;
            //}
            //if (Request.QueryString["AId"] == "0")
            //{
            //    if (isFlash)
            //    {
            //        if (!fuPFlash.HasFile)
            //        {
            //            Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择幻灯图片');</script>");
            //            fuPFlash.Focus();
            //            return;
            //        }
            //    }
            //}
            if (string.IsNullOrEmpty(description)) //判断商品概述是否为空
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入导读');</script>");
                tarDescription.Focus();
                return;
            }
            if (string.IsNullOrEmpty(content)) //判断商品概述是否为空
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入详细内容');</script>");
                tarContent.Focus();
                return;
            }
            if (string.IsNullOrEmpty(displayTime)) //判断商品概述是否为空
            {
                displayTime = "0";
            }
            else
            {
                try
                {
                    Convert.ToInt32(displayTime);
                }
                catch (Exception)
                {
                    Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('显示时长请输入数字');</script>");
                    tarContent.Focus();
                    return;
                }
            }
            #endregion
            //修改信息
            if (!string.IsNullOrEmpty(hidAId.Value)) //判断商品Id是否为空,如果不为空就是编辑数据
            {
                #region 修改内容
                try
                {
                    List <Logs.InfoLog> infolist = new List <Logs.InfoLog>();
                    #region 查询编辑对象,并赋值给对象字段
                    //查询编辑的商品信息
                    aModel = aDAL.GetModel(Convert.ToInt32(hidAId.Value)); //查询产品信息
                    if (aModel != null)                                    //判断编辑果品对象是否为空
                    {
                        if (title != aModel.Title)
                        {
                            infolist.Add(new Logs.InfoLog(title, aModel.Title, "文章标题"));
                        }
                        aModel.Title = title; //文章标题

                        string orgId = Session["OrgId"] != null ? Session["OrgId"].ToString() : "";
                        if (!string.IsNullOrEmpty(orgId))
                        {
                            if (Convert.ToInt32(orgId) != aModel.OrgId)
                            {
                                infolist.Add(new Logs.InfoLog(orgId, aModel.OrgId.ToString(), "生产厂商"));
                            }
                            aModel.OrgId = Convert.ToInt32(orgId); //生产厂商
                        }

                        if (Convert.ToInt32(col) != aModel.ColId)
                        {
                            ECommerce.CM.DAL.CMColumn cmColumnDal = new ECommerce.CM.DAL.CMColumn();
                            var cmColimnInfo = cmColumnDal.GetModel(Convert.ToInt32(aModel.ColId));
                            infolist.Add(new Logs.InfoLog(ddlColumn.SelectedItem.Text, cmColimnInfo.ColName.ToString(), "栏目"));
                        }
                        aModel.ColId = Convert.ToInt32(col); //栏目
                        if (Convert.ToInt32(type) != aModel.ATId)
                        {
                            ECommerce.CM.DAL.CMArticleType cmArticleDal = new ECommerce.CM.DAL.CMArticleType();
                            var cmColimnInfo = cmArticleDal.GetModel(Convert.ToInt32(aModel.ATId));
                            infolist.Add(new Logs.InfoLog(ddlType.SelectedItem.Text, cmColimnInfo.ATName.ToString(), "类型"));
                        }
                        aModel.ATId = Convert.ToInt32(type); //类型
                        if (author != aModel.Author)
                        {
                            infolist.Add(new Logs.InfoLog(author, aModel.Author, "作者"));
                        }
                        aModel.Author = author;
                        if (from != aModel.Source)
                        {
                            infolist.Add(new Logs.InfoLog(from, aModel.Source, "来源"));
                        }
                        aModel.Source = from;
                        if (description != aModel.Description)
                        {
                            infolist.Add(new Logs.InfoLog(description, aModel.Description, "内容导读"));
                        }
                        aModel.Description = description;
                        if (content != aModel.Content)
                        {
                            infolist.Add(new Logs.InfoLog(content, aModel.Content, "详细内容"));
                        }
                        aModel.Content = content;

                        aModel.CheckTime   = DateTime.Now;
                        aModel.DisplayTime = Convert.ToInt32(displayTime);
                        //aModel.PEmplId=  修改人
                        //审核人
                        if (isTop)
                        {
                            if (1 != aModel.IsTop)
                            {
                                infolist.Add(new Logs.InfoLog("1", aModel.IsTop.ToString(), "是否置顶"));
                            }
                            aModel.IsTop = 1;
                        }
                        else
                        {
                            if (0 != aModel.IsTop)
                            {
                                infolist.Add(new Logs.InfoLog("0", aModel.IsTop.ToString(), "是否置顶"));
                            }
                            aModel.IsTop = 0;
                        }

                        #endregion

                        if (fuPFlash.HasFile)
                        {
                            int    sizeFlash;
                            string msgFlash;
                            string imgFlashUrl;
                            if (attDAL.Exists(Convert.ToInt32(hidAId.Value), 0)) //判断图片地址是否存在
                            {
                                attModel = attDAL.GetModel(Convert.ToInt32(hidAId.Value), 0);
                                attMod   = attDAL.GetModel(Convert.ToInt32(hidAId.Value), 0);
                                DirFile.DeleteFile(attModel.AttName); // 删除图片地址

                                UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash);
                                //上传图片(无水印)
                                if (string.IsNullOrEmpty(imgFlashUrl))
                                {
                                    Page.ClientScript.RegisterStartupScript(GetType(), "",
                                                                            "<script>alert('" + msgFlash + "');</script>");
                                    return;
                                }
                                attModel.AttName = imgFlashUrl; //幻灯地址
                                if (!attDAL.Update(attModel))
                                {
                                    return;
                                }
                            }
                            else
                            {
                                UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash);
                                //上传图片(无水印)
                                if (string.IsNullOrEmpty(imgFlashUrl))
                                {
                                    Page.ClientScript.RegisterStartupScript(GetType(), "",
                                                                            "<script>alert('" + msgFlash + "');</script>");
                                    return;
                                }
                                attModel.AttName = imgFlashUrl; //幻灯地址
                                attModel.Type    = 0;
                                attModel.AId     = Convert.ToInt32(hidAId.Value);
                                attModel.Status  = 1;
                                if (!(attDAL.Add(attModel) > 0))
                                {
                                    return;
                                }
                            }
                        }
                        attDAL.DeleteByAid(Convert.ToInt32(hidAId.Value));
                        string attName = atts.Value;
                        if (!string.IsNullOrEmpty(attName))
                        {
                            var attNames = attName.Split(',');
                            for (int i = 0; i < attNames.Length - 1; i++)
                            {
                                if (!string.IsNullOrEmpty(attNames[i]))
                                {
                                    attMod.AId     = Convert.ToInt32(hidAId.Value);
                                    attMod.Type    = 1;
                                    attMod.AttName = attNames[i];

                                    attMod.Status = 1;
                                    attDAL.Add(attMod);
                                }
                            }
                        }

                        bool re = aDAL.Update(aModel);
                        if (re)
                        {
                            string orgAreaIds = Session["OrgAreaIds"] != null ? Session["OrgAreaIds"].ToString() : "";
                            if (!string.IsNullOrEmpty(orgAreaIds))
                            {
                                bool res = cmAreaDal.AddList(hidAId.Value, orgAreaIds);
                                if (res)
                                {
                                    if (infolist.Count > 0)
                                    {
                                        _logsDal.WriteLogs(infolist, CurrentUser.EmplId.ToString(), aModel.AId, DateTime.Now, "CMArticle");
                                    }
                                }
                                else
                                {
                                    System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "",
                                                                                      "<script>alert('修改区域失败'); </script>", false);
                                }
                            }
                            else
                            {
                                if (infolist.Count > 0)
                                {
                                    _logsDal.WriteLogs(infolist, CurrentUser.EmplId.ToString(), aModel.AId, DateTime.Now, "CMArticle");
                                }
                            }
                            Session["OrgAreaIds"] = null;

                            string aid  = hidAId.Value;
                            string pids = Session["PIDS"] != null ? Session["PIDS"].ToString() : "";

                            if (!string.IsNullOrEmpty(aid) && !string.IsNullOrEmpty(pids))
                            {
                                int res = cmProDal.AddPro(Convert.ToInt32(aid), pids);
                                if (res > 0)
                                {
                                    if (infolist.Count > 0)
                                    {
                                        _logsDal.WriteLogs(infolist, CurrentUser.EmplId.ToString(), aModel.AId, DateTime.Now, "CMPro");
                                    }
                                }
                                else
                                {
                                    System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "",
                                                                                      "<script>alert('修改关联商品失败'); </script>", false);
                                }
                            }
                            else
                            {
                                if (infolist.Count > 0)
                                {
                                    _logsDal.WriteLogs(infolist, CurrentUser.EmplId.ToString(), aModel.AId, DateTime.Now, "CMArticle");
                                }
                            }
                            Session["AID"]   = null;
                            Session["PIDS"]  = null;
                            Session["OrgId"] = null;

                            System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "",
                                                                              "<script>window.location = '/Manage/CM/CMArticle.aspx?Page=" + page + "';</script>", false);//跳转页面
                        }
                        else
                        {
                            System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "",
                                                                              "<script>alert('修改失败'); </script>", false);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                #endregion
            }
            else //新增信息
            {
                #region 新增信息
                try
                {
                    #region 给果品实体对象字段赋值
                    aModel.Title = title; //商品名称
                    string orgId = Session["OrgId"] != null ? Session["OrgId"].ToString() : "";
                    if (!string.IsNullOrEmpty(orgId))
                    {
                        aModel.OrgId = Convert.ToInt32(orgId);  //生产厂商
                    }
                    aModel.ColId       = Convert.ToInt32(col);  //产品概述
                    aModel.ATId        = Convert.ToInt32(type); //产品描述
                    aModel.Author      = author;
                    aModel.Source      = from;
                    aModel.Description = description;
                    aModel.Content     = content;
                    aModel.Hits        = 0;
                    aModel.Status      = 0;
                    aModel.AddTime     = DateTime.Now;
                    aModel.DisplayTime = Convert.ToInt32(displayTime);
                    if (isTop)
                    {
                        aModel.IsTop = 1;
                    }
                    else
                    {
                        aModel.IsTop = 0;
                    }

                    #endregion
                    int re = aDAL.Add(aModel); //增加方法

                    if (fuPFlash.HasFile)
                    {
                        int    sizeFlash;
                        string msgFlash;
                        string imgFlashUrl;
                        UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash);//上传图片
                        if (string.IsNullOrEmpty(imgFlashUrl))
                        {
                            Page.ClientScript.RegisterStartupScript(GetType(), "",
                                                                    "<script>alert('" + msgFlash + "');</script>");
                            return;
                        }

                        attModel.Type    = 0;
                        attModel.AttName = imgFlashUrl; //幻灯地址
                        attModel.Status  = 1;
                        attModel.AId     = re;
                        attDAL.Add(attModel);
                    }

                    string attName = atts.Value;
                    if (!string.IsNullOrEmpty(attName))
                    {
                        var attNames = attName.Split(',');
                        for (int i = 0; i < attNames.Length - 1; i++)
                        {
                            if (!string.IsNullOrEmpty(attNames[i]))
                            {
                                attMod.AId     = re;
                                attMod.Type    = 1;
                                attMod.AttName = attNames[i];
                                attMod.Status  = 1;
                                attDAL.Add(attMod);
                            }
                        }
                    }
                    if (re > 0) //判断商品增加是否成功
                    {
                        string orgAreaIds = Session["OrgAreaIds"] != null ? Session["OrgAreaIds"].ToString() : "";
                        if (!string.IsNullOrEmpty(orgAreaIds))
                        {
                            bool res = cmAreaDal.AddList(re.ToString(), orgAreaIds);
                            if (res)
                            {
                                System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>window.location = '/Manage/CM/CMArticle.aspx?Page=" + page + "';</script>", false);//跳转页面
                            }
                            else
                            {
                                System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "",
                                                                                  "<script>alert('新增区域失败'); </script>", false);
                            }
                        }
                        Session["OrgAreaIds"] = null;

                        string aid  = re.ToString();
                        string pids = Session["PIDS"] != null ? Session["PIDS"].ToString() : "";
                        if (!string.IsNullOrEmpty(aid) && !string.IsNullOrEmpty(pids))
                        {
                            int res = cmProDal.AddPro(Convert.ToInt32(aid), pids);
                            if (res > 0)
                            {
                                page = Request.QueryString["Page"] == null ? 1 : Convert.ToInt32(Request.QueryString["Page"]);
                                System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>window.location = '/Manage/CM/CMArticle.aspx?Page=" + page + "';</script>", false);//跳转页面
                            }
                            else
                            {
                                System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "",
                                                                                  "<script>alert('新增关联商品失败');</script> ", false);
                            }
                        }
                        Session["AID"]   = null;
                        Session["PIDS"]  = null;
                        Session["OrgId"] = null;
                        System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>window.location = '/Manage/CM/CMArticle.aspx';</script>", false);//跳转页面
                    }
                    else
                    {
                        System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "",
                                                                          "<script>alert('新增失败'); </script>", false);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                #endregion
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 保存方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            #region 获取字段值并赋给变量
            string title = txtTitle.Value.Trim();//标题
            string col = ddlColumn.SelectedValue;//栏目
            string type = ddlType.SelectedValue;//类型
            string author = txtAuthor.Value.Trim();//作者
            string from = txtFrom.Value.Trim();//来源
            string description = tarDescription.Value.Trim();//导读
            string content = tarContent.Value.Trim();//详细内容
            bool isTop = rboIsTopTrue.Checked;//是否置顶
            string displayTime = txtDisplayTime.Value;     //显示时长
            #endregion
            #region  验证输入内容
            if (string.IsNullOrEmpty(title))
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入标题');</script>");
                txtTitle.Focus();
                return;
            }
            if (string.IsNullOrEmpty(col) || col == "0") //判断栏目
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择栏目');</script>");
                ddlColumn.Focus();
                return;
            }
            if (string.IsNullOrEmpty(type) || type == "0") //判断类型
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择类型');</script>");
                ddlType.Focus();
                return;
            }
            //if (string.IsNullOrEmpty(author)) //判断库存是否为空
            //{
            //    Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入作者');</script>");
            //    txtAuthor.Focus();
            //    return;
            //}
            //if (string.IsNullOrEmpty(from)) //判断库存是否为空
            //{
            //    Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入来源');</script>");
            //    txtFrom.Focus();
            //    return;
            //}
            //if (Request.QueryString["AId"] == "0")
            //{
            //    if (isFlash)
            //    {
            //        if (!fuPFlash.HasFile)
            //        {
            //            Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择幻灯图片');</script>");
            //            fuPFlash.Focus();
            //            return;
            //        }
            //    }
            //}
            if (string.IsNullOrEmpty(description)) //判断商品概述是否为空
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入导读');</script>");
                tarDescription.Focus();
                return;
            }
            if (string.IsNullOrEmpty(content)) //判断商品概述是否为空
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入详细内容');</script>");
                tarContent.Focus();
                return;
            }
            if (string.IsNullOrEmpty(displayTime)) //判断商品概述是否为空
            {
                displayTime = "0";
            }
            else
            {
                try
                {
                    Convert.ToInt32(displayTime);
                }
                catch (Exception)
                {
                    Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('显示时长请输入数字');</script>");
                    tarContent.Focus();
                    return;
                }

            }
            #endregion
            //修改信息
            if (!string.IsNullOrEmpty(hidAId.Value)) //判断商品Id是否为空,如果不为空就是编辑数据
            {
                #region 修改内容
                try
                {
                    List<Logs.InfoLog> infolist = new List<Logs.InfoLog>();
                    #region 查询编辑对象,并赋值给对象字段
                    //查询编辑的商品信息
                    aModel = aDAL.GetModel(Convert.ToInt32(hidAId.Value)); //查询产品信息
                    if (aModel != null) //判断编辑果品对象是否为空
                    {
                        if (title != aModel.Title)
                        {
                            infolist.Add(new Logs.InfoLog(title, aModel.Title, "文章标题"));
                        }
                        aModel.Title = title; //文章标题

                        string orgId = Session["OrgId"] != null ? Session["OrgId"].ToString() : "";
                        if (!string.IsNullOrEmpty(orgId))
                        {
                            if (Convert.ToInt32(orgId) != aModel.OrgId)
                            {
                                infolist.Add(new Logs.InfoLog(orgId, aModel.OrgId.ToString(), "生产厂商"));
                            }
                            aModel.OrgId = Convert.ToInt32(orgId); //生产厂商
                        }

                        if (Convert.ToInt32(col) != aModel.ColId)
                        {
                            ECommerce.CM.DAL.CMColumn cmColumnDal = new ECommerce.CM.DAL.CMColumn();
                            var cmColimnInfo = cmColumnDal.GetModel(Convert.ToInt32(aModel.ColId));
                            infolist.Add(new Logs.InfoLog(ddlColumn.SelectedItem.Text, cmColimnInfo.ColName.ToString(), "栏目"));
                        }
                        aModel.ColId = Convert.ToInt32(col); //栏目
                        if (Convert.ToInt32(type) != aModel.ATId)
                        {

                            ECommerce.CM.DAL.CMArticleType cmArticleDal = new ECommerce.CM.DAL.CMArticleType();
                            var cmColimnInfo = cmArticleDal.GetModel(Convert.ToInt32(aModel.ATId));
                            infolist.Add(new Logs.InfoLog(ddlType.SelectedItem.Text, cmColimnInfo.ATName.ToString(), "类型"));
                        }
                        aModel.ATId = Convert.ToInt32(type); //类型
                        if (author != aModel.Author)
                        {
                            infolist.Add(new Logs.InfoLog(author, aModel.Author, "作者"));
                        }
                        aModel.Author = author;
                        if (from != aModel.Source)
                        {
                            infolist.Add(new Logs.InfoLog(from, aModel.Source, "来源"));
                        }
                        aModel.Source = from;
                        if (description != aModel.Description)
                        {
                            infolist.Add(new Logs.InfoLog(description, aModel.Description, "内容导读"));
                        }
                        aModel.Description = description;
                        if (content != aModel.Content)
                        {
                            infolist.Add(new Logs.InfoLog(content, aModel.Content, "详细内容"));
                        }
                        aModel.Content = content;

                        aModel.CheckTime = DateTime.Now;
                        aModel.DisplayTime = Convert.ToInt32(displayTime);
                        //aModel.PEmplId=  修改人
                        //审核人
                        if (isTop)
                        {
                            if (1 != aModel.IsTop)
                            {
                                infolist.Add(new Logs.InfoLog("1", aModel.IsTop.ToString(), "是否置顶"));
                            }
                            aModel.IsTop = 1;

                        }
                        else
                        {
                            if (0 != aModel.IsTop)
                            {
                                infolist.Add(new Logs.InfoLog("0", aModel.IsTop.ToString(), "是否置顶"));
                            }
                            aModel.IsTop = 0;
                        }

                    #endregion

                        if (fuPFlash.HasFile)
                        {
                            int sizeFlash;
                            string msgFlash;
                            string imgFlashUrl;
                            if (attDAL.Exists(Convert.ToInt32(hidAId.Value), 0)) //判断图片地址是否存在
                            {
                                attModel = attDAL.GetModel(Convert.ToInt32(hidAId.Value), 0);
                                attMod = attDAL.GetModel(Convert.ToInt32(hidAId.Value), 0);
                                DirFile.DeleteFile(attModel.AttName); // 删除图片地址

                                UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash);
                                //上传图片(无水印)
                                if (string.IsNullOrEmpty(imgFlashUrl))
                                {
                                    Page.ClientScript.RegisterStartupScript(GetType(), "",
                                        "<script>alert('" + msgFlash + "');</script>");
                                    return;
                                }
                                attModel.AttName = imgFlashUrl; //幻灯地址
                                if (!attDAL.Update(attModel))
                                {
                                    return;
                                }

                            }
                            else
                            {
                                UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash);
                                //上传图片(无水印)
                                if (string.IsNullOrEmpty(imgFlashUrl))
                                {
                                    Page.ClientScript.RegisterStartupScript(GetType(), "",
                                        "<script>alert('" + msgFlash + "');</script>");
                                    return;
                                }
                                attModel.AttName = imgFlashUrl; //幻灯地址
                                attModel.Type = 0;
                                attModel.AId = Convert.ToInt32(hidAId.Value);
                                attModel.Status = 1;
                                if (!(attDAL.Add(attModel) > 0))
                                {
                                    return;
                                }

                            }
                        }
                        attDAL.DeleteByAid(Convert.ToInt32(hidAId.Value));
                        string attName = atts.Value;
                        if (!string.IsNullOrEmpty(attName))
                        {
                            var attNames = attName.Split(',');
                            for (int i = 0; i < attNames.Length - 1; i++)
                            {
                                if (!string.IsNullOrEmpty(attNames[i]))
                                {
                                    attMod.AId = Convert.ToInt32(hidAId.Value);
                                    attMod.Type = 1;
                                    attMod.AttName = attNames[i];

                                    attMod.Status = 1;
                                    attDAL.Add(attMod);
                                }
                            }
                        }

                        bool re = aDAL.Update(aModel);
                        if (re)
                        {
                            string orgAreaIds = Session["OrgAreaIds"] != null ? Session["OrgAreaIds"].ToString() : "";
                            if (!string.IsNullOrEmpty(orgAreaIds))
                            {
                                bool res = cmAreaDal.AddList(hidAId.Value, orgAreaIds);
                                if (res)
                                {
                                    if (infolist.Count > 0)
                                    {

                                        _logsDal.WriteLogs(infolist, CurrentUser.EmplId.ToString(), aModel.AId, DateTime.Now, "CMArticle");
                                    }
                                }
                                else
                                {
                                    System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "",
                                     "<script>alert('修改区域失败'); </script>", false);
                                }
                            }
                            else
                            {
                                if (infolist.Count > 0)
                                {
                                    _logsDal.WriteLogs(infolist, CurrentUser.EmplId.ToString(), aModel.AId, DateTime.Now, "CMArticle");
                                }
                            }
                            Session["OrgAreaIds"] = null;

                            string aid = hidAId.Value;
                            string pids = Session["PIDS"] != null ? Session["PIDS"].ToString() : "";

                            if (!string.IsNullOrEmpty(aid) && !string.IsNullOrEmpty(pids))
                            {
                                int res = cmProDal.AddPro(Convert.ToInt32(aid), pids);
                                if (res > 0)
                                {
                                    if (infolist.Count > 0)
                                    {
                                        _logsDal.WriteLogs(infolist, CurrentUser.EmplId.ToString(), aModel.AId, DateTime.Now, "CMPro");
                                    }
                                }
                                else
                                {
                                    System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "",
                                     "<script>alert('修改关联商品失败'); </script>", false);
                                }
                            }
                            else
                            {
                                if (infolist.Count > 0)
                                {
                                    _logsDal.WriteLogs(infolist, CurrentUser.EmplId.ToString(), aModel.AId, DateTime.Now, "CMArticle");
                                }
                            }
                            Session["AID"] = null;
                            Session["PIDS"] = null;
                            Session["OrgId"] = null;

                            System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "",
                                       "<script>window.location = '/Manage/CM/CMArticle.aspx?Page=" + page + "';</script>", false);//跳转页面
                        }
                        else
                        {
                            System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "",
                                        "<script>alert('修改失败'); </script>", false);
                        }

                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                #endregion
            }
            else //新增信息
            {
                #region 新增信息
                try
                {
                    #region 给果品实体对象字段赋值
                    aModel.Title = title; //商品名称
                    string orgId = Session["OrgId"] != null ? Session["OrgId"].ToString() : "";
                    if (!string.IsNullOrEmpty(orgId))
                    {
                        aModel.OrgId = Convert.ToInt32(orgId); //生产厂商
                    }
                    aModel.ColId = Convert.ToInt32(col); //产品概述
                    aModel.ATId = Convert.ToInt32(type); //产品描述
                    aModel.Author = author;
                    aModel.Source = from;
                    aModel.Description = description;
                    aModel.Content = content;
                    aModel.Hits = 0;
                    aModel.Status = 0;
                    aModel.AddTime = DateTime.Now;
                    aModel.DisplayTime = Convert.ToInt32(displayTime);
                    if (isTop)
                    {
                        aModel.IsTop = 1;
                    }
                    else
                    {
                        aModel.IsTop = 0;
                    }

                    #endregion
                    int re = aDAL.Add(aModel); //增加方法

                    if (fuPFlash.HasFile)
                    {
                        int sizeFlash;
                        string msgFlash;
                        string imgFlashUrl;
                        UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash);//上传图片
                        if (string.IsNullOrEmpty(imgFlashUrl))
                        {
                            Page.ClientScript.RegisterStartupScript(GetType(), "",
                                "<script>alert('" + msgFlash + "');</script>");
                            return;
                        }

                        attModel.Type = 0;
                        attModel.AttName = imgFlashUrl; //幻灯地址
                        attModel.Status = 1;
                        attModel.AId = re;
                        attDAL.Add(attModel);
                    }

                    string attName = atts.Value;
                    if (!string.IsNullOrEmpty(attName))
                    {
                        var attNames = attName.Split(',');
                        for (int i = 0; i < attNames.Length - 1; i++)
                        {
                            if (!string.IsNullOrEmpty(attNames[i]))
                            {
                                attMod.AId = re;
                                attMod.Type = 1;
                                attMod.AttName = attNames[i];
                                attMod.Status = 1;
                                attDAL.Add(attMod);
                            }
                        }
                    }
                    if (re > 0) //判断商品增加是否成功
                    {
                        string orgAreaIds = Session["OrgAreaIds"] != null ? Session["OrgAreaIds"].ToString() : "";
                        if (!string.IsNullOrEmpty(orgAreaIds))
                        {
                            bool res = cmAreaDal.AddList(re.ToString(), orgAreaIds);
                            if (res)
                            {
                                System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>window.location = '/Manage/CM/CMArticle.aspx?Page=" + page + "';</script>", false);//跳转页面
                            }
                            else
                            {
                                System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "",
                                  "<script>alert('新增区域失败'); </script>", false);

                            }
                        }
                        Session["OrgAreaIds"] = null;

                        string aid = re.ToString();
                        string pids = Session["PIDS"] != null ? Session["PIDS"].ToString() : "";
                        if (!string.IsNullOrEmpty(aid) && !string.IsNullOrEmpty(pids))
                        {
                            int res = cmProDal.AddPro(Convert.ToInt32(aid), pids);
                            if (res > 0)
                            {

                                page = Request.QueryString["Page"] == null ? 1 : Convert.ToInt32(Request.QueryString["Page"]);
                                System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>window.location = '/Manage/CM/CMArticle.aspx?Page=" + page + "';</script>", false);//跳转页面
                            }
                            else
                            {
                                System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "",
                                  "<script>alert('新增关联商品失败');</script> ", false);

                            }
                        }
                        Session["AID"] = null;
                        Session["PIDS"] = null;
                        Session["OrgId"] = null;
                        System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>window.location = '/Manage/CM/CMArticle.aspx';</script>", false);//跳转页面
                    }
                    else
                    {
                        System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "",
                            "<script>alert('新增失败'); </script>", false);
                    }

                }
                catch (Exception ex)
                {
                    throw ex;
                }
                #endregion
            }
        }
Exemplo n.º 4
0
        ECommerce.CM.DAL.CMArticle aDAL = new ECommerce.CM.DAL.CMArticle();      //创建商品品牌DAL对象
        protected void Page_Load(object sender, EventArgs e)
        {
            //VerifyPage("", false);
            if (!IsPostBack)
            {
                var ColId    = Request.QueryString["ColId"];                          //编辑分类Id
                var PTColId  = Request.QueryString["PTColId"];                        //添加商品子分类分类Id
                var detColId = Request.QueryString["detColId"];                       //删除商品分类Id
                var ColName  = HttpUtility.UrlDecode(Request.QueryString["ColName"]); //商品名称
                #region  除分类
                if (!string.IsNullOrEmpty(detColId))
                {
                    #region 查询分类是否有品牌关联
                    string sqlWhere = "";
                    List <SqlParameter> parameters = new List <SqlParameter>();     //创建查询参数集合
                    sqlWhere = "  ColId=@detColId ";
                    var parameter = new SqlParameter("@detColId", DbType.AnsiString);
                    parameter.Value = detColId;
                    parameters.Add(parameter);
                    DataSet dts = aDAL.GetList(sqlWhere, parameters);     //通过商品分类Id查找关系表数据
                    if (dts.Tables[0].Rows.Count > 0)
                    {
                        Response.Write("该栏目下有文章,不能删除");
                        Response.End();
                    }
                    #endregion
                    #region 判断分类是否存在子分类
                    else
                    {
                        string sqlWhere1 = "";
                        List <SqlParameter> parameters1 = new List <SqlParameter>();     //创建查询参数集合
                        sqlWhere1 = "  ParentId=@ParentId ";
                        var parameter1 = new SqlParameter("@ParentId", DbType.AnsiString);
                        parameter1.Value = detColId;
                        parameters1.Add(parameter1);
                        DataSet dt = cDAL.GetList(sqlWhere1, parameters1);         //通过商品分类Id查找子分类
                        if (dt.Tables[0].Rows.Count > 0)
                        {
                            Response.Write("存在子栏目,不能删除,请先删除子栏目");
                            Response.End();
                        }
                        else
                        {
                            Response.Write(cDAL.Delete(Convert.ToInt32(detColId)) ? "删除成功" : "删除失败");
                            Response.End();
                        }
                    }
                    #endregion
                }
                #endregion
                #region  添加、修改、添加子分类
                else
                {
                    if (string.IsNullOrEmpty(ColName))
                    {
                        Response.Write("栏目名称不能为空");
                        Response.End();
                    }

                    #region 修改商品分类
                    ECommerce.CM.Model.CMColumn cMdoel = new ECommerce.CM.Model.CMColumn();     //商品分类实体
                    if (!string.IsNullOrEmpty(ColId))
                    {
                        try
                        {
                            cMdoel = cDAL.GetModel(Convert.ToInt32(ColId));
                            if (cMdoel != null)
                            {
                                string sqlWhere = "";
                                List <SqlParameter> parameters = new List <SqlParameter>();            //创建查询参数集合
                                sqlWhere = "  ColName=@ColName and ColId!=@ColId  and  ParentId=@PID"; //查询条件
                                var parameter = new SqlParameter("@ColName", DbType.AnsiString);
                                parameter.Value = ColName;
                                parameters.Add(parameter);
                                var parameter1 = new SqlParameter("@ColId", DbType.AnsiString);
                                parameter1.Value = ColId;
                                parameters.Add(parameter1);
                                var parameter2 = new SqlParameter("@PID", DbType.AnsiString);
                                parameter2.Value = cMdoel.ParentId;
                                parameters.Add(parameter2);
                                var ds = cDAL.GetList(sqlWhere, parameters);            //通过商品分类名称及商品Id查询商品分类名称是否存在
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    Response.Write("该栏目名称已存在");
                                    Response.End();
                                }
                                cMdoel.ColName = ColName;
                                Response.Write(cDAL.Update(cMdoel) ? "保存成功" : "保存失败");
                                Response.End();
                            }
                        }
                        catch (System.Threading.ThreadAbortException ex)
                        {
                            throw ex;
                        }
                        catch
                        {
                            Response.Write("保存失败");
                            Response.End();
                        }
                    }
                    #endregion
                    #region 添加子分类、添加分类
                    else
                    {
                        try
                        {
                            string sqlWhere = "";
                            List <SqlParameter> parameters = new List <SqlParameter>();     //创建查询参数集合
                            sqlWhere = "  ColName=@PTName  and ParentId=@ColId ";
                            var parameter = new SqlParameter("@PTName", DbType.AnsiString);
                            parameter.Value = ColName;
                            parameters.Add(parameter);
                            var parameter1 = new SqlParameter("@ColId", DbType.AnsiString);
                            parameter1.Value = PTColId;
                            parameters.Add(parameter1);
                            var ds = cDAL.GetList(sqlWhere, parameters);
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                Response.Write("该栏目名称已存在");
                                Response.End();
                            }
                            cMdoel.ColName   = ColName;                     //商品分类名称
                            cMdoel.ClickRate = 0;                           //点击率
                            cMdoel.Status    = 1;                           //状态
                            if (!string.IsNullOrEmpty(PTColId))             //判断是添加子商品分类还是父商品分类
                            {
                                cMdoel.ParentId = Convert.ToInt32(PTColId); //商品分类父节点字段
                                var proInfo = cDAL.GetModel(Convert.ToInt32(PTColId));
                                if (proInfo != null)
                                {
                                    cMdoel.Level = proInfo.Level + 1;            //分类级别
                                }
                            }
                            else
                            {
                                cMdoel.ParentId = 0;          //分类父节点
                                cMdoel.Level    = 1;          //分类级别
                            }
                            cMdoel.AddTime = DateTime.Now;    //添加时间
                            Response.Write(cDAL.Add(cMdoel) > 0 ? "保存成功" : "保存失败");
                            Response.End();
                        }
                        catch (System.Threading.ThreadAbortException ex)
                        {
                            throw ex;
                        }
                        catch
                        {
                            Response.Write("保存失败");
                            Response.End();
                        }
                    }
                    #endregion
                }
                #endregion
            }
        }