Ejemplo n.º 1
0
        /// <summary>
        /// 获得该分类信息,使用wid仅仅作为限制条件
        /// </summary>
        /// <param name="wid"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public Model.wx_book_category GetCategoryByWid(int wid, int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select top 1");
            strSql.Append(" id,title,code,parent_id,class_list,class_layer,sort_id,link_url,img_url,class_content,remark,seo_title,seo_keywords,seo_description,wid,ico_url  ");
            strSql.Append(" from wx_book_category  where   id=@id  and wid=@wid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id",  SqlDbType.Int, 4),
                new SqlParameter("@wid", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;
            parameters[1].Value = wid;
            SqlDataReader sr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters);

            Model.wx_book_category category = new Model.wx_book_category();
            while (sr.Read())
            {
                category                 = new Model.wx_book_category();
                category.id              = MyCommFun.Obj2Int(sr["id"]);
                category.title           = MyCommFun.ObjToStr(sr["title"]);
                category.parent_id       = MyCommFun.Obj2Int(sr["parent_id"]);
                category.class_layer     = MyCommFun.Obj2Int(sr["class_layer"]);
                category.link_url        = MyCommFun.ObjToStr(sr["link_url"]);
                category.img_url         = MyCommFun.ObjToStr(sr["img_url"]);
                category.class_content   = MyCommFun.ObjToStr(sr["class_content"]);
                category.ico_url         = MyCommFun.ObjToStr(sr["ico_url"]);
                category.seo_title       = MyCommFun.ObjToStr(sr["seo_title"]);
                category.seo_keywords    = MyCommFun.ObjToStr(sr["seo_keywords"]);
                category.seo_description = MyCommFun.ObjToStr(sr["seo_description"]);
            }
            sr.Close();
            return(category);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获得微帐号的分类信息
        /// </summary>
        /// <param name="wid"></param>
        /// <param name="topNum">取前几条数据;若为-1,则不作筛选条件</param>
        /// <param name="parentId">若为-1,则不作筛选条件</param>
        /// <returns></returns>
        public IList <Model.wx_book_category> GetCategoryListByWid(int wid, int topNum, int parentId, int class_layer)
        {
            IList <Model.wx_book_category> categoryList = new List <Model.wx_book_category>();

            StringBuilder strSql = new StringBuilder();

            strSql.Append("select ");
            if (topNum >= 0)
            {
                strSql.Append(" top " + topNum + " ");
            }
            strSql.Append(" id,title,code,parent_id,class_list,class_layer,sort_id,link_url,img_url,class_content,remark,seo_title,seo_keywords,seo_description,wid,ico_url from wx_book_category   where 1=1 ");
            if (parentId != -1)
            {
                strSql.Append(" and parent_id=" + parentId);
            }
            if (class_layer != -1)
            {
                strSql.Append(" and class_layer=" + class_layer);
            }

            strSql.Append(" and wid=@wid order by sort_id asc");
            SqlParameter[] parameters =
            {
                new SqlParameter("@wid", SqlDbType.Int, 4)
            };
            parameters[0].Value = wid;
            SqlDataReader sr = DbHelperSQL.ExecuteReader(strSql.ToString(), parameters);

            Model.wx_book_category category = new Model.wx_book_category();
            while (sr.Read())
            {
                category                 = new Model.wx_book_category();
                category.id              = MyCommFun.Obj2Int(sr["id"]);
                category.title           = MyCommFun.ObjToStr(sr["title"]);
                category.parent_id       = MyCommFun.Obj2Int(sr["parent_id"]);
                category.class_layer     = MyCommFun.Obj2Int(sr["class_layer"]);
                category.link_url        = MyCommFun.ObjToStr(sr["link_url"]);
                category.img_url         = MyCommFun.ObjToStr(sr["img_url"]);
                category.class_content   = MyCommFun.ObjToStr(sr["class_content"]);
                category.ico_url         = MyCommFun.ObjToStr(sr["ico_url"]);
                category.seo_title       = MyCommFun.ObjToStr(sr["seo_title"]);
                category.seo_keywords    = MyCommFun.ObjToStr(sr["seo_keywords"]);
                category.seo_description = MyCommFun.ObjToStr(sr["seo_description"]);
                categoryList.Add(category);
            }
            sr.Close();



            return(categoryList);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获得wid的用户分类信息
        /// </summary>
        /// <returns></returns>
        public IList <Model.wx_book_category> getCategory()
        {
            Tag tag = this.Document.CurrentRenderingTag;

            ///classlayer表示取类别深度,如果为-1,则取所有分类的深度,如果为1,则取第一层目录,如果为2,则去第2层目录
            var classlayer  = tag.Attributes["classlayer"];
            var parentidObj = tag.Attributes["parentid"];
            int parentid    = -1;

            if (parentidObj != null && MyCommFun.isNumber(parentidObj.Value.GetValue()))
            {
                parentid = MyCommFun.Obj2Int(parentidObj.Value.GetValue());
            }
            int class_layer = -1;

            if (classlayer != null && MyCommFun.isNumber(classlayer.Value.GetValue()))
            {
                class_layer = MyCommFun.Obj2Int(classlayer.Value.GetValue());
            }
            DAL.wx_book_category           cateBll      = new DAL.wx_book_category();
            IList <Model.wx_book_category> categorylist = cateBll.GetCategoryListByWid(wid, -1, parentid, class_layer);

            if (categorylist != null && categorylist.Count > 0)
            {
                Model.wx_book_category cat = new Model.wx_book_category();
                for (int i = 0; i < categorylist.Count; i++)
                {
                    cat = categorylist[i];
                    if (cat.link_url == null || cat.link_url.Trim() == "")
                    {  //如果link_url为空,则直接调用本系统的信息
                        cat.link_url     = MyCommFun.urlAddOpenid("/book/list.aspx?wid=" + wid + "&cid=" + cat.id, openid);
                        cat.category_url = MyCommFun.urlAddOpenid("/book/category.aspx?wid=" + wid + "&cid=" + cat.id, openid);
                    }
                    else
                    {
                        cat.link_url = MyCommFun.urlAddOpenid(cat.link_url, openid);
                    }
                }
            }

            return(categorylist);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 修改子节点的ID列表及深度(自身迭代)
        /// </summary>
        /// <param name="parent_id"></param>
        private void UpdateChilds(SqlConnection conn, SqlTransaction trans, int parent_id)
        {
            //查找父节点信息
            Model.wx_book_category model = GetModel(conn, trans, parent_id);
            if (model != null)
            {
                //查找子节点
                string  strSql = "select id from wx_book_category where parent_id=" + parent_id;
                DataSet ds     = DbHelperSQL.Query(conn, trans, strSql); //带事务
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    //修改子节点的ID列表及深度
                    int    id          = int.Parse(dr["id"].ToString());
                    string class_list  = model.class_list + id + ",";
                    int    class_layer = model.class_layer.Value + 1;
                    DbHelperSQL.ExecuteSql(conn, trans, "update wx_book_category set class_list='" + class_list + "', class_layer=" + class_layer + " where id=" + id); //带事务

                    //调用自身迭代
                    this.UpdateChilds(conn, trans, id); //带事务
                }
            }
        }
Ejemplo n.º 5
0
        private void ShowInfo(int _id)
        {
            BLL.wx_book_category   bll   = new BLL.wx_book_category();
            Model.wx_book_category model = bll.GetModel(_id);

            ddlParentId.SelectedValue = model.parent_id.ToString();

            txtTitle.Text          = model.title;
            txtSortId.Text         = model.sort_id.ToString();
            txtSeoTitle.Text       = model.seo_title;
            txtSeoKeywords.Text    = model.seo_keywords;
            txtSeoDescription.Text = model.seo_description;
            txtLinkUrl.Text        = model.link_url;
            txtImgUrl.Text         = model.img_url;
            if (model.img_url != null && model.img_url.Trim() != "")
            {
                imgUrl.ImageUrl = model.img_url;
            }
            txtContent.Text = model.class_content;
            txtImgICO.Text  = model.ico_url;
            if (model.ico_url != null && model.ico_url.Trim() != "")
            {
                if (model.ico_url.Contains("/"))
                {
                    imgIco.ImageUrl = model.ico_url;
                }
                else
                {
                    imgIco.Style.Add("display", "none");
                    litImgIco.Text = "<span class=\"" + model.ico_url + "\"></span>";
                }
            }

            model.albums            = new wx_book_albums().GetModelList("classId=" + model.id);
            rptAlbumList.DataSource = model.albums;
            rptAlbumList.DataBind();
        }
Ejemplo n.º 6
0
        public void ProductClassPage()
        {
            int category_id = MyCommFun.RequestInt("cid");

            //--=====begin: 将这个列表(文章类别)的基本信息展示出来 ====--
            DAL.wx_book_category   cateBll  = new DAL.wx_book_category();
            Model.wx_book_category category = cateBll.GetCategoryByWid(wid, category_id);
            this.Document.SetValue("category", category);
            this.Document.SetValue("wid", wid);
            //--=====end: 将这个列表(文章类别)的基本信息展示出来 ====--

            Tag    orderByTag = this.Document.GetChildTagById("norderby");
            string orderby    = orderByTag.Attributes["value"].Value.ToString();

            Tag    pagesizeTag = this.Document.GetChildTagById("npagesize");
            string pagesizeStr = pagesizeTag.Attributes["value"].Value.ToString();

            int currPage    = 1;                              //当前页面
            int recordCount = 0;                              //总记录数
            int totPage     = 1;                              //总页数
            int pageSize    = MyCommFun.Str2Int(pagesizeStr); //每页的记录数

            if (pageSize <= 0)
            {
                pageSize = 10;
            }
            if (MyCommFun.RequestInt("page") > 0)
            {
                currPage = MyCommFun.RequestInt("page");
            }

            DataSet productlist = new DataSet();

            if (category_id != 0)
            {
                DAL.wx_book_product artDal = new DAL.wx_book_product();
                productlist = artDal.GetList(wid, category_id, pageSize, currPage, "upselling=1", orderby, out recordCount);
                if (productlist != null && productlist.Tables.Count > 0 && productlist.Tables[0].Rows.Count > 0)
                {
                    DataRow dr;
                    for (int i = 0; i < productlist.Tables[0].Rows.Count; i++)
                    {
                        dr = productlist.Tables[0].Rows[i];
                        if (dr["link_url"] != null && dr["link_url"].ToString().Trim().Length > 0)
                        {
                            dr["link_url"] = MyCommFun.urlAddOpenid(dr["link_url"].ToString().Trim(), openid);
                        }
                        else
                        {
                            dr["link_url"] = MyCommFun.urlAddOpenid("detail.aspx?wid=" + wid + "&pid=" + dr["id"].ToString(), openid);
                        }
                        productlist.AcceptChanges();
                    }

                    totPage = recordCount / pageSize;
                    int yushu = recordCount % pageSize;
                    if (yushu > 0)
                    {
                        totPage += 1;
                    }
                    if (totPage < 1)
                    {
                        totPage = 1;
                    }
                }
                if (currPage > totPage)
                {
                    currPage = totPage;
                }
            }
            else
            {
                currPage    = 1;
                recordCount = 0;
                totPage     = 1;
            }
            this.Document.SetValue("totPage", totPage);         //总页数
            this.Document.SetValue("currPage", currPage);       //当前页
            this.Document.SetValue("productlist", productlist); //文章列表

            string beforePageStr = "";                          //上一页
            string nextPageStr   = "";                          //下一页
            string bgrey         = "c-p-grey";
            string ngrey         = "c-p-grey";

            if (currPage <= 1)
            {
                beforePageStr = "";
                bgrey         = "c-p-grey";
            }
            else
            {
                beforePageStr = MyCommFun.ChangePageNum(MyCommFun.getTotalUrl(), (currPage - 1));
                beforePageStr = "href=\"" + beforePageStr + "\"";
                bgrey         = "";
            }

            if (currPage >= totPage)
            {
                nextPageStr = "";
                ngrey       = " c-p-grey";
            }
            else
            {
                nextPageStr = MyCommFun.ChangePageNum(MyCommFun.getTotalUrl(), (currPage + 1));
                nextPageStr = "href=\"" + nextPageStr + "\"";
                ngrey       = "";
            }
            this.Document.SetValue("bpage", beforePageStr); //上一页
            this.Document.SetValue("npage", nextPageStr);   //下一页
            this.Document.SetValue("bgrey", bgrey);         //上一页灰色的样式
            this.Document.SetValue("ngrey", ngrey);         //下一页灰色的样式
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.wx_book_category model)
        {
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        //先判断选中的父节点是否被包含
                        if (IsContainNode(model.id, model.parent_id.Value))
                        {
                            //查找旧数据
                            Model.wx_book_category oldModel = GetModel(model.id);
                            //查找旧父节点数据
                            string class_list  = "," + model.parent_id + ",";
                            int    class_layer = 1;
                            if (oldModel.parent_id > 0)
                            {
                                Model.wx_book_category oldParentModel = GetModel(conn, trans, oldModel.parent_id.Value); //带事务
                                class_list  = oldParentModel.class_list + model.parent_id + ",";
                                class_layer = oldParentModel.class_layer.Value + 1;
                            }
                            //先提升选中的父节点
                            DbHelperSQL.ExecuteSql(conn, trans, "update wx_book_category set parent_id=" + oldModel.parent_id + ",class_list='" + class_list + "', class_layer=" + class_layer + " where id=" + model.parent_id); //带事务
                            UpdateChilds(conn, trans, model.parent_id.Value);                                                                                                                                                     //带事务
                        }
                        //更新子节点
                        if (model.parent_id > 0)
                        {
                            Model.wx_book_category model2 = GetModel(conn, trans, model.parent_id.Value); //带事务
                            model.class_list  = model2.class_list + model.id + ",";
                            model.class_layer = model2.class_layer + 1;
                        }
                        else
                        {
                            model.class_list  = "," + model.id + ",";
                            model.class_layer = 1;
                        }

                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("update wx_book_category set ");
                        strSql.Append("title=@title,");
                        strSql.Append("parent_id=@parent_id,");
                        strSql.Append("class_list=@class_list,");
                        strSql.Append("class_layer=@class_layer,");
                        strSql.Append("sort_id=@sort_id,");
                        strSql.Append("link_url=@link_url,");
                        strSql.Append("img_url=@img_url,");
                        strSql.Append("class_content=@class_content,");
                        strSql.Append("seo_title=@seo_title,");
                        strSql.Append("seo_keywords=@seo_keywords,");
                        strSql.Append("seo_description=@seo_description,");
                        strSql.Append("wid=@wid,");
                        strSql.Append("ico_url=@ico_url");
                        strSql.Append(" where id=@id");
                        SqlParameter[] parameters =
                        {
                            new SqlParameter("@title",           SqlDbType.NVarChar, 100),
                            new SqlParameter("@parent_id",       SqlDbType.Int,        4),
                            new SqlParameter("@class_list",      SqlDbType.NVarChar, 500),
                            new SqlParameter("@class_layer",     SqlDbType.Int,        4),
                            new SqlParameter("@sort_id",         SqlDbType.Int,        4),
                            new SqlParameter("@link_url",        SqlDbType.NVarChar, 255),
                            new SqlParameter("@img_url",         SqlDbType.NVarChar, 255),
                            new SqlParameter("@class_content",   SqlDbType.NText),
                            new SqlParameter("@seo_title",       SqlDbType.NVarChar, 255),
                            new SqlParameter("@seo_keywords",    SqlDbType.NVarChar, 255),
                            new SqlParameter("@seo_description", SqlDbType.NVarChar, 255),
                            new SqlParameter("@wid",             SqlDbType.Int,        4),
                            new SqlParameter("@ico_url",         SqlDbType.NVarChar, 500),
                            new SqlParameter("@id",              SqlDbType.Int, 4)
                        };
                        parameters[0].Value  = model.title;
                        parameters[1].Value  = model.parent_id;
                        parameters[2].Value  = model.class_list;
                        parameters[3].Value  = model.class_layer;
                        parameters[4].Value  = model.sort_id;
                        parameters[5].Value  = model.link_url;
                        parameters[6].Value  = model.img_url;
                        parameters[7].Value  = model.class_content;
                        parameters[8].Value  = model.seo_title;
                        parameters[9].Value  = model.seo_keywords;
                        parameters[10].Value = model.seo_description;
                        parameters[11].Value = model.wid;
                        parameters[12].Value = model.ico_url;
                        parameters[13].Value = model.id;

                        DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters);


                        #region  //添加/修改相册

                        new wx_book_albums().DeleteClass(model.albums, model.id);
                        if (model.albums != null)
                        {
                            StringBuilder strSql3;
                            foreach (Model.wx_book_albums modelt in model.albums)
                            {
                                strSql3 = new StringBuilder();
                                if (modelt.id > 0)
                                {
                                    strSql3.Append("update  wx_book_albums set ");
                                    strSql3.Append("classId=@classId,");
                                    strSql3.Append("thumb_path=@thumb_path,");
                                    strSql3.Append("original_path=@original_path,");
                                    strSql3.Append("remark=@remark,");
                                    strSql3.Append("add_time=@add_time,");
                                    strSql3.Append("wid=@wid");
                                    strSql3.Append(" where id=@id");
                                    SqlParameter[] parameters3 =
                                    {
                                        new SqlParameter("@classId",       SqlDbType.Int,        4),
                                        new SqlParameter("@thumb_path",    SqlDbType.NVarChar, 255),
                                        new SqlParameter("@original_path", SqlDbType.NVarChar, 255),
                                        new SqlParameter("@remark",        SqlDbType.NVarChar, 500),
                                        new SqlParameter("@add_time",      SqlDbType.DateTime,  20),
                                        new SqlParameter("@wid",           SqlDbType.Int,        4),
                                        new SqlParameter("@id",            SqlDbType.Int, 4)
                                    };
                                    parameters3[0].Value = model.id;
                                    parameters3[1].Value = modelt.thumb_path;
                                    parameters3[2].Value = modelt.original_path;
                                    parameters3[3].Value = modelt.remark;
                                    parameters3[4].Value = DateTime.Now.ToString();
                                    parameters3[5].Value = model.wid;
                                    parameters3[6].Value = modelt.id;
                                    DbHelperSQL.GetSingle(strSql3.ToString(), parameters3);
                                }
                                else
                                {
                                    strSql3.Append("insert into wx_book_albums(");
                                    strSql3.Append("classId,thumb_path,original_path,remark,add_time,wid)");
                                    strSql3.Append(" values (");
                                    strSql3.Append("@classId,@thumb_path,@original_path,@remark,@add_time,@wid)");
                                    SqlParameter[] parameters3 =
                                    {
                                        new SqlParameter("@classId",       SqlDbType.Int,        4),
                                        new SqlParameter("@thumb_path",    SqlDbType.NVarChar, 255),
                                        new SqlParameter("@original_path", SqlDbType.NVarChar, 255),
                                        new SqlParameter("@remark",        SqlDbType.NVarChar, 500),
                                        new SqlParameter("@add_time",      SqlDbType.DateTime,  30),
                                        new SqlParameter("@wid",           SqlDbType.Int, 4)
                                    };

                                    parameters3[0].Value = model.id;
                                    parameters3[1].Value = modelt.thumb_path;
                                    parameters3[2].Value = modelt.original_path;
                                    parameters3[3].Value = modelt.remark;
                                    parameters3[4].Value = DateTime.Now.ToString();
                                    parameters3[5].Value = model.wid;
                                    DbHelperSQL.GetSingle(strSql3.ToString(), parameters3);
                                }
                            }
                        }

                        #endregion

                        //更新子节点
                        UpdateChilds(conn, trans, model.id);
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 得到一个对象实体(重载,带事务)
        /// </summary>
        public Model.wx_book_category GetModel(SqlConnection conn, SqlTransaction trans, int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1  id,title,code,parent_id,class_list,class_layer,sort_id,link_url,img_url,class_content,remark,seo_title,seo_keywords,seo_description,wid,ico_url from wx_book_category  ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Model.wx_book_category model = new Model.wx_book_category();
            DataSet ds = DbHelperSQL.Query(conn, trans, strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"] != null && ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }

                if (ds.Tables[0].Rows[0]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "")
                {
                    model.title = ds.Tables[0].Rows[0]["title"].ToString();
                }

                if (ds.Tables[0].Rows[0]["parent_id"] != null && ds.Tables[0].Rows[0]["parent_id"].ToString() != "")
                {
                    model.parent_id = int.Parse(ds.Tables[0].Rows[0]["parent_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["class_list"] != null && ds.Tables[0].Rows[0]["class_list"].ToString() != "")
                {
                    model.class_list = ds.Tables[0].Rows[0]["class_list"].ToString();
                }
                if (ds.Tables[0].Rows[0]["class_layer"] != null && ds.Tables[0].Rows[0]["class_layer"].ToString() != "")
                {
                    model.class_layer = int.Parse(ds.Tables[0].Rows[0]["class_layer"].ToString());
                }
                if (ds.Tables[0].Rows[0]["sort_id"] != null && ds.Tables[0].Rows[0]["sort_id"].ToString() != "")
                {
                    model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["link_url"] != null && ds.Tables[0].Rows[0]["link_url"].ToString() != "")
                {
                    model.link_url = ds.Tables[0].Rows[0]["link_url"].ToString();
                }
                if (ds.Tables[0].Rows[0]["img_url"] != null && ds.Tables[0].Rows[0]["img_url"].ToString() != "")
                {
                    model.img_url = ds.Tables[0].Rows[0]["img_url"].ToString();
                }
                if (ds.Tables[0].Rows[0]["class_content"] != null && ds.Tables[0].Rows[0]["class_content"].ToString() != "")
                {
                    model.class_content = ds.Tables[0].Rows[0]["class_content"].ToString();
                }
                if (ds.Tables[0].Rows[0]["seo_title"] != null && ds.Tables[0].Rows[0]["seo_title"].ToString() != "")
                {
                    model.seo_title = ds.Tables[0].Rows[0]["seo_title"].ToString();
                }
                if (ds.Tables[0].Rows[0]["seo_keywords"] != null && ds.Tables[0].Rows[0]["seo_keywords"].ToString() != "")
                {
                    model.seo_keywords = ds.Tables[0].Rows[0]["seo_keywords"].ToString();
                }
                if (ds.Tables[0].Rows[0]["seo_description"] != null && ds.Tables[0].Rows[0]["seo_description"].ToString() != "")
                {
                    model.seo_description = ds.Tables[0].Rows[0]["seo_description"].ToString();
                }

                if (ds.Tables[0].Rows[0]["ico_url"] != null && ds.Tables[0].Rows[0]["ico_url"].ToString() != "")
                {
                    model.ico_url = ds.Tables[0].Rows[0]["ico_url"].ToString();
                }

                if (ds.Tables[0].Rows[0]["wid"] != null && ds.Tables[0].Rows[0]["wid"].ToString() != "")
                {
                    model.wid = int.Parse(ds.Tables[0].Rows[0]["wid"].ToString());
                }


                return(model);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.wx_book_category model)
        {
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("insert into wx_book_category(");
                        strSql.Append("title,parent_id,class_list,class_layer,sort_id,link_url,img_url,class_content,seo_title,seo_keywords,seo_description,wid,ico_url)");
                        strSql.Append(" values (");
                        strSql.Append("@title,@parent_id,@class_list,@class_layer,@sort_id,@link_url,@img_url,@class_content,@seo_title,@seo_keywords,@seo_description,@wid,@ico_url)");
                        strSql.Append(";select @@IDENTITY");
                        SqlParameter[] parameters =
                        {
                            new SqlParameter("@title",           SqlDbType.NVarChar, 100),
                            new SqlParameter("@parent_id",       SqlDbType.Int,        4),
                            new SqlParameter("@class_list",      SqlDbType.NVarChar, 500),
                            new SqlParameter("@class_layer",     SqlDbType.Int,        4),
                            new SqlParameter("@sort_id",         SqlDbType.Int,        4),
                            new SqlParameter("@link_url",        SqlDbType.NVarChar, 255),
                            new SqlParameter("@img_url",         SqlDbType.NVarChar, 255),
                            new SqlParameter("@class_content",   SqlDbType.NText),
                            new SqlParameter("@seo_title",       SqlDbType.NVarChar, 255),
                            new SqlParameter("@seo_keywords",    SqlDbType.NVarChar, 255),
                            new SqlParameter("@seo_description", SqlDbType.NVarChar, 255),
                            new SqlParameter("@wid",             SqlDbType.Int,        4),
                            new SqlParameter("@ico_url",         SqlDbType.NVarChar, 500)
                        };
                        parameters[0].Value  = model.title;
                        parameters[1].Value  = model.parent_id;
                        parameters[2].Value  = model.class_list;
                        parameters[3].Value  = model.class_layer;
                        parameters[4].Value  = model.sort_id;
                        parameters[5].Value  = model.link_url;
                        parameters[6].Value  = model.img_url;
                        parameters[7].Value  = model.class_content;
                        parameters[8].Value  = model.seo_title;
                        parameters[9].Value  = model.seo_keywords;
                        parameters[10].Value = model.seo_description;
                        parameters[11].Value = model.wid;
                        parameters[12].Value = model.ico_url;
                        object obj = DbHelperSQL.GetSingle(conn, trans, strSql.ToString(), parameters); //带事务
                        model.id = Convert.ToInt32(obj);

                        #region  //图片相册
                        if (model.albums != null)
                        {
                            StringBuilder strSql2;
                            foreach (Model.wx_book_albums modelt in model.albums)
                            {
                                strSql2 = new StringBuilder();
                                strSql2.Append("insert into  wx_book_albums(");
                                strSql2.Append("classId,thumb_path,original_path,remark,add_time,wid)");
                                strSql2.Append(" values (");
                                strSql2.Append("@classId,@thumb_path,@original_path,@remark,@add_time,@wid)");
                                SqlParameter[] parameters2 =
                                {
                                    new SqlParameter("@classId",       SqlDbType.Int,        4),
                                    new SqlParameter("@thumb_path",    SqlDbType.NVarChar, 255),
                                    new SqlParameter("@original_path", SqlDbType.NVarChar, 255),
                                    new SqlParameter("@remark",        SqlDbType.NVarChar, 500),
                                    new SqlParameter("@add_time",      SqlDbType.DateTime,  30),
                                    new SqlParameter("@wid",           SqlDbType.Int, 4)
                                };
                                parameters2[0].Value = model.id;
                                parameters2[1].Value = modelt.thumb_path;
                                parameters2[2].Value = modelt.original_path;
                                parameters2[3].Value = modelt.remark;
                                parameters2[4].Value = DateTime.Now.ToString();
                                parameters2[5].Value = model.wid;
                                DbHelperSQL.GetSingle(strSql2.ToString(), parameters2);
                            }
                        }
                        #endregion



                        if (model.parent_id > 0)
                        {
                            Model.wx_book_category model2 = GetModel(conn, trans, model.parent_id.Value); //带事务
                            model.class_list  = model2.class_list + model.id + ",";
                            model.class_layer = model2.class_layer + 1;
                        }
                        else
                        {
                            model.class_list  = "," + model.id + ",";
                            model.class_layer = 1;
                        }
                        //修改节点列表和深度
                        DbHelperSQL.ExecuteSql(conn, trans, "update wx_book_category set class_list='" + model.class_list + "', class_layer=" + model.class_layer + " where id=" + model.id); //带事务
                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return(0);
                    }
                }
            }
            return(model.id);
        }
Ejemplo n.º 10
0
        private bool DoEdit(int _id)
        {
            try
            {
                BLL.wx_book_category   bll   = new BLL.wx_book_category();
                Model.wx_book_category model = bll.GetModel(_id);

                int parentId = int.Parse(ddlParentId.SelectedValue);

                model.title = txtTitle.Text.Trim();
                //如果选择的父ID不是自己,则更改
                if (parentId != model.id)
                {
                    model.parent_id = parentId;
                }
                model.sort_id         = int.Parse(txtSortId.Text.Trim());
                model.seo_title       = txtSeoTitle.Text;
                model.seo_keywords    = txtSeoKeywords.Text;
                model.seo_description = txtSeoDescription.Text;
                model.link_url        = txtLinkUrl.Text.Trim();
                model.img_url         = txtImgUrl.Text.Trim();
                model.class_content   = txtContent.Text.Trim();
                model.ico_url         = Request.Form["txtImgICO"].Trim();// txtImgICO.Text;


                #region 保存相册====================
                //检查是否有自定义图片
                if (model.albums != null)
                {
                    model.albums.Clear();
                }
                string[] albumArr  = Request.Form.GetValues("hid_photo_name");
                string[] remarkArr = Request.Form.GetValues("hid_photo_remark");
                if (albumArr != null)
                {
                    List <Model.wx_book_albums> ls = new List <Model.wx_book_albums>();
                    for (int i = 0; i < albumArr.Length; i++)
                    {
                        string[] imgArr = albumArr[i].Split('|');
                        int      img_id = Utils.StrToInt(imgArr[0], 0);
                        if (imgArr.Length == 3)
                        {
                            if (!string.IsNullOrEmpty(remarkArr[i]))
                            {
                                ls.Add(new Model.wx_book_albums {
                                    id = img_id, productId = id, original_path = imgArr[1], thumb_path = imgArr[2], remark = remarkArr[i]
                                });
                            }
                            else
                            {
                                ls.Add(new Model.wx_book_albums {
                                    id = img_id, productId = id, original_path = imgArr[1], thumb_path = imgArr[2]
                                });
                            }
                        }
                    }
                    model.albums = ls;
                }

                #endregion
                if (bll.Update(model))
                {
                    AddAdminLog(MXEnums.ActionEnum.Edit.ToString(), "修改预订目分类:" + model.title); //记录日志
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
            return(false);
        }
Ejemplo n.º 11
0
        private bool DoAdd()
        {
            try
            {
                Model.wx_book_category model = new Model.wx_book_category();
                BLL.wx_book_category   bll   = new BLL.wx_book_category();


                model.title           = txtTitle.Text.Trim();
                model.parent_id       = int.Parse(ddlParentId.SelectedValue);
                model.sort_id         = int.Parse(txtSortId.Text.Trim());
                model.seo_title       = txtSeoTitle.Text;
                model.seo_keywords    = txtSeoKeywords.Text;
                model.seo_description = txtSeoDescription.Text;
                model.link_url        = txtLinkUrl.Text.Trim();
                model.img_url         = txtImgUrl.Text.Trim();
                model.class_content   = txtContent.Text.Trim();
                model.ico_url         = Request.Form["txtImgICO"].Trim();// txtImgICO.Text;
                Model.wx_userweixin weixin = GetWeiXinCode();
                model.wid = weixin.id;



                #region 保存相册====================
                //检查是否有自定义图片
                string[] albumArr  = Request.Form.GetValues("hid_photo_name");
                string[] remarkArr = Request.Form.GetValues("hid_photo_remark");
                if (albumArr != null && albumArr.Length > 0)
                {
                    List <Model.wx_book_albums> ls = new List <Model.wx_book_albums>();
                    for (int i = 0; i < albumArr.Length; i++)
                    {
                        string[] imgArr = albumArr[i].Split('|');
                        if (imgArr.Length == 3)
                        {
                            if (!string.IsNullOrEmpty(remarkArr[i]))
                            {
                                ls.Add(new Model.wx_book_albums {
                                    original_path = imgArr[1], thumb_path = imgArr[2], remark = remarkArr[i]
                                });
                            }
                            else
                            {
                                ls.Add(new Model.wx_book_albums {
                                    original_path = imgArr[1], thumb_path = imgArr[2]
                                });
                            }
                        }
                    }
                    model.albums = ls;
                }
                #endregion
                if (bll.Add(model) > 0)
                {
                    AddAdminLog(MXEnums.ActionEnum.Add.ToString(), "添加预订分类:" + model.title); //记录日志
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
            return(false);
        }