示例#1
0
        /// <summary>
        /// ²éÕÒ²»´æÔÚµÄͼƬ²¢É¾³ýÒÑɾ³ýµÄͼƬ¼°Êý¾Ý
        /// </summary>
        public void DeleteList(SqlConnection conn, SqlTransaction trans, List <Model.article_albums> models, int article_id)
        {
            StringBuilder idList = new StringBuilder();

            if (models != null)
            {
                foreach (Model.article_albums modelt in models)
                {
                    if (modelt.id > 0)
                    {
                        idList.Append(modelt.id + ",");
                    }
                }
            }
            string        id_list = Utils.DelLastChar(idList.ToString(), ",");
            StringBuilder strSql  = new StringBuilder();

            strSql.Append("select id,big_img,small_img from dt_article_albums where article_id=" + article_id);
            if (!string.IsNullOrEmpty(id_list))
            {
                strSql.Append(" and id not in(" + id_list + ")");
            }
            DataSet ds = DbHelperSQL2.Query(conn, trans, strSql.ToString());

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                int rows = DbHelperSQL2.ExecuteSql(conn, trans, "delete from dt_article_albums where id=" + dr["id"].ToString()); //ɾ³ýÊý¾Ý¿â
                if (rows > 0)
                {
                    Utils.DeleteFile(dr["big_img"].ToString());   //ɾ³ýԭͼ
                    Utils.DeleteFile(dr["small_img"].ToString()); //ɾ³ýËõÂÔͼ
                }
            }
        }
示例#2
0
        /// <summary>
        /// 查找不存在的文件并删除已删除的附件及数据
        /// </summary>
        public void DeleteList(SqlConnection conn, SqlTransaction trans, List <Model.download_attach> models, int article_id)
        {
            StringBuilder idList = new StringBuilder();

            if (models != null)
            {
                foreach (Model.download_attach modelt in models)
                {
                    if (modelt.id > 0)
                    {
                        idList.Append(modelt.id + ",");
                    }
                }
            }
            string        id_list = Utils.DelLastChar(idList.ToString(), ",");
            StringBuilder strSql  = new StringBuilder();

            strSql.Append("select id,file_path from dt_download_attach where article_id=" + article_id);
            if (!string.IsNullOrEmpty(id_list))
            {
                strSql.Append(" and id not in(" + id_list + ")");
            }
            DataSet ds = DbHelperSQL2.Query(conn, trans, strSql.ToString());

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                int rows = DbHelperSQL2.ExecuteSql(conn, trans, "delete from dt_download_attach where id=" + dr["id"].ToString()); //删除数据库
                if (rows > 0)
                {
                    Utils.DeleteFile(dr["file_path"].ToString()); //删除文件
                }
            }
        }
示例#3
0
        /// <summary>
        /// 修改一列数据
        /// </summary>
        public void UpdateField(int id, string strValue)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update dt_article set " + strValue);
            strSql.Append(" where id=" + id);
            DbHelperSQL2.ExecuteSql(strSql.ToString());
        }
