Exemplo n.º 1
0
        private void MyDeviceWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            btSave.IsEnabled = true;

            if (result.Result)
            {
                if (this.mode == EType.WindowMode.ADD_MODE)
                {
                    if (getDeviceWorker.IsBusy)
                    {
                        getDeviceWorker.CancelAsync();
                    }
                    else
                    {
                        getDeviceWorker.RunWorkerAsync();
                    }
                }
                else
                {
                    DTO_Device oldDevice = Repository.lstAllDevices.FirstOrDefault(c => c.Id == myDevice.Id);

                    if (oldDevice != null)
                    {
                        oldDevice = myDevice;
                    }

                    this.DialogResult = true;
                    this.Hide();
                }
            }
            else
            {
                MessageBox.Show(result.Detail, "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 2
0
        private void cbConnectDevice_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (mode == EType.WindowMode.ADD_MODE)
            {
                DTO_Device selectedDevice = (DTO_Device)cbConnectDevice.SelectedItem;

                cbConnectSocket.ItemsSource       = selectedDevice.Sockets.Where(s => s.IsUse == false);
                cbConnectSocket.DisplayMemberPath = "Name";
                cbConnectSocket.SelectedValuePath = "Id";

                cbConnectSocket.SelectedIndex = 0;
            }
            else
            {
                DTO_Device selectedDevice = (DTO_Device)cbConnectDevice.SelectedItem;

                cbConnectSocket.ItemsSource       = selectedDevice.Sockets;
                cbConnectSocket.DisplayMemberPath = "Name";
                cbConnectSocket.SelectedValuePath = "Id";

                if (socket.ConnectedDeviceId == null)
                {
                    cbConnectSocket.SelectedIndex = 0;
                }
                else
                {
                    cbConnectSocket.SelectedValue = socket.ConnectedDeviceSocketId;
                }
            }
        }
Exemplo n.º 3
0
        private void cbDevice_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DTO_Device selectedDevice = (DTO_Device)cbDevice.SelectedItem;

            if (selectedDevice != null)
            {
                cbDeviceSocket.ItemsSource       = selectedDevice.Sockets;
                cbDeviceSocket.DisplayMemberPath = "Name";
                cbDeviceSocket.SelectedValuePath = "Id";
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Update device information
        /// </summary>
        /// <param name="device">The device object want to update</param>
        /// <returns>Return true if update success, Error if update fail or validate fail</returns>
        public SQLResult UpdateDevice(DTO_Device device)
        {
            if (device == null)
            {
                return(new SQLResult(false, "Device can't null"));
            }

            if (!device.Validate().Result)
            {
                return(new SQLResult(false, device.Validate().Detail));
            }

            return(dal.UpdateDevice(device));
        }
Exemplo n.º 5
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            InitData();

            switch (mode)
            {
            case EType.WindowMode.ADD_MODE:
                ResetControl();
                myDevice = new DTO_Device();
                break;

            default:
                BindData();
                break;
            }
        }
Exemplo n.º 6
0
        private void DeleteDeviceWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (result.Result)
            {
                DTO_Device oldDevice = Repository.lstAllDevices.FirstOrDefault(c => c.Id == myDevice.Id);
                if (oldDevice != null)
                {
                    Repository.lstAllDevices.Remove(oldDevice);
                }

                this.DialogResult = true;
                this.Hide();
            }
            else
            {
                MessageBox.Show(result.Detail, "", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Get all device
        /// </summary>
        /// <returns>Return list device or null if error</returns>
        public List <DTO_Device> GetAllDevice()
        {
            List <DTO_Device> lstDevices = new List <DTO_Device>();
            DataTable         dt         = dal.GetAllDevice();

            if (dt.Rows.Count < 0)
            {
                return(null);
            }

            try
            {
                foreach (DataRow row in dt.Rows)
                {
                    FAMode mode = new FAMode();
                    mode.IsUse      = Convert.ToInt16(row["FAMode"].ToString()) == 1 ? true : false;
                    mode.FAHWNumber = Convert.ToInt16(row["FAHW"].ToString());

                    DTO_Device device = new DTO_Device();

                    device.Id          = row["Id"].ToString();
                    device.Name        = row["Name"].ToString();
                    device.MAC         = row["MAC"].ToString();
                    device.IP          = row["IP"].ToString();
                    device.Subnet      = row["Subnet"].ToString();
                    device.GateWay     = row["GateWay"].ToString();
                    device.HostIp      = row["HostIp"].ToString();
                    device.FAMode      = mode;
                    device.CtrMode     = (ControlMode)Convert.ToInt16(row["CtrlMode"].ToString());
                    device.Description = row["Description"].ToString();

                    device.Sockets = busSocket.GetSocketByDevice(device.Id);

                    lstDevices.Add(device);
                }

                return(lstDevices);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Update device information in database
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public SQLResult UpdateDevice(DTO_Device device)
        {
            DataTable dt     = new DataTable();
            SQLResult result = new SQLResult(false, "");

            try
            {
                _conn.Open();

                SqlCommand command = new SqlCommand();
                command.Connection  = _conn;
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "spLDeviceSave";
                command.Parameters.AddWithValue("WorkType", "U");
                command.Parameters.AddWithValue("Id", device.Id);
                command.Parameters.AddWithValue("Name", device.Name);
                command.Parameters.AddWithValue("MAC", device.MAC);
                if (device.IP == null)
                {
                    command.Parameters.AddWithValue("IP", DBNull.Value);
                }
                else
                {
                    command.Parameters.AddWithValue("IP", device.IP);
                }

                if (device.Subnet == null)
                {
                    command.Parameters.AddWithValue("Subnet", DBNull.Value);
                }
                else
                {
                    command.Parameters.AddWithValue("Subnet", device.Subnet);
                }

                if (device.GateWay == null)
                {
                    command.Parameters.AddWithValue("Gateway", DBNull.Value);
                }
                else
                {
                    command.Parameters.AddWithValue("Gateway", device.GateWay);
                }

                if (device.HostIp == null)
                {
                    command.Parameters.AddWithValue("HostIP", DBNull.Value);
                }
                else
                {
                    command.Parameters.AddWithValue("HostIP", device.HostIp);
                }
                command.Parameters.AddWithValue("FAMode", device.FAMode.IsUse ? 1 : 0);
                command.Parameters.AddWithValue("FAHW", device.FAMode.FAHWNumber);
                command.Parameters.AddWithValue("CtrlMode", device.CtrMode);
                command.Parameters.AddWithValue("Description", device.Description);

                SqlDataAdapter adapter = new SqlDataAdapter();
                adapter.SelectCommand = command;
                adapter.Fill(dt);

                if (dt.Rows[0]["Result"].ToString() == "OK")
                {
                    result.Result = true;
                }

                result.Detail = dt.Rows[0]["Detail"].ToString();
            }
            catch (Exception ex)
            {
                result.Detail = ex.Message;
            }
            finally
            {
                _conn.Close();
            }

            return(result);
        }
Exemplo n.º 9
0
 public wdDeviceDetail(EType.WindowMode mode, DTO_Device device)
 {
     InitializeComponent();
     this.myDevice = device;
     this.mode     = mode;
 }