You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
D7QUANTAI/DSWeb/ParameterSet/FeeTemplateGridSource.aspx.cs

1337 lines
60 KiB
C#

using System;
using System.Collections;
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 DSWeb.Models;
using DSWeb.EntityDA;
using System.Text;
using System.Text.RegularExpressions;
namespace DSWeb.ParameterSet
{
public partial class FeeTemplateGridSource : System.Web.UI.Page
{
#region 私有变量
private string strHandle;
private int iCurrentPage;//当前页数
private int iShowPage;//显示最大页数
private string strSearch;//查询搜索条件
private string strFeeTemplateGID;
private string strFeeTemplateDetailID;
private int iFeeType;//费用类型 1-应收费用 2-应付费用
private string strCacheName;//Session 缓存名称
private string strOldCacheName;//原Session缓存名称
private string strCheckType;//全选类型 值"check"选中的值 值"uncheck"去除选择的值
#endregion
protected void Page_Load(object sender, EventArgs e)
{
#region 页面传值参数
if (Request.QueryString["id"] != null)
{
strFeeTemplateGID = Request.QueryString["id"].ToString();
}
if (Request.QueryString["handle"] != null)
{
strHandle = Request.QueryString["handle"].ToString();
}
if (Request.QueryString["cur_page"] != null)
{
iCurrentPage = int.Parse(Request.QueryString["cur_page"].ToString().Trim());
}
else
{
iCurrentPage = 0;
}
if (Request.QueryString["show_page"] != null)
{
iShowPage = int.Parse(Request.QueryString["show_page"].ToString().Trim());
}
else
{
iShowPage = 0;
}
if (Request.QueryString["search"] != null)
{
UnicodeEncoding unicode = new UnicodeEncoding();
strSearch = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["search"].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["oldcache"] != null)
{
strOldCacheName = Request.QueryString["oldcache"].ToString();
}
if (Request.QueryString["op"] != null)
{
strCheckType = Request.QueryString["op"].ToString();
}
if (strHandle != null)
{
if (strHandle == "templatelist")
{
Response.Write(GetFeeTemplateList());
}
if (strHandle == "templatelistpage")
{
Response.Write(GetFeeTemplateListPage());
}
if (strHandle == "detaillist" && strFeeTemplateGID != null)
{
Response.Write(GetFeeTemplateDetailList(strFeeTemplateGID));
}
if (strHandle == "detaillistpage" && strFeeTemplateGID != null)
{
Response.Write(GetFeeTemplateDetailListPage(strFeeTemplateGID));
}
if (strHandle == "deletedetail" && strFeeTemplateDetailID != null)
{
Response.Write(DeleteFeeTemplateDetailByGID(strFeeTemplateDetailID).ToString());
}
if (strHandle == "deletetemplate" && strFeeTemplateGID != null)
{
Response.Write(DeleteFeeTemplateByGID(strFeeTemplateGID).ToString());
}
if (strHandle == "poptemplate" && iFeeType >= 1)
{
Response.Write(GetPopFeeTemplateList(iFeeType));
}
if (strHandle == "poptemplatepage" && iFeeType >= 1)
{
Response.Write(GetPopFeeTemplateListPage(iFeeType));
}
if (strHandle == "popfee" && strFeeTemplateGID != null && strCacheName != null)
{
Response.Write(GetPopFeeTemplateDetailList(strFeeTemplateGID,strCacheName));
}
if (strHandle == "checktemplate" && strFeeTemplateGID != null && strCacheName != null && strCheckType != null)
{
Response.Write(CacheTemplate(strCacheName,strFeeTemplateGID, strCheckType).ToString());
}
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());
}
}
#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
#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.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.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>
/// <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.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.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.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 strTopInclude = "";
string strTopNotInclude = "";
if (strSearch != null)
{
if (!strSearch.Trim().Equals(""))
{
string tempSearch = strSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "btime"://Customer
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,120) >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "etime"://BillNO
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,120) <= '{0}' )", strArg[1].Replace("\"", ""));
break;
case "cus"://ETD BeginDate
strCondition += String.Format(" AND A.CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "no"://ETD EndDate
strCondition += String.Format(" AND A.BILLNO LIKE '%{0}%'", strArg[1].Replace("\"", ""));
break;
default:
break;
}
}
}
}
}
string strSql = "";
if (iCurrentPage > 0 && iShowPage > 0)
{
if (iCurrentPage == 1)
{
strSql = String.Format(" SELECT {0} 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.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.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 + "' AND A.GID NOT IN "
+ " (SELECT {1} GID FROM code_fee_templatedetail WHERE TEMPLATEID = '" + tempFeeTemplateID + "' " + strCondition + " ORDER BY CREATETIME DESC ) " + strCondition
+ " ORDER BY A.CREATETIME DESC ", strTopInclude, strTopNotInclude);
}
}
else
{
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.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>
/// <returns>返回费用模板总页数</returns>
private int GetPopFeeTemplateListPage(int tempFeeType)
{
FeeTemplateDA feeTemplateDA = new FeeTemplateDA();
string strSql = "SELECT COUNT(*) FROM code_fee_template WHERE FEETYPE = "+tempFeeType+" ";
string strCondition = "";
if (strSearch != null)
{
if (!strSearch.Trim().Equals(""))
{
string tempSearch = strSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "btime"://Customer
strCondition += String.Format(" AND convert(char(10),APPLYTIME,120) >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "etime"://BillNO
strCondition += String.Format(" AND convert(char(10),APPLYTIME,120) <= '{0}' )", strArg[1].Replace("\"", ""));
break;
case "cus"://ETD BeginDate
strCondition += String.Format(" AND CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "no"://ETD EndDate
strCondition += String.Format(" AND BILLNO LIKE '%{0}%'", strArg[1].Replace("\"", ""));
break;
default:
break;
}
}
}
strSql += strCondition;
}
}
int iTotal = int.Parse(feeTemplateDA.GetExcuteSql(strSql).Tables[0].Rows[0][0].ToString());
return iTotal;
}
#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 = "";
if (strSearch != null)
{
if (!strSearch.Trim().Equals(""))
{
string tempSearch = strSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "btime"://Customer
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,120) >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "etime"://BillNO
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,120) <= '{0}' )", strArg[1].Replace("\"", ""));
break;
case "cus"://ETD BeginDate
strCondition += String.Format(" AND A.CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "no"://ETD EndDate
strCondition += String.Format(" AND A.BILLNO LIKE '%{0}%'", strArg[1].Replace("\"", ""));
break;
default:
break;
}
}
}
}
}
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 + " 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 + " ORDER BY CREATETIME DESC ) " + strCondition
+ " 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>
/// <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="tempFeeTemplateID">费用模板GID</param>
/// <returns>值1表示删除成功 值不等于1表示删除失败</returns>
private int DeleteFeeTemplateByGID(string tempFeeTemplateID)
{
int iResult = 0;
FeeTemplateDA feeTemplateDA = new FeeTemplateDA();
iResult = feeTemplateDA.Delete(tempFeeTemplateID);
return iResult;
}
#endregion
#region 获取费用模板信息总页数
/// <summary>
/// 获取费用模板信息总页数
/// </summary>
/// <returns>返回费用模板总页数</returns>
private int GetFeeTemplateListPage()
{
FeeTemplateDA feeTemplateDA = new FeeTemplateDA();
string strSql = "SELECT COUNT(*) FROM code_fee_template WHERE 1 > 0 ";
string strCondition = "";
if (strSearch != null)
{
if (!strSearch.Trim().Equals(""))
{
string tempSearch = strSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "btime"://Customer
strCondition += String.Format(" AND convert(char(10),APPLYTIME,120) >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "etime"://BillNO
strCondition += String.Format(" AND convert(char(10),APPLYTIME,120) <= '{0}' )", strArg[1].Replace("\"", ""));
break;
case "cus"://ETD BeginDate
strCondition += String.Format(" AND CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "no"://ETD EndDate
strCondition += String.Format(" AND BILLNO LIKE '%{0}%'", strArg[1].Replace("\"", ""));
break;
default:
break;
}
}
}
strSql += strCondition;
}
}
int iTotal = int.Parse(feeTemplateDA.GetExcuteSql(strSql).Tables[0].Rows[0][0].ToString());
return iTotal;
}
#endregion
#region 通过费用模板主表GID获取费用模板明细信息总页数
/// <summary>
/// 通过费用模板主表GID获取费用模板明细信息总页数
/// </summary>
/// <param name="tempFeeTemplateID">费用模板主表GID</param>
/// <returns>返回费用模板总页数</returns>
private int GetFeeTemplateDetailListPage(string tempFeeTemplateID)
{
FeeTemplateDetailDA feeTemplateDetailDA = new FeeTemplateDetailDA();
string strSql = "SELECT COUNT(*) FROM code_fee_templatedetail WHERE TEMPLATEID = '" + tempFeeTemplateID + "' ";
string strCondition = "";
if (strSearch != null)
{
if (!strSearch.Trim().Equals(""))
{
string tempSearch = strSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "btime"://Customer
strCondition += String.Format(" AND convert(char(10),APPLYTIME,120) >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "etime"://BillNO
strCondition += String.Format(" AND convert(char(10),APPLYTIME,120) <= '{0}' )", strArg[1].Replace("\"", ""));
break;
case "cus"://ETD BeginDate
strCondition += String.Format(" AND CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "no"://ETD EndDate
strCondition += String.Format(" AND BILLNO LIKE '%{0}%'", strArg[1].Replace("\"", ""));
break;
default:
break;
}
}
}
strSql += strCondition;
}
}
int iTotal = int.Parse(feeTemplateDetailDA.GetExcuteSql(strSql).Tables[0].Rows[0][0].ToString());
return iTotal;
}
#endregion
#region 获取费用模板信息
/// <summary>
/// 获取费用模板信息
/// </summary>
/// <returns>返回JSON数据</returns>
private string GetFeeTemplateList()
{
FeeTemplateDA feeTemplateDA = new FeeTemplateDA();
DataTable sourceTable;
string strCondition = "";
string strTopInclude = "";
string strTopNotInclude = "";
if (strSearch != null)
{
if (!strSearch.Trim().Equals(""))
{
string tempSearch = strSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "btime"://Customer
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,120) >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "etime"://BillNO
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,120) <= '{0}' )", strArg[1].Replace("\"", ""));
break;
case "cus"://ETD BeginDate
strCondition += String.Format(" AND A.CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "no"://ETD EndDate
strCondition += String.Format(" AND A.BILLNO LIKE '%{0}%'", strArg[1].Replace("\"", ""));
break;
default:
break;
}
}
}
}
}
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 1 > 0 " + strCondition + " 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 A.GID NOT IN "
+ " (SELECT {1} GID FROM code_fee_template WHERE 1>0 " + strCondition + " ORDER BY CREATETIME DESC ) " + strCondition
+ " 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 " + strCondition + " ORDER BY A.CREATETIME DESC ";
}
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 根据费用模板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 = "";
if (strSearch != null)
{
if (!strSearch.Trim().Equals(""))
{
string tempSearch = strSearch;
tempSearch = tempSearch.Replace("{", "");
tempSearch = tempSearch.Replace("}", "");
tempSearch = tempSearch.Replace("[", "");
tempSearch = tempSearch.Replace("]", "");
string[] searchArg = tempSearch.Split(new char[] { ',' });
for (int i = 0; i < searchArg.Length; i++)
{
string[] strArg = searchArg[i].Split(new char[] { ':' });
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
switch (strArg[0].Replace("\"", ""))
{
case "btime"://Customer
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,120) >= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "etime"://BillNO
strCondition += String.Format(" AND convert(char(10),A.APPLYTIME,120) <= '{0}' ", strArg[1].Replace("\"", ""));
break;
case "cus"://ETD BeginDate
strCondition += String.Format(" AND A.CUSTOMERNAME LIKE '%{0}%' ", strArg[1].Replace("\"", ""));
break;
case "no"://ETD EndDate
strCondition += String.Format(" AND A.BILLNO LIKE '%{0}%'", strArg[1].Replace("\"", ""));
break;
default:
break;
}
}
}
}
}
string strSql = "";
if (iCurrentPage > 0 && iShowPage > 0)
{
if (iCurrentPage == 1)
{
strSql = String.Format(" SELECT {0} 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.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.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 + "' AND A.GID NOT IN "
+ " (SELECT {1} GID FROM code_fee_templatedetail WHERE TEMPLATEID = '" + tempFeeTemplateID + "' " + strCondition + " ORDER BY CREATETIME DESC ) " + strCondition
+ " ORDER BY A.CREATETIME DESC ", strTopInclude, strTopNotInclude);
}
}
else
{
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.CREATETIME DESC ";
}
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;
default:
strFeeStatus = "";
break;
}
cloneRow[sourceTable.Columns[k].ColumnName] = strFeeStatus;
}
else
{
cloneRow[sourceTable.Columns[k].ColumnName] = sourceTable.Rows[i][k];
}
}
cloneTable.Rows.Add(cloneRow);
}
//cloneTable.Columns.Remove("FEESTATUS");
//cloneTable.Columns.Add(new DataColumn("FEESTATUS", System.Type.GetType("System.String")));
return cloneTable;
}
#endregion
}
}