using System; using System.Collections; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using DSWeb.EntityDA; using DSWeb.Models; using JsonHelper; using System.Xml; using System.IO; using System.Text; namespace DSWeb.Shipping { public partial class OwefeeModuleReport : System.Web.UI.Page { T_ALL_DA T_ALL_DA = new T_ALL_DA(); //grid public string strUserID;//用户GID public string strCompanyID;//公司GID public string strShowName;//用户显示名 public string strDeptName;//部门名称 //gridEnd protected void Page_Load(object sender, EventArgs e) { Session["USERID"] = "b775e6db-fa3b-40a2-8e38-a59b03125881"; Session["SHOWNAME"] = "邵林媛"; Session["COMPANYID"] = "Comcab2d43f60454327af30a131fc1d3abd"; Session["DEPTNAME"] = ""; if (Session["USERID"] != null) { strUserID = Session["USERID"].ToString().Trim(); this.hdUserID.Value = Session["USERID"].ToString().Trim(); } else { Server.Transfer("~/Error/FriendError.aspx"); return; } if (Session["SHOWNAME"] != null) { strShowName = Session["SHOWNAME"].ToString(); } if (Session["COMPANYID"] != null) { strCompanyID = Session["COMPANYID"].ToString(); } if (Session["DEPTNAME"] != null) { strDeptName = Session["DEPTNAME"].ToString(); } //grid if (!IsPostBack) { string sSQL = "select * from [code_owefee_module] order by [MODULENAME]"; DataSet ds = T_ALL_DA.GetAllSQL(sSQL); if (ds != null) { ddlMODULETYPE.Items.Clear(); foreach (DataTable myTable in ds.Tables) { foreach (DataRow myRow in myTable.Rows)//遍历表 { ddlMODULETYPE.Items.Add(new ListItem(myRow["MODULENAME"].ToString().Trim(), myRow["GID"].ToString().Trim())); } } } // LoadGridView(); } //gridEnd } /// /// 加载gridview信息 /// /// public void LoadGridView() { T_ALL_DA T_ALL_DA = new T_ALL_DA(); string sSQL = "select * from VW_OP_SEA_ALL where 1=1 " + this.hid_sel.Value.Trim() + " order by MODULENAME"; DataSet ds = T_ALL_DA.GetAllSQL(sSQL); if (ds != null) { ddlBSTYPE.DataSource = ds.Tables[0]; ddlBSTYPE.DataBind(); } else { ddlBSTYPE.DataSource = null; ddlBSTYPE.DataBind(); } } protected void ibSelect_Click(object sender, EventArgs e) { if (this.hid_sel.Value.Trim() != "") { string strFIELDS = ""; string strFIELDNAME = ""; // T_ALL_DA T_ALL_DA = new T_ALL_DA(); string sSQL = "select GID,LINKGID,FIELDS,FIELDNAME,ISFEEFIELD from code_owefee_module_detail where 1=1 and LINKGID='" + ddlMODULETYPE.SelectedValue.ToString().Trim() + "'"; DataSet ds = T_ALL_DA.GetAllSQL(sSQL); if (ds != null) { for (int i=0; i < ds.Tables[0].Rows.Count; i++) { if (ds.Tables[0].Rows[i]["ISFEEFIELD"].ToString().Trim() == "0") { strFIELDS += "," + ds.Tables[0].Rows[i]["FIELDS"].ToString().Trim(); strFIELDNAME += "," + ds.Tables[0].Rows[i]["FIELDS"].ToString().Trim() + " as " + ds.Tables[0].Rows[i]["FIELDNAME"].ToString().Trim(); } else { strFIELDS += "," + ds.Tables[0].Rows[i]["FIELDS"].ToString().Trim(); } } } // sSQL = "select * from VW_OP_SEA_ALL_FEE where 1=1 " + this.hid_sel.Value.Trim() + " order by customername"; ds = T_ALL_DA.GetAllSQL(sSQL); if (ds != null) { GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); } else { GridView1.DataSource = null; GridView1.DataBind(); } // LoadGridView(); } } protected void ibExcel_Click(object sender, EventArgs e) { //setExcelReport(); setExcelReport2(); } protected void setExcelReport2() { if (this.hdSQL.Value.Trim() != "") { T_ALL_DA T_ALL_DA = new T_ALL_DA(); DataSet DS = T_ALL_DA.GetAllSQL(this.hdSQL.Value.Trim()); if (DS != null) { ExcelDA ExcelDA = new EntityDA.ExcelDA(); MemoryStream ms = ExcelDA.RenderToExcel(DS.Tables[0], this.hdNAMES.Value.Trim()); ExcelDA.RenderToBrowser(ms, Context, "report.xls"); } } } protected void setExcelReport() { StringWriter sw = new StringWriter(); string sSQL = ""; //sw.WriteLine("结算单位\t委托编号\t主提单号\t分提单号\t船名\t航次\tETD\t目的港\t揽货人\t应收RMB\t实收RMB\t应收USD\t实收USD\t余额"); sw.WriteLine(this.hdNAMES.Value.Trim()); T_ALL_DA T_ALL_DA = new T_ALL_DA(); DataSet DS = T_ALL_DA.GetAllSQL(this.hdSQL.Value.Trim()); if (DS != null) { foreach (DataTable myTable in DS.Tables) { foreach (DataRow myRow in myTable.Rows)//遍历表 { sSQL = ""; for (int i = 0; i < myTable.Columns.Count; i++) { if (sSQL.Trim() != "") sSQL += "\t"; if (myRow[i].ToString() == null || myRow[i].ToString() == "") { sSQL += ""; if (sSQL.Trim() == "") { sSQL += "\t"; } } else { sSQL += myRow[i].ToString().Trim(); } } sw.WriteLine(sSQL); } } // sw.Close(); switch ("MUEXCEL") { case "MUEXCEL": Response.AddHeader("Content-Disposition", "attachment; filename=report.xls"); Response.ContentType = "application/ms-excel"; break; case "MUTEXT": Response.AddHeader("Content-Disposition", "attachment; filename=report.txt"); Response.ContentType = "application/txt"; break; case "MUWORD": Response.AddHeader("Content-Disposition", "attachment; filename=report.doc"); Response.ContentType = "application/ms-word"; break; case "MUPDF": Response.AddHeader("Content-Disposition", "attachment; filename=report.pdf"); Response.ContentType = "application/pdf"; break; case "MUXML": Response.AddHeader("Content-Disposition", "attachment; filename=report.xml"); Response.ContentType = "application/xml"; break; } Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); Response.Write(sw); Response.End(); } } // } }