Exemple #1
0
        //批量删除
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            ChkAdminLevel("site_channel_list", DTEnums.ActionEnum.Delete.ToString()); //检查权限
            int sucCount   = 0;
            int errorCount = 0;

            BLL.channel bll = new BLL.channel();
            for (int i = 0; i < rptList.Items.Count; i++)
            {
                int      id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value);
                CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId");
                if (cb.Checked)
                {
                    //检查该频道下是否还有文章
                    int articleCount = new BLL.article().GetCount("channel_id=" + id);
                    if (articleCount > 0)
                    {
                        errorCount += 1;
                        continue;
                    }
                    Model.channel model = bll.GetModel(id);
                    if (bll.Delete(id))
                    {
                        sucCount += 1;
                        //删除URL配置
                        new BLL.url_rewrite().Remove("channel", model.name);
                    }
                    else
                    {
                        errorCount += 1;
                    }
                }
            }
            AddAdminLog(DTEnums.ActionEnum.Delete.ToString(), "删除频道成功" + sucCount + "条,失败" + errorCount + "条"); //记录日志
            JscriptMsg("删除成功" + sucCount + "条,失败" + errorCount + "条!",
                       Utils.CombUrlTxt("channel_list.aspx", "category_id={0}&keywords={1}", this.category_id.ToString(), this.keywords), "Success", "parent.loadMenuTree");
        }
Exemple #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.channel GetViewModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select top 1 id,site_id,name,title,seo_title,seo_keywords,seo_description from " + databaseprefix + "channel ");
            strSql.Append(" where id=@id ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToViewModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.channel GetModel(string channel_name)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select top 1 id,site_id,name,title,is_albums,is_attach,is_spec,sort_id from " + databaseprefix + "channel ");
            strSql.Append(" where name=@channel_name ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@channel_name", SqlDbType.VarChar, 50)
            };
            parameters[0].Value = channel_name;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Exemple #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.channel GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select top 1 id,site_id,[name],title,is_albums,is_attach,is_spec,sort_id from " + databaseprefix + "channel ");
            strSql.Append(" where id=@id ");
            OleDbParameter[] parameters =
            {
                new OleDbParameter("@id", OleDbType.Integer, 4)
            };
            parameters[0].Value = id;

            Model.channel model = new Model.channel();
            DataSet       ds    = DbHelperOleDb.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Exemple #5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.channel GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select top 1 " + this.column + " from " + databaseprefix + "channel ");
            strSql.Append(" where id=@id ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Exemple #6
0
        /// <summary>
        /// 得到一个对象实体,带事务
        /// </summary>
        public Model.channel GetModel(MySqlConnection conn, MySqlTransaction trans, int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id,site_id,name,title,is_albums,is_attach,is_spec,sort_id from " + databaseprefix + "channel ");
            strSql.Append(" where id=@id limit 1");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@id", MySqlDbType.Int32, 4)
            };
            parameters[0].Value = id;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(conn, trans, ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Exemple #7
0
        /// <summary>
        /// 增加一条数据及其子表
        /// </summary>
        public int Add(Model.channel 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 + "channel(");
                        strSql.Append("category_id,name,title,is_albums,is_attach,is_group_price,page_size,sort_id)");
                        strSql.Append(" values (");
                        strSql.Append("@category_id,@name,@title,@is_albums,@is_attach,@is_group_price,@page_size,@sort_id)");
                        strSql.Append(";select @@IDENTITY");
                        SqlParameter[] parameters = {
					            new SqlParameter("@category_id", SqlDbType.Int,4),
					            new SqlParameter("@name", SqlDbType.VarChar,50),
					            new SqlParameter("@title", SqlDbType.VarChar,100),
                                new SqlParameter("@is_albums", SqlDbType.TinyInt,1),
					            new SqlParameter("@is_attach", SqlDbType.TinyInt,1),
					            new SqlParameter("@is_group_price", SqlDbType.TinyInt,1),
					            new SqlParameter("@page_size", SqlDbType.Int,4),
					            new SqlParameter("@sort_id", SqlDbType.Int,4),
                                new SqlParameter("@ReturnValue",SqlDbType.Int)};
                        parameters[0].Value = model.category_id;
                        parameters[1].Value = model.name;
                        parameters[2].Value = model.title;
                        parameters[3].Value = model.is_albums;
                        parameters[4].Value = model.is_attach;
                        parameters[5].Value = model.is_group_price;
                        parameters[6].Value = model.page_size;
                        parameters[7].Value = model.sort_id;
                        object obj = DbHelperSQL.GetSingle(conn, trans, strSql.ToString(), parameters); //带事务
                        model.id = Convert.ToInt32(obj);

                        //扩展字段
                        if (model.channel_fields != null)
                        {
                            StringBuilder strSql2;
                            foreach (Model.channel_field modelt in model.channel_fields)
                            {
                                strSql2 = new StringBuilder();
                                strSql2.Append("insert into " + databaseprefix + "channel_field(");
                                strSql2.Append("channel_id,field_id)");
                                strSql2.Append(" values (");
                                strSql2.Append("@channel_id,@field_id)");
                                SqlParameter[] parameters2 = {
					                    new SqlParameter("@channel_id", SqlDbType.Int,4),
					                    new SqlParameter("@field_id", SqlDbType.Int,4)};
                                parameters2[0].Value = model.id;
                                parameters2[1].Value = modelt.field_id;
                                DbHelperSQL.ExecuteSql(conn, trans, strSql2.ToString(), parameters2);
                            }
                        }

                        //添加视图
                        StringBuilder strSql3 = new StringBuilder();
                        strSql3.Append("CREATE VIEW view_channel_" + model.name + " as");
                        strSql3.Append(" SELECT " + databaseprefix + "article.*");
                        if (model.channel_fields != null)
                        {
                            foreach (Model.channel_field modelt in model.channel_fields)
                            {
                                Model.article_attribute_field fieldModel = new DAL.article_attribute_field(databaseprefix).GetModel(modelt.field_id);
                                if (fieldModel != null)
                                {
                                    strSql3.Append("," + databaseprefix + "article_attribute_value." + fieldModel.name);
                                }
                            }
                        }
                        strSql3.Append(" FROM " + databaseprefix + "article_attribute_value INNER JOIN");
                        strSql3.Append(" " + databaseprefix + "article ON " + databaseprefix + "article_attribute_value.article_id = " + databaseprefix + "article.id");
                        strSql3.Append(" WHERE " + databaseprefix + "article.channel_id=" + model.id);
                        DbHelperSQL.ExecuteSql(conn, trans, strSql3.ToString());

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return 0;
                    }
                }
            }
            return model.id;
        }
Exemple #8
0
        /// <summary>
        /// 根据频道的名称查询ID
        /// </summary>
        public Model.channel GetModel(string channel_name)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,category_id,name,title,is_albums,is_attach,is_group_price,page_size,sort_id from " + databaseprefix + "channel ");
            strSql.Append(" where name=@name ");
            SqlParameter[] parameters = {
					new SqlParameter("@name", SqlDbType.VarChar,250)};
            parameters[0].Value = channel_name;

            Model.channel model = new Model.channel();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                #region  父表信息
                if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["category_id"].ToString() != "")
                {
                    model.category_id = int.Parse(ds.Tables[0].Rows[0]["category_id"].ToString());
                }
                model.name = ds.Tables[0].Rows[0]["name"].ToString();
                model.title = ds.Tables[0].Rows[0]["title"].ToString();
                if (ds.Tables[0].Rows[0]["is_albums"].ToString() != "")
                {
                    model.is_albums = int.Parse(ds.Tables[0].Rows[0]["is_albums"].ToString());
                }
                if (ds.Tables[0].Rows[0]["is_attach"].ToString() != "")
                {
                    model.is_attach = int.Parse(ds.Tables[0].Rows[0]["is_attach"].ToString());
                }
                if (ds.Tables[0].Rows[0]["is_group_price"].ToString() != "")
                {
                    model.is_group_price = int.Parse(ds.Tables[0].Rows[0]["is_group_price"].ToString());
                }
                if (ds.Tables[0].Rows[0]["page_size"].ToString() != "")
                {
                    model.page_size = int.Parse(ds.Tables[0].Rows[0]["page_size"].ToString());
                }
                if (ds.Tables[0].Rows[0]["sort_id"].ToString() != "")
                {
                    model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString());
                }
                #endregion  父表信息end

                #region  子表信息
                StringBuilder strSql2 = new StringBuilder();
                strSql2.Append("select id,channel_id,field_id from " + databaseprefix + "channel_field ");
                strSql2.Append(" where channel_id=@channel_id ");
                SqlParameter[] parameters2 = {
					new SqlParameter("@channel_id", SqlDbType.Int,4)};
                parameters2[0].Value = model.id;

                DataSet ds2 = DbHelperSQL.Query(strSql2.ToString(), parameters2);
                if (ds2.Tables[0].Rows.Count > 0)
                {
                    int i = ds2.Tables[0].Rows.Count;
                    List<Model.channel_field> models = new List<Model.channel_field>();
                    Model.channel_field modelt;
                    for (int n = 0; n < i; n++)
                    {
                        modelt = new Model.channel_field();
                        if (ds2.Tables[0].Rows[n]["id"].ToString() != "")
                        {
                            modelt.id = int.Parse(ds2.Tables[0].Rows[n]["id"].ToString());
                        }
                        if (ds2.Tables[0].Rows[n]["channel_id"].ToString() != "")
                        {
                            modelt.channel_id = int.Parse(ds2.Tables[0].Rows[n]["channel_id"].ToString());
                        }
                        if (ds2.Tables[0].Rows[n]["field_id"].ToString() != "")
                        {
                            modelt.field_id = int.Parse(ds2.Tables[0].Rows[n]["field_id"].ToString());
                        }
                        models.Add(modelt);
                    }
                    model.channel_fields = models;
                }
                #endregion  子表信息end

                return model;
            }
            else
            {
                return null;
            }
        }
