示例#1
0
 private bool DoAdd()
 {
     try
     {
         Model.area_category model = new Model.area_category();
         BLL.area_category   bll   = new BLL.area_category();
         model.call_index      = txtCallIndex.Text.Trim();
         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.content         = txtContent.Value;
         if (bll.Add(model) > 0)
         {
             AddAdminLog(PLEnums.ActionEnum.Add.ToString(), "添加" + model.title + "地区栏目分类:" + model.title); //记录日志
             return(true);
         }
     }
     catch
     {
         return(false);
     }
     return(false);
 }
示例#2
0
        private bool DoEdit(int _id)
        {
            try
            {
                BLL.area_category   bll   = new BLL.area_category();
                Model.area_category model = bll.GetModel(_id);

                int parentId = int.Parse(ddlParentId.SelectedValue);
                model.call_index = txtCallIndex.Text.Trim();
                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.content         = txtContent.Value;
                if (bll.Update(model))
                {
                    AddAdminLog(PLEnums.ActionEnum.Edit.ToString(), "修改" + model.title + "地区栏目分类:" + model.title); //记录日志
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
            return(false);
        }
示例#3
0
 /// <summary>
 /// 将对象转换为实体
 /// </summary>
 public Model.area_category DataRowToModel(DataRow row)
 {
     Model.area_category model = new Model.area_category();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["title"] != null)
         {
             model.title = row["title"].ToString();
         }
         if (row["call_index"] != null)
         {
             model.call_index = row["call_index"].ToString();
         }
         if (row["parent_id"] != null && row["parent_id"].ToString() != "")
         {
             model.parent_id = int.Parse(row["parent_id"].ToString());
         }
         if (row["class_list"] != null)
         {
             model.class_list = row["class_list"].ToString();
         }
         if (row["class_layer"] != null && row["class_layer"].ToString() != "")
         {
             model.class_layer = int.Parse(row["class_layer"].ToString());
         }
         if (row["sort_id"] != null && row["sort_id"].ToString() != "")
         {
             model.sort_id = int.Parse(row["sort_id"].ToString());
         }
         if (row["link_url"] != null)
         {
             model.link_url = row["link_url"].ToString();
         }
         if (row["img_url"] != null)
         {
             model.img_url = row["img_url"].ToString();
         }
         if (row["content"] != null)
         {
             model.content = row["content"].ToString();
         }
         if (row["seo_title"] != null)
         {
             model.seo_title = row["seo_title"].ToString();
         }
         if (row["seo_keywords"] != null)
         {
             model.seo_keywords = row["seo_keywords"].ToString();
         }
         if (row["seo_description"] != null)
         {
             model.seo_description = row["seo_description"].ToString();
         }
     }
     return(model);
 }
示例#4
0
        /// <summary>
        /// 得到一个对象实体(重载,带事务)
        /// </summary>
        public Model.area_category GetModel(SqlConnection conn, SqlTransaction trans, int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select top 1 id,title,call_index,parent_id,class_list,class_layer,sort_id,link_url,img_url,content,seo_title,seo_keywords,seo_description");
            strSql.Append(" from " + databaseprefix + "area_category ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
示例#5
0
        private void ShowInfo(int _id)
        {
            BLL.area_category   bll   = new BLL.area_category();
            Model.area_category model = bll.GetModel(_id);

            ddlParentId.SelectedValue = model.parent_id.ToString();
            txtCallIndex.Text         = model.call_index;
            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;
            txtContent.Value          = model.content;
        }
示例#6
0
        /// <summary>
        /// 修改子节点的ID列表及深度(自身迭代)
        /// </summary>
        /// <param name="parent_id"></param>
        private void UpdateChilds(SqlConnection conn, SqlTransaction trans, int parent_id)
        {
            //查找父节点信息
            Model.area_category model = GetModel(conn, trans, parent_id);
            if (model != null)
            {
                //查找子节点
                string  strSql = "select id from " + databaseprefix + "area_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 + 1;
                    DbHelperSQL.ExecuteSql(conn, trans, "update " + databaseprefix + "area_category set class_list='" + class_list + "', class_layer=" + class_layer + " where id=" + id); //带事务

                    //调用自身迭代
                    this.UpdateChilds(conn, trans, id); //带事务
                }
            }
        }
示例#7
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.area_category model)
 {
     return(dal.Update(model));
 }
示例#8
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Model.area_category model)
 {
     return(dal.Add(model));
 }
