//硬盘监控 public void threadDisk(bool is_first, int exec) { string db_dir = System.Windows.Forms.Application.StartupPath + "\\db.accdb"; bool begin = tool.execute_or_not("disk_size", db_dir, disk, is_first, exec); if (begin == true) { monitor mtt = new monitor(); List <string> driverList = mtt.getFixDisk();//获取硬盘列表 string cd = ""; foreach (string driver in driverList) { float per = mtt.getDiskFreePercent(driver); string drive = driver.Substring(0, 1); DriverInfo driverInfo = new DriverInfo(); driverInfo.WarningDrivers = driver; driverInfo.WarningValue = per; driverInfo.WarningDateTime = DateTime.Now; cd += driverInfo.WarningDrivers.Substring(0, 1) + ": " + driverInfo.WarningValue.ToString("0") + "G;\r\n"; int csizewarn = int.Parse(tool.readconfig("jb", "Cwarn")); int dsizewarn = int.Parse(tool.readconfig("jb", "Dwarn")); int esizewarn = int.Parse(tool.readconfig("jb", "Ewarn")); int fsizewarn = int.Parse(tool.readconfig("jb", "Fwarn")); int csizeerror = int.Parse(tool.readconfig("bj", "Cerror")); int dsizeerror = int.Parse(tool.readconfig("bj", "Derror")); int esizeerror = int.Parse(tool.readconfig("bj", "Eerror")); int fsizeerror = int.Parse(tool.readconfig("bj", "Ferror")); ////textBox2.Text = csizewarn; if ((drive == "C" && per < csizeerror) || (drive == "D" && per < dsizeerror) || (drive == "E" && per < esizeerror) || (drive == "F" && per < fsizeerror)) { WarningListErrorOfDisk.Add(driverInfo);//达到报错条件硬盘 } if ((drive == "C" && per < csizewarn) || (drive == "D" && per < dsizewarn) || (drive == "E" && per < esizewarn) || (drive == "F" && per < fsizewarn)) { WarningListWarnOfDisk.Add(driverInfo);//达到警告条件硬盘 } } string str5 = System.Windows.Forms.Application.StartupPath; string a = str5 + "\\db.accdb"; Tool_Class.AccessDbClass1 db = new Tool_Class.AccessDbClass1(); db.AccessDbClass2(a); ////textBox1.Text = c; string sql3 = "update Status_Now set details ='" + cd + "',create_date = '" + DateTime.Now + "' where para_name = 'disk_size'"; bool dd = db.ExecuteSQLNonquery(sql3); string fgg = ""; if (WarningListWarnOfDisk.Count == 0 && WarningListErrorOfDisk.Count == 0) //正常 { fgg = "N"; string sql4 = "update Status_Now set para_value='正常',flag ='N' where para_name = 'disk_size'"; bool cc = db.ExecuteSQLNonquery(sql4); //////textBox3.Text = cc.ToString(); } if (WarningListWarnOfDisk.Count > 0) //大于设置警告值 { fgg = "W"; string sql4 = "update Status_Now set para_value='警告',flag ='W' where para_name = 'disk_size'"; bool cc = db.ExecuteSQLNonquery(sql4); //////textBox3.Text = cc.ToString(); } if (WarningListErrorOfDisk.Count > 0) //大于设置错误值 { fgg = "E"; string sql4 = "update Status_Now set para_value='错误',flag ='E' where para_name = 'disk_size'"; bool cc = db.ExecuteSQLNonquery(sql4); //////textBox3.Text = cc.ToString(); } if (WarningListWarnOfDisk.Count > 0 || WarningListErrorOfDisk.Count > 0) { string sql11 = "insert into Status_Histroy (para_name,details,flag,create_date) values ('disk_size','" + cd + "','" + fgg + "','" + DateTime.Now + "')"; bool ee = db.ExecuteSQLNonquery(sql11); ////textBox3.Text = ee.ToString(); } } }