You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

376 lines
14 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;
using NetLibrary.Express;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TradeData;
using TradeModel;
namespace TradeManage.PrintTemplate
{
public partial class DD_OrderPrintTM : System.Web.UI.Page
{
public static List<Order> ordermodel = null;
public static string idlist = "";
private void Page_Init(object sender, EventArgs e)
{
}
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
ordermodel = null;
CrystalReportSource1.Dispose();
}
if (Session["OrderPrint"] == null)
return;
string idarr = Convert.ToString(Session["OrderPrint"]); //"5342600";//.Split(',');
if (idlist == "") idlist = idarr;
else
{
if (idlist != idarr)
{
ordermodel = null;
idlist = idarr;
}
}
int printType = 0;
//int ExpressID = Convert.ToInt32(Session["ExpressID"].ToString());
int CompanyId = 1;
if (idarr == null || idarr == "")
return;
//List<int> orderlist = new List<int>();
//for (int i = 0; i < idarr.Length; i++)
//{
// orderlist.Add(Convert.ToInt32(idarr[i]));
//}
OrderPrintData opd = new OrderPrintData();
if (ordermodel == null)
ordermodel = opd.GetOrderPrint(idarr, CompanyId, printType);
if (ordermodel == null || ordermodel.Count() == 0)
return;
CrystalReportSource1.Report.FileName = ordermodel.First().ExpressRPT;
if (ordermodel.First().ExpressService.Contains("EUB") || ordermodel.First().ExpressService.Contains("E邮宝"))
{
List<OrderDetail> listod = new List<OrderDetail>();
foreach (var q in ordermodel)
{
if (q.ExpressService.Contains("EUB美国") || q.ExpressService.Contains("EUB(美国)") || q.ExpressService.Contains("EUB美国") || q.ExpressService == ("EUB") || q.ExpressService == ("线上EUB") || q.ExpressService == ("Wish-E邮宝") || q.ExpressService.Contains("燕文上海E邮宝") || q.ExpressService == ("EUB上海") || q.ExpressService == ("EUB慈溪"))
{
//美国EUB邮编图片
q.Image = GetZipcodeImg(q.RevZip);
}
int count = 0;
foreach (var d in q.ListModel)
{
var check = listod.Where(o => o.JoinOrderCode == d.JoinOrderCode && o.GoodsCode == d.GoodsCode && o.GoodsSku == d.GoodsSku && o.TypeDesc == d.TypeDesc && o.GoodsName == d.GoodsName);
if (check.Count() == 0)
{
if (count > 2) break;
OrderDetail od = new OrderDetail();
od = d;
count++;
listod.Add(od);
}
}
}
//EUB子报表
//Sections sections = CrystalReportSource1.ReportDocument.ReportDefinition.Sections;
//DD_OrderPrintTM ppe = new DD_OrderPrintTM();
//string back = setdata(listod, sections, ppe,1);
CrystalDecisions.CrystalReports.Engine.Sections crSections = CrystalReportSource1.ReportDocument.ReportDefinition.Sections;
foreach (Section crSection in crSections)
{
ReportObjects crReportObjects = crSection.ReportObjects;
foreach (ReportObject crReportObject in crReportObjects)
{
if (crReportObject.Kind == ReportObjectKind.SubreportObject)
{
SubreportObject crSubreportObject = (SubreportObject)crReportObject;
ReportDocument crSubReportDoc = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);
crSubReportDoc.SetDataSource(listod);
}
}
}
CrystalReportSource1.ReportDocument.SetDataSource(ordermodel);
CrystalReportSource1.DataBind();
CrystalReportViewer1.ReportSource = CrystalReportSource1;
CrystalReportViewer1.RefreshReport();
}
else
{
if (ordermodel.First().ExpressService.Contains("Wish") || ordermodel.First().ExpressService == "燕邮宝" || ordermodel.First().ExpressService.Contains("德邮"))
{
foreach (var q in ordermodel)
{
//Wish邮
if (q.ExpressService.Contains("Wish"))
q.RevAddress = GetInfoWH(q.RevCountry, q.RevAddress, q.RevMobile, q.RevPhone, q.ExpressService, q.AreaSerial, q.CountryName);
//燕邮宝
if (q.ExpressService.Contains("燕邮宝"))
q.AreaSerial = Getcode(q.RevZip);
//德国邮政
if (q.ExpressService.Contains("德邮"))
q.RevAddress = getDHLCustom(q.RevAddress);
}
}
foreach (var q in ordermodel)
{
if (q.JoinOrderCode != null)
{
q.OrderCode = q.JoinOrderCode;
}
}
CrystalReportSource1.ReportDocument.SetDataSource(ordermodel);
CrystalReportSource1.DataBind();
}
}
catch (Exception ex)
{
}
}
public string getDHLCustom(string custom)
{
string str = "";
string[] templist = custom.Split(',');
for (int i = 0; i < templist.Length; i++)
{
if (templist[i].Trim() != "") str += templist[i].Trim() + "\r\n";
}
return str;
}
protected string GetInfoWH(string CountryEn, string address, string phone, string tel, string shippmark, string code1, string CountryCN)
{
string result = "";
string pstr = "";
string str = "";
if (shippmark.Contains("平邮"))
{
str = CountryEn + " " + code1 + " " + CountryCN + "\r\n";
if (phone != null)
{
if (phone.Length > 5)
{
pstr = phone;
}
}
if (pstr == "") pstr = tel;
string[] alist = address.Split(',');
string a = alist[0] + "\r\n";
string zip = alist[alist.Length - 2].ToString();
for (int i = 1; i < alist.Length - 2; i++)
{
a += alist[i] + ",";
}
result = a + CountryEn + " " + zip + "\r\n" + str + "Phone:" + pstr;
}
else
{
//var data = pr.Where(o => o.Country.Trim() == CountryEn.Trim());
//if (data.Count() > 0)
//{
str = CountryEn + " " + code1 + " " + CountryCN + "\r\n";
//}
if (phone != null)
{
if (phone.Length > 5)
{
pstr = phone;
}
}
if (pstr == "") pstr = tel;
string[] alist = address.Split(',');
string a = alist[0] + "\r\n";
string zip = alist[alist.Length - 2].ToString();
for (int i = 1; i < alist.Length - 2; i++)
{
a += alist[i] + ",";
}
result = a + CountryEn + " " + zip + "\r\n" + str + "Phone:" + pstr;
}
return result;
}
public string Getcode(string data)
{
var str = "1";
try
{
string[] address = data.Split(',');
string temp = address[address.Length - 2];
int zip = Convert.ToInt32(temp);
if (zip >= 100000 && zip <= 199999)
str = "1";
if (zip >= 200000 && zip <= 299999)
str = "2";
if (zip >= 300000 && zip <= 399999)
str = "3";
if ((zip >= 400000 && zip <= 499999) || (zip >= 600000 && zip <= 629999) || (zip >= 640000 && zip <= 641999))
str = "4";
if (zip >= 500000 && zip <= 599999)
str = "5";
if ((zip >= 630000 && zip <= 639999) || (zip >= 642000 && zip <= 699999))
str = "6";
}
catch
{
}
return str;
}
public string setdata(List<OrderDetail> listod, Sections sections, DD_OrderPrintTM ppe,int flag)
{
try
{
ppe.CrystalReportSource1 = new CrystalDecisions.Web.CrystalReportSource();
foreach (Section section in sections)
{
ReportObjects reportObjects = section.ReportObjects;
foreach (ReportObject reportObject in reportObjects)
{
if (reportObject.Kind == ReportObjectKind.SubreportObject)
{
SubreportObject subreportObject = (SubreportObject)reportObject;
ReportDocument subReportDocument = subreportObject.OpenSubreport(subreportObject.SubreportName);
subReportDocument.SetDataSource(listod);
}
}
}
}
catch(ExportException ex)
{
}
return "";
}
public byte[] GetZipcodeImg(string str)
{
string barType = "A";
string rawData = "420" + str;
if (string.IsNullOrEmpty(barType))
{
barType = "C";
}
int cw = 1;
int hm = 1;
int vm = 1;
bool showblank = false;
bool showfont = false;
int emSize = 12;
int textA = 1;
FontFamily ff = new FontFamily("Arial");
absCode128 code128;
code128 = new GS1_128(rawData);
code128.BarCellWidth = (byte)cw;
code128.HorizontalMulriple = (byte)hm;
code128.VerticalMulriple = (byte)vm;
code128.ShowBlank = showblank;
code128.DataDisplay = showfont;
code128.FontSize = emSize;
code128.FontFamily = ff;
code128.TextAlignment = (System.Drawing.StringAlignment)textA;
System.Drawing.Image img = code128.GetBarCodeImage();
ReportDocument rptDoc1;
System.IO.MemoryStream ms = new System.IO.MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Position = 0;
byte[] imageBytes = new byte[ms.Length];
ms.Read(imageBytes, 0, imageBytes.Length);
// CrystalDecisions.CrystalReports.Engine.FieldObject img1 = rptDoc1.ReportDefinition.ReportObjects["crtimg"] as CrystalDecisions.CrystalReports.Engine.FieldObject;
//img1=img
return imageBytes;
}
public static DataTable ToDataTable<T>(IEnumerable<T> varlist)
{
DataTable dtReturn = new DataTable();
// column names
PropertyInfo[] oProps = null;
if (varlist == null) return dtReturn;
foreach (T rec in varlist)
{
if (oProps == null)
{
oProps = ((Type)rec.GetType()).GetProperties();
foreach (PropertyInfo pi in oProps)
{
Type colType = pi.PropertyType;
if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition()
== typeof(Nullable<>)))
{
colType = colType.GetGenericArguments()[0];
}
dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
}
}
DataRow dr = dtReturn.NewRow();
foreach (PropertyInfo pi in oProps)
{
dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue
(rec, null);
}
dtReturn.Rows.Add(dr);
}
return dtReturn;
}
protected void Button1_Click(object sender, EventArgs e)
{
CrystalReportSource1.Dispose();
}
}
}