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.SeaiFee { public partial class WmsRateDetailGridSource : System.Web.UI.Page { private string strReadXmlType = "";//读取xml串方式 "init"-初始化获取所有账户信息;"add"-添加新的账户信息;"delete"-删除账户信息;"exist"查看是否有与委托相关账户 private int iShowCount;//每页显示数据量 //delete private string strWmsRateGid;//账户信息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 strParentGID;// public string strassociatedno;// public string strGIDS;// public string strgoodspack;// public string strgoodname;// public string strgoodsrksl;// public string strcntrno;// 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) { strParentGID = Request.QueryString["id"].ToString(); } if (Request.QueryString["associatedno"] != null) { strassociatedno = Request.QueryString["associatedno"].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["cntrno"] != null) { UnicodeEncoding unicode = new UnicodeEncoding(); strcntrno = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["cntrno"].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")) { strWmsRateGid = (String)Request.QueryString["gid"] as String; strHandle = (String)Request.QueryString["read"] as String; if (strWmsRateGid == null || strHandle == null) { Response.Write(iResult); } else { string strQuery = DoExcute(strWmsRateGid, strHandle); Response.Write(strQuery); } } 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 DoExcute(string tempGid, string tempHandle) { string strVal = ""; WmsRateDetailDA WmsRateDetailDA = new WmsRateDetailDA(); //操作类型为删除 if (tempHandle == "delete") { int iResult = 0; //先判断当前要删除的账户是否存在 if (!tempGid.Trim().Equals("")) { tempGid = "'" + tempGid.Replace(",","','") + "'"; string txt_outbsno = T_ALL_DA.GetStrSQL("outbsno", "select top 1 outbsno from wms_out_detail where gid in (select ASSOCIATEDNO from wms_rate_detail where gid in(" + tempGid + "))"); bool bl = WmsRateDetailDA.DeleteList(tempGid.Trim(), strUserID, strShowName, txt_outbsno); if (bl) { iResult = 1; } else { iResult = -3; //未获取相关账户信息 } } strVal = iResult.ToString(); } else if (tempHandle == "recover") { if (!tempGid.Trim().Equals("")) { WmsRateDetailEntity WmsRateDetailEntity = new WmsRateDetailEntity(); WmsRateDetailEntity = WmsRateDetailDA.GetModel(tempGid); if (WmsRateDetailEntity != null) { StringBuilder WMSBuilder = new StringBuilder(); WMSBuilder.Append(WmsRateDetailEntity.GID + ",");//惟一编号 WMSBuilder.Append("0,"); WMSBuilder.Append(WmsRateDetailEntity.FEEGRADE + ",");//费用等级 if (WmsRateDetailEntity.FEETYPE == 1) { WMSBuilder.Append("收,");//费用类别 } else { WMSBuilder.Append("付,");//费用类别 } WMSBuilder.Append(WmsRateDetailEntity.STARTBILLINGDATE + ",");//开始计费日期 WMSBuilder.Append(WmsRateDetailEntity.ENDBILLINGDATE + ",");//结束计费日期 WMSBuilder.Append(WmsRateDetailEntity.FEESCALE + ",");//计费区间 WMSBuilder.Append(WmsRateDetailEntity.FEEUNIT + ",");//单位 WMSBuilder.Append(WmsRateDetailEntity.FEEPRICE + ",");//单价 WMSBuilder.Append(WmsRateDetailEntity.GOODSPFSL + ",");//单价 WMSBuilder.Append(WmsRateDetailEntity.OUTFEE + ",");//单价 WMSBuilder.Append(WmsRateDetailEntity.REMARK + ",");//备注 WMSBuilder.Append(WmsRateDetailEntity.CREATEUSER);//创建人 WMSBuilder.Append(WmsRateDetailEntity.CREATETIME + ",");//创建时间 WMSBuilder.Append(WmsRateDetailEntity.ASSOCIATEDNO);// strVal = WMSBuilder.ToString(); } else { strVal = "-3"; } } else { strVal = "-3"; } } return strVal; } /// /// 获取账户信息 /// /// private string GetCells(int iShowCount, string readXmlType) { WmsRateDetailDA WmsRateDetailEntity = new WmsRateDetailDA(); WmsRateDetailDA WmsRateDetailDA = new WmsRateDetailDA(); if (strReadXmlType.Equals("exist")) { return "1";//存在账户 } else if (strReadXmlType.Equals("add")) { StringBuilder dataBuilder = new StringBuilder(); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(""); // dataBuilder.Append("0");//全不选 dataBuilder.Append("1");//计费等级 // string strcb = GetFEETYPE("收");//费用类别 if (strcb.Trim() == "") { dataBuilder.Append(""); } else { dataBuilder.Append(strcb); } // dataBuilder.Append("");//开始计费日期 dataBuilder.Append("");//结束计费日期 dataBuilder.Append("");//计费区间 strcb = GetFEEUNIT("吨天");//单位 if (strcb.Trim() == "") { dataBuilder.Append("吨天"); } else { dataBuilder.Append(strcb); } dataBuilder.Append("0.00");//单价 dataBuilder.Append("0.0000");//出库量 dataBuilder.Append("0.00");//仓储费 dataBuilder.Append("");//备注 dataBuilder.Append("");//创建人 dataBuilder.Append("");//创建时间 dataBuilder.Append("");// // dataBuilder.Append(""); dataBuilder.Append(""); return dataBuilder.ToString(); } else if (!strReadXmlType.Equals("exist")) { //获取所有账户信息,用做Grid显示 DataTable WmsRateTable = new DataTable(); //初始化 string strInitSql = ""; if (strParentGID.ToString().Trim() == "") { strInitSql = " SELECT GID,FEEGRADE,FEETYPE,convert(char(10),STARTBILLINGDATE,20) AS STARTBILLINGDATE,convert(char(10),ENDBILLINGDATE,20) AS ENDBILLINGDATE,FEESCALE,FEEUNIT,FEEPRICE,GOODSPFSL,OUTFEE,REMARK,MODIFIEDUSER=(select top 1 SHOWNAME from [user] where gid=wms_rate_detail.MODIFIEDUSER),MODIFIEDTIME,ASSOCIATEDNO FROM wms_rate_detail WHERE 1<0"; } else { if (strassociatedno.ToString().Trim() == "") { strInitSql = " SELECT GID,FEEGRADE,FEETYPE,convert(char(10),STARTBILLINGDATE,20) AS STARTBILLINGDATE,convert(char(10),ENDBILLINGDATE,20) AS ENDBILLINGDATE,FEESCALE,FEEUNIT,FEEPRICE,GOODSPFSL,OUTFEE,REMARK,MODIFIEDUSER=(select top 1 SHOWNAME from [user] where gid=wms_rate_detail.MODIFIEDUSER),MODIFIEDTIME,ASSOCIATEDNO FROM wms_rate_detail WHERE 1=1 and ASSOCIATEDNO in (select GID from wms_out_detail where OUTBSNO in (select bsno from wms_out where gid='" + strParentGID.ToString().Trim() + "'))" + strRange + " ORDER BY ASSOCIATEDNO,FEETYPE,FEEGRADE,CREATETIME"; } else { strInitSql = " SELECT GID,FEEGRADE,FEETYPE,convert(char(10),STARTBILLINGDATE,20) AS STARTBILLINGDATE,convert(char(10),ENDBILLINGDATE,20) AS ENDBILLINGDATE,FEESCALE,FEEUNIT,FEEPRICE,GOODSPFSL,OUTFEE,REMARK,MODIFIEDUSER=(select top 1 SHOWNAME from [user] where gid=wms_rate_detail.MODIFIEDUSER),MODIFIEDTIME,ASSOCIATEDNO FROM wms_rate_detail WHERE 1=1 and ASSOCIATEDNO='" + strassociatedno.ToString().Trim() + "'" + strRange + " ORDER BY ASSOCIATEDNO,FEETYPE,FEEGRADE,CREATETIME"; } } WmsRateTable = getStatusNameTable(WmsRateDetailDA.GetExcuteSql(strInitSql).Tables[0]); //编排字符串 xml串 StringBuilder dataBuilder = new StringBuilder(); dataBuilder.Append(""); dataBuilder.Append(""); int iCount = WmsRateTable.Rows.Count; for (int i = 0; i < iCount; i++) { int jCount = WmsRateTable.Columns.Count; dataBuilder.Append(""); dataBuilder.Append("0"); for (int j = 1; j < jCount; j++) { switch (j) { case 1: dataBuilder.Append("" + WmsRateTable.Rows[i][j].ToString() + "");//计费等级 break; case 2: //string xl = GetFEETYPE(WmsRateTable.Rows[i][j].ToString().Trim());//费用类别 //if (xl != "") //{ // dataBuilder.Append(xl); //} //else //{ // dataBuilder.Append("" + WmsRateTable.Rows[i][j].ToString() + ""); //} if (WmsRateTable.Rows[i][j].ToString() == "1") { dataBuilder.Append("");//费用类别 } else { dataBuilder.Append("");//费用类别 } break; case 3: dataBuilder.Append("" + WmsRateTable.Rows[i][j].ToString() + "");//开始计费日期 break; case 4: dataBuilder.Append("" + WmsRateTable.Rows[i][j].ToString() + "");//结束计费日期 break; case 5: dataBuilder.Append("" + WmsRateTable.Rows[i][j].ToString() + "");//计费区间 break; case 6: //xl = GetFEEUNIT(WmsRateTable.Rows[i][j].ToString().Trim());//单位 //if (xl != "") //{ // dataBuilder.Append(xl); //} //else //{ // dataBuilder.Append("" + WmsRateTable.Rows[i][j].ToString() + ""); //} dataBuilder.Append("" + WmsRateTable.Rows[i][j].ToString() + ""); break; case 7: dataBuilder.Append("" + WmsRateTable.Rows[i][j].ToString() + "");//单价 break; case 8: dataBuilder.Append("" + WmsRateTable.Rows[i][j].ToString() + "");//出库量 break; case 9: dataBuilder.Append("" + WmsRateTable.Rows[i][j].ToString() + "");//仓储费 break; case 10: dataBuilder.Append("" + WmsRateTable.Rows[i][j].ToString() + "");//备注 break; case 11: dataBuilder.Append("" + WmsRateTable.Rows[i][j].ToString() + "");//创建人 break; case 12: dataBuilder.Append("" + WmsRateTable.Rows[i][j].ToString() + "");//创建时间 break; case 13: dataBuilder.Append("" + WmsRateTable.Rows[i][j].ToString() + "");//创建时间 break; } } dataBuilder.Append(""); } dataBuilder.Append(""); return dataBuilder.ToString(); } else { return "-3";//没有相关的账户 } } /// /// 获取当前业务录入的区别费用收、付类型 /// /// 当前业务GID /// public string GetFEETYPE(string strFEETYPE) { StringBuilder sBuilder = new StringBuilder(); sBuilder.Append("" + strFEETYPE); sBuilder.Append(""); sBuilder.Append(""); sBuilder.Append(""); return sBuilder.ToString(); } /// /// 获取当前业务录入的区别费用收、付类型 /// /// 当前业务GID /// public string GetFEEUNIT(string strFEEUNIT) { StringBuilder sBuilder = new StringBuilder(); sBuilder.Append("" + strFEEUNIT); sBuilder.Append(""); sBuilder.Append(""); sBuilder.Append(""); sBuilder.Append(""); sBuilder.Append(""); return sBuilder.ToString(); } /// /// 将数据集表中账户状态WmsRateStatus和应收应付类型WmsRateType的数字状态位转换成文字 /// /// 原数据源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; } // } }