using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using CDWareHouse.rpt.OpenBiblioTableAdapters;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace CDWareHouse
{
public partial class CDLabels : System.Web.UI.Page
{
private ReportDocument rdm;
protected void Page_Load(object sender, EventArgs e)
{
string cbibid = Request["bibid"];
string copyid = Request["copyid"];
string splitStr = System.Configuration.ConfigurationManager.AppSettings["splitStr"];
string printerName = System.Configuration.ConfigurationManager.AppSettings["printerName"];
string pageSizeName = System.Configuration.ConfigurationManager.AppSettings["pageSizeName"];
#if DEBUG
cbibid= "4";
copyid="1";
#endif
//Debug.Assert(test());
if (cbibid != null && copyid != null)
{
CDLabelsDa cdlabelsda = new CDLabelsDa();
bibcopyfieldsDA bibfieldsda = new bibcopyfieldsDA();
DataTable cdlabelsDataTable = (DataTable)cdlabelsda.GetData(Convert.ToInt32(cbibid), Convert.ToInt32(copyid));
DataTable fieldDS = bibfieldsda.GetData(Convert.ToInt32(cbibid), Convert.ToInt32(copyid));
string colName="";
string cdType = "";
//當主記錄表有記錄時才進行插入操作
if (cdlabelsDataTable.Rows.Count > 0)
{
//把文件夾列表插入到 cdlabelsda DataTable
foreach (DataRow r in fieldDS.Rows)
{
string[] data = Regex.Split(r["data"].ToString(), splitStr, RegexOptions.IgnoreCase);
colName = r["code"].ToString();
//CD類型
if (colName == "cdtype")
cdType = r["data"].ToString();
//文字數組不匹配時自動跳到下一個數據.
if (data.Length != 3)
continue;
if (cdlabelsDataTable.Columns[colName + "_ckb"] != null)
{
cdlabelsDataTable.Rows[0][colName + "_ckb"] = data[0]=="true"?"true":"false";
cdlabelsDataTable.Rows[0][colName + "_per"] = data[1];
cdlabelsDataTable.Rows[0][colName + "_memo"] = data[2];
}
}
}
rdm = new ReportDocument();
rdm.Load(Request.PhysicalApplicationPath + (cdType.IndexOf("mac") > 0 ? @"\rpt\rptCDLabelsMAC.rpt" : @"\rpt\rptCDLabelsPC.rpt"));
rdm.SetDataSource(cdlabelsDataTable);
Response.Clear();
rdm.PrintOptions.PrinterName = "Adobe PDF";
System.Drawing.Printing.PrintDocument doctoprint= new System.Drawing.Printing.PrintDocument();
int rawKind =0;
doctoprint.PrinterSettings.PrinterName = printerName;
for(int i=0;i<doctoprint.PrinterSettings.PaperSizes.Count;i++){
if(doctoprint.PrinterSettings.PaperSizes[i].PaperName==pageSizeName){
rawKind=doctoprint.PrinterSettings.PaperSizes[i].RawKind;
//Response.Write("CD");
//Response.End();
break;
}
}
rdm.PrintOptions.PaperSize = (PaperSize)rawKind;
rdm.ExportToHttpResponse(ExportFormatType.PortableDocFormat , Response, false, "ExportedReport");
Response.End();
//cdlabelsda.Dispose();
}
else
{
Response.Write("錯誤的CD信息!");
}
}
protected void Page_UnLoad(object sender, EventArgs e)
{
//斷開rdm連接
if (rdm != null)
{
rdm.Close();
rdm.Dispose();
}
}
}
}