using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using System.Text;
using System.Data.Odbc;
public partial class Purchase : System.Web.UI.Page
{
public static OdbcDataAdapter daerp = new OdbcDataAdapter();
public ReportDocument report = new ReportDocument();
public DataTable rptdt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
ParameterFields paraFields = new ParameterFields();
ParameterField paraField = new ParameterField();
ParameterDiscreteValue paravalue = new ParameterDiscreteValue();
paraField.Name = "單號";
paravalue.Value = Session["pur_nbr"].ToString();
paraField.CurrentValues.Add(paravalue);
paraFields.Add(paraField);
#region prevent login dialog
#region 依據廠別加載rpt
if (Session["rpt_fac"].ToString().Trim() == "'1'")
{
report.Load(Server.MapPath("1.rpt"));
}
if (Session["rpt_fac"].ToString().Trim() == "'2'")
{
report.Load(Server.MapPath("2.rpt"));
}
if (Session["rpt_fac"].ToString().Trim() == "'3'")
{
report.Load(Server.MapPath("3.rpt"));
}
#endregion
TableLogOnInfo loginfo = new TableLogOnInfo();
#region
//loginfo.ConnectionInfo.ServerName = "192.168.1.1";
loginfo.ConnectionInfo.ServerName = "Server1";
loginfo.ConnectionInfo.DatabaseName = "Database1";
loginfo.ConnectionInfo.UserID = "sa";
loginfo.ConnectionInfo.Password = "sa.";
report.Database.Tables[2].ApplyLogOnInfo(loginfo);
report.Database.Tables[8].ApplyLogOnInfo(loginfo);
TableLogOnInfo loginfo1 = new TableLogOnInfo();
if (Session["rpt_fac"].ToString().Trim() == "'1'")
{
loginfo1.ConnectionInfo.ServerName = "Server2";
loginfo1.ConnectionInfo.DatabaseName = "Database2";
loginfo1.ConnectionInfo.UserID = "sa";
loginfo1.ConnectionInfo.Password = "";
}
if (Session["rpt_fac"].ToString().Trim() == "'2'")
{
loginfo1.ConnectionInfo.ServerName = "Server3";
loginfo1.ConnectionInfo.DatabaseName = "Database3";
loginfo1.ConnectionInfo.UserID = "sa";
loginfo1.ConnectionInfo.Password = "";
}
if (Session["rpt_fac"].ToString().Trim() == "'3'")
{
loginfo1.ConnectionInfo.ServerName = "Server4";
loginfo1.ConnectionInfo.DatabaseName = "Database4";
loginfo1.ConnectionInfo.UserID = "sa";
loginfo1.ConnectionInfo.Password = "";
}
//report.Database.Tables[0].ApplyLogOnInfo(loginfo);
report.Database.Tables[0].ApplyLogOnInfo(loginfo1);
report.Database.Tables[1].ApplyLogOnInfo(loginfo1);
report.Database.Tables[3].ApplyLogOnInfo(loginfo1);
report.Database.Tables[4].ApplyLogOnInfo(loginfo1);
report.Database.Tables[5].ApplyLogOnInfo(loginfo1);
report.Database.Tables[6].ApplyLogOnInfo(loginfo1);
report.Database.Tables[7].ApplyLogOnInfo(loginfo1);
#endregion
#endregion
try
{
#region old
//report.SetDataSource(rptdt);
//CrystalReportViewer1.ReportSource = report;
//CrystalReportViewer1.DataBind();
#endregion
CrystalReportViewer1.ReportSource = report;
CrystalReportViewer1.ParameterFieldInfo = paraFields;
CrystalReportViewer1.DataBind();
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
private void InitializeComponent()
{
this.Unload += new System.EventHandler(this.Purchase_Unload);
}
private void Purchase_Unload(object sender, EventArgs e)
{
rptdt.Reset();
report.Dispose();
report.Close();
}
}