using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TopWinCMS.BLL;
using TopWinCMS.Model;
using TopWinCMS.Common;
namespace TopWinCMS.WebUI.Admin.Soft
{
    public partial class Soft_LinkErr : System.Web.UI.Page
    {
        SQLModel s_model = new SQLModel();
        SoftLinkErrManage MyClassBLL = new SoftLinkErrManage();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RightsCheck.CheckWorkRight("LinkErr",true);


                BT_Complete.Attributes.Add("onclick", "return confirm('您确定设置为“处理完毕”？');");
                BT_Delete.Attributes.Add("onclick", "return confirm('您确定要删除？');");

                Action = null;
                
              
                BindList();
            }
        }

        #region 当前状态
        private string Action
        {
            set
            {
                ViewState["Action"] = value;
            }
            get
            {
                if (ViewState["Action"] == null)
                {
                    return null;
                }
                else
                {
                    return ViewState["Action"].ToString();
                }
            }
        }
        #endregion

        public void BindList()
        {
            GV_List.EmptyDataTemplate = TopWinCMS.WebFactory.PageBase.GetTemplate(this);
            if (Action == null)
            {
                LB_Path.Text = Config.SiteName + "后台 → <a href=\"Soft_LinkErr.aspx\">软件错误报告管理</a> → 未处理错误报告";
                s_model.WHERE = " Complete=0 And ModelID=" + Request.QueryString["ModelID"];
            }
            else
            {
                LB_Path.Text = Config.SiteName + "后台 → <a href=\"Soft_LinkErr.aspx\">软件错误报告管理</a> →  已处理错误报告";
                s_model.WHERE = " Complete=1 And ModelID=" + Request.QueryString["ModelID"];
            }
            s_model.PageSize = 10;

            MyClassBLL.BindList(GV_List, PageNavigation1, s_model);
         

            MyJavascript.RegJS(UpdatePanel1, "attachMouseEvent('" + GV_List.ClientID + "');");
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Action = null;
            BindList();
        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            Action = "Complete=1";
            BindList();
        }

        protected void PageNavigation1_PageChanging(object src, TopWinCMS.WebControls.PageChangingEventArgs e)
        {
            s_model.PageNo = e.NewPageIndex;
            BindList();
        }

        protected void GV_List_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int Index = Convert.ToInt32(e.CommandArgument);
            string ID = GV_List.DataKeys[Index].Value.ToString();
            if (e.CommandName == "Complete")
            {
                MyClassBLL.Complete(ID, UpdatePanel1);
                MsgBox.Alert("设置成功！", UpdatePanel1);
            }
            if (e.CommandName == "DeleteSoftLinkErr")
            {
                MyClassBLL.Delete(ID, UpdatePanel1);
                MsgBox.Alert("删除成功！", UpdatePanel1);
            }
            BindList();
        }

        protected void GV_List_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                TableCell myTableCell = e.Row.Cells[7];

                LinkButton btnDel = (LinkButton)myTableCell.Controls[0];

                btnDel.Attributes.Add("onclick", "return confirm('您确定要删除？');");

                myTableCell = e.Row.Cells[6];
                LinkButton LB_IsLock = (LinkButton)myTableCell.Controls[0];

                if (LB_IsLock.Text == "1")
                {
                    LB_IsLock.Text = "未处理";
                    LB_IsLock.Attributes.Add("onclick", "return confirm('您确定设置为“处理完毕”？');");
                }
                else
                {
                    LB_IsLock.Text = "处理完毕";

                }
            }
        }

        protected void BT_Delete_Click(object sender, EventArgs e)
        {
            MyClassBLL.Delete(GetSelectedRow.IDs(GV_List), UpdatePanel1);
            MsgBox.Alert("删除成功！", UpdatePanel1);
            BindList();
        }

        protected void BT_Complete_Click(object sender, EventArgs e)
        {
            MyClassBLL.Complete(GetSelectedRow.IDs(GV_List), UpdatePanel1);
            MsgBox.Alert("设置成功！", UpdatePanel1);
            BindList();
        }

    }
}