示例#4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(DBAccess.Model.Tb_CheckDataModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Tb_CheckData(");
            strSql.Append("BarCode,Tf_TrayId,cTray,FileName,fltCapacity,fltVol,fltResistance,tf_CheckGrade,tf_Group,tf_GroupNum,tf_Location,cState,cDate,cStateCode)");
            strSql.Append(" values (");
            strSql.Append("@BarCode,@Tf_TrayId,@cTray,@FileName,@fltCapacity,@fltVol,@fltResistance,@tf_CheckGrade,@tf_Group,@tf_GroupNum,@tf_Location,@cState,@cDate,@cStateCode)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@BarCode",       SqlDbType.NVarChar, 32),
                new SqlParameter("@Tf_TrayId",     SqlDbType.NVarChar, 32),
                new SqlParameter("@cTray",         SqlDbType.NVarChar, 32),
                new SqlParameter("@FileName",      SqlDbType.NVarChar, 32),
                new SqlParameter("@fltCapacity",   SqlDbType.Float,     8),
                new SqlParameter("@fltVol",        SqlDbType.Float,     8),
                new SqlParameter("@fltResistance", SqlDbType.Float,     8),
                new SqlParameter("@tf_CheckGrade", SqlDbType.NVarChar, 32),
                new SqlParameter("@tf_Group",      SqlDbType.NVarChar, 32),
                new SqlParameter("@tf_GroupNum",   SqlDbType.Int,       4),
                new SqlParameter("@tf_Location",   SqlDbType.NVarChar, 32),
                new SqlParameter("@cState",        SqlDbType.Float,     8),
                new SqlParameter("@cDate",         SqlDbType.NVarChar, 32),
                new SqlParameter("@cStateCode",    SqlDbType.NVarChar, 32)
            };
            parameters[0].Value  = model.BarCode;
            parameters[1].Value  = model.Tf_TrayId;
            parameters[2].Value  = model.cTray;
            parameters[3].Value  = model.FileName;
            parameters[4].Value  = model.fltCapacity;
            parameters[5].Value  = model.fltVol;
            parameters[6].Value  = model.fltResistance;
            parameters[7].Value  = model.tf_CheckGrade;
            parameters[8].Value  = model.tf_Group;
            parameters[9].Value  = model.tf_GroupNum;
            parameters[10].Value = model.tf_Location;
            parameters[11].Value = model.cState;
            parameters[12].Value = model.cDate;
            parameters[13].Value = model.cStateCode;

            int rows = DbHelperSQL2.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#5
0
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string BarCodelist)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("delete from Tb_CheckData ");
            strSql.Append(" where BarCode in (" + BarCodelist + ")  ");
            int rows = DbHelperSQL2.ExecuteSql(strSql.ToString());

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

                    //调用自身迭代
                    this.UpdateChilds(conn, trans, id); //带事务
                }
            }
        }
示例#7
0
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string BarCode)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("delete from Tb_CheckData ");
            strSql.Append(" where BarCode=@BarCode ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@BarCode", SqlDbType.NVarChar, 32)
            };
            parameters[0].Value = BarCode;

            int rows = DbHelperSQL2.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#8
