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/SeaiInfo/ImportReceiptListGridSource...

483 lines
20 KiB
C#

11 months ago
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.SeaiInfo
{
public partial class ImportReceiptListGridSource : System.Web.UI.Page
{
private string strReadXmlType = "";//读取xml串方式 "init"-初始化获取所有账户信息;"add"-添加新的账户信息;"delete"-删除账户信息;"exist"查看是否有与委托相关账户
private int iShowCount;//每页显示数据量
private string strBSNO;//委托编号/账户信息GID
private string strGID;//委托编号/账户信息GID
//delete
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
public string strCompanyID;//公司GID
public string strShowName;//用户显示名
public string strDeptName;//部门名称
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString().Trim();
}
else
{
Server.Transfer("~/Error/FriendError.aspx");
return;
//strUserID = "";
}
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["read"] != null)
{
strReadXmlType = Request.QueryString["read"].ToString().Trim();
}
if (Request.QueryString["showcount"] != null)
{
iShowCount = int.Parse(Request.QueryString["showcount"].ToString());
}
if (Request.QueryString["BSNO"] != null)
{
strBSNO = Request.QueryString["BSNO"].ToString();
}
if (Request.QueryString["gid"] != null)
{
strGID = Request.QueryString["gid"].ToString();
}
#endregion
#region 权限可视范围
strRange = RangeDA.GetVISIBLERANGE(strUserID.Trim(), "modSeaImportList");
if (strRange.Trim().Equals("0"))//全部
{
strRange = "";
}
else if (strRange.Trim().Equals("1"))//分公司
{
strRange = " and BSNO in(" + RangeDA.GetSeaImportListCompany(strUserID.Trim()) + ")";
}
else if (strRange.Trim().Equals("2"))//部门
{
strRange = " and BSNO in(" + RangeDA.GetSeaImportListDEPT(strUserID.Trim()) + ")";
}
else if (strRange.Trim().Equals("3"))//个人
{
strRange = " and BSNO in(" + RangeDA.GetSeaImportListPerson(strUserID.Trim()) + ")";
}
else if (strRange.Trim().Equals("4"))//无
{
strRange = " and 1<0";
}
else//空
{
strRange = " and 1<0";
}
#endregion
//
if (!strReadXmlType.Equals(""))
{
if (strReadXmlType.Equals("delete") || strReadXmlType.Equals("recover"))
{
strHandle = (String)Request.QueryString["read"] as String;
if (strGID == null || strHandle == null)
{
Response.Write(iResult);
}
else
{
string strQuery = DoExcute(strGID, strHandle);
Response.Write(strQuery);
}
}
else if (strReadXmlType.Equals("addrq"))
{
string rq = T_ALL_DA.GetStrSQL("rq", "select rq=getdate()");
if (rq.Trim() != "")
{
int irq = rq.IndexOf(" ");
rq = rq.Substring(0, irq);
rq = rq.Replace("-", "/");
}
Response.Write(rq);
return;
}
else if (strReadXmlType.Equals("addname"))
{
Response.Write(strShowName);
return;
}
else
{
string strXml = GetCells(iShowCount, strReadXmlType);
//输出XML字符串
Response.ContentType = "text/xml";
strXml.Replace("&", "&amp;");
Response.Write(strXml);
}
}
else
{
//访问参数不正确
Response.ContentType = "text/xml";
Response.Write("-2");
}
}
/// <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 = "";
ImportReceiptListDA ImportReceiptListDA = new ImportReceiptListDA();
//操作类型为删除
if (tempHandle == "delete")
{
int iResult = 0;
//先判断当前要删除的账户是否存在
if (!tempGid.Trim().Equals(""))
{
ImportReceiptListEntity ImportReceiptListEntity = new ImportReceiptListEntity();
ImportReceiptListEntity = ImportReceiptListDA.GetModel(int.Parse(strGID));
//if (ImportReceiptListEntity.id != null)
//{
iResult = ImportReceiptListDA.Delete(ImportReceiptListEntity.id);
//}
//else
//{
// iResult = -3; //未获取相关账户信息
//}
}
strVal = iResult.ToString();
}
if (tempHandle == "recover")
{
if (!tempGid.Trim().Equals(""))
{
ImportReceiptListEntity ImportReceiptListEntity = new ImportReceiptListEntity();
ImportReceiptListEntity = ImportReceiptListDA.GetModel(int.Parse(strGID));
if (ImportReceiptListEntity != null)
{
StringBuilder StrBuilder = new StringBuilder();
StrBuilder.Append(ImportReceiptListEntity.id + ",");//自增序列号
StrBuilder.Append(ImportReceiptListEntity.RECEIPTTYPE + ",");//单据类型
StrBuilder.Append(ImportReceiptListEntity.ReceiptNo + ",");//单据编号
StrBuilder.Append(ImportReceiptListEntity.RECEIPTSTATE + ",");//单据状态
StrBuilder.Append(ImportReceiptListEntity.Send_date + ",");//发出时间
StrBuilder.Append(ImportReceiptListEntity.receive_date + ",");//收到时间
StrBuilder.Append(ImportReceiptListEntity.trancer + ",");//快递公司
StrBuilder.Append(ImportReceiptListEntity.trancNo + ",");//快递单号
StrBuilder.Append(ImportReceiptListEntity.remark + ",");//备注
StrBuilder.Append(ImportReceiptListEntity.MODIFIEDUSER + ",");//录入人
StrBuilder.Append(ImportReceiptListEntity.MODIFIEDTIME);//录入时间
strVal = StrBuilder.ToString();
}
else
{
strVal = "-3";
}
}
else
{
strVal = "-3";
}
}
return strVal;
}
/// <summary>
/// 获取账户信息
/// </summary>
/// <returns></returns>
private string GetCells(int iShowCount, string readXmlType)
{
ImportReceiptListEntity ImportReceiptListEntity = new ImportReceiptListEntity();
ImportReceiptListDA ImportReceiptListDA = new ImportReceiptListDA();
ImportReceiptListEntity existImportReceiptListEntity = new ImportReceiptListEntity();
existImportReceiptListEntity = ImportReceiptListDA.GetModel(strBSNO);
if (existImportReceiptListEntity != null && !strReadXmlType.Equals("exist"))
{
//获取所有账户信息,用做Grid显示
DataTable DTable = new DataTable();
//初始化
string strSql = " SELECT [Id],RECEIPTTYPE,Receiptno,RECEIPTSTATE,Send_date,Receive_date,Trancer,TrancNo,remark,MODIFIEDUSER=(SELECT top 1 SHOWNAME from [user] where GID=Import_receipt.MODIFIEDUSER),MODIFIEDTIME FROM Import_receipt WHERE BSNO = '" + strBSNO + "' " + strRange + " ORDER BY [Id] ASC";
DTable = getStatusNameTable(ImportReceiptListDA.GetExcuteSql(strSql).Tables[0]);
//编排字符串 xml串
StringBuilder dataBuilder = new StringBuilder();
dataBuilder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
dataBuilder.Append("<rows>");
int iCount = DTable.Rows.Count;
for (int i = 0; i < iCount; i++)
{
int jCount = DTable.Columns.Count;
dataBuilder.Append("<row id=\"" + DTable.Rows[i]["Id"].ToString() + "\">");
for (int j = 1; j < jCount; j++)
{
switch (j)
{
case 1://单据类型
string xl = GetRECEIPTTYPE(DTable.Rows[i][j].ToString().Trim());
if (xl != "")
{
dataBuilder.Append(xl);
}
else
{
dataBuilder.Append("<cell>" + DTable.Rows[i][j].ToString() + "</cell>");
}
break;
case 2://单据编号
dataBuilder.Append("<cell>" + DTable.Rows[i][j].ToString() + "</cell>");
break;
case 3://单据状态
xl = GetRECEIPTSTATE(DTable.Rows[i][j].ToString().Trim());
if (xl != "")
{
dataBuilder.Append(xl);
}
else
{
dataBuilder.Append("<cell>" + DTable.Rows[i][j].ToString() + "</cell>");
}
break;
case 4://发出时间
string rq = DTable.Rows[i][j].ToString();
if (rq.Trim() != "")
{
int irq = rq.IndexOf(" ");
rq = rq.Substring(0, irq);
rq = rq.Replace("-", "/");
}
dataBuilder.Append("<cell>" + rq + "</cell>");
break;
case 5://收到时间
rq = DTable.Rows[i][j].ToString();
if (rq.Trim() != "")
{
int irq = rq.IndexOf(" ");
rq = rq.Substring(0, irq);
rq = rq.Replace("-", "/");
}
dataBuilder.Append("<cell>" + rq + "</cell>");
break;
case 6://快递公司
dataBuilder.Append("<cell>" + DTable.Rows[i][j].ToString() + "</cell>");
break;
case 7://快递单号
dataBuilder.Append("<cell>" + DTable.Rows[i][j].ToString() + "</cell>");
break;
case 8://备注
dataBuilder.Append("<cell>" + DTable.Rows[i][j].ToString() + "</cell>");
break;
case 9://录入人
dataBuilder.Append("<cell>" + DTable.Rows[i][j].ToString() + "</cell>");
break;
case 10://录入时间
dataBuilder.Append("<cell>" + DTable.Rows[i][j].ToString() + "</cell>");
break;
}
}
dataBuilder.Append("</row>");
}
dataBuilder.Append("</rows>");
return dataBuilder.ToString();
}
else if (existImportReceiptListEntity != null && strReadXmlType.Equals("exist"))
{
return "1";//存在账户
}
else if (existImportReceiptListEntity == null && 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() + "\">");
//单据类型
string strcb = GetRECEIPTTYPE("");
if (strcb.Trim() == "")
{
dataBuilder.Append("<cell></cell>");
}
else
{
dataBuilder.Append(strcb);
}
//单据编号
dataBuilder.Append("<cell></cell>");
//单据状态
strcb = GetRECEIPTSTATE("");
if (strcb.Trim() == "")
{
dataBuilder.Append("<cell></cell>");
}
else
{
dataBuilder.Append(strcb);
}
//发出时间
dataBuilder.Append("<cell></cell>");
//收到时间
dataBuilder.Append("<cell></cell>");
//快递公司
dataBuilder.Append("<cell></cell>");
//快递单号
dataBuilder.Append("<cell></cell>");
//备注
dataBuilder.Append("<cell></cell>");
//录入人
dataBuilder.Append("<cell>" + strShowName + "</cell>");
//录入时间
string rq = T_ALL_DA.GetStrSQL("rq", "select rq=getdate()");
//if (rq.Trim() != "")
//{
// int irq = rq.IndexOf(" ");
// rq = rq.Substring(0, irq);
// rq = rq.Replace("-", "/");
//}
dataBuilder.Append("<cell>" + rq + "</cell>");
dataBuilder.Append("</row>");
dataBuilder.Append("</rows>");
return dataBuilder.ToString();
}
else
{
return "-3";//没有相关的账户
}
}
/// <summary>
/// 获取 单据类型 下拉列表
/// </summary>
/// <param name="strClientValue">当前信息值</param>
/// <returns></returns>
public string GetRECEIPTTYPE(string strValue)
{
DataSet ds = T_ALL_DA.GetAllSQL("select * from crm_key_code where [KEYTYPE]='单据类型'");// and BSNO = '" + strBSNO + "'
if (ds != null)
{
StringBuilder clientBuilder = new StringBuilder();
clientBuilder.Append("<cell xmlcontent=\"1\" editable=\"1\">" + strValue);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (!ds.Tables[0].Rows[i]["KEYVALUE"].ToString().Trim().Equals(""))
{
clientBuilder.Append("<option value=\"" + ds.Tables[0].Rows[i]["KEYVALUE"].ToString() + "\">" + ds.Tables[0].Rows[i]["KEYVALUE"].ToString() + "</option>");
}
}
clientBuilder.Append("</cell>");
return clientBuilder.ToString();
}
else
{
return "";
}
}
/// <summary>
/// 获取 单据状态 下拉列表
/// </summary>
/// <param name="strClientValue">当前信息值</param>
/// <returns></returns>
public string GetRECEIPTSTATE(string strValue)
{
DataSet ds = T_ALL_DA.GetAllSQL("select * from crm_key_code where [KEYTYPE]='单据状态'");
if (ds != null)
{
StringBuilder clientBuilder = new StringBuilder();
clientBuilder.Append("<cell xmlcontent=\"1\" editable=\"1\">" + strValue);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (!ds.Tables[0].Rows[i]["KEYVALUE"].ToString().Trim().Equals(""))
{
clientBuilder.Append("<option value=\"" + ds.Tables[0].Rows[i]["KEYVALUE"].ToString() + "\">" + ds.Tables[0].Rows[i]["KEYVALUE"].ToString() + "</option>");
}
}
clientBuilder.Append("</cell>");
return clientBuilder.ToString();
}
else
{
return "";
}
}
/// <summary>
/// 将数据集表中账户状态OpStatusListStatus和应收应付类型OpStatusListType的数字状态位转换成文字
/// </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;
}
}
}