|
[code=csharp]using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
using LogisticsSystem.BLL;
namespace LogisticsSystem.Web.UI.Invoice
{
public partial class OutputInvoiceManage : System.Web.UI.Page
{
protected Button btnSearch;
protected Button Button1;
protected CalendarExtender Calendarextender1;
protected CalendarExtender Calendarextender3;
protected HyperLink HyperLink1;
protected ObjectDataSource ObjectDataSource1;
private void BindData()
{
this.gvItemFlow.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSearch_Click(object sender, EventArgs e)
{
gvItemFlow.DataBind();
}
public string BindhFlowState(object flowStates)
{
string flowState = string.Empty;
switch (flowStates.ToString())
{
case "-2": flowState = "待审核"; break;
case "-1": flowState = "退回修改"; break;
case "0": flowState = "申请开票"; break;
case "1": flowState = "已开票"; break;
case "2": flowState = "已收费"; break;
case "3": flowState = "完成"; break;
}
return flowState;
}
public string BindhAuditFlowName(object flowStates)
{
return new BLL.AuditFlowManage().GetAuditFlowByAuditFlowID(Convert.ToInt32(flowStates.ToString())).ReportNumber;
}
public string BindhItemFlowName(object flowStates)
{
return new BLL.ItemFlowManage().GetItemFlowByID(Convert.ToInt32(flowStates.ToString())).FlowNumber;
}
public string BindhCompanyName(object companyID)
{
string companyName = string.Empty;
//switch (flowStates.ToString())
//{
// case "0": flowState = "未分配"; break;
// case "1": flowState = "已分配"; break;
// case "2": flowState = "实施中"; break;
// case "3": flowState = "完成"; break;
//}
CompanyManage cp = new CompanyManage();
companyName = cp.GetCompanyNameByCompanyID(Convert.ToInt32(companyID));
return companyName;
}
protected void Button2_Click(object sender, EventArgs e)
{
InvoiceManage ivnm = new InvoiceManage();
CompanyManage cpm = new CompanyManage();
UserManage usm = new UserManage();
AuditFlowManage afm = new AuditFlowManage();
List<Invoice> list = ivnm.GetOutSelectInvoice(this.ddlOfficeTpye.Text, this.txtCompanyName.Text, this.ddlState.SelectedValue, this.txttime1.Text, this.txttime2.Text);
HttpContext.Current.Response.Clear();
StringWriter sw = new StringWriter();
int iColCount = list.Count;
sw.Write("发票号码,开票时间,开票抬头,开票内容,金额,部门,作业人,来源人,注师");
sw.Write(",事务所,审计单位,发票种类,发票状态,备注");
sw.Write(sw.NewLine);
for (int i = 0; i < iColCount; i++)
{
Invoice inv = list;
sw.Write(string.Concat(new object[] { inv.IntendExpend.Replace(",", "、"), ",", inv.BeginTime.ToLongDateString(), ",", inv.InvoiceName, ",", inv.InvoiceContent.Replace(",", "、"), ",", inv.InvoiceSumCost, ",", usm.GetUserByUserID(inv.UserID.ToString()).Department, ",", usm.GetUserByUserID(inv.UserID.ToString()).UserName, ",", cpm.GetOneCompany(inv.CompanyID.ToString()).Source.Replace(",", "、") }));
if (inv.AuditFlowID > 0)
{
sw.Write("," + afm.GetAuditFlowByAuditFlowID(inv.AuditFlowID).SignatureName.Replace(",", "、"));
}
else
{
sw.Write(",");
}
sw.Write("," + inv.OfficeTpye + "," + cpm.GetCompanyNameByCompanyID(inv.CompanyID) + "," + ((inv.InvoiceType == 1) ? "专用发票" : "普通发票") + "," + this.BindhFlowState(inv.State) + "," + inv.Remark.Replace(",", "、"));
sw.Write(sw.NewLine);
}
sw.Close();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + this.txttime1.Text + "~" + this.txttime2.Text + ".csv");
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding("GB2312");
HttpContext.Current.Response.Write(sw);
HttpContext.Current.Response.End();
}
public void ExExcel<T>(List<T> objList, string FileName, Dictionary<string, string> columnInfo)
{
if ((columnInfo.Count != 0) && (objList.Count != 0))
{
string excelStr = "";
Type myType = objList[0].GetType();
List<PropertyInfo> myPro = new List<PropertyInfo>();
foreach (string cName in columnInfo.Keys)
{
PropertyInfo p = myType.GetProperty(cName);
if (p != null)
{
myPro.Add(p);
excelStr = excelStr + columnInfo[cName] + "\t";
}
}
if (myPro.Count != 0)
{
excelStr = excelStr + "\n";
foreach (T obj in objList)
{
foreach (PropertyInfo p in myPro)
{
excelStr = excelStr + p.GetValue(obj, null) + "\t";
}
excelStr = excelStr + "\n";
}
HttpResponse rs = HttpContext.Current.Response;
rs.ContentEncoding = Encoding.GetEncoding("GB2312");
rs.AppendHeader("Content-Disposition", "attachment;filename=" + FileName);
rs.ContentType = "application/ms-excel";
rs.Write(excelStr);
rs.End();
}
}
}
protected void gvItemFlow_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.gvItemFlow.PageIndex = e.NewPageIndex;
this.BindData();
}
protected void Page_Load(object sender, EventArgs e)
{
}
public void ToExcel(Control ctl)
{
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=Excel.xls");
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = Encoding.Default;
HttpContext.Current.Response.ContentType = "application/ms-excel";
ctl.Page.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
ctl.RenderControl(hw);
HttpContext.Current.Response.Write(tw.ToString());
HttpContext.Current.Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}
private string ConnectionString
{
get
{
return "Server=localhost;Database=Northwind;\r\n Trusted_Connection=true";
}
}
}
}[/code]
错误提示:错误 “LogisticsSystem.Web.UI.Invoice”是“命名空间”,但此处被当做“类型”来使用
|
|