0
        /// <summary>
        /// 更新一条数据,及其子表数据
        /// </summary>
        public bool Update(Model.article_news model)
        {
            using (SqlConnection conn = new SqlConnection(DbHelperSQL2.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("update dt_article set ");
                        strSql.Append("channel_id=@channel_id,");
                        strSql.Append("category_id=@category_id,");
                        strSql.Append("title=@title,");
                        strSql.Append("link_url=@link_url,");
                        strSql.Append("img_url=@img_url,");
                        strSql.Append("seo_title=@seo_title,");
                        strSql.Append("seo_keywords=@seo_keywords,");
                        strSql.Append("seo_description=@seo_description,");
                        strSql.Append("content=@content,");
                        strSql.Append("sort_id=@sort_id,");
                        strSql.Append("click=@click,");
                        strSql.Append("is_lock=@is_lock,");
                        strSql.Append("user_id=@user_id,");
                        strSql.Append("add_time=@add_time");
                        strSql.Append(" where id=@id");
                        SqlParameter[] parameters =
                        {
                            new SqlParameter("@channel_id",      SqlDbType.Int,         4),
                            new SqlParameter("@category_id",     SqlDbType.Int,         4),
                            new SqlParameter("@title",           SqlDbType.NVarChar,  100),
                            new SqlParameter("@link_url",        SqlDbType.NVarChar,  255),
                            new SqlParameter("@img_url",         SqlDbType.NVarChar,  255),
                            new SqlParameter("@seo_title",       SqlDbType.NVarChar,  255),
                            new SqlParameter("@seo_keywords",    SqlDbType.NVarChar,  255),
                            new SqlParameter("@seo_description", SqlDbType.NVarChar,  255),
                            new SqlParameter("@content",         SqlDbType.NText),
                            new SqlParameter("@sort_id",         SqlDbType.Int,         4),
                            new SqlParameter("@click",           SqlDbType.Int,         4),
                            new SqlParameter("@is_lock",         SqlDbType.TinyInt,     1),
                            new SqlParameter("@user_id",         SqlDbType.Int,         4),
                            new SqlParameter("@add_time",        SqlDbType.DateTime),
                            new SqlParameter("@id",              SqlDbType.Int, 4)
                        };
                        parameters[0].Value  = model.channel_id;
                        parameters[1].Value  = model.category_id;
                        parameters[2].Value  = model.title;
                        parameters[3].Value  = model.link_url;
                        parameters[4].Value  = model.img_url;
                        parameters[5].Value  = model.seo_title;
                        parameters[6].Value  = model.seo_keywords;
                        parameters[7].Value  = model.seo_description;
                        parameters[8].Value  = model.content;
                        parameters[9].Value  = model.sort_id;
                        parameters[10].Value = model.click;
                        parameters[11].Value = model.is_lock;
                        parameters[12].Value = model.user_id;
                        parameters[13].Value = model.add_time;
                        parameters[14].Value = model.id;
                        DbHelperSQL2.ExecuteSql(conn, trans, strSql.ToString(), parameters);

                        //修改副表
                        StringBuilder strSql21 = new StringBuilder();
                        strSql21.Append("update dt_article_news set ");
                        strSql21.Append("author=@author,");
                        strSql21.Append("[from]=@from,");
                        strSql21.Append("zhaiyao=@zhaiyao,");
                        strSql21.Append("is_msg=@is_msg,");
                        strSql21.Append("is_top=@is_top,");
                        strSql21.Append("is_red=@is_red,");
                        strSql21.Append("is_hot=@is_hot,");
                        strSql21.Append("is_slide=@is_slide");
                        strSql21.Append(" where id=@id ");
                        SqlParameter[] parameters21 =
                        {
                            new SqlParameter("@author",   SqlDbType.NVarChar, 100),
                            new SqlParameter("@from",     SqlDbType.NVarChar,  50),
                            new SqlParameter("@zhaiyao",  SqlDbType.NVarChar, 255),
                            new SqlParameter("@is_msg",   SqlDbType.TinyInt,    1),
                            new SqlParameter("@is_top",   SqlDbType.TinyInt,    1),
                            new SqlParameter("@is_red",   SqlDbType.TinyInt,    1),
                            new SqlParameter("@is_hot",   SqlDbType.TinyInt,    1),
                            new SqlParameter("@is_slide", SqlDbType.TinyInt,    1),
                            new SqlParameter("@id",       SqlDbType.Int, 4)
                        };
                        parameters21[0].Value = model.author;
                        parameters21[1].Value = model.from;
                        parameters21[2].Value = model.zhaiyao;
                        parameters21[3].Value = model.is_msg;
                        parameters21[4].Value = model.is_top;
                        parameters21[5].Value = model.is_red;
                        parameters21[6].Value = model.is_hot;
                        parameters21[7].Value = model.is_slide;
                        parameters21[8].Value = model.id;
                        DbHelperSQL2.ExecuteSql(conn, trans, strSql21.ToString(), parameters21);

                        ////修改顶和踩
                        //StringBuilder strSql22 = new StringBuilder();
                        //strSql22.Append("update dt_article_diggs set ");
                        //strSql22.Append("digg_good=@digg_good,");
                        //strSql22.Append("digg_bad=@digg_bad");
                        //strSql22.Append(" where id=@id ");
                        //SqlParameter[] parameters22 = {
                        //        new SqlParameter("@digg_good", SqlDbType.Int,4),
                        //        new SqlParameter("@digg_bad", SqlDbType.Int,4),
                        //        new SqlParameter("@id", SqlDbType.Int,4)};
                        //parameters22[0].Value = model.digg_good;
                        //parameters22[1].Value = model.digg_bad;
                        //parameters22[2].Value = model.id;
                        //DbHelperSQL2.ExecuteSql(conn, trans, strSql22.ToString(), parameters22);

                        //删除已删除的图片
                        new article_albums().DeleteList(conn, trans, model.albums, model.id);
                        //添加/修改相册
                        if (model.albums != null)
                        {
                            StringBuilder strSql2;
                            foreach (Model.article_albums models in model.albums)
                            {
                                strSql2 = new StringBuilder();
                                if (models.id > 0)
                                {
                                    strSql2.Append("update dt_article_albums set ");
                                    strSql2.Append("article_id=@article_id,");
                                    strSql2.Append("big_img=@big_img,");
                                    strSql2.Append("small_img=@small_img,");
                                    strSql2.Append("remark=@remark");
                                    strSql2.Append(" where id=@id");
                                    SqlParameter[] parameters2 =
                                    {
                                        new SqlParameter("@article_id", SqlDbType.Int,        4),
                                        new SqlParameter("@big_img",    SqlDbType.NVarChar, 255),
                                        new SqlParameter("@small_img",  SqlDbType.NVarChar, 255),
                                        new SqlParameter("@remark",     SqlDbType.NVarChar, 500),
                                        new SqlParameter("@id",         SqlDbType.Int, 4)
                                    };
                                    parameters2[0].Value = models.article_id;
                                    parameters2[1].Value = models.big_img;
                                    parameters2[2].Value = models.small_img;
                                    parameters2[3].Value = models.remark;
                                    parameters2[4].Value = models.id;
                                    DbHelperSQL2.ExecuteSql(conn, trans, strSql2.ToString(), parameters2);
                                }
                                else
                                {
                                    strSql2.Append("insert into dt_article_albums(");
                                    strSql2.Append("article_id,big_img,small_img,remark)");
                                    strSql2.Append(" values (");
                                    strSql2.Append("@article_id,@big_img,@small_img,@remark)");
                                    SqlParameter[] parameters2 =
                                    {
                                        new SqlParameter("@article_id", SqlDbType.Int,        4),
                                        new SqlParameter("@big_img",    SqlDbType.NVarChar, 255),
                                        new SqlParameter("@small_img",  SqlDbType.NVarChar, 255),
                                        new SqlParameter("@remark",     SqlDbType.NVarChar, 500)
                                    };
                                    parameters2[0].Value = models.article_id;
                                    parameters2[1].Value = models.big_img;
                                    parameters2[2].Value = models.small_img;
                                    parameters2[3].Value = models.remark;
                                    DbHelperSQL2.ExecuteSql(conn, trans, strSql2.ToString(), parameters2);
                                }
                            }
                        }

                        ////添加/修改属性
                        //if (model.attribute_values != null)
                        //{
                        //    StringBuilder strSql3;
                        //    foreach (Model.attribute_value models in model.attribute_values)
                        //    {
                        //        strSql3 = new StringBuilder();
                        //        if (models.id > 0)
                        //        {
                        //            strSql3.Append("update dt_attribute_value set ");
                        //            strSql3.Append("article_id=@article_id,");
                        //            strSql3.Append("attribute_id=@attribute_id,");
                        //            strSql3.Append("title=@title,");
                        //            strSql3.Append("content=@content");
                        //            strSql3.Append(" where id=@id");
                        //            SqlParameter[] parameters3 = {
                        //                    new SqlParameter("@article_id", SqlDbType.Int,4),
                        //                    new SqlParameter("@attribute_id", SqlDbType.Int,4),
                        //                    new SqlParameter("@title", SqlDbType.NVarChar,100),
                        //                    new SqlParameter("@content", SqlDbType.NText),
                        //                    new SqlParameter("@id", SqlDbType.Int,4)};
                        //            parameters3[0].Value = models.article_id;
                        //            parameters3[1].Value = models.attribute_id;
                        //            parameters3[2].Value = models.title;
                        //            parameters3[3].Value = models.content;
                        //            parameters3[4].Value = models.id;
                        //            DbHelperSQL2.ExecuteSql(conn, trans, strSql3.ToString(), parameters3);
                        //        }
                        //        else
                        //        {
                        //            strSql3.Append("insert into dt_attribute_value(");
                        //            strSql3.Append("article_id,attribute_id,title,content)");
                        //            strSql3.Append(" values (");
                        //            strSql3.Append("@article_id,@attribute_id,@title,@content)");
                        //            SqlParameter[] parameters3 = {
                        //                    new SqlParameter("@article_id", SqlDbType.Int,4),
                        //                    new SqlParameter("@attribute_id", SqlDbType.Int,4),
                        //                    new SqlParameter("@title", SqlDbType.NVarChar,100),
                        //                    new SqlParameter("@content", SqlDbType.NText)};
                        //            parameters3[0].Value = models.article_id;
                        //            parameters3[1].Value = models.attribute_id;
                        //            parameters3[2].Value = models.title;
                        //            parameters3[3].Value = models.content;
                        //            DbHelperSQL2.ExecuteSql(conn, trans, strSql3.ToString(), parameters3);
                        //        }
                        //    }
                        //}

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return(false);
                    }
                }
            }
            return(true);
        }
