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 ""; } /// /// 根据库位查出库位面积 /// 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; } /// /// 根据仓库查出库位 /// /// 账户GID /// 操作类型 delete删除单条账户 /// 值1-删除成功;值-1 -删除操作异常 值-2 -回滚失败 值-3 -未获取相关账户信息 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; } /// /// 根据用户提交的 /// /// 账户GID /// 操作类型 delete删除单条账户 /// 值1-删除成功;值-1 -删除操作异常 值-2 -回滚失败 值-3 -未获取相关账户信息 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; } /// /// 获取账户信息 /// /// 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(""); dataBuilder.Append(""); dataBuilder.Append(""); // dataBuilder.Append("0"); // string strcb = GetCRMClientCells(""); if (strcb.Trim() == "") { dataBuilder.Append(""); } else { dataBuilder.Append(strcb); } // strcb = GetSTORAGENAMECells(""); if (strcb.Trim() == "") { dataBuilder.Append(""); } else { dataBuilder.Append(strcb); } // strcb = GetAREANAME("",""); if (strcb.Trim() == "") { dataBuilder.Append(""); } else { dataBuilder.Append(strcb); } // dataBuilder.Append("0.00"); dataBuilder.Append("0.00"); dataBuilder.Append("0.00"); // strcb = GetUNIT(""); if (strcb.Trim() == "") { dataBuilder.Append(""); } else { dataBuilder.Append(strcb); } // dataBuilder.Append(""); dataBuilder.Append(""); // dataBuilder.Append(""); dataBuilder.Append(""); 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(""); dataBuilder.Append(""); int iCount = WmsZXFeeTable.Rows.Count; for (int i = 0; i < iCount; i++) { int jCount = WmsZXFeeTable.Columns.Count; dataBuilder.Append(""); dataBuilder.Append("0"); 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("" + WmsZXFeeTable.Rows[i][j].ToString() + ""); } 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("" + WmsZXFeeTable.Rows[i][j].ToString() + ""); } break; case 3: xl = GetAREANAME(WmsZXFeeTable.Rows[i][j].ToString().Trim(), strclient); if (xl != "") { dataBuilder.Append(xl); } else { dataBuilder.Append("" + WmsZXFeeTable.Rows[i][j].ToString() + ""); } break; case 4: dataBuilder.Append("" + WmsZXFeeTable.Rows[i][j].ToString() + ""); break; case 5: dataBuilder.Append("" + WmsZXFeeTable.Rows[i][j].ToString() + ""); break; case 6: dataBuilder.Append("" + WmsZXFeeTable.Rows[i][j].ToString() + ""); break; case 7: xl = GetUNIT(WmsZXFeeTable.Rows[i][j].ToString().Trim()); if (xl != "") { dataBuilder.Append(xl); } else { dataBuilder.Append("" + WmsZXFeeTable.Rows[i][j].ToString() + ""); } break; case 8: dataBuilder.Append("" + WmsZXFeeTable.Rows[i][j].ToString() + ""); break; case 9: if (WmsZXFeeTable.Rows[i][j].ToString().Trim()=="True") { dataBuilder.Append(""); } else { dataBuilder.Append(""); } break; } } dataBuilder.Append(""); } dataBuilder.Append(""); return dataBuilder.ToString(); } else { return "-3";//没有相关的账户 } } /// /// 获取数量单位信息下拉列表 /// /// 获取数量单位值 /// public string GetUNIT(string strUNIT) { StringBuilder clientBuilder = new StringBuilder(); clientBuilder.Append("" + strUNIT); clientBuilder.Append(""); clientBuilder.Append(""); clientBuilder.Append(""); clientBuilder.Append(""); return clientBuilder.ToString(); } /// /// 获取库位信息下拉列表 /// /// 获取库位信息下拉列表id值 /// 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("" + 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(""); // } // } //} clientBuilder.Append(""); clientBuilder.Append(""); return clientBuilder.ToString(); } #region 根据仓库查出库位信息,返回JSON数据源 /// /// 根据仓库查出库位信息,返回JSON数据源 /// /// 返回JSON数据源 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(""); 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 /// /// 获取信息下拉列表——客户 /// /// 当前列表客户信息值 /// 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("" + 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(""); } } clientBuilder.Append(""); return clientBuilder.ToString(); } } return ""; } /// /// 获取信息下拉列表——仓库 /// /// 当前列表客户信息值 /// 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("" + 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(""); } } clientBuilder.Append(""); return clientBuilder.ToString(); } } return ""; } /// /// 将数据集表中账户状态WmsZXInfoStatus和应收应付类型WmsZXInfoType的数字状态位转换成文字 /// /// 原数据源DataTable /// 返回新数据源DataTable 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; } // } }