以后写日志,发短信什么的,统一集合到一份!虽然代码超简单。但是我的思维总是不够面向对象,写代码如果感觉到了麻烦,就要考虑方式了。
提醒我这个猪脑子。。。
private static void monitoring() { //监控是否有数据 //监控是否有数据 var strbuilder = new StringBuilder(); var networkerrorbuilder = new StringBuilder(); networkerrorbuilder = null; for (int i = 0; i < FactoryID.Length; i++) { string plant=""; try { int ID = int.Parse(FactoryID[i]); string sql = "select COUNT(*) from Realtime5.dbo.Web_HistoryData with(nolock) where FactoryId=" + ID + " and datediff(HOUR, DateTime,GETDATE())<=1"; int count = int.Parse(SqlHelper.SelectCounts(sql)); string sqlplant = "select fname from PMIS5.dbo.Sys_Factorys with(nolock) where fid=" + ID + ""; plant = SqlHelper.SelectCounts(sqlplant); if (count <= 0) { strbuilder.Append(plant+ ","); } } catch (Exception ex) { networkerrorbuilder.Append(plant + ","); } } // if have result,to send if (!string.IsNullOrEmpty(strbuilder.ToString()) || !string.IsNullOrEmpty(networkerrorbuilder.ToString())) { if (networkerrorbuilder == null) { SendSmsHelper.SendSms(strPhone, strbuilder.ToString() + "的Web_History表近一个小时数据为空;"); Log.Save(strbuilder.ToString() + "的Web_History表近一个小时数据为空"); } else { SendSmsHelper.SendSms(strPhone, strbuilder.ToString() + "的Web_History表近一个小时数据为空;" + "\r\n" + networkerrorbuilder.ToString() + "的网络出现故障"); Log.Save(strbuilder.ToString() + "的Web_History表近一个小时数据为空" + networkerrorbuilder.ToString() + "的网络出现故障"); } } } }