CeramicProject/newyt/Common/khqk_dy.aspx.cs

176 lines
8.5 KiB
C#

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 Ajax;
public partial class Common_khqk_dy : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = DBHlper.Execute(returntj()).Tables[0];
//DataTable newtable = dt.Select("qk>0").CopyToDataTable();
DataTable newtable = new DataTable();
DataRow[] dtrow = null;
string jefwtj = getqkfw();
if (dt.Rows.Count > 0)
{
dtrow = dt.Select(jefwtj);
if (dtrow.Length > 0)
{
newtable = dtrow.CopyToDataTable();
}
else
{
newtable = null;
}
rep_ddlr.DataSource = newtable;
}
else
{
rep_ddlr.DataSource = dt;
}
//rep_ddlr.DataSource = newtable;
rep_ddlr.DataBind();
heji();
}
Utility.RegisterTypeForAjax(typeof(Common_khqk_dy));
}
//合计
protected void heji()
{
string tj = returntj();
string jefwtj = getqkfw();
DataTable dtdata = DBHlper.Execute(tj).Tables[0];
DataTable newtable = new DataTable();
DataRow[] dtrow = null;
if (dtdata.Rows.Count > 0)
{
dtrow = dtdata.Select(jefwtj);
if (dtrow.Length > 0)
{
newtable = dtrow.CopyToDataTable();
}
else
{
newtable = null;
}
}
else
{
newtable = dtdata;
}
decimal ddze = 0;
decimal skje = 0;
decimal qk = 0;
decimal qcqk = 0;
decimal mzze = 0;
if (newtable != null)
{
foreach (DataRow dr in newtable.Rows)
{
ddze += Convert.ToDecimal(dr["ddze"]);
skje += Convert.ToDecimal(dr["skje"]);
qk += Convert.ToDecimal(dr["qk"]);
qcqk += Convert.ToDecimal(dr["csqk"]);
mzze = Convert.ToDecimal(dr["mzje"]);
}
hz_ddze.InnerText = ddze.ToString();
hz_skze.InnerText = skje.ToString();
hz_qk.InnerText = qk.ToString();
hz_qcqk.InnerText = qcqk.ToString();
hz_mz.InnerText = mzze.ToString();
}
else
{
hz_ddze.InnerText = "0";
hz_skze.InnerText = "0";
hz_qk.InnerText = "0";
hz_qcqk.InnerText = "0";
hz_mz.InnerText = "0";
}
}
protected string returntj()
{
string bgtime =Request["bgtime"];
string edtime = Request["edtime"];
string txt_tj = Request["content"];
if (edtime != "")
{
string[] timezu = edtime.Split('-');
if (Convert.ToInt32(timezu[2]) < 31)
{
edtime = Convert.ToDateTime(edtime).AddDays(1).ToString("yyyy-MM-dd");
}
}
string tj = "";
if (bgtime != "" && edtime != "")
{
tj = "select mingcheng as khmc,ISNULL(csqk,0) as csqk,(select ISNULL(SUM(zje),0) as ddze from view_nr_z_dd as dd where dd.kh_bh =kh.bianhao and zt='1' and xdrq between '" + bgtime + "' and '" + edtime + "' ) as ddze,"
+ "(select ISNULL(SUM(skje),0) as skje from view_z_dd_skjl as sk where sk.kh_bh =kh.bianhao and sk.kh_bh"
+ "=kh.bianhao and zt='已确认' and skrq between '" + bgtime + "' and '" + edtime + "' ) as skje,"
+ "(select ISNULL(SUM(mzje),0) as mzje from view_z_dd_skjl as sk where sk.kh_bh =kh.bianhao and sk.kh_bh=kh.bianhao and zt='已确认' and skrq between '" + bgtime + "' and '" + edtime + "' ) as mzje,"
+ "((select ISNULL(SUM(zje),0) from view_nr_z_dd as dd where dd.kh_bh =kh.bianhao and zt='1' and xdrq between '" + bgtime + "' and '" + edtime + "' )+ISNULL(csqk,0)-((select ISNULL(SUM(skje),0) as skje from view_z_dd_skjl as sk where sk.kh_bh =kh.bianhao and sk.kh_bh =kh.bianhao and zt='已确认' and skrq between '" + bgtime + "' and '" + edtime + "' )+(select ISNULL(SUM(mzje),0) as mzje from view_z_dd_skjl as sk where sk.kh_bh =kh.bianhao and sk.kh_bh=kh.bianhao and zt='已确认' and skrq between '" + bgtime + "' and '" + edtime + "' ))) as qk "
+ " from nr_z_kehu as kh";
}
else if (bgtime != "" && edtime == "")
{
tj = "select mingcheng as khmc,ISNULL(csqk,0) as csqk,(select ISNULL(SUM(zje),0) as ddze from view_nr_z_dd as dd where dd.kh_bh =kh.bianhao and zt='1' and xdrq>='" + bgtime + "' ) as ddze,"
+ "(select ISNULL(SUM(skje),0) as skje from view_z_dd_skjl as sk where sk.kh_bh =kh.bianhao and sk.kh_bh"
+ "=kh.bianhao and zt='已确认' and skrq >='" + bgtime + "') as skje,"
+ "(select ISNULL(SUM(mzje),0) as mzje from view_z_dd_skjl as sk where sk.kh_bh =kh.bianhao and sk.kh_bh=kh.bianhao and zt='已确认' and skrq>='" + bgtime + "') as mzje,"
+ "((select ISNULL(SUM(zje),0) from view_nr_z_dd as dd where dd.kh_bh =kh.bianhao and zt='1' and xdrq>='" + bgtime + "' )+ISNULL(csqk,0)-((select ISNULL(SUM(skje),0) as skje from view_z_dd_skjl as sk where sk.kh_bh =kh.bianhao and sk.kh_bh =kh.bianhao and zt='已确认' and skrq >='" + bgtime + "')+(select ISNULL(SUM(mzje),0) as mzje from view_z_dd_skjl as sk where sk.kh_bh =kh.bianhao and sk.kh_bh=kh.bianhao and zt='已确认' and skrq >='" + bgtime + "'))) as qk "
+ " from nr_z_kehu as kh";
}
else if (bgtime == "" && edtime != "")
{
tj = "select mingcheng as khmc,ISNULL(csqk,0) as csqk,(select ISNULL(SUM(zje),0) as ddze from view_nr_z_dd as dd where dd.kh_bh =kh.bianhao and zt='1' and xdrq<='" + edtime + "' ) as ddze,"
+ "(select ISNULL(SUM(skje),0) as skje from view_z_dd_skjl as sk where sk.kh_bh =kh.bianhao and sk.kh_bh"
+ "=kh.bianhao and zt='已确认' and skrq <='" + edtime + "') as skje,"
+ "(select ISNULL(SUM(mzje),0) as mzje from view_z_dd_skjl as sk where sk.kh_bh =kh.bianhao and sk.kh_bh=kh.bianhao and zt='已确认' skrq<='" + edtime + "') as mzje,"
+ "((select ISNULL(SUM(zje),0) from view_nr_z_dd as dd where dd.kh_bh =kh.bianhao and zt='1' and xdrq <='" + edtime + "' )+ISNULL(csqk,0)-((select ISNULL(SUM(skje),0) as skje from view_z_dd_skjl as sk where sk.kh_bh =kh.bianhao and sk.kh_bh =kh.bianhao and zt='已确认' and skrq <='" + edtime + "')+(select ISNULL(SUM(mzje),0) as mzje from view_z_dd_skjl as sk where sk.kh_bh =kh.bianhao and sk.kh_bh=kh.bianhao and zt='已确认' and skrq <='" + edtime + "'))) as qk "
+ " from nr_z_kehu as kh";
}
else if (bgtime == "" && edtime == "")
{
tj = "select mingcheng as khmc,ISNULL(csqk,0) as csqk,(select ISNULL(SUM(zje),0) as ddze from view_nr_z_dd as dd where dd.kh_bh =kh.bianhao and zt='1' ) as ddze,"
+ "(select ISNULL(SUM(skje),0) as skje from view_z_dd_skjl as sk where sk.kh_bh =kh.bianhao and sk.kh_bh"
+ "=kh.bianhao and zt='已确认') as skje,"
+ "(select ISNULL(SUM(mzje),0) as mzje from view_z_dd_skjl as sk where sk.kh_bh =kh.bianhao and sk.kh_bh=kh.bianhao and zt='已确认') as mzje,"
+ "((select ISNULL(SUM(zje),0) from view_nr_z_dd as dd where dd.kh_bh =kh.bianhao and zt='1' )+ISNULL(csqk,0)-((select ISNULL(SUM(skje),0) as skje from view_z_dd_skjl as sk where sk.kh_bh =kh.bianhao and sk.kh_bh =kh.bianhao and zt='已确认')+(select ISNULL(SUM(mzje),0) as mzje from view_z_dd_skjl as sk where sk.kh_bh =kh.bianhao and sk.kh_bh=kh.bianhao and zt='已确认'))) as qk "
+ " from nr_z_kehu as kh";
}
if (tj == "")
{
tj = " 1=1 ";
}
tj += " where kh.mingcheng like '%" + txt_tj + "%'";
return tj;
}
//获取欠款条件
protected string getqkfw()
{
string tj = "qk>0 ";
string minval = Request["minval"];
string maxval = Request["maxval"];
if (minval != "" && maxval == "")
{
tj += "and qk>=" + minval;
}
else if (minval == "" && maxval != "")
{
tj += "and qk<=" + maxval;
}
else if (minval != "" && maxval != "")
{
tj += "and qk<=" + maxval + " and qk>=" + minval;
}
return tj;
}
}