private void SMSapplication_Load(object sender, EventArgs e) { try { #region Hien thi cac port có the su dung foreach (COMPortInfo comPort in COMPortInfo.GetCOMPortsInfo()) { if (comPort.Description.Contains("PC UI Interface")) { this.cboPortName.Items.Add(comPort.Name); } } btnThem.Enabled = false; cbChonNhaMang.Enabled = true; #endregion #region Hien thi so ky tu lbSoKyTu.Text = txtMessage.Text.Length.ToString(); #endregion #region Load du lieu cho combobox chon cac so thuoc nha mang // Mang di dong var mangDatasource = new[] { new { Text = "-Lọc Danh Sách-", Value = "" }, new { Text = "Chọn tất cả", Value = "All" }, new { Text = "Mobifone", Value = "Mobifone" }, new { Text = "Viettel", Value = "Viettel" }, new { Text = "Vinaphone", Value = "Vinaphone" }, new { Text = "Other", Value = "Other" }, new { Text = "Số đã gửi", Value = "Sent" }, new { Text = "Số gửi lỗi", Value = "Error" } }; cbChonNhaMang.DataSource = mangDatasource; cbChonNhaMang.DisplayMember = "Text"; cbChonNhaMang.ValueMember = "Value"; #endregion // Tim Thiet Bi timThietBi(); } catch (Exception ex) { ErrorLog(ex.Message); } }
private void timThietBi() { dgvDevice.Columns.Clear(); DataTable dtDevice = new DataTable(); // Tao cau truc datatable dtDevice.Columns.Add("Chọn", typeof(bool)); dtDevice.Columns.Add("Cổng", typeof(string)); dtDevice.Columns.Add("Mạng", typeof(string)); dtDevice.Columns.Add("Độ trễ", typeof(int)); dtDevice.Columns.Add("Giới hạn", typeof(int)); foreach (COMPortInfo comPort in COMPortInfo.GetCOMPortsInfo()) { if (comPort.Description.Contains("PC UI Interface")) { string portName = comPort.Name; //Open communication port SerialPort sPort = objclsSMS.OpenPort(portName, Convert.ToInt32(this.cboBaudRate.Text), Convert.ToInt32(this.cboDataBits.Text), Convert.ToInt32(this.txtReadTimeOut.Text), Convert.ToInt32(this.txtWriteTimeOut.Text)); if (sPort != null) { string copSim = objclsSMS.readSimCode(sPort); if ("\"45201\"".Equals(copSim)) { SettingDevice setting = ReadXML(envPath + "\\" + "Mobifone" + ".xml"); if (setting != null) { dtDevice.Rows.Add(false, portName, setting.Cops, setting.DelayTime.ToString(), setting.Limit.ToString()); } else { dtDevice.Rows.Add(false, portName, "Mobifone", "0", "0"); } } if ("\"45202\"".Equals(copSim)) { SettingDevice setting = ReadXML(envPath + "\\" + "Vinaphone" + ".xml"); if (setting != null) { dtDevice.Rows.Add(false, portName, setting.Cops, setting.DelayTime.ToString(), setting.Limit.ToString()); } else { dtDevice.Rows.Add(false, portName, "Vinaphone", "0", "0"); } } if ("\"45204\"".Equals(copSim)) { SettingDevice setting = ReadXML(envPath + "\\" + "Viettel" + ".xml"); if (setting != null) { dtDevice.Rows.Add(false, portName, setting.Cops, setting.DelayTime.ToString(), setting.Limit.ToString()); } else { dtDevice.Rows.Add(false, portName, "Viettel", "0", "0"); } } } else { //MessageBox.Show("Invalid port settings"); this.statusBar1.Text = "Invalid port settings"; } objclsSMS.ClosePort(sPort); } dgvDevice.DataSource = dtDevice; dgvDevice.Refresh(); } DataGridViewButtonColumn btnSetup = new DataGridViewButtonColumn(); dgvDevice.Columns.Add(btnSetup); btnSetup.Text = "Cài đặt"; btnSetup.Name = ""; btnSetup.UseColumnTextForButtonValue = true; }