private void AddForm_Save_Button_Click(object sender, EventArgs e) { String title = AddForm_Title_TextBox.Text; String url = AddForm_Url_TextBox.Text; String warn = AddForm_Warn_RichTextBox.Text; Boolean checkFlag = true; StringBuilder checkMsg = new StringBuilder(); if ("".Equals(title)) { checkFlag = false; checkMsg.Append("名称未填写\r\n"); } if ("".Equals(url)) { checkFlag = false; checkMsg.Append("地址未填写\r\n"); } if (!checkFlag) { MessageBox.Show(checkMsg.ToString(), "错误"); } else { /** 数据正常,生成新的ini数据,执行StartForm添加按钮和新增rdp文件操作 */ /* 生成新INI ****************************/ String newSection = Guid.NewGuid().ToString(); // 生成title iniUtils.IniWriteValue(Config.MonitorIniPath, newSection, "title", title); iniUtils.IniWriteValue(Config.MonitorIniPath, newSection, "url", url); iniUtils.IniWriteValue(Config.MonitorIniPath, newSection, "warn", warn); // 添加默认是监听 iniUtils.IniWriteValue(Config.MonitorIniPath, newSection, "stat", "1"); // sections缓存数据新增 MonitorSections.MonitorSection monitorSection = new MonitorSections.MonitorSection(); monitorSection.title = title; monitorSection.url = url; monitorSection.stat = "1"; monitorSection.warn = warn; MonitorSections.updateMonitor(newSection, monitorSection); /* 生成新INI结束 ************************/ /* StartForm中添加新服务按钮 *************/ mainForm.addButton(newSection); /* 添加新服务按钮完成****** *************/ // 关闭新增窗口 AddForm_Cancel_Button_Click(sender, e); } }
/** * 右键停止按钮点击事件 * */ private void BtnRightStopClick(Object sender, EventArgs e) { ToolStripMenuItem menuItem = (ToolStripMenuItem)sender; String section = (String)menuItem.Tag; // 停止监听 iniUtils.IniWriteValue(Config.MonitorIniPath, section, "stat", "0"); // 按钮背景置灰 Button button = (Button)ControlUtils.GetControlInstance(flowLayoutPanel, section); setButtonBackColor(button, Color.LightGray); // 缓存数据更新为停止 MonitorSections.MonitorSection monitorSection = MonitorSections.getMonitorByKey(section); monitorSection.stat = "0"; MonitorSections.updateMonitor(section, monitorSection); }
private void UpdateForm_Save_Button_Click(object sender, EventArgs e) { String title = UpdateForm_Title_TextBox.Text; String url = UpdateForm_Url_TextBox.Text; String warn = UpdateForm_Warn_RichTextBox.Text; Boolean checkFlag = true; StringBuilder checkMsg = new StringBuilder(); if ("".Equals(title)) { checkFlag = false; checkMsg.Append("名称未填写\r\n"); } if ("".Equals(url)) { checkFlag = false; checkMsg.Append("地址未填写\r\n"); } if (!checkFlag) { MessageBox.Show(checkMsg.ToString(), "错误"); } else { /** 数据正常,修改ini数据,执行StartForm添加按钮和新增rdp文件操作 */ // 生成title iniUtils.IniWriteValue(Config.MonitorIniPath, section, "title", title); iniUtils.IniWriteValue(Config.MonitorIniPath, section, "url", url); iniUtils.IniWriteValue(Config.MonitorIniPath, section, "warn", warn); /* 生成新INI结束 ************************/ // sections缓存数据新增 MonitorSections.MonitorSection monitorSection = MonitorSections.getMonitorByKey(section); monitorSection.title = title; monitorSection.url = url; monitorSection.warn = warn; MonitorSections.updateMonitor(section, monitorSection); /* StartForm中更新服务按钮 *************/ mainForm.updateButton(section); /* 更新服务按钮完成****** *************/ // 关闭新增窗口 UpdateForm_Cancel_Button_Click(sender, e); } }
/// <summary> /// 添加按钮 /// </summary> public void addButton(String section) { String buttonText = iniUtils.IniReadValue(Config.MonitorIniPath, section, "title"); // 监控地址 String url = iniUtils.IniReadValue(Config.MonitorIniPath, section, "url"); // 状态,是暂停还是启动状态 String stat = iniUtils.IniReadValue(Config.MonitorIniPath, section, "stat"); // 预警 String warn = iniUtils.IniReadValue(Config.MonitorIniPath, section, "warn"); Button button = new Button(); button.ImageAlign = System.Drawing.ContentAlignment.TopCenter; button.Location = new System.Drawing.Point(3, 0); button.Name = section; button.Size = new System.Drawing.Size(90, 70); button.TabIndex = 0; if ("0".Equals(stat)) { // 当前任务是暂停(背景色置灰) setButtonBackColor(button, Color.LightGray); } else if ("1".Equals(stat)) { // 当前任务是启动(背景色置浅蓝) setButtonBackColor(button, Color.AliceBlue); } Image image = Image.FromFile(@"resource\icons\computer.ico"); button.BackgroundImageLayout = ImageLayout.None; button.BackgroundImage = image; button.Text = buttonText; button.TextAlign = System.Drawing.ContentAlignment.BottomCenter; button.Font = new Font("微软雅黑", 8); button.MouseHover += new EventHandler(BtnMouseHover); // 右键按钮添加事件 ContextMenuStrip rightMenu = new ContextMenuStrip(); ToolStripMenuItem monitorItem = new ToolStripMenuItem(); monitorItem.Name = section + "MouseRightMenu_Monitor"; monitorItem.Text = "监听"; monitorItem.Tag = section; monitorItem.Click += new EventHandler(BtnRightMonitorClick); rightMenu.Items.Add(monitorItem); ToolStripMenuItem stopItem = new ToolStripMenuItem(); stopItem.Name = section + "MouseRightMenu_Stop"; stopItem.Text = "停止"; stopItem.Tag = section; stopItem.Click += new EventHandler(BtnRightStopClick); rightMenu.Items.Add(stopItem); ToolStripMenuItem updateItem = new ToolStripMenuItem(); updateItem.Name = section + "MouseRightMenu_Update"; updateItem.Text = "修改"; updateItem.Tag = section; updateItem.Click += new EventHandler(BtnRightUpdateClick); rightMenu.Items.Add(updateItem); button.ContextMenuStrip = rightMenu; flowLayoutPanel.Controls.Add(button); // // 数据写进缓存 MonitorSections.MonitorSection monitorSection = new MonitorSections.MonitorSection(); monitorSection.title = buttonText; monitorSection.url = url; monitorSection.stat = stat; monitorSection.warn = warn; MonitorSections.updateMonitor(section, monitorSection); }