Exemple #9
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.channel GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 id,site_id,[name],title,is_albums,is_attach,is_spec,sort_id from " + databaseprefix + "channel ");
            strSql.Append(" where id=@id ");
            OleDbParameter[] parameters = {
                    new OleDbParameter("@id", OleDbType.Integer,4)};
            parameters[0].Value = id;

            Model.channel model = new Model.channel();
            DataSet ds = DbHelperOleDb.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }
        private bool DoAdd()
        {
            Model.channel model = new Model.channel();
            BLL.channel   bll   = new BLL.channel();

            model.site_id = Utils.StrToInt(ddlSiteId.SelectedValue, 0);
            model.name    = txtName.Text.Trim();
            model.title   = txtTitle.Text.Trim();
            if (cbIsAlbums.Checked == true)
            {
                model.is_albums = 1;
            }
            if (cbIsAttach.Checked == true)
            {
                model.is_attach = 1;
            }
            if (cbIsSpec.Checked == true)
            {
                model.is_spec = 1;
            }
            model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99);

            //扩展
            if (cbIsComment.Checked == true)
            {
                model.is_comment = 1;
            }
            if (cbIsAttr.Checked == true)
            {
                model.is_attribute = 1;
            }
            if (cbIsRecycle.Checked == true)
            {
                model.is_recycle = 1;
            }
            model.is_type = Utils.StrToInt(rblIsType.SelectedValue, 0);
            model.height  = int.Parse(txtHeight.Text.Trim(), 0);
            model.width   = int.Parse(txtWidth.Text.Trim(), 0);

            //SEO优化
            model.seo_title       = txtSeoTitle.Text.Trim();
            model.seo_keywords    = txtSeoKeywords.Text.Trim().Replace(",", ",");
            model.seo_description = txtSeoDescription.Text.Trim();

            //添加频道扩展字段
            List <Model.channel_field> ls = new List <Model.channel_field>();

            for (int i = 0; i < cblAttributeField.Items.Count; i++)
            {
                if (cblAttributeField.Items[i].Selected)
                {
                    string[] fieldIdArr = cblAttributeField.Items[i].Value.Split(','); //分解出ID值
                    ls.Add(new Model.channel_field {
                        field_id = Utils.StrToInt(fieldIdArr[1], 0)
                    });
                }
            }
            model.channel_fields = ls;

            if (bll.Add(model) < 1)
            {
                return(false);
            }

            #region 保存URL配置
            BLL.url_rewrite urlBll = new BLL.url_rewrite();
            urlBll.Remove("channel", model.name); //先删除
            string[] itemTypeArr     = Request.Form.GetValues("item_type");
            string[] itemNameArr     = Request.Form.GetValues("item_name");
            string[] itemPageArr     = Request.Form.GetValues("item_page");
            string[] itemTempletArr  = Request.Form.GetValues("item_templet");
            string[] itemPageSizeArr = Request.Form.GetValues("item_pagesize");
            string[] itemRewriteArr  = Request.Form.GetValues("item_rewrite");

            if (itemTypeArr != null && itemNameArr != null && itemPageArr != null && itemTempletArr != null && itemPageSizeArr != null && itemRewriteArr != null)
            {
                if ((itemTypeArr.Length == itemNameArr.Length) && (itemNameArr.Length == itemPageArr.Length) && (itemPageArr.Length == itemTempletArr.Length) &&
                    (itemTempletArr.Length == itemPageSizeArr.Length) && (itemPageSizeArr.Length == itemRewriteArr.Length))
                {
                    for (int i = 0; i < itemTypeArr.Length; i++)
                    {
                        Model.url_rewrite urlModel = new Model.url_rewrite();
                        urlModel.name    = itemNameArr[i].Trim();
                        urlModel.type    = itemTypeArr[i].Trim();
                        urlModel.page    = itemPageArr[i].Trim();
                        urlModel.inherit = GetInherit(urlModel.type);
                        urlModel.templet = itemTempletArr[i].Trim();
                        if (Utils.StrToInt(itemPageSizeArr[i].Trim(), 0) > 0)
                        {
                            urlModel.pagesize = itemPageSizeArr[i].Trim();
                        }
                        urlModel.channel = model.name;

                        List <Model.url_rewrite_item> itemLs = new List <Model.url_rewrite_item>();
                        string[] urlRewriteArr = itemRewriteArr[i].Split('&'); //分解URL重写字符串
                        for (int j = 0; j < urlRewriteArr.Length; j++)
                        {
                            string[] urlItemArr = urlRewriteArr[j].Split(',');
                            if (urlItemArr.Length == 3)
                            {
                                itemLs.Add(new Model.url_rewrite_item {
                                    path = urlItemArr[0], pattern = urlItemArr[1], querystring = urlItemArr[2]
                                });
                            }
                        }
                        urlModel.url_rewrite_items = itemLs;
                        urlBll.Add(urlModel);
                    }
                }
            }
            #endregion

            AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加频道" + model.title); //记录日志
            return(true);
        }
Exemple #11
0
        /// <summary>
        /// 增加一条数据及其子表
        /// </summary>
        public int Add(Model.channel model)
        {
            //取得站点对应的导航ID
            int parent_id = new DAL.Mysql.channel_site(databaseprefix).GetSiteNavId(model.site_id);

            if (parent_id == 0)
            {
                return(0);
            }
            using (MySqlConnection conn = new MySqlConnection(DbHelperMySql.connectionString))
            {
                conn.Open();
                using (MySqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("insert into " + databaseprefix + "channel(");
                        strSql.Append("site_id,name,title,is_albums,is_attach,is_spec,sort_id)");
                        strSql.Append(" values (");
                        strSql.Append("@site_id,@name,@title,@is_albums,@is_attach,@is_spec,@sort_id)");
                        MySqlParameter[] parameters =
                        {
                            new MySqlParameter("@site_id",   MySqlDbType.Int32,     4),
                            new MySqlParameter("@name",      MySqlDbType.VarChar,  50),
                            new MySqlParameter("@title",     MySqlDbType.VarChar, 100),
                            new MySqlParameter("@is_albums", MySqlDbType.Int32,     4),
                            new MySqlParameter("@is_attach", MySqlDbType.Int32,     4),
                            new MySqlParameter("@is_spec",   MySqlDbType.Int32,     4),
                            new MySqlParameter("@sort_id",   MySqlDbType.Int32, 4)
                        };
                        parameters[0].Value = model.site_id;
                        parameters[1].Value = model.name;
                        parameters[2].Value = model.title;
                        parameters[3].Value = model.is_albums;
                        parameters[4].Value = model.is_attach;
                        parameters[5].Value = model.is_spec;
                        parameters[6].Value = model.sort_id;
                        DbHelperMySql.ExecuteSql(conn, trans, strSql.ToString(), parameters);
                        //取得新插入的ID
                        model.id = GetMaxId(conn, trans);

                        //扩展字段
                        if (model.channel_fields != null)
                        {
                            StringBuilder strSql2;
                            foreach (Model.channel_field modelt in model.channel_fields)
                            {
                                strSql2 = new StringBuilder();
                                strSql2.Append("insert into " + databaseprefix + "channel_field(");
                                strSql2.Append("channel_id,field_id)");
                                strSql2.Append(" values (");
                                strSql2.Append("@channel_id,@field_id)");
                                MySqlParameter[] parameters2 =
                                {
                                    new MySqlParameter("@channel_id", MySqlDbType.Int32, 4),
                                    new MySqlParameter("@field_id",   MySqlDbType.Int32, 4)
                                };
                                parameters2[0].Value = model.id;
                                parameters2[1].Value = modelt.field_id;
                                DbHelperMySql.ExecuteSql(conn, trans, strSql2.ToString(), parameters2);
                            }
                        }

                        //添加视图
                        StringBuilder strSql3 = new StringBuilder();
                        strSql3.Append("CREATE VIEW view_channel_" + model.name + " as");
                        strSql3.Append(" SELECT " + databaseprefix + "article.*");
                        if (model.channel_fields != null)
                        {
                            foreach (Model.channel_field modelt in model.channel_fields)
                            {
                                Model.article_attribute_field fieldModel = new DAL.Mysql.article_attribute_field(databaseprefix).GetModel(modelt.field_id);
                                if (fieldModel != null)
                                {
                                    strSql3.Append("," + databaseprefix + "article_attribute_value." + fieldModel.name);
                                }
                            }
                        }
                        strSql3.Append(" FROM " + databaseprefix + "article_attribute_value INNER JOIN");
                        strSql3.Append(" " + databaseprefix + "article ON " + databaseprefix + "article_attribute_value.article_id = " + databaseprefix + "article.id");
                        strSql3.Append(" WHERE " + databaseprefix + "article.channel_id=" + model.id);
                        DbHelperMySql.ExecuteSql(conn, trans, strSql3.ToString());

                        //添加导航菜单
                        int newNavId = new DAL.Mysql.navigation(databaseprefix).Add(conn, trans, parent_id, "channel_" + model.name, model.title, "", model.sort_id, model.id, "Show");
                        new DAL.Mysql.navigation(databaseprefix).Add(conn, trans, newNavId, "channel_" + model.name + "_list", "内容管理", "article/article_list.aspx", 99, model.id, "Show,View,Add,Edit,Delete,Audit");
                        new DAL.Mysql.navigation(databaseprefix).Add(conn, trans, newNavId, "channel_" + model.name + "_category", "栏目类别", "article/category_list.aspx", 100, model.id, "Show,View,Add,Edit,Delete");
                        new DAL.Mysql.navigation(databaseprefix).Add(conn, trans, newNavId, "channel_" + model.name + "_comment", "评论管理", "article/comment_list.aspx", 101, model.id, "Show,View,Delete,Reply");

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return(0);
                    }
                }
            }
            return(model.id);
        }
