코드 몇 줄~ 이리저리 고쳐!

19075 단어 코드
요구 사항은 다음과 같습니다(직접 복사). 표준 전자면 단일 인터페이스를 개발하여 몇 개의 흔한 물류 회사를 연결하고 테스트하기 시작합니다.
 
과정은 생략하고 퇴근해야 하니 대충 기록해 두세요. 결과는 이렇습니다. 바로 코드에 올리세요.
 
   1:  //       ,      
   2:  public class ESingleLogic : _BaseLogic
   3:      {
   4:          ESingle _InitESingle(string carrierNo)
   5:          {
   6:              SystemParaLogic sysParalogic = new SystemParaLogic();
   7:   
   8:              if (carrierNo.Equals("EMS", StringComparison.CurrentCultureIgnoreCase))
   9:              {
  10:                  //ems
  11:                  return new ESingleEMS(sysParalogic.QuerySystemPara(""),
  12:                      sysParalogic.QuerySystemPara(""),
  13:                      sysParalogic.QuerySystemPara(""));
  14:              }
  15:              else if (carrierNo.Equals("JD", StringComparison.CurrentCultureIgnoreCase))
  16:              {
  17:                  //  
  18:                  return new ESingleJD(
  19:                      sysParalogic.QuerySystemPara(""),
  20:                      sysParalogic.QuerySystemPara(""),
  21:                      sysParalogic.QuerySystemPara(""));
  22:              }           
  23:              else
  24:              {
  25:                  return null;
  26:              }
  27:          }
  28:   
  29:          public string CreateESingle(vew_wms_ExpressList orderInfo)
  30:          {
  31:              //    
  32:              var eSingle = _InitESingle(orderInfo.fCarrierNo);
  33:   
  34:              if (eSingle == null)
  35:              {
  36:                  return null;
  37:              }
  38:   
  39:              var response = eSingle.CreateESingle(orderInfo);
  40:              
  41:              //      
  42:              Log(response.OriginalResponseString, "ESingleResponse");
  43:   
  44:              return response.ResponseData;
  45:          }
  46:      }

<!--
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
-->
 
기본 클래스:
   1:  public abstract class ESingle
   2:      {
   3:          /// <summary>
   4:          ///     (   )
   5:          /// </summary>
   6:          public string Url { get; set; }
   7:   
   8:          /// <summary>
   9:          /// 【WMS->    】        
  10:          /// </summary>
  11:          /// <param name="url">url  </param>
  12:          /// <param name="orderInfo">      </param>
  13:          /// <returns>         </returns>
  14:          public virtual ESingleResponse CreateESingle(vew_wms_ExpressList orderInfo)
  15:          {
  16:              throw new NotImplementedException();
  17:          }
  18:  }

<!--
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
-->
 
하나의 구현 클래스:
   1:  /// <summary>
   2:      /// EMS      
   3:      /// </summary>
   4:      public class ESingleEMS : ESingle
   5:      {
   6:          string userName = "";
   7:          string userPsw = "";
   8:   
   9:          /// <summary>
  10:          ///             URL  
  11:          /// </summary>
  12:          /// <param name="url"></param>
  13:          /// <param name="userName"></param>
  14:          /// <param name="userPsw"></param>
  15:          public ESingleEMS(string url, string userName, string userPsw)
  16:          {
  17:              this.Url = url;
  18:              this.userName = userName;
  19:              this.userPsw = userPsw;
  20:          }
  21:   
  22:          public override ESingleResponse CreateESingle(vew_wms_ExpressList orderInfo)
  23:          {
  24:              var request = _CreateRequestXml(orderInfo,
  25:                   userName,
  26:                   userPsw);
  27:               var response =Post(this.Url, request);
  29:              
  32:              ESingleResponse result = new ESingleResponse();

           
return result;
  46:          }
  47:      }

<!--
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
-->
 
 
설계의 취지는 WMS에 있어서 하나의 입구만 있고 같은 파라미터를 전달하여 같은 구조의 결과를 얻는 것이다.따라서 여기에 통일된 결과류도 도입한다(보완이 필요하다)
 
   1:  /// <summary>
   2:      ///                        
   3:      /// </summary>
   4:      public class ESingleResponse
   5:      {
   6:          /// <summary>
   7:          ///        
   8:          /// </summary>
   9:          public string OriginalResponseString { get; set; }
  10:          /// <summary>
  11:          ///       
  12:          /// </summary>
  13:          public bool isSuccess { get; set; }
  14:          /// <summary>
  15:          ///     
  16:          /// </summary>
  17:          public string ErrMsg { get; set; }
  18:          /// <summary>
  19:          ///     
  20:          /// </summary>
  21:          public string ReqOrderNo { get; set; }
  22:          /// <summary>
  23:          ///     
  24:          /// </summary>
  25:          public string ResponseData { get; set; }
  26:      }

<!--
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
-->
 
 
모든 물류 회사의 인터페이스에 필요한 매개 변수가 같지 않기 때문에 실례화류에 이 매개 변수를 구조 함수를 통해 채워넣는다
  //ems

                return new ESingleEMS(sysParalogic.QuerySystemPara(""),

                    sysParalogic.QuerySystemPara(""),

                    sysParalogic.QuerySystemPara(""));
 
          ,    ,            ,           。
 public virtual ESingleResponse CreateESingle(string url,

           vew_wms_ExpressList orderInfo,

            string userName,

            string userPsw,

            Dictionary<string,string> otherPara)

        {

            throw new NotImplementedException();

        }

VS

public string CreateESingle(vew_wms_ExpressList orderInfo){}



<!--
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
-->
 

좋은 웹페이지 즐겨찾기