Example #1
0
        private SettingDevice ReadXML(string path)
        {
            SettingDevice setting = null;

            try
            {
                XmlDocument xdoc = new XmlDocument();
                xdoc.Load(path);

                foreach (XmlNode node in xdoc.DocumentElement)
                {
                    setting = new SettingDevice();
                    setting.Cops = node.Attributes["Name"].Value.ToString();
                    setting.DelayTime = Int32.Parse(node.Attributes["Delay"].Value.ToString());
                    setting.Limit = Int32.Parse(node.Attributes["Limit"].Value.ToString());
                    //MessageBox.Show(first);
                }
            }
            catch (IOException ex)
            {
                return null;
            }
            return setting;
        }
Example #2
0
        private void WriteXML(string path, SettingDevice device)
        {
            XmlTextWriter textWriter = new XmlTextWriter(path, null);
            // Opens the document
            textWriter.WriteStartDocument();
            // Write first element
            textWriter.WriteStartElement("Root");
            textWriter.WriteStartElement("Device");
            // Write next element
            textWriter.WriteAttributeString("Name", device.Cops);
            textWriter.WriteAttributeString("Delay", device.DelayTime.ToString());
            textWriter.WriteAttributeString("Limit", device.Limit.ToString());

            textWriter.WriteEndElement();
            textWriter.WriteEndElement();
            // Ends the document.
            textWriter.WriteEndDocument();
            // close writer
            textWriter.Close();

            MessageBox.Show("Cập nhật thành công");
        }
Example #3
0
        private void dgvDevice_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            // Cai dat cau hinh
            if (e.ColumnIndex == 5)
            {
                int index = e.RowIndex;
                SettingDevice settingDevice = new SettingDevice();
                settingDevice.DeviceName = dgvDevice.Rows[index].Cells[1].Value.ToString();
                settingDevice.Cops = dgvDevice.Rows[index].Cells[2].Value.ToString();
                settingDevice.DelayTime = Int32.Parse(dgvDevice.Rows[index].Cells[3].Value.ToString());
                settingDevice.Limit = Int32.Parse(dgvDevice.Rows[index].Cells[4].Value.ToString());

                SetupDeviceForm deviceSetupForm = new SetupDeviceForm();
                deviceSetupForm.dataSetup = settingDevice;
                deviceSetupForm.ShowDialog();

                dgvDevice.Rows[index].Cells[2].Value = deviceSetupForm.cbMangDiDong.SelectedValue.ToString();
                dgvDevice.Rows[index].Cells[3].Value = deviceSetupForm.cbDoTre.SelectedValue.ToString();
                dgvDevice.Rows[index].Cells[4].Value = deviceSetupForm.cbGioiHan.SelectedValue.ToString();

                dgvDevice.Refresh();


                // Create a new file in C:\\ dir
                WriteXML(envPath + "\\" + dgvDevice.Rows[e.RowIndex].Cells[2].Value + ".xml",
                    new SettingDevice(dgvDevice.Rows[e.RowIndex].Cells[1].Value.ToString(),
                        dgvDevice.Rows[e.RowIndex].Cells[2].Value.ToString(),
                        Int32.Parse(dgvDevice.Rows[e.RowIndex].Cells[3].Value.ToString()),
                    Int32.Parse(dgvDevice.Rows[e.RowIndex].Cells[4].Value.ToString())));

            }
        }