using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Reporting.WinForms;
using FB.Entity;
using FB.Helper;
using System.Windows.Forms;
namespace FB.PrintHelper
{
public class PrintUtils
{
public static string PrintPaper(ContractTicket ticket, ContractOrder order, ReportViewer reportViewer1)
{
bool flag = false;
ReportParameter[] rps = new ReportParameter[]
{
new ReportParameter("UserName"),
new ReportParameter("CardNum"),
new ReportParameter("StartPlace"),
new ReportParameter("EndPlace"),
new ReportParameter("FlightName"),
new ReportParameter("FlightId"),
new ReportParameter("SeatClass"),
new ReportParameter("FlyDate"),
new ReportParameter("FlyTime"),
new ReportParameter("TicketNum"),//客票级别
new ReportParameter("PaperNum"),//电子客票号
new ReportParameter("VerifyNum"),//行程单号
new ReportParameter("TicketPay"),
new ReportParameter("AirPortTax"),
new ReportParameter("TotalPay"),
new ReportParameter("SafePay"),
new ReportParameter("CreateDate"),
new ReportParameter("EndPlace1"),
new ReportParameter("FlightName1"),
new ReportParameter("FlightId1"),
new ReportParameter("SeatClass1"),
new ReportParameter("FlyDate1"),
new ReportParameter("FlyTime1"),
new ReportParameter("TicketNum1"),
new ReportParameter("ranyou"),
new ReportParameter("PNR"),
new ReportParameter("NewWeight")
};
StringBuilder sb = new StringBuilder();
foreach (ContractPassenger P in ticket.Passengers)
{
foreach (var r in rps)
{
r.Values.Clear();
}
//用户名
rps[0].Values.Add(P.UserName);
//用户证件号码
rps[1].Values.Add(P.Z_ID);
//起飞城市
rps[2].Values.Add(Utils.SplitStr(ticket.StartPoint, '#', flag) + " " + Utils.SplitStr(ticket.AirSC, '#', flag));
//终点城市
rps[3].Values.Add(Utils.SplitStr(ticket.EndPoint, '#', flag) + " " + Utils.SplitStr(ticket.AirSE, '#', flag));
//承运人
rps[4].Values.Add(Utils.SplitStr(ticket.Flight_ID, '#', flag).Substring(0, 2));
//航班号
rps[5].Values.Add(Utils.SplitStr(ticket.Flight_ID, '#', flag).Substring(2, 4));
//座位等级
rps[6].Values.Add(Utils.SplitStr(ticket.CabinType, '#', flag).Split('(')[1].Substring(0, 1));
//起飞日期
string[] str = Utils.SplitStr(ticket.FlightDate, '#', flag).Split('-');
rps[7].Values.Add(str[2]+Utils.mmonth(str[1]));
//起飞时间
rps[8].Values.Add(Utils.SplitStr(ticket.FlightTime, '#', flag).Replace(":", ""));
//客票级别
rps[9].Values.Add(rps[6].Values[0] + "/" + Utils.SplitStr(ticket.AirSE, '#', flag) + str[0] +"N20");
//保险费
if (P.UserBorn == "1")
{
if (ticket.StartPoint.Contains('#'))
{
rps[15].Values.Add("40.00");
}
else
{
rps[15].Values.Add("20.00");
}
}
else
{
rps[15].Values.Add("xxx");
}
//添开日期
rps[16].Values.Add(DateTime.Now.ToShortDateString());
if (ticket.StartPoint.Contains('#'))
{
flag = true;
//终点城市
rps[17].Values.Add(Utils.SplitStr(ticket.EndPoint, '#', flag) + " " + Utils.SplitStr(ticket.AirSE, '#', flag));
//承运人
rps[18].Values.Add(Utils.SplitStr(ticket.Flight_ID, '#', flag).Substring(0, 2));
//航班号
rps[19].Values.Add(Utils.SplitStr(ticket.Flight_ID, '#', flag).Substring(2, 4));
//座位等级
rps[20].Values.Add(Utils.SplitStr(ticket.CabinType, '#', flag).Split('(')[1].Substring(0, 1));
//起飞日期
str = Utils.SplitStr(ticket.FlightDate, '#', flag).Split('-');
rps[21].Values.Add(str[2] + Utils.mmonth(str[1]));
//起飞时间
rps[22].Values.Add(Utils.SplitStr(ticket.FlightTime, '#', flag).Replace(":", ""));
//客票级别
rps[23].Values.Add(rps[20].Values[0] + "/" + Utils.SplitStr(ticket.AirSE, '#', flag) + str[0] + "N20");
//行礼重量
rps[26].Values.Add("20k");
}
string[] arr = P.PnrText.Split('
); //单价 rps[12].Values.Add("CNY " + arr[0]); //机建 if (!string.IsNullOrEmpty(arr[1])) { rps[13].Values.Add("CN " + arr[1]); } else { rps[13].Values.Add("EXEMPT"); } //燃油 if (!string.IsNullOrEmpty(arr[2])) { rps[24].Values.Add("CN " + arr[2]); } else { rps[24].Values.Add("EXEMPT"); } //行程单后四位 if(!string.IsNullOrEmpty(arr[3])) { rps[11].Values.Add(arr[3].Substring(arr[3].Length - 4)); } //电子客票号 rps[10].Values.Add(arr[4]); //PNR rps[25].Values.Add(P.PNR); //合计 rps[14].Values.Add("CNY " + P.Price); //不能让他打印空数据 foreach (ReportParameter p in rps) { if (p.Values.Count < 1) { p.Values.Add(" "); } } reportViewer1.LocalReport.SetParameters(rps); reportViewer1.RefreshReport(); reportViewer1.Refresh(); StreamPrintDocument printDoc; try { printDoc = new StreamPrintDocument(reportViewer1.LocalReport); printDoc.Print(); sb.AppendFormat("{0}的行程单打印成功\n", P.UserName); } catch { sb.AppendFormat("{0}的行程单打印失败\n", P.UserName); } printDoc = null; } return sb.ToString(); } }}