You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/box/BoxReport2.aspx.cs

108 lines
3.3 KiB
C#

3 years ago
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 WebSqlHelper;
using System.IO;
namespace DSWeb.box
{
public partial class BoxReport2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
createdata();
}
}
protected void createdata()
{
grid.DataSource = retable();
grid.DataBind();
}
protected DataTable retable()
{
DataTable dt = new DataTable();
DataTable dt_b = BaseClass.db.GetSqlStrTable("select * from code_ctn");
dt.Columns.Add(new DataColumn("港口", typeof(string)));
foreach (DataRow dr in dt_b.Rows)
{
dt.Columns.Add(new DataColumn(dr["ctn"].ToString(), typeof(int)));
}
DataTable dt_vessel = BaseClass.db.GetSqlStrTable("select b.* from (select position from container_info group by position) a left join code_disport b on a.position=portid");
foreach (DataRow dr in dt_vessel.Rows)
{
DataRow drv = dt.NewRow();
drv["港口"] = dr["cname"].ToString();
foreach (DataRow dr1 in dt_b.Rows)
{
drv[dr1["ctn"].ToString()] = boxnum(dr["portid"].ToString(), dr1["ctn"].ToString());
}
dt.Rows.Add(drv);
}
//合计
DataRow drw = dt.NewRow();
drw["港口"] = "合计";
foreach (DataRow dr in dt_b.Rows)
{
drw[dr["ctn"].ToString()] = dt.Compute("sum([" + dr["ctn"].ToString() + "])", "");
}
dt.Rows.Add(drw);
return dt;
}
protected object boxnum(string portid,string ctn)
{
int i = 0;
try {
i = int.Parse(BaseClass.db.GetSqlStrScalar("select count(*) from container_info where position='" + portid + "' and Cntype='"+ctn+"'").ToString());
}
catch { }
if (i == 0)
return DBNull.Value;
else
return i;
}
protected void ibsave_Click(object sender, ImageClickEventArgs e)
{
createdata();
grid.Attributes.Add("style", "vnd.ms-excel.numberformat:@");
Response.ClearContent();
Response.Buffer = false;
Response.Charset = "GB2312";
Response.AddHeader("content-disposition", "attachment; filename=excel.xls");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.ContentType = "application/excel";
this.EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
grid.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
//base.VerifyRenderingInServerForm(control);
}
protected void btsearch_Click(object sender, EventArgs e)
{
createdata();
}
}
}