示例#1
0
        protected void btnDelSelected_Click(object sender, EventArgs e)
        {
            string selectItems = getSelectedItemsId();

            if (selectItems != "")
            {
                //1.删除文章并且获取需要重新生成的类型id集合。2.从数据库中删除。3.重新生成相关页面

                string[] ids     = selectItems.Split(',');
                int[]    typeids = new int[ids.Length];
                int      length  = 0; //不重复的typeid数目
                // DateTime[] articlePtime = new DateTime[ids.Length];

                int spcId = 0;
                if (Request.QueryString["spcId"] != null)
                {
                    spcId = Convert.ToInt32(Request.QueryString["spcId"]);
                }

                string strDir = string.Empty;

                //不论是否静态生成都尝试删除已有的文件
                //if (sys.IsStatic)
                //{
                strDir = sys.getSpcDir(spcId);
                DataTable dt = bllarticle.GetList("id in (" + selectItems + ")").Tables[0];
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    int  typeid      = Convert.ToInt32(dt.Rows[i]["dbo_typeid"]);
                    bool ExistTypeId = false;
                    for (int j = 0; j < length; j++)
                    {
                        if (typeid == typeids[j])
                        {
                            ExistTypeId = true;
                        }
                    }
                    if (!ExistTypeId)
                    {
                        typeids[length] = typeid;
                        length++;
                    }
                    //articlePtime[i] = Convert.ToDateTime(dt.Rows[i]["ptime"]);
                    sys.deleteArticleFile(Convert.ToInt32(ids[i]), strDir, Convert.ToDateTime(dt.Rows[i]["dbo_ptime"]));
                }
                //}
                bllarticle.DeleteList(selectItems);
                bllarticleimg.DeleteByArticleIdList(selectItems);


                if (sys.IsStatic)
                {
                    for (int i = 0; i < length; i++)
                    {
                        sys.ToStaticListWithArticleEdit(typeids[i], strDir);
                    }

                    if (Request.QueryString["spcId"] != null)
                    {
                        spcId = Convert.ToInt32(Request.QueryString["spcId"]);
                    }
                    sys.ToStaticPageWithActive(Convert.ToInt32(spcId));
                }
            }
            this.BindData();
        }