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();
     }
 }
        /*更新報廢設備資訊*/

        public static bool UpdateUselessDevice(UselessDeviceModel uselessDevice)
        {
            string updateString = "update [t_device_useless] set typeId=";

            updateString += uselessDevice.getTypeId() + ",deviceName=";
            updateString += SqlString.GetQuotedString(uselessDevice.getDeviceName()) + ",deviceModel=";
            updateString += SqlString.GetQuotedString(uselessDevice.getDeviceModel()) + ",deviceFrom=";
            updateString += SqlString.GetQuotedString(uselessDevice.getDeviceFrom()) + ",deviceCount=";
            updateString += uselessDevice.getDeviceCount() + " where id=" + uselessDevice.getId();

            DataBase db = new DataBase();

            if (db.InsertOrUpdate(updateString) > 0)
            {
                return(true);
            }
            return(true);
        }
        /*登記報廢設備資訊*/

        public static bool AddUselessDevice(UselessDeviceModel uselessDevice)
        {
            string insertString = "insert into [t_device_useless] (typeId,deviceName,deviceModel,deviceFrom,deviceCount) values (";

            insertString += uselessDevice.getTypeId() + ",";
            insertString += SqlString.GetQuotedString(uselessDevice.getDeviceName()) + ",";
            insertString += SqlString.GetQuotedString(uselessDevice.getDeviceModel()) + ",";
            insertString += SqlString.GetQuotedString(uselessDevice.getDeviceFrom()) + ",";
            insertString += uselessDevice.getDeviceCount() + ")";

            DataBase db = new DataBase();

            if (db.InsertOrUpdate(insertString) > 0)
            {
                return(true);
            }
            return(false);
        }