示例#9
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(DBAccess.Model.Tb_CheckDataModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Tb_CheckData set ");
            strSql.Append("Tf_TrayId=@Tf_TrayId,");
            strSql.Append("cTray=@cTray,");
            strSql.Append("FileName=@FileName,");
            strSql.Append("fltCapacity=@fltCapacity,");
            strSql.Append("fltVol=@fltVol,");
            strSql.Append("fltResistance=@fltResistance,");
            strSql.Append("tf_CheckGrade=@tf_CheckGrade,");
            strSql.Append("tf_Group=@tf_Group,");
            strSql.Append("tf_GroupNum=@tf_GroupNum,");
            strSql.Append("tf_Location=@tf_Location,");
            strSql.Append("cState=@cState,");
            strSql.Append("cDate=@cDate,");
            strSql.Append("cStateCode=@cStateCode");
            strSql.Append(" where BarCode=@BarCode ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Tf_TrayId",     SqlDbType.NVarChar, 32),
                new SqlParameter("@cTray",         SqlDbType.NVarChar, 32),
                new SqlParameter("@FileName",      SqlDbType.NVarChar, 32),
                new SqlParameter("@fltCapacity",   SqlDbType.Float,     8),
                new SqlParameter("@fltVol",        SqlDbType.Float,     8),
                new SqlParameter("@fltResistance", SqlDbType.Float,     8),
                new SqlParameter("@tf_CheckGrade", SqlDbType.NVarChar, 32),
                new SqlParameter("@tf_Group",      SqlDbType.NVarChar, 32),
                new SqlParameter("@tf_GroupNum",   SqlDbType.Int,       4),
                new SqlParameter("@tf_Location",   SqlDbType.NVarChar, 32),
                new SqlParameter("@cState",        SqlDbType.Float,     8),
                new SqlParameter("@cDate",         SqlDbType.NVarChar, 32),
                new SqlParameter("@cStateCode",    SqlDbType.NVarChar, 32),
                new SqlParameter("@BarCode",       SqlDbType.NVarChar, 32)
            };
            parameters[0].Value  = model.Tf_TrayId;
            parameters[1].Value  = model.cTray;
            parameters[2].Value  = model.FileName;
            parameters[3].Value  = model.fltCapacity;
            parameters[4].Value  = model.fltVol;
            parameters[5].Value  = model.fltResistance;
            parameters[6].Value  = model.tf_CheckGrade;
            parameters[7].Value  = model.tf_Group;
            parameters[8].Value  = model.tf_GroupNum;
            parameters[9].Value  = model.tf_Location;
            parameters[10].Value = model.cState;
            parameters[11].Value = model.cDate;
            parameters[12].Value = model.cStateCode;
            parameters[13].Value = model.BarCode;

            int rows = DbHelperSQL2.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#10
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.category model)
        {
            using (SqlConnection conn = new SqlConnection(DbHelperSQL2.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("insert into dt_category(");
                        strSql.Append("channel_id,title,call_index,parent_id,class_list,class_layer,sort_id,link_url,img_url,content,seo_title,seo_keywords,seo_description)");
                        strSql.Append(" values (");
                        strSql.Append("@channel_id,@title,@call_index,@parent_id,@class_list,@class_layer,@sort_id,@link_url,@img_url,@content,@seo_title,@seo_keywords,@seo_description)");
                        strSql.Append(";select @@IDENTITY");
                        SqlParameter[] parameters =
                        {
                            new SqlParameter("@channel_id",      SqlDbType.Int,        4),
                            new SqlParameter("@title",           SqlDbType.NVarChar, 100),
                            new SqlParameter("@call_index",      SqlDbType.NVarChar,  50),
                            new SqlParameter("@parent_id",       SqlDbType.Int,        4),
                            new SqlParameter("@class_list",      SqlDbType.NVarChar, 500),
                            new SqlParameter("@class_layer",     SqlDbType.Int,        4),
                            new SqlParameter("@sort_id",         SqlDbType.Int,        4),
                            new SqlParameter("@link_url",        SqlDbType.NVarChar, 255),
                            new SqlParameter("@img_url",         SqlDbType.NVarChar, 255),
                            new SqlParameter("@content",         SqlDbType.NText),
                            new SqlParameter("@seo_title",       SqlDbType.NVarChar, 255),
                            new SqlParameter("@seo_keywords",    SqlDbType.NVarChar, 255),
                            new SqlParameter("@seo_description", SqlDbType.NVarChar, 255)
                        };
                        parameters[0].Value  = model.channel_id;
                        parameters[1].Value  = model.title;
                        parameters[2].Value  = model.call_index;
                        parameters[3].Value  = model.parent_id;
                        parameters[4].Value  = model.class_list;
                        parameters[5].Value  = model.class_layer;
                        parameters[6].Value  = model.sort_id;
                        parameters[7].Value  = model.link_url;
                        parameters[8].Value  = model.img_url;
                        parameters[9].Value  = model.content;
                        parameters[10].Value = model.seo_title;
                        parameters[11].Value = model.seo_keywords;
                        parameters[12].Value = model.seo_description;

                        object obj = DbHelperSQL2.GetSingle(conn, trans, strSql.ToString(), parameters); //带事务
                        model.id = Convert.ToInt32(obj);
                        if (model.parent_id > 0)
                        {
                            Model.category model2 = GetModel(conn, trans, model.parent_id); //带事务
                            model.class_list  = model2.class_list + model.id + ",";
                            model.class_layer = model2.class_layer + 1;
                        }
                        else
                        {
                            model.class_list  = "," + model.id + ",";
                            model.class_layer = 1;
                        }
                        //修改节点列表和深度
                        DbHelperSQL2.ExecuteSql(conn, trans, "update dt_category set class_list='" + model.class_list + "', class_layer=" + model.class_layer + " where id=" + model.id); //带事务
                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return(0);
                    }
                }
            }
            return(model.id);
        }
