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 WmsZXInfoGridSource : 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 strGID;// public string strGIDS;// public string strgoodspack;// public string strgoodname;// 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(); } 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["id"] != null) { strGID = Request.QueryString["id"].ToString(); } if (Request.QueryString["gids"] != null) { strGIDS = Request.QueryString["gids"].ToString(); } if (Request.QueryString["goodspack"] != null) { strgoodspack = Request.QueryString["goodspack"].ToString(); } if (Request.QueryString["goodsrksl"] != null) { strgoodsrksl = Request.QueryString["goodsrksl"].ToString(); } if (Request.QueryString["goodname"] != null) { UnicodeEncoding unicode = new UnicodeEncoding(); strgoodname = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["goodname"].ToString().Trim()))); } if (Request.QueryString["areaname"] != null) { UnicodeEncoding unicode = new UnicodeEncoding(); strareaname = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["areaname"].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")) { 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("goodsrksl")) { Response.Write(DoGoodspack(strgoodsrksl, strgoodname)); } else if (strReadXmlType.Equals("areaname")) { Response.Write(DoAreaname(strareaname)); } else if (strReadXmlType.Equals("isout")) { Response.Write(Doisout(strGIDS)); } 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"); } } /// /// 根据仓库查出库位 /// /// 账户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 DoGoodspack(string sGoodsrksl, string strgoodname) { string strVal = ""; Decimal dARRATE = 0; Decimal dAPRATE = 0; Decimal dGoodspack = 0; if (sGoodsrksl.Trim().Length > 0) { dGoodspack = Decimal.Parse(sGoodsrksl); } // T_ALL_DA T_ALL_DA = new T_ALL_DA(); DataSet DS = T_ALL_DA.GetAllSQL("select * from code_goods where goodname='" + strgoodname.Trim() + "'"); if (DS != null) { if(DS.Tables[0].Rows.Count>0) { if (DS.Tables[0].Rows[0]["ARRATE"].ToString().Trim() != "") { dARRATE = Decimal.Parse(DS.Tables[0].Rows[0]["ARRATE"].ToString().Trim()); } if (DS.Tables[0].Rows[0]["APRATE"].ToString().Trim() != "") { dAPRATE = Decimal.Parse(DS.Tables[0].Rows[0]["APRATE"].ToString().Trim()); } // dARRATE = dARRATE * dGoodspack; if (dARRATE != 0) { dARRATE = Decimal.Parse(dARRATE.ToString("#.##")); } dAPRATE = dAPRATE * dGoodspack; if (dAPRATE != 0) { dARRATE = Decimal.Parse(dARRATE.ToString("#.##")); } } } // string sARRATE = "0.00"; string sAPRATE = "0.00"; if (dARRATE != 0) { sARRATE = dARRATE.ToString("F2").Trim(); } if (dAPRATE != 0) { sAPRATE = dAPRATE.ToString("F2").Trim(); } strVal = sARRATE + "," + sAPRATE; return strVal; } /// /// 根据用户提交的 /// /// 账户GID /// 操作类型 delete删除单条账户 /// 值1-删除成功;值-1 -删除操作异常 值-2 -回滚失败 值-3 -未获取相关账户信息 private string DoExcute(string tempGid, string tempHandle) { string strVal = ""; WmsInDA WmsInDA = new WmsInDA(); //操作类型为删除 if (tempHandle == "delete") { int iResult = 0; //先判断当前要删除的账户是否存在 if (!tempGid.Trim().Equals("")) { WmsInEntity WmsInEntity = new WmsInEntity(); WmsInEntity = WmsInDA.GetID(tempGid); if (WmsInEntity.GID != null) { string alt = ""; alt = WmsInDA.GetWmsInDel(WmsInEntity.GID.ToString().Trim(), strUserID); if (alt.Trim() == "") { iResult = 1; } else { iResult = -3; //未获取相关账户信息 } } else { iResult = -3; //未获取相关账户信息 } } strVal = iResult.ToString(); } if (tempHandle == "recover") { if (!tempGid.Trim().Equals("")) { WmsInEntity WmsInEntity = new WmsInEntity(); WmsInEntity = WmsInDA.GetID(tempGid); if (WmsInEntity != null) { StringBuilder WMSZXBuilder = new StringBuilder(); WMSZXBuilder.Append(WmsInEntity.GID + ",");//惟一编号 WMSZXBuilder.Append("0,"); WMSZXBuilder.Append(WmsInEntity.STORAGENAME + ",");//仓库名称 WMSZXBuilder.Append(WmsInEntity.AREANAME + ",");//库位名称 WMSZXBuilder.Append(WmsInEntity.GOODSNAME + ",");//货物名称 WMSZXBuilder.Append(WmsInEntity.GOODSMODEL + ",");//型号 WMSZXBuilder.Append(WmsInEntity.CHARGEUNIT + ",");//计费单位 WMSZXBuilder.Append(WmsInEntity.GOODSPACK + ",");//件数 WMSZXBuilder.Append(WmsInEntity.GOODSRKSL + ",");//计费数量 WMSZXBuilder.Append(WmsInEntity.ARFEE + ",");//应收账款 WMSZXBuilder.Append(WmsInEntity.APFEE + ",");//应付账款 WMSZXBuilder.Append(WmsInEntity.REMARK);//备注 strVal = WMSZXBuilder.ToString(); } else { strVal = "-3"; } } else { strVal = "-3"; } } return strVal; } /// /// 获取账户信息 /// /// private string GetCells(int iShowCount, string readXmlType) { WmsInDA WmsZXInfoEntity = new WmsInDA(); WmsInDA WmsInDA = new WmsInDA(); 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 = GetAREANAME("",""); if (strcb.Trim() == "") { dataBuilder.Append(""); } else { dataBuilder.Append(strcb); } // strcb = GetGOODSNAME(""); if (strcb.Trim() == "") { dataBuilder.Append(""); } else { dataBuilder.Append(strcb); } // dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append("0.0000"); dataBuilder.Append("0.0000"); dataBuilder.Append("0.00"); dataBuilder.Append("0.00"); dataBuilder.Append(""); // dataBuilder.Append(""); dataBuilder.Append(""); return dataBuilder.ToString(); } else if (!strReadXmlType.Equals("exist")) { //获取所有账户信息,用做Grid显示 DataTable WmsZXInfoTable = new DataTable(); //初始化 string strInitSql = ""; if (strGID.ToString().Trim() == "") { strInitSql = " SELECT GID,STORAGENAME,AREANAME,GOODSNAME,GOODSMODEL,CHARGEUNIT,GOODSPACK,GOODSRKSL,ARFEE,APFEE,REMARK,GOODSPACKSTOCK,ASSOCIATEDNO,MODIFIEDTIME FROM wms_in WHERE 1<0"; } else { strInitSql = " SELECT GID,STORAGENAME,AREANAME,GOODSNAME,GOODSMODEL,CHARGEUNIT,GOODSPACK,GOODSRKSL,ARFEE,APFEE,REMARK,GOODSPACKSTOCK,ASSOCIATEDNO,MODIFIEDTIME FROM wms_in WHERE 1=1 and ASSOCIATEDNO='" + strGID.ToString().Trim() + "'" + strRange + " ORDER BY MODIFIEDTIME desc"; } WmsZXInfoTable = getStatusNameTable(WmsInDA.GetExcuteSql(strInitSql).Tables[0]); //编排字符串 xml串 StringBuilder dataBuilder = new StringBuilder(); dataBuilder.Append(""); dataBuilder.Append(""); int iCount = WmsZXInfoTable.Rows.Count; for (int i = 0; i < iCount; i++) { int jCount = WmsZXInfoTable.Columns.Count; dataBuilder.Append(""); dataBuilder.Append("0"); for (int j = 1; j < jCount; j++) { string strclient=""; switch (j) { //GID,STORAGENAME,AREANAME,GOODSNAME,GOODSMODEL,CHARGEUNIT,GOODSPACK,ARFEE,APFEE,REMARK,ASSOCIATEDNO case 1: strclient = WmsZXInfoTable.Rows[i][j].ToString().Trim(); string xl = GetCRMClientCells(WmsZXInfoTable.Rows[i][j].ToString().Trim()); if (xl != "") { dataBuilder.Append(xl); } else { dataBuilder.Append("" + WmsZXInfoTable.Rows[i][j].ToString() + ""); } break; case 2: xl = GetAREANAME(WmsZXInfoTable.Rows[i][j].ToString().Trim(), strclient); if (xl != "") { dataBuilder.Append(xl); } else { dataBuilder.Append("" + WmsZXInfoTable.Rows[i][j].ToString() + ""); } break; case 3: xl = GetGOODSNAME(WmsZXInfoTable.Rows[i][j].ToString().Trim()); if (xl != "") { dataBuilder.Append(xl); } else { dataBuilder.Append("" + WmsZXInfoTable.Rows[i][j].ToString() + ""); } break; case 4: dataBuilder.Append("" + WmsZXInfoTable.Rows[i][j].ToString() + ""); break; case 5: dataBuilder.Append("" + WmsZXInfoTable.Rows[i][j].ToString() + ""); break; case 6: dataBuilder.Append("" + WmsZXInfoTable.Rows[i][j].ToString() + ""); break; case 7: dataBuilder.Append("" + WmsZXInfoTable.Rows[i][j].ToString() + ""); break; case 8: dataBuilder.Append("" + WmsZXInfoTable.Rows[i][j].ToString() + ""); break; case 9: dataBuilder.Append("" + WmsZXInfoTable.Rows[i][j].ToString() + ""); break; case 10: dataBuilder.Append("" + WmsZXInfoTable.Rows[i][j].ToString() + ""); break; case 11: dataBuilder.Append("" + WmsZXInfoTable.Rows[i][j].ToString() + ""); break; } } dataBuilder.Append(""); } dataBuilder.Append(""); return dataBuilder.ToString(); } else { return "-3";//没有相关的账户 } } /// /// 获取品名信息下拉列表 /// /// 获取品名信息下拉列表id值 /// public string GetGOODSNAME(string strGOODNAME) { T_ALL_DA T_ALL_DA = new T_ALL_DA(); DataSet ds = T_ALL_DA.GetAllSQL("select * from code_goods where ISSTOP=0 order by GOODNAME"); if (ds != null) { StringBuilder clientBuilder = new StringBuilder(); clientBuilder.Append("" + strGOODNAME); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (!ds.Tables[0].Rows[i]["GOODCODE"].ToString().Trim().Equals("")) { string ls = ds.Tables[0].Rows[i]["GOODCODE"].ToString() + " | " + ds.Tables[0].Rows[i]["GOODNAME"].ToString(); clientBuilder.Append(""); } } clientBuilder.Append(""); return clientBuilder.ToString(); } else { return ""; } } /// /// 获取库位信息下拉列表 /// /// 获取库位信息下拉列表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 /// /// 获取CRM系统客户信息下拉列表——仓库 /// /// 当前列表客户信息值 /// public string GetCRMClientCells(string strClientValue) { T_ALL_DA T_ALL_DA = new T_ALL_DA(); DataSet ds = T_ALL_DA.GetWebCrmClient("ISWAREHOUSE", strCompanyID); 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(); } else { 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; } // } }