Exemple #12
0
        /// <summary>
        /// 将对象转换实体
        /// </summary>
        public Model.channel DataRowToModel(MySqlConnection conn, MySqlTransaction trans, DataRow row)
        {
            Model.channel model = new Model.channel();
            if (row != null)
            {
                #region 主表信息======================
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.id = int.Parse(row["id"].ToString());
                }
                if (row["site_id"] != null && row["site_id"].ToString() != "")
                {
                    model.site_id = int.Parse(row["site_id"].ToString());
                }
                if (row["name"] != null)
                {
                    model.name = row["name"].ToString();
                }
                if (row["title"] != null)
                {
                    model.title = row["title"].ToString();
                }
                if (row["is_albums"] != null && row["is_albums"].ToString() != "")
                {
                    model.is_albums = int.Parse(row["is_albums"].ToString());
                }
                if (row["is_attach"] != null && row["is_attach"].ToString() != "")
                {
                    model.is_attach = int.Parse(row["is_attach"].ToString());
                }
                if (row["is_spec"] != null && row["is_spec"].ToString() != "")
                {
                    model.is_spec = int.Parse(row["is_spec"].ToString());
                }
                if (row["sort_id"] != null && row["sort_id"].ToString() != "")
                {
                    model.sort_id = int.Parse(row["sort_id"].ToString());
                }
                #endregion

                #region 子表信息======================
                StringBuilder strSql2 = new StringBuilder();
                strSql2.Append("select id,channel_id,field_id from " + databaseprefix + "channel_field ");
                strSql2.Append(" where channel_id=@channel_id limit 1");
                MySqlParameter[] parameters2 =
                {
                    new MySqlParameter("@channel_id", MySqlDbType.Int32, 4)
                };
                parameters2[0].Value = model.id;
                DataSet ds2 = DbHelperMySql.Query(conn, trans, strSql2.ToString(), parameters2);

                if (ds2.Tables[0].Rows.Count > 0)
                {
                    int i = ds2.Tables[0].Rows.Count;
                    List <Model.channel_field> models = new List <Model.channel_field>();
                    Model.channel_field        modelt;
                    for (int n = 0; n < i; n++)
                    {
                        modelt = new Model.channel_field();
                        if (ds2.Tables[0].Rows[n]["id"].ToString() != "")
                        {
                            modelt.id = int.Parse(ds2.Tables[0].Rows[n]["id"].ToString());
                        }
                        if (ds2.Tables[0].Rows[n]["channel_id"].ToString() != "")
                        {
                            modelt.channel_id = int.Parse(ds2.Tables[0].Rows[n]["channel_id"].ToString());
                        }
                        if (ds2.Tables[0].Rows[n]["field_id"].ToString() != "")
                        {
                            modelt.field_id = int.Parse(ds2.Tables[0].Rows[n]["field_id"].ToString());
                        }
                        models.Add(modelt);
                    }
                    model.channel_fields = models;
                }
                #endregion
            }
            return(model);
        }
Exemple #13
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.channel model)
        {
            Model.channel oldModel = GetModel(model.id); //旧的数据
            //取得站点对应的导航ID
            int parent_id = new DAL.channel_site(databaseprefix).GetSiteNavId(model.site_id);

            if (parent_id == 0)
            {
                return(false);
            }
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("update [" + databaseprefix + "channel] set ");
                        strSql.Append("site_id=@site_id,");
                        strSql.Append("name=@name,");
                        strSql.Append("title=@title,");
                        strSql.Append("is_albums=@is_albums,");
                        strSql.Append("is_attach=@is_attach,");
                        strSql.Append("is_spec=@is_spec,");
                        strSql.Append("sort_id=@sort_id,");
                        strSql.Append("seo_title=@seo_title,");
                        strSql.Append("seo_keywords=@seo_keywords,");
                        strSql.Append("seo_description=@seo_description,");
                        strSql.Append("is_type=@is_type,");
                        strSql.Append("is_attribute=@is_attribute,");
                        strSql.Append("is_comment=@is_comment,");
                        strSql.Append("height=@height,");
                        strSql.Append("width=@width,");
                        strSql.Append("is_recycle=@is_recycle");
                        strSql.Append(" where id=@id");
                        SqlParameter[] parameters =
                        {
                            new SqlParameter("@site_id",         SqlDbType.Int,        4),
                            new SqlParameter("@name",            SqlDbType.VarChar,   50),
                            new SqlParameter("@title",           SqlDbType.VarChar,  100),
                            new SqlParameter("@is_albums",       SqlDbType.TinyInt,    1),
                            new SqlParameter("@is_attach",       SqlDbType.TinyInt,    1),
                            new SqlParameter("@is_spec",         SqlDbType.TinyInt,    1),
                            new SqlParameter("@sort_id",         SqlDbType.Int,        4),
                            new SqlParameter("@seo_title",       SqlDbType.NVarChar, 255),
                            new SqlParameter("@seo_keywords",    SqlDbType.NVarChar, 255),
                            new SqlParameter("@seo_description", SqlDbType.NVarChar, 255),
                            new SqlParameter("@is_type",         SqlDbType.TinyInt,    1),
                            new SqlParameter("@is_attribute",    SqlDbType.TinyInt,    1),
                            new SqlParameter("@is_comment",      SqlDbType.TinyInt,    1),
                            new SqlParameter("@height",          SqlDbType.Int,        4),
                            new SqlParameter("@width",           SqlDbType.Int,        4),
                            new SqlParameter("@is_recycle",      SqlDbType.TinyInt,    1),
                            new SqlParameter("@id",              SqlDbType.Int, 4)
                        };
                        parameters[0].Value  = model.site_id;
                        parameters[1].Value  = model.name;
                        parameters[2].Value  = model.title;
                        parameters[3].Value  = model.is_albums;
                        parameters[4].Value  = model.is_attach;
                        parameters[5].Value  = model.is_spec;
                        parameters[6].Value  = model.sort_id;
                        parameters[7].Value  = model.seo_title;
                        parameters[8].Value  = model.seo_keywords;
                        parameters[9].Value  = model.seo_description;
                        parameters[10].Value = model.is_type;
                        parameters[11].Value = model.is_attribute;
                        parameters[12].Value = model.is_comment;
                        parameters[13].Value = model.height;
                        parameters[14].Value = model.width;
                        parameters[15].Value = model.is_recycle;
                        parameters[16].Value = model.id;
                        DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters);

                        //删除已移除的扩展字段
                        FieldDelete(conn, trans, model.channel_fields, model.id);
                        //添加扩展字段
                        if (model.channel_fields != null)
                        {
                            StringBuilder strSql2;
                            foreach (Model.channel_field modelt in model.channel_fields)
                            {
                                strSql2 = new StringBuilder();
                                Model.channel_field fieldModel = null;
                                if (oldModel.channel_fields != null)
                                {
                                    fieldModel = oldModel.channel_fields.Find(p => p.field_id == modelt.field_id); //查找是否已经存在
                                }
                                if (fieldModel == null)                                                            //如果不存在则添加
                                {
                                    strSql2.Append("insert into " + databaseprefix + "channel_field(");
                                    strSql2.Append("channel_id,field_id)");
                                    strSql2.Append(" values (");
                                    strSql2.Append("@channel_id,@field_id)");
                                    SqlParameter[] parameters2 =
                                    {
                                        new SqlParameter("@channel_id", SqlDbType.Int, 4),
                                        new SqlParameter("@field_id",   SqlDbType.Int, 4)
                                    };
                                    parameters2[0].Value = modelt.channel_id;
                                    parameters2[1].Value = modelt.field_id;
                                    DbHelperSQL.ExecuteSql(conn, trans, strSql2.ToString(), parameters2);
                                }
                            }
                        }
                        //删除旧视图重建新视图
                        RehabChannelViews(conn, trans, model, oldModel.name);

                        int            newNavId = 0;
                        DAL.navigation dal      = new DAL.navigation(databaseprefix);
                        if (!dal.Exists("channel_" + oldModel.name))
                        {
                            //添加导航菜单
                            newNavId = dal.Add(conn, trans, parent_id, "channel_" + model.name, model.title, "", model.sort_id, model.id, "Show");
                            dal.Add(conn, trans, newNavId, "channel_" + model.name + "_list", "内容管理", "article/article_list.aspx", 99, model.id, "Show,View,Add,Edit,Delete,Audit");
                            dal.Add(conn, trans, newNavId, "channel_" + model.name + "_category", "栏目类别", "article/category_list.aspx", 100, model.id, "Show,View,Add,Edit,Delete");
                            //是否开启评论
                            if (model.is_comment > 0)
                            {
                                dal.Add(conn, trans, newNavId, "channel_" + model.name + "_comment", "评论管理", "article/comment_list.aspx", 101, model.id, "Show,View,Delete,Audit,Reply");
                            }
                            //是否开启回收站
                            if (model.is_recycle > 0)
                            {
                                dal.Add(conn, trans, newNavId, "channel_" + model.name + "_recycle", "回收站", "article/recycle_list.aspx", 102, model.id, "Show,View,Edit,Delete,Audit");
                            }
                        }
                        else
                        {
                            //修改菜单
                            newNavId = new DAL.navigation(databaseprefix).GetId(conn, trans, "channel_" + oldModel.name);
                            dal.Update(conn, trans, "channel_" + oldModel.name, parent_id, "channel_" + model.name, model.title, model.sort_id);
                            dal.Update(conn, trans, "channel_" + oldModel.name + "_list", "channel_" + model.name + "_list");         //内容管理
                            dal.Update(conn, trans, "channel_" + oldModel.name + "_category", "channel_" + model.name + "_category"); //栏目类别
                            //是否开启评论
                            if (model.is_comment > 0)
                            {
                                if (Convert.ToInt32(DbHelperSQL.GetSingle(conn, trans, "select count(*) as H from [" + databaseprefix + "navigation] where name='channel_" + oldModel.name + "_comment'")) == 0)
                                {
                                    dal.Add(conn, trans, newNavId, "channel_" + model.name + "_comment", "评论管理", "article/comment_list.aspx", 101, model.id, "Show,View,Delete,Audit,Reply");
                                }
                                else
                                {
                                    dal.Update(conn, trans, "channel_" + oldModel.name + "_comment", "channel_" + model.name + "_comment"); //评论管理
                                }
                            }
                            else
                            {
                                dal.Delete(conn, trans, "channel_" + oldModel.name + "_comment");
                            }
                            //是否开启回收站
                            if (model.is_recycle > 0)
                            {
                                if (Convert.ToInt32(DbHelperSQL.GetSingle(conn, trans, "select count(*) as H from [" + databaseprefix + "navigation] where name='channel_" + oldModel.name + "_recycle'")) == 0)
                                {
                                    dal.Add(conn, trans, newNavId, "channel_" + model.name + "_recycle", "回收站", "article/recycle_list.aspx", 102, model.id, "Show,View,Edit,Delete,Audit");
                                }
                                else
                                {
                                    dal.Update(conn, trans, "channel_" + oldModel.name + "_recycle", "channel_" + model.name + "_recycle"); //回收站
                                }
                            }
                            else
                            {
                                dal.Delete(conn, trans, "channel_" + oldModel.name + "_recycle");
                            }
                        }
                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemple #14
0
        /// <summary>
        /// 增加一条数据及其子表
        /// </summary>
        public int Add(Model.channel model)
        {
            //取得站点对应的导航ID
            int parent_id = new DAL.channel_site(databaseprefix).GetSiteNavId(model.site_id);

            if (parent_id == 0)
            {
                return(0);
            }
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("insert into [" + databaseprefix + "channel](");
                        strSql.Append("site_id,name,title,is_albums,is_attach,is_spec,sort_id,seo_title,seo_keywords,seo_description,is_type,is_attribute,is_comment,height,width,is_recycle");
                        strSql.Append(") values(");
                        strSql.Append("@site_id,@name,@title,@is_albums,@is_attach,@is_spec,@sort_id,@seo_title,@seo_keywords,@seo_description,@is_type,@is_attribute,@is_comment,@height,@width,@is_recycle)");
                        strSql.Append(";select @@IDENTITY");
                        SqlParameter[] parameters =
                        {
                            new SqlParameter("@site_id",         SqlDbType.Int,        4),
                            new SqlParameter("@name",            SqlDbType.VarChar,   50),
                            new SqlParameter("@title",           SqlDbType.VarChar,  100),
                            new SqlParameter("@is_albums",       SqlDbType.TinyInt,    1),
                            new SqlParameter("@is_attach",       SqlDbType.TinyInt,    1),
                            new SqlParameter("@is_spec",         SqlDbType.TinyInt,    1),
                            new SqlParameter("@sort_id",         SqlDbType.Int,        4),
                            new SqlParameter("@seo_title",       SqlDbType.NVarChar, 255),
                            new SqlParameter("@seo_keywords",    SqlDbType.NVarChar, 255),
                            new SqlParameter("@seo_description", SqlDbType.NVarChar, 255),
                            new SqlParameter("@is_type",         SqlDbType.TinyInt,    1),
                            new SqlParameter("@is_attribute",    SqlDbType.TinyInt,    1),
                            new SqlParameter("@is_comment",      SqlDbType.TinyInt,    1),
                            new SqlParameter("@height",          SqlDbType.Int,        4),
                            new SqlParameter("@width",           SqlDbType.Int,        4),
                            new SqlParameter("@is_recycle",      SqlDbType.TinyInt, 1)
                        };
                        parameters[0].Value  = model.site_id;
                        parameters[1].Value  = model.name;
                        parameters[2].Value  = model.title;
                        parameters[3].Value  = model.is_albums;
                        parameters[4].Value  = model.is_attach;
                        parameters[5].Value  = model.is_spec;
                        parameters[6].Value  = model.sort_id;
                        parameters[7].Value  = model.seo_title;
                        parameters[8].Value  = model.seo_keywords;
                        parameters[9].Value  = model.seo_description;
                        parameters[10].Value = model.is_type;
                        parameters[11].Value = model.is_attribute;
                        parameters[12].Value = model.is_comment;
                        parameters[13].Value = model.height;
                        parameters[14].Value = model.width;
                        parameters[15].Value = model.is_recycle;
                        object obj = DbHelperSQL.GetSingle(conn, trans, strSql.ToString(), parameters); //带事务
                        model.id = Convert.ToInt32(obj);

                        //扩展字段
                        if (model.channel_fields != null)
                        {
                            StringBuilder strSql2;
                            foreach (Model.channel_field modelt in model.channel_fields)
                            {
                                strSql2 = new StringBuilder();
                                strSql2.Append("insert into " + databaseprefix + "channel_field(");
                                strSql2.Append("channel_id,field_id)");
                                strSql2.Append(" values (");
                                strSql2.Append("@channel_id,@field_id)");
                                SqlParameter[] parameters2 =
                                {
                                    new SqlParameter("@channel_id", SqlDbType.Int, 4),
                                    new SqlParameter("@field_id",   SqlDbType.Int, 4)
                                };
                                parameters2[0].Value = model.id;
                                parameters2[1].Value = modelt.field_id;
                                DbHelperSQL.ExecuteSql(conn, trans, strSql2.ToString(), parameters2);
                            }
                        }

                        //添加视图
                        StringBuilder strSql3 = new StringBuilder();
                        strSql3.Append("CREATE VIEW view_channel_" + model.name + " as");
                        strSql3.Append(" SELECT " + databaseprefix + "article.*");
                        if (model.channel_fields != null)
                        {
                            foreach (Model.channel_field modelt in model.channel_fields)
                            {
                                Model.article_attribute_field fieldModel = new DAL.article_attribute_field(databaseprefix).GetModel(modelt.field_id);
                                if (fieldModel != null)
                                {
                                    strSql3.Append("," + databaseprefix + "article_attribute_value." + fieldModel.name);
                                }
                            }
                        }
                        strSql3.Append(" FROM " + databaseprefix + "article_attribute_value INNER JOIN");
                        strSql3.Append(" " + databaseprefix + "article ON " + databaseprefix + "article_attribute_value.article_id = " + databaseprefix + "article.id");
                        strSql3.Append(" WHERE " + databaseprefix + "article.channel_id=" + model.id);
                        DbHelperSQL.ExecuteSql(conn, trans, strSql3.ToString());

                        //添加导航菜单
                        DAL.navigation dal      = new DAL.navigation(databaseprefix);
                        int            newNavId = dal.Add(conn, trans, parent_id, "channel_" + model.name, model.title, "", model.sort_id, model.id, "Show");
                        dal.Add(conn, trans, newNavId, "channel_" + model.name + "_list", "内容管理", "article/article_list.aspx", 99, model.id, "Show,View,Add,Edit,Delete,Audit");
                        dal.Add(conn, trans, newNavId, "channel_" + model.name + "_category", "栏目类别", "article/category_list.aspx", 100, model.id, "Show,View,Add,Edit,Delete");
                        if (model.is_comment == 1)
                        {
                            dal.Add(conn, trans, newNavId, "channel_" + model.name + "_comment", "评论管理", "article/comment_list.aspx", 101, model.id, "Show,View,Delete,Reply");
                        }
                        if (model.is_recycle == 1)
                        {
                            dal.Add(conn, trans, newNavId, "channel_" + model.name + "_recycle", "回收站", "article/recycle_list.aspx", 102, model.id, "Show,View,Edit,Delete,Audit");
                        }
                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return(0);
                    }
                }
            }
            return(model.id);
        }
