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.
JiCangHai/PingTai/DSWeb/Invoice/InvoiceBookGridSource.aspx.cs

863 lines
38 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;
using DSWeb.ConfigManager;
using System.Collections.Generic;
namespace DSWeb.Invoice
{
public partial class InvoiceBookGridSource : System.Web.UI.Page
{
private string strHandle;
private string strUserID;
private int iCurrentPage;//当前页数
private int iShowPage;//显示最大页数
private string strSearch;//查询搜索条件
private string strInvoiceNumStart;//发票号码起始值
private string strInvoiceNumEnd;//发票号码结束值
private int InvoiceTotal;//发票总数
private string strPostInfo;
private string strBookID;//发票册编号
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].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["startnum"] != null)
{
strInvoiceNumStart = Request.QueryString["startnum"].ToString();
}
if (Request.QueryString["endnum"] != null)
{
strInvoiceNumEnd = Request.QueryString["endnum"].ToString();
}
if (Request.QueryString["totalnum"] != null)
{
InvoiceTotal = int.Parse(Request.QueryString["totalnum"].ToString());
}
else
{
InvoiceTotal = 0;
}
if (Request.QueryString["post"] != null)
{
UnicodeEncoding unicode = new UnicodeEncoding();
strPostInfo = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["post"].ToString())));
}
if(Request.QueryString["bookid"] != null)
{
strBookID = Request.QueryString["bookid"].ToString();
}
if (strHandle != null)
{
if (strHandle.Equals("booklist"))
{
Response.Write(GetInvoiceBookList());
}
if (strHandle.Equals("booklistpage"))
{
Response.Write(GetBookListPageCount().ToString());
}
if (strHandle.Equals("itemlist") && strBookID != null)
{
Response.Write(GetInvoiceBookItemList());
}
if (strHandle.Equals("itemlistpage"))
{
Response.Write(GetBookItemListPageCount().ToString());
}
if (strHandle.Equals("validinvoice") && strInvoiceNumStart != null && strInvoiceNumEnd != null)
{
Response.Write(ValidateInvoiceNum(strInvoiceNumStart, strInvoiceNumEnd).ToString());
}
if (strHandle.Equals("createinvoice") && strPostInfo != null)
{
Response.Write(CreateInvoice());
}
if (strHandle.Equals("deletebook") && strBookID != null)
{
Response.Write(DeleteInvoiceBooks(strBookID));
}
}
}
#region 删除发票册主表信息
/// <summary>
/// 删除发票册主表信息
/// </summary>
/// <param name="tempInvoiceBookID"></param>
/// <returns></returns>
private int DeleteInvoiceBooks(string tempInvoiceBookID)
{
int iResult = 0;
InvoiceBookDA invoiceBookDA = new InvoiceBookDA();
iResult = invoiceBookDA.DeleteInvoiceBook(tempInvoiceBookID, strUserID);
return iResult;
}
#endregion
#region 生成发票
/// <summary>
/// 生成发票
/// </summary>
/// <returns></returns>
private string CreateInvoice()
{
//strBookID//支票册gid
int iResult = 0;
InvoiceBookDA invoiceBookDA = new InvoiceBookDA();
InvoiceBookEntity invoiceBookEntity = new InvoiceBookEntity();
StringBuilder resultBuilder = new StringBuilder();
invoiceBookEntity.GID = Guid.NewGuid().ToString();
if (strPostInfo != null)
{
if (!strPostInfo.Trim().Equals(""))
{
string tempSearch = strPostInfo;
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("\"", ""))
{//GID,NAME,DESCRIPTION,CREATEUSER,CREATETIME,INVOICECODE,INVOICENUMSTART,INVOICENUMEND,INVOICETOTAL,ISLOCK,ISDELETE,COMPANYID,TYPE
case "gid":
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
invoiceBookEntity.GID = strArg[1].Replace("\"", "").Trim();//Guid.NewGuid().ToString()
}
break;
case "name"://Customer
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
invoiceBookEntity.Name = strArg[1].Replace("\"", "").Trim();
}
break;
case "desp"://BillNO
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
invoiceBookEntity.Description = strArg[1].Replace("\"", "").Trim();
}
break;
case "creator"://ETD EndDate
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
invoiceBookEntity.CreateUser = strArg[1].Replace("\"", "").Trim();
}
break;
case "code"://ETD EndDate
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
invoiceBookEntity.InvoiceCode = strArg[1].Replace("\"", "").Trim();
}
break;
case "start"://ETD EndDate
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
invoiceBookEntity.InvoiceNumStart = strArg[1].Replace("\"", "").Trim();
}
break;
case "end"://ETD EndDate
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
invoiceBookEntity.InvoiceNumEnd = strArg[1].Replace("\"", "").Trim();
}
break;
case "total"://ETD EndDate
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
invoiceBookEntity.InvoiceTotal = int.Parse(strArg[1].Replace("\"", "").Trim());
}
break;
case "islock":
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
invoiceBookEntity.IsLock =bool.Parse(strArg[1].Replace("\"", ""));
}
break;
case "isdelete":
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
invoiceBookEntity.IsDelete = bool.Parse(strArg[1].Replace("\"", ""));
}
break;
case "comp"://ETD EndDate
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
invoiceBookEntity.CompanyID = strArg[1].Replace("\"", "").Trim();
}
break;
case "type"://ETD BeginDate
if (!strArg[1].Replace("\"", "").Trim().Equals(""))
{
invoiceBookEntity.Type = int.Parse(strArg[1].Replace("\"", "").Trim());
}
break;
default:
break;
}
}
}
}
}
string strHead = "";
int iStartCount = 0;
int iEndCount = 0;
int iStartNum = 0;
int iEndNum = 0;
int iTotalCount = 0;
for (int i = 0; i < invoiceBookEntity.InvoiceNumStart.Length; i++)
{
//将发票起始值进行过滤,将开头为0的字符过滤掉
if (invoiceBookEntity.InvoiceNumStart[i].ToString().Equals("0"))
{
iStartCount++;
}
else
{
break;
}
}
//if (iStartCount > 0)
//{
// iStartNum = int.Parse(invoiceBookEntity.InvoiceNumStart.Substring((iStartCount > 1 ? iStartCount - 1 : iStartCount), (iStartCount > 1 ? invoiceBookEntity.InvoiceNumStart.Length - iStartCount : invoiceBookEntity.InvoiceNumStart.Length-1)));
//}
//else
//{
// iStartNum = int.Parse(invoiceBookEntity.InvoiceNumStart.Substring((iStartCount > 1 ? iStartCount - 1 : iStartCount), (iStartCount > 1 ? invoiceBookEntity.InvoiceNumStart.Length - iStartCount : invoiceBookEntity.InvoiceNumStart.Length)));
//}
//2013-10-29 修改
iStartNum = int.Parse(invoiceBookEntity.InvoiceNumStart.Substring(iStartCount, invoiceBookEntity.InvoiceNumStart.Length - iStartCount));
//
if (!invoiceBookEntity.InvoiceNumEnd.Equals(""))
{
for (int j = 0; j < invoiceBookEntity.InvoiceNumEnd.Length; j++)
{
//将发票起始值进行过滤,将开头为0的字符过滤掉
if (invoiceBookEntity.InvoiceNumEnd[j].ToString().Equals("0"))
{
iEndCount++;
}
else
{
break;
}
}
//if (iEndCount > 0)
//{
// iEndNum = int.Parse(invoiceBookEntity.InvoiceNumEnd.Substring((iEndCount > 1 ? iEndCount - 1 : iEndCount), (iEndCount > 1 ? invoiceBookEntity.InvoiceNumEnd.Length - iEndCount : invoiceBookEntity.InvoiceNumEnd.Length - 1)));
//}
//else
//{
// iEndNum = int.Parse(invoiceBookEntity.InvoiceNumEnd.Substring((iEndCount > 1 ? iEndCount - 1 : iEndCount), (iEndCount > 1 ? invoiceBookEntity.InvoiceNumEnd.Length - iEndCount : invoiceBookEntity.InvoiceNumEnd.Length)));
//}
//2013-10-29 修改
iEndNum = int.Parse(invoiceBookEntity.InvoiceNumEnd.Substring(iEndCount, invoiceBookEntity.InvoiceNumEnd.Length - iEndCount));
iTotalCount = iEndNum - iStartNum+1;
}
else
{
iTotalCount = invoiceBookEntity.InvoiceTotal;
}
IList<InvoiceBookItemEntity> invoiceBookItemEntities = new List<InvoiceBookItemEntity>();
if(iStartCount > 0)
{
strHead = invoiceBookEntity.InvoiceNumStart.Substring(0,iStartCount);
}
//验证code值是否有重复
int iValidateState = invoiceBookDA.ValidateInvoiceCode(invoiceBookEntity.InvoiceCode);
if (iValidateState == 0)
{
for (int i = 0; i < iTotalCount; i++)
{
InvoiceBookItemEntity invoiceBookItemEntity = new InvoiceBookItemEntity();
invoiceBookItemEntity.GID = Guid.NewGuid().ToString();
invoiceBookItemEntity.BookID = invoiceBookEntity.GID;
invoiceBookItemEntity.InvoiceNum = strHead + (iStartNum + i).ToString();
invoiceBookItemEntity.IsLock = false;
invoiceBookItemEntity.IsDelete = false;
invoiceBookItemEntity.IsMakeOut = false;
invoiceBookItemEntity.CreateUser = invoiceBookEntity.CreateUser;
invoiceBookItemEntities.Add(invoiceBookItemEntity);
//if (i == iTotalCount - 1)
//{
// InvoiceBookItemEntity invoiceBookItemLastEntity = new InvoiceBookItemEntity();
// invoiceBookItemLastEntity.GID = Guid.NewGuid().ToString();
// invoiceBookItemLastEntity.BookID = invoiceBookEntity.GID;
// invoiceBookItemLastEntity.InvoiceNum = strHead + (iStartNum + iTotalCount).ToString();
// invoiceBookItemLastEntity.IsLock = false;
// invoiceBookItemLastEntity.IsDelete = false;
// invoiceBookItemLastEntity.IsMakeOut = false;
// invoiceBookItemLastEntity.CreateUser = invoiceBookEntity.CreateUser;
// invoiceBookItemEntities.Add(invoiceBookItemLastEntity);
//}
}
if (invoiceBookItemEntities.Count > 0)
{
if (invoiceBookEntity.InvoiceNumEnd == "")
{
invoiceBookEntity.InvoiceNumEnd = invoiceBookItemEntities[invoiceBookItemEntities.Count - 1].InvoiceNum;
}
invoiceBookEntity.InvoiceTotal = iTotalCount;
invoiceBookEntity.IsDelete = false;
invoiceBookEntity.IsLock = false;
invoiceBookEntity.InvoiceBookItemEntities = invoiceBookItemEntities;
//开始生成发票
if (strBookID == "")
{
iResult = invoiceBookDA.InsertInvoiceBook(invoiceBookEntity);
}
else
{
//iResult = invoiceBookDA.updateInvoiceBook(invoiceBookEntity);
}
}
//
resultBuilder.Append("{");
resultBuilder.Append("result:[");
resultBuilder.Append("{result:" + iResult.ToString() + ",");
resultBuilder.Append("bookid:\"" + invoiceBookEntity.GID + "\"}");
resultBuilder.Append("]");
resultBuilder.Append("}");
}
else
{
resultBuilder.Append("{");
resultBuilder.Append("result:[");
resultBuilder.Append("{result:-3,");//发票代码重复错误
resultBuilder.Append("bookid:\"\"}");
resultBuilder.Append("]");
resultBuilder.Append("}");
}
return resultBuilder.ToString();
}
#endregion
#region 验证生成发票输入值
/// <summary>
/// 验证生成发票输入值
/// </summary>
/// <param name="tempStartValue">发票起始号码</param>
/// <param name="tempEndValue">发票结束号码</param>
/// <returns>值1表示验证通过 值不等于1表示验证失败</returns>
private int ValidateInvoiceNum(string tempStartValue,string tempEndValue)
{
int iResult = 0;
int iStartCount = 0;
int iEndCount = 0;
int iStartNum = 0;
int iEndNum = 0;
for (int i = 0; i < tempStartValue.Length; i++)
{
//将发票起始值进行过滤,将开头为0的字符过滤掉
if (tempStartValue[i].ToString().Equals("0"))
{
iStartCount++;
}
else
{
break;
}
}
//iStartNum = int.Parse(tempStartValue.Substring((iStartCount > 1 ? iStartCount - 1 : iStartCount), (iStartCount > 1 ? tempStartValue.Length - iStartCount : tempStartValue.Length - 1)));
//2013-10-29 修改
iStartNum = int.Parse(tempStartValue.Substring(iStartCount, tempStartValue.Length - iStartCount));
for (int j = 0; j < tempEndValue.Length; j++)
{
//将发票起始值进行过滤,将开头为0的字符过滤掉
if (tempEndValue[j].ToString().Equals("0"))
{
iEndCount++;
}
else
{
break;
}
}
//iEndNum = int.Parse(tempEndValue.Substring((iEndCount > 1 ? iEndCount - 1 : iEndCount), (iEndCount > 1 ? tempEndValue.Length - iEndCount : tempEndValue.Length - 1)));
//2013-10-29 修改
iEndNum = int.Parse(tempEndValue.Substring(iEndCount, tempEndValue.Length - iEndCount));
if (iStartCount != iEndCount)
{
iResult = -1;//验证错误,发票号码长度错误
}
else if (iStartNum >= iEndNum)
{
iResult = -2;//发票结束值不能大于等于发票起始值,输入错误
}
else if (InvoiceTotal > 0)
{
if ((iEndNum - iStartNum) > InvoiceTotal)
{
iResult = -3;//发票总数与起始结束值不相符
}
else
{
iResult = 1;
}
}
else
{
int iInvoiceBookTotal = 0;
//查看是否超过发票最大行数
object configObj = ConfigManager.ConfigManager.Instance().GetConfigInfo(ConfigType.INVOICECONFIG);
IList<InvoiceConfigEntity> invoiceConfigEntities = new List<InvoiceConfigEntity>();
invoiceConfigEntities = (IList<InvoiceConfigEntity>)configObj;
if (invoiceConfigEntities.Count > 0)
{
foreach (InvoiceConfigEntity invoicConfigEntity in invoiceConfigEntities)
{
if (invoicConfigEntity.ItemName.ToLower().Equals("booktotal"))
{
iInvoiceBookTotal = int.Parse(invoicConfigEntity.ItemValue);
break;
}
}
}
if ((iEndNum - iStartNum) > iInvoiceBookTotal)
{
iResult = -4;//录入的发票起始和结束间值超过发票册最大发票数值
}
else
{
iResult = 1;
}
}
return iResult;
}
#endregion
#region 获取发票册总页数
/// <summary>
/// 获取发票册总页数
/// </summary>
/// <returns>返回总页数</returns>
private int GetBookListPageCount()
{
InvoiceBookDA invoiceBookDA = new InvoiceBookDA();
string strSql = "SELECT COUNT(*) FROM ch_fee_invoicebooks WHERE 1 > 0 AND ISDELETE <> 1 ";
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(invoiceBookDA.GetExcuteSql(strSql).Tables[0].Rows[0][0].ToString());
return iTotal;
}
#endregion
#region 获取发票总页数
/// <summary>
/// 获取发票总页数
/// </summary>
/// <returns>返回总页数</returns>
private int GetBookItemListPageCount()
{
InvoiceBookDA invoiceBookDA = new InvoiceBookDA();
string strSql = "SELECT COUNT(*) FROM ch_fee_invoiceitems WHERE BOOKID = '" + strBookID + "'";
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(invoiceBookDA.GetExcuteSql(strSql).Tables[0].Rows[0][0].ToString());
return iTotal;
}
#endregion
#region 获取发票册列表信息
/// <summary>
/// 获取发票册列表信息
/// </summary>
/// <returns>返回JSON数据</returns>
private string GetInvoiceBookList()
{
InvoiceBookDA invoiceBookDA = new InvoiceBookDA();
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.NAME,A.DESCRIPTION,A.INVOICECODE,A.INVOICENUMSTART,A.INVOICENUMEND,A.INVOICETOTAL,CASE WHEN A.ISLOCK = 1 THEN 1 ELSE 0 END as ISLOCK, CASE WHEN A.ISDELETE = 1 THEN 1 ELSE 0 END as ISDELETE,B.SHOWNAME,A.CREATETIME "
+ " FROM ch_fee_invoicebooks as A INNER JOIN [user] as B ON A.CREATEUSER = B.GID WHERE 1>0 AND A.ISDELETE <> 1 " + 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.NAME,A.DESCRIPTION,A.INVOICECODE,A.INVOICENUMSTART,A.INVOICENUMEND,A.INVOICETOTAL,CASE WHEN A.ISLOCK = 1 THEN 1 ELSE 0 END as ISLOCK, CASE WHEN A.ISDELETE = 1 THEN 1 ELSE 0 END as ISDELETE,B.SHOWNAME,A.CREATETIME "
+ " FROM ch_fee_invoicebooks as A INNER JOIN [user] as B ON A.CREATEUSER = B.GID WHERE A.ISDELETE <> 1 AND A.GID NOT IN "
+ " (SELECT {1} GID FROM ch_fee_invoicebooks WHERE 1>0 AND A.ISDELETE <> 1 " + strCondition + " ORDER BY CREATETIME DESC ) " + strCondition
+ " ORDER BY A.CREATETIME DESC ", strTopInclude, strTopNotInclude);
}
}
else
{
strSql = " SELECT A.GID,A.NAME,A.DESCRIPTION,A.INVOICECODE,A.INVOICENUMSTART,A.INVOICENUMEND,A.INVOICETOTAL,CASE WHEN A.ISLOCK = 1 THEN 1 ELSE 0 END as ISLOCK, CASE WHEN A.ISDELETE = 1 THEN 1 ELSE 0 END as ISDELETE,B.SHOWNAME,A.CREATETIME "
+ " FROM ch_fee_invoicebooks as A INNER JOIN [user] as B ON A.CREATEUSER = B.GID WHERE 1>0 AND A.ISDELETE <> 1 " + strCondition + " ORDER BY A.CREATETIME DESC ";
}
sourceTable = invoiceBookDA.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>返回JSON数据</returns>
private string GetInvoiceBookItemList()
{
InvoiceBookDA invoiceBookDA = new InvoiceBookDA();
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.INVOICENUM,CASE WHEN A.ISLOCK = 1 THEN 1 ELSE 0 END as ISLOCK, CASE WHEN A.ISDELETE = 1 THEN 1 ELSE 0 END as ISDELETE,CASE WHEN A.ISMAKEOUT = 1 THEN 1 ELSE 0 END as ISMAKEOUT,B.SHOWNAME,A.CREATETIME "
+ " FROM ch_fee_invoiceitems as A INNER JOIN [user] as B ON A.CREATEUSER = B.GID WHERE BOOKID = '" + strBookID +"' "+ strCondition + " ORDER BY A.INVOICENUM ASC ", "top " + iShowPage.ToString());
}
else
{
strTopNotInclude = "top " + (iShowPage * (iCurrentPage - 1)).ToString();//RowCount*PageNum
strTopInclude = "top " + iShowPage.ToString();
strSql = String.Format(" SELECT {0} A.GID, A.INVOICENUM,CASE WHEN A.ISLOCK = 1 THEN 1 ELSE 0 END as ISLOCK, CASE WHEN A.ISDELETE = 1 THEN 1 ELSE 0 END as ISDELETE,CASE WHEN A.ISMAKEOUT = 1 THEN 1 ELSE 0 END as ISMAKEOUT,B.SHOWNAME,A.CREATETIME "
+ " FROM ch_fee_invoiceitems as A INNER JOIN [user] as B ON A.CREATEUSER = B.GID WHERE A.GID NOT IN "
+ " (SELECT {1} GID FROM ch_fee_invoiceitems WHERE BOOKID = '" + strBookID + "' " + strCondition + " ORDER BY INVOICENUM ASC ) AND BOOKID = '" + strBookID + "' " + strCondition
+ " ORDER BY A.INVOICENUM ASC ", strTopInclude, strTopNotInclude);
}
}
else
{
strSql = " SELECT A.GID, A.INVOICENUM,CASE WHEN A.ISLOCK = 1 THEN 1 ELSE 0 END as ISLOCK, CASE WHEN A.ISDELETE = 1 THEN 1 ELSE 0 END as ISDELETE,CASE WHEN A.ISMAKEOUT = 1 THEN 1 ELSE 0 END as ISMAKEOUT,B.SHOWNAME,A.CREATETIME "
+ " FROM ch_fee_invoiceitems as A INNER JOIN [user] as B ON A.CREATEUSER = B.GID WHERE BOOKID = '" + strBookID +"' " + strCondition + " ORDER BY A.INVOICENUM ASC ";
}
sourceTable = invoiceBookDA.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
}
}