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/ParameterSet/CodeFeeTemplateSetGridSourc...

1310 lines
58 KiB
C#

3 years 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.ParameterSet
{
public partial class CodeFeeTemplateSetGridSource : 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 strCompanyID;//公司GID
private string strShowName;//用户显示名
private string strDeptName;//部门名称
private string strType = "51";//Grid模块号
private string strOldHeader;
private string strNewHeader;
public string strgids = "";
public string strRange = "";
private string strFeeTemplateGID;
private string strFeeTemplateDetailID;
private int iFeeType;//费用类型 1-应收费用 2-应付费用
private string strCacheName;//Session 缓存名称
private string strCheckType;//全选类型 值"check"选中的值 值"uncheck"去除选择的值
private string strOldCacheName;//原Session缓存名称
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["id"] != null)
{
strFeeTemplateGID = Request.QueryString["id"].ToString();
}
if (Request.QueryString["detailid"] != null)
{
strFeeTemplateDetailID = Request.QueryString["detailid"].ToString();
}
if (Request.QueryString["type"] != null)
{
iFeeType = int.Parse(Request.QueryString["type"].ToString());
}
else
{
iFeeType = 0;
}
if (Request.QueryString["cachename"] != null)
{
strCacheName = Request.QueryString["cachename"].ToString();
}
if (Request.QueryString["op"] != null)
{
strCheckType = Request.QueryString["op"].ToString();
}
if (Request.QueryString["oldcache"] != null)
{
strOldCacheName = Request.QueryString["oldcache"].ToString();
}
//
#region 权限可视范围
RangeDA RangeDA = new EntityDA.RangeDA();
strRange = RangeDA.GetVISIBLERANGE(strUserID.Trim(), "modCodeFeeTemplateSet");
if (strRange.Trim().Equals("0"))//全部
{
strRange = "";
}
else if (strRange.Trim().Equals("1"))//分公司
{
strRange = RangeDA.GetCodeFeeTemplateSetCompany(strCompanyID.Trim());
}
else if (strRange.Trim().Equals("2"))//部门
{
strRange = RangeDA.GetCodeFeeTemplateSetDEPT(strCompanyID, strUserID, strDeptName);
}
else if (strRange.Trim().Equals("3"))//个人
{
strRange = RangeDA.GetCodeFeeTemplateSetPerson(strCompanyID, strUserID);
}
else if (strRange.Trim().Equals("4"))//无
{
strRange = " and 1<0";
}
else//空
{
strRange = " and 1<0";
}
#endregion
//
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 == "detaillist" && strFeeTemplateGID != null)
{
Response.Write(GetFeeTemplateDetailList(strFeeTemplateGID));
}
if (strHandle == "deletedetail" && strFeeTemplateDetailID != null)
{
Response.Write(DeleteFeeTemplateDetailByGID(strFeeTemplateDetailID).ToString());
}
if (strHandle == "poptemplate" && iFeeType >= 1)
{
Response.Write(GetPopFeeTemplateList(iFeeType));
}
if (strHandle == "poptemplatepage" && iFeeType >= 1)
{
Response.Write(GetPopFeeTemplateListPage(iFeeType));
}
if (strHandle == "checktemplate" && strFeeTemplateGID != null && strCacheName != null && strCheckType != null)
{
Response.Write(CacheTemplate(strCacheName, strFeeTemplateGID, strCheckType).ToString());
}
if (strHandle == "popfee" && strFeeTemplateGID != null && strCacheName != null)
{
Response.Write(GetPopFeeTemplateDetailList(strFeeTemplateGID, strCacheName));
}
if (strHandle == "checkfee" && strFeeTemplateDetailID != null && strCacheName != null && strCheckType != null)
{
Response.Write(CacheFee(strCacheName, strFeeTemplateDetailID, strCheckType).ToString());
}
if (strHandle == "importfee" && strCacheName != null)
{
Response.Write(ImportTemplateFee(strCacheName).ToString());
}
}
else
{
strJSON = "-1";//GET 参数错误
}
}
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 code_fee_template WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + strRange;
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)
{
if (tempCurPage == 1)
{
// 1 2 3 4 5 6 7
//业务种类,费用类型,模板系统名称,模板中文名称,创建人,创建时间,备注");
strSql = String.Format("select {0} GID,(case when OPTYPE=1 then '海运出口' when OPTYPE=2 then '海运进口' else '报关业务' end) as OPTYPE,(case when FEETYPE=1 then '收' else '付' end) as FEETYPE,NAME,DESCRIPTION,CREATEUSER=(select top 1 SHOWNAME from [user] where GID=code_fee_template.CREATEUSER),CREATETIME,REMARK FROM code_fee_template WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + strRange + " order by CREATETIME DESC ", "top " + tempShowPage);
}
else
{
strTopNotInclude = "top " + (tempShowPage * (tempCurPage - 1));//RowCount*PageNum
strTopInclude = "top " + tempShowPage;//RowCount*PageNum
strSql = String.Format(" SELECT {1} GID,(case when OPTYPE=1 then '海运出口' when OPTYPE=2 then '海运进口' else '报关业务' end) as OPTYPE,(case when FEETYPE=1 then '收' else '付' end) as FEETYPE,NAME,DESCRIPTION,CREATEUSER=(select top 1 SHOWNAME from [user] where GID=code_fee_template.CREATEUSER),CREATETIME,REMARK FROM code_fee_template "
+ " WHERE GID NOT IN (SELECT {0} GID FROM code_fee_template WHERE 1=1 " + ViewState["hid_sel"].ToString().Trim() + strRange + " order by CREATETIME DESC) " + ViewState["hid_sel"].ToString().Trim() + strRange + " order by CREATETIME DESC", strTopNotInclude, strTopInclude);
}
}
else
{
strSql = " SELECT GID,(case when OPTYPE=1 then '海运出口' when OPTYPE=2 then '海运进口' else '报关业务' end) as OPTYPE,(case when FEETYPE=1 then '收' else '付' end) as FEETYPE,NAME,DESCRIPTION,CREATEUSER=(select top 1 SHOWNAME from [user] where GID=code_fee_template.CREATEUSER),CREATETIME,REMARK FROM code_fee_template 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 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;
}
#region 根据费用模板GID获取费用模板费用明细数据
/// <summary>
/// 根据费用模板GID获取费用模板费用明细数据
/// </summary>
/// <param name="tempFeeTemplateID">费用模板GID</param>
/// <returns>返回JSON数据源</returns>
private string GetFeeTemplateDetailList(string tempFeeTemplateID)
{
FeeTemplateDetailDA feeTemplateDetailDA = new FeeTemplateDetailDA();
DataTable sourceTable;
string strCondition = "";
string strTopInclude = "";
string strTopNotInclude = "";
string strSql = "";
if (iCurrentPage > 0 && iShowPage > 0)
{
if (iCurrentPage == 1)
{
strSql = String.Format("SELECT {0} GID,FEENAME,CLIENT,CUSTOMERNAME,UNIT,UNITPRICE,CURRENCY,EXCHANGERATE,REMARK,SORT FROM code_fee_templatedetail WHERE TEMPLATEID = '" + tempFeeTemplateID + "' " + strCondition + " ORDER BY sort,CREATETIME ", "top " + iShowPage.ToString());
}
else
{
strTopNotInclude = "top " + (iShowPage * (iCurrentPage - 1)).ToString();//RowCount*PageNum
strTopInclude = "top " + iShowPage.ToString();
strSql = String.Format(" SELECT {0} GID,FEENAME,CLIENT,CUSTOMERNAME,UNIT,UNITPRICE,CURRENCY,EXCHANGERATE,REMARK,SORT "
+ " FROM code_fee_templatedetail WHERE TEMPLATEID = '" + tempFeeTemplateID + "' AND GID NOT IN "
+ " (SELECT {1} GID FROM code_fee_templatedetail WHERE TEMPLATEID = '" + tempFeeTemplateID + "' " + strCondition + " ORDER BY sort,CREATETIME DESC ) " + strCondition + " ORDER BY sort,CREATETIME DESC ", strTopInclude, strTopNotInclude);
}
}
else
{
strSql = " SELECT GID,FEENAME,CLIENT,CUSTOMERNAME,UNIT,UNITPRICE,CURRENCY,EXCHANGERATE,REMARK,SORT FROM code_fee_templatedetail WHERE 1<0";
}
sourceTable = getStatusNameTable(feeTemplateDetailDA.GetExcuteSql(strSql).Tables[0]);
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
sourceBuilder.Append("\"0\",");
for (int j = 1; j < sourceTable.Columns.Count; j++)
{
if (j == sourceTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\",");
}
}
if (i == sourceTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
#region 将数据集表中费用状态FeeStatus和应收应付类型FeeType的数字状态位转换成文字
/// <summary>
/// 将数据集表中费用状态FeeStatus和应收应付类型FeeType的数字状态位转换成文字
/// </summary>
/// <param name="tempTable">原数据源DataTable</param>
/// <returns>返回新数据源DataTable</returns>
private DataTable getStatusNameTable(DataTable tempTable)
{
DataTable sourceTable = tempTable;
DataTable cloneTable = new DataTable();
int iSwitch = 0;
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
if (iSwitch == 0)
{
for (int j = 0; j < sourceTable.Columns.Count; j++)
{
if (sourceTable.Columns[j].ColumnName.Equals("OPTYPE"))
{
DataColumn newColumn = new DataColumn();
newColumn.ColumnName = sourceTable.Columns[j].ColumnName;
newColumn.DataType = System.Type.GetType("System.String");
cloneTable.Columns.Add(newColumn);
}
else if (sourceTable.Columns[j].ColumnName.Equals("FEETYPE"))
{
DataColumn newColumn = new DataColumn();
newColumn.ColumnName = sourceTable.Columns[j].ColumnName;
newColumn.DataType = System.Type.GetType("System.String");
cloneTable.Columns.Add(newColumn);
}
else if (sourceTable.Columns[j].ColumnName.Equals("CLIENT"))
{
DataColumn newColumn = new DataColumn();
newColumn.ColumnName = sourceTable.Columns[j].ColumnName;
newColumn.DataType = System.Type.GetType("System.String");
cloneTable.Columns.Add(newColumn);
}
else
{
DataColumn newColumn = new DataColumn();
newColumn.ColumnName = sourceTable.Columns[j].ColumnName;
newColumn.DataType = sourceTable.Columns[j].DataType;
cloneTable.Columns.Add(newColumn);
}
}
iSwitch = 1;
}
DataRow cloneRow = cloneTable.NewRow();
for (int k = 0; k < sourceTable.Columns.Count; k++)
{
if (sourceTable.Columns[k].ColumnName.Equals("OPTYPE"))
{
int iFeeStatus = int.Parse(sourceTable.Rows[i][k].ToString());
string strFeeStatus = "";
switch (iFeeStatus)
{
case 1:
strFeeStatus = "海运出口";
break;
case 2:
strFeeStatus = "海运进口";
break;
case 3:
strFeeStatus = "CRM报价单费用";
break;
case 4:
strFeeStatus = "报关业务";
break;
default:
break;
}
cloneRow[sourceTable.Columns[k].ColumnName] = strFeeStatus;
}
else if (sourceTable.Columns[k].ColumnName.Equals("FEETYPE"))
{
int iFeeStatus = int.Parse(sourceTable.Rows[i][k].ToString());
string strFeeStatus = "";
switch (iFeeStatus)
{
case 1:
strFeeStatus = "收费";
break;
case 2:
strFeeStatus = "付费";
break;
default:
break;
}
cloneRow[sourceTable.Columns[k].ColumnName] = strFeeStatus;
}
else if (sourceTable.Columns[k].ColumnName.Equals("CLIENT"))
{
int iFeeStatus = int.Parse(sourceTable.Rows[i][k].ToString());
string strFeeStatus = "";
switch (iFeeStatus)
{
case 1:
strFeeStatus = "船公司";
break;
case 2:
strFeeStatus = "订舱代理";
break;
case 3:
strFeeStatus = "场站";
break;
case 4:
strFeeStatus = "车队";
break;
case 5:
strFeeStatus = "委托单位";
break;
case 6:
strFeeStatus = "报关行";
break;
case 7:
strFeeStatus = "代理";
break;
case 8:
strFeeStatus = "航空公司";
break;
case 9:
strFeeStatus = "发货人";
break;
case 10:
strFeeStatus = "收货人";
break;
case 11:
strFeeStatus = "通知人";
break;
case 12:
strFeeStatus = "船代";
break;
case 13:
strFeeStatus = "码头";
break;
case 14:
strFeeStatus = "其他";
break;
default:
strFeeStatus = "";
break;
}
cloneRow[sourceTable.Columns[k].ColumnName] = strFeeStatus;
}
else
{
cloneRow[sourceTable.Columns[k].ColumnName] = sourceTable.Rows[i][k];
}
}
cloneTable.Rows.Add(cloneRow);
}
return cloneTable;
}
#endregion
#region 删除费用模板费用明细
/// <summary>
/// 删除费用模板费用明细
/// </summary>
/// <param name="tempFeeTemplateDetailID">费用模板费用明细GID</param>
/// <returns>值1表示删除成功 值不等于1表示删除失败</returns>
private int DeleteFeeTemplateDetailByGID(string tempFeeTemplateDetailID)
{
int iResult = 0;
FeeTemplateDetailDA feeTemplateDetailDA = new FeeTemplateDetailDA();
iResult = feeTemplateDetailDA.Delete(tempFeeTemplateDetailID);
return iResult;
}
#endregion
#region 获取弹出费用模板列表信息
/// <summary>
/// 获取弹出费用模板列表信息
/// </summary>
/// <param name="tempFeeType">费用类型 1-应收费用 2-应付费用</param>
/// <returns>返回JSON数据源</returns>
private string GetPopFeeTemplateList(int tempFeeType)
{
FeeTemplateDA feeTemplateDA = new FeeTemplateDA();
DataTable sourceTable;
string strCondition = "";
string strTopInclude = "";
string strTopNotInclude = "";
string strSql = "";
if (iCurrentPage > 0 && iShowPage > 0)
{
if (iCurrentPage == 1)
{
strSql = String.Format(" SELECT {0} A.GID,A.OPTYPE,A.FEETYPE,A.NAME,A.DESCRIPTION,B.SHOWNAME,A.CREATETIME,A.REMARK "
+ " FROM code_fee_template as A INNER JOIN [user] as B ON A.CREATEUSER = B.GID WHERE FEETYPE = " + tempFeeType + " " + strCondition + ViewState["hid_sel"].ToString().Trim() + " ORDER BY A.CREATETIME DESC ", "top " + iShowPage.ToString());
}
else
{
strTopNotInclude = "top " + (iShowPage * (iCurrentPage - 1)).ToString();//RowCount*PageNum
strTopInclude = "top " + iShowPage.ToString();
strSql = String.Format(" SELECT {0} A.GID,A.OPTYPE,A.FEETYPE,A.NAME,A.DESCRIPTION,B.SHOWNAME,A.CREATETIME,A.REMARK "
+ " FROM code_fee_template as A INNER JOIN [user] as B ON A.CREATEUSER = B.GID WHERE FEETYPE = " + tempFeeType + " and A.GID NOT IN "
+ " (SELECT {1} GID FROM code_fee_template WHERE FEETYPE = " + tempFeeType + strCondition + ViewState["hid_sel"].ToString().Trim() + " ORDER BY CREATETIME DESC ) "
+ strCondition + ViewState["hid_sel"].ToString().Trim()
+ " ORDER BY A.CREATETIME DESC ", strTopInclude, strTopNotInclude);
}
}
else
{
strSql = "SELECT A.GID,A.OPTYPE,A.FEETYPE,A.NAME,A.DESCRIPTION,B.SHOWNAME,A.CREATETIME,A.REMARK FROM code_fee_template as A INNER JOIN [user] as B ON A.CREATEUSER = B.GID WHERE 1<0";
}
sourceTable = getStatusNameTable(feeTemplateDA.GetExcuteSql(strSql).Tables[0]);
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
sourceBuilder.Append("\"0\",");
for (int j = 1; j < sourceTable.Columns.Count; j++)
{
if (j == sourceTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\",");
}
}
if (i == sourceTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
#region 获取弹出费用模板列表信息总页数
/// <summary>
/// 获取弹出费用模板列表信息总页数
/// </summary>
/// <returns>返回费用模板总页数</returns>
private int GetPopFeeTemplateListPage(int tempFeeType)
{
FeeTemplateDA feeTemplateDA = new FeeTemplateDA();
string strSql = "SELECT COUNT(*) FROM code_fee_template WHERE FEETYPE = " + tempFeeType + ViewState["hid_sel"].ToString().Trim();
int iTotal = int.Parse(feeTemplateDA.GetExcuteSql(strSql).Tables[0].Rows[0][0].ToString());
return iTotal;
}
#endregion
#region 缓存费用模板内所有费用明细信息
/// <summary>
/// 缓存费用模板内所有费用明细信息
/// </summary>
/// <param name="tempCacheName">缓存名称</param>
/// <param name="tempTemplateID">费用模板GID</param>
/// <param name="tempCheckType">选中类型 check-选中状态 uncheck-取消选中状态</param>
/// <returns>值1表示缓存成功 值不等于1表示缓存失败</returns>
private int CacheTemplate(string tempCacheName, string tempTemplateID, string tempCheckType)
{
int iRsult = 0;
DataTable feeTable = null;
DataTable oldTable = null;
if (Session[tempCacheName] != null)
{
if (strOldCacheName != null)
{
if (Session[strOldCacheName] != null)
{
oldTable = (DataTable)Session[strOldCacheName];
}
}
feeTable = (DataTable)Session[tempCacheName];
if (oldTable != null)
{
if (oldTable.Rows.Count > 0)
{
for (int i = 0; i < oldTable.Rows.Count; i++)
{
//缓存新的费用信息
DataRow newRow = feeTable.NewRow();
newRow["GID"] = oldTable.Rows[i]["GID"].ToString();
newRow["FEENAME"] = oldTable.Rows[i]["FEENAME"].ToString();
newRow["CLIENT"] = oldTable.Rows[i]["CLIENT"].ToString();
newRow["CUSTOMERNAME"] = oldTable.Rows[i]["CUSTOMERNAME"].ToString();
newRow["UNIT"] = oldTable.Rows[i]["UNIT"].ToString();
newRow["UNITPRICE"] = oldTable.Rows[i]["UNITPRICE"].ToString();
newRow["CURRENCY"] = oldTable.Rows[i]["CURRENCY"].ToString();
newRow["EXCHANGERATE"] = oldTable.Rows[i]["EXCHANGERATE"].ToString();
newRow["REMARK"] = oldTable.Rows[i]["REMARK"].ToString();
newRow["FEETYPE"] = oldTable.Rows[i]["FEETYPE"].ToString();
feeTable.Rows.Add(newRow);
}
}
}
if (tempCheckType.Trim().ToLower().Equals("check"))
{
string strSql = String.Format(" SELECT A.GID,A.FEENAME,A.CLIENT,A.CUSTOMERNAME,A.UNIT,A.UNITPRICE,A.CURRENCY,"
+ " A.EXCHANGERATE,A.REMARK,A.FEETYPE FROM code_fee_templatedetail as A WHERE A.TEMPLATEID = '{0}' ORDER BY A.SORT,A.CREATETIME DESC", tempTemplateID);
DataTable checkFeeTable = new DataTable();
FeeDA feeDA = new FeeDA();
checkFeeTable = feeDA.GetExcuteSql(strSql).Tables[0];
if (checkFeeTable.Rows.Count > 0)
{
for (int i = 0; i < checkFeeTable.Rows.Count; i++)
{
int iCount = 0;
for (int j = 0; j < feeTable.Rows.Count; j++)
{
if (feeTable.Rows[j]["GID"].ToString().Trim().Equals(checkFeeTable.Rows[i]["GID"].ToString().Trim()))
{
iCount++;
break;
}
}
if (iCount == 0)
{
//缓存新的费用信息
DataRow newRow = feeTable.NewRow();
newRow["GID"] = checkFeeTable.Rows[i]["GID"].ToString();
newRow["FEENAME"] = checkFeeTable.Rows[i]["FEENAME"].ToString();
newRow["CLIENT"] = checkFeeTable.Rows[i]["CLIENT"].ToString();
newRow["CUSTOMERNAME"] = checkFeeTable.Rows[i]["CUSTOMERNAME"].ToString();
newRow["UNIT"] = checkFeeTable.Rows[i]["UNIT"].ToString();
newRow["UNITPRICE"] = checkFeeTable.Rows[i]["UNITPRICE"].ToString();
newRow["CURRENCY"] = checkFeeTable.Rows[i]["CURRENCY"].ToString();
newRow["EXCHANGERATE"] = checkFeeTable.Rows[i]["EXCHANGERATE"].ToString();
newRow["REMARK"] = checkFeeTable.Rows[i]["REMARK"].ToString();
newRow["FEETYPE"] = checkFeeTable.Rows[i]["FEETYPE"].ToString();
feeTable.Rows.Add(newRow);
}
}
Session[tempCacheName] = feeTable;
}
iRsult = 1;
}
else if (tempCheckType.Trim().ToLower().Equals("uncheck"))
{
string strSql = String.Format(" SELECT A.GID,A.FEENAME,A.CLIENT,A.CUSTOMERNAME,A.UNIT,A.UNITPRICE,A.CURRENCY,"
+ " A.EXCHANGERATE,A.REMARK,A.FEETYPE FROM code_fee_templatedetail as A WHERE A.TEMPLATEID = '{0}' ORDER BY A.SORT,A.CREATETIME DESC", tempTemplateID);
DataTable checkFeeTable = new DataTable();
FeeDA feeDA = new FeeDA();
checkFeeTable = feeDA.GetExcuteSql(strSql).Tables[0];
if (checkFeeTable.Rows.Count > 0)
{
for (int i = 0; i < checkFeeTable.Rows.Count; i++)
{
for (int j = 0; j < feeTable.Rows.Count; j++)
{
if (feeTable.Rows[j]["GID"].ToString().Trim().Equals(checkFeeTable.Rows[i]["GID"].ToString().Trim()))
{
feeTable.Rows.Remove(feeTable.Rows[j]);
break;
}
}
}
Session[tempCacheName] = feeTable;
}
iRsult = 1;
}
}
else
{
if (tempCheckType.Trim().ToLower().Equals("check"))
{
string strSql = String.Format(" SELECT A.GID,A.FEENAME,A.CLIENT,A.CUSTOMERNAME,A.UNIT,A.UNITPRICE,A.CURRENCY,"
+ " A.EXCHANGERATE,A.REMARK,A.FEETYPE FROM code_fee_templatedetail as A WHERE A.TEMPLATEID = '{0}' ORDER BY A.SORT,A.CREATETIME DESC", tempTemplateID);
DataTable checkFeeTable = new DataTable();
FeeDA feeDA = new FeeDA();
checkFeeTable = feeDA.GetExcuteSql(strSql).Tables[0];
if (strOldCacheName != null)
{
if (Session[strOldCacheName] != null)
{
oldTable = (DataTable)Session[strOldCacheName];
}
}
if (oldTable != null)
{
if (oldTable.Rows.Count > 0)
{
for (int i = 0; i < oldTable.Rows.Count; i++)
{
//缓存新的费用信息
DataRow newRow = checkFeeTable.NewRow();
newRow["GID"] = oldTable.Rows[i]["GID"].ToString();
newRow["FEENAME"] = oldTable.Rows[i]["FEENAME"].ToString();
newRow["CLIENT"] = oldTable.Rows[i]["CLIENT"].ToString();
newRow["CUSTOMERNAME"] = oldTable.Rows[i]["CUSTOMERNAME"].ToString();
newRow["UNIT"] = oldTable.Rows[i]["UNIT"].ToString();
newRow["UNITPRICE"] = oldTable.Rows[i]["UNITPRICE"].ToString();
newRow["CURRENCY"] = oldTable.Rows[i]["CURRENCY"].ToString();
newRow["EXCHANGERATE"] = oldTable.Rows[i]["EXCHANGERATE"].ToString();
newRow["REMARK"] = oldTable.Rows[i]["REMARK"].ToString();
newRow["FEETYPE"] = oldTable.Rows[i]["FEETYPE"].ToString();
checkFeeTable.Rows.Add(newRow);
}
}
}
Session[tempCacheName] = checkFeeTable;
iRsult = 1;
}
}
return iRsult;
}
#endregion
#region 根据费用模板GID获取费用模板费用明细数据
/// <summary>
/// 根据费用模板GID获取费用模板费用明细数据
/// </summary>
/// <param name="tempFeeTemplateID">费用模板GID</param>
/// <returns>返回JSON数据源</returns>
private string GetPopFeeTemplateDetailList(string tempFeeTemplateID, string tempCacheName)
{
FeeTemplateDetailDA feeTemplateDetailDA = new FeeTemplateDetailDA();
DataTable sourceTable;
string strCondition = "";
string strSql = "";
strSql = "SELECT A.GID,A.FEENAME,A.CLIENT,A.CUSTOMERNAME,A.UNIT,A.UNITPRICE,A.CURRENCY,A.EXCHANGERATE,A.REMARK "
+ " FROM code_fee_templatedetail as A INNER JOIN [user] as B ON A.CREATEUSER = B.GID WHERE TEMPLATEID = '" + tempFeeTemplateID + "' " + strCondition + " ORDER BY A.SORT,A.CREATETIME DESC ";
sourceTable = getStatusNameTable(feeTemplateDetailDA.GetExcuteSql(strSql).Tables[0]);
DataTable cacheTable = null;
if (Session[tempCacheName] != null)
{
cacheTable = (DataTable)Session[tempCacheName];
}
StringBuilder sourceBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("rows:[");
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\",");
sourceBuilder.Append("data:[");
if (cacheTable != null)
{
if (cacheTable.Rows.Count > 0)
{
int iCount = 0;
for (int k = 0; k < cacheTable.Rows.Count; k++)
{
if (cacheTable.Rows[k]["GID"].ToString() == sourceTable.Rows[i]["GID"].ToString())
{
sourceBuilder.Append("\"1\",");
iCount++;
break;
}
}
if (iCount == 0)
{
sourceBuilder.Append("\"0\",");
}
}
else
{
sourceBuilder.Append("\"0\",");
}
}
else
{
sourceBuilder.Append("\"0\",");
}
for (int j = 1; j < sourceTable.Columns.Count; j++)
{
if (j == sourceTable.Columns.Count - 1)
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\"");
}
else
{
sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\",");
}
}
if (i == sourceTable.Rows.Count - 1)
{
sourceBuilder.Append("]}");
}
else
{
sourceBuilder.Append("]},");
}
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
#region 缓存费用模板单个费用信息
/// <summary>
/// 缓存费用模板单个费用信息
/// </summary>
/// <param name="tempCacheName">缓存名称</param>
/// <param name="tempTemplateDetailID">费用模板费用明细费用GID</param>
/// <param name="tempCheckType">选中类型 check-选中状态 uncheck-取消选中状态</param>
/// <returns>值1表示缓存成功 值不等于1表示缓存失败</returns>
private int CacheFee(string tempCacheName, string tempTemplateDetailID, string tempCheckType)
{
int iResult = 0;
DataTable feeTable = null;
if (Session[tempCacheName] != null)
{
feeTable = (DataTable)Session[tempCacheName];
if (tempCheckType.Trim().ToLower().Equals("check"))
{
string strSql = String.Format(" SELECT A.GID,A.FEENAME,A.CLIENT,A.CUSTOMERNAME,A.UNIT,A.UNITPRICE,A.CURRENCY,"
+ " A.EXCHANGERATE,A.REMARK,A.FEETYPE FROM code_fee_templatedetail as A WHERE A.GID = '{0}' ORDER BY A.SORT,A.CREATETIME DESC", tempTemplateDetailID);
DataTable checkFeeTable = new DataTable();
FeeDA feeDA = new FeeDA();
checkFeeTable = feeDA.GetExcuteSql(strSql).Tables[0];
if (checkFeeTable.Rows.Count > 0)
{
for (int i = 0; i < checkFeeTable.Rows.Count; i++)
{
int iCount = 0;
for (int j = 0; j < feeTable.Rows.Count; j++)
{
if (feeTable.Rows[j]["GID"].ToString().Trim().Equals(tempTemplateDetailID))
{
iCount++;
break;
}
}
if (iCount == 0)
{
//缓存新的费用信息
DataRow newRow = feeTable.NewRow();
newRow["GID"] = checkFeeTable.Rows[i]["GID"].ToString();
newRow["FEENAME"] = checkFeeTable.Rows[i]["FEENAME"].ToString();
newRow["CLIENT"] = checkFeeTable.Rows[i]["CLIENT"].ToString();
newRow["CUSTOMERNAME"] = checkFeeTable.Rows[i]["CUSTOMERNAME"].ToString();
newRow["UNIT"] = checkFeeTable.Rows[i]["UNIT"].ToString();
newRow["UNITPRICE"] = checkFeeTable.Rows[i]["UNITPRICE"].ToString();
newRow["CURRENCY"] = checkFeeTable.Rows[i]["CURRENCY"].ToString();
newRow["EXCHANGERATE"] = checkFeeTable.Rows[i]["EXCHANGERATE"].ToString();
newRow["REMARK"] = checkFeeTable.Rows[i]["REMARK"].ToString();
newRow["FEETYPE"] = checkFeeTable.Rows[i]["FEETYPE"].ToString();
feeTable.Rows.Add(newRow);
}
}
Session[tempCacheName] = feeTable;
}
iResult = 1;
}
else if (tempCheckType.Trim().ToLower().Equals("uncheck"))
{
for (int j = 0; j < feeTable.Rows.Count; j++)
{
if (feeTable.Rows[j]["GID"].ToString().Trim().Equals(tempTemplateDetailID))
{
feeTable.Rows.Remove(feeTable.Rows[j]);
break;
}
}
if (feeTable.Rows.Count == 0)
{
Session.Remove(tempCacheName);
}
else
{
Session[tempCacheName] = feeTable;
}
iResult = 1;
}
}
else
{
if (tempCheckType.Trim().ToLower().Equals("check"))
{
string strSql = String.Format(" SELECT A.GID,A.FEENAME,A.CLIENT,A.CUSTOMERNAME,A.UNIT,A.UNITPRICE,A.CURRENCY,"
+ " A.EXCHANGERATE,A.REMARK,A.FEETYPE FROM code_fee_templatedetail as A WHERE A.GID = '{0}' ORDER BY A.SORT,A.CREATETIME DESC", tempTemplateDetailID);
DataTable checkFeeTable = new DataTable();
FeeDA feeDA = new FeeDA();
checkFeeTable = feeDA.GetExcuteSql(strSql).Tables[0];
Session[tempCacheName] = checkFeeTable;
iResult = 1;
}
}
return iResult;
}
#endregion
#region 导入费用模板的费用明细
/// <summary>
/// 导入费用模板的费用明细
/// </summary>
/// <param name="tempCacheName">缓存名称</param>
/// <returns>值1已经缓存明细数据 值不等于1表示没有缓存数据</returns>
private int ImportTemplateFee(string tempCacheName)
{
int iResult = 0;
if (Session[tempCacheName] != null)
{
DataTable cacheTable = (DataTable)Session[tempCacheName];
if (cacheTable.Rows.Count > 0)
{
iResult = 1;
}
else
{
iResult = -2;//没有要选择的费用明细
}
}
else
{
iResult = -1;//没有选择费用明细
}
return iResult;
}
#endregion
//
}
}