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/CW/CwVouchersListGridSource_2....

600 lines
25 KiB
C#

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
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.CW
{
public partial class CwVouchersListGridSource_2 : System.Web.UI.Page
{
private string strReadXmlType = "";//读取xml串方式 "init"-初始化获取所有账户信息;"add"-添加新的账户信息;"delete"-删除账户信息;"exist"查看是否有与委托相关账户
private int iShowCount;//每页显示数据量
//delete
private string strCwVouitemsGid;//账户信息GID
private string strHandle;//账户操作说明
private const int iResult = -99;//参数错误
T_ALL_DA T_ALL_DA = new T_ALL_DA();
private string strRange = String.Empty;//权限可视范围
RangeDA RangeDA = new RangeDA();
public string strUserID;//用户GID
private string strORDNO;
private string strGID;
private string strGids;
private string strAccid;
private string strCustomername;
private string strFarapType;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString().Trim();
}
//
#region 判断参数是否正确
if (Request.QueryString["read"] != null)
{
strReadXmlType = Request.QueryString["read"].ToString().Trim();
}
if (Request.QueryString["showcount"] != null)
{
iShowCount = int.Parse(Request.QueryString["showcount"].ToString());
}
if (Request.QueryString["ordno"] != null)
{
strORDNO = Request.QueryString["ordno"].ToString().Trim();
}
if (Request.QueryString["gid"] != null)
{
strGID = Request.QueryString["gid"].ToString().Trim();
}
if (Request.QueryString["gids"] != null)
{
strGids = Request.QueryString["gids"].ToString().Trim();
}
if (Request.QueryString["accid"] != null)
{
strAccid = Request.QueryString["accid"].ToString().Trim();
}
if (Request.QueryString["customername"] != null)
{
UnicodeEncoding unicode = new UnicodeEncoding();
strCustomername = unicode.GetString(unicode.GetBytes(Request.QueryString["customername"].ToString().Trim()));
}
if (Request.QueryString["faraptype"] != null)
{
strFarapType = Request.QueryString["faraptype"].ToString().Trim();
}
#endregion
/*
//权限可视范围
strRange = RangeDA.GetVISIBLERANGE(strUserID.Trim(), "modOrderManagement");
if (strRange.Trim().Equals("0"))//全部
{
strRange = "";
}
else if (strRange.Trim().Equals("1"))//分公司
{
strRange = " and BSNO in(" + RangeDA.GetOrderManagementCompany(strUserID.Trim()) + ")";
}
else if (strRange.Trim().Equals("2"))//部门
{
strRange = " and BSNO in(" + RangeDA.GetOrderManagementDEPT(strUserID.Trim()) + ")";
}
else if (strRange.Trim().Equals("3"))//个人
{
strRange = " and BSNO in(" + RangeDA.GetOrderManagementPerson(strUserID.Trim()) + ")";
}
else if (strRange.Trim().Equals("4"))//无
{
strRange = " and 1<0";
}
else//空
{
strRange = " and 1<0";
}
*/
//
//
if (!strReadXmlType.Equals(""))
{
if (strReadXmlType.Equals("delete") || strReadXmlType.Equals("recover"))
{
strCwVouitemsGid = (String)Request.QueryString["gid"] as String;
strHandle = (String)Request.QueryString["read"] as String;
if (strCwVouitemsGid == null || strHandle == null)
{
Response.Write(iResult);
}
else
{
string strQuery = DoExcute(strCwVouitemsGid, strHandle);
Response.Write(strQuery);
}
}
else if (strReadXmlType.Trim().Equals("delete2"))
{
Response.Write(GetDel());
return;
}
else if (strReadXmlType.Equals("additemno"))
{
Response.Write(GetITEMNO());
return;
}
else if (strReadXmlType.Equals("isedit"))
{
string strname = T_ALL_DA.GetStrSQL("ISSYS", "SELECT ISSYS FROM cw_vouitems WHERE GID='" + strGID.Trim() + "'" + strRange);
Response.Write(strname);
return;
}
else if (strReadXmlType.Equals("accid"))
{
string strname = T_ALL_DA.GetStrSQL("ACCNAME", "SELECT ACCNAME FROM cw_accitems WHERE accid='" + strAccid.Trim() + "'" + strRange);
Response.Write(strname);
return;
}
else if (strReadXmlType.Equals("customername"))
{
string strFAPCODE = T_ALL_DA.GetStrSQL("FAPCODE", "SELECT FAPCODE FROM info_client WHERE SHORTNAME='" + strCustomername.Trim() + "'" + strRange);
Response.Write(strFAPCODE);
return;
}
else if (strReadXmlType.Equals("setitemno"))
{
Response.Write(SetItemno());
return;
}
else if (strReadXmlType.Equals("getfarapcode"))
{
Response.Write(GetFarapCode());
return;
}
else
{
string strOutputXml = "";
strOutputXml = GetCells(iShowCount, strReadXmlType);
//输出XML字符串
Response.ContentType = "text/xml";
strOutputXml.Replace("&", "&amp;");
Response.Write(strOutputXml);
}
}
else
{
//访问参数不正确
Response.ContentType = "text/xml";
Response.Write("-2");
}
}
/// <summary>
/// 获取相应客户的财务帐款代码
/// </summary>
/// <returns></returns>
private string GetFarapCode()
{
T_ALL_DA T_ALL_DA = new T_ALL_DA();
string strFAPCODE = T_ALL_DA.GetStrSQL(strFarapType, "SELECT top 1 " + strFarapType + " FROM info_client WHERE SHORTNAME='" + strCustomername.Trim() + "'");
return strFAPCODE.Trim();
}
protected string GetDel()
{
int iResult = 0;
string alt = "";
if (strGids.Trim() != "")
{
CwVouitemsDA CwVouitemsDA = new CwVouitemsDA();
strGids = "'" + strGids.Trim().Replace(",", "','") + "'";
iResult = CwVouitemsDA.DeleteAll(strGids);
}
if (iResult < 0)
{
alt = "操作出错!";
}
return alt;
}
/// <summary>
/// 根据用户提交的
/// </summary>
/// <param name="tempGid">账户GID</param>
/// <param name="tempHandle">操作类型 delete删除单条账户</param>
/// <returns>值1-删除成功;值-1 -删除操作异常 值-2 -回滚失败 值-3 -未获取相关账户信息</returns>
private string DoExcute(string tempGid, string tempHandle)
{
string strVal = "";
CwVouitemsDA CwVouitemsDA = new CwVouitemsDA();
//操作类型为删除
if (tempHandle == "delete")
{
int iResult = 0;
//先判断当前要删除的账户是否存在
if (!tempGid.Trim().Equals(""))
{
CwVouitemsEntity CwVouitemsEntity = new CwVouitemsEntity();
CwVouitemsEntity = CwVouitemsDA.GetModel(tempGid);
if (CwVouitemsEntity.GID != null)
{
iResult = CwVouitemsDA.Delete(CwVouitemsEntity.GID);
}
else
{
iResult = -3; //未获取相关账户信息
}
}
strVal = iResult.ToString();
}
if (tempHandle == "recover")
{
if (!tempGid.Trim().Equals(""))
{
CwVouitemsEntity CwVouitemsEntity = new CwVouitemsEntity();
CwVouitemsEntity = CwVouitemsDA.GetModel(tempGid);
if (CwVouitemsEntity != null)
{
StringBuilder CwVouitemsBuilder = new StringBuilder();
CwVouitemsBuilder.Append(CwVouitemsEntity.GID + ",");
CwVouitemsBuilder.Append(CwVouitemsEntity.ITEMNO + ",");
CwVouitemsBuilder.Append(CwVouitemsEntity.EXPLAN + ",");
CwVouitemsBuilder.Append(CwVouitemsEntity.ACCID + ",");
CwVouitemsBuilder.Append(CwVouitemsEntity.ACCNAME + ",");
CwVouitemsBuilder.Append(CwVouitemsEntity.AMTDR + ",");
CwVouitemsBuilder.Append(CwVouitemsEntity.AMTCR + ",");
CwVouitemsBuilder.Append(CwVouitemsEntity.FCYDR + ",");
CwVouitemsBuilder.Append(CwVouitemsEntity.FCYCR + ",");
CwVouitemsBuilder.Append(CwVouitemsEntity.FCYEXRATE + ",");
CwVouitemsBuilder.Append(CwVouitemsEntity.CUSTOMERNAME + ",");
CwVouitemsBuilder.Append(CwVouitemsEntity.CORPID + ",");
CwVouitemsBuilder.Append(CwVouitemsEntity.SALE + ",");
CwVouitemsBuilder.Append(CwVouitemsEntity.BLNO);
strVal = CwVouitemsBuilder.ToString();
}
else
{
strVal = "-3";
}
}
else
{
strVal = "-3";
}
}
return strVal;
}
/// <summary>
/// 获取数据库顺序递增的行号
/// </summary>
/// <returns></returns>
private string SetItemno()
{
bool bl = false;
T_ALL_DA T_ALL_DA = new T_ALL_DA();
DataSet ds = T_ALL_DA.GetAllSQL("select * from cw_vouitems WHERE (ORDNO = '" + strORDNO + "') order by ITEMNO");
if (ds != null)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
bl = T_ALL_DA.GetExecuteSqlCommand("update cw_vouitems set ITEMNO=" + i + " WHERE (ORDNO = '" + strORDNO + "') and gid='" + ds.Tables[0].Rows[i]["gid"].ToString().Trim() + "'");
}
}
return bl.ToString().Trim();
}
/// <summary>
/// 获取数据库顺序递增的行号
/// </summary>
/// <returns></returns>
private string GetITEMNO()
{
CwVouitemsDA CwVouitemsDA = new CwVouitemsDA();
string strITEMNO = CwVouitemsDA.GetStrSQL("hh", "select isnull(max(ITEMNO),0)+1 as hh from Cw_Vouitems where ORDNO='" + strORDNO + "'");
return strITEMNO;
}
/// <summary>
/// 获取账户信息
/// </summary>
/// <returns></returns>
private string GetCells(int iShowCount, string readXmlType)
{
CwVouitemsEntity CwVouitemsEntity = new CwVouitemsEntity();
CwVouitemsDA CwVouitemsDA = new CwVouitemsDA();
if (!strReadXmlType.Equals("exist"))
{
//获取所有账户信息,用做Grid显示
DataTable CwVouitemsTable = new DataTable();
//初始化
string strInitSql = " SELECT GID,ITEMNO,EXPLAN,ACCID,ACCNAME,AMTDR,AMTCR,FCYDR,FCYCR,FCYEXRATE,CUSTOMERNAME,CORPID,SALE,BLNO FROM cw_vouitems WHERE 1=1 and ORDNO='" + strORDNO.ToString().Trim() + "'" + strRange + " ORDER BY ITEMNO";
CwVouitemsTable = getStatusNameTable(CwVouitemsDA.GetExcuteSql(strInitSql).Tables[0]);
//编排字符串 xml串
StringBuilder dataBuilder = new StringBuilder();
dataBuilder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
dataBuilder.Append("<rows>");
int iCount = CwVouitemsTable.Rows.Count;
for (int i = 0; i < iCount; i++)
{
int jCount = CwVouitemsTable.Columns.Count;
dataBuilder.Append("<row id=\"" + CwVouitemsTable.Rows[i]["GID"].ToString() + "\">");
dataBuilder.Append("<cell>0</cell>");
for (int j = 1; j < jCount; j++)
{
switch (j)
{
//case 1:
// dataBuilder.Append("<cell>0</cell>");
// break;
case 1:
dataBuilder.Append("<cell>" + CwVouitemsTable.Rows[i][j].ToString() + "</cell>");
break;
case 2:
dataBuilder.Append("<cell>" + CwVouitemsTable.Rows[i][j].ToString() + "</cell>");
break;
case 3:
//string xl = GetACCID(CwVouitemsTable.Rows[i][j].ToString().Trim());
//if (xl != "")
//{
// dataBuilder.Append(xl);
//}
//else
//{
dataBuilder.Append("<cell>" + CwVouitemsTable.Rows[i][j].ToString() + "</cell>");
//}
break;
case 4:
dataBuilder.Append("<cell>" + CwVouitemsTable.Rows[i][j].ToString() + "</cell>");
break;
case 5:
dataBuilder.Append("<cell>" + CwVouitemsTable.Rows[i][j].ToString() + "</cell>");
break;
case 6:
dataBuilder.Append("<cell>" + CwVouitemsTable.Rows[i][j].ToString() + "</cell>");
break;
case 7:
dataBuilder.Append("<cell>" + CwVouitemsTable.Rows[i][j].ToString() + "</cell>");
break;
case 8:
dataBuilder.Append("<cell>" + CwVouitemsTable.Rows[i][j].ToString() + "</cell>");
break;
case 9:
dataBuilder.Append("<cell>" + CwVouitemsTable.Rows[i][j].ToString() + "</cell>");
break;
case 10:
//xl = GetCRMClientCells(CwVouitemsTable.Rows[i][j].ToString().Trim());
//if (xl != "")
//{
// dataBuilder.Append(xl);
//}
//else
//{
dataBuilder.Append("<cell>" + CwVouitemsTable.Rows[i][j].ToString() + "</cell>");
//}
break;
case 11:
dataBuilder.Append("<cell>" + CwVouitemsTable.Rows[i][j].ToString() + "</cell>");
break;
case 12:
//xl = GetSALE(CwVouitemsTable.Rows[i][j].ToString().Trim());
//if (xl != "")
//{
// dataBuilder.Append(xl);
//}
//else
//{
dataBuilder.Append("<cell>" + CwVouitemsTable.Rows[i][j].ToString() + "</cell>");
//}
break;
case 13:
dataBuilder.Append("<cell>" + CwVouitemsTable.Rows[i][j].ToString() + "</cell>");
break;
}
}
dataBuilder.Append("</row>");
}
dataBuilder.Append("</rows>");
return dataBuilder.ToString();
}
else if (strReadXmlType.Equals("exist"))
{
return "1";//存在账户
}
else if (strReadXmlType.Equals("add"))
{
StringBuilder dataBuilder = new StringBuilder();
dataBuilder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
dataBuilder.Append("<rows>");
dataBuilder.Append("<row id=\"" + Guid.NewGuid().ToString() + "\">");
//
dataBuilder.Append("<cell>0</cell>");
dataBuilder.Append("<cell>" + GetITEMNO() + "</cell>");
dataBuilder.Append("<cell></cell>");
//
//string strcb = GetACCID("");
//if (strcb.Trim() == "")
//{
dataBuilder.Append("<cell></cell>");
//}
//else
//{
// dataBuilder.Append(strcb);
//}
//
dataBuilder.Append("<cell></cell>");
dataBuilder.Append("<cell>0</cell>");
dataBuilder.Append("<cell>0</cell>");
dataBuilder.Append("<cell>0</cell>");
dataBuilder.Append("<cell>0</cell>");
dataBuilder.Append("<cell>0</cell>");
//
//strcb = GetCRMClientCells("");
//if (strcb.Trim() == "")
//{
dataBuilder.Append("<cell></cell>");
//}
//else
//{
// dataBuilder.Append(strcb);
//}
//
dataBuilder.Append("<cell></cell>");
//
//strcb = GetSALE("");
//if (strcb.Trim() == "")
//{
dataBuilder.Append("<cell></cell>");
//}
//else
//{
// dataBuilder.Append(strcb);
//}
//
dataBuilder.Append("<cell></cell>");
//
dataBuilder.Append("</row>");
dataBuilder.Append("</rows>");
return dataBuilder.ToString();
}
else
{
return "-3";//没有相关的账户
}
}
/// <summary>
/// 获取科目信息下拉列表
/// </summary>
/// <param name="strClientValue">当前列表科目信息id值</param>
/// <returns></returns>
public string GetACCID(string strACCID)
{
T_ALL_DA T_ALL_DA = new T_ALL_DA();
DataSet ds = T_ALL_DA.GetAllSQL("select * from cw_accitems order by ACCID");
StringBuilder clientBuilder = new StringBuilder();
clientBuilder.Append("<cell xmlcontent=\"1\" editable=\"1\">" + strACCID);
if (ds != null)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (!ds.Tables[0].Rows[i]["ACCID"].ToString().Trim().Equals(""))
{
clientBuilder.Append("<option value=\"" + ds.Tables[0].Rows[i]["ACCID"].ToString() + "\">" + ds.Tables[0].Rows[i]["ACCID"].ToString() + " | " + ds.Tables[0].Rows[i]["ACCNAME"].ToString() + "</option>");
}
}
}
clientBuilder.Append("</cell>");
return clientBuilder.ToString();
}
/// <summary>
/// 获取CRM系统客户信息下拉列表
/// </summary>
/// <param name="strClientValue">当前列表客户信息值</param>
/// <returns></returns>
public string GetCRMClientCells(string strClientValue)
{
CRMClientDA crmClientDA = new CRMClientDA();
DataTable clientTable = crmClientDA.GetCRMClientList().Tables[0];
StringBuilder clientBuilder = new StringBuilder();
clientBuilder.Append("<cell xmlcontent=\"1\" editable=\"1\">" + strClientValue);
for (int i = 0; i < clientTable.Rows.Count; i++)
{
if (!clientTable.Rows[i]["SHORTNAME"].ToString().Trim().Equals(""))
{
clientBuilder.Append("<option value=\"" + clientTable.Rows[i]["CODENAME"].ToString() + "\">" + clientTable.Rows[i]["CODENAME"].ToString().ToUpper() + " | " + clientTable.Rows[i]["SHORTNAME"].ToString() + "</option>");
}
}
clientBuilder.Append("</cell>");
return clientBuilder.ToString();
}
/// <summary>
/// 获取揽货人信息下拉列表
/// </summary>
/// <param name="strClientValue">当前列表揽货人信息值</param>
/// <returns></returns>
public string GetSALE(string strClientValue)
{
StringBuilder SALEBuilder = new StringBuilder();
SALEBuilder.Append("<cell xmlcontent=\"1\" editable=\"1\">" + strClientValue);
T_ALL_DA T_ALL_DA = new T_ALL_DA();
DataSet ds = T_ALL_DA.GetOP(strUserID, "isSaleMan");
if (ds != null)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (!ds.Tables[0].Rows[i]["CODENAME"].ToString().Trim().Equals(""))
{
SALEBuilder.Append("<option value=\"" + ds.Tables[0].Rows[i]["CODENAME"].ToString() + "\">" + ds.Tables[0].Rows[i]["CODENAME"].ToString().ToUpper() + " | " + ds.Tables[0].Rows[i]["SHOWNAME"].ToString() + "</option>");
}
}
}
SALEBuilder.Append("</cell>");
return SALEBuilder.ToString();
}
/// <summary>
/// 将数据集表中账户状态CwVouitemsStatus和应收应付类型CwVouitemsType的数字状态位转换成文字
/// </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++)
{
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++)
{
cloneRow[sourceTable.Columns[k].ColumnName] = sourceTable.Rows[i][k];
}
cloneTable.Rows.Add(cloneRow);
}
return cloneTable;
}
}
}