Esempio n. 1
0
 /// <summary>
 /// 大批量插入数据(_BatchSize/每批次) 。
 /// </summary>
 /// <param name="dt"></param>
 /// <param name="tableName"></param>
 /// <param name="msg"></param>
 /// <returns></returns>
 public bool innserMsg(DataTable dt, string tableName, ref SmsError msg)
 {
     using (SqlConnection conn = new SqlConnection(_conStr))
     {
         conn.Open();
         using (SqlTransaction transaction = conn.BeginTransaction())
         {
             try
             {
                 //SqlBulkCopy bulkCopy = new SqlBulkCopy(conn, SqlBulkCopyOptions.CheckConstraints, transaction);
                 using (SqlBulkCopy bulkCopy = new SqlBulkCopy(conn, SqlBulkCopyOptions.Default, transaction))
                 {
                     bulkCopy.BatchSize            = _BatchSize;
                     bulkCopy.BulkCopyTimeout      = _commandTimeOut;
                     bulkCopy.DestinationTableName = tableName;
                     foreach (DataColumn col in dt.Columns)
                     {
                         bulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName);
                     }
                     bulkCopy.WriteToServer(dt);
                     transaction.Commit();
                     conn.Close();
                     conn.Dispose();
                     msg.errosMsg = "success";
                     msg.errorNum = "000";
                     return(true);
                 }
             }
             catch (Exception ex)
             {
                 LogHelper.Error(ex);
                 msg.errosMsg = ex.Message;
                 msg.errorNum = "005";
                 transaction.Rollback();
                 conn.Close();
                 conn.Dispose();
                 return(false);
             }
         }
     }
 }
Esempio n. 2
0
        public string SmsSend(string mobiles, string msg, int?creatorId, string creator, DateTime?sendTime, int?sysPlatform = (int)Platform.网站系统, int?stype = (int)SendType.一般短信, int?levelNum = 0)
        {
            SmsError             se         = new SmsError();
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            if (!myHeader.CheckLogin())
            {
                se.errorNum = "010";
                se.errosMsg = "身份认证不通过!";
                var emsg = serializer.Serialize(se);
                return(emsg);
            }

            string filterstr = string.Empty;

            if (KeysFilter(msg, ref filterstr))
            {
                se.errorNum = "007";
                se.errosMsg = "内容包括非法字符!非法字符:" + filterstr;
                var emsg = serializer.Serialize(se);
                return(emsg);
            }
            try
            {
                string  error = string.Empty;
                SmsInfo info  = new SmsInfo()
                {
                    creator     = creator,
                    creatorId   = creatorId,
                    levelNum    = levelNum,
                    mobile      = mobiles,
                    msg         = msg,
                    pipeId      = _pipeId,
                    sendTime    = sendTime,
                    stype       = stype,
                    sysPlatform = sysPlatform
                };
                if (validate(info, ref se))
                {
                    string[]  arrys = info.mobile.Replace(';', ';').Replace(',', ';').Split(';');
                    DataTable dt    = CreateTable();
                    dt = CreateRow(dt, arrys, info);
                    bool result = innserMsg(dt, _tableName, ref se);
                    var  emsg   = serializer.Serialize(se);
                    LogHelper.Info("系统异常error :" + emsg);
                    return(emsg);
                }
                else
                {
                    var emsg = serializer.Serialize(se);
                    LogHelper.Info("参数丢失error :" + emsg);
                    return(emsg);
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                se = new SmsError()
                {
                    errorNum = "006", errosMsg = ex.Message
                };
                var emsg = serializer.Serialize(se);
                return(emsg);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// 参数验证和填充表数据
 /// </summary>
 /// <param name="info"></param>
 /// <param name="se"></param>
 /// <returns></returns>
 public bool validate(SmsInfo info, ref SmsError se)
 {
     //SmsError se = new SmsError();
     if (string.IsNullOrWhiteSpace(info.mobile))
     {
         se.errosMsg = "客户手机号码为空!";
         se.errorNum = "001";
         return(false);
     }
     if (!string.IsNullOrWhiteSpace(info.mobile))
     {
         string[] arrys = info.mobile.Replace(';', ';').Replace(',', ';').Split(';');
         if (arrys.Length > 100)
         {
             se.errosMsg = "手机号最多选中100个!";
             se.errorNum = "009";
             return(false);
         }
     }
     if (string.IsNullOrWhiteSpace(info.msg))
     {
         se.errosMsg = "发送消息内容为空!";
         se.errorNum = "002";
         return(false);
     }
     if (!string.IsNullOrWhiteSpace(info.msg) && info.msg.Length >= 70)
     {
         se.errosMsg = "发送消息内容长度小于70个字符!";
         se.errorNum = "008";
         return(false);
     }
     if (info.creatorId == null)
     {
         info.creatorId = 0;
         //se.errosMsg = "发送消息人ID值为空!";
         //se.errorNum = "003";
         //return false;
     }
     if (string.IsNullOrWhiteSpace(info.creator))
     {
         info.creator = "0";
         //se.errosMsg = "发送消息人名字为空!";
         //se.errorNum = "004";
         //return false;
     }
     if (info.stype == null)
     {
         info.stype = (int)SendType.一般短信;//默认为一般短信
     }
     if (info.sendTime == null)
     {
         info.sendTime = DateTime.Now;
     }
     if (info.levelNum == null)
     {
         info.levelNum = 0;
     }
     if (info.sysPlatform == null)
     {
         info.sysPlatform = (int)Platform.网站系统;
     }
     info.msg = _autograph + info.msg;
     return(true);
 }