示例#9
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.area_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 " + databaseprefix + "area_category(");
                        strSql.Append("title,call_index,parent_id,class_list,class_layer,sort_id,link_url,img_url,content,seo_title,seo_keywords,seo_description)");
                        strSql.Append(" values (");
                        strSql.Append("@title,@call_index,@parent_id,@class_list,@class_layer,@sort_id,@link_url,@img_url,@content,@seo_title,@seo_keywords,@seo_description)");
                        strSql.Append(";select @@IDENTITY");
                        SqlParameter[] parameters =
                        {
                            new SqlParameter("@title",           SqlDbType.NVarChar, 100),
                            new SqlParameter("@call_index",      SqlDbType.NVarChar,  50),
                            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("@content",         SqlDbType.NText),
                            new SqlParameter("@seo_title",       SqlDbType.NVarChar, 255),
                            new SqlParameter("@seo_keywords",    SqlDbType.NVarChar, 255),
                            new SqlParameter("@seo_description", SqlDbType.NVarChar, 255)
                        };
                        parameters[0].Value  = model.title;
                        parameters[1].Value  = model.call_index;
                        parameters[2].Value  = model.parent_id;
                        parameters[3].Value  = model.class_list;
                        parameters[4].Value  = model.class_layer;
                        parameters[5].Value  = model.sort_id;
                        parameters[6].Value  = model.link_url;
                        parameters[7].Value  = model.img_url;
                        parameters[8].Value  = model.content;
                        parameters[9].Value  = model.seo_title;
                        parameters[10].Value = model.seo_keywords;
                        parameters[11].Value = model.seo_description;

                        object obj = DbHelperSQL.GetSingle(conn, trans, strSql.ToString(), parameters); //带事务
                        model.id = Convert.ToInt32(obj);

                        if (model.parent_id > 0)
                        {
                            Model.area_category model2 = GetModel(conn, trans, model.parent_id); //带事务
                            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 " + databaseprefix + "area_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);
        }
示例#10
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.area_category model)
        {
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        //先判断选中的父节点是否被包含
                        if (IsContainNode(model.id, model.parent_id))
                        {
                            //查找旧数据
                            Model.area_category oldModel = GetModel(model.id);
                            //查找旧父节点数据
                            string class_list  = "," + model.parent_id + ",";
                            int    class_layer = 1;
                            if (oldModel.parent_id > 0)
                            {
                                Model.area_category oldParentModel = GetModel(conn, trans, oldModel.parent_id); //带事务
                                class_list  = oldParentModel.class_list + model.parent_id + ",";
                                class_layer = oldParentModel.class_layer + 1;
                            }
                            //先提升选中的父节点
                            DbHelperSQL.ExecuteSql(conn, trans, "update " + databaseprefix + "area_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);                                                                                                                                                                              //带事务
                        }
                        //更新子节点
                        if (model.parent_id > 0)
                        {
                            Model.area_category model2 = GetModel(conn, trans, model.parent_id); //带事务
                            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 " + databaseprefix + "area_category set ");
                        strSql.Append("title=@title,");
                        strSql.Append("call_index=@call_index,");
                        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("content=@content,");
                        strSql.Append("seo_title=@seo_title,");
                        strSql.Append("seo_keywords=@seo_keywords,");
                        strSql.Append("seo_description=@seo_description");
                        strSql.Append(" where id=@id");
                        SqlParameter[] parameters =
                        {
                            new SqlParameter("@title",           SqlDbType.NVarChar, 100),
                            new SqlParameter("@call_index",      SqlDbType.NVarChar,  50),
                            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("@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("@id",              SqlDbType.Int, 4)
                        };
                        parameters[0].Value  = model.title;
                        parameters[1].Value  = model.call_index;
                        parameters[2].Value  = model.parent_id;
                        parameters[3].Value  = model.class_list;
                        parameters[4].Value  = model.class_layer;
                        parameters[5].Value  = model.sort_id;
                        parameters[6].Value  = model.link_url;
                        parameters[7].Value  = model.img_url;
                        parameters[8].Value  = model.content;
                        parameters[9].Value  = model.seo_title;
                        parameters[10].Value = model.seo_keywords;
                        parameters[11].Value = model.seo_description;
                        parameters[12].Value = model.id;
                        DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters);

                        //更新子节点
                        UpdateChilds(conn, trans, model.id);
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        return(false);
                    }
                }
            }
            return(true);
        }