private void exceloutclass(string savename) { string sql = "select para_title,details,ref_value,flag,'',para_type,para_level,'' from Status_Now"; Tool_Class.IO_tool tool = new Tool_Class.IO_tool(); DataTable dt = tool.DbToDatatable(sql); StringBuilder sb1 = history("syslog_warn"); StringBuilder sb2 = history("instrument_connection"); StringBuilder sb3 = history("disk_size"); StringBuilder sb4 = history("cpu_running"); StringBuilder sb5 = history("memory_running"); StringBuilder sb6 = history("table_count"); StringBuilder sb7 = history("db_size"); StringBuilder sb8 = history("para_check"); StringBuilder sb9 = history("log_error"); StringBuilder sb10 = history("db_backup"); dt.Rows[0][7] = sb1; dt.Rows[1][7] = sb2; dt.Rows[2][7] = sb3; dt.Rows[3][7] = sb4; dt.Rows[4][7] = sb5; dt.Rows[5][7] = sb6; dt.Rows[6][7] = sb7; dt.Rows[7][7] = sb8; dt.Rows[8][7] = sb9; dt.Rows[9][7] = sb10; tool.DataTableToExcel(dt, savename); }
private void exceloutclass(string savename) { string sql = "select para_title,details,ref_value,flag,'',para_type,para_level,'' from Status_Now"; Tool_Class.IO_tool tool = new Tool_Class.IO_tool(); DataTable dt = tool.DbToDatatable(sql); StringBuilder sb1 = history("syslog_warn"); StringBuilder sb2 = history("instrument_connection"); StringBuilder sb3 = history("disk_size"); StringBuilder sb4 = history("cpu_running"); StringBuilder sb5 = history("memory_running"); StringBuilder sb6 = history("table_count"); StringBuilder sb7 = history("db_size"); StringBuilder sb8 = history("para_check"); StringBuilder sb9 = history("log_error"); StringBuilder sb10 = history("db_backup"); StringBuilder sb11 = history("check_option"); dt.Rows[0][7] = sb1; dt.Rows[1][7] = sb2; dt.Rows[2][7] = sb3; dt.Rows[3][7] = sb4.Append(sb5); dt.Rows[4][7] = sb6; dt.Rows[5][7] = sb7; dt.Rows[6][7] = sb8; dt.Rows[7][7] = sb9; dt.Rows[8][7] = sb10; dt.Rows[9][7] = sb11; tool.DataTableToExcel(dt,savename); }
private StringBuilder history(string name) { StringBuilder sb1 = new StringBuilder(); string sql = "select * from Status_Histroy where para_name = '" + name + "' and sign is null"; Tool_Class.IO_tool tool = new Tool_Class.IO_tool(); DataTable dt = tool.DbToDatatable(sql); int dtr; if (dt.Rows.Count < 5) { dtr = dt.Rows.Count; } else { dtr = 5; } for (int i = 0; i < dtr; i++) { sb1.Append(dt.Rows[i][6].ToString() + " " + dt.Rows[i][1].ToString() + " " + dt.Rows[i][7].ToString() + dt.Rows[i][2].ToString() + "\r\n"); } return(sb1); }
private StringBuilder history(string name) { StringBuilder sb1 = new StringBuilder(); string sql = "select * from Status_Histroy where para_name = '" + name + "' and sign is null"; Tool_Class.IO_tool tool = new Tool_Class.IO_tool(); DataTable dt = tool.DbToDatatable(sql); int dtr; if (dt.Rows.Count < 5) { dtr = dt.Rows.Count; } else { dtr = 5; } for (int i = 0; i < dtr; i++) { sb1.Append(dt.Rows[i][6].ToString() + " " + dt.Rows[i][1].ToString() + " " + dt.Rows[i][7].ToString() + dt.Rows[i][2].ToString() + "\r\n"); } return sb1; }
//内存监控 public void threadMem(bool is_first, int exec) { string memvalue = "内存正常;\n\r"; string memsign = "N"; string cpuvalue = "CPU正常;\n\r"; string cpusign = "N"; string db_dir = System.Windows.Forms.Application.StartupPath + "\\db.accdb"; bool begin = tool.execute_or_not("memory_running", db_dir, cpumem, is_first, exec); if (begin == true) { monitor mem = new monitor(); uint memValue = mem.getRamUsePercent(); int perOfRam = int.Parse(memValue.ToString().Split('.').ElementAt(0)); int memerrorvalue = int.Parse(tool.readconfig("bj", "memerrorvalue")); int memerrortime = int.Parse(tool.readconfig("bj", "memerrortime")); int memwarnvalue = int.Parse(tool.readconfig("jb", "memwarnvalue")); int memwarntime = int.Parse(tool.readconfig("jb", "memwarntime")); if (perOfRam >= memwarnvalue) { RamCpuInfo ramCpuInfo = new RamCpuInfo(); ramCpuInfo.WarningDateTime = DateTime.Now; ramCpuInfo.WarningValue = perOfRam; WarningListOfMem.Add(ramCpuInfo); string str5 = System.Windows.Forms.Application.StartupPath; string a = str5 + "\\db.accdb"; Tool_Class.AccessDbClass1 db = new Tool_Class.AccessDbClass1(); db.AccessDbClass2(a); string sql11 = "insert into Status_Histroy (para_name,details,create_date) values ('memory_running','" + perOfRam + "','" + DateTime.Now + "')"; bool ee = db.ExecuteSQLNonquery(sql11); } ////textBox3.Text = ee.ToString(); string sql5 = "select details from Status_Histroy where para_name = 'memory_running' and sign is null"; DataTable memerrorcount = tool.DbToDatatable(sql5); int num = 0; int errornum = 0; for (int i = 0; i < memerrorcount.Rows.Count; i++) { int numm = int.Parse(memerrorcount.Rows[i][0].ToString()); if (numm > memwarnvalue) { num++; //达到警告值的次数 } if (numm > memerrorvalue) { errornum++; //达到错误值的次数 } } if (num < memwarntime) { memvalue = "内存正常;\n\r"; memsign = "N"; } if (num > memwarntime) { memvalue = "内存>" + memwarnvalue + "% 共:" + num + "次;\n\r"; memsign = "W"; } if (errornum > memerrortime) { memvalue = "内存>" + memerrorvalue + "% 共:" + errornum + "次;\n\r"; memsign = "E"; } string sql6 = "select details from Status_Histroy where para_name = 'cpu_running' and sign is null"; DataTable cpuerrorcount = tool.DbToDatatable(sql6); int numcpu = 0; int errornumcpu = 0; int cpuerrorvalue = int.Parse(tool.readconfig("bj", "cpuerrorvalue")); int cpuerrortime = int.Parse(tool.readconfig("bj", "cpuerrortime")); int cpuwarnvalue = int.Parse(tool.readconfig("jb", "cpuwarnvalue")); int cpuwarntime = int.Parse(tool.readconfig("jb", "cpuwarntime")); for (int i = 0; i < cpuerrorcount.Rows.Count; i++) { int numm = int.Parse(cpuerrorcount.Rows[i][0].ToString()); if (numm > cpuwarnvalue) { numcpu++; //达到警告值的次数 } if (numm > cpuerrorvalue) { errornumcpu++; //达到错误值的次数 } } if (numcpu < cpuwarntime) { cpuvalue = "正常;\n\r"; cpusign = "N"; } if (numcpu > cpuwarntime) { cpuvalue = "CPU>" + cpuwarnvalue + "% 共:" + numcpu + "次;\n\r"; cpusign = "W"; } if (errornumcpu > cpuerrortime) { cpuvalue = "CPU>" + cpuerrorvalue + "% 共:" + errornumcpu + "次;\n\r"; cpusign = "E"; } if (cpusign == "N" && memsign == "N") { string sql10 = "update Status_Now set para_value='正常',flag ='N',details = '" + cpuvalue + "',create_date = '" + DateTime.Now + "' where para_name = 'cpu_running'"; tool.AccessDbclass(sql10); } else { if (cpusign == "E" || memsign == "E") { string sql10 = "update Status_Now set para_value='错误',flag ='E',details = '" + cpuvalue + memvalue + "',create_date = '" + DateTime.Now + "' where para_name = 'cpu_running'"; tool.AccessDbclass(sql10); } else { string sql10 = "update Status_Now set para_value='警告',flag ='W',details = '" + cpuvalue + memvalue + "',create_date = '" + DateTime.Now + "' where para_name = 'cpu_running'"; tool.AccessDbclass(sql10); } } } }