• 简洁的写日志发短信


      以后写日志,发短信什么的,统一集合到一份!虽然代码超简单。但是我的思维总是不够面向对象,写代码如果感觉到了麻烦,就要考虑方式了。

    提醒我这个猪脑子。。。

      

        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表近一个小时数据为空;" + "
    " + networkerrorbuilder.ToString() + "的网络出现故障");
                        Log.Save(strbuilder.ToString() + "的Web_History表近一个小时数据为空" + networkerrorbuilder.ToString() + "的网络出现故障");
                    }
                    
                }
             
            }
        }
  • 相关阅读:
    pandas 读取excle ,迭代
    prettytable模块(格式化打印内容)
    Python开发丨这些面试题会不会难倒你
    python开发最受欢迎的十款工具
    语言组成
    运算符优先级
    Python 位运算符 逻辑运算符 成员运算符
    **算术运算符
    **Python数据类型转换
    字符串-数字-列表(转换)
  • 原文地址:https://www.cnblogs.com/yunquan/p/8436066.html
Copyright © 2020-2023  润新知