/// <summary>
        /// Get with transaction
        /// </summary>
        public PM_ALT_MESSAGE Get(object entityId, DbTransaction transaction)
        {
            ArgumentValidator.CheckForNullArgument(entityId, "entityId");
            ArgumentValidator.CheckForNullArgument(transaction, "transaction");

            PM_ALT_MESSAGE PM_ALT_MESSAGEEntity = null;

            try
            {
                Database  db        = GetDatabaseInstance();
                DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_MESSAGEDAO.SqlGet);

                db.AddInParameter(dbCommand, "@MsgPK", DbType.Int64, entityId);
                using (IDataReader dataReader = db.ExecuteReader(dbCommand, transaction))
                {
                    if (dataReader.Read())
                    {
                        PM_ALT_MESSAGEEntity = ReadEntity(dataReader);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy);
            }

            return(PM_ALT_MESSAGEEntity);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 图片测试
        /// 数据源为DataTable
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSendImage_Click(object sender, EventArgs e)
        {
            try
            {
                PM_ALT_MESSAGE altMes = new PM_ALT_MESSAGE();
                altMes.MsgPK      = 0;                                                //需要插入表产生新的MsgPK
                altMes.MsgType    = 2;
                altMes.ObjectID   = new Guid("6BCBEA79-2F97-47F0-A20D-6D3D9A36CA1A"); //预警主键,用于查询发送的人
                altMes.Format     = "IMAGE";
                altMes.MsgSubject = "图片测试标题";

                DataTable dtContent = new DataTable();
                dtContent.Columns.Add("姓名");
                dtContent.Columns.Add("年龄");
                dtContent.Columns.Add("岗位");
                dtContent.Rows.Add("张三", "21", "贴片");
                dtContent.Rows.Add("李四", "17", "AOI");
                dtContent.Rows.Add("王五", "19", "回流焊");
                string content = this.BuildTable(dtContent); //把DataTable转成html table

                altMes.MsgContent = content;
                this.ExecuteNotify(altMes);
            }
            catch (Exception ex)
            {
                MessageBox.Show("系统异常:" + ex.Message);
            }
        }
 public void Update(PM_ALT_MESSAGE entity, bool updateAll, DbTransaction transaction)
 {
     if (!updateAll)
     {
         UpdateSome(entity, transaction);
     }
     else
     {
         UpdateAll(entity, transaction);
     }
 }
 public void Update(PM_ALT_MESSAGE entity, bool updateAll)
 {
     if (!updateAll)
     {
         UpdateSome(entity);
     }
     else
     {
         UpdateAll(entity);
     }
 }
        public void UpdateSome(PM_ALT_MESSAGE entity)
        {
            try
            {
                ArgumentValidator.CheckForNullArgument(entity, "PM_ALT_MESSAGE Entity");

                _PM_ALT_MESSAGEDAO.Update(entity, false);
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.BusinessLogicDefaultPolicy);
            }
        }
        //
        #region base interface impl

        public PM_ALT_MESSAGE Insert(PM_ALT_MESSAGE entity)
        {
            PM_ALT_MESSAGE newEntity = null;

            try
            {
                ArgumentValidator.CheckForNullArgument(entity, "PM_ALT_MESSAGE Entity");

                newEntity = _PM_ALT_MESSAGEDAO.Insert(entity);
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.BusinessLogicDefaultPolicy);
            }

            return(newEntity);
        }
        public PM_ALT_MESSAGE GetEntity(Int64 entityPK)
        {
            PM_ALT_MESSAGE entity = null;

            try
            {
                ArgumentValidator.CheckForNullArgument(entityPK, "PM_ALT_MESSAGE Int64");

                entity = _PM_ALT_MESSAGEDAO.Get(entityPK);
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.BusinessLogicDefaultPolicy);
            }

            return(entity);
        }
        private void UpdateAll(PM_ALT_MESSAGE entity, DbTransaction transaction)
        {
            ArgumentValidator.CheckForNullArgument(entity, "entity");
            ArgumentValidator.CheckForNullArgument(transaction, "transaction");

            PersistentPM_ALT_MESSAGE PM_ALT_MESSAGEEntity = entity as PersistentPM_ALT_MESSAGE;

            try
            {
                Database  db        = GetDatabaseInstance();
                DbCommand dbCommand = db.GetSqlStringCommand(PM_ALT_MESSAGEDAO.SqlUpdate);

                db.AddInParameter(dbCommand, "@MsgPK", DbType.Int64, PM_ALT_MESSAGEEntity.MsgPK);
                db.AddInParameter(dbCommand, "@MsgSubject", DbType.String, PM_ALT_MESSAGEEntity.MsgSubject);
                db.AddInParameter(dbCommand, "@MsgContent", DbType.String, PM_ALT_MESSAGEEntity.MsgContent);
                db.AddInParameter(dbCommand, "@MsgType", DbType.Int32, PM_ALT_MESSAGEEntity.MsgType);
                db.AddInParameter(dbCommand, "@Format", DbType.String, PM_ALT_MESSAGEEntity.Format);
                db.AddInParameter(dbCommand, "@ObjectID", DbType.Guid, PM_ALT_MESSAGEEntity.ObjectID);
                db.AddInParameter(dbCommand, "@MsgFrom", DbType.String, PM_ALT_MESSAGEEntity.MsgFrom);
                db.AddInParameter(dbCommand, "@MsgTo", DbType.String, PM_ALT_MESSAGEEntity.MsgTo);
                db.AddInParameter(dbCommand, "@MsgCc", DbType.String, PM_ALT_MESSAGEEntity.MsgCc);
                db.AddInParameter(dbCommand, "@MsgBcc", DbType.String, PM_ALT_MESSAGEEntity.MsgBcc);
                db.AddInParameter(dbCommand, "@Attachments", DbType.String, PM_ALT_MESSAGEEntity.Attachments);
                db.AddInParameter(dbCommand, "@URL", DbType.String, PM_ALT_MESSAGEEntity.URL);
                db.AddInParameter(dbCommand, "@Category", DbType.String, PM_ALT_MESSAGEEntity.Category);
                db.AddInParameter(dbCommand, "@Source", DbType.String, PM_ALT_MESSAGEEntity.Source);
                db.AddInParameter(dbCommand, "@ErrorMsg", DbType.String, PM_ALT_MESSAGEEntity.ErrorMsg);
                db.AddInParameter(dbCommand, "@SentCnt", DbType.Int32, PM_ALT_MESSAGEEntity.SentCnt);
                db.AddInParameter(dbCommand, "@ModifiedOn", DbType.DateTime, PM_ALT_MESSAGEEntity.ModifiedOn);
                db.AddInParameter(dbCommand, "@RowDeleted", DbType.Boolean, PM_ALT_MESSAGEEntity.RowDeleted);
                int result = db.ExecuteNonQuery(dbCommand, transaction);

                if (result == 0)
                {
                    throw new EntityNotFoundException();
                }
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 文字测试
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnTest_Click(object sender, EventArgs e)
        {
            try
            {
                PM_ALT_MESSAGE altMes = new PM_ALT_MESSAGE();
                altMes.MsgPK      = 0;                                                //需要插入表产生新的MsgPK
                altMes.MsgType    = 2;
                altMes.ObjectID   = new Guid("6BCBEA79-2F97-47F0-A20D-6D3D9A36CA1A"); //用于查询发送的人
                altMes.Format     = "TEXT";
                altMes.MsgSubject = "文本测试标题";
                altMes.MsgContent = "文本测试内容";

                bool boolReturn = this.ExecuteNotify(altMes);
                if (!boolReturn)
                {
                    MessageBox.Show("发送失败");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("系统异常" + ex.Message);
            }
        }
        private static PM_ALT_MESSAGE ReadEntity(IDataReader dataReader)
        {
            PM_ALT_MESSAGE PM_ALT_MESSAGEEntity = new PM_ALT_MESSAGE();
            object         value;


            value = dataReader["MsgPK"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.MsgPK = (Int64?)value;
            }

            value = dataReader["MsgSubject"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.MsgSubject = (String)value;
            }

            value = dataReader["MsgContent"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.MsgContent = (String)value;
            }

            value = dataReader["MsgType"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.MsgType = (Int32?)value;
            }

            value = dataReader["Format"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.Format = (String)value;
            }

            value = dataReader["ObjectID"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.ObjectID = (Guid?)value;
            }

            value = dataReader["MsgFrom"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.MsgFrom = (String)value;
            }

            value = dataReader["MsgTo"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.MsgTo = (String)value;
            }

            value = dataReader["MsgCc"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.MsgCc = (String)value;
            }

            value = dataReader["MsgBcc"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.MsgBcc = (String)value;
            }

            value = dataReader["Attachments"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.Attachments = (String)value;
            }

            value = dataReader["URL"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.URL = (String)value;
            }

            value = dataReader["Category"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.Category = (String)value;
            }

            value = dataReader["Source"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.Source = (String)value;
            }

            value = dataReader["ErrorMsg"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.ErrorMsg = (String)value;
            }

            value = dataReader["SentCnt"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.SentCnt = (Int32?)value;
            }

            value = dataReader["ModifiedOn"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.ModifiedOn = (DateTime?)value;
            }

            value = dataReader["RowDeleted"];
            if (value != DBNull.Value)
            {
                PM_ALT_MESSAGEEntity.RowDeleted = (Boolean?)value;
            }

            return(PM_ALT_MESSAGEEntity);
        }
        private void UpdateSome(PM_ALT_MESSAGE entity, DbTransaction transaction)
        {
            ArgumentValidator.CheckForNullArgument(entity, "entity");
            ArgumentValidator.CheckForNullArgument(transaction, "transaction");

            PersistentPM_ALT_MESSAGE PM_ALT_MESSAGEEntity = entity as PersistentPM_ALT_MESSAGE;

            StringBuilder sqlUpdateSome = new StringBuilder();

            sqlUpdateSome.Append("UPDATE dbo.PM_ALT_MESSAGE SET ");

            PropertyInfo[] propertyInfos        = PM_ALT_MESSAGEEntity.GetType().GetProperties();
            Hashtable      propertyValues       = new System.Collections.Hashtable();
            int            columnCountForUpdate = 0;

            foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                if (EntityMapping.ContainsProperty(propertyInfo.Name))
                {
                    object     propertyValue = propertyInfo.GetValue(PM_ALT_MESSAGEEntity, null);
                    ORProperty property      = EntityMapping[propertyInfo.Name];
                    if (!property.IsPrimaryKey)
                    {
                        if (!PM_ALT_MESSAGEEntity.IsDefaultValue(propertyInfo.Name))
                        {
                            propertyValues[propertyInfo.Name] = propertyValue;

                            sqlUpdateSome.Append(" " + property.ColumnName + " = @" + property.ColumnName + ",");
                            columnCountForUpdate++;
                        }
                    }
                    else
                    {
                        propertyValues[propertyInfo.Name] = propertyValue;
                    }
                }
            }
            if (columnCountForUpdate == 0)
            {
                return;
            }

            sqlUpdateSome.Remove(sqlUpdateSome.Length - 1, 1);
            sqlUpdateSome.Append(" WHERE 1 = 1 ");
            sqlUpdateSome.Append(" AND MsgPK = @MsgPK ");

            try
            {
                Database  db        = GetDatabaseInstance();
                DbCommand dbCommand = db.GetSqlStringCommand(sqlUpdateSome.ToString());

                foreach (DictionaryEntry de in propertyValues)
                {
                    ORProperty property = EntityMapping[de.Key.ToString()];
                    db.AddInParameter(dbCommand, "@" + property.ColumnName, property.DatabaseType, de.Value);
                }

                int result = db.ExecuteNonQuery(dbCommand, transaction);

                if (result == 0)
                {
                    throw new EntityNotFoundException();
                }
            }
            catch (Exception ex)
            {
                ExceptionPolicy.HandleException(ex, ExceptionPolicy.DataAccessDefaultPolicy);
            }
        }
Ejemplo n.º 12
0
        protected override bool Execute(object readyData)
        {
            try
            {
                if (readyData == null)
                {
                    return(false);
                }
                //
                DataTable dtAll = readyData as DataTable;

                IList <PM_ALT_LOG>     logs     = new List <PM_ALT_LOG>();
                IList <PM_ALT_MESSAGE> messages = new List <PM_ALT_MESSAGE>();
                if (_alert.Format == "TABLE" || _alert.Format == "IMAGE")
                {
                    //fill Log Subject & Content
                    string logSubject = _alert.AlertContent;
                    if (!string.IsNullOrEmpty(logSubject))
                    {
                        logSubject = logSubject.Replace("@日期$", DateTime.Now.ToString("yyyy-MM-dd"));
                    }

                    string logContent = _alert.AlertDesc;
                    if (!string.IsNullOrEmpty(logContent))
                    {
                        logContent = _PM_ALT_BASEBO.BuildTable(_alert.AlertDesc, dtAll);
                    }

                    PM_ALT_MESSAGE msg = new PM_ALT_MESSAGE();
                    msg.MsgSubject = logSubject;
                    msg.MsgContent = logContent;
                    msg.MsgFrom    = "MESAdmin";
                    msg.MsgTo      = _MessageToMembers;
                    msg.Category   = _alert.AlertName;
                    msg.MsgType    = _alert.AlertType;
                    msg.Format     = _alert.Format;
                    msg.ObjectID   = _alert.AlertID;
                    msg.SentCnt    = 0;
                    msg.RowDeleted = false;

                    messages.Add(msg);

                    PM_ALT_LOG log = new PM_ALT_LOG();
                    log.AlertID     = _alert.AlertID;
                    log.LogTitle    = logSubject; //_alert.AlertAlias;
                    log.LogContent  = logContent;
                    log.NotifiedCnt = 1;
                    log.IsClosed    = false;
                    log.RowDeleted  = false;

                    logs.Add(log);
                }
                else
                {
                    for (int z = 0; z < dtAll.Rows.Count; z++)
                    {
                        //fill Log Subject & Content
                        string logSubject = _alert.AlertContent;

                        if (!string.IsNullOrEmpty(logSubject))
                        {
                            logSubject = logSubject.Replace("@日期$", DateTime.Now.ToString("yyyy-MM-dd"));
                        }


                        if (!string.IsNullOrEmpty(logSubject))
                        {
                            for (int i = 0; i < dtAll.Columns.Count; i++)
                            {
                                logSubject = logSubject.Replace("@" + dtAll.Columns[i].ColumnName + "$", dtAll.Rows[z][i].ToString());
                            }
                        }

                        string logURL = _alert.URL;
                        if (!string.IsNullOrEmpty(logURL))
                        {
                            for (int i = 0; i < dtAll.Columns.Count; i++)
                            {
                                logURL = logURL.Replace("@" + dtAll.Columns[i].ColumnName + "$", dtAll.Rows[z][i].ToString());
                            }
                        }

                        string logContent = _alert.AlertDesc;
                        if (!string.IsNullOrEmpty(logContent))
                        {
                            logContent = _PM_ALT_BASEBO.BuildContent(_alert.AlertDesc, dtAll, z);
                        }

                        PM_ALT_MESSAGE msg = new PM_ALT_MESSAGE();
                        msg.MsgSubject = logSubject; //_alert.AlertAlias;
                        msg.MsgContent = logContent;
                        msg.MsgFrom    = "MESAdmin";
                        msg.MsgTo      = _MessageToMembers;
                        msg.Category   = _alert.AlertName;
                        msg.MsgType    = _alert.AlertType;
                        msg.Format     = _alert.Format;
                        msg.ObjectID   = _alert.AlertID;
                        msg.SentCnt    = 0;
                        msg.RowDeleted = false;
                        msg.URL        = logURL;

                        messages.Add(msg);
                        //
                        //create log
                        PM_ALT_LOG log = new PM_ALT_LOG();
                        log.AlertID     = _alert.AlertID;
                        log.LogTitle    = logSubject; //_alert.AlertAlias;
                        log.LogContent  = logContent;
                        log.NotifiedCnt = 1;
                        log.IsClosed    = false;
                        log.RowDeleted  = false;

                        logs.Add(log);
                    }
                }
                //
                string returnMessage = string.Empty;
                if (!string.IsNullOrEmpty(returnMessage))
                {
                    log.Error("Exception: " + returnMessage + this.Name + ".SaveLogs()");
                    return(false);
                }

                //
                _PM_ALT_MESSAGEBO.SaveBatch(messages, out returnMessage);
                if (!string.IsNullOrEmpty(returnMessage))
                {
                    log.Error("Exception: " + returnMessage + this.Name + ".SaveMessages()");
                    return(false);
                }
                //
                if (!string.IsNullOrEmpty(_alert.PostProcedure))
                {
                    try
                    {
                        _PM_ALT_BASEBO.CallProcedure(_alert.PostProcedure);
                    }
                    catch (Exception ex)
                    {
                        log.Error(this.Name + ".CallPostProcedure()", ex);
                        return(false);
                    }
                }
                //
                if (_alert != null)
                {
                    PM_ALT_BASE alert = new PM_ALT_BASE();
                    alert.AlertID         = _alert.AlertID;
                    alert.LastAlertedTime = Siemens.Simatic.Util.Utilities.DAO.UtilDAO.GetDatabaseUtcDatetime().Value.AddHours(8);
                    _PM_ALT_BASEBO.UpdateSome(alert);
                }
            }
            catch (Exception ex)
            {
                log.Error(this.Name + ".Execute()", ex);
                return(false);
            }
            //
            return(true);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 发送预警 -- 作废
        /// </summary>
        /// <param name="readyData"></param>
        /// <returns></returns>
        public bool ExecuteNotify(PM_ALT_MESSAGE msg)
        {
            //try
            //{
            //    string returnMessage = string.Empty;
            //    if (string.IsNullOrEmpty(corpid) || string.IsNullOrEmpty(corpSecret))
            //    {
            //        string strInitServer = this.InitServer();
            //        if (strInitServer != "OK")
            //        {
            //            msg.ErrorMsg = strInitServer;
            //            goto HanderProcess;
            //        }
            //    }

            //    bool isSent = false;

            //    if (string.IsNullOrEmpty(msg.MsgContent))
            //    {
            //        msg.ErrorMsg = "消息内容为空";
            //        goto HanderProcess;
            //    }

            //    if (msg.MsgType == 1) //邮件发送
            //    {
            //        isSent = false;
            //        string to = msg.MsgTo;
            //        string cc = msg.MsgCc;
            //        string bcc = msg.MsgBcc;
            //        string subject = msg.MsgSubject;
            //        string body = msg.MsgContent;
            //        body = System.Web.HttpUtility.HtmlDecode(body);

            //        try
            //        {
            //            isSent = MailHelper.SendNetMail(to, cc, bcc, subject, body, msg.Attachments, this.SenderAccount, this.SenderUser, this.SenderPassword, this.SmtpServer, this.SmtpPort, false);
            //            msg.ErrorMsg = string.Empty;
            //        }
            //        catch (Exception ex)
            //        {
            //            msg.ErrorMsg = ex.Message;
            //            goto HanderProcess;
            //        }
            //    }
            //    else if (msg.MsgType == 2) //微信发送
            //    {
            //        api_wechat_bo.Gettoken(this, corpid, corpSecret);

            //        IList<Siemens.Simatic.Wechat.Common.CV_PM_WECHAT_NOTI> notiList = _cv_WECHAT_NOTIBO.GetEntities(new Siemens.Simatic.Wechat.Common.CV_PM_WECHAT_NOTI { AlertID = msg.ObjectID });
            //        if (notiList != null && notiList.Count > 0)
            //        {
            //            foreach (Siemens.Simatic.Wechat.Common.CV_PM_WECHAT_NOTI noti in notiList)
            //            {
            //                if (msg.Format == WechatFormat.IMAGE)
            //                {
            //                    Siemens.Simatic.Wechat.Common.ReturnValue rv = api_wechat_bo.SendImage(noti.AgentID.Value, msg.MsgSubject, msg.MsgContent, noti.UserIDs, false);
            //                    msg.ErrorMsg = "SendImage: Success=[" + rv.Success + "]" + ",Message=[" + rv.Message + "]";
            //                }
            //                else if (msg.Format == WechatFormat.TEXT) //发送文本
            //                {
            //                    Siemens.Simatic.Wechat.Common.ReturnValue rv = api_wechat_bo.SendText(noti.AgentID.Value, msg.MsgContent, noti.UserIDs, false);
            //                    msg.ErrorMsg = "SendText: Success=[" + rv.Success + "]" + ",Message=[" + rv.Message + "]";
            //                }
            //                else if (msg.Format == WechatFormat.QRCODE)
            //                {
            //                    Content cnt = this.GetSplitEmailContent(msg.MsgContent);
            //                    Siemens.Simatic.Wechat.Common.ReturnValue rv = new Siemens.Simatic.Wechat.Common.ReturnValue();
            //                    if (!string.IsNullOrEmpty(cnt.BodyContent))
            //                    {
            //                        rv = api_wechat_bo.SendText(noti.AgentID.Value, cnt.BodyContent, noti.UserIDs, false);
            //                        msg.ErrorMsg = "SendText: Success=[" + rv.Success + "]" + ",Message=[" + rv.Message + "]";
            //                    }

            //                    if (rv.Success)
            //                    {
            //                        if (!string.IsNullOrEmpty(cnt.QrContent))
            //                        {
            //                            rv = api_wechat_bo.SendQRImage(noti.AgentID.Value, msg.MsgSubject, cnt.QrContent, noti.UserIDs, false);
            //                            msg.ErrorMsg = "SendQRCode: Success=[" + rv.Success + "]" + ",Message=[" + rv.Message + "]";
            //                        }
            //                    }
            //                }
            //            }
            //        }
            //    }

            //HanderProcess:
            //    msg.SentCnt += 1;
            //    msg.ModifiedOn = DateTime.Now;
            //    _co_BSC_EMAILBO.UpdateSome(msg); //更新message

            //    if (!string.IsNullOrEmpty(msg.ErrorMsg) && !msg.ErrorMsg.Contains("Success=[True],Message=[ok]"))
            //    {
            //        //log.Error("ExecuteNotify error: " + returnMessage);
            //        return false;
            //    }
            //    else //移到历史表
            //    {
            //        string sql = @"INSERT INTO PM_ALT_MESSAGE_HISTORY SELECT * FROM PM_ALT_MESSAGE WHERE MsgPK={0};
            //                           DELETE FROM PM_ALT_MESSAGE WHERE MsgPK={0};";
            //        sql = string.Format(sql, msg.MsgPK);
            //        this.ExecuteNonQueryBySql(sql);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    return false;
            //}
            //return true;
            return(true);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 发送报警
        /// </summary>
        /// <param name="readyData"></param>
        /// <returns></returns>
        public bool ExecuteNotify(PM_ALT_MESSAGE msg)
        {
            try
            {
                string returnMessage = string.Empty;
                if (string.IsNullOrEmpty(corpid))
                {
                    msg.ErrorMsg = "企业ID为空";
                    return(false);
                }
                bool isSent = false;

                if (msg.MsgType == 1) //邮件发送
                {
                    isSent = false;
                    string to = msg.MsgTo;
                    string cc = msg.MsgCc;
                    //string bcc = msg.MsgBcc;
                    string subject = msg.MsgSubject;
                    string body    = msg.MsgContent;
                    //body = System.Web.HttpUtility.HtmlDecode(body);
                    //try
                    //{
                    //    isSent = MailHelper.SendNetMail(to, cc, bcc, subject, body, msg.Attachments, this.SenderName, this.SenderUser, this.SenderPassword, this.SmtpServer, this.SmtpPort, false);
                    //    msg.ErrorMsg = string.Empty;
                    //}
                    //catch (Exception ex)
                    //{
                    //    msg.ErrorMsg = ex.Message;
                    //    //log.Error("ExecuteNotify error: ", ex);
                    //    return false;
                    //}
                }
                else if (msg.MsgType == 2) //微信发送
                {
                    //获取微信token
                    api_wechat_bo.Gettoken(corpid, corpSecret);

                    //查询发给哪些人
                    string strSelectUsers = @"WITH sql1 AS
                    (
                      SELECT DISTINCT pwn.AlertID,pwa.AgentGuid,pwa.AgentID,pwa.SecretID,pwu.UserID 
                      FROM PM_ALT_NOTI pwn WITH(NOLOCK) 
                      INNER JOIN PM_WECHAT_USER pwu WITH(NOLOCK) ON pwn.UserGuid = pwu.UserGuid
                      --INNER JOIN PM_WECHAT_DEPARTMENT pwd WITH(NOLOCK) ON pwn.DepartmentGuid = pwd.DepartmentGuid
                      INNER JOIN PM_WECHAT_AGENT pwa WITH(NOLOCK) ON pwn.AgentGuid = pwa.AgentGuid
                    )
                    SELECT AlertID,AgentGuid,AgentID,SecretID,[UserIDs]=STUFF((SELECT '|' + UserID FROM sql1 t WHERE t.AlertID=sql1.AlertID AND t.AgentGuid = sql1.AgentGuid FOR XML PATH('')), 1, 1, '') 
                    FROM sql1 
                    WHERE AlertID ='{0}'
                    GROUP BY AlertID,AgentGuid,AgentID,SecretID ";
                    strSelectUsers = string.Format(strSelectUsers, msg.ObjectID);
                    DataTable dtNotiUsers = DbHelperSQL.QueryDt(strSelectUsers);
                    if (dtNotiUsers == null || dtNotiUsers.Rows.Count == 0)
                    {
                        msg.ErrorMsg = "缺少预警的人";
                        return(false);
                    }
                    int    agentID = int.Parse(dtNotiUsers.Rows[0]["AgentID"].ToString());
                    string userIDs = dtNotiUsers.Rows[0]["UserIDs"].ToString();

                    if (msg.Format == WechatFormat.IMAGE) //图片
                    {
                        Siemens.Simatic.Wechat.Common.ReturnValue rv = api_wechat_bo.SendImage(agentID, msg.MsgSubject, msg.MsgContent, userIDs, false);
                        msg.ErrorMsg = "SendImage: Success=[" + rv.Success + "]" + ",Message=[" + rv.Message + "]";
                    }
                    else if (msg.Format == WechatFormat.TEXT) //文字
                    {
                        Siemens.Simatic.Wechat.Common.ReturnValue rv = api_wechat_bo.SendText(agentID, msg.MsgContent, userIDs, false);
                        msg.ErrorMsg = "SendText: Success=[" + rv.Success + "]" + ",Message=[" + rv.Message + "]";
                    }
                }

                //发送失败,更新message
                if (!string.IsNullOrEmpty(msg.ErrorMsg) && !msg.ErrorMsg.Contains("Success=[True],Message=[ok]"))
                {
                    string sql = @"UPDATE PM_ALT_MESSAGE SET ErrorMsg='{1}',SentCnt=SentCnt+1 WHERE MsgPK={0}";
                    sql = string.Format(sql, msg.MsgPK, msg.ErrorMsg);
                    DbHelperSQL.ExecuteSql(sql);
                    return(false);
                }
                else //发送成功,移到历史表
                {
                    string sql = @"INSERT INTO PM_ALT_MESSAGE_HISTORY SELECT * FROM PM_ALT_MESSAGE WHERE MsgPK={0};
                                   DELETE FROM PM_ALT_MESSAGE WHERE MsgPK={0};";
                    sql = string.Format(sql, msg.MsgPK);
                    DbHelperSQL.ExecuteSql(sql);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        /// <summary>
        /// 插入消息表
        /// </summary>
        /// <returns></returns>
        public string Trigger(DataTable dtTrigger, PM_ALT_BASE alertEntity)
        {
            try
            {
                if (dtTrigger == null || dtTrigger.Rows.Count == 0)
                {
                    return("没有执行内容");
                }

                IList <PM_ALT_LOG>     logs     = new List <PM_ALT_LOG>();
                IList <PM_ALT_MESSAGE> messages = new List <PM_ALT_MESSAGE>();
                if (alertEntity.Format == "TABLE" || alertEntity.Format == "IMAGE")
                {
                    //fill Log Subject & Content
                    string logSubject = alertEntity.AlertContent;
                    if (!string.IsNullOrEmpty(logSubject))
                    {
                        logSubject = logSubject.Replace("@日期$", DateTime.Now.ToString("yyyy-MM-dd"));
                    }

                    string logContent = alertEntity.AlertDesc;
                    if (!string.IsNullOrEmpty(logContent))
                    {
                        logContent = this.BuildTable(alertEntity.AlertDesc, dtTrigger);
                    }

                    PM_ALT_MESSAGE msg = new PM_ALT_MESSAGE();
                    msg.MsgSubject = logSubject;
                    msg.MsgContent = logContent;
                    msg.MsgFrom    = "MESAdmin";
                    msg.MsgTo      = this.GetEmailToList(alertEntity.AlertID.ToString());
                    msg.Category   = alertEntity.AlertName;
                    msg.MsgType    = alertEntity.AlertType;
                    msg.Format     = alertEntity.Format;
                    msg.ObjectID   = alertEntity.AlertID;
                    msg.SentCnt    = 0;
                    msg.RowDeleted = false;

                    messages.Add(msg);

                    PM_ALT_LOG log = new PM_ALT_LOG();
                    log.AlertID     = alertEntity.AlertID;
                    log.LogTitle    = logSubject; //_alert.AlertAlias;
                    log.LogContent  = logContent;
                    log.NotifiedCnt = 1;
                    log.IsClosed    = false;
                    log.RowDeleted  = false;

                    logs.Add(log);
                }
                else
                {
                    for (int z = 0; z < dtTrigger.Rows.Count; z++)
                    {
                        //fill Log Subject & Content
                        string logSubject = alertEntity.AlertContent;

                        if (!string.IsNullOrEmpty(logSubject))
                        {
                            logSubject = logSubject.Replace("@日期$", DateTime.Now.ToString("yyyy-MM-dd"));
                        }


                        if (!string.IsNullOrEmpty(logSubject))
                        {
                            for (int i = 0; i < dtTrigger.Columns.Count; i++)
                            {
                                logSubject = logSubject.Replace("@" + dtTrigger.Columns[i].ColumnName + "$", dtTrigger.Rows[z][i].ToString());
                            }
                        }

                        string logContent = alertEntity.AlertDesc;
                        if (!string.IsNullOrEmpty(logContent))
                        {
                            logContent = this.BuildContent(alertEntity.AlertDesc, dtTrigger, z);
                        }

                        string logURL = alertEntity.URL;
                        if (!string.IsNullOrEmpty(logURL))
                        {
                            for (int i = 0; i < dtTrigger.Columns.Count; i++)
                            {
                                logURL = logURL.Replace("@" + dtTrigger.Columns[i].ColumnName + "$", dtTrigger.Rows[z][i].ToString());
                            }
                        }

                        PM_ALT_MESSAGE msg = new PM_ALT_MESSAGE();
                        msg.MsgSubject = logSubject; //_alert.AlertAlias;
                        msg.MsgContent = logContent;
                        msg.MsgFrom    = "MESAdmin";
                        msg.MsgTo      = this.GetEmailToList(alertEntity.AlertID.ToString());
                        msg.Category   = alertEntity.AlertName;
                        msg.MsgType    = alertEntity.AlertType;
                        msg.Format     = alertEntity.Format;
                        msg.ObjectID   = alertEntity.AlertID;
                        msg.URL        = logURL;
                        msg.SentCnt    = 0;
                        msg.RowDeleted = false;

                        messages.Add(msg);
                        //
                        //create log
                        PM_ALT_LOG log = new PM_ALT_LOG();
                        log.AlertID     = alertEntity.AlertID;
                        log.LogTitle    = logSubject; //_alert.AlertAlias;
                        log.LogContent  = logContent;
                        log.NotifiedCnt = 1;
                        log.IsClosed    = false;
                        log.RowDeleted  = false;

                        logs.Add(log);
                    }
                }
                //
                string returnMessage = string.Empty;
                if (!string.IsNullOrEmpty(returnMessage))
                {
                    return("Exception: " + returnMessage + ".SaveLogs()");
                }

                //
                pm_ALT_MESSAGEBO.SaveBatch(messages, out returnMessage);
                if (!string.IsNullOrEmpty(returnMessage))
                {
                    return("Exception: " + returnMessage + ".SaveEmails()");
                }

                //
                if (alertEntity != null)
                {
                    PM_ALT_BASE alert = new PM_ALT_BASE();
                    alert.AlertID         = alertEntity.AlertID;
                    alert.LastAlertedTime = Siemens.Simatic.Util.Utilities.DAO.UtilDAO.GetDatabaseUtcDatetime().Value.AddHours(8);
                    this.UpdateSome(alert);
                }
                return("生成预警成功");
            }
            catch (Exception ex) {
                return("生成预警失败");
            }
        }
        /// <summary>
        /// 插入消息表-并发送
        /// </summary>
        /// <param name="dtTrigger"></param>
        /// <param name="alertEntity"></param>
        /// <returns></returns>
        public string TriggerAndSend(DataTable dtTrigger, PM_ALT_BASE alertEntity)
        {
            if (dtTrigger == null || dtTrigger.Rows.Count == 0)
            {
                return("没有执行内容");
            }
            //IList<PM_ALT_SCALE> scales = new List<PM_ALT_SCALE>();
            //IList<PM_ALT_LOG> logs = new List<PM_ALT_LOG>();
            IList <PM_ALT_MESSAGE> messageList = new List <PM_ALT_MESSAGE>();

            if (alertEntity.Format == "TABLE" || alertEntity.Format == "IMAGE")
            {
                string logSubject = alertEntity.AlertName; //预警标题
                logSubject = logSubject.Replace("@日期", SSGlobalConfig.Now.ToString("yyyy-MM-dd"));

                string logContent = "";
                logContent = this.BuildTable2(logSubject + "\r\n", dtTrigger);

                PM_ALT_MESSAGE email = new PM_ALT_MESSAGE();
                email.MsgSubject = logSubject; //_alert.AlertAlias;
                email.MsgContent = logContent;
                email.MsgFrom    = "MESAdmin";
                email.MsgTo      = this.GetEmailToList(alertEntity.AlertID.Value.ToString());
                email.Category   = alertEntity.Category;
                email.MsgType    = alertEntity.AlertType;
                email.Format     = alertEntity.Format;
                email.ObjectID   = alertEntity.AlertID;
                email.SentCnt    = 0;
                email.RowDeleted = false;
                messageList.Add(email);

                //PM_ALT_LOG log = new PM_ALT_LOG();
                //log.AlertID = alertEntity.AlertID;
                //log.LogTitle = logSubject; //_alert.AlertAlias;
                //log.LogContent = logContent;
                //log.NotifiedCnt = 1;
                //log.IsClosed = false;
                //log.RowDeleted = false;
                //logs.Add(log);
            }
            else if (alertEntity.Format == "TEXT")             //文本--作废
            {
                for (int z = 0; z < dtTrigger.Rows.Count; z++) //每行数据发一次
                {
                    string logSubject = alertEntity.AlertName;

                    string logContent = "";                                             //alertEntity.AlertDesc;
                    logContent = this.BuildContent2(logSubject + "\r\n", dtTrigger, z); //logContent.Replace("@" + dtEvents.Columns[i].ColumnName, dtEvents.Rows[z][i].ToString());

                    PM_ALT_MESSAGE email = new PM_ALT_MESSAGE();
                    email.MsgSubject = logSubject; //_alert.AlertAlias;
                    email.MsgContent = logContent;
                    email.MsgFrom    = "MESAdmin";
                    email.MsgTo      = this.GetEmailToList(alertEntity.AlertID.ToString());
                    email.Category   = alertEntity.Category;
                    email.MsgType    = alertEntity.AlertType;
                    email.Format     = alertEntity.Format;
                    email.ObjectID   = alertEntity.AlertID;
                    email.SentCnt    = 0;
                    email.RowDeleted = false;

                    messageList.Add(email);
                } //end for
            }

            string returnMessage = string.Empty;

            //if (scales != null)
            //{
            //    PM_ALT_SCALEBO.SaveBatch(scales, out returnMessage);
            //    if (!string.IsNullOrEmpty(returnMessage))
            //    {
            //        SSMessageBox.ShowError(returnMessage);
            //        return returnMessage;
            //    }
            //}

            //保存预警消息
            //pm_ALT_MESSAGEBO.SaveBatch(messageList, out returnMessage);
            //if (!string.IsNullOrEmpty(returnMessage))
            //{
            //    return returnMessage;
            //}
            foreach (PM_ALT_MESSAGE msg in messageList)
            {
                string insertSql = @"INSERT INTO PM_ALT_MESSAGE(MsgSubject,MsgContent,MsgType,Format,ObjectID,MsgFrom,MsgTo,Category,SentCnt,ModifiedOn,RowDeleted)
                SELECT '{0}','{1}',alt.AlertType,alt.Format,alt.AlertID,'MESAdmin',
                STUFF((SELECT ','+u.Email FROM PM_ALT_NOTI t JOIN PM_WECHAT_USER u ON t.UserGuid=u.UserGuid WHERE t.AlertID=alt.AlertID AND u.Email<>'' for xml path('') ),1,1,'' ) AS MsgTo,alt.Category,0,GETDATE(),0 
                FROM PM_ALT_BASE as alt WHERE alertID='{2}';select @@identity ";
                insertSql = string.Format(insertSql, msg.MsgSubject, msg.MsgContent, msg.ObjectID);
                DataTable dt = alt_BSC_BO.GetDataTableBySql(insertSql);
                if (dt == null || dt.Rows.Count == 0)
                {
                    return("插入数据失败");
                }
                else
                {
                    msg.MsgPK = int.Parse(dt.Rows[0][0].ToString());
                    alt_BSC_BO.ExecuteNotify(msg); //发送消息
                }
            }
            return("生成预警成功");
        }
        /// <summary>
        /// Update
        /// </summary>

        public void Update(PM_ALT_MESSAGE entity)
        {
            Update(entity, true);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 发送预警 - Aux接口
        /// </summary>
        /// <param name="readyData"></param>
        /// <returns></returns>
        public bool ExecuteNotifyAux(PM_ALT_MESSAGE msg)
        {
            //try
            //{
            //    string returnMessage = string.Empty;
            //    if (string.IsNullOrEmpty(corpid) || string.IsNullOrEmpty(corpSecret))
            //    {
            //        string strInitServer = this.InitServer();
            //        if (strInitServer != "OK")
            //        {
            //            msg.ErrorMsg = strInitServer;
            //            goto HanderProcess;
            //        }
            //    }

            //    if (string.IsNullOrEmpty(msg.MsgContent))
            //    {
            //        msg.ErrorMsg = "消息内容为空";
            //        goto HanderProcess;
            //    }

            //    bool isSent = false;
            //    if (msg.MsgType == 1) //邮件发送
            //    {
            //        //isSent = false;
            //        //string to = msg.MsgTo;
            //        //string cc = msg.MsgCc;
            //        //string bcc = msg.MsgBcc;
            //        //string subject = msg.MsgSubject;
            //        //string body = msg.MsgContent;
            //        //body = System.Web.HttpUtility.HtmlDecode(body);

            //        //try
            //        //{
            //        //    isSent = MailHelper.SendNetMail(to, cc, bcc, subject, body, msg.Attachments, this.SenderAccount, this.SenderUser, this.SenderPassword, this.SmtpServer, this.SmtpPort, false);
            //        //    msg.ErrorMsg = string.Empty;
            //        //}
            //        //catch (Exception ex)
            //        //{
            //        //    msg.ErrorMsg = ex.Message;
            //        //}
            //        //goto HanderProcess;
            //    }
            //    else if (msg.MsgType == 2) //微信发送
            //    {
            //        //api_wechat_bo.Gettoken(this, corpid, corpSecret);
            //        Siemens.Simatic.Wechat.Common.CV_PM_WECHAT_NOTI qp = new Siemens.Simatic.Wechat.Common.CV_PM_WECHAT_NOTI { AlertID = msg.ObjectID };
            //        IList<Siemens.Simatic.Wechat.Common.CV_PM_WECHAT_NOTI> notiList = _cv_WECHAT_NOTIBO.GetEntities(qp);
            //        if (notiList == null || notiList.Count == 0)
            //        {
            //            msg.ErrorMsg = "找不到预警的配置";
            //            goto HanderProcess;
            //        }
            //        Siemens.Simatic.Wechat.Common.CV_PM_WECHAT_NOTI noti = notiList[0];

            //        //if (msg.Format == WechatFormat.IMAGE)
            //        //{
            //        //    Siemens.Simatic.Wechat.Common.ReturnValue rv = api_wechat_bo.SendImage(noti.AgentID.Value, msg.MsgSubject, msg.MsgContent, noti.UserIDs, false);
            //        //    msg.ErrorMsg = "SendImage: Success=[" + rv.Success + "]" + ",Message=[" + rv.Message + "]";
            //        //}
            //        //else if (msg.Format == WechatFormat.TEXT)
            //        //{
            //        //    Siemens.Simatic.Wechat.Common.ReturnValue rv = api_wechat_bo.SendText(noti.AgentID.Value, msg.MsgContent, noti.UserIDs, false);
            //        //    msg.ErrorMsg = "SendText: Success=[" + rv.Success + "]" + ",Message=[" + rv.Message + "]";
            //        //}

            //        List<string> userlist = new List<string>();
            //        //userlist.Add("030301069"); //测试用户
            //        //userlist.Add("030301069"); //测试用户
            //        foreach (string user in noti.UserIDs.Split('|'))
            //        {
            //            userlist.Add(user);
            //        }
            //        apiEntity.agentId = "9";
            //        apiEntity.userIds = userlist; //noti.UserIDs;
            //        apiEntity.content = msg.MsgContent;
            //        string strjson = JsonConvert.SerializeObject(apiEntity);
            //        string strReturn = http_Request.HttpPost(this.AuxApiUrl, strjson);//aux的接口
            //        if (strReturn == "1") //成功
            //        {
            //            msg.ErrorMsg = string.Empty;
            //        }
            //        else
            //        {
            //            msg.ErrorMsg = strReturn;
            //        }
            //    }

            //HanderProcess:
            //    msg.SentCnt += 1;
            //    msg.ModifiedOn = DateTime.Now;
            //    _co_BSC_EMAILBO.UpdateSome(msg); //更新message

            //    if (!string.IsNullOrEmpty(msg.ErrorMsg)) //&& !msg.ErrorMsg.Contains("Success=[True],Message=[ok]")
            //    {
            //        return false;
            //    }
            //    else //成功,移到历史表
            //    {
            //        string sql = @"INSERT INTO PM_ALT_MESSAGE_HISTORY SELECT * FROM PM_ALT_MESSAGE WHERE MsgPK={0};
            //                       DELETE FROM PM_ALT_MESSAGE WHERE MsgPK={0};";
            //        sql = string.Format(sql, msg.MsgPK);
            //        this.ExecuteNonQueryBySql(sql);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    return false;
            //}
            return(true);
        }
        /// <summary>
        /// Update with transaction
        /// </summary>

        public void Update(PM_ALT_MESSAGE entity, DbTransaction transaction)
        {
            Update(entity, true, transaction);
        }
        public string createIPQC(RepairOrderRequest param)
        {
            DateTime now = SSGlobalConfig.Now;
            IList <CV_QM_REPAIR_ORDER>  orderList = param.orderList;
            Dictionary <string, string> dict      = new Dictionary <string, string>();

            dict.Add("PN", "IPQC");
            dict.Add("Y", now.ToString("yyyyMMdd"));
            string message = "";

            //创建IPQC表单
            using (TransactionScope ts = new TransactionScope())
            {
                string         ipqcSequence = createCode("IPQCRule", dict);
                QM_REPAIR_IPQC ipqc         = new QM_REPAIR_IPQC()
                {
                    TGuid          = Guid.NewGuid(),
                    Sequence       = ipqcSequence,
                    OrderID        = orderList[0].OrderID,
                    ReportLine     = orderList[0].ReportLine,
                    ReportWorkshop = orderList[0].ReportWorkshop,
                    DefID          = orderList[0].DefID,
                    DefName        = orderList[0].DefDescript,
                    Status         = "新建",
                    CreatedBy      = param.user,
                    CreatedOn      = now
                };
                ipqcbo.Insert(ipqc);
                foreach (CV_QM_REPAIR_ORDER tmp in orderList)
                {
                    QM_REPAIR_IPQC_DETAIL detail = new QM_REPAIR_IPQC_DETAIL()
                    {
                        TGuid           = ipqc.TGuid,
                        SN              = tmp.AbnormalitySN,
                        ReportID        = tmp.ReportID,
                        Result          = tmp.Result,
                        ReportTerminal  = tmp.ReportTerminal,
                        ProductDecision = tmp.ProductDecision,
                        QualityDecision = tmp.QualityDecision
                    };
                    ipqc_detailbo.Insert(detail);
                    //修改SN状态为IPQC(7)
                    string cmd_ipqcSql1 = string.Format(CultureInfo.InvariantCulture, ipqcSql1, 7, tmp.AbnormalitySN);
                    alt_bscbo.ExecuteNonQueryBySql(cmd_ipqcSql1);
                }

                //创建预警信息
                string cmd_altsql = string.Format(CultureInfo.InvariantCulture, ipqcAltSql, ipqc.DefID + ipqc.DefName, ipqc.OrderID, orderList[0].LineName, ipqcSequence);
                log.Info("createIPQC Sql : " + cmd_altsql);
                DataTable dt = alt_bscbo.GetDataTableBySql(cmd_altsql);
                if (dt.Rows.Count > 0)
                {
                    //开始推送
                    PM_ALT_MESSAGE msg = alt_messagebo.GetEntity(SafeConvert.ToInt64(dt.Rows[0]["MsgPK"].ToString()));
                    if (alt_bscbo.ExecuteNotify(msg))
                    {
                        message = ipqcSequence;
                        ts.Complete();
                    }
                    else
                    {
                        message = "NG,推送失败,请重新提交..";
                    }
                }
            }
            return(message);
        }
        public string addFirstCheck(AddFirstCheckRequest param)
        {
            string message = "";
            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("PN", "SJ" + param.snOrderList[0].OrderID);
            DateTime now = SSGlobalConfig.Now;

            CV_QM_FIRSTCHECK_SN snOrder = param.snOrderList[0];
            //先获得首检检验项
            string SubBopID = null;

            if (snOrder.Step == "装配" || snOrder.Step == "检定" || snOrder.Step == "包装")
            {   //查询step是否为包装或者装配,若是,则查询需加上subbopid
                SubBopID = snOrder.Step;
            }
            IList <CV_QM_PROCESSITEM> processItemList = _ICV_QM_PROCESSITEMBO.GetEntitiesByOrderID(snOrder.OrderID, "1", SubBopID);//首检InspectSource = 1

            if (processItemList.Count() == 0)
            {
                message = "NG,无首检检验项信息";
            }
            else
            {
                QM_PROCESS_TOP top = new QM_PROCESS_TOP()
                {
                    Source           = 1,
                    SequenceStatus   = "待检",
                    SapOrderID       = snOrder.SalesOrderID,    //SAP订单
                    WorkOrderID      = snOrder.OrderID,         //MES工单
                    MinSampleSize    = param.minSampleSize,     //最小抽样数量
                    SampleQua        = param.snOrderList.Count, //抽样数量
                    MaterielID       = snOrder.DefID,           //物料编码
                    MaterielVer      = snOrder.DefVer,          //物料版本
                    MaterielDescript = snOrder.DefDescript,     //物料描述
                    PlantID          = snOrder.PlanPlant,       //工厂ID
                    Plant            = snOrder.PlantName,       //工厂名称
                    Step             = snOrder.Step,            //工序
                    Workshop         = snOrder.DepartID,        //车间
                    LineID           = snOrder.LineID,          //产线ID
                    ProdLine         = snOrder.LineName,        //产线名称
                    CreateBy         = param.user,              //创建者
                    CreateTime       = now                      //创建时间
                };

                using (TransactionScope ts = new TransactionScope())
                {
                    top.Sequence = createCode("FirstInspectRule", dict);//首检单号
                    //创建首检单
                    _IQM_PROCESS_TOPBO.Insert(top);
                    //获得刚创建的首检单
                    QM_PROCESS_TOP_QueryParam topParam = new QM_PROCESS_TOP_QueryParam()
                    {
                        Source   = 1,
                        Sequence = top.Sequence
                    };
                    //查询KID
                    top = _IQM_PROCESS_TOPBO.GetEntitiesByQueryParam(topParam)[0];
                    foreach (CV_QM_FIRSTCHECK_SN tmp in param.snOrderList)
                    {
                        QM_PROCESS_MIDDLE middle = new QM_PROCESS_MIDDLE()
                        {
                            KID      = top.KID,
                            Sequence = top.Sequence,
                            SN       = tmp.LotID,
                            SNStatus = "待检"
                        };
                        _IQM_PROCESS_MIDDLEBO.Insert(middle);
                    }
                    //查询KLID
                    IList <QM_PROCESS_MIDDLE> middleList = _IQM_PROCESS_MIDDLEBO.GetByKid(top.KID.Value);
                    //操作底表
                    foreach (QM_PROCESS_MIDDLE middleTmp in middleList)
                    {
                        foreach (CV_QM_PROCESSITEM item in processItemList)
                        {
                            QM_PROCESS_BOTTOM bottom = new QM_PROCESS_BOTTOM()
                            {
                                KLID         = middleTmp.KLID,
                                Sequence     = middleTmp.Sequence,
                                SN           = middleTmp.SN,
                                MaterielID   = top.MaterielID,
                                ItemIndex    = item.InforDetailID,
                                Item         = item.InspectItemDes,
                                ItemStatus   = "待检",
                                ItemProperty = item.InspectItemProperty.Equals("2") ? "定量" : "定性",
                            };

                            if (!string.IsNullOrEmpty(item.TargetValue))
                            {
                                bottom.Target = SafeConvert.ToDouble(item.TargetValue);
                            }

                            if (!string.IsNullOrEmpty(item.UpperLimit))
                            {
                                bottom.UpperBound = SafeConvert.ToDouble(item.UpperLimit);
                            }

                            if (!string.IsNullOrEmpty(item.LowerLimit))
                            {
                                bottom.LowerBound = SafeConvert.ToDouble(item.LowerLimit);
                            }
                            _IQM_PROCESS_BOTTOMBO.Insert(bottom);
                        }
                    }

                    //创建预警信息
                    string    cmd_altsql = string.Format(CultureInfo.InvariantCulture, firstAltSql, top.ProdLine, top.WorkOrderID, top.Sequence);
                    DataTable dt         = bscbo.GetDataTableBySql(cmd_altsql);
                    if (dt.Rows.Count > 0)
                    {
                        //开始推送
                        PM_ALT_MESSAGE msg = alt_messagebo.GetEntity(SafeConvert.ToInt64(dt.Rows[0]["MsgPK"].ToString()));
                        if (alt_bscbo.ExecuteNotify(msg))
                        {
                            message = top.Sequence;
                            ts.Complete();
                        }
                        else
                        {
                            message = "NG,推送失败,请重新提交..";
                        }
                    }
                }
            }
            return(message);
        }