DS7/DSWeb/Attributes/AttributeGridSource.aspx.cs

550 lines
23 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;
namespace DSWeb.Attributes
{
public partial class AttributeGridSource : System.Web.UI.Page
{
private string strHandle;//操作方式
private string strUserID;//登录用户GID
private string strCompanyID;//公司GID
private string strShowName;//用户显示名
private string strDeptName;//部门名称
private int iCurrentPage;//当前页数
private int iShowPage;//显示最大页数
private string strCheckCompanyID;
private string strCompanyAttributeID;
private string strAttributeID;
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();
}
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());
}
else
{
iCurrentPage = 0;
}
if (Request.QueryString["show_page"] != null)
{
iShowPage = int.Parse(Request.QueryString["show_page"].ToString().Trim());
}
else
{
iShowPage = 0;
}
if (Request.QueryString["checkcompid"] != null)
{
strCheckCompanyID = Request.QueryString["checkcompid"].ToString();
}
if(Request.QueryString["compattrid"] != null)
{
strCompanyAttributeID = Request.QueryString["compattrid"].ToString();
}
if(Request.QueryString["attrid"] != null)
{
strAttributeID = Request.QueryString["attrid"].ToString();
}
if (strHandle == "attrtypepage")
{
Response.Write(GetAttributeTypeListPage());
}
if (strHandle == "attrtype")
{
Response.Write(GetAttributeTypeList());
}
if (strHandle == "attrlist")
{
Response.Write(GetAttributeList());
}
if (strHandle == "attrlistpage")
{
Response.Write(GetAttributeListPage());
}
if (strHandle == "compattrlist")
{
Response.Write(GetCompanyAttributeList(strCheckCompanyID));
}
if (strHandle == "compattrlistpage")
{
Response.Write(GetCompanyAttributeListPage(strCheckCompanyID));
}
if (strHandle == "deletecompattr" && strCompanyAttributeID != null)
{
Response.Write(DeleteCompanyAttribute(strCompanyAttributeID));
}
if (strHandle == "deleteattr" && strAttributeID != null)
{
Response.Write(DeleteAttribute(strAttributeID));
}
}
#region 删除参数信息
/// <summary>
/// 删除参数信息
/// </summary>
/// <param name="tempAttributeID">参数GID</param>
/// <returns>值1表示删除参数成功 值不等于1表示删除参数失败</returns>
private int DeleteAttribute(string tempAttributeID)
{
int iResult = 0;
AttributeDA attributeDA = new AttributeDA();
AttributeEntity attributeEntity = new AttributeEntity();
attributeEntity = attributeDA.GetAttributeByID(tempAttributeID);
if (attributeEntity != null)
{
if (attributeEntity.GID != null)
{
iResult = attributeDA.DeleteAttributeByGID(tempAttributeID, strUserID);
}
else
{
iResult = 2;//未获取到要删除的参数信息
}
}
else
{
iResult = 2;//未获取到要删除的参数信息
}
return iResult;
}
#endregion
private int DeleteCompanyAttribute(string tempCompanyAttributeID)
{
int iResult = 0;
AttributeCompanyDA attributeCompanyDA = new AttributeCompanyDA();
iResult = attributeCompanyDA.DeleteCompanyAttributeByID(tempCompanyAttributeID,strUserID);
return iResult;
}
#region 获取已开出发票页总数
/// <summary>
/// 获取已开出发票页总数
/// </summary>
/// <returns>返回总页数</returns>
private int GetCompanyAttributeListPage(string tempCheckCompanyID)
{
AttributeCompanyDA attributeCompanyDA = new AttributeCompanyDA();
string strSql = "SELECT COUNT(*) FROM company_attribute as A WHERE 1 > 0 AND COMPANYID = '" + tempCheckCompanyID + "' ";
int iTotal = int.Parse(attributeCompanyDA.GetExcuteSql(strSql).Tables[0].Rows[0][0].ToString());
return iTotal;
}
#endregion
private string GetCompanyAttributeList(string tempCompanyID)
{
AttributeCompanyDA attributeCompanyDA = new AttributeCompanyDA();
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 A.APPLYTIME >= '{0} 00:00:00' ", strArg[1].Replace("\"", ""));
// break;
// case "etime"://BillNO
// strCondition += String.Format(" AND A.APPLYTIME <= '{0} 23:59:59' ", 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;
// default:
// break;
// }
// }
// }
// }
//}
string strSql = "";
if (iCurrentPage > 0 && iShowPage > 0)
{
if (iCurrentPage == 1)
{
strSql = String.Format(" SELECT {0} A.GID,B.NAME,B.DESCRIPTION, A.VALUE, C.SHOWNAME, A.CREATETIME "
+ " FROM company_attribute as A INNER JOIN attribute as B ON A.ATTRIBUTEID = B.GID "
+ " LEFT JOIN [user] as C ON A.CREATEUSER = C.GID WHERE A.COMPANYID = '{1}' AND ISNULL(A.ISDELETE,0) <> 1 "
+ strCondition + " ORDER BY A.CREATETIME DESC ", "top " + iShowPage.ToString(), tempCompanyID);
}
else
{
strTopNotInclude = "top " + (iShowPage * (iCurrentPage - 1)).ToString();//RowCount*PageNum
strTopInclude = "top " + iShowPage.ToString();
strSql = String.Format(" SELECT {0} A.GID,B.NAME,B.DESCRIPTION, A.VALUE, C.SHOWNAME, A.CREATETIME "
+ " FROM company_attribute as A INNER JOIN attribute as B ON A.ATTRIBUTEID = B.GID "
+ " LEFT JOIN [user] as C ON A.CREATEUSER = C.GID WHERE A.COMPANYID = '{2}' AND ISNULL(A.ISDELETE,0) <> 1 AND A.GID NOT IN "
+ " (SELECT {1} GID FROM company_attribute WHERE COMPANYID = '{2}' AND ISNULL(ISDELETE,0) <> 1 " + strCondition + " ORDER BY CREATETIME DESC ) " + strCondition
+ " ORDER BY A.CREATETIME DESC ", strTopInclude, strTopNotInclude, tempCompanyID);
}
}
else
{
strSql = " SELECT A.GID,B.NAME,B.DESCRIPTION, A.VALUE, C.SHOWNAME, A.CREATETIME "
+ " FROM company_attribute as A INNER JOIN attribute as B ON A.ATTRIBUTEID = B.GID "
+ " LEFT JOIN [user] as C ON A.CREATEUSER = C.GID WHERE A.COMPANYID = '" + tempCompanyID + "' AND ISNULL(A.ISDELETE,0) <> 1 "
+ strCondition + " ORDER BY A.CREATETIME DESC ";
}
sourceTable = attributeCompanyDA.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 获取已开出发票页总数
/// <summary>
/// 获取已开出发票页总数
/// </summary>
/// <returns>返回总页数</returns>
private int GetAttributeListPage()
{
AttributeTypeDA attributeTypeDA = new AttributeTypeDA();
string strSql = "SELECT COUNT(*) FROM attribute as A WHERE 1 > 0 ";
int iTotal = int.Parse(attributeTypeDA.GetExcuteSql(strSql).Tables[0].Rows[0][0].ToString());
return iTotal;
}
#endregion
private string GetAttributeList()
{
AttributeTypeDA attributeTypeDA = new AttributeTypeDA();
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 A.APPLYTIME >= '{0} 00:00:00' ", strArg[1].Replace("\"", ""));
// break;
// case "etime"://BillNO
// strCondition += String.Format(" AND A.APPLYTIME <= '{0} 23:59:59' ", 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;
// default:
// break;
// }
// }
// }
// }
//}
string strSql = "";
if (iCurrentPage > 0 && iShowPage > 0)
{
if (iCurrentPage == 1)
{
strSql = String.Format(" SELECT {0} A.GID,A.NAME,A.DESCRIPTION,B.NAME AS TYPENAME,A.DEFAULTVALUE,C.SHOWNAME AS CREATEUSER,A.CREATETIME "
+ " FROM attribute as A LEFT JOIN attribute_type AS B ON A.TYPEID = B.GID LEFT JOIN [user] as C ON A.CREATEUSER = C.GID WHERE ISNULL(A.ISDELETE,0) <> 1 AND ISNULL(B.ISDELETE,0) <> 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,B.NAME AS TYPENAME,A.DEFAULTVALUE,C.SHOWNAME AS CREATEUSER,A.CREATETIME "
+ " FROM attribute as A LEFT JOIN attribute_type AS B ON A.TYPEID = B.GID LEFT JOIN [user] as C ON A.CREATEUSER = C.GID WHERE A.GID NOT IN "
+ " (SELECT {1} GID FROM attribute WHERE ISNULL(ISDELETE,0) <> 1 " + strCondition + " ORDER BY CREATETIME DESC ) AND ISNULL(A.ISDELETE,0) <> 1 AND ISNULL(B.ISDELETE,0) <> 1 " + strCondition
+ " ORDER BY A.CREATETIME DESC ", strTopInclude, strTopNotInclude);
}
}
else
{
strSql = " SELECT A.GID,A.NAME,A.DESCRIPTION,B.NAME AS TYPENAME,A.DEFAULTVALUE,C.SHOWNAME AS CREATEUSER,A.CREATETIME "
+ " FROM attribute as A LEFT JOIN attribute_type AS B ON A.TYPEID = B.GID LEFT JOIN [user] as C ON A.CREATEUSER = C.GID WHERE ISNULL(A.ISDELETE,0) <> 1 AND ISNULL(B.ISDELETE,0) <> 1 "
+ strCondition + " ORDER BY CREATETIME DESC ";
}
sourceTable = attributeTypeDA.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 获取已开出发票页总数
/// <summary>
/// 获取已开出发票页总数
/// </summary>
/// <returns>返回总页数</returns>
private int GetAttributeTypeListPage()
{
AttributeTypeDA attributeTypeDA = new AttributeTypeDA();
string strSql = "SELECT COUNT(*) FROM attribute_type as A WHERE 1 > 0 ";
int iTotal = int.Parse(attributeTypeDA.GetExcuteSql(strSql).Tables[0].Rows[0][0].ToString());
return iTotal;
}
#endregion
private string GetAttributeTypeList()
{
AttributeTypeDA attributeTypeDA = new AttributeTypeDA();
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 A.APPLYTIME >= '{0} 00:00:00' ", strArg[1].Replace("\"", ""));
// break;
// case "etime"://BillNO
// strCondition += String.Format(" AND A.APPLYTIME <= '{0} 23:59:59' ", 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;
// default:
// break;
// }
// }
// }
// }
//}
string strSql = "";
if (iCurrentPage > 0 && iShowPage > 0)
{
if (iCurrentPage == 1)
{
strSql = String.Format(" SELECT {0} A.GID, A.NAME, A.DESCRIPTION, B.SHOWNAME AS CREATEUSER, CREATETIME FROM attribute_type as A LEFT JOIN [user] as B ON A.CREATEUSER = B.GID "
+" WHERE 1>0 " + strCondition + " ORDER BY 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, B.SHOWNAME AS CREATEUSER, CREATETIME "
+ " FROM attribute_type as A LEFT JOIN [user] as B ON A.CREATEUSER = B.GID WHERE A.GID NOT IN "
+ " (SELECT {1} GID FROM attribute_type WHERE 1>0 " + strCondition + " ORDER BY CREATETIME DESC ) " + strCondition
+ " ORDER BY CREATETIME DESC ", strTopInclude, strTopNotInclude);
}
}
else
{
strSql = " SELECT A.GID, A.NAME, A.DESCRIPTION, B.SHOWNAME AS CREATEUSER, CREATETIME FROM attribute_type as A LEFT JOIN [user] as B ON A.CREATEUSER = B.GID "
+ " WHERE 1>0 " + strCondition + " ORDER BY CREATETIME DESC ";
}
sourceTable = attributeTypeDA.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();
}
}
}