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.
483 lines
22 KiB
C#
483 lines
22 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
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 System.Text.RegularExpressions;
|
|
using DSWeb.Models;
|
|
using DSWeb.EntityDA;
|
|
using DSWeb.ConfigManager;
|
|
using DSWeb.Authority;
|
|
|
|
|
|
namespace DSWeb.CW
|
|
{
|
|
public partial class CwInvoiceApplicationGridSource : System.Web.UI.Page
|
|
{
|
|
private string strHandle;
|
|
private string strSearch;//委托信息查询条件
|
|
private string strUserID;//登录人GID
|
|
private int iCurrentPage;//当前页数
|
|
private int iShowPage;//显示最大页数
|
|
private string strCompanyID;//公司GID
|
|
private string strShowName;//用户显示名
|
|
private string strDeptName;//部门名称
|
|
public string strGids;//
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (Session["USERID"] != null)
|
|
{
|
|
strUserID = Session["USERID"].ToString();
|
|
}
|
|
if (Session["SHOWNAME"] != null)
|
|
{
|
|
strShowName = Session["SHOWNAME"].ToString();
|
|
}
|
|
if (Session["COMPANYID"] != null)
|
|
{
|
|
strCompanyID = Session["COMPANYID"].ToString();
|
|
}
|
|
if (Session["DEPTNAME"] != null)
|
|
{
|
|
strDeptName = Session["DEPTNAME"].ToString();
|
|
}
|
|
#region 请求处理
|
|
if (Request.QueryString["handle"] != null)
|
|
{
|
|
strHandle = Request.QueryString["handle"].ToString().Trim().ToLower();
|
|
}
|
|
|
|
if (Request.QueryString["search"] != null)
|
|
{
|
|
UnicodeEncoding unicode = new UnicodeEncoding();
|
|
strSearch = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["search"].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["gids"] != null)
|
|
{
|
|
strGids = Request.QueryString["gids"].ToString();
|
|
}
|
|
|
|
if (strHandle != null)
|
|
{
|
|
if (strHandle == "makeoutlist")
|
|
{
|
|
Response.Write(GetMakeOutList());
|
|
}
|
|
else if (strHandle == "makeoutlistpage")
|
|
{
|
|
Response.Write(GetMakeOutListPage());
|
|
}
|
|
else if (strHandle.Trim().ToLower().Equals("isvouchers"))
|
|
{
|
|
Response.Write(GetIsVouchers().ToString());
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
private string GetIsVouchers()
|
|
{
|
|
T_ALL_DA T_ALL_DA = new T_ALL_DA();
|
|
string sSQL = "";
|
|
string alt = "";
|
|
string sResult = "";
|
|
string sgids = "'" + strGids.Trim().Replace(",", "','") + "'";
|
|
//
|
|
sSQL = "select top 1 gid from ch_fee_invoice where gid in(" + sgids + ") and (VOUCHERNO is not null and VOUCHERNO<>'')";
|
|
alt = T_ALL_DA.GetStrSQL("gid", sSQL);
|
|
if (alt.Trim() != "")
|
|
{
|
|
sResult += "有已生成的凭证,不能重复生成!";
|
|
}
|
|
//帐套设置
|
|
sSQL = "SELECT top 1 * from cw_design";
|
|
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
|
|
if (ds == null)
|
|
{
|
|
sResult += "请先设置系统帐套信息!";
|
|
}
|
|
else
|
|
{
|
|
string strISFCY = "";//是否核算外币
|
|
string strISEMPLACC = "";//是否核算人员
|
|
string strISCORPACC = "";//是否算客户门
|
|
//客户财务编码 (应收的客户财务编码必须核算,应付可以根据配置决定是否核算)
|
|
sSQL = "select top 1 GID from info_client where SHORTNAME in (select CUSTOMERNAME from ch_fee_invoice where gid in(" + sgids + ")) and (FARCODE is null or FARCODE='')";
|
|
alt = T_ALL_DA.GetStrSQL("GID", sSQL);
|
|
if (alt.Trim() != "")
|
|
{
|
|
strISCORPACC = "有客户财务编码为空的数据,请先维护!";
|
|
}
|
|
//其他常用科目设置 应收
|
|
//ISITEMACC 是否核算项目
|
|
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["AR"].ToString().Trim() + "'";
|
|
DataSet ds1 = T_ALL_DA.GetAllSQL(sSQL);
|
|
if (ds1 != null)
|
|
{
|
|
if (ds1.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim() == "True")
|
|
{
|
|
if (strISCORPACC.Trim() == "")
|
|
{
|
|
//客户财务编码 (应收的客户财务编码必须核算,应付可以根据配置决定是否核算)
|
|
sSQL = "select top 1 GID from info_client where SHORTNAME in (select CUSTOMERNAME from ch_fee_invoice where gid in(" + sgids + ")) and (FAPCODE is null or FAPCODE='')";
|
|
alt = T_ALL_DA.GetStrSQL("GID", sSQL);
|
|
if (alt.Trim() != "")
|
|
{
|
|
strISCORPACC = "有财务应付帐款代码为空的数据,请先维护!";
|
|
}
|
|
}
|
|
}
|
|
if (ds1.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim() == "True")
|
|
{
|
|
//人员财务编码
|
|
sSQL = "select top 1 GID from user_baseinfo where USERID in (select gid from [user] where ISDELETED=0 and SHOWNAME in (select SALE from ch_fee_invoice where bsno in(" + sgids + "))) and COMPANYNAME=(select [NAME] from [company] where GID='" + strCompanyID + "') and (FINANCESOFTCODE is null or FINANCESOFTCODE='')";
|
|
alt = T_ALL_DA.GetStrSQL("GID", sSQL);
|
|
if (alt.Trim() != "")
|
|
{
|
|
strISEMPLACC = "有人员财务软件代码为空的数据,请先维护!";
|
|
}
|
|
}
|
|
if (ds1.Tables[0].Rows[0]["ISFCY"].ToString().Trim() == "True")
|
|
{
|
|
//外币财务编码
|
|
sSQL = "select top 1 GID from code_currency where CODENAME in (select CURRENCY from ch_fee_invoice where bsno in(" + sgids + ")) and (FINANCESOFTCODE is null or FINANCESOFTCODE='')";// and CURRENCY<>'RMB'
|
|
alt = T_ALL_DA.GetStrSQL("GID", sSQL);
|
|
if (alt.Trim() != "")
|
|
{
|
|
strISFCY = "有外币财务软件代码为空的数据,请先维护!";
|
|
}
|
|
}
|
|
}
|
|
sResult += strISCORPACC + strISEMPLACC + strISFCY;
|
|
}
|
|
//
|
|
return sResult;
|
|
}
|
|
|
|
#region 获取已开出发票页总数
|
|
/// <summary>
|
|
/// 获取已开出发票页总数
|
|
/// </summary>
|
|
/// <returns>返回总页数</returns>
|
|
private int GetMakeOutListPage()
|
|
{
|
|
InvoiceDA invoiceDA = new InvoiceDA();
|
|
string strSql = "SELECT COUNT(*) FROM ch_fee_invoice as A WHERE (ISDELETE=0 or ISDELETE is null) ";
|
|
|
|
string strCondition = "";
|
|
|
|
string strAuthorityCondition = "";
|
|
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceManagement");
|
|
|
|
if (userAuthorityManage.OperateType != AuthorityType.NULL)
|
|
{
|
|
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEMAKEOUT, strShowName, strCompanyID, strDeptName, strUserID);
|
|
strSql += strAuthorityCondition;
|
|
}
|
|
//
|
|
string strcbisv = " and (VOUCHERNO is null or VOUCHERNO='') and billstatus=1";
|
|
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;
|
|
case "cbisv"://ETD EndDate
|
|
string cbisv = strArg[1].Replace("\"", "");
|
|
if (cbisv.Trim() == "true")
|
|
{
|
|
strcbisv="";
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
strSql += strCondition;
|
|
}
|
|
}
|
|
strSql += strcbisv;
|
|
int iTotal = int.Parse(invoiceDA.GetExcuteSql(strSql).Tables[0].Rows[0][0].ToString());
|
|
return iTotal;
|
|
}
|
|
#endregion
|
|
|
|
private string GetMakeOutList()
|
|
{
|
|
InvoiceDA invoiceDA = new InvoiceDA();
|
|
DataTable sourceTable;
|
|
|
|
string strTopInclude = "";
|
|
string strTopNotInclude = "";
|
|
string strCondition = " and (ISDELETE=0 or ISDELETE is null)";
|
|
string strcbisv = " and (VOUCHERNO is null or VOUCHERNO='') and billstatus=1";
|
|
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}%' OR A.INVOICENO LIKE '%{0}%') ", strArg[1].Replace("\"", ""));
|
|
break;
|
|
case "cbisv"://ETD EndDate
|
|
string cbisv = strArg[1].Replace("\"", "");
|
|
if (cbisv.Trim() == "true")
|
|
{
|
|
strcbisv = "";
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
strCondition += strcbisv;
|
|
//
|
|
string strAuthorityCondition = "";
|
|
UserAuthorityManage userAuthorityManage = new UserAuthorityManage(strUserID, "modInvoiceManagement");
|
|
|
|
if (userAuthorityManage.OperateType != AuthorityType.NULL)
|
|
{
|
|
strAuthorityCondition = userAuthorityManage.GetVisibleRangeSql(userAuthorityManage.VisibleType, ModuleType.INVOICEMAKEOUT, strShowName, strCompanyID, strDeptName,strUserID);
|
|
}
|
|
|
|
string strSql = "";
|
|
if (iCurrentPage > 0 && iShowPage > 0)
|
|
{
|
|
if (iCurrentPage == 1)
|
|
{
|
|
strSql = String.Format(" SELECT {0} A.GID,A.VOUCHERNO,A.INVOICETYPE,CASE WHEN A.ISNEEDFEE = 1 THEN 1 ELSE 0 END,CASE WHEN A.ISDELETE = 1 THEN 1 ELSE 0 END,A.BILLNO,A.INVOICENO,A.CUSTOMERNAME,A.INVOICECUSTNAME,A.AMOUNT,A.CURRENCY,B.SHOWNAME,A.APPLYTIME,C.SHOWNAME,A.OPERATETIME "
|
|
+ " FROM ch_fee_invoice as A LEFT JOIN [user] as B ON A.APPLICANT = B.GID LEFT JOIN [user] as C ON A.OPERATOR = C.GID WHERE 1>0 " + strAuthorityCondition + strCondition + " ORDER BY BILLNO 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.VOUCHERNO,A.INVOICETYPE,CASE WHEN A.ISNEEDFEE = 1 THEN 1 ELSE 0 END,CASE WHEN A.ISDELETE = 1 THEN 1 ELSE 0 END,A.BILLNO,A.INVOICENO,A.CUSTOMERNAME,A.INVOICECUSTNAME,A.AMOUNT,A.CURRENCY,B.SHOWNAME,A.APPLYTIME,C.SHOWNAME,A.OPERATETIME "
|
|
+ " FROM ch_fee_invoice as A LEFT JOIN [user] as B ON A.APPLICANT = B.GID LEFT JOIN [user] as C ON A.OPERATOR = C.GID WHERE A.GID NOT IN "
|
|
+ " (SELECT {1} GID FROM ch_fee_invoice WHERE 1>0 " + strAuthorityCondition + strCondition + " ORDER BY BILLNO DESC ) " + strAuthorityCondition + strCondition
|
|
+ " ORDER BY BILLNO DESC ", strTopInclude, strTopNotInclude);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
strSql = " SELECT A.GID,A.VOUCHERNO,A.INVOICETYPE,CASE WHEN A.ISNEEDFEE = 1 THEN 1 ELSE 0 END,CASE WHEN A.ISDELETE = 1 THEN 1 ELSE 0 END,A.BILLNO,A.INVOICENO,A.CUSTOMERNAME,A.INVOICECUSTNAME,A.AMOUNT,A.CURRENCY,B.SHOWNAME,A.APPLYTIME,C.SHOWNAME,A.OPERATETIME "
|
|
+ " FROM ch_fee_invoice as A LEFT JOIN [user] as B ON A.APPLICANT = B.GID LEFT JOIN [user] as C ON A.OPERATOR = C.GID WHERE 1>0 " + strAuthorityCondition + strCondition + " ORDER BY BILLNO DESC ";
|
|
}
|
|
sourceTable = getBillStatusNameTable(invoiceDA.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();
|
|
}
|
|
|
|
#region 将数据集表中费用状态FeeStatus和应收应付类型FeeType的数字状态位转换成文字
|
|
/// <summary>
|
|
/// 将数据集表中费用状态FeeStatus和应收应付类型FeeType的数字状态位转换成文字
|
|
/// </summary>
|
|
/// <param name="tempTable">原数据源DataTable</param>
|
|
/// <returns>返回新数据源DataTable</returns>
|
|
private DataTable getBillStatusNameTable(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("BILLSTATUS"))
|
|
{
|
|
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("INVOICETYPE"))
|
|
{
|
|
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("BILLSTATUS"))
|
|
{
|
|
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;
|
|
default:
|
|
break;
|
|
}
|
|
cloneRow[sourceTable.Columns[k].ColumnName] = strFeeStatus;
|
|
}
|
|
else if (sourceTable.Columns[k].ColumnName.Equals("INVOICETYPE"))
|
|
{
|
|
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
|
|
{
|
|
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
|
|
}
|
|
}
|