Exemple #15
0
        /// <summary>
        /// 得到一个对象实体,带事务
        /// </summary>
        public Model.channel GetModel(SqlConnection conn, SqlTransaction trans, int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 id,site_id,name,title,is_albums,is_attach,is_spec,sort_id from " + databaseprefix + "channel ");
            strSql.Append(" where id=@id ");
            SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)};
            parameters[0].Value = id;

            Model.channel model = new Model.channel();
            DataSet ds = DbHelperSQL.Query(conn, trans, strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(conn, trans, ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }
Exemple #16
0
        /// <summary>
        /// 将对象转换实体
        /// </summary>
        public Model.channel DataRowToModel(SqlConnection conn, SqlTransaction trans, DataRow row)
        {
            Model.channel model = new Model.channel();
            if (row != null)
            {
                #region 主表信息======================
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.id = int.Parse(row["id"].ToString());
                }
                if (row["site_id"] != null && row["site_id"].ToString() != "")
                {
                    model.site_id = int.Parse(row["site_id"].ToString());
                }
                if (row["name"] != null)
                {
                    model.name = row["name"].ToString();
                }
                if (row["title"] != null)
                {
                    model.title = row["title"].ToString();
                }
                if (row["is_albums"] != null && row["is_albums"].ToString() != "")
                {
                    model.is_albums = int.Parse(row["is_albums"].ToString());
                }
                if (row["is_attach"] != null && row["is_attach"].ToString() != "")
                {
                    model.is_attach = int.Parse(row["is_attach"].ToString());
                }
                if (row["is_spec"] != null && row["is_spec"].ToString() != "")
                {
                    model.is_spec = int.Parse(row["is_spec"].ToString());
                }
                if (row["sort_id"] != null && row["sort_id"].ToString() != "")
                {
                    model.sort_id = int.Parse(row["sort_id"].ToString());
                }
                #endregion

                #region 子表信息======================
                StringBuilder strSql2 = new StringBuilder();
                strSql2.Append("select top 1 id,channel_id,field_id from " + databaseprefix + "channel_field ");
                strSql2.Append(" where channel_id=@channel_id ");
                SqlParameter[] parameters2 = {
					    new SqlParameter("@channel_id", SqlDbType.Int,4)};
                parameters2[0].Value = model.id;
                DataSet ds2 = DbHelperSQL.Query(conn, trans, strSql2.ToString(), parameters2);

                if (ds2.Tables[0].Rows.Count > 0)
                {
                    int i = ds2.Tables[0].Rows.Count;
                    List<Model.channel_field> models = new List<Model.channel_field>();
                    Model.channel_field modelt;
                    for (int n = 0; n < i; n++)
                    {
                        modelt = new Model.channel_field();
                        if (ds2.Tables[0].Rows[n]["id"].ToString() != "")
                        {
                            modelt.id = int.Parse(ds2.Tables[0].Rows[n]["id"].ToString());
                        }
                        if (ds2.Tables[0].Rows[n]["channel_id"].ToString() != "")
                        {
                            modelt.channel_id = int.Parse(ds2.Tables[0].Rows[n]["channel_id"].ToString());
                        }
                        if (ds2.Tables[0].Rows[n]["field_id"].ToString() != "")
                        {
                            modelt.field_id = int.Parse(ds2.Tables[0].Rows[n]["field_id"].ToString());
                        }
                        models.Add(modelt);
                    }
                    model.channel_fields = models;
                }
                #endregion
            }
            return model;
        }
Exemple #17
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.channel GetModel(string channel_name)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 id,site_id,name,title,is_albums,is_attach,is_spec,sort_id from " + databaseprefix + "channel ");
            strSql.Append(" where name=@channel_name ");
            SqlParameter[] parameters = {
					new SqlParameter("@channel_name", SqlDbType.VarChar,50)};
            parameters[0].Value = channel_name;

            Model.channel model = new Model.channel();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }
Exemple #18
0
        /// <summary>
        /// 根据频道的名称查询ID
        /// </summary>
        public Model.channel GetModel(string channel_name)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,category_id,name,title,is_albums,is_attach,is_group_price,page_size,sort_id from " + databaseprefix + "channel ");
            strSql.Append(" where name=@name ");
            SqlParameter[] parameters = {
					new SqlParameter("@name", SqlDbType.VarChar,250)};
            parameters[0].Value = channel_name;

            Model.channel model = new Model.channel();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                #region  父表信息
                if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["category_id"].ToString() != "")
                {
                    model.category_id = int.Parse(ds.Tables[0].Rows[0]["category_id"].ToString());
                }
                model.name = ds.Tables[0].Rows[0]["name"].ToString();
                model.title = ds.Tables[0].Rows[0]["title"].ToString();
                if (ds.Tables[0].Rows[0]["is_albums"].ToString() != "")
                {
                    model.is_albums = int.Parse(ds.Tables[0].Rows[0]["is_albums"].ToString());
                }
                if (ds.Tables[0].Rows[0]["is_attach"].ToString() != "")
                {
                    model.is_attach = int.Parse(ds.Tables[0].Rows[0]["is_attach"].ToString());
                }
                if (ds.Tables[0].Rows[0]["is_group_price"].ToString() != "")
                {
                    model.is_group_price = int.Parse(ds.Tables[0].Rows[0]["is_group_price"].ToString());
                }
                if (ds.Tables[0].Rows[0]["page_size"].ToString() != "")
                {
                    model.page_size = int.Parse(ds.Tables[0].Rows[0]["page_size"].ToString());
                }
                if (ds.Tables[0].Rows[0]["sort_id"].ToString() != "")
                {
                    model.sort_id = int.Parse(ds.Tables[0].Rows[0]["sort_id"].ToString());
                }
                #endregion  父表信息end

                #region  子表信息
                StringBuilder strSql2 = new StringBuilder();
                strSql2.Append("select id,channel_id,field_id from " + databaseprefix + "channel_field ");
                strSql2.Append(" where channel_id=@channel_id ");
                SqlParameter[] parameters2 = {
					new SqlParameter("@channel_id", SqlDbType.Int,4)};
                parameters2[0].Value = model.id;

                DataSet ds2 = DbHelperSQL.Query(strSql2.ToString(), parameters2);
                if (ds2.Tables[0].Rows.Count > 0)
                {
                    int i = ds2.Tables[0].Rows.Count;
                    List<Model.channel_field> models = new List<Model.channel_field>();
                    Model.channel_field modelt;
                    for (int n = 0; n < i; n++)
                    {
                        modelt = new Model.channel_field();
                        if (ds2.Tables[0].Rows[n]["id"].ToString() != "")
                        {
                            modelt.id = int.Parse(ds2.Tables[0].Rows[n]["id"].ToString());
                        }
                        if (ds2.Tables[0].Rows[n]["channel_id"].ToString() != "")
                        {
                            modelt.channel_id = int.Parse(ds2.Tables[0].Rows[n]["channel_id"].ToString());
                        }
                        if (ds2.Tables[0].Rows[n]["field_id"].ToString() != "")
                        {
                            modelt.field_id = int.Parse(ds2.Tables[0].Rows[n]["field_id"].ToString());
                        }
                        models.Add(modelt);
                    }
                    model.channel_fields = models;
                }
                #endregion  子表信息end

                return model;
            }
            else
            {
                return null;
            }
        }
