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.ParameterSet { public partial class CodeCtnSetGridSource : System.Web.UI.Page { private string strReadXmlType = "";//读取xml串方式 "init"-初始化获取所有账户信息;"add"-添加新的账户信息;"delete"-删除账户信息;"exist"查看是否有与委托相关账户 private int iShowCount;//每页显示数据量 //delete private string strCodeCtnSetGid;//账户信息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 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 = ""; } // #region 判断参数是否正确 if (Request.QueryString["read"] != null) { strReadXmlType = Request.QueryString["read"].ToString().Trim(); } if (Request.QueryString["showcount"] != null) { iShowCount = int.Parse(Request.QueryString["showcount"].ToString()); } #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")) { strCodeCtnSetGid = (String)Request.QueryString["gid"] as String; strHandle = (String)Request.QueryString["read"] as String; if (strCodeCtnSetGid == null || strHandle == null) { Response.Write(iResult); } else { string strQuery = DoExcute(strCodeCtnSetGid, 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")) { string strname = T_ALL_DA.GetStrSQL("SHOWNAME", "select SHOWNAME from [user] where GID='" + strUserID.Trim() + "'"); Response.Write(strname); return; } 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 = ""; CodeCtnSetDA CodeCtnSetDA = new CodeCtnSetDA(); //操作类型为删除 if (tempHandle == "delete") { int iResult = 0; //先判断当前要删除的账户是否存在 if (!tempGid.Trim().Equals("")) { CodeCtnSetEntity CodeCtnSetEntity = new CodeCtnSetEntity(); CodeCtnSetEntity = CodeCtnSetDA.GetCodeCtnSetByID(tempGid); if (CodeCtnSetEntity.CTNID != null) { iResult = CodeCtnSetDA.DeleteCodeCtnSetByGid(CodeCtnSetEntity.CTNID); } else { iResult = -3; //未获取相关账户信息 } } strVal = iResult.ToString(); } if (tempHandle == "recover") { if (!tempGid.Trim().Equals("")) { CodeCtnSetEntity CodeCtnSetEntity = new CodeCtnSetEntity(); CodeCtnSetEntity = CodeCtnSetDA.GetCodeCtnSetByID(tempGid); if (CodeCtnSetEntity != null) { StringBuilder CodeCtnSetBuilder = new StringBuilder(); CodeCtnSetBuilder.Append(CodeCtnSetEntity.CTNID + ","); CodeCtnSetBuilder.Append(CodeCtnSetEntity.CTNSIZE + ","); CodeCtnSetBuilder.Append(CodeCtnSetEntity.CTNTYPE + ","); CodeCtnSetBuilder.Append(CodeCtnSetEntity.CTN + ","); CodeCtnSetBuilder.Append(CodeCtnSetEntity.EDICODE + ","); CodeCtnSetBuilder.Append(CodeCtnSetEntity.CTNWEIGHT + ","); CodeCtnSetBuilder.Append(CodeCtnSetEntity.EEXPLAIN + ","); CodeCtnSetBuilder.Append(CodeCtnSetEntity.CEXPLAIN); strVal = CodeCtnSetBuilder.ToString(); } else { strVal = "-3"; } } else { strVal = "-3"; } } return strVal; } /// /// 获取账户信息 /// /// private string GetCells(int iShowCount, string readXmlType) { CodeCtnSetEntity CodeCtnSetEntity = new CodeCtnSetEntity(); CodeCtnSetDA CodeCtnSetDA = new CodeCtnSetDA(); if (!strReadXmlType.Equals("exist")) { //获取所有账户信息,用做Grid显示 DataTable CodeCtnSetTable = new DataTable(); //初始化 string strInitSql = " SELECT CTNID,CTNSIZE,CTNTYPE,CTN,EDICODE,CTNWEIGHT,EEXPLAIN,CEXPLAIN FROM code_ctn WHERE 1=1 " + strRange + " ORDER BY CTNTYPE"; CodeCtnSetTable = getStatusNameTable(CodeCtnSetDA.GetExcuteSql(strInitSql).Tables[0]); //编排字符串 xml串 StringBuilder dataBuilder = new StringBuilder(); dataBuilder.Append(""); dataBuilder.Append(""); int iCount = CodeCtnSetTable.Rows.Count; for (int i = 0; i < iCount; i++) { int jCount = CodeCtnSetTable.Columns.Count; dataBuilder.Append(""); for (int j = 1; j < jCount; j++) { switch (j) { case 1: string xl = GetCTNTYPE(CodeCtnSetTable.Rows[i][j].ToString().Trim()); if (xl != "") { dataBuilder.Append(xl); } else { dataBuilder.Append("" + CodeCtnSetTable.Rows[i][j].ToString() + ""); } break; case 2: //dataBuilder.Append("" + CodeCtnSetTable.Rows[i][j].ToString() + ""); xl = GetCTNKINDCODE(CodeCtnSetTable.Rows[i][j].ToString().Trim()); if (xl != "") { dataBuilder.Append(xl); } else { dataBuilder.Append("" + CodeCtnSetTable.Rows[i][j].ToString() + ""); } break; case 3: dataBuilder.Append("" + CodeCtnSetTable.Rows[i][j].ToString() + ""); break; case 4: dataBuilder.Append("" + CodeCtnSetTable.Rows[i][j].ToString() + ""); break; case 5: dataBuilder.Append("" + CodeCtnSetTable.Rows[i][j].ToString() + ""); break; case 6: dataBuilder.Append("" + CodeCtnSetTable.Rows[i][j].ToString() + ""); break; case 7: dataBuilder.Append("" + CodeCtnSetTable.Rows[i][j].ToString() + ""); break; } } dataBuilder.Append(""); } dataBuilder.Append(""); return dataBuilder.ToString(); } else if (strReadXmlType.Equals("exist")) { return "1";//存在账户 } else if (strReadXmlType.Equals("add")) { StringBuilder dataBuilder = new StringBuilder(); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(""); // string strcb = GetCTNTYPE(""); if (strcb.Trim() == "") { dataBuilder.Append(""); } else { dataBuilder.Append(strcb); } // strcb = GetCTNKINDCODE(""); if (strcb.Trim() == "") { dataBuilder.Append(""); } else { dataBuilder.Append(strcb); } // dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(""); return dataBuilder.ToString(); } else { return "-3";//没有相关的账户 } } /// /// 获取集装箱类型信息下拉列表 /// /// 当前列表集装箱类型信息值 /// public string GetCTNTYPE(string strCTNTYPE) { StringBuilder clientBuilder = new StringBuilder(); clientBuilder.Append("" + strCTNTYPE); clientBuilder.Append(""); clientBuilder.Append(""); clientBuilder.Append(""); clientBuilder.Append(""); return clientBuilder.ToString(); } /// /// 获取集装箱尺寸信息下拉列表 /// /// 当前列表集装箱尺寸信息值 /// public string GetCTNKINDCODE(string strCTNKINDCODE) { DataSet ds = T_ALL_DA.GetAllSQL("select * from code_ctn_kind order by CTNKINDCODE"); if (ds != null) { StringBuilder clientBuilder = new StringBuilder(); clientBuilder.Append("" + strCTNKINDCODE); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (!ds.Tables[0].Rows[i]["CTNKINDCODE"].ToString().Trim().Equals("")) { clientBuilder.Append(""); //clientBuilder.Append(""); } } clientBuilder.Append(""); return clientBuilder.ToString(); } else { return ""; } } /// /// 将数据集表中账户状态CodeCtnSetStatus和应收应付类型CodeCtnSetType的数字状态位转换成文字 /// /// 原数据源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; } } }