protected void btnAdd_OnClick(object sender, EventArgs e)
        {
            DeviceDa deviceDa = new DeviceDa();
            List<Device> lstDevice = deviceDa.getDevices();

            Device device = new Device();
            lstDevice.Add(device);

            grdDevices.EditIndex = lstDevice.Count-1;

            grdDevices.DataSource = lstDevice;
            grdDevices.DataBind();
        }
        protected void grdDevices_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Device device = new Device();
            device.Id = int.Parse(e.Keys[0].ToString());

            GridViewRow row = (GridViewRow)grdDevices.Rows[e.RowIndex];
            DropDownList drpCell = (DropDownList)row.FindControl("drpCell");
            DropDownList drpType = (DropDownList)row.FindControl("drpType");
            DropDownList drpBrand = (DropDownList)row.FindControl("drpBrand");

            device.IP = e.NewValues[0].ToString();
            device.CellId = int.Parse(drpCell.SelectedValue);
            device.Name = e.NewValues[1].ToString();
            device.TypeId = int.Parse(drpType.SelectedValue);
            device.BrandId = int.Parse(drpBrand.SelectedValue);

            //Save Data
            DeviceDa deviceDa = new DeviceDa();
            deviceDa.Save(device);

            grdDevices.EditIndex = -1;
            loadData();
        }
 private void loadDevices()
 {
     DeviceDa deviceDa = new DeviceDa();
     grdDevices.DataSource = deviceDa.getDevices();
     grdDevices.DataBind();
 }
        protected void grdDevices_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int id = int.Parse(e.Keys[0].ToString());
            DeviceDa deviceDa = new DeviceDa();
            deviceDa.Delete(id);

            grdDevices.EditIndex = -1;
            loadData((DateTime)Session["date"]);
        }
        protected void btnShowDevices_OnClick(int taskId)
        {
            btnAdd.Visible = false;
            btnSave.Visible = true;

            mpe.Show();

            DeviceDa deviceDa = new DeviceDa();
            TaskDa taskDa = new TaskDa();

            TaskData taskData = taskDa.GetTask(taskId);

            Session["SelectedDevices"] = deviceDa.GetDevicesFromTask(taskId);
            Session["ActiveTask"] = taskData;

            grdDevices.DataSource = deviceDa.getDevices();
            grdDevices.DataBind();
        }
        protected void btnSelectCell_OnCommand(object sender, CommandEventArgs e)
        {
            int cellId;
            if(int.TryParse(e.CommandArgument.ToString(),out cellId))
            {
                List<Device> lstDevice = new DeviceDa().GetDevicesByCell(cellId);

                for (int i = 0; i < grdDevices.Rows.Count; i++)
                {
                    CheckBox chkSelectDevice = (CheckBox)grdDevices.Rows[i].Cells[0].FindControl("ChbSelect");
                    chkSelectDevice.Checked = false;

                    for(int iDiv=0;iDiv<lstDevice.Count;iDiv++){
                        if ((int)grdDevices.DataKeys[i].Value == lstDevice[iDiv].Id)
                        {
                            chkSelectDevice.Checked = true; break;
                        }
                    }
                }
            }

            mpe.Show();
        }
        protected void btnSaveDate_OnClick(object sender, EventArgs e)
        {
            TaskData taskData = (TaskData)  Session["ActiveTask"];

            List<Device> lstActiveDevices = new List<Device>();

            for (int i = 0; i < grdDevices.Rows.Count; i++)
            {
                int id = (int) grdDevices.DataKeys[i].Value;
                DeviceDa deviceDa = new DeviceDa();
                Device device = deviceDa.GetDevice(id);
                //Device device = (Device) ;

                CheckBox ChbSelect = (CheckBox) grdDevices.Rows[i].Cells[0].FindControl("ChbSelect");
                if (ChbSelect.Checked)
                {
                    lstActiveDevices.Add(device);
                }
            }

            TaskDa taskDa = new TaskDa();
            taskDa.updateTask(taskData, lstActiveDevices);

            //Update
            loadData(taskData.Date);
        }
        public void GetDevicesForBackupByDate(DateTime date)
        {
            DeviceDa deviceDa = new DeviceDa();
            List<Device> devices = deviceDa.getDevicesByTime(date);

            //backup via ftp met thread
            for (int i = 0; i < devices.Count; i++)
            {
                doBackUp(devices[i],date);
            }
        }