Exemple #19
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.channel model)
        {
            Model.channel oldModel = GetModel(model.id); //旧的数据
            //取得站点对应的导航ID
            int parent_id = new DAL.Mysql.channel_site(databaseprefix).GetSiteNavId(model.site_id);

            if (parent_id == 0)
            {
                return(false);
            }
            using (MySqlConnection conn = new MySqlConnection(DbHelperMySql.connectionString))
            {
                conn.Open();
                using (MySqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("update " + databaseprefix + "channel set ");
                        strSql.Append("site_id=@site_id,");
                        strSql.Append("name=@name,");
                        strSql.Append("title=@title,");
                        strSql.Append("is_albums=@is_albums,");
                        strSql.Append("is_attach=@is_attach,");
                        strSql.Append("is_spec=@is_spec,");
                        strSql.Append("sort_id=@sort_id");
                        strSql.Append(" where id=@id ");
                        MySqlParameter[] parameters =
                        {
                            new MySqlParameter("@site_id",   MySqlDbType.Int32,     4),
                            new MySqlParameter("@name",      MySqlDbType.VarChar,  50),
                            new MySqlParameter("@title",     MySqlDbType.VarChar, 100),
                            new MySqlParameter("@is_albums", MySqlDbType.Int32,     4),
                            new MySqlParameter("@is_attach", MySqlDbType.Int32,     4),
                            new MySqlParameter("@is_spec",   MySqlDbType.Int32,     4),
                            new MySqlParameter("@sort_id",   MySqlDbType.Int32,     4),
                            new MySqlParameter("@id",        MySqlDbType.Int32, 4)
                        };
                        parameters[0].Value = model.site_id;
                        parameters[1].Value = model.name;
                        parameters[2].Value = model.title;
                        parameters[3].Value = model.is_albums;
                        parameters[4].Value = model.is_attach;
                        parameters[5].Value = model.is_spec;
                        parameters[6].Value = model.sort_id;
                        parameters[7].Value = model.id;
                        DbHelperMySql.ExecuteSql(conn, trans, strSql.ToString(), parameters);

                        //删除已移除的扩展字段
                        FieldDelete(conn, trans, model.channel_fields, model.id);
                        //添加扩展字段
                        if (model.channel_fields != null)
                        {
                            StringBuilder strSql2;
                            foreach (Model.channel_field modelt in model.channel_fields)
                            {
                                strSql2 = new StringBuilder();
                                Model.channel_field fieldModel = null;
                                if (oldModel.channel_fields != null)
                                {
                                    fieldModel = oldModel.channel_fields.Find(p => p.field_id == modelt.field_id); //查找是否已经存在
                                }
                                if (fieldModel == null)                                                            //如果不存在则添加
                                {
                                    strSql2.Append("insert into " + databaseprefix + "channel_field(");
                                    strSql2.Append("channel_id,field_id)");
                                    strSql2.Append(" values (");
                                    strSql2.Append("@channel_id,@field_id)");
                                    MySqlParameter[] parameters2 =
                                    {
                                        new MySqlParameter("@channel_id", MySqlDbType.Int32, 4),
                                        new MySqlParameter("@field_id",   MySqlDbType.Int32, 4)
                                    };
                                    parameters2[0].Value = modelt.channel_id;
                                    parameters2[1].Value = modelt.field_id;
                                    DbHelperMySql.ExecuteSql(conn, trans, strSql2.ToString(), parameters2);
                                }
                            }
                        }
                        //删除旧视图重建新视图
                        RehabChannelViews(conn, trans, model, oldModel.name);

                        //修改对应的导航
                        new DAL.Mysql.navigation(databaseprefix).Update(conn, trans, "channel_" + oldModel.name, parent_id, "channel_" + model.name, model.title, model.sort_id);
                        new DAL.Mysql.navigation(databaseprefix).Update(conn, trans, "channel_" + oldModel.name + "_list", "channel_" + model.name + "_list");         //内容管理
                        new DAL.Mysql.navigation(databaseprefix).Update(conn, trans, "channel_" + oldModel.name + "_category", "channel_" + model.name + "_category"); //栏目类别
                        new DAL.Mysql.navigation(databaseprefix).Update(conn, trans, "channel_" + oldModel.name + "_comment", "channel_" + model.name + "_comment");   //评论管理

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemple #20
0
        /// <summary>
        /// 将对象转换实体
        /// </summary>
        public Model.channel DataRowToModel(SqlConnection conn, SqlTransaction trans, DataRow row)
        {
            Model.channel model = new Model.channel();
            if (row != null)
            {
                #region 主表信息======================
                if (null != row["id"] && "" != row["id"].ToString())
                {
                    model.id = int.Parse(row["id"].ToString());
                }
                if (null != row["site_id"] && "" != row["site_id"].ToString())
                {
                    model.site_id = int.Parse(row["site_id"].ToString());
                }
                if (null != row["name"])
                {
                    model.name = row["name"].ToString();
                }
                if (null != row["title"])
                {
                    model.title = row["title"].ToString();
                }
                if (null != row["is_albums"] && "" != row["is_albums"].ToString())
                {
                    model.is_albums = int.Parse(row["is_albums"].ToString());
                }
                if (null != row["is_attach"] && "" != row["is_attach"].ToString())
                {
                    model.is_attach = int.Parse(row["is_attach"].ToString());
                }
                if (null != row["is_spec"] && "" != row["is_spec"].ToString())
                {
                    model.is_spec = int.Parse(row["is_spec"].ToString());
                }
                if (null != row["sort_id"] && "" != row["sort_id"].ToString())
                {
                    model.sort_id = int.Parse(row["sort_id"].ToString());
                }
                if (null != row["seo_title"])
                {
                    model.seo_title = row["seo_title"].ToString();
                }
                if (null != row["seo_keywords"])
                {
                    model.seo_keywords = row["seo_keywords"].ToString();
                }
                if (null != row["seo_description"])
                {
                    model.seo_description = row["seo_description"].ToString();
                }
                if (null != row["is_type"] && "" != row["is_type"].ToString())
                {
                    model.is_type = int.Parse(row["is_type"].ToString());
                }
                if (null != row["is_attribute"] && "" != row["is_attribute"].ToString())
                {
                    model.is_attribute = int.Parse(row["is_attribute"].ToString());
                }
                if (null != row["is_comment"] && "" != row["is_comment"].ToString())
                {
                    model.is_comment = int.Parse(row["is_comment"].ToString());
                }
                if (null != row["height"] && "" != row["height"].ToString())
                {
                    model.height = int.Parse(row["height"].ToString());
                }
                if (null != row["width"] && "" != row["width"].ToString())
                {
                    model.width = int.Parse(row["width"].ToString());
                }
                if (null != row["is_recycle"] && "" != row["is_recycle"].ToString())
                {
                    model.is_recycle = int.Parse(row["is_recycle"].ToString());
                }
                #endregion

                #region 子表信息======================
                StringBuilder strSql2 = new StringBuilder();
                strSql2.Append("select top 1 id,channel_id,field_id from " + databaseprefix + "channel_field ");
                strSql2.Append(" where channel_id=@channel_id ");
                SqlParameter[] parameters2 =
                {
                    new SqlParameter("@channel_id", SqlDbType.Int, 4)
                };
                parameters2[0].Value = model.id;
                DataSet ds2 = DbHelperSQL.Query(conn, trans, strSql2.ToString(), parameters2);

                if (ds2.Tables[0].Rows.Count > 0)
                {
                    int i = ds2.Tables[0].Rows.Count;
                    List <Model.channel_field> models = new List <Model.channel_field>();
                    Model.channel_field        modelt;
                    for (int n = 0; n < i; n++)
                    {
                        modelt = new Model.channel_field();
                        if (ds2.Tables[0].Rows[n]["id"].ToString() != "")
                        {
                            modelt.id = int.Parse(ds2.Tables[0].Rows[n]["id"].ToString());
                        }
                        if (ds2.Tables[0].Rows[n]["channel_id"].ToString() != "")
                        {
                            modelt.channel_id = int.Parse(ds2.Tables[0].Rows[n]["channel_id"].ToString());
                        }
                        if (ds2.Tables[0].Rows[n]["field_id"].ToString() != "")
                        {
                            modelt.field_id = int.Parse(ds2.Tables[0].Rows[n]["field_id"].ToString());
                        }
                        models.Add(modelt);
                    }
                    model.channel_fields = models;
                }
                #endregion
            }
            return(model);
        }
        private bool DoAdd()
        {
            Model.channel model = new Model.channel();
            BLL.channel   bll   = new BLL.channel();

            model.category_id = Utils.StrToInt(ddlCategoryId.SelectedValue, 0);
            model.name        = txtName.Text.Trim();
            model.title       = txtTitle.Text.Trim();
            if (cbIsAlbums.Checked == true)
            {
                model.is_albums = 1;
            }
            if (cbIsAttach.Checked == true)
            {
                model.is_attach = 1;
            }
            if (cbIsGroupPrice.Checked == true)
            {
                model.is_group_price = 1;
            }
            model.page_size = Utils.StrToInt(txtPageSize.Text.Trim(), 10);
            model.sort_id   = Utils.StrToInt(txtSortId.Text.Trim(), 99);

            //添加频道扩展字段
            List <Model.channel_field> ls = new List <Model.channel_field>();

            for (int i = 0; i < cblAttributeField.Items.Count; i++)
            {
                if (cblAttributeField.Items[i].Selected)
                {
                    ls.Add(new Model.channel_field {
                        field_id = Utils.StrToInt(cblAttributeField.Items[i].Value, 0)
                    });
                }
            }
            model.channel_fields = ls;

            if (bll.Add(model) < 1)
            {
                return(false);
            }

            #region 保存URL配置
            BLL.url_rewrite urlBll = new BLL.url_rewrite();
            urlBll.Remove("channel", model.name); //先删除
            string[] itemTypeArr    = Request.Form.GetValues("item_type");
            string[] itemNameArr    = Request.Form.GetValues("item_name");
            string[] itemPageArr    = Request.Form.GetValues("item_page");
            string[] itemTempletArr = Request.Form.GetValues("item_templet");
            string[] itemRewriteArr = Request.Form.GetValues("item_rewrite");

            if (itemTypeArr != null && itemNameArr != null && itemPageArr != null && itemTempletArr != null && itemRewriteArr != null)
            {
                if ((itemTypeArr.Length == itemNameArr.Length) && (itemNameArr.Length == itemPageArr.Length) &&
                    (itemPageArr.Length == itemTempletArr.Length) && (itemTempletArr.Length == itemRewriteArr.Length))
                {
                    for (int i = 0; i < itemTypeArr.Length; i++)
                    {
                        Model.url_rewrite urlModel = new Model.url_rewrite();
                        urlModel.name    = itemNameArr[i].Trim();
                        urlModel.type    = itemTypeArr[i].Trim();
                        urlModel.page    = itemPageArr[i].Trim();
                        urlModel.inherit = GetInherit(urlModel.type);
                        urlModel.templet = itemTempletArr[i].Trim();
                        urlModel.channel = model.name;

                        List <Model.url_rewrite_item> itemLs = new List <Model.url_rewrite_item>();
                        string[] urlRewriteArr = itemRewriteArr[i].Split('&'); //分解URL重写字符串
                        for (int j = 0; j < urlRewriteArr.Length; j++)
                        {
                            string[] urlItemArr = urlRewriteArr[j].Split(',');
                            if (urlItemArr.Length == 3)
                            {
                                itemLs.Add(new Model.url_rewrite_item {
                                    path = urlItemArr[0], pattern = urlItemArr[1], querystring = urlItemArr[2]
                                });
                            }
                        }
                        urlModel.url_rewrite_items = itemLs;
                        urlBll.Add(urlModel);
                    }
                }
            }
            #endregion

            AddAdminLog(MXEnums.ActionEnum.Add.ToString(), "添加频道" + model.title); //记录日志
            return(true);
        }
Exemple #22
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Model.channel model)
 {
     return(dal.Add(model));
 }
        private bool DoAdd()
        {
            Model.channel model = new Model.channel();
            BLL.channel bll = new BLL.channel();

            model.site_id = Utils.StrToInt(ddlSiteId.SelectedValue, 0);
            model.name = txtName.Text.Trim();
            model.title = txtTitle.Text.Trim();
            if (cbIsAlbums.Checked == true)
            {
                model.is_albums = 1;
            }
            if (cbIsAttach.Checked == true)
            {
                model.is_attach = 1;
            }
            if (cbIsSpec.Checked == true)
            {
                model.is_spec = 1;
            }
            model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99);

            //添加频道扩展字段
            List<Model.channel_field> ls = new List<Model.channel_field>();
            for (int i = 0; i < cblAttributeField.Items.Count; i++)
            {
                if (cblAttributeField.Items[i].Selected)
                {
                    string[] fieldIdArr = cblAttributeField.Items[i].Value.Split(','); //分解出ID值
                    ls.Add(new Model.channel_field { field_id = Utils.StrToInt(fieldIdArr[1], 0) });
                }
            }
            model.channel_fields = ls;

            if (bll.Add(model) < 1)
            {
                return false;
            }

            #region 保存URL配置
            BLL.url_rewrite urlBll = new BLL.url_rewrite();
            urlBll.Remove("channel", model.name); //先删除
            string[] itemTypeArr = Request.Form.GetValues("item_type");
            string[] itemNameArr = Request.Form.GetValues("item_name");
            string[] itemPageArr = Request.Form.GetValues("item_page");
            string[] itemTempletArr = Request.Form.GetValues("item_templet");
            string[] itemPageSizeArr = Request.Form.GetValues("item_pagesize");
            string[] itemRewriteArr = Request.Form.GetValues("item_rewrite");

            if (itemTypeArr != null && itemNameArr != null && itemPageArr != null && itemTempletArr != null && itemPageSizeArr != null && itemRewriteArr != null)
            {
                if ((itemTypeArr.Length == itemNameArr.Length) && (itemNameArr.Length == itemPageArr.Length) && (itemPageArr.Length == itemTempletArr.Length)
                    && (itemTempletArr.Length == itemPageSizeArr.Length) && (itemPageSizeArr.Length == itemRewriteArr.Length))
                {
                    for (int i = 0; i < itemTypeArr.Length; i++)
                    {
                        Model.url_rewrite urlModel = new Model.url_rewrite();
                        urlModel.name = itemNameArr[i].Trim();
                        urlModel.type = itemTypeArr[i].Trim();
                        urlModel.page = itemPageArr[i].Trim();
                        urlModel.inherit = GetInherit(urlModel.type);
                        urlModel.templet = itemTempletArr[i].Trim();
                        if (Utils.StrToInt(itemPageSizeArr[i].Trim(), 0) > 0)
                        {
                            urlModel.pagesize = itemPageSizeArr[i].Trim();
                        }
                        urlModel.channel = model.name;

                        List<Model.url_rewrite_item> itemLs = new List<Model.url_rewrite_item>();
                        string[] urlRewriteArr = itemRewriteArr[i].Split('&'); //分解URL重写字符串
                        for (int j = 0; j < urlRewriteArr.Length; j++)
                        {
                            string[] urlItemArr = urlRewriteArr[j].Split(',');
                            if (urlItemArr.Length == 3)
                            {
                                itemLs.Add(new Model.url_rewrite_item { path = urlItemArr[0], pattern = urlItemArr[1], querystring = urlItemArr[2] });
                            }
                        }
                        urlModel.url_rewrite_items = itemLs;
                        urlBll.Add(urlModel);
                    }
                }
            }
            #endregion

            AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "添加频道" + model.title); //记录日志
            return true;
        }
        private void ShowInfo(int _id)
        {
            BLL.channel   bll   = new BLL.channel();
            Model.channel model = bll.GetModel(_id);

            txtTitle.Text = model.title;
            txtName.Text  = model.name;
            txtName.Attributes.Add("ajaxurl", "../../tools/admin_ajax.ashx?action=channel_name_validate&old_channel_name=" + Utils.UrlEncode(model.name));
            txtName.Focus(); //设置焦点,防止JS无法提交

            ddlSiteId.SelectedValue = model.site_id.ToString();
            if (model.is_albums == 1)
            {
                cbIsAlbums.Checked = true;
            }
            if (model.is_attach == 1)
            {
                cbIsAttach.Checked = true;
            }
            if (model.is_spec == 1)
            {
                cbIsSpec.Checked = true;
            }
            txtSortId.Text = model.sort_id.ToString();

            //扩展
            if (model.is_comment == 1)
            {
                cbIsComment.Checked = true;
            }
            if (model.is_attribute == 1)
            {
                cbIsAttr.Checked = true;
            }
            if (model.is_recycle == 1)
            {
                cbIsRecycle.Checked = true;
            }
            rblIsType.SelectedValue = model.is_type.ToString();
            txtHeight.Text          = model.height.ToString();
            txtWidth.Text           = model.width.ToString();

            //SEO优化
            txtSeoTitle.Text       = model.seo_title;
            txtSeoKeywords.Text    = model.seo_keywords;
            txtSeoDescription.Text = model.seo_description;

            //赋值扩展字段
            if (model.channel_fields != null)
            {
                for (int i = 0; i < cblAttributeField.Items.Count; i++)
                {
                    string[]            fieldIdArr = cblAttributeField.Items[i].Value.Split(',');                            //分解出ID值
                    Model.channel_field modelt     = model.channel_fields.Find(p => p.field_id == int.Parse(fieldIdArr[1])); //查找对应的字段ID
                    if (modelt != null)
                    {
                        cblAttributeField.Items[i].Selected = true;
                    }
                }
            }

            //绑定URL配置列表
            rptList.DataSource = new BLL.url_rewrite().GetList(model.name);
            rptList.DataBind();
        }
