/// <summary>
        /// 上载报文(到QP)
        /// </summary>
        /// <param name="keyValue">激活码</param>
        /// <param name="machineCode">机器代码</param>
        /// <param name="cusCiqNo">关检关联号(可选),如果没有填空字符</param>
        /// <param name="msgXml">消息</param>
        /// <returns></returns>
        public MesReceipt SendMessage(string keyValue, string machineCode, string cusCiqNo, string msgXml)
        {
            var       receipt   = new MesReceipt();
            LogHelper logHelper = LogHelper.GetInstance();

            try
            {
                CusCiqNoInfo cusCiqNoInfo = new CusCiqNoInfo {
                    CusCiqNo = cusCiqNo
                };

                var cusDataMsg = new CusDataMsg {
                    KeyValue = keyValue, MachineCode = machineCode, MessageXml = msgXml, CusCiqNo = cusCiqNoInfo
                };
                IMessageDataHelper dataHelper = DataHelperFactory.GetMessageDataHelper();
                //检查激活码
                if (!Utility.CheckKey(dataHelper.GetKeyInfo(keyValue, machineCode)))
                {
                    receipt.Status  = "003";
                    receipt.Message = GetErrInfo(Context.ErrKeyValueInvalid, Context.ErrKeyValueInvalidId);
                    return(receipt);
                }
                cusDataMsg    = Utility.FormatCusDataMsg(cusDataMsg, dataHelper.GetMaxTcsCurrentId(), ConfigInfo.TscIdHead, ConfigInfo.DocumentNo);
                receipt.RDate = DateTime.Now.ToString("yyyyMMddHHmmss");
                DeclHelper      declHelper = new DeclHelper();
                DeclEnvelopHead msgHeader  = declHelper.GetEnvelopHeader(msgXml);
                #region 生成TCS报文
                XDocEntity tmpDoc    = ConfigInfo.GetTemplateDocEntity();
                TcsHelper  tcsHelper = new TcsHelper();
                //保存报文
                XDocument tcsDoc = tcsHelper.GenerateTcsXDoc(tmpDoc, cusDataMsg);
                tcsDoc.Save(GetFileName(ConfigInfo.Path));
                #endregion
                #region 报文落地数据库
                cusDataMsg.TcsMessageXml = tcsDoc.ToString();
                cusDataMsg.DeclTime      = DateTime.Now;
                cusDataMsg.MsgGuid       = msgHeader.MsgGuid;
                cusDataMsg.Sendtime      = msgHeader.SendTime;
                dataHelper.SaveMessageInfo(cusDataMsg);
                #endregion

                receipt.Status   = "000";
                receipt.Message  = string.Empty;
                receipt.MessagID = cusDataMsg.TaskId;

                //记录操作日志
                logHelper.LogOperation(string.Format("SendMessage 上载报文(到QP),KeyValue:{0},Machinecode:{1},CusCiqNo:{2}",
                                                     keyValue, machineCode, cusCiqNo), Context.SendMessageEventId, "SendMessage", keyValue);
                return(receipt);
            }
            catch (Exception ex)
            {
                receipt.Status  = "001";
                receipt.Message = GetErrInfo(Context.ErrSendMessage, Context.SendMessageEventId);
                logHelper.LogErrInfo(ex.Message, Context.SendMessageEventId, "SendMessage", keyValue, msgXml);
                return(receipt);
            }
        }
        internal DeclEnvelopHead GetEnvelopHeader(string msgXml)
        {
            XDocument       doc       = XDocument.Parse(msgXml);
            XElement        headerEle = doc.Root.Element("EnvelopHead");
            DeclEnvelopHead head      = new DeclEnvelopHead
            {
                Name      = headerEle.Element("Name").Value,
                Version   = headerEle.Element("Version").Value,
                From      = headerEle.Element("From").Value,
                To        = headerEle.Element("To").Value,
                Operation = headerEle.Element("Operation").Value,
                MsgGuid   = headerEle.Element("Guid").Value
            };
            DateTime time;

            if (DateTime.TryParse(headerEle.Element("SendTime").Value, out time))
            {
                head.SendTime = time;
            }
            return(head);
        }