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.

738 lines
30 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;
using System.Collections.Generic;
using System.Xml.Linq;
using JsonHelper;
using System.Xml;
using System.Text.RegularExpressions;
namespace DSWeb.WMS_ZX
{
public partial class WmsZXFeeGridSource : System.Web.UI.Page
{
private string strReadXmlType = "";//读取xml串方式 "init"-初始化获取所有账户信息;"add"-添加新的账户信息;"delete"-删除账户信息;"exist"查看是否有与委托相关账户
private int iShowCount;//每页显示数据量
//delete
private string strWmsZXInfoGid;//账户信息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
public string stryear;//
public string strmonth;//
public string stryear1;//
public string strmonth1;//
public string stryear2;//
public string strmonth2;//
public string strGIDS;//
public string strgoodspack;//
public string strclientname;//
public string strareaname;//
public string strgoodsrksl;//
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();
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
else
{
strCompanyID = "Comcab2d43f60454327af30a131fc1d3abd";
}
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["year"] != null)
{
stryear = Request.QueryString["year"].ToString();
}
if (Request.QueryString["month"] != null)
{
strmonth = Request.QueryString["month"].ToString();
}
if (Request.QueryString["year1"] != null)
{
stryear1 = Request.QueryString["year1"].ToString();
}
if (Request.QueryString["month1"] != null)
{
strmonth1 = Request.QueryString["month1"].ToString();
}
if (Request.QueryString["year2"] != null)
{
stryear2 = Request.QueryString["year2"].ToString();
}
if (Request.QueryString["month2"] != null)
{
strmonth2 = Request.QueryString["month2"].ToString();
}
if (Request.QueryString["gids"] != null)
{
strGIDS = Request.QueryString["gids"].ToString();
}
if (Request.QueryString["clientname"] != null)
{
UnicodeEncoding unicode = new UnicodeEncoding();
strclientname = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["clientname"].ToString().Trim())));
}
if (Request.QueryString["areaname"] != null)
{
UnicodeEncoding unicode = new UnicodeEncoding();
strareaname = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["areaname"].ToString().Trim())));
}
#endregion
//
#region read解读
if (!strReadXmlType.Equals(""))
{
if (strReadXmlType.Equals("delete") || strReadXmlType.Equals("recover"))
{
strWmsZXInfoGid = (String)Request.QueryString["gid"] as String;
strHandle = (String)Request.QueryString["read"] as String;
if (strWmsZXInfoGid == null || strHandle == null)
{
Response.Write(iResult);
}
else
{
string strQuery = DoExcute(strWmsZXInfoGid, strHandle);
Response.Write(strQuery);
}
}
else if (strReadXmlType.Equals("areaname"))
{
Response.Write(DoAreaname(strareaname));
}
else if (strReadXmlType.Equals("isout"))
{
Response.Write(Doisout(strGIDS));
}
else if (strReadXmlType.Equals("getacreage"))
{
Response.Write(getacreage(strareaname));
}
else if (strReadXmlType.Trim().ToLower().Equals("islock"))
{
Response.Write(setislock());
return;
}
else if (strReadXmlType == "notlock")
{
//取消入账信息
Response.Write(setnotlock());
}
else if (strReadXmlType == "getislock")
{
//判断是否入账信息
Response.Write(getislock());
}
else if (strReadXmlType == "setcopy")
{
//把某个月的数据复制到另一个月
Response.Write(setCopy());
}
else
{
string strOutputXml = "";
strOutputXml = GetCells(iShowCount, strReadXmlType);
//输出XML字符串
Response.ContentType = "text/xml";
strOutputXml.Replace("&", "&");
Response.Write(strOutputXml);
}
}
else
{
//访问参数不正确
Response.ContentType = "text/xml";
Response.Write("-2");
}
#endregion
}
private string setCopy()
{
string sGids = "insert into wms_fee select newid() as [GID]," + stryear2 + " as [FEEYEAR]," + strmonth2 + " as [FEEMONTH],[CLIENTNAME],[STORAGENAME],[AREANAME],[UNITPRICE],[ACREAGE],[ARFEE],[APFEE],[REMARK],0 as [ISLOCK],getdate() as [LOCKTIME],'' as [LOCKUSER],'" + strUserID + "' as [CREATEUSER],getdate() as [CREATETIME],'" + strUserID + "' as [MODIFIEDUSER],getdate() as [MODIFIEDTIME],[UNIT] from wms_fee where [FEEYEAR]=" + stryear1 + " and [FEEMONTH]=" + strmonth1;
T_ALL_DA T_ALL_DA = new T_ALL_DA();
bool bl = T_ALL_DA.GetExecuteSqlCommand(sGids);
return bl.ToString().Trim();
}
private string getislock()
{
string sGids = "'" + strGIDS.Replace(",", "','") + "'";
T_ALL_DA T_ALL_DA = new T_ALL_DA();
string ls = T_ALL_DA.GetStrSQL("nums", "select count(gid) nums from wms_fee where ISLOCK=1 and gid in (" + sGids + ")");
return ls;
}
private string setnotlock()
{
string sGids = "'" + strGIDS.Replace(",", "','") + "'";
T_ALL_DA T_ALL_DA = new T_ALL_DA();
string ls = T_ALL_DA.GetStrSQL("nums", "select count(gid) nums from ch_fee where (bsno in (" + sGids + ") or WMSOUTBSNO in (" + sGids + ")) and (ISINVOICE=1 or AUDITSTATUS=1 or ORDERINVOICE<>0.00 or DEBITNO is not null or (FEESTATUS<>0 and FEESTATUS<>1))");
if (ls.Trim() == "0")
{
ls = T_ALL_DA.GetStrSQL("nums", "select count(gid) nums from ch_fee_do where feeid in (select gid nums from ch_fee where (bsno in (" + sGids + ") or WMSOUTBSNO in (" + sGids + ")))");
if (ls.Trim() == "0")
{
WmsFeeDA WmsFeeDA = new WmsFeeDA();
int iResult = WmsFeeDA.setnotlock(strGIDS, strUserID);
if (iResult < 0)
{
return "操作有误,请重新操作!";
}
}
else
{
return "有“未申请开票、未开发票或未对帐”的入账数据,不允许取消入账,请重新操作!";
}
}
else
{
return "有“未申请开票、未开发票或未对帐”的入账数据,不允许取消入账,请重新操作!";
}
return "";
}
private string setislock()
{
WmsFeeDA WmsFeeDA = new WmsFeeDA();
int iResult = WmsFeeDA.setislock(strGIDS, strUserID);
if (iResult < 0)
{
return "操作有误,请重新操作!";
}
return "";
}
/// <summary>
/// 根据库位查出库位面积
/// </summary>
private string getacreage(string sareaname)
{
T_ALL_DA T_ALL_DA = new T_ALL_DA();
string sACREAGE = "select isnull(ACREAGE,0) as ACREAGE from wms_storage_area where AREANAME='" + sareaname.Trim() + "'";
sACREAGE = T_ALL_DA.GetStrSQL("ACREAGE", sACREAGE);
return sACREAGE;
}
/// <summary>
/// 根据仓库查出库位
/// </summary>
/// <param name="tempGid">账户GID</param>
/// <param name="tempHandle">操作类型 delete删除单条账户</param>
/// <returns>值1-删除成功;值-1 -删除操作异常 值-2 -回滚失败 值-3 -未获取相关账户信息</returns>
private string Doisout(string sGIDS)
{
T_ALL_DA T_ALL_DA = new T_ALL_DA();
string snum="select count(*) num from wms_out_detail where INBSNO in ('" + sGIDS.Trim() + "')";
snum = T_ALL_DA.GetStrSQL("num", snum);
return snum;
}
/// <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 = "";
WmsFeeDA WmsFeeDA = new WmsFeeDA();
//操作类型为删除
if (tempHandle == "delete")
{
int iResult = 0;
//先判断当前要删除的账户是否存在
if (!tempGid.Trim().Equals(""))
{
WmsFeeEntity WmsFeeEntity = new WmsFeeEntity();
WmsFeeEntity = WmsFeeDA.GetModel(tempGid);
if (WmsFeeEntity.GID != null)
{
iResult = WmsFeeDA.Delete(WmsFeeEntity.GID.ToString().Trim());
if (iResult>0)
{
iResult = 1;
}
else
{
iResult = -3; //未获取相关账户信息
}
}
else
{
iResult = -3; //未获取相关账户信息
}
}
strVal = iResult.ToString();
}
if (tempHandle == "recover")
{
if (!tempGid.Trim().Equals(""))
{
WmsFeeEntity WmsFeeEntity = new WmsFeeEntity();
WmsFeeEntity = WmsFeeDA.GetModel(tempGid);
if (WmsFeeEntity != null)
{
StringBuilder WMSZXBuilder = new StringBuilder();
WMSZXBuilder.Append(WmsFeeEntity.GID + ",");//惟一编号
WMSZXBuilder.Append("0,");
WMSZXBuilder.Append(WmsFeeEntity.CLIENTNAME + ",");//
WMSZXBuilder.Append(WmsFeeEntity.STORAGENAME + ",");//仓库名称
WMSZXBuilder.Append(WmsFeeEntity.AREANAME + ",");//库位名称
WMSZXBuilder.Append(WmsFeeEntity.UNITPRICE.ToString().Trim() + ",");//
WMSZXBuilder.Append(WmsFeeEntity.ACREAGE.ToString().Trim() + ",");//
WMSZXBuilder.Append(WmsFeeEntity.ARFEE.ToString().Trim() + ",");//
WMSZXBuilder.Append(WmsFeeEntity.UNIT + ",");//
WMSZXBuilder.Append(WmsFeeEntity.REMARK + ",");//
if (WmsFeeEntity.ISLOCK)
{
WMSZXBuilder.Append("是");
}
else
{
WMSZXBuilder.Append("否");
}
strVal = WMSZXBuilder.ToString();
}
else
{
strVal = "-3";
}
}
else
{
strVal = "-3";
}
}
return strVal;
}
/// <summary>
/// 获取账户信息
/// </summary>
/// <returns></returns>
private string GetCells(int iShowCount, string readXmlType)
{
WmsFeeDA WmsZXInfoEntity = new WmsFeeDA();
WmsFeeDA WmsFeeDA = new WmsFeeDA();
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>");
//
string strcb = GetCRMClientCells("");
if (strcb.Trim() == "")
{
dataBuilder.Append("<cell></cell>");
}
else
{
dataBuilder.Append(strcb);
}
//
strcb = GetSTORAGENAMECells("");
if (strcb.Trim() == "")
{
dataBuilder.Append("<cell></cell>");
}
else
{
dataBuilder.Append(strcb);
}
//
strcb = GetAREANAME("","");
if (strcb.Trim() == "")
{
dataBuilder.Append("<cell></cell>");
}
else
{
dataBuilder.Append(strcb);
}
//
dataBuilder.Append("<cell>0.00</cell>");
dataBuilder.Append("<cell>0.00</cell>");
dataBuilder.Append("<cell>0.00</cell>");
//
strcb = GetUNIT("");
if (strcb.Trim() == "")
{
dataBuilder.Append("<cell></cell>");
}
else
{
dataBuilder.Append(strcb);
}
//
dataBuilder.Append("<cell></cell>");
dataBuilder.Append("<cell>否</cell>");
//
dataBuilder.Append("</row>");
dataBuilder.Append("</rows>");
return dataBuilder.ToString();
}
else if (!strReadXmlType.Equals("exist"))
{
//获取所有账户信息,用做Grid显示
DataTable WmsZXFeeTable = new DataTable();
//初始化
string strInitSql = " SELECT GID,CLIENTNAME,STORAGENAME,AREANAME,UNITPRICE,ACREAGE,ARFEE,UNIT,REMARK,ISLOCK FROM wms_fee WHERE 1=1 and FEEYEAR='" + stryear.Trim() + "' and FEEMONTH='" + strmonth.Trim() + "' ORDER BY MODIFIEDTIME desc";
WmsZXFeeTable = getStatusNameTable(WmsFeeDA.GetExcuteSql(strInitSql).Tables[0]);
//编排字符串 xml串
StringBuilder dataBuilder = new StringBuilder();
dataBuilder.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
dataBuilder.Append("<rows>");
int iCount = WmsZXFeeTable.Rows.Count;
for (int i = 0; i < iCount; i++)
{
int jCount = WmsZXFeeTable.Columns.Count;
dataBuilder.Append("<row id=\"" + WmsZXFeeTable.Rows[i]["GID"].ToString() + "\">");
dataBuilder.Append("<cell>0</cell>");
for (int j = 1; j < jCount; j++)
{
string strclient="";
switch (j)
{
case 1:
string xl = GetCRMClientCells(WmsZXFeeTable.Rows[i][j].ToString().Trim());
if (xl != "")
{
dataBuilder.Append(xl);
}
else
{
dataBuilder.Append("<cell>" + WmsZXFeeTable.Rows[i][j].ToString() + "</cell>");
}
break;
case 2:
strclient = WmsZXFeeTable.Rows[i][j].ToString().Trim();
xl = GetSTORAGENAMECells(WmsZXFeeTable.Rows[i][j].ToString().Trim());
if (xl != "")
{
dataBuilder.Append(xl);
}
else
{
dataBuilder.Append("<cell>" + WmsZXFeeTable.Rows[i][j].ToString() + "</cell>");
}
break;
case 3:
xl = GetAREANAME(WmsZXFeeTable.Rows[i][j].ToString().Trim(), strclient);
if (xl != "")
{
dataBuilder.Append(xl);
}
else
{
dataBuilder.Append("<cell>" + WmsZXFeeTable.Rows[i][j].ToString() + "</cell>");
}
break;
case 4:
dataBuilder.Append("<cell>" + WmsZXFeeTable.Rows[i][j].ToString() + "</cell>");
break;
case 5:
dataBuilder.Append("<cell>" + WmsZXFeeTable.Rows[i][j].ToString() + "</cell>");
break;
case 6:
dataBuilder.Append("<cell>" + WmsZXFeeTable.Rows[i][j].ToString() + "</cell>");
break;
case 7:
xl = GetUNIT(WmsZXFeeTable.Rows[i][j].ToString().Trim());
if (xl != "")
{
dataBuilder.Append(xl);
}
else
{
dataBuilder.Append("<cell>" + WmsZXFeeTable.Rows[i][j].ToString() + "</cell>");
}
break;
case 8:
dataBuilder.Append("<cell>" + WmsZXFeeTable.Rows[i][j].ToString() + "</cell>");
break;
case 9:
if (WmsZXFeeTable.Rows[i][j].ToString().Trim()=="True")
{
dataBuilder.Append("<cell>是</cell>");
}
else
{
dataBuilder.Append("<cell>否</cell>");
}
break;
}
}
dataBuilder.Append("</row>");
}
dataBuilder.Append("</rows>");
return dataBuilder.ToString();
}
else
{
return "-3";//没有相关的账户
}
}
/// <summary>
/// 获取数量单位信息下拉列表
/// </summary>
/// <param name="strUNIT">获取数量单位值</param>
/// <returns></returns>
public string GetUNIT(string strUNIT)
{
StringBuilder clientBuilder = new StringBuilder();
clientBuilder.Append("<cell xmlcontent=\"1\" editable=\"1\">" + strUNIT);
clientBuilder.Append("<option value=\"重量\">重量</option>");
clientBuilder.Append("<option value=\"面积\">面积</option>");
clientBuilder.Append("<option value=\"\"></option>");
clientBuilder.Append("</cell>");
return clientBuilder.ToString();
}
/// <summary>
/// 获取库位信息下拉列表
/// </summary>
/// <param name="strClientValue">获取库位信息下拉列表id值</param>
/// <returns></returns>
public string GetAREANAME(string strAREANAME,string strClientValue)
{
T_ALL_DA T_ALL_DA = new T_ALL_DA();
string ls = "";
if (strClientValue.Trim() != "")
{
ls = " and STORAGENAME='" + ls + "'";
}
StringBuilder clientBuilder = new StringBuilder();
clientBuilder.Append("<cell xmlcontent=\"1\" editable=\"1\">" + strAREANAME);
//DataSet ds = T_ALL_DA.GetAllSQL("select * from wms_storage_area where 1=1 " + ls + " and ISENABLE=1 order by AREANAME");
//if (ds != null)
//{
// for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
// {
// if (!ds.Tables[0].Rows[i]["AREACODE"].ToString().Trim().Equals(""))
// {
// ls = ds.Tables[0].Rows[i]["AREACODE"].ToString() + " | " + ds.Tables[0].Rows[i]["AREANAME"].ToString();
// clientBuilder.Append("<option value=\"" + ls + "\">" + ls + "</option>");
// }
// }
//}
clientBuilder.Append("<option value=\"\"></option>");
clientBuilder.Append("</cell>");
return clientBuilder.ToString();
}
#region 根据仓库查出库位信息返回JSON数据源
/// <summary>
/// 根据仓库查出库位信息返回JSON数据源
/// </summary>
/// <returns>返回JSON数据源</returns>
private string DoAreaname(string strClientValue)
{
StringBuilder sourceBuilder = new StringBuilder();
StringBuilder itemBuilder = new StringBuilder();
sourceBuilder.Append("{");
sourceBuilder.Append("area:[");
T_ALL_DA T_ALL_DA = new T_ALL_DA();
string ls = "";
if (strClientValue.Trim() != "")
{
ls = " and STORAGENAME='" + strClientValue + "'";
}
DataSet ds = T_ALL_DA.GetAllSQL("select * from wms_storage_area where 1=1 " + ls + " and ISENABLE=1 order by AREANAME");
if (ds != null)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
//ls = ds.Tables[0].Rows[i]["AREACODE"].ToString() + " | " + ds.Tables[0].Rows[i]["AREANAME"].ToString();
//clientBuilder.Append("<option value=\"" + ls + "\">" + ls + "</option>");
itemBuilder.Append("{name:\"" + ds.Tables[0].Rows[i]["AREANAME"].ToString() + "\",");
itemBuilder.Append("num:" + i+1 + "");
itemBuilder.Append("},");
}
if (itemBuilder.ToString().EndsWith(","))
{
sourceBuilder.Append(itemBuilder.ToString().Trim().Substring(0, itemBuilder.ToString().Trim().Length - 1));
}
else
{
sourceBuilder.Append(itemBuilder.ToString());
}
}
else
{
itemBuilder.Append("{name:\"\",");
itemBuilder.Append("num:0");
itemBuilder.Append("}");
}
sourceBuilder.Append("]");
sourceBuilder.Append("}");
return sourceBuilder.ToString();
}
#endregion
/// <summary>
/// 获取信息下拉列表——客户
/// </summary>
/// <param name="strClientValue">当前列表客户信息值</param>
/// <returns></returns>
public string GetCRMClientCells(string strClientValue)
{
T_ALL_DA T_ALL_DA = new T_ALL_DA();
DataSet ds = T_ALL_DA.GetWebCrmClient("ISCONTROLLER", strCompanyID);
if (ds != null)
{
DataTable clientTable = ds.Tables[0];
if (clientTable != null)
{
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(""))
{
string ls = clientTable.Rows[i]["CODENAME"].ToString().ToUpper() + " | " + clientTable.Rows[i]["SHORTNAME"].ToString();
clientBuilder.Append("<option value=\"" + ls + "\">" + ls + "</option>");
}
}
clientBuilder.Append("</cell>");
return clientBuilder.ToString();
}
}
return "";
}
/// <summary>
/// 获取信息下拉列表——仓库
/// </summary>
/// <param name="strClientValue">当前列表客户信息值</param>
/// <returns></returns>
public string GetSTORAGENAMECells(string strSTORAGENAME)
{
T_ALL_DA T_ALL_DA = new T_ALL_DA();
DataSet ds = T_ALL_DA.GetWebCrmClient("ISWAREHOUSE", strCompanyID);
if (ds != null)
{
DataTable clientTable = ds.Tables[0];
if (clientTable != null)
{
StringBuilder clientBuilder = new StringBuilder();
clientBuilder.Append("<cell xmlcontent=\"1\" editable=\"1\">" + strSTORAGENAME);
for (int i = 0; i < clientTable.Rows.Count; i++)
{
if (!clientTable.Rows[i]["SHORTNAME"].ToString().Trim().Equals(""))
{
string ls = clientTable.Rows[i]["CODENAME"].ToString().ToUpper() + " | " + clientTable.Rows[i]["SHORTNAME"].ToString();
clientBuilder.Append("<option value=\"" + ls + "\">" + ls + "</option>");
}
}
clientBuilder.Append("</cell>");
return clientBuilder.ToString();
}
}
return "";
}
/// <summary>
/// 将数据集表中账户状态WmsZXInfoStatus和应收应付类型WmsZXInfoType的数字状态位转换成文字
/// </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;
}
//
}
}