Exemple #25
0
        private bool DoEdit(int _id)
        {
            BLL.channel   bll   = new BLL.channel();
            Model.channel model = bll.GetModel(_id);

            string old_name = model.name;

            model.site_id   = Utils.StrToInt(ddlSiteId.SelectedValue, 0);
            model.name      = txtName.Text.Trim();
            model.title     = txtTitle.Text.Trim();
            model.is_albums = 0;
            model.is_attach = 0;
            model.is_spec   = 0;
            if (cbIsAlbums.Checked == true)
            {
                model.is_albums = 1;
            }
            if (cbIsAttach.Checked == true)
            {
                model.is_attach = 1;
            }
            if (cbIsSpec.Checked == true)
            {
                model.is_spec = 1;
            }
            model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99);

            //添加频道扩展字段
            List <Model.channel_field> ls = new List <Model.channel_field>();

            for (int i = 0; i < cblAttributeField.Items.Count; i++)
            {
                if (cblAttributeField.Items[i].Selected)
                {
                    string[] fieldIdArr = cblAttributeField.Items[i].Value.Split(','); //分解出ID值
                    ls.Add(new Model.channel_field {
                        channel_id = model.id, field_id = Utils.StrToInt(fieldIdArr[1], 0)
                    });
                }
            }
            model.channel_fields = ls;

            if (!bll.Update(model))
            {
                return(false);
            }

            #region 保存URL配置
            BLL.url_rewrite urlBll = new BLL.url_rewrite();
            urlBll.Remove("channel", old_name); //先删除旧的
            string[] itemTypeArr     = Request.Form.GetValues("item_type");
            string[] itemNameArr     = Request.Form.GetValues("item_name");
            string[] itemPageArr     = Request.Form.GetValues("item_page");
            string[] itemTempletArr  = Request.Form.GetValues("item_templet");
            string[] itemPageSizeArr = Request.Form.GetValues("item_pagesize");
            string[] itemRewriteArr  = Request.Form.GetValues("item_rewrite");

            if (itemTypeArr != null && itemNameArr != null && itemPageArr != null && itemTempletArr != null && itemPageSizeArr != null && itemRewriteArr != null)
            {
                if ((itemTypeArr.Length == itemNameArr.Length) && (itemNameArr.Length == itemPageArr.Length) && (itemPageArr.Length == itemTempletArr.Length) &&
                    (itemTempletArr.Length == itemPageSizeArr.Length) && (itemPageSizeArr.Length == itemRewriteArr.Length))
                {
                    for (int i = 0; i < itemTypeArr.Length; i++)
                    {
                        Model.url_rewrite urlModel = new Model.url_rewrite();
                        urlModel.name    = itemNameArr[i].Trim();
                        urlModel.type    = itemTypeArr[i].Trim();
                        urlModel.page    = itemPageArr[i].Trim();
                        urlModel.inherit = GetInherit(urlModel.type);
                        urlModel.templet = itemTempletArr[i].Trim();
                        if (Utils.StrToInt(itemPageSizeArr[i].Trim(), 0) > 0)
                        {
                            urlModel.pagesize = itemPageSizeArr[i].Trim();
                        }
                        urlModel.channel = model.name;

                        List <Model.url_rewrite_item> itemLs = new List <Model.url_rewrite_item>();
                        string[] urlRewriteArr = itemRewriteArr[i].Split('&'); //分解URL重写字符串
                        for (int j = 0; j < urlRewriteArr.Length; j++)
                        {
                            string[] urlItemArr = urlRewriteArr[j].Split(',');
                            if (urlItemArr.Length == 3)
                            {
                                itemLs.Add(new Model.url_rewrite_item {
                                    path = urlItemArr[0], pattern = urlItemArr[1], querystring = urlItemArr[2]
                                });
                            }
                        }
                        urlModel.url_rewrite_items = itemLs;
                        urlBll.Add(urlModel);
                    }
                }
            }
            #endregion

            AddAdminLog(PLEnums.ActionEnum.Edit.ToString(), "修改频道" + model.title); //记录日志
            return(true);
        }
