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/CRM/SaleProfitReportGridSource....

825 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.CRM
{
public partial class SaleProfitReportGridSource : System.Web.UI.Page
{
private int iCurrentPage;
private int iShowPage;
private int iType;
private string strField;
private string strHandle;//值为"page"获取分页状态值数组 值为"list"获取日志显示JSON数据 值为"columns"获取日志显示记录 值为"rename"更新列标题
public string strUserID = "";//用户GID
public string strCompanyID;//公司GID
public string strShowName;//用户显示名
public string strDeptName;//部门名称
private string strType = "17";//Grid模块号
private string strOldHeader;
private string strNewHeader;
private string hidsel = "";
public string strBSTYPE;
public string strFEETYPE;
public string strCntr;//部门名称
UnicodeEncoding unicode = new UnicodeEncoding();
public string strRange = String.Empty;//权限可视范围
RangeDA RangeDA = new RangeDA();
T_ALL_DA T_ALL_DA = new T_ALL_DA();
string strCrmCsDataName = System.Configuration.ConfigurationSettings.AppSettings["crmCsDataName"].ToString();
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 (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].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["field"] != null)
{
strField = Request.QueryString["field"].ToString().Trim().ToLower();
}
if (Request.QueryString["type"] != null)
{
iType = int.Parse(Request.QueryString["type"].ToString().Trim().ToLower());
}
//
ViewState["hid_sel"] = "";
if (Request.QueryString["tbNO"] != null && Request.QueryString["tbNO"] !="")
{
ViewState["hid_sel"] += " and (业务编号 like '%" + Request.QueryString["tbNO"].ToString().Trim() + "%' or 主提单号 like '%" + Request.QueryString["tbNO"].ToString().Trim() + "%' or 分提单号 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 委托单位='" + strCUSTOMERNAME.Trim() + "'";
}
if (Request.QueryString["ddlSALE"] != null && Request.QueryString["ddlSALE"] != "")
{
string strSALE = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["ddlSALE"].ToString().Trim())));
string strSALECODE = T_ALL_DA.GetStrSQL("codename", "select top 1 codename from [user] where showname='" + strSALE.Trim() + "'");
ViewState["hid_sel"] += " and (揽货人='" + strSALE.Trim() + "' or 揽货人='" + strSALECODE.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 船名='" + 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 航次='" + strVOYNO.Trim() + "'";
}
if (Request.QueryString["tbETD"] != null && Request.QueryString["tbETD"] != "")
{
ViewState["hid_sel"] += " and convert(char(10),开船日期,20)>='" + Request.QueryString["tbETD"].ToString().Trim() + "'";
}
if (Request.QueryString["tbETD2"] != null && Request.QueryString["tbETD2"] != "")
{
ViewState["hid_sel"] += " and convert(char(10),开船日期,20)<='" + Request.QueryString["tbETD2"].ToString().Trim() + "'";
}
if (Request.QueryString["subcompany"] != null && Request.QueryString["subcompany"] != "")
{
ViewState["hid_sel"] += " and 分部名称 ='" + 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 商品名称='" + strgoodname.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 业务类型='" + strBSTYPE + "'";
}
}
//
DateTime dt = DateTime.Parse(T_ALL_DA.GetStrSQL("sdate", "select convert(char(10),getdate(),20) as sdate"));
int iday = dt.Day;
DateTime startMonth = dt.AddDays(1 - dt.Day); //本月月初
DateTime startMonth_sy = startMonth.AddMonths(-1); //上月月初
DateTime endMonth = startMonth.AddMonths(1).AddDays(-1); //本月月末
if (iday >= 4)
{
ViewState["hid_sel"] += " and convert(char(10),开船日期,20)>='" + startMonth.ToString("yyyy-MM-dd") + "' and convert(char(10),开船日期,20)<='" + endMonth.ToString("yyyy-MM-dd") + "'";
}
else
{
ViewState["hid_sel"] += " and convert(char(10),开船日期,20)>='" + startMonth_sy.ToString("yyyy-MM-dd") + "' and convert(char(10),开船日期,20)<='" + endMonth.ToString("yyyy-MM-dd") + "'";
}
//
ViewState["hid_sel"] += " and (isnull(应收RMB,0)<>0 or isnull(应收USD,0)<>0 or isnull(应付RMB,0)<>0 or isnull(应付USD,0)<>0 or isnull(合计应收,0)<>0 or isnull(合计应付,0)<>0 or isnull(利润RMB,0)<>0 or isnull(利润USD,0)<>0 or isnull(毛利润,0)<>0)";
//
if (Request.QueryString["hidsel"] != null && Request.QueryString["hidsel"] != "")
{
hidsel = Request.QueryString["hidsel"].ToString().Trim();
}
if (Request.QueryString["cntr"] != null)
{
strCntr = Request.QueryString["cntr"].ToString();
}
//
//权限可视范围
strRange = RangeDA.GetVISIBLERANGE(strUserID.Trim(), "modSaleProfitReport");//销售业绩查询列表范围
if (strRange.Trim().Equals("0"))//全部
{
strRange = "";
}
else if (strRange.Trim().Equals("1"))//分公司
{
strRange = " and 揽货人 in(" + RangeDA.GetSaleProfitReportCompany(strCompanyID, strShowName) + ")";
}
else if (strRange.Trim().Equals("2"))//部门
{
strRange = " and 揽货人 in(" + RangeDA.GetSaleProfitReportDEPT(strCompanyID, strDeptName, strShowName) + ")";
}
else if (strRange.Trim().Equals("3"))//个人
{
strRange = " and 揽货人 in(" + RangeDA.GetSaleProfitReportPerson(strCompanyID, strShowName) + ")";
}
else if (strRange.Trim().Equals("4"))//无
{
strRange = " and 1<0";
}
else//空
{
strRange = " and 1<0";
}
ViewState["hid_sel"] += strRange;
//
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)
{
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 (hidsel.Trim() != "")
{
sSQL = " SELECT 业务类型,委托单位,业务编号,主提单号,分提单号,业务来源,商品名称,船公司,船名,航次,航线,convert(char(10),开船日期,20) as 业务日期,操作部门,操作员,揽货人,isnull(净重,0) as 净重,isnull(重量,0) as 重量,isnull(箱TEU,0) as 箱TEU,集装箱,isnull(应收RMB,0) as 应收RMB,isnull(应收USD,0) as 应收USD,isnull(应付RMB,0) as 应付RMB,isnull(应付USD,0) as 应付USD,isnull(合计应收,0) as 合计应收,isnull(合计应付,0) as 合计应付,isnull(利润RMB,0) as 利润RMB,isnull(利润USD,0) as 利润USD,isnull(毛利润,0) as 毛利润,isnull(利润率,0) as 利润率 "
+ " FROM [" + strCrmCsDataName + "].[dbo].[v_op_bscard] "
+ " WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim()
+ " union all "
+ " SELECT '总计:' as 业务类型,'','','','','','','','','','',null,'','','',sum(isnull(净重,0)) as 净重,sum(isnull(重量,0)) as 重量,sum(isnull(箱TEU,0)) as 箱TEU,'',sum(isnull(应收RMB,0)) as 应收RMB,sum(isnull(应收USD,0)) as 应收USD,sum(isnull(应付RMB,0)) as 应付RMB,sum(isnull(应付USD,0)) as 应付USD,sum(isnull(合计应收,0)) as 合计应收,sum(isnull(合计应付,0)) as 合计应付,sum(isnull(利润RMB,0)) as 利润RMB,sum(isnull(利润USD,0)) as 利润USD,sum(isnull(毛利润,0)) as 毛利润"
+ ",convert(varchar(20),convert(decimal(18,2),(case when ((isnull(sum(毛利润),0)=0) or (isnull(sum(合计应收),0)=0)) then 0 else (isnull(sum(毛利润),0)/isnull(sum(合计应收),0)*100) end)))+'%' as 利润率 "//利润
+ " FROM [" + strCrmCsDataName + "].[dbo].[v_op_bscard] "
+ " WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " order by 业务类型,委托单位,业务日期 DESC ";
}
Response.Write(sSQL);//GET 参数错误
}
else if (strHandle.Trim().ToLower().Equals("getsum"))
{
Response.Write(getsum());//GET 参数错误
}
else if (strHandle.Trim().ToLower().Equals("load"))
{
XmlDocument docs = GetDoc();
Response.ContentType = "text/xml";
Response.Write(docs.OuterXml.ToString());
}
}
else
{
strJSON = "-1";//GET 参数错误
}
}
/// <summary>
/// 根据视图内容加载下拉框内容
/// </summary>
/// <returns></returns>
public string BuildXML()
{
StringBuilder resultBuilder = new StringBuilder();
resultBuilder.Append("<?xml version=\"1.0\" ?>");
resultBuilder.AppendFormat("<complete{0}>", string.Empty);
string js = "";
if (iType == 2)
{
string[] items = strField.Trim().Split(new string[] { "" }, StringSplitOptions.RemoveEmptyEntries);
DataSet ds = T_ALL_DA.GetAllSQL("SELECT " + items[0].ToString().Trim() + "," + items[1].ToString().Trim() + " FROM [" + strCrmCsDataName + "].[dbo].[" + items[2].ToString().Trim() + "] order by " + items[1].ToString().Trim());
if (ds != null)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (dr[items[1].ToString().Trim()].ToString().Trim() != "")
{
js = dr[items[0].ToString().Trim()].ToString().Trim() + " | " + dr[items[1].ToString().Trim()].ToString().Trim();
resultBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", dr[items[0].ToString().Trim()].ToString().Trim(), js);
}
}
}
}
else
{
DataSet ds = T_ALL_DA.GetAllSQL("SELECT " + strField + " FROM [" + strCrmCsDataName + "].[dbo].[v_op_bscard] group by " + strField + " order by " + strField);
if (ds != null)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (dr[strField].ToString().Trim() != "")
{
resultBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", dr[strField].ToString().Trim(), dr[strField].ToString().Trim());
}
}
}
}
resultBuilder.AppendFormat("<option value=\"{0}\">{1}</option>", "", "");
resultBuilder.Append("</complete>");
return resultBuilder.ToString().Replace("&", "&amp;");
}
public XmlDocument GetDoc()
{
XmlDocument xmldoc = new XmlDocument();
string content = BuildXML();
try
{
xmldoc.LoadXml(content);
}
catch (Exception)
{
}
return xmldoc;
}
protected string getsum()
{
string ls = "";
if (hidsel.Trim() != "")
{
string sSQL = "SELECT sum(isnull(应收RMB,0)) as 应收RMB"
+ ",sum(isnull(应收USD,0)) as 应收USD"
+ ",sum(isnull(应付RMB,0)) as 应付RMB"
+ ",sum(isnull(应付USD,0)) as 应付USD"
+ ",sum(isnull(合计应收,0)) as 合计应收"
+ ",sum(isnull(合计应付,0)) as 合计应付"
+ ",sum(isnull(利润RMB,0)) as 利润RMB"
+ ",sum(isnull(利润USD,0)) as 利润USD"
+ ",sum(isnull(毛利润,0)) as 毛利润"
+ ",convert(varchar(20),convert(decimal(18,2),(case when ((isnull(sum(毛利润),0)=0) or (isnull(sum(合计应收),0)=0)) then 0 else (isnull(sum(毛利润),0)/isnull(sum(合计应收),0)*100) end)))+'%' as 利润率"//例如率=利润/收入*100
+ " FROM [" + strCrmCsDataName + "].[dbo].[v_op_bscard] WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim();
//
LogDA logDA = new LogDA();
DataTable logTable = GetSqlDataIndex(logDA.GetExcuteSql(sSQL).Tables[0]);
ls = logTable.Rows[0]["应收RMB"].ToString().Trim();//应收RMB
ls += "" + logTable.Rows[0]["应付RMB"].ToString().Trim();//应付RMB
ls += "" + logTable.Rows[0]["合计应收"].ToString().Trim();//应收合计
ls += "" + logTable.Rows[0]["利润RMB"].ToString().Trim();//RMB利润
ls += "" + logTable.Rows[0]["毛利润"].ToString().Trim();//本位币利润合计
ls += "" + logTable.Rows[0]["应收USD"].ToString().Trim();//应收USD
ls += "" + logTable.Rows[0]["应付USD"].ToString().Trim();//应付USD
ls += "" + logTable.Rows[0]["合计应付"].ToString().Trim();//应付合计
ls += "" + logTable.Rows[0]["利润USD"].ToString().Trim();//USD利润
ls += "" + logTable.Rows[0]["利润率"].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 [" + strCrmCsDataName + "].[dbo].[v_op_bscard] WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim();
if (hidsel.Trim() == "")
{
strSql = "SELECT COUNT(*) FROM [" + strCrmCsDataName + "].[dbo].[v_op_bscard] 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() == "")
{
//业务类型", "业务状态", "费用状态", "委托单位", "委托编号", "主提单号", "分提单号", "业务来源", "贸易方式", "品名", "船公司", "船名", "航次", "航线", "订舱公司", "业务日期", "部门", "操作", "销售", "净重", "重量", "TEU", "集装箱", "应收RMB", "应收USD", "应付RMB", "应付USD"
//, "应收合计", "应付合计"
//, "RMB利润", "USD利润"
//, "本位币利润合计", "利润率"); //, "其他箱型"
//编号, 主编号, 业务来源, 来源明细, 业务状态, 业务类型, 业务编号, 会计期间, 费用状态, 业务种类, 分部名称,
//主提单号, 分提单号, 委托单位, 报关操作, 报检操作, 发票号, 周次, 委托编号, 船公司, 货代公司, 报关行, 船名,
//航次, 开船日期, 装货港, 装货港 AS 起运港, 航线, 销售部门, 揽货人, 操作部门, 通关日期, 核销单号, 报关单号, 报检单号,
//经营单位, 是否退税, 操作员, 客服员, 录入人, 录入日期, 装运方式, 卸货港, 目的地, 付费方式, 件数, 重量,
//尺码, 箱型1, 箱型2, 箱型3, 箱型4, 箱型5, 箱型6, 箱型7, 箱型8, 箱型9, 箱型10, 其他箱型, 箱TEU, 集装箱,
//利润USD, 应收USD, 应付USD, 已收USD, 已付USD, 利润RMB, 应收RMB, 应付RMB, 已收RMB, 已付RMB
//, 合计应收, 合计应付, 毛利润, 利润率, 合计已收, 合计已付, 垫付费用, 商品名称, 接单日期, 净重, 总价,
//场站费应收RMB, 场站费应付RMB, 港杂费应收RMB, 港杂费应付RMB,
//THC应收RMB, THC应付RMB, 单证费应收RMB, 单证费应付RMB,
//报关费应收RMB, 报关费应付RMB, 洗箱费应收RMB, 洗箱费应付RMB,
//监装费应收RMB, 监装费应付RMB, 海运费应收USD, 海运费应付USD,
//代理费应收USD, 代理费应付USD, 目的港运杂费应收USD,
//目的港运杂费应付USD, 转船费应收USD, 转船费应付USD
strSql = "SELECT 编号,业务类型,委托单位,业务编号,主提单号,分提单号,业务来源,商品名称,船公司,船名,航次,航线,convert(char(10),开船日期,20) as 业务日期,操作部门,操作员,揽货人,净重,重量,箱TEU,集装箱,应收RMB,应收USD,应付RMB,应付USD,合计应收,合计应付,利润RMB,利润USD,毛利润,利润率 FROM [" + strCrmCsDataName + "].[dbo].[v_op_bscard] WHERE 1<0 ";//如果页数为空或者页数为0不返回数据
}
else
{
if (tempShowPage > 0 && tempCurPage > 0)
{
if (tempCurPage == 1)
{
strSql = String.Format(" SELECT {0} 编号,业务类型,委托单位,业务编号,主提单号,分提单号,业务来源,商品名称,船公司,船名,航次,航线,convert(char(10),开船日期,20) as 业务日期,操作部门,操作员,揽货人,净重,重量,箱TEU,集装箱,应收RMB,应收USD,应付RMB,应付USD,合计应收,合计应付,利润RMB,利润USD,毛利润,利润率 FROM [" + strCrmCsDataName + "].[dbo].[v_op_bscard] "
+ " WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " order by 业务类型,委托单位,开船日期 DESC ", "top " + tempShowPage);
}
else
{
strTopNotInclude = "top " + (tempShowPage * (tempCurPage - 1));//RowCount*PageNum
strTopInclude = "top " + tempShowPage;//RowCount*PageNum
strSql = String.Format(" SELECT {1} 编号,业务类型,委托单位,业务编号,主提单号,分提单号,业务来源,商品名称,船公司,船名,航次,航线,convert(char(10),开船日期,20) as 业务日期,操作部门,操作员,揽货人,净重,重量,箱TEU,集装箱,应收RMB,应收USD,应付RMB,应付USD,合计应收,合计应付,利润RMB,利润USD,毛利润,利润率 FROM [" + strCrmCsDataName + "].[dbo].[v_op_bscard] "
+ " WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " AND 编号 NOT IN (SELECT {0} 编号 FROM [" + strCrmCsDataName + "].[dbo].[v_op_bscard] WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + " order by 业务类型,委托单位,开船日期 DESC ) order by 业务类型,委托单位,开船日期 DESC ", strTopNotInclude, strTopInclude);
}
}
else
{
strSql = "SELECT 编号,业务类型,委托单位,业务编号,主提单号,分提单号,业务来源,商品名称,船公司,船名,航次,航线,convert(char(10),开船日期,20) as 业务日期,操作部门,操作员,揽货人,净重,重量,箱TEU,集装箱,应收RMB,应收USD,应付RMB,应付USD,合计应收,合计应付,利润RMB,利润USD,毛利润,利润率 FROM [" + strCrmCsDataName + "].[dbo].[v_op_bscard] 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 [" + strCrmCsDataName + "].[dbo].[v_op_bscard] where 1=1 " + ViewState["strSel"].ToString().Trim();
if (hidsel.Trim() == "")
{
strSql = "SELECT COUNT(*) FROM [" + strCrmCsDataName + "].[dbo].[v_op_bscard] 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;
}
}
}