public bool Create501Message(LogisticsHead logisticsHead)
 {
     bool isSuccess = true;
     BaseSubscribe baseSubscribe = null;
     XElement xele = null;
     XNamespace ns = null;
     try
     {
         Logs.Debug("Create501Message Start!" + logisticsHead.orderNo);
         baseSubscribe = GetBaseSubscribe();
         ns = "http://www.chinaport.gov.cn/ceb";
         xele = new XElement(ns + "CEB501Message");
         xele.SetAttributeValue(XNamespace.Xmlns + "ceb", ns);
         xele = logisticsHead.ToXElememt(xele, ns);
         xele = baseSubscribe.ToXElememt(xele, ns);
         FileUtilities.CreateFolder(ConfigurationInfo.PathSend);
         xele.Save(ConfigurationInfo.PathSend + "\\" + logisticsHead.orderNo + "_501.xml");
         Logs.Debug("Create501Message End! OrderNo_" + logisticsHead.orderNo);
     }
     catch (Exception ex)
     {
         Logs.Error("Create501Message Exception: " + ex.ToString());
         isSuccess = false;
     }
     return isSuccess;
 }
 public void QueryData501(string orderNoFake, ref LogisticsHead logisticsHead)
 {
     SqlDataReader dr = null;
     try
     {
         dr = a_sqlServer.ExePROC("MessageCenterQuery", ConvertToSqlParameters(501, orderNoFake, ""));
         if (dr.HasRows)
         {
             while (dr.Read())
             {
                 logisticsHead = GetLogisticsHead(dr);
             }
         }
     }
     catch (Exception ex)
     {
         Logs.Error("Query501DataByOrderNo Exception : " + ex.ToString());
     }
     finally
     {
         dr.Close();
     }
 }
        public bool CreateMessage501(string orderNoFake)
        {
            bool success = true;
            LogisticsHead logisticsHead = null;
            MessageSql mssql = null;
            MessageService msService = null;
            XElement xele = null;
            XNamespace ns = null;
            try
            {
                mssql = new MessageSql();
                logisticsHead = new LogisticsHead();
                mssql.QueryData501(orderNoFake, ref logisticsHead);

                if (logisticsHead.guid != new Guid())
                {
                    string url = GetRequestHostByCode(logisticsHead.logisticsCode);
                    RestRequest restRequest = new RestRequest(string.Format("{0}:{1}/Logistics/Create501", url, ConfigurationInfo.RestPort), Utilities.JsonSerialize(logisticsHead));
                    success = Convert.ToBoolean(restRequest.Execute());
                }
                else
                {
                    success = false;
                }
                if (success)
                {
                    mssql.UpdateSchedule501(orderNoFake, logisticsHead.billNo, logisticsHead.weight.ToString(), logisticsHead.freight.ToString());

                    ns = "http://www.chinaport.gov.cn/ceb";
                    xele = new XElement(ns + "CEB501Message");
                    xele.SetAttributeValue(XNamespace.Xmlns + "ceb", ns);
                    xele = logisticsHead.ToXElememt(xele, ns);

                    string destPath = FileUtilities.GetNewFolderName(true, ConfigurationInfo.PathBackUp, "501") + "\\" + FileUtilities.GetNewFileName(orderNoFake, "Create") + ".xml";

                    xele.Save(destPath);

                    msService = new MessageService();
                    msService.DealMessage501(false, true, logisticsHead.guid.ToString(), orderNoFake, logisticsHead.logisticsNo, destPath);
                }
                else
                {
                    Logs.Info("Create501Message Response Error! Date:" + Utilities.JsonSerialize(logisticsHead));
                }
            }
            catch (Exception ex)
            {
                success = false;
                Logs.Error("Create501Message Exception: " + ex.ToString());
            }
            finally
            {
                if (!success)
                {
                    MessageCache.DeleteMessageCache("503R" + logisticsHead.logisticsNo);
                    MessageCache.DeleteMessageCache("601" + logisticsHead.logisticsNo);
                }
            }
            return success;
        }
 private LogisticsHead GetLogisticsHead(SqlDataReader dr)
 {
     LogisticsHead result = null;
     try
     {
         result = new LogisticsHead();
         result.guid = Guid.NewGuid();
         result.customsCode = Convert.ToString(dr["customsCode"]);
         result.appType = Convert.ToInt32(AppType.Add);
         result.appTime = DateTime.UtcNow;
         result.appStatus = Convert.ToInt32(AppStatus.Declare);
         result.appUid = Convert.ToString(dr["appUid"]);
         result.appUname = Convert.ToString(dr["appUname"]);
         result.orderNo = Convert.ToString(dr["customs_OrderNo"]);
         result.ebpCode = Convert.ToString(dr["ebpCode"]);
         result.ebpName = Convert.ToString(dr["ebpName"]);
         result.logisticsCode = Convert.ToString(dr["logisticsCode"]);
         result.logisticsName = Convert.ToString(dr["logisticsName"]);
         result.logisticsNo = Convert.ToString(dr["logisticsNo"]);
         result.ieFlag = OrderType.E;
         result.trafMode = "9";
         result.trafName = Convert.ToString(dr["trafName"]);
         result.voyageNo = Convert.ToString(dr["voyageNo"]);
         result.billNo = DateTime.Now.ToString("yyyyMMdd") + "_" + result.logisticsNo;
         result.freight = Convert.ToSingle(dr["loginticsFreight"]);
         result.insuredFee = Convert.ToSingle(dr["insuredFee"]);
         result.currency = "142";
         result.weight = Convert.ToSingle(dr["orderWeight"]);
         result.netWt = Convert.ToSingle(dr["orderNetWeight"]);
         result.packNo = Convert.ToSingle(dr["packNo"]);
         result.parcelInfo = result.logisticsNo;
         result.goodsInfo = ";";
         result.consignee = Convert.ToString(dr["consignee"]);
         result.consigneeAddress = Convert.ToString(dr["consigneeAddress"]);
         result.consigneeTelephone = Convert.ToString(dr["consigneeTelephone"]);
         result.consigneeCountry = Convert.ToString(dr["consigneeCountry_Code"]);
         result.shipper = Convert.ToString(dr["shipper"]);
         result.shipperAddress = Convert.ToString(dr["shipperAddress"]);
         result.shipperTelephone = Convert.ToString(dr["shipperTelephone"]);
         result.shipperCountry = "142";
         result.note = "";
     }
     catch (Exception ex)
     {
         throw new Exception("GetLogisticsHead Exception : " + ex.ToString());
     }
     return result;
 }
 public bool UploadLogistics501(LogisticsHead info)
 {
     LogisticsControl control = new LogisticsControl();
     return control.Create501Message(info);
 }