//确定按钮 private void button1_Click(object sender, EventArgs e) { if (comboBox_clientSelect.Text == "") { MessageBox.Show("请选择客户端名称!"); } else { if (String.IsNullOrEmpty(MainWindow.TerminalNumber)) //新客户端 { MainWindow.TerminalNumber = comboBox_clientSelect.Text; Program.mw.statusStripStatusLabel_client.Text = MainWindow.TerminalNumber; //插入配置文件 using (StreamWriter sw = new StreamWriter(MainWindow.configPath, true, Encoding.UTF8)) { String str1 = "[TerminalNumber]"; String str2 = MainWindow.TerminalNumber; sw.WriteLine(); sw.WriteLine(str1); sw.WriteLine(str2); sw.Close(); } //插入数据库 connnection.Insert("insert into terminal (terminal) values ('" + MainWindow.TerminalNumber + "')"); } else //变更客户端 { ClientManageFunction cmf = new ClientManageFunction(); cmf.ChangeTerminal(comboBox_clientSelect.Text); } this.Close(); } }
//启动加载函数 private void Init_Load(object sender, EventArgs e) { //实例化主窗口 Program.mw = this; //获取程序的基目录:System.AppDomain.CurrentDomain.BaseDirectory mainPath = System.IO.Directory.GetCurrentDirectory(); configPath = mainPath + "/config.txt"; //配置文件目录 SetConfig.ReadConfig(configPath); //读取配置文件中的内容 //连接数据库 connection = new DBConnection(); if (connection.Open()) { connection.Close(); } else { System.Environment.Exit(0); } this.menuStrip.终端管理ToolStripMenuItem_Click(); //检测客户端名称,若已存在检测是否重复,若已存在则导入,若无则弹出登陆界面 ClientManageFunction cmf = new ClientManageFunction(); cmf.CheckTerminal(); //检索预警项,显示报警信息 CommonFunction.WarningUpdate(); //建立时钟 Timer timer = new Timer(); //实例化一个timer timer.Enabled = true; //使timer可用 timer.Interval = 10800000; //设置时间间隔,每3小时刷新一次(以毫秒为单位) timer.Tick += new EventHandler(CommonFunction.RefreshAllTime); //给timer关联函数 DateTime buildDate = System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location); //////////////////////////////////// //绘制各panel中的DataGridView FillDataGridViews(); DrawDataGridViews(); }