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.
D7QUANTAI/DSWeb/Shipping/DRReportGridSource.aspx.cs

649 lines
40 KiB
C#

10 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
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.Text;
using DSWeb.EntityDA;
using DSWeb.Models;
using System.Xml;
using System.Text.RegularExpressions;
namespace DSWeb.Shipping
{
public partial class DRReportGridSource : System.Web.UI.Page
{
private int iCurrentPage;
private int iShowPage;
private string strHandle;//值为"page"获取分页状态值数组 值为"list"获取日志显示JSON数据 值为"columns"获取日志显示记录 值为"rename"更新列标题
public string strUserID = "";//"04eaeac5-f271-45d1-b17b-ad4ccbab63d0";//用户GID
private string strType = "51";//Grid模块号
private string strOldHeader;
private string strNewHeader;
public string strgids = "";
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString().Trim();
}
else
{
Server.Transfer("~/Error/FriendError.aspx");
return;
//strUserID = "";
}
//
if (Request.QueryString["handle"] != null)
{
strHandle = Request.QueryString["handle"].ToString().Trim().ToLower();
}
if (Request.QueryString["cur_page"] != null)
{
iCurrentPage = int.Parse(Request.QueryString["cur_page"].ToString().Trim());
}
if (Request.QueryString["show_page"] != null)
{
iShowPage = int.Parse(Request.QueryString["show_page"].ToString().Trim());
}
//
ViewState["hid_sel"] = "";
if (Request.QueryString["hid_sel"] != null && Request.QueryString["hid_sel"].ToString().Trim() != "")
{
UnicodeEncoding unicode = new UnicodeEncoding();
ViewState["hid_sel"] = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["hid_sel"].ToString().Trim())));
}
//
string strJSON = "";
if (strHandle != null)
{
if (strHandle.Equals("list"))
{
if (iCurrentPage <= 0 && iShowPage < 0)
{
strJSON = "-2";//提交页数参数错误
}
}
if (strHandle.Trim().ToLower().Equals("setting"))
{
Response.Write(GetUserSettingJson());
}
if (strHandle.Trim().ToLower().Equals("page"))
{
Response.Write(GetPageInfo().ToString());
}
if (strHandle.Trim().ToLower().Equals("list"))
{
Response.Write(GetLogContent(iShowPage, iCurrentPage));
}
if (strHandle.Trim().ToLower().Equals("rename"))
{
if (Request.QueryString["old_header"] != null && Request.QueryString["new_header"] != null)
{
UnicodeEncoding unicode = new UnicodeEncoding();
strOldHeader = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["old_header"].ToString())));
strNewHeader = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["new_header"].ToString())));
Response.Write(UpdateColumnHeader(strOldHeader, strNewHeader));
}
else
{
Response.Write("-1");//GET 参数错误
}
}
if (strHandle.Trim().ToLower().Equals("excel"))
{
string sSQL = "";
if (ViewState["hid_sel"].ToString().Trim().IndexOf("and ACCDATE=") > -1 && ViewState["hid_sel"].ToString().Trim().IndexOf("and SALE=") > -1)
{
sSQL = "select bstype,customername,ACCDATE,SALE,getdate() as rqdate,hjRMB,hjRMBSS,hjRMBWS,hjRMBKP,hjUSD,hjUSDSS,hjUSDWS,hjUSDKP,hj,hjSS,hjWS,hjKP from (SELECT nid+ACCDATE+SALE as nid,bstype,customername,ACCDATE,SALE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,ACCDATE,SALE,CORPID,nid) as a "
+ " union all "
+ " select '总计:' as bstype,'','','',null,sum(isnull(hjRMB,0)) as hjRMB,sum(isnull(hjRMBSS,0)) as hjRMBSS,sum(isnull(hjRMBWS,0)) as hjRMBWS,sum(isnull(hjRMBKP,0)) as hjRMBKP,sum(isnull(hjUSD,0)) as hjUSD,sum(isnull(hjUSDSS,0)) as hjUSDSS,sum(isnull(hjUSDWS,0)) as hjUSDWS,sum(isnull(hjUSDKP,0)) as hjUSDKP,sum(isnull(hj,0)) as hj,sum(isnull(hjSS,0)) as hjSS,sum(isnull(hjWS,0)) as hjWS,sum(isnull(hjKP,0)) as hjKP from (SELECT nid+ACCDATE+SALE as nid,bstype,customername,ACCDATE,SALE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,ACCDATE,SALE,CORPID,nid) as b ORDER BY bstype,customername,ACCDATE,SALE ";
}
else if (ViewState["hid_sel"].ToString().Trim().IndexOf("and ACCDATE=") > -1 && ViewState["hid_sel"].ToString().Trim().IndexOf("and SALE=") <= -1)
{
sSQL = "select bstype,customername,ACCDATE,'' as SALE,getdate() as rqdate,hjRMB,hjRMBSS,hjRMBWS,hjRMBKP,hjUSD,hjUSDSS,hjUSDWS,hjUSDKP,hj,hjSS,hjWS,hjKP from (SELECT nid+ACCDATE as nid,bstype,customername,ACCDATE,'' as SALE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,ACCDATE,CORPID,nid) as a "
+ " union all "
+ " select '总计:' as bstype,'','','',null,sum(isnull(hjRMB,0)) as hjRMB,sum(isnull(hjRMBSS,0)) as hjRMBSS,sum(isnull(hjRMBWS,0)) as hjRMBWS,sum(isnull(hjRMBKP,0)) as hjRMBKP,sum(isnull(hjUSD,0)) as hjUSD,sum(isnull(hjUSDSS,0)) as hjUSDSS,sum(isnull(hjUSDWS,0)) as hjUSDWS,sum(isnull(hjUSDKP,0)) as hjUSDKP,sum(isnull(hj,0)) as hj,sum(isnull(hjSS,0)) as hjSS,sum(isnull(hjWS,0)) as hjWS,sum(isnull(hjKP,0)) as hjKP from (SELECT nid+ACCDATE as nid,bstype,customername,ACCDATE,'' as SALE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,ACCDATE,CORPID,nid) as b ORDER BY bstype,customername,ACCDATE ";
}
else if (ViewState["hid_sel"].ToString().Trim().IndexOf("and ACCDATE=") <= -1 && ViewState["hid_sel"].ToString().Trim().IndexOf("and SALE=") > -1)
{
sSQL = "select bstype,customername,'' as ACCDATE,SALE,getdate() as rqdate,hjRMB,hjRMBSS,hjRMBWS,hjRMBKP,hjUSD,hjUSDSS,hjUSDWS,hjUSDKP,hj,hjSS,hjWS,hjKP from (SELECT nid+SALE as nid,bstype,customername,'' as ACCDATE,SALE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,SALE,CORPID,nid) as a "
+ " union all "
+ " select '总计:' as bstype,'','','',null,sum(isnull(hjRMB,0)) as hjRMB,sum(isnull(hjRMBSS,0)) as hjRMBSS,sum(isnull(hjRMBWS,0)) as hjRMBWS,sum(isnull(hjRMBKP,0)) as hjRMBKP,sum(isnull(hjUSD,0)) as hjUSD,sum(isnull(hjUSDSS,0)) as hjUSDSS,sum(isnull(hjUSDWS,0)) as hjUSDWS,sum(isnull(hjUSDKP,0)) as hjUSDKP,sum(isnull(hj,0)) as hj,sum(isnull(hjSS,0)) as hjSS,sum(isnull(hjWS,0)) as hjWS,sum(isnull(hjKP,0)) as hjKP from (SELECT nid+SALE as nid,bstype,customername,'' as ACCDATE,SALE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,SALE,CORPID,nid) as b ORDER BY bstype,customername,SALE ";
}
else
{
sSQL = "select bstype,customername,'' as ACCDATE,'' as SALE,getdate() as rqdate,hjRMB,hjRMBSS,hjRMBWS,hjRMBKP,hjUSD,hjUSDSS,hjUSDWS,hjUSDKP,hj,hjSS,hjWS,hjKP from (SELECT nid as nid,bstype,customername,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,CORPID,nid) as a "
+" union all "
+ " select '总计:' as bstype,'','' as ACCDATE,'' as SALE,null,sum(isnull(hjRMB,0)) as hjRMB,sum(isnull(hjRMBSS,0)) as hjRMBSS,sum(isnull(hjRMBWS,0)) as hjRMBWS,sum(isnull(hjRMBKP,0)) as hjRMBKP,sum(isnull(hjUSD,0)) as hjUSD,sum(isnull(hjUSDSS,0)) as hjUSDSS,sum(isnull(hjUSDWS,0)) as hjUSDWS,sum(isnull(hjUSDKP,0)) as hjUSDKP,sum(isnull(hj,0)) as hj,sum(isnull(hjSS,0)) as hjSS,sum(isnull(hjWS,0)) as hjWS,sum(isnull(hjKP,0)) as hjKP from (SELECT nid as nid,bstype,customername,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,CORPID,nid) as b ORDER BY bstype,customername ";
}
Response.Write(sSQL);//GET 参数错误
}
else if (strHandle.Trim().ToLower().Equals("getsum"))
{
Response.Write(getsum());//GET 参数错误
}
}
else
{
strJSON = "-1";//GET 参数错误
}
}
protected string getsum()
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string ls = "";
if (ViewState["hid_sel"].ToString().Trim() != "")
{
string sSQL = "SELECT sum(hjRMB) hjRMB,sum(hjUSD) hjUSD,sum(hj) hj FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim();
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
ls += ds.Tables[0].Rows[0]["hjRMB"].ToString().Trim() + "" + ds.Tables[0].Rows[0]["hjUSD"].ToString().Trim() + "" + ds.Tables[0].Rows[0]["hj"].ToString().Trim();
}
}
}
return ls;
}
private int UpdateColumnHeader(string tempOldHeader, string tempNewHeader)
{
int iResult = 0;
UserSettingDA userSettingDA = new UserSettingDA();
UserSettingEntity userSettingEntity = userSettingDA.GetUserSettingByUserIDType(strUserID, strType);
GridEntity gridEntity = null;
if (userSettingEntity != null)
{
if (userSettingEntity.GID != null)
{
gridEntity = GetSettingXml(userSettingEntity.Xml);
foreach (GridColumnEntity column in gridEntity.Columns)
{
if (column.Description.Equals(tempOldHeader))
{
column.Description = tempNewHeader;
break;
}
}
userSettingEntity.Xml = GetUserSettingXml(gridEntity).OuterXml;
iResult = userSettingDA.UpdateUserSetting(userSettingEntity);
}
else
{
iResult = -3;//没有相关用户Grid设置记录
}
}
else
{
iResult = -3;//没有相关用户Grid设置记录
}
return iResult;
}
private string GetUserSettingJson()
{
UserSettingDA userSettingDA = new UserSettingDA();
UserSettingEntity userSettingEntity = userSettingDA.GetUserSettingByUserIDType(strUserID, strType);
GridEntity gridEntity = null;
StringBuilder settingBuilder = new StringBuilder();
if (userSettingEntity != null)
{
if (userSettingEntity.GID != null)
{
gridEntity = GetSettingXml(userSettingEntity.Xml);
settingBuilder.Append("{");
settingBuilder.Append("\"show\":" + gridEntity.PagePreCount + ",");
settingBuilder.Append("\"columns\":");
int i = 0;
StringBuilder columnGroupBuilder = new StringBuilder();
while (gridEntity.Columns.Count > i)
{
foreach (GridColumnEntity column in gridEntity.Columns)
{
if (column.Index == i)
{
StringBuilder columnBuilder = new StringBuilder();
columnBuilder.Append("{\"name\":\"" + column.Name + "\",");
columnBuilder.Append("\"description\":\"" + column.Description + "\",");
columnBuilder.Append("\"index\":" + column.Index.ToString() + ",");
columnBuilder.Append("\"width\":" + column.Width.ToString() + ",");
columnBuilder.Append("\"visible\":" + column.VisibleState.ToString());
columnGroupBuilder.Append(columnBuilder.ToString() + "},");
break;
}
}
i++;
}
string strGroup = columnGroupBuilder.ToString().Trim();
if (strGroup.EndsWith(","))
{
strGroup = strGroup.Substring(0, strGroup.Length - 1);
}
strGroup = "[" + strGroup + "]";
settingBuilder.Append(strGroup);
settingBuilder.Append("}");
}
else
{
settingBuilder.Append("-3");//没有相关用户Grid设置记录
}
}
else
{
settingBuilder.Append("-3");//没有相关用户Grid设置记录
}
return settingBuilder.ToString();
}
private GridEntity GetSettingXml(string strXml)
{
XmlDocument xmlSettingDoc = new XmlDocument();
GridEntity gridEntity = new GridEntity();
try
{
xmlSettingDoc.LoadXml(strXml);
gridEntity.GID = xmlSettingDoc.ChildNodes[0].ChildNodes[0].InnerText.Trim();
gridEntity.UserID = xmlSettingDoc.ChildNodes[0].ChildNodes[1].InnerText.Trim();
gridEntity.CreateTime = DateTime.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[2].InnerText.Trim());
IList<GridColumnEntity> columnsEntities = new List<GridColumnEntity>();
int iColCount = xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes.Count;
for (int i = 0; i < iColCount; i++)
{
GridColumnEntity columnEntity = new GridColumnEntity();
//columnEntity.GID = xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[0].ToString();
columnEntity.Name = xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[i].ChildNodes[0].InnerText.Trim();
columnEntity.Description = xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[i].ChildNodes[1].InnerText.Trim();
columnEntity.Index = int.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[i].ChildNodes[2].InnerText.Trim());
columnEntity.Width = int.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[3].ChildNodes[i].ChildNodes[3].InnerText.Trim());
columnsEntities.Add(columnEntity);
}
gridEntity.Columns = columnsEntities;
gridEntity.GroupBy = xmlSettingDoc.ChildNodes[0].ChildNodes[4].InnerText.Trim();
gridEntity.DefaultPrePageCount = int.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[5].ChildNodes[0].InnerText.Trim());
gridEntity.PagePreCount = int.Parse(xmlSettingDoc.ChildNodes[0].ChildNodes[5].ChildNodes[1].InnerText.Trim());
}
catch (Exception error)
{
throw (error);
}
return gridEntity;
}
private int GetPageInfo()
{
LogDA logDA = new LogDA();
StringBuilder logBuilder = new StringBuilder();
string strSql = "";
if (ViewState["hid_sel"].ToString().Trim() != "")
{
if (ViewState["hid_sel"].ToString().Trim().IndexOf("and ACCDATE=") > -1 && ViewState["hid_sel"].ToString().Trim().IndexOf("and SALE=") > -1)
{
strSql = "select COUNT(*) from (SELECT nid+ACCDATE+SALE as nid,bstype,customername,ACCDATE,SALE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,ACCDATE,SALE,CORPID,nid) as a";
}
else if (ViewState["hid_sel"].ToString().Trim().IndexOf("and ACCDATE=") > -1 && ViewState["hid_sel"].ToString().Trim().IndexOf("and SALE=") <= -1)
{
strSql = "select COUNT(*) from (SELECT nid+ACCDATE as nid,bstype,customername,ACCDATE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,ACCDATE,CORPID,nid) as a";
}
else if (ViewState["hid_sel"].ToString().Trim().IndexOf("and ACCDATE=") <= -1 && ViewState["hid_sel"].ToString().Trim().IndexOf("and SALE=") > -1)
{
strSql = "select COUNT(*) from (SELECT nid+SALE as nid,bstype,customername,SALE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,SALE,CORPID,nid) as a";
}
else
{
strSql = "select COUNT(*) from (SELECT nid as nid,bstype,customername,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,CORPID,nid) as a ";
}
}
else
{
strSql = "select COUNT(*) from VW_SUMDR where 1<0";
}
int iTotal = logDA.GetPageTotal(strSql);
return iTotal;
}
private string GetLogContent(int tempShowPage, int tempCurPage)
{
LogDA logDA = new LogDA();
StringBuilder logBuilder = new StringBuilder();
string strSql = "";
string strTopInclude = "";
string strTopNotInclude = "";
if (tempShowPage > 0 && tempCurPage > 0 && ViewState["hid_sel"].ToString().Trim() != "")
{
if (tempCurPage == 1)
{
if (ViewState["hid_sel"].ToString().Trim().IndexOf("and ACCDATE=") > -1 && ViewState["hid_sel"].ToString().Trim().IndexOf("and SALE=") > -1)
{
strSql = String.Format("select {0} nid,bstype,customername,ACCDATE,SALE,getdate() as rqdate,hjRMB,hjRMBSS,hjRMBWS,hjRMBKP,hjUSD,hjUSDSS,hjUSDWS,hjUSDKP,hj,hjSS,hjWS,hjKP from (SELECT nid+ACCDATE+SALE as nid,bstype,customername,ACCDATE,SALE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,ACCDATE,SALE,CORPID,nid) as a ORDER BY nid ", "top " + tempShowPage);
}
else if (ViewState["hid_sel"].ToString().Trim().IndexOf("and ACCDATE=") > -1 && ViewState["hid_sel"].ToString().Trim().IndexOf("and SALE=") <= -1)
{
strSql = String.Format("select {0} nid,bstype,customername,ACCDATE,'' as SALE,getdate() as rqdate,hjRMB,hjRMBSS,hjRMBWS,hjRMBKP,hjUSD,hjUSDSS,hjUSDWS,hjUSDKP,hj,hjSS,hjWS,hjKP from (SELECT nid+ACCDATE as nid,bstype,customername,ACCDATE,'' as SALE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,ACCDATE,CORPID,nid) as a ORDER BY nid ", "top " + tempShowPage);
}
else if (ViewState["hid_sel"].ToString().Trim().IndexOf("and ACCDATE=") <= -1 && ViewState["hid_sel"].ToString().Trim().IndexOf("and SALE=") > -1)
{
strSql = String.Format("select {0} nid,bstype,customername,'' as ACCDATE,SALE,getdate() as rqdate,hjRMB,hjRMBSS,hjRMBWS,hjRMBKP,hjUSD,hjUSDSS,hjUSDWS,hjUSDKP,hj,hjSS,hjWS,hjKP from (SELECT nid+SALE as nid,bstype,customername,'' as ACCDATE,SALE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,SALE,CORPID,nid) as a ORDER BY nid ", "top " + tempShowPage);
}
else
{
strSql = String.Format("select {0} nid,bstype,customername,'' as ACCDATE,'' as SALE,getdate() as rqdate,hjRMB,hjRMBSS,hjRMBWS,hjRMBKP,hjUSD,hjUSDSS,hjUSDWS,hjUSDKP,hj,hjSS,hjWS,hjKP from (SELECT nid as nid,bstype,customername,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,CORPID,nid) as a ORDER BY nid ", "top " + tempShowPage);
}
}
else
{
strTopNotInclude = "top " + (tempShowPage * (tempCurPage - 1));//RowCount*PageNum
strTopInclude = "top " + tempShowPage;//RowCount*PageNum
//strSql = String.Format("SELECT nid,bstype,customername,ACCDATE,getdate() as rqdate,hjRMB,hjRMBSS,hjRMBWS,hjRMBKP,hjUSD,hjUSDSS,hjUSDWS,hjUSDKP,hj,hjSS,hjWS,hjKP FROM (SELECT {1} * FROM VW_SUMDR WHERE NID NOT IN (SELECT {0} NID FROM VW_SUMDR where 1=1 " + ViewState["hid_sel"].ToString().Trim() + " ORDER BY customername,bstype) " + ViewState["hid_sel"].ToString().Trim() + " ORDER BY customername,bstype) AS A", strTopNotInclude, strTopInclude);
if (ViewState["hid_sel"].ToString().Trim().IndexOf("and ACCDATE=") > -1 && ViewState["hid_sel"].ToString().Trim().IndexOf("and SALE=") > -1)
{
strSql = String.Format("select nid,bstype,customername,ACCDATE,SALE,getdate() as rqdate,hjRMB,hjRMBSS,hjRMBWS,hjRMBKP,hjUSD,hjUSDSS,hjUSDWS,hjUSDKP,hj,hjSS,hjWS,hjKP from "
+ " (select {1} * from "
+ " (SELECT nid+ACCDATE+SALE as nid,bstype,customername,ACCDATE,SALE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP "
+ " FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,ACCDATE,SALE,CORPID,nid) as b "
+ " WHERE NID NOT IN (select {0} NID from (SELECT nid+ACCDATE+SALE as nid,bstype,customername,ACCDATE,SALE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,ACCDATE,SALE,CORPID,nid) as c ORDER BY nid ) "
+ " ORDER BY nid ) as a", strTopNotInclude, strTopInclude);
}
else if (ViewState["hid_sel"].ToString().Trim().IndexOf("and ACCDATE=") > -1 && ViewState["hid_sel"].ToString().Trim().IndexOf("and SALE=") <= -1)
{
strSql = String.Format("select nid,bstype,customername,ACCDATE,'' as SALE,getdate() as rqdate,hjRMB,hjRMBSS,hjRMBWS,hjRMBKP,hjUSD,hjUSDSS,hjUSDWS,hjUSDKP,hj,hjSS,hjWS,hjKP from "
+ " (select {1} * from "
+ " (SELECT nid+ACCDATE as nid,bstype,customername,ACCDATE,'' as SALE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP "
+ " FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,ACCDATE,CORPID,nid) as b "
+ " WHERE NID NOT IN (select {0} NID from (SELECT nid+ACCDATE as nid,bstype,customername,ACCDATE,'' as SALE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,ACCDATE,CORPID,nid) as c ORDER BY nid) "
+ " ORDER BY nid ) as a", strTopNotInclude, strTopInclude);
}
else if (ViewState["hid_sel"].ToString().Trim().IndexOf("and ACCDATE=") <= -1 && ViewState["hid_sel"].ToString().Trim().IndexOf("and SALE=") > -1)
{
strSql = String.Format("select nid,bstype,customername,'' as ACCDATE,SALE,getdate() as rqdate,hjRMB,hjRMBSS,hjRMBWS,hjRMBKP,hjUSD,hjUSDSS,hjUSDWS,hjUSDKP,hj,hjSS,hjWS,hjKP from "
+ " (select {1} * from "
+ " (SELECT nid+SALE as nid,bstype,customername,'' as ACCDATE,SALE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP "
+ " FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,SALE,CORPID,nid) as b "
+ " WHERE NID NOT IN (select {0} NID from (SELECT nid+SALE as nid,bstype,customername,'' as ACCDATE,SALE,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,SALE,CORPID,nid) as c ORDER BY nid ) "
+ " ORDER BY nid ) as a", strTopNotInclude, strTopInclude);
}
else
{
strSql = String.Format("select nid,bstype,customername,'' as ACCDATE,'' as SALE,getdate() as rqdate,hjRMB,hjRMBSS,hjRMBWS,hjRMBKP,hjUSD,hjUSDSS,hjUSDWS,hjUSDKP,hj,hjSS,hjWS,hjKP from "
+ " (select {1} * from "
+ " (SELECT nid,bstype,customername,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP "
+ " FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,CORPID,nid) as b "
+ " WHERE NID NOT IN (select {0} NID from (SELECT nid,bstype,customername,sum(hjRMB) as hjRMB,sum(hjRMBSS) as hjRMBSS,sum(hjRMBWS) as hjRMBWS,sum(hjRMBKP) as hjRMBKP,sum(hjUSD) as hjUSD,sum(hjUSDSS) as hjUSDSS,sum(hjUSDWS) as hjUSDWS,sum(hjUSDKP) as hjUSDKP,sum(hj) as hj,sum(hjSS) as hjSS,sum(hjWS) as hjWS,sum(hjKP) as hjKP FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " group by customername,bstype,CORPID,nid) as c ORDER BY nid ) "
+ " ORDER BY nid ) as a", strTopNotInclude, strTopInclude);
}
}
}
else
{
strSql = " SELECT nid,bstype,customername,ACCDATE,SALE,getdate() as rqdate,hjRMB,hjRMBSS,hjRMBWS,hjRMBKP,hjUSD,hjUSDSS,hjUSDWS,hjUSDKP,hj,hjSS,hjWS,hjKP FROM VW_SUMDR WHERE 1<0 ";
}
DataTable logTable = GetSqlDataIndex(logDA.GetExcuteSql(strSql).Tables[0]);
logBuilder.Append("{");
logBuilder.Append("rows:[");
for (int i = 0; i < logTable.Rows.Count; i++)
{
logBuilder.Append("{id:\"" + logTable.Rows[i][0].ToString() + "\",");
logBuilder.Append("data:[");
//logBuilder.Append("\"0\",");
for (int j = 1; j < logTable.Columns.Count; j++)
{
if (j == logTable.Columns.Count - 1)
{
logBuilder.Append("\"" + logTable.Rows[i][j].ToString() + "\"");
}
else
{
logBuilder.Append("\"" + logTable.Rows[i][j].ToString() + "\",");
}
}
if (i == logTable.Rows.Count - 1)
{
logBuilder.Append("]}");
}
else
{
logBuilder.Append("]},");
}
}
logBuilder.Append("]");
logBuilder.Append("}");
return logBuilder.ToString();
}
private string GetSeaExPKGSInfoBusinessListGridSource()
{
//GetLogGridSource
LogDA logDA = new LogDA();
StringBuilder logBuilder = new StringBuilder();
StringBuilder userdateBuilder = new StringBuilder();
StringBuilder dataBuilder = new StringBuilder();
string strSql = String.Format("SELECT COUNT(*) FROM VW_SUMDR WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim());
DataTable logTable = logDA.GetExcuteSql(strSql).Tables[0];
logBuilder.Append("{");
logBuilder.Append("rows:[");
for (int i = 0; i < logTable.Rows.Count; i++)
{
logBuilder.Append("{id:\"" + logTable.Rows[i][0].ToString() + "\",");
userdateBuilder.Append("userdata:{");
dataBuilder.Append("data:[");
for (int j = 1; j < logTable.Columns.Count; j++)
{
if (j == logTable.Columns.Count - 1)
{
userdateBuilder.Append("\"" + logTable.Columns[j].ColumnName + "\":\"" + logTable.Rows[i][j].ToString() + "\"");
dataBuilder.Append("\"" + logTable.Rows[i][j].ToString() + "\"");
}
else
{
userdateBuilder.Append("\"" + logTable.Columns[j].ColumnName + "\":\"" + logTable.Rows[i][j].ToString() + "\",");
dataBuilder.Append("\"" + logTable.Rows[i][j].ToString() + "\",");
}
}
userdateBuilder.Append("}");
dataBuilder.Append("]");
logBuilder.Append(userdateBuilder.ToString() + ",");
logBuilder.Append(dataBuilder);
if (i == logTable.Rows.Count - 1)
{
logBuilder.Append("}");
}
else
{
logBuilder.Append("},");
}
}
logBuilder.Append("]");
logBuilder.Append("}");
return logBuilder.ToString();
//return logBuilder.ToString();
}
private DataTable GetSqlDataIndex(DataTable tempTable)
{
UserSettingDA userSettingDA = new UserSettingDA();
UserSettingEntity userSettingEntity = userSettingDA.GetUserSettingByUserIDType(strUserID, strType);
GridEntity gridEntity = null;
StringBuilder settingBuilder = new StringBuilder();
DataTable dataTable = new DataTable();
if (userSettingEntity != null)
{
if (userSettingEntity.GID != null)
{
gridEntity = GetSettingXml(userSettingEntity.Xml);
int i = 0;
StringBuilder columnGroupBuilder = new StringBuilder();
dataTable.Columns.Add(tempTable.Columns[0].ColumnName, tempTable.Columns[0].DataType);
for (int k = 0; k < tempTable.Rows.Count; k++)
{
DataRow newRow = dataTable.NewRow();
newRow[tempTable.Columns[0].ColumnName] = tempTable.Rows[k][tempTable.Columns[0].ColumnName].ToString();
dataTable.Rows.Add(newRow);
}
while (gridEntity.Columns.Count > i)
{
foreach (GridColumnEntity column in gridEntity.Columns)
{
if (column.Index == i)
{
for (int j = 1; j < tempTable.Columns.Count; j++)
{
if (tempTable.Columns[j].ColumnName.Equals(column.Name))
{
dataTable.Columns.Add(tempTable.Columns[j].ColumnName, tempTable.Columns[j].DataType);
for (int k = 0; k < tempTable.Rows.Count; k++)
{
dataTable.Rows[k][tempTable.Columns[j].ColumnName] = tempTable.Rows[k][tempTable.Columns[j].ColumnName].ToString();
}
break;
}
}
break;
}
}
i++;
}
}
else
{
return tempTable;
}
}
else
{
return tempTable;
}
return dataTable;
}
private XmlDocument GetUserSettingXml(GridEntity gridEntity)
{
XmlDocument xmlDoc = new XmlDocument();
XmlElement root = xmlDoc.CreateElement("user-settings");
//xmlDoc.AppendChild(root);
XmlElement xGID = xmlDoc.CreateElement("GID");
xGID.InnerText = gridEntity.GID;
root.AppendChild(xGID);
XmlElement xUserID = xmlDoc.CreateElement("userid");
xUserID.InnerText = gridEntity.UserID;
root.AppendChild(xUserID);
XmlElement xCreateTime = xmlDoc.CreateElement("create-time");
xCreateTime.InnerText = gridEntity.CreateTime.ToString();
root.AppendChild(xCreateTime);
XmlElement xColumns = xmlDoc.CreateElement("columns");
foreach (GridColumnEntity column in gridEntity.Columns)
{
XmlElement xColumn = xmlDoc.CreateElement("column");
XmlElement nName = xmlDoc.CreateElement("name");
nName.InnerText = column.Name;
xColumn.AppendChild(nName);
XmlElement nDescription = xmlDoc.CreateElement("description");
nDescription.InnerText = column.Description;
xColumn.AppendChild(nDescription);
XmlElement nIndex = xmlDoc.CreateElement("index");
nIndex.InnerText = column.Index.ToString();
xColumn.AppendChild(nIndex);
XmlElement nWidth = xmlDoc.CreateElement("width");
nWidth.InnerText = column.Width.ToString();
xColumn.AppendChild(nWidth);
XmlElement nVisible = xmlDoc.CreateElement("visible");
nVisible.InnerText = column.VisibleState.ToString();
xColumn.AppendChild(nVisible);
xColumns.AppendChild(xColumn);
}
root.AppendChild(xColumns);
XmlElement xGroupBy = xmlDoc.CreateElement("group-by");
xGroupBy.InnerText = gridEntity.GroupBy;
root.AppendChild(xGroupBy);
XmlElement xPage = xmlDoc.CreateElement("page");
XmlElement nPageDefault = xmlDoc.CreateElement("page-default");
nPageDefault.InnerText = gridEntity.DefaultPrePageCount.ToString();
xPage.AppendChild(nPageDefault);
XmlElement nPagePre = xmlDoc.CreateElement("page-pre");
nPagePre.InnerText = gridEntity.PagePreCount.ToString();
xPage.AppendChild(nPagePre);
root.AppendChild(xPage);
xmlDoc.AppendChild(root);
return xmlDoc;
}
}
}