Exemple #26
0
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            //取得将要删除的记录
            Model.channel model = GetModel(id);
            if (model == null)
            {
                return(false);
            }
            //取得导航的ID
            int nav_id = new navigation(databaseprefix).GetNavId("channel_" + model.name);

            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        //删除导航主表
                        if (nav_id > 0)
                        {
                            DbHelperSQL.ExecuteSql(conn, trans, "delete from " + databaseprefix + "navigation  where class_list like '%," + nav_id + ",%'");
                        }

                        //删除视图
                        StringBuilder strSql1 = new StringBuilder();
                        strSql1.Append("if exists (select 1 from sysobjects where id = object_id('view_channel_" + model.name + "') and type = 'V')");
                        strSql1.Append("drop view view_channel_" + model.name);
                        DbHelperSQL.ExecuteSql(conn, trans, strSql1.ToString());

                        //删除频道扩展字段表
                        StringBuilder strSql2 = new StringBuilder();
                        strSql2.Append("delete from " + databaseprefix + "channel_field ");
                        strSql2.Append(" where channel_id=@channel_id ");
                        SqlParameter[] parameters2 =
                        {
                            new SqlParameter("@channel_id", SqlDbType.Int, 4)
                        };
                        parameters2[0].Value = id;
                        DbHelperSQL.ExecuteSql(conn, trans, strSql2.ToString(), parameters2);

                        //删除频道表
                        StringBuilder strSql3 = new StringBuilder();
                        strSql3.Append("delete from " + databaseprefix + "channel ");
                        strSql3.Append(" where id=@id ");
                        SqlParameter[] parameters3 =
                        {
                            new SqlParameter("@id", SqlDbType.Int, 4)
                        };
                        parameters3[0].Value = id;
                        DbHelperSQL.ExecuteSql(conn, trans, strSql3.ToString(), parameters3);

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemple #27
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.channel model)
 {
     return(dal.Update(model));
 }
Exemple #28
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.channel model)
        {
            Model.channel oldModel = GetModel(model.id); //旧的数据
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("update " + databaseprefix + "channel set ");
                        strSql.Append("category_id=@category_id,");
                        strSql.Append("name=@name,");
                        strSql.Append("title=@title,");
                        strSql.Append("is_albums=@is_albums,");
                        strSql.Append("is_attach=@is_attach,");
                        strSql.Append("is_group_price=@is_group_price,");
                        strSql.Append("page_size=@page_size,");
                        strSql.Append("sort_id=@sort_id");
                        strSql.Append(" where id=@id ");
                        SqlParameter[] parameters = {
					            new SqlParameter("@category_id", SqlDbType.Int,4),
					            new SqlParameter("@name", SqlDbType.VarChar,50),
					            new SqlParameter("@title", SqlDbType.VarChar,100),
                                new SqlParameter("@is_albums", SqlDbType.TinyInt,1),
					            new SqlParameter("@is_attach", SqlDbType.TinyInt,1),
					            new SqlParameter("@is_group_price", SqlDbType.TinyInt,1),
					            new SqlParameter("@page_size", SqlDbType.Int,4),
					            new SqlParameter("@sort_id", SqlDbType.Int,4),
                                new SqlParameter("@id", SqlDbType.Int,4)};
                        parameters[0].Value = model.category_id;
                        parameters[1].Value = model.name;
                        parameters[2].Value = model.title;
                        parameters[3].Value = model.is_albums;
                        parameters[4].Value = model.is_attach;
                        parameters[5].Value = model.is_group_price;
                        parameters[6].Value = model.page_size;
                        parameters[7].Value = model.sort_id;
                        parameters[8].Value = model.id;
                        DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters);

                        //删除已移除的扩展字段
                        FieldDelete(conn, trans, model.channel_fields, model.id);
                        //添加扩展字段
                        if (model.channel_fields != null)
                        {
                            StringBuilder strSql2;
                            foreach (Model.channel_field modelt in model.channel_fields)
                            {
                                strSql2 = new StringBuilder();
                                Model.channel_field fieldModel = null;
                                if (oldModel.channel_fields != null)
                                {
                                    fieldModel = oldModel.channel_fields.Find(p => p.field_id == modelt.field_id); //查找是否已经存在
                                }
                                if (fieldModel == null) //如果不存在则添加
                                {
                                    strSql2.Append("insert into " + databaseprefix + "channel_field(");
                                    strSql2.Append("channel_id,field_id)");
                                    strSql2.Append(" values (");
                                    strSql2.Append("@channel_id,@field_id)");
                                    SqlParameter[] parameters2 = {
					                        new SqlParameter("@channel_id", SqlDbType.Int,4),
					                        new SqlParameter("@field_id", SqlDbType.Int,4)};
                                    parameters2[0].Value = modelt.channel_id;
                                    parameters2[1].Value = modelt.field_id;
                                    DbHelperSQL.ExecuteSql(conn, trans, strSql2.ToString(), parameters2);
                                }
                            }
                        }
                        //删除旧视图重建新视图
                        RehabChannelViews(conn, trans, model, oldModel.name);

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return false;
                    }
                }
            }
            return true;
        }