protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["username"] == null)
     {
         Response.Write("<script>alert('請先登入系統!');top.location.href='login.aspx';</script>");
         return;
     }
     if (!IsPostBack)
     {
         DataSet deviceTypeDs = DeviceTypeDAO.QueryAllDeviceType();
         for (int i = 0; i < deviceTypeDs.Tables[0].Rows.Count; i++)
         {
             DataRow  dr = deviceTypeDs.Tables[0].Rows[i];
             ListItem li = new ListItem(dr["typeName"].ToString(), dr["typeId"].ToString());
             this.TypeId.Items.Add(li);
         }
         int id = Int32.Parse(Request.QueryString["id"]);
         UselessDeviceModel uselessDevice = UselessDeviceDAO.GetUselessDevice(id);
         this.TypeId.SelectedValue = uselessDevice.getTypeId().ToString();
         this.DeviceName.Text      = uselessDevice.getDeviceName();
         this.DeviceModel.Text     = uselessDevice.getDeviceModel();
         this.DeviceFrom.Text      = uselessDevice.getDeviceFrom();
         this.DeviceCount.Text     = uselessDevice.getDeviceCount().ToString();
     }
 }
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            string  deviceName = this.DeviceName.Text;
            int     typeId     = Int32.Parse(this.TypeId.SelectedValue);
            DataSet ds         = UselessDeviceDAO.QueryDeviceInfo(deviceName, typeId);

            this.GridView1.DataSourceID = null;
            this.GridView1.DataSource   = ds;
            this.GridView1.PageIndex    = e.NewPageIndex;
            this.GridView1.DataBind();
        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //当鼠标选择某行时变颜色
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00ffee';");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");

                Literal TypeName = (Literal)e.Row.Cells[1].FindControl("TypeName");

                int id = Convert.ToInt32(this.GridView1.DataKeys[e.Row.RowIndex].Value.ToString());
                TypeName.Text = UselessDeviceDAO.GetDeviceTypeName(id);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["username"] == null)
            {
                Response.Write("<script>alert('請先登入系統!');top.location.href='login.aspx';</script>");
                return;
            }

            int id = Int32.Parse(Request.QueryString["id"]);

            if (UselessDeviceDAO.DeleteUselessDevice(id))
            {
                Response.Write("<script>alert('刪除成功!');location.href='UselessDeviceManage.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('刪除失敗!');location.href='UselessDeviceManage.aspx';</script>");
            }
        }
        protected void Btn_Add_Click(object sender, EventArgs e)
        {
            UselessDeviceModel uselessDevice = new UselessDeviceModel();

            uselessDevice.setTypeId(Int32.Parse(this.TypeId.SelectedValue));
            uselessDevice.setDeviceName(this.DeviceName.Text);
            uselessDevice.setDeviceModel(this.DeviceModel.Text);
            uselessDevice.setDeviceFrom(this.DeviceFrom.Text);
            uselessDevice.setDeviceCount(Int32.Parse(this.DeviceCount.Text));

            if (UselessDeviceDAO.AddUselessDevice(uselessDevice))
            {
                Response.Write("<script>alert('報廢設備登記成功!');location.href='UselessDeviceAdd.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('報廢設備登記失敗!');location.href='UselessDeviceAdd.aspx';</script>");
            }
        }
        protected void Btn_Update_Click(object sender, EventArgs e)
        {
            UselessDeviceModel uselessDevice = new UselessDeviceModel();
            int id = Int32.Parse(Request.QueryString["id"]);

            uselessDevice.setId(id);
            uselessDevice.setTypeId(Int32.Parse(this.TypeId.SelectedValue));
            uselessDevice.setDeviceName(this.DeviceName.Text);
            uselessDevice.setDeviceModel(this.DeviceModel.Text);
            uselessDevice.setDeviceFrom(this.DeviceFrom.Text);
            uselessDevice.setDeviceCount(Int32.Parse(this.DeviceCount.Text));

            if (UselessDeviceDAO.UpdateUselessDevice(uselessDevice))
            {
                Response.Write("<script>alert('更新成功!');location.href='UselessDeviceManage.aspx';</script>");
            }
            else
            {
                Response.Write("<script>alert('更新失败!');</script>");
            }
        }