示例#11
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(DTcms.Model.category model)
 {
     using (SqlConnection conn = new SqlConnection(DbHelperSQL2.connectionString))
     {
         conn.Open();
         using (SqlTransaction trans = conn.BeginTransaction())
         {
             try
             {
                 //先判断选中的父节点是否被包含
                 if (IsContainNode(model.id, model.parent_id))
                 {
                     //查找旧数据
                     Model.category oldModel = GetModel(model.id);
                     //查找旧父节点数据
                     string class_list  = "," + model.parent_id + ",";
                     int    class_layer = 1;
                     if (oldModel.parent_id > 0)
                     {
                         Model.category oldParentModel = GetModel(conn, trans, oldModel.parent_id); //带事务
                         class_list  = oldParentModel.class_list + model.parent_id + ",";
                         class_layer = oldParentModel.class_layer + 1;
                     }
                     //先提升选中的父节点
                     DbHelperSQL2.ExecuteSql(conn, trans, "update dt_category set parent_id=" + oldModel.parent_id + ",class_list='" + class_list + "', class_layer=" + class_layer + " where id=" + model.parent_id); //带事务
                     UpdateChilds(conn, trans, model.parent_id);                                                                                                                                                       //带事务
                 }
                 //更新子节点
                 if (model.parent_id > 0)
                 {
                     Model.category model2 = GetModel(conn, trans, model.parent_id); //带事务
                     model.class_list  = model2.class_list + model.id + ",";
                     model.class_layer = model2.class_layer + 1;
                 }
                 else
                 {
                     model.class_list  = "," + model.id + ",";
                     model.class_layer = 1;
                 }
                 StringBuilder strSql = new StringBuilder();
                 strSql.Append("update dt_category set ");
                 strSql.Append("channel_id=@channel_id,");
                 strSql.Append("title=@title,");
                 strSql.Append("call_index=@call_index,");
                 strSql.Append("parent_id=@parent_id,");
                 strSql.Append("class_list=@class_list,");
                 strSql.Append("class_layer=@class_layer,");
                 strSql.Append("sort_id=@sort_id,");
                 strSql.Append("link_url=@link_url,");
                 strSql.Append("img_url=@img_url,");
                 strSql.Append("content=@content,");
                 strSql.Append("seo_title=@seo_title,");
                 strSql.Append("seo_keywords=@seo_keywords,");
                 strSql.Append("seo_description=@seo_description");
                 strSql.Append(" where id=@id");
                 SqlParameter[] parameters =
                 {
                     new SqlParameter("@channel_id",      SqlDbType.Int,        4),
                     new SqlParameter("@title",           SqlDbType.NVarChar, 100),
                     new SqlParameter("@call_index",      SqlDbType.NVarChar,  50),
                     new SqlParameter("@parent_id",       SqlDbType.Int,        4),
                     new SqlParameter("@class_list",      SqlDbType.NVarChar, 500),
                     new SqlParameter("@class_layer",     SqlDbType.Int,        4),
                     new SqlParameter("@sort_id",         SqlDbType.Int,        4),
                     new SqlParameter("@link_url",        SqlDbType.NVarChar, 255),
                     new SqlParameter("@img_url",         SqlDbType.NVarChar, 255),
                     new SqlParameter("@content",         SqlDbType.NText),
                     new SqlParameter("@seo_title",       SqlDbType.NVarChar, 255),
                     new SqlParameter("@seo_keywords",    SqlDbType.NVarChar, 255),
                     new SqlParameter("@seo_description", SqlDbType.NVarChar, 255),
                     new SqlParameter("@id",              SqlDbType.Int, 4)
                 };
                 parameters[0].Value  = model.channel_id;
                 parameters[1].Value  = model.title;
                 parameters[2].Value  = model.call_index;
                 parameters[3].Value  = model.parent_id;
                 parameters[4].Value  = model.class_list;
                 parameters[5].Value  = model.class_layer;
                 parameters[6].Value  = model.sort_id;
                 parameters[7].Value  = model.link_url;
                 parameters[8].Value  = model.img_url;
                 parameters[9].Value  = model.content;
                 parameters[10].Value = model.seo_title;
                 parameters[11].Value = model.seo_keywords;
                 parameters[12].Value = model.seo_description;
                 parameters[13].Value = model.id;
                 DbHelperSQL2.ExecuteSql(conn, trans, strSql.ToString(), parameters);
                 //更新子节点
                 UpdateChilds(conn, trans, model.id);
                 trans.Commit();
             }
             catch
             {
                 trans.Rollback();
                 return(false);
             }
         }
     }
     return(true);
 }