private async void btnGetPorts_Click(object sender, EventArgs e) { clearAllText(); MvItCiscoBo bo = new MvItCiscoBo(); SplashScreenManager.ShowDefaultWaitForm(); DataTable dt = null; gridControl1.DataSource = null; gridControl1.DataBindings.Clear(); gridControl1.RefreshDataSource(); gridView1.Columns.Clear(); gridView1.RefreshData(); dt = await bo.getPortStatusTable(GlobalConstant.MvMisCiscoIpList); SocketException se = null; se = bo.getSocketException(); if (se != null) { MessageBox.Show(se.Message + Environment.NewLine + Environment.NewLine + "持續載入資訊中 ......"); } gridControl1.DataSource = dt; gridView1.OptionsBehavior.Editable = false; gridControl1.RefreshDataSource(); gridView1.RefreshData(); SplashScreenManager.CloseForm(false); }
private async void btnDebugGetPorts_Click(object sender, EventArgs e) { clearAllText(); SplashScreenManager.ShowDefaultWaitForm(); MvItCiscoBo bo = new MvItCiscoBo(); string result = await bo.getPortStatus(GlobalConstant.MvMisCiscoIpList); richTextBox1.Text = result.ToString(); richTextBox1.Refresh(); SplashScreenManager.CloseForm(false); }
private async void btnAddMac_Click(object sender, EventArgs e) { if (teIp.Text.Length == 0 || tePort.Text.Length == 0 || teStatus.Text.Length == 0 || teMacAddress.Text.Length == 0 || teName.Text.Length == 0) { MessageBox.Show("請輸入完整的Cisco及Mac資訊"); return; } if (teStatus.Text.IndexOf("err-disable") == 0) { // err-disable 正常操作 } else if (teStatus.Text.IndexOf("disable") >= 0) { MessageBox.Show("請先將該port enable後再重新操作"); return; } // 比對是否符合網卡輸入規則 Regex rgx = new Regex(@"[a-z0-9]{4}.[a-z0-9]{4}.[a-z0-9]{4}$"); bool isMatch = rgx.IsMatch(teMacAddress.Text); if (isMatch == false) { MessageBox.Show("請輸入符合格式如下, 並請轉為小寫" + Environment.NewLine + "bxxe.bxxb.0xx4"); return; } // 執行mac address add作業 SplashScreenManager.ShowDefaultWaitForm(); string result = string.Empty; using (MvItCiscoBo bo = new MvItCiscoBo()) { result = await bo.addMacAddressOnPortByTelnet(teIp.Text, tePort.Text, teMacAddress.Text, teName.Text, true); } if (result.IndexOf("has reached maximum limit") > 0) { //代表已超過上線 MessageBox.Show("已超過maximum limit上限, 該mac address無法加入" + Environment.NewLine + "請看debug output"); richTextBox1.Text = result; } else { btnGetMac_Click(sender, e); } clearAllText(); disableAllComponent(); SplashScreenManager.CloseForm(false); }
private async void btnGetLogsByIp_Click(object sender, EventArgs e, string routerIp) { SplashScreenManager.ShowDefaultWaitForm(); string result = string.Empty; using (MvItCiscoBo bo = new MvItCiscoBo()) { result = await bo.getRouterLogsByTelnet(routerIp); } richTextBox1.Text = result.ToString(); richTextBox1.Refresh(); SplashScreenManager.CloseForm(false); }
private async void btnGetPortsFromDB_Click(object sender, EventArgs e) { clearAllText(); MvItCiscoBo bo = new MvItCiscoBo(); SplashScreenManager.ShowDefaultWaitForm(); DataTable dt = null; DataTable dtFromCisco = null; gridControl1.DataSource = null; gridControl1.DataBindings.Clear(); gridControl1.RefreshDataSource(); gridView1.Columns.Clear(); gridView1.RefreshData(); dt = MvDbDao.collectData_ItNetworkDevice(); dt.Columns.Remove("SN"); dt.Columns.Add("IsInCisco"); //dtFromCisco = await bo.getStatusTableIncludeMacAddress(new string[] { "192.168.151.11" }); dtFromCisco = await bo.getStatusTableIncludeMacAddress(GlobalConstant.MvMisCiscoIpList); Hashtable cacheResult = new Hashtable(); string matchKey = string.Empty; // 將Cisco 資料放入HashTable foreach (DataRow drFromCisco in dtFromCisco.Rows) { matchKey = string.Format("{0}{1}{2}{3}", drFromCisco["IP"], drFromCisco["Port"], drFromCisco["MacAddress"], drFromCisco["Name"]); cacheResult.Add(matchKey, true); } matchKey = string.Empty; foreach (DataRow dr in dt.Rows) { matchKey = string.Format("{0}{1}{2}{3}", dr["DeviceIP"], dr["Port"], dr["Mac"], dr["No"]); if (cacheResult.Contains(matchKey) == true) { dr["IsInCisco"] = "V"; } } gridView1.Columns.Clear(); gridControl1.DataSource = dt; gridView1.OptionsBehavior.Editable = false; gridControl1.RefreshDataSource(); gridView1.RefreshData(); SplashScreenManager.CloseForm(false); }
private async void btnSetMacNumber_Click(object sender, EventArgs e) { if (teIp.Text.Length == 0 || tePort.Text.Length == 0 || teStatus.Text.Length == 0 || teName.Text.Length == 0 || teMacNumber.Text.Length == 0) { MessageBox.Show("請輸入完整的Cisco及Mac Number資訊"); return; } if (teStatus.Text.IndexOf("err-disable") == 0) { // err-disable 正常操作 } else if (teStatus.Text.IndexOf("disable") >= 0) { MessageBox.Show("請先將該port enable後再重新操作"); return; } // 比對輸入是否為數字 int n; if (int.TryParse(teMacNumber.Text, out n) == false) { MessageBox.Show("請輸入數字"); return; } // 執行mac address number modify作業 SplashScreenManager.ShowDefaultWaitForm(); string result = string.Empty; using (MvItCiscoBo bo = new MvItCiscoBo()) { result = await bo.setMacAddressNumberOnPortByTelnet(teIp.Text, tePort.Text, teMacNumber.Text, true); } if (result.IndexOf("Maximum is less than") >= 0) { //代表設定的數量比已存在的網卡少, 要先移除網卡 MessageBox.Show("修改數量比已設定的網卡數量少, 請加大輸入數量或先移除網卡" + Environment.NewLine + "請看debug output"); richTextBox1.Text = result; } else { btnGetMac_Click(sender, e); } clearAllText(); disableAllComponent(); SplashScreenManager.CloseForm(false); }
private void btnDisablePort_Click(object sender, EventArgs e) { if (teIp.Text.Length == 0 || tePort.Text.Length == 0) { return; } // 不可以使用static 的寫法, 會被cache using (MvItCiscoBo bo = new MvItCiscoBo()) { bo.disablePortByTelnet(teIp.Text, tePort.Text); } Thread.Sleep(300); // 跑太快抓回來的資訊會不同步 clearAllText(); btnGetPorts_Click(sender, e); disableAllComponent(); }
private async void btnGetMac_Click(object sender, EventArgs e) { if (teIp.Text.Length == 0 || tePort.Text.Length == 0 || teStatus.Text.Length == 0) { return; } richTextBox1.Text = string.Empty; // Get Mac Address string macAddress = string.Empty; using (MvItCiscoBo bo = new MvItCiscoBo()) { macAddress = await bo.getMacAddressOnPortByTelnet(teIp.Text, tePort.Text); } richTextBox1.Text = macAddress; }