LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

C#一般处理程序+Lodop打印跨境电商电子面单

admin
2023年9月25日 16:53 本文热度 449

效果图:


Aspx页面代码:

1.  <table class="table table-bordered table-striped">

2.  <tbody>

3.    <tr class="even gradeC">

4.      <td>波次单号:</td>

5.      <td>

6.         <input type="text" runat="server" id="txtWaveNo" value="SO1512150540" /></td>

7.       <td>SO订单号:</td>

8.      <td>

9.          <input type="text" runat="server" id="txtSoNo" />

10.    </td>

11.  </tr>

12.  <tr class="odd gradeA">

13.          <td colspan="4"><input type="button" class="btn btn-info"  id="btnPrint" value="比利时小包打印" runat="server" />&nbsp;&nbsp;&nbsp;<input type="button" class="btn btn-info"  id="btnPrint" value="荷兰小包打印" runat="server" />

14.              <input type="button" class="btn btn-info"  id="btnFoShanPrint" value="佛山小包打印" runat="server" />   

15.              <span style="color:red">友情提示:可选择扫描波次或者SO单号进行打印。</span>

16.          </td>

17.    </tr>

18.</tbody>

19.</table>

20.<div id="main-content">

21.   <div class="tab-content">

22.     <!--发运订单信息-->

23.     <div id="live" class="tab-pane active">

24.       <div class='row-fluid'>

25.         <div class='span12 widget'>

26.          <div class='widget-content summary-list'>

27.               <div class='row-fluid' >

28.                    <div class='span12 section '>

29.                       <table class='table table-bordered table-striped'>

30.                              <tbody id="divErrorMessage" runat="server">

31.                              </tbody>

32.                       </table>

33.                    </div>

34.               </div>

35.          </div>

36.         </div>

37.        </div>

38.     </div>

39.   </div>

40.</div>

 JS代码:

1.  荷兰和佛山小包打印:  

2.   <input type="hidden" id="hfExpressHtml"/>

3.      <!-- Core scripts -->

4.      <script src="http://www.orderonline.cn/js/jquery-1.7.2.js"></script>

5.       <script src="assets/js/Lodop.js"></script>

6.          <script type="text/javascript">

7.              $(document).ready(function () {

8.                  $("#btnPrint").click(function () {

9.                      if ($("#txtWaveNo").val() == "" && $("#txtSoNo").val() =="") {

10.                        alert('波次单号或SO订单号不能全为空,请任意输入一个进行打印。');

11.                    }

12.                    else {

13.                        var searchwhere = $("#txtWaveNo").val() + "_" + $("#txtSoNo").val();

14.                        $.ajax({

15.                            type: "get",

16.                            url: "ExpressPrint.ashx",

17.                            data: "getExpressInfo=" + encodeURIComponent(searchwhere),

18.                            datatype: "json",

19.                            async: false,

20.                            success: function (returnData, textstatus, xmlhttprequest) {

21.                                LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));

22.                                LODOP.SET_SHOW_MODE("HIDE_PAPER_BOARD", 1);

23.                                $("#hfExpressHtml").html(returnData);

24.                                var html = $("#hfExpressHtml .main_all >div");

25.                                //  var strStyleCSS = "<!DOCTYPE html> <head>";

26.                                var strStyleCSS = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns=\"http://www.w3.org/1999/xhtml\"><head>";

27.                                strStyleCSS += "<link href='http://www.orderonline.cn/css/A4.css' type='text/css' rel='stylesheet'></head><body>";

28.                                //HTML格式用

29.                                // LODOP.SET_PRINT_PAGESIZE(1, "760px", "650px", "A5");

30.                                var num = 0; var strFormHtml = "";

31.                                for (var i = 0; i < html.length; i++) {

32.                                    if (num % 2 == 0) {

33.                                        LODOP.NewPage(); strFormHtml = "";

34.                                        strFormHtml += strStyleCSS + html[i].outerHTML;

35.                                    }

36.                                    else {

37.                                        strFormHtml += strStyleCSS + html[i].outerHTML;

38.                                    }

39.                                    LODOP.ADD_PRINT_HTM(15, 0, 800, 650, strFormHtml + "</body></html>");

40.                                    // LODOP.ADD_PRINT_HTM(30, 0, 800, 650, strFormHtml + "</body></html>");

41.                                    num++;

42.                                } LODOP.PREVIEW(); strFormHtml = "";

43.                            },

44.                            error: function (errorinfo) {

45.                                alert("快递单打印失败,请重新刷新后打印。");

46.                            }

47.                        });

48.                    }

49.                })

50.                $("#btnFoShanPrint").click(function () {

51.                    if ($("#txtWaveNo").val() == "" && $("#txtSoNo").val() == "") {

52.                        alert('波次单号或SO订单号不能全为空,请任意输入一个进行打印。');

53.                    }

54.                    else {

55.

56.                        var searchwhere = $("#txtWaveNo").val() + "_" + $("#txtSoNo").val();

57.                        $.ajax({

58.                            type: "get",

59.                            url: "ExpressPrint.ashx",

60.                            data: "getExpressInfo=" + encodeURIComponent(searchwhere),

61.                            datatype: "json",

62.                            async: false,

63.                            success: function (returnData, textstatus, xmlhttprequest) {

64.                                LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));

65.                                LODOP.SET_SHOW_MODE("HIDE_PAPER_BOARD", 1);

66.                                $("#hfExpressHtml").html(returnData);

67.                                var html = $("#hfExpressHtml .main_all >div");

68.                                //  var strStyleCSS = "<!DOCTYPE html> <head>";

69.                                var strStyleCSS = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns=\"http://www.w3.org/1999/xhtml\"><head>";

70.                                strStyleCSS += "<link href='http://www.orderonline.cn/css/A4.css' type='text/css' rel='stylesheet'></head><body>";

71.                                //HTML格式用

72.                                 LODOP.SET_PRINT_PAGESIZE(2, "760px", "650px", "A5");

73.                                var num = 0; var strFormHtml = "";

74.                                for (var i = 0; i < html.length; i++) {

75.                                    if (num % 2 == 0) {

76.                                        LODOP.NewPage(); strFormHtml = "";

77.                                        strFormHtml += strStyleCSS + html[i].outerHTML;

78.                                    }

79.                                    else {

80.

81.                                        strFormHtml += strStyleCSS + html[i].outerHTML;

82.                                    }

83.                                    LODOP.ADD_PRINT_HTM(15, 0, 800, 650, strFormHtml + "</body></html>");

84.                                    // LODOP.ADD_PRINT_HTM(30, 0, 800, 650, strFormHtml + "</body></html>");

85.                                    num++;

86.                                } LODOP.PREVIEW(); strFormHtml = "";

87.

88.                            },

89.                            error: function (errorinfo) {

90.                                alert("快递单打印失败,请重新刷新后打印。");

91.                            }

92.                        });

93.                    }

94.                })

95.                //清除转向页面

96.                $("#txtWaveNo").val(''); $("#txtSoNo").val(''); $("#hfExpressHtml").html('');

97.            });

98.        </script>

99. 

100.   比利时小包打印:

101.     <script type="text/javascript">

102.    

103.               $(document).ready(function () {

104.    

105.                   $("#btnPrint").click(function () {

106.                       if ($("#txtWaveNo").val() == "" && $("#txtSoNo").val() == "") {

107.                           alert('波次单号或SO订单号不能全为空,请任意输入一个进行打印。');

108.                       }

109.                       else {

110.    

111.                           var searchwhere = $("#txtWaveNo").val() + "_" + $("#txtSoNo").val();

112.                           $.ajax({

113.                               type: "get",

114.                               url: "ExpressPrint.ashx",

115.                               data: "getBlsExpressInfo=" + encodeURIComponent(searchwhere),

116.                               datatype: "json",

117.                               async: false,

118.                               success: function (returnData, textstatus, xmlhttprequest) {

119.    

120.                                   LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM'));

121.                                   LODOP.SET_SHOW_MODE("HIDE_PAPER_BOARD", 1);

122.    

123.                                   $("#hfExpressHtml").html(returnData);

124.                                   var html = $("#hfExpressHtml .main_all >div");

125.                                   //  var strStyleCSS = "<!DOCTYPE html> <head>";

126.                                   var strStyleCSS = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns=\"http://www.w3.org/1999/xhtml\"><head>";

127.                                   strStyleCSS += "<link href='http://www.orderonline.cn/css/A4.css' type='text/css' rel='stylesheet'></head><body>";

128.    

129.                                   //HTML格式用

130.                                   // LODOP.SET_PRINT_PAGESIZE(1, "760px", "650px", "A5");

131.    

132.                                   var num = 0; var strFormHtml = "";

133.                                   for (var i = 0; i < html.length; i++) {

134.                                       if (num % 2 == 0) {

135.                                           LODOP.NewPage(); strFormHtml = "";

136.                                           strFormHtml += strStyleCSS + html[i].outerHTML;

137.                                       }

138.                                       else {

139.    

140.                                           strFormHtml += strStyleCSS + html[i].outerHTML;

141.                                       }

142.                                       LODOP.ADD_PRINT_HTM(15, 0, 800, 650, strFormHtml + "</body></html>");

143.                                       // LODOP.ADD_PRINT_HTM(30, 0, 800, 650, strFormHtml + "</body></html>");

144.                                       num++;

145.                                   } LODOP.PREVIEW(); strFormHtml = "";

146.    

147.                               },

148.                               error: function (errorinfo) {

149.                                   alert("快递单打印失败,请重新刷新后打印。");

150.                               }

151.                           });

152.                       }

153.                       //清除转向页面

154.                       $("#txtWaveNo").val(''); $("#txtSoNo").val(''); $("#hfExpressHtml").html('');

155.                   })

156.               });

157.           </script>

ExpressPrint.ashx 代码:

1.  public class ExpressPrint : IHttpHandler

2.      {

3.          public void ProcessRequest(HttpContext context)

4.          {

5.              context.Response.ContentType = "text/plain";

6.              if (!string.IsNullOrEmpty(context.Request["getExpressInfo"]))

7.                 {

8.                     string[] strParm = context.Request["getExpressInfo"].Split('_');

9.                    StringBuilder sbExpressHtml = new StringBuilder();

10.                  var returnHtml = string.Empty;

11.                  using (ExpressPrintDataContext db = new ExpressPrintDataContext())

12.                  {

13.                      var getExpressList = from p in db.DOC_Wave_Details

14.                                           join pp in db.DOC_Order_Header

15.                                           on p.OrderNo equals pp.OrderNo

16.                                           where p.WaveNo.Contains(strParm[0]) && p.OrderNo.Contains(strParm[1])

17.                                           select new { p.WaveNo, p.OrderNo, pp.SOReference3 };

18.                      var expressNo = string.Empty;

19.                      returnHtml = @"<link href=""http://www.orderonline.cn/A4.css"" rel=""stylesheet"" type=""text/css"" />";

20.                      returnHtml += "<div class=\"wapper\" id=\"A4_print\"><div class=\"main_all\">";

21.                      foreach (var item in getExpressList)

22.                      {

23.                         // expressNo += item.SOReference3 + ',';

24.                          string strURL = "http://www.orderonline.cn/printNo.action?print=A4&remak=1&prType=W&hawbNos=" + item.SOReference3;

25.

26.                          HttpWebRequest request = (HttpWebRequest)HttpWebRequest.create(strURL);

27.                          request.Method = "GET";

28.                          request.ContentType = "text/html;charset=UTF-8";

29.                          HttpWebResponse response = (HttpWebResponse)request.GetResponse();

30.                          Stream myResponseStream = response.GetResponseStream();

31.                          StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));

32.                          string retString = myStreamReader.ReadToEnd();

33.

34.                          myStreamReader.Close();

35.                          myResponseStream.Close();

36.                          returnHtml += Regex.Match(retString, @"(?is)<div class=""main p_r"">((?<o><div[^<>]*>)|(?<-o></div>)|(?!</?div>).)+(?(o)(?!))</div>").Groups[0].Value.Trim();

37.                         

38.                          Regex reg = new Regex("<td colspan=\"2\" class=\"bar-con tx-ce \">([\\s\\S]*?)<\\/td>", RegexOptions.IgnoreCase);

39.                          MatchCollection mac = reg.Matches(returnHtml);

40.                          var code="barbecue?fmt=png&height=40&type=code128&data="+item.SOReference3;

41.                          foreach (Match m in mac)

42.                          {

43.                              string f1 = m.Groups[1].Value.Replace("/[\r\n]/g", "");

44.                              returnHtml = returnHtml.Replace(f1, "<div style=\"float:left\"><img  style=\"width:260px;height:40px;\"  src="+code+"> </div>

);

45.                          }   

46.                      }

47.                      Regex regex = new Regex("/images", RegexOptions.IgnoreCase);

48.                      returnHtml = regex.Replace(returnHtml, "http://www.orderonline.cn/images");

49.                      Regex regex1 = new Regex("barbecue", RegexOptions.IgnoreCase);

50.                      returnHtml = regex1.Replace(returnHtml, "http://www.orderonline.cn/barbecue");

51.                      sbExpressHtml.Append(returnHtml+"</div></div>");

52.                  }

53.                  context.Response.Write(sbExpressHtml.ToString());

54.            }

55.       if (!string.IsNullOrEmpty(context.Request["getBlsExpressInfo"]))

56.       {

57.           string[] strParm = context.Request["getBlsExpressInfo"].Split('_');

58.           StringBuilder sbExpressHtml = new StringBuilder();

59.           var returnHtml = string.Empty;

60.           using (ExpressPrintDataContext db = new ExpressPrintDataContext())

61.           {

62.              //var getExpressList = from p in db.DOC_Wave_Details

63.              //                     join pp in db.DOC_Order_Header

64.              //                     on p.OrderNo equals pp.OrderNo

65.              //                     where p.WaveNo.Contains(strParm[0]) && p.OrderNo.Contains(strParm[1])

66.              //                     select new { p.WaveNo, p.OrderNo, pp.SOReference3 };

67.              //数据放入ticket

68.              var apiToken = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", "mega", "bpost")));

69.              string url = "http://42.121.252.25/api/lvsparcels?productBarcode=BLVS1592170000004048";

70.              try

71.              {

72.                  //配置请求header    

73.                  HttpWebRequest request = (HttpWebRequest)HttpWebRequest.create(url);

74.                  request.Method = "GET";

75.                  request.ContentType = "text/json; charset=utf-8";

76.                  request.Headers.Add(HttpRequestHeader.Authorization, "basic " + apiToken);

77.                  HttpWebResponse response = (HttpWebResponse)request.GetResponse();

78.                  Stream myResponseStream = response.GetResponseStream();

79.                  StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));

80.                  string retString = myStreamReader.ReadToEnd();

81.                  LvsParcelJson getExpressInfo = (LvsParcelJson)JsonConvert.DeserializeObject<LvsParcelJson>(retString);

82.                  myStreamReader.Close();

83.                  myResponseStream.Close();

84.              }

85.              catch (Exception e)

86.              {

87.                  context.Response.Write(e.Message);

88.              }

89.           }

90.       }

91.       context.Response.End();

92.    }

93.     public class LvsParcelJson

94.    {

95.       public int Id { get; set; }

96.       public string OrderNumber { get; set; }

97.       public string ProductBarcode { get; set; }

98.       public string RecipientName { get; set; }

99.       public string RecipientStreet { get; set; }

100.           public string RecipientHouseNumber { get; set; }

101.           public string RecipientBusnumber { get; set; }

102.           public string RecipientZipCode { get; set; }

103.           public string RecipientCity { get; set; }

104.           public string RecipientState { get; set; }

105.           public string RecipientCountry { get; set; }

106.           public string PhoneNumber { get; set; }

107.           public string SenderName { get; set; }

108.           public DateTime createTime { get; set; }

109.           public string SenderAddress { get; set; }

110.           public  List<Customers> Customs { get; set; }

111.        }

112.    

113.        public class Customers

114.        {

115.           public string Sku { get; set; }

116.           public string ChineseContentDescription { get; set; }

117.           public string ItemContent { get; set; }

118.           public int ItemCount { get; set; }

119.            public decimal Value { get; set; }

120.           public string Currency { get; set; }

121.           public decimal Weight { get; set; }

122.           public string SkuInInvoice { get; set; }

123.        }

124.        public bool IsReusable

125.           {

126.               get

127.               {

128.                   return false;

129.               }

130.           }

131.       }


该文章在 2023/9/25 16:53:52 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved