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.
HENGCHENG/DSWeb/Shipping/ProfitReportGridSource.aspx.cs

782 lines
40 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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;
using DSWeb.DataAccess;
namespace DSWeb.Shipping
{
public partial class ProfitReportGridSource : System.Web.UI.Page
{
private int iCurrentPage;
private int iShowPage;
private string strHandle;//值为"page"获取分页状态值数组 值为"list"获取日志显示JSON数据 值为"columns"获取日志显示记录 值为"rename"更新列标题
private string strType = "17";//Grid模块号
private string strOldHeader;
private string strNewHeader;
private string hidsel = "";
public string strBSTYPE;
public string strFEETYPE;
public string strCntr;
public string RangeViewID = "";//用户可视权限代码
public string strRangeViewSQL = "";
RangeDA rangeDA = new RangeDA();
UnicodeEncoding unicode = new UnicodeEncoding();
public string strUserID;//用户GID
private string strShowName;//用户登录名
private string strCompanyID;//分公司GID
private string strDeptName;//部门名称
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString().Trim();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
//
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());
}
//
if (Request.QueryString["RangeViewId"] != null)
{
RangeViewID = Request.QueryString["RangeViewId"].ToString().Trim();
if (RangeViewID == "0")//用户可视权限--全部
{
strRangeViewSQL = " ";
}
else if (RangeViewID == "1")//--分公司
{
strRangeViewSQL = rangeDA.ProfitReportViewPartCompany(strCompanyID);
}
else if (RangeViewID == "2")//--部门
{
strRangeViewSQL = rangeDA.ProfitReportViewDept(strCompanyID, strUserID);
}
else if (RangeViewID == "3")//--个人
{
strRangeViewSQL = rangeDA.ProfitReportViewPerson(strCompanyID, strUserID);
}
else
{
strRangeViewSQL = "";//4
}
}
//
ViewState["hid_sel"] = "";
if (Request.QueryString["tbNO"] != null && Request.QueryString["tbNO"] !="")
{
ViewState["hid_sel"] += " and (CUSTNO like '%" + Request.QueryString["tbNO"].ToString().Trim() + "%' or MBLNO like '%" + Request.QueryString["tbNO"].ToString().Trim() + "%' or HBLNO like '%" + Request.QueryString["tbNO"].ToString().Trim() + "%')";// or ORDERNO like '%" + Request.QueryString["tbNO"].ToString().Trim() + "%'";
}
if (Request.QueryString["ddlCUSTOMERNAME"] != null && Request.QueryString["ddlCUSTOMERNAME"] != "")
{
string strCUSTOMERNAME = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["ddlCUSTOMERNAME"].ToString().Trim())));
ViewState["hid_sel"] += " and CUSTOMERNAME like '%" + strCUSTOMERNAME.Trim() + "%'";
}
if (Request.QueryString["ddlSALE"] != null && Request.QueryString["ddlSALE"] != "")
{
string strSALE = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["ddlSALE"].ToString().Trim())));
ViewState["hid_sel"] += " and SALE='" + strSALE.Trim() + "'";
}
if (Request.QueryString["ddlVESSEL"] != null && Request.QueryString["ddlVESSEL"] != "")
{
string strVESSEL = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["ddlVESSEL"].ToString().Trim())));
ViewState["hid_sel"] += " and VESSEL='" + strVESSEL.Trim() + "'";
}
if (Request.QueryString["ddlVOYNO"] != null && Request.QueryString["ddlVOYNO"] != "")
{
string strVOYNO = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["ddlVOYNO"].ToString().Trim())));
ViewState["hid_sel"] += " and VOYNO='" + strVOYNO.Trim() + "'";
}
if (Request.QueryString["tbETD"] != null && Request.QueryString["tbETD"] != "")
{
ViewState["hid_sel"] += " and convert(char(10),ETD,20)>='" + Request.QueryString["tbETD"].ToString().Trim() + "'";
}
if (Request.QueryString["tbETD2"] != null && Request.QueryString["tbETD2"] != "")
{
ViewState["hid_sel"] += " and convert(char(10),ETD,20)<='" + Request.QueryString["tbETD2"].ToString().Trim() + "'";
}
if (Request.QueryString["tbACCDATE"] != null && Request.QueryString["tbACCDATE"] != "")
{
ViewState["hid_sel"] += " and ACCDATE='" + Request.QueryString["tbACCDATE"].ToString().Trim() + "'";
}
if (Request.QueryString["subcompany"] != null && Request.QueryString["subcompany"] != "")
{
ViewState["hid_sel"] += " and CORPID in (select gid from [company] where NAME='" + unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["subcompany"].ToString().Trim()))) + "')";
}
if (Request.QueryString["goodname"] != null && Request.QueryString["goodname"] != "")
{
string strgoodname = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["goodname"].ToString().Trim())));
ViewState["hid_sel"] += " and GOODSNAME like '%" + strgoodname.Trim() + "%'";
}
if (Request.QueryString["tradetype"] != null && Request.QueryString["tradetype"] != "")
{
string strtradetype = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["tradetype"].ToString().Trim())));
ViewState["hid_sel"] += " and tradetype='" + strtradetype.Trim() + "'";
}
if (Request.QueryString["ddlBSTYPE"] != null && Request.QueryString["ddlBSTYPE"] != "")
{
strBSTYPE = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["ddlBSTYPE"].ToString().Trim())));
if (strBSTYPE.Trim() != "all")
{
ViewState["hid_sel"] += " and bstypename='" + strBSTYPE + "'";
}
}
if (Request.QueryString["ddlFEETYPE"] != null && Request.QueryString["ddlFEETYPE"] != "")
{
strFEETYPE = Request.QueryString["ddlFEETYPE"].ToString().Trim();
ViewState["hid_sel"] += " and FEESTATUS='" + strFEETYPE + "'";
}
if (Request.QueryString["ddlBSSTATUS"] != null && Request.QueryString["ddlBSSTATUS"] != "")
{
strFEETYPE = Request.QueryString["ddlBSSTATUS"].ToString().Trim();
ViewState["hid_sel"] += " and BSSTATUS='" + strFEETYPE + "'";
}
if (Request.QueryString["bssource"] != null && Request.QueryString["bssource"] != "")
{
string strBssource = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["bssource"].ToString().Trim())));
ViewState["hid_sel"] += " and bssource='" + strBssource + "'";
}
if (Request.QueryString["gids"] != null && Request.QueryString["gids"] != "")
{
string strGIDS = Request.QueryString["gids"].ToString().Trim();
ViewState["hid_sel"] += " and bsno in (" + strGIDS + ")";
}
//
if (Request.QueryString["hidsel"] != null && Request.QueryString["hidsel"] != "")
{
hidsel = Request.QueryString["hidsel"].ToString().Trim();
}
if (Request.QueryString["cntr"] != null)
{
strCntr = Request.QueryString["cntr"].ToString();
}
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 = "";
//sSQL = "SELECT CUSTOMERNAME,MBLNO,CONTRACTNO,CUSTNO,HBLNO,VESSEL,VOYNO,ETD,PORTDISCHARGE,SALE,RMBDR,USDDR,RMBCR,USDCR,DRTTL,CRTTL,RMBPROFIT,USDPROFIT FROM VW_PROFIT where 1=1 " + ViewState["hid_sel"].ToString().Trim() + " order by CUSTOMERNAME";
//sSQL = "SELECT CUSTOMERNAME,MBLNO,CONTRACTNO,CUSTNO,HBLNO,VESSEL,VOYNO,ETD,PORTDISCHARGE,SALE,RMBDR,USDDR,RMBCR,USDCR,DRTTL,CRTTL,RMBPROFIT,USDPROFIT FROM VW_PROFIT where 1=1 " + ViewState["hid_sel"].ToString().Trim() + " order by CUSTOMERNAME";
//sSQL = "SELECT CUSTOMERNAME,MBLNO,CONTRACTNO,CUSTNO,HBLNO,VESSEL,VOYNO,ETD,PORTDISCHARGE,SALE,RMBDR,USDDR,RMBCR,USDCR,DRTTL,CRTTL,RMBPROFIT,USDPROFIT,PROFITRATE,CNTRTOTAL,TEU,OTCNTR" + strCntr + " FROM VW_PROFIT where 1=1 " + ViewState["hid_sel"].ToString().Trim() + " order by CUSTOMERNAME";
if (hidsel.Trim() != "")
{
sSQL = " SELECT bstypename,(case BSSTATUS when 0 then '未锁定' else '锁定' end) as BSSTATUS,(case FEESTATUS when 0 then '未锁定' else '锁定' end) as FEESTATUS,ACCDATE,CUSTOMERNAME,MBLNO,CONTRACTNO,CUSTNO,HBLNO,BSSOURCE,TRADETYPE, GOODSNAME,CARRIER,VESSEL,VOYNO,LANE,FORWARDER,ETD,DEPTNAME,OP,SALE,isnull(NETWEIGHT,0) as NETWEIGHT,isnull(KGS,0) as KGS,isnull(TEU,0) as TEU,CNTRTOTAL,isnull(RMBDR,0) as RMBDR,isnull(USDDR,0) as USDDR,isnull(RMBCR,0) as RMBCR,isnull(USDCR,0) as USDCR,isnull(DRTTL,0) as DRTTL,isnull(CRTTL,0) as CRTTL,isnull(RMBPROFIT,0) as RMBPROFIT,isnull(USDPROFIT,0) as USDPROFIT,isnull(TTLPROFIT,0) as TTLPROFIT,isnull(PROFITRATE,0) as PROFITRATE"
+ " FROM VW_PROFIT "
+ " WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " " + strRangeViewSQL
+ " union all "
+ " SELECT '总计:' as bstypename,'','','','','','','','','','', '','','','','','','','','','',sum(isnull(NETWEIGHT,0)) as NETWEIGHT,sum(isnull(KGS,0)) as KGS,sum(isnull(TEU,0)) as TEU,'',sum(isnull(RMBDR,0)) as RMBDR,sum(isnull(USDDR,0)) as USDDR,sum(isnull(RMBCR,0)) as RMBCR,sum(isnull(USDCR,0)) as USDCR,sum(isnull(DRTTL,0)) as DRTTL,sum(isnull(CRTTL,0)) as CRTTL,sum(isnull(RMBPROFIT,0)) as RMBPROFIT,sum(isnull(USDPROFIT,0)) as USDPROFIT,sum(isnull(TTLPROFIT,0)) as TTLPROFIT"
//+ ",convert(varchar(20),convert(decimal(18,2),(case when ((isnull(sum(TTLPROFIT),0)=0) or (isnull(sum(DRTTL),0)=0)) then 0 else (isnull(sum(TTLPROFIT),0)/isnull(sum(DRTTL),0)*100) end)))+'%' as PROFITRATE "//利润
+ ",convert(varchar(20),convert(decimal(18,2),(case when ((isnull(sum(TTLPROFIT),0)=0) or (isnull(sum(CRTTL),0)=0)) then 0 else (isnull(sum(TTLPROFIT),0)/isnull(sum(CRTTL),4)*100) end)))+'%' as PROFITRATE "//利润
+ " FROM VW_PROFIT "
+ " WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " " + strRangeViewSQL + " order by bstypename,CUSTOMERNAME,ETD DESC ";
}
Response.Write(sSQL);//GET 参数错误
}
if (strHandle.Trim().ToLower().Equals("excel2"))
{
string sSQL2 = "";
if (hidsel.Trim() != "")
{
// sSQL2 = " SELECT SELE,MBLNO,A.* FROM CH_FEE A,VW_PROFIT B WHERE BSNO IN (SELECT BSNO FROM VW_PROFIT WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + ") ";
sSQL2 = " SELECT C.MBLNO ,C.SALE,(case A.FEESTATUS when 0 then '审核通过' when 1 then '录入状态' when 2 then '提交审核' when 3 then '申请修改' when 4 then '申请删除 ' when 5 then '取消申请' when 6 then '驳回提交' when 7 then '驳回申请' when 8 then '部分结算' else '结算完毕' end) as FEESTATUS , A.FEENAME, A.CUSTOMERNAME, A.UNIT, A.UNITPRICE, A.QUANTITY,A.AMOUNT, A.CURRENCY, "
+ "A.EXCHANGERATE,A.FEEFRT,A.REMARK, (case A.ISADVANCEDPAY when 'True' then '是' else '否' end)as ISADVANCEDPAY,ISNULL(A.SETTLEMENT,0),ISNULL(A.INVOICE,0),ISNULL(A.INVOICENUM,''),B.SHOWNAME,A.ENTERDATE "
+ "FROM ch_fee as A LEFT JOIN [user] as B ON A.ENTEROPERATOR = B.GID inner join VW_PROFIT C ON A.BSNO=C.BSNO WHERE (A.FEETYPE = 1 or A.FEETYPE=2) AND A.BSNO IN (SELECT BSNO FROM VW_PROFIT WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim()+" "+strRangeViewSQL + ") "
+ "AND ENTEROPERATOR IN (SELECT USERID FROM user_company WHERE COMPANYID='" + strCompanyID + "') AND (FEETYPE=1 or FEETYPE=2) ORDER BY SALE,MBLNO,FEETYPE,LINENUM ";
}
Response.Write(sSQL2);
}
else if (strHandle.Trim().ToLower().Equals("getsum"))
{
Response.Write(getsum());//GET 参数错误
}
}
else
{
strJSON = "-1";//GET 参数错误
}
}
protected string getsum()
{
string ls = "";
if (hidsel.Trim() != "")
{
string sSQL = "SELECT isnull(sum(RMBDR),0) as RMBDR"
+ ",isnull(sum(USDDR),0) as USDDR"
+ ",isnull(sum(RMBCR),0) as RMBCR"
+ ",isnull(sum(USDCR),0) as USDCR"
+ ",isnull(sum(DRTTL),0) as DRTTL"
+ ",isnull(sum(CRTTL),0) as CRTTL"
+ ",isnull(sum(RMBPROFIT),0) as RMBPROFIT"
+ ",isnull(sum(USDPROFIT),0) as USDPROFIT"
+ ",isnull(sum(TTLPROFIT),0) as TTLPROFIT"
//+ ",(case when ((isnull(sum(TTLPROFIT),0)=0) or (isnull(sum(DRTTL),0)=0)) then 0 else (isnull(sum(TTLPROFIT),0)/isnull(sum(DRTTL),0)*100) end) as PROFITRATE"//例如率=利润/收入*100
+ ",(case when ((isnull(sum(TTLPROFIT),0)=0) or (isnull(sum(DRTTL),0)=0)) then 0 else (isnull(sum(TTLPROFIT),0)/isnull(sum(CRTTL),4)*100) end) as PROFITRATE"//例如率=利润/收入*100
+ " FROM VW_PROFIT WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim()+" "+strRangeViewSQL;
//
LogDA logDA = new LogDA();
DataTable logTable = GetSqlDataIndex(logDA.GetExcuteSql(sSQL).Tables[0]);
ls = logTable.Rows[0]["RMBDR"].ToString().Trim();//应收RMB
ls += "" + logTable.Rows[0]["RMBCR"].ToString().Trim();//应付RMB
ls += "" + logTable.Rows[0]["DRTTL"].ToString().Trim();//应收合计
ls += "" + logTable.Rows[0]["RMBPROFIT"].ToString().Trim();//RMB利润
ls += "" + logTable.Rows[0]["TTLPROFIT"].ToString().Trim();//本位币利润合计
ls += "" + logTable.Rows[0]["USDDR"].ToString().Trim();//应收USD
ls += "" + logTable.Rows[0]["USDCR"].ToString().Trim();//应付USD
ls += "" + logTable.Rows[0]["CRTTL"].ToString().Trim();//应付合计
ls += "" + logTable.Rows[0]["USDPROFIT"].ToString().Trim();//USD利润
ls += "" + logTable.Rows[0]["PROFITRATE"].ToString().Trim();//利润率
ls += "";
//
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
sSQL = "select sum(TEU) as TEU,CTNALL,sum(CTNNUM) as CTNNUM from op_ctn where BSNO in (SELECT BSNO FROM VW_PROFIT WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim()+" "+strRangeViewSQL + ") group by CTNALL order by CTNALL";
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
string strCNTRTOTAL = "";
foreach (DataTable myTable in ds.Tables)
{
foreach (DataRow myRow in myTable.Rows)//遍历表
{
strCNTRTOTAL += myRow["CTNALL"].ToString().Trim() + "*" + myRow["CTNNUM"].ToString().Trim() + " / ";
}
}
ls += strCNTRTOTAL.Trim().Substring(0, strCNTRTOTAL.Trim().Length - 1);
}
}
//
sSQL = "select isnull(sum(TEU),0) as TEU from op_ctn where BSNO in (SELECT BSNO FROM VW_PROFIT WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() +" "+strRangeViewSQL+ ")";
ds = T_ALL_DA.GetAllSQL(sSQL);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
ls += "&nbsp;&nbsp;&nbsp;&nbsp;TEU" + ds.Tables[0].Rows[0]["TEU"].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 = "SELECT COUNT(*) FROM VW_PROFIT WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " " + strRangeViewSQL;
if (hidsel.Trim() == "")
{
strSql = "SELECT COUNT(*) FROM VW_PROFIT WHERE 1<0 ";//如果页数为空或者页数为0不返回数据
}
//
int iTotal = 0;
if (strSql.Trim() != "")
{
iTotal = logDA.GetPageTotal(strSql);
}
return iTotal;
}
/// <summary>
/// 获取列表信息
/// </summary>
/// <param name="tempShowPage"></param>
/// <param name="tempCurPage"></param>
/// <returns></returns>
private string GetLogContent(int tempShowPage, int tempCurPage)
{
LogDA logDA = new LogDA();
StringBuilder logBuilder = new StringBuilder();
string strSql = "";
string strTopInclude = "";
string strTopNotInclude = "";
if (hidsel.Trim() == "")
{
strSql = "SELECT BSNO,bstypename,(case BSSTATUS when 0 then '未锁定' else '锁定' end) as BSSTATUS,(case FEESTATUS when 0 then '未锁定' else '锁定' end) as FEESTATUS,ACCDATE,CUSTOMERNAME,MBLNO,CONTRACTNO,CUSTNO,HBLNO,BSSOURCE,TRADETYPE, GOODSNAME,CARRIER,VESSEL,VOYNO,LANE,FORWARDER,ETD,DEPTNAME,OP,SALE,NETWEIGHT,KGS,TEU,CNTRTOTAL,RMBDR,USDDR,RMBCR,USDCR,DRTTL,CRTTL,RMBPROFIT,USDPROFIT,TTLPROFIT,PROFITRATE "//" + (strCntr.Trim() == "" ? "" : strCntr) + " ,OTCNTR
+ " FROM VW_PROFIT WHERE 1<0 ";//如果页数为空或者页数为0不返回数据
}
else
{
if (tempShowPage > 0 && tempCurPage > 0)
{
if (tempCurPage == 1)
{
strSql = String.Format(" SELECT {0} BSNO,bstypename,(case BSSTATUS when 0 then '未锁定' else '锁定' end) as BSSTATUS,(case FEESTATUS when 0 then '未锁定' else '锁定' end) as FEESTATUS,ACCDATE,CUSTOMERNAME,MBLNO,CONTRACTNO,CUSTNO,HBLNO,BSSOURCE,TRADETYPE, GOODSNAME,CARRIER,VESSEL,VOYNO,LANE,FORWARDER,ETD,DEPTNAME,OP,SALE,NETWEIGHT,KGS,TEU,CNTRTOTAL,RMBDR,USDDR,RMBCR,USDCR,DRTTL,CRTTL,RMBPROFIT,USDPROFIT,TTLPROFIT,PROFITRATE "//" + (strCntr.Trim() == "" ? "" : strCntr) + " ,OTCNTR
+ " FROM VW_PROFIT "
+ " WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " " + strRangeViewSQL.Trim() + " order by bstypename,CUSTOMERNAME,ETD DESC,BSNO ", "top " + tempShowPage);
}
else
{
strTopNotInclude = "top " + (tempShowPage * (tempCurPage - 1));//RowCount*PageNum
strTopInclude = "top " + tempShowPage;//RowCount*PageNum
strSql = String.Format(" SELECT {1} BSNO,bstypename,(case BSSTATUS when 0 then '未锁定' else '锁定' end) as BSSTATUS,(case FEESTATUS when 0 then '未锁定' else '锁定' end) as FEESTATUS,ACCDATE,CUSTOMERNAME,MBLNO,CONTRACTNO,CUSTNO,HBLNO,BSSOURCE,TRADETYPE, GOODSNAME,CARRIER,VESSEL,VOYNO,LANE,FORWARDER,ETD,DEPTNAME,OP,SALE,NETWEIGHT,KGS,TEU,CNTRTOTAL,RMBDR,USDDR,RMBCR,USDCR,DRTTL,CRTTL,RMBPROFIT,USDPROFIT,TTLPROFIT,PROFITRATE "//" + (strCntr.Trim() == "" ? "" : strCntr) + " ,OTCNTR
+ " FROM VW_PROFIT "
+ " WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " " + strRangeViewSQL.Trim() + " AND BSNO NOT IN (SELECT {0} BSNO FROM VW_PROFIT WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " " + strRangeViewSQL.Trim() + " order by bstypename,CUSTOMERNAME,ETD DESC,BSNO ) order by bstypename,CUSTOMERNAME,ETD DESC,BSNO ", strTopNotInclude, strTopInclude);
}
}
else
{
strSql = "SELECT BSNO,bstypename,(case BSSTATUS when 0 then '未锁定' else '锁定' end) as BSSTATUS,(case FEESTATUS when 0 then '未锁定' else '锁定' end) as FEESTATUS,ACCDATE,CUSTOMERNAME,MBLNO,CONTRACTNO,CUSTNO,HBLNO,BSSOURCE,TRADETYPE, GOODSNAME,CARRIER,VESSEL,VOYNO,LANE,FORWARDER,ETD,DEPTNAME,OP,SALE,NETWEIGHT,KGS,TEU,CNTRTOTAL,RMBDR,USDDR,RMBCR,USDCR,DRTTL,CRTTL,RMBPROFIT,USDPROFIT,TTLPROFIT,PROFITRATE "//" + (strCntr.Trim() == "" ? "" : strCntr) + " ,OTCNTR
+ " FROM VW_PROFIT WHERE 1<0 ";//如果页数为空或者页数为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 GetSeaExportInfoBusinessGridSource()
{
//GetLogGridSource
LogDA logDA = new LogDA();
StringBuilder logBuilder = new StringBuilder();
StringBuilder userdateBuilder = new StringBuilder();
StringBuilder dataBuilder = new StringBuilder();
string strSql = "SELECT COUNT(*) FROM VW_PROFIT where 1=1 " + ViewState["strSel"].ToString().Trim()+" "+strRangeViewSQL;
if (hidsel.Trim() == "")
{
strSql = "SELECT COUNT(*) FROM VW_PROFIT where 1<0";
}
//
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();
}
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++)
{
if (tempTable.Columns[j].DataType.ToString().Trim().Equals("System.DateTime") && tempTable.Rows[k][tempTable.Columns[j].ColumnName].ToString().Trim().Equals(""))
{
//日期如果为空,就不赋值
//string ddd = tempTable.Rows[k][tempTable.Columns[j].ColumnName].ToString();
//dataTable.Rows[k][tempTable.Columns[j].ColumnName] = tempTable.Rows[k][tempTable.Columns[j].ColumnName].ToString();
}
else
{
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;
}
}
}