1 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Stimulsoft.Report;
using Stimulsoft.Report.Components;
using Stimulsoft.Report.Print;
using Stimulsoft.Report.Export;
using System.IO;
using System.Net.Mail;
using System.Text;
using System.Net;
public class applicationStart
{
public static bool isshowlogo = false;
public static string orderid = "";
public static DataTable dthead;
public static DataTable dtmessage;
}
public partial class StimulReport : System.Web.UI.Page
{
double left = , right = , top = , bottom = ;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
try
{
string aa = Request.QueryString["printno"];
if (aa == null || aa == "")
throw new Exception();
applicationStart.orderid = aa;
}
catch
{
return;
}
try
{
applicationStart.isshowlogo = Convert.ToBoolean(Request.QueryString["isshowlogo"]);
}
catch
{
}
GetSource();
}
ShowReport(applicationStart.isshowlogo);
}
private void ShowReport(bool isshowlogo)
{
if (applicationStart.isshowlogo)
{
this.Button2.Text = "HideLogo";
}
else
{
this.Button2.Text = "ShowLogo";
}
string filepath = Server.MapPath("~/Report_1.mrt");
StiReport stireport = new StiReport();
stireport.Load(filepath);
stireport.RegData("datasource", applicationStart.dtmessage);
//设置报表内控件状态
StiFooterBand fb = stireport.Pages[].Components["FooterBand1"] as StiFooterBand;
StiText st = fb.Components["Text47"] as StiText;
st.Enabled = applicationStart.dthead.Rows[]["looksampletype"].ToString() == "" ? false : true;
StiPageHeaderBand head = stireport.Pages[].Components["PageHeaderBand1"] as StiPageHeaderBand;
StiImage imglogo1 = head.Components["Image1"] as StiImage;
imglogo1.Enabled = applicationStart.isshowlogo;
StiPageFooterBand footer = stireport.Pages[].Components["PageFooterBand1"] as StiPageFooterBand;
StiImage imglogo2 = footer.Components["Image2"] as StiImage;
imglogo2.Enabled = applicationStart.isshowlogo;
//设置页边距
stireport.Pages[].Margins = new StiMargins(left, right, top, bottom);
stireport.Compile();
//设置报表内的参数值
stireport["code"] = applicationStart.dthead.Rows[]["code"].ToString();
stireport["orderno"] = applicationStart.dthead.Rows[]["orderno"].ToString();
stireport["price"] = applicationStart.dthead.Rows[]["price"].ToString();
stireport["discountprice"] = applicationStart.dthead.Rows[]["discountprice"].ToString();
stireport["tobefinishstr"] = applicationStart.dthead.Rows[]["tobefinishstr"].ToString();
stireport["createdate"] = applicationStart.dthead.Rows[]["createdate"].ToString();
stireport["contact"] = applicationStart.dthead.Rows[]["contact"].ToString();
stireport["companyname"] = applicationStart.dthead.Rows[]["companyname"].ToString();
stireport["tel"] = applicationStart.dthead.Rows[]["tel"].ToString();
stireport["fax"] = applicationStart.dthead.Rows[]["fax"].ToString();
stireport["mobile"] = applicationStart.dthead.Rows[]["mobile"].ToString();
stireport["address"] = applicationStart.dthead.Rows[]["address"].ToString();
stireport["email"] = applicationStart.dthead.Rows[]["email"].ToString();
stireport["deliverytypeenname"] = applicationStart.dthead.Rows[]["deliverytypeenname"].ToString();
stireport["name"] = applicationStart.dthead.Rows[]["name"].ToString();
stireport["customermemo"] = applicationStart.dthead.Rows[]["customermemo"].ToString();
stireport["looksampletypestr"] = applicationStart.dthead.Rows[]["looksampletypestr"].ToString();
viewer1.Report = stireport;
}
private void GetSource()
{
string headsql = "select orderno, tobefinishdate, so.price,so.discountprice, tobefinishstr,so.deliverydate,createdate ,so.contact,so.companyname,so.tel,so.fax,so.mobile,so.address,so.looksampletype, " +
"so.orderid, so.email,so.code, sales.username as salename ,openso.username as openname ,base_delivery_type.deliverytypeenname,base_delivery_type.shiptypename,user_position.positionname," + "name,so.discountoffflag,so.customermemo from so ,user as sales,user as openso ,base_delivery_type,user_position ,customer,customer_discount " +
"where so.userid=sales.userid and so.opuserid=openso.userid and base_delivery_type.deliverytypeid=so.deliverytypeid " +
"and so.positionid=user_position.positionid and customer.discountid=customer_discount.discountid " +
"and so.customerid=customer.customerid and so.orderid=" + applicationStart.orderid;
string messagesql = "SELECT *from (" +
"select jobno,product.productname,enproductname,so_detail.printnum,sampleflag,socontent as jobcontent , printprice , " +
"sodetailid as sortno,so.customermemo as memo " +
"From so_detail ,so,product where so_detail.deleteflag=0 and so.orderid=so_detail.orderid and " +
"product.productid=so_detail.productid and so.orderid= " + applicationStart.orderid +
" union all " +
"select '' as jobno , 'Delivery' as productname ,'Delivery' as enproductname , ' ' as printnum ,' ' as sampleflag , '' as jobcontent ,price ," +
"'1' as sortno ,address as memo from so_delivery where orderid= " + applicationStart.orderid +
" union all " +
"select '' as jobno , 'PostProcess' as productname ,'PostProcess' as enproductname, outsidenum as printnum ,' ' as sampleflag , postprocessname, costamount " +
", so_detail.sodetailid as sortno ,concat(memo,memostr) as memo From so_detail_outside,so ,so_detail where so.orderid=so_detail.orderid and so_detail.deleteflag=0 " +
"and so_detail.sodetailid=so_detail_outside.sodetailid and so.orderid= " + applicationStart.orderid +
" union all " +
"select '' as jobno , 'OtherItem' as productname ,'OtherItem' as enproductname , ' ' as printnum ,' ' as sampleflag , pricenamecn, so_detail_price.price " +
", so_detail.sodetailid as sortno ,'' as memo From so_detail_price,so ,so_detail where so.orderid=so_detail.orderid and so_detail.deleteflag=0 " +
"and so_detail.sodetailid=so_detail_price.sodetailid and so.orderid= " + applicationStart.orderid +
" union all " +
"select '' as jobno , offername as productname ," +
"'Discountinfo' as enproductname , ' ' as printnum ,' ' as sampleflag , offer_so_history.offermemo as discountmemo, -offer_so_history.discountprice as price , " +
"'0' as sortno , offer_so_history.offername as memo From offer_so_history,so where so.orderid=offer_so_history.orderid and so.deleteflag=0 " +
"and so.orderid=" + applicationStart.orderid + " ) as itemlist order by sortno desc";
DataModule dm = DataModule.GetDataModule();
applicationStart.dthead = dm.QuerySql(headsql);
applicationStart.dtmessage = dm.QuerySql(messagesql);
DataTable dt = applicationStart.dtmessage;
applicationStart.dthead.Columns.Add(new DataColumn("looksampletypestr", typeof(string)));
applicationStart.dthead.Columns.Add(new DataColumn("isshowdiscountprice", typeof(string)));
if (applicationStart.dthead.Rows.Count > )
{
if (applicationStart.dthead.Rows[][].ToString() == applicationStart.dthead.Rows[][].ToString())
{
applicationStart.dthead.Rows[]["isshowdiscountprice"] = ;//false
}
else
{
applicationStart.dthead.Rows[]["isshowdiscountprice"] = ;//true
}
}
foreach (DataRow dr in applicationStart.dthead.Rows)
{
if (dr["looksampletype"].ToString() == "")
{
dr["looksampletypestr"] = "不打稿";
}
else if (dr["looksampletype"].ToString() == "")
{
dr["looksampletypestr"] = "打稿";
}
else
{
dr["looksampletypestr"] = "";
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SendEmail(this.DropDownList1.SelectedValue, this.viewer1.Report, "aaa@163.com", this.TextBox1.Text, "Report[" + this.DropDownList1.SelectedValue + "]" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "", "smtp.163.com", , "aaa@163.com", "");
}
private void GetFormat(string filetype, ref StiExportFormat sf, ref string filename)
{
switch (filetype)
{
case "pdf": sf = StiExportFormat.Pdf; filename = "report.pdf"; break;
case "jpeg": sf = StiExportFormat.ImageJpeg; filename = "report.jpeg"; break;
case "gif": sf = StiExportFormat.ImageGif; filename = "report.gif"; break;
case "excel": sf = StiExportFormat.Excel; filename = "report.xls"; break;
case "word2007": sf = StiExportFormat.Word2007; filename = "report.docx"; break;
}
}
public void SendEmail(string filetype, StiReport report, string fromaddress, string toaddress, string subject, string messageBody, string host, int port, string username, string password)
{
using (MemoryStream ms = new MemoryStream())
{
string filename = "";
StiExportFormat sef = StiExportFormat.Pdf;
GetFormat(filetype, ref sef, ref filename);
report.ExportDocument(sef, ms);
ms.Seek(, SeekOrigin.Begin);
//使用自己的邮件发送机制
System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(ms, filename);
MailMessage item = new MailMessage(fromaddress, toaddress);
item.Subject = subject;
item.Body = messageBody;
item.Attachments.Add(attachment);
SmtpClient smtp = new SmtpClient(host, port);
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential(username, password);
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(item);
ms.Close();
}
ClientScript.RegisterStartupScript(GetType(), "", "<script>showmessage();</script>");
}
protected void Button2_Click(object sender, EventArgs e)
{
applicationStart.isshowlogo = !applicationStart.isshowlogo;
ShowReport(applicationStart.isshowlogo);
}
}