Пример #1
0
    //删除操作
    protected void List_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int    ztId         = Convert.ToInt32(List.DataKeys[e.RowIndex].Value);
        string zhuanTiImage = ((HiddenField)List.Rows[e.RowIndex].FindControl("ZhuanTiImageHid")).Value;

        ZhuanTiInfo zhuanTi = bll.GetZhuanTiByZhuanTiId(userId, ztId);

        zhuanTi.ZhuanTiLive = 0;
        zhuanTi.Synchronize = 1;
        zhuanTi.ModifyDate  = DateTime.Now;

        using (TransactionScope ts = new TransactionScope())
        {
            bool success = false;

            DataTable lists = item_bll.GetItemListAllByZhuanTiId(userId, ztId);
            if (lists.Rows.Count > 0)
            {
                foreach (DataRow dr in lists.Rows)
                {
                    int itemId    = Convert.ToInt32(dr["ItemID"]);
                    int itemAppId = Convert.ToInt32(dr["ItemAppID"]);

                    success = item_bll.DeleteItem(userId, itemId, itemAppId);
                    if (!success)
                    {
                        break;
                    }
                }
            }
            else
            {
                success = true;
            }

            if (success)
            {
                success = bll.UpdateZhuanTi(zhuanTi);
            }
            else
            {
                Utility.Alert(this, "消费删除失败!");
                return;
            }

            if (success)
            {
                Utility.Alert(this, "删除成功。");

                List.EditIndex = -1;
                BindGrid();
            }
            else
            {
                Utility.Alert(this, "专题删除失败!");
            }

            ts.Complete();
        }

        //删除专题图片
        if (ImageHelper.CanDelete(zhuanTiImage))
        {
            try
            {
                ImageHelper.DeleteZhuanTiImage(zhuanTiImage);
            }
            catch { }
        }
    }