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.SeaiInfoLCL { public partial class SeaImportLCLInfoGridSource : System.Web.UI.Page { private string strReadXmlType = "";//读取xml串方式 "init"-初始化获取所有账户信息;"add"-添加新的账户信息;"delete"-删除账户信息;"exist"查看是否有与委托相关账户 private int iShowCount;//每页显示数据量 private string strBSNO;//委托编号 private string strCTN_ID;//委托编号 //delete private string strTopCtnGid;//账户信息GID private string strHandle;//账户操作说明 private const int iResult = -99;//参数错误 T_ALL_DA T_ALL_DA = new T_ALL_DA(); 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()); } if (Request.QueryString["BSNO"] != null) { strBSNO = Request.QueryString["BSNO"].ToString(); } if (Request.QueryString["CTN_ID"] != null) { strCTN_ID = Request.QueryString["CTN_ID"].ToString(); } #endregion // if (!strReadXmlType.Equals("")) { if (strReadXmlType.Equals("delete") || strReadXmlType.Equals("recover")) { strTopCtnGid = (String)Request.QueryString["CTN_ID"] as String; strHandle = (String)Request.QueryString["read"] as String; if (strTopCtnGid == null || strHandle == null) { Response.Write(iResult); } else { //int iQuery = int.Parse(DoExcute(strTopCtnGid, strHandle)); string iQuery = DoExcute(strTopCtnGid, strHandle); Response.Write(iQuery); } } if (strReadXmlType.Equals("del")) { bool bl = T_ALL_DA.GetExecuteSqlCommand("delete from op_seai where bsno='" + strBSNO + "'"); if (bl) { Response.Write("1"); } else { Response.Write("-1"); } } 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"); } } protected void getCNTRTOTAL(string strBSNO) { string strCNTRTOTAL = ""; string strCNTRNO = ""; TopCtnDA TopCtnDA = new TopCtnDA(); DataSet ds = TopCtnDA.GetFieldAll(" and BSNO='" + strBSNO.Trim() + "'"); if (ds != null) { if (ds.Tables[0].Rows.Count > 0) { foreach (DataTable myTable in ds.Tables) { foreach (DataRow myRow in myTable.Rows)//遍历表 { //strCNTRTOTAL += myRow["CTNALL"].ToString().Trim() + "*" + myRow["CTNNUM"].ToString().Trim() + " / "; strCNTRNO += myRow["CNTRNO"].ToString().Trim() + "/" + myRow["SEALNO"].ToString().Trim() + "/" + myRow["CTNALL"].ToString().Trim() + "\r\n";//"/" + myRow["PKGS"].ToString().Trim() + "PKGS/" + myRow["KGS"].ToString().Trim() + "KGS/" + myRow["CBM"].ToString().Trim() + "CBM } } // T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); ds = T_ALL_DA.GetAllSQL("select CTNALL,sum(CTNNUM) as hj from op_ctn where BSNO='" + ViewState["GID"].ToString().Trim() + "' group by CTNALL order by CTNALL"); foreach (DataTable myTable in ds.Tables) { foreach (DataRow myRow in myTable.Rows)//遍历表 { strCNTRTOTAL += myRow["CTNALL"].ToString().Trim() + "*" + myRow["hj"].ToString().Trim() + " / "; } } strCNTRTOTAL = strCNTRTOTAL.Trim().Substring(0, strCNTRTOTAL.Trim().Length - 1); } } CrmSeaeorderDA CrmSeaeorderDA = new CrmSeaeorderDA(); int iii = CrmSeaeorderDA.UpdateInfoCNTRTOTAL("update op_seai set CNTRTOTAL='" + strCNTRTOTAL + "',CNTRSEALNO='" + strCNTRNO + "' where BSNO='" + strBSNO.Trim() + "'", strUserID.Trim()); } /// /// 根据用户提交的 /// /// 账户GID /// 操作类型 delete删除单条账户 /// 值1-删除成功;值-1 -删除操作异常 值-2 -回滚失败 值-3 -未获取相关账户信息 private string DoExcute(string tempGid, string tempHandle) { string strVal = ""; TopCtnDA TopCtnDA = new TopCtnDA(); //操作类型为删除 if (tempHandle == "delete") { int iResult = 0; //先判断当前要删除的账户是否存在 if (!tempGid.Trim().Equals("")) { TopCtnEntity TopCtnEntity = new TopCtnEntity(); TopCtnEntity = TopCtnDA.GetTopCtnByID(tempGid); if (TopCtnEntity.CTN_ID != null) { //iResult = TopCtnDA.DeleteTopCtnByGid(TopCtnEntity.CTN_ID); string alt = T_ALL_DA.GetCTNCODEDel(TopCtnEntity.BSNO.ToString(), strUserID.Trim(), TopCtnEntity.CTN_ID.ToString().Trim(), TopCtnEntity.CTNALL.ToString().Trim(), int.Parse(TopCtnEntity.CTNNUM.ToString().Trim())); if (alt != "") { iResult = -1; } else { iResult = 1; getCNTRTOTAL(TopCtnEntity.BSNO.ToString()); } } else { iResult = -3; //未获取相关账户信息 } } strVal = iResult.ToString(); } if (tempHandle == "recover") { if (!tempGid.Trim().Equals("")) { TopCtnEntity TopCtnEntity = new TopCtnEntity(); TopCtnEntity = TopCtnDA.GetTopCtnByID(tempGid); if (TopCtnEntity != null) { StringBuilder TopCtnBuilder = new StringBuilder(); TopCtnBuilder.Append(TopCtnEntity.CTN_ID + ","); TopCtnBuilder.Append(TopCtnEntity.CTNALL + ","); TopCtnBuilder.Append(TopCtnEntity.CTNNUM + ","); TopCtnBuilder.Append(TopCtnEntity.CNTRNO + ","); TopCtnBuilder.Append(TopCtnEntity.SEALNO + ","); TopCtnBuilder.Append(TopCtnEntity.PKGS + ","); TopCtnBuilder.Append(TopCtnEntity.KINDPKGS + ","); TopCtnBuilder.Append(TopCtnEntity.KGS + ","); TopCtnBuilder.Append(TopCtnEntity.TAREWEIGHT + ","); TopCtnBuilder.Append(TopCtnEntity.CBM + ","); TopCtnBuilder.Append(TopCtnEntity.REMARK); strVal = TopCtnBuilder.ToString(); } else { strVal = "-3"; } } else { strVal = "-3"; } } return strVal; } /// /// 获取账户信息 /// /// private string GetCells(int iShowCount, string readXmlType) { TopCtnEntity TopCtnEntity = new TopCtnEntity(); TopCtnDA TopCtnDA = new TopCtnDA(); TopCtnEntity existTopCtnEntity = new TopCtnEntity(); existTopCtnEntity = TopCtnDA.GetTopCtnByLINKIDAndType(strBSNO); if (existTopCtnEntity != null && !strReadXmlType.Equals("exist")) { //获取所有账户信息,用做Grid显示 DataTable TopCtnTable = new DataTable(); //初始化 string strInitSql = " SELECT CTN_ID,CTNALL,CTNNUM,CNTRNO,SEALNO,PKGS,KINDPKGS,KGS,TAREWEIGHT,CBM,REMARK FROM op_ctn WHERE BSNO = '" + strBSNO + "' ORDER BY CTN_ID"; TopCtnTable = getStatusNameTable(TopCtnDA.GetExcuteSql(strInitSql).Tables[0]); //编排字符串 xml串 StringBuilder dataBuilder = new StringBuilder(); dataBuilder.Append(""); dataBuilder.Append(""); int iCount = TopCtnTable.Rows.Count; for (int i = 0; i < iCount; i++) { int jCount = TopCtnTable.Columns.Count; dataBuilder.Append(""); for (int j = 1; j < jCount; j++) { switch (j) { case 1: dataBuilder.Append(GetCodeCtn(TopCtnTable.Rows[i][j].ToString())); break; case 2: dataBuilder.Append("" + TopCtnTable.Rows[i][j].ToString() + ""); break; case 3: dataBuilder.Append("" + TopCtnTable.Rows[i][j].ToString() + ""); break; case 4: dataBuilder.Append("" + TopCtnTable.Rows[i][j].ToString() + ""); break; case 5: dataBuilder.Append("" + TopCtnTable.Rows[i][j].ToString() + ""); break; case 6: dataBuilder.Append(GetKINDPKGS(TopCtnTable.Rows[i][j].ToString())); break; case 7: dataBuilder.Append("" + TopCtnTable.Rows[i][j].ToString() + ""); break; case 8: dataBuilder.Append("" + TopCtnTable.Rows[i][j].ToString() + ""); break; case 9: dataBuilder.Append("" + TopCtnTable.Rows[i][j].ToString() + ""); break; case 10: dataBuilder.Append("" + TopCtnTable.Rows[i][j].ToString() + ""); break; } } dataBuilder.Append(""); } dataBuilder.Append(""); return dataBuilder.ToString(); } else if (existTopCtnEntity != null && strReadXmlType.Equals("exist")) { return "1";//存在账户 } else if (existTopCtnEntity == null && strReadXmlType.Equals("add")) { StringBuilder dataBuilder = new StringBuilder(); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(GetCodeCtn("")); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(GetKINDPKGS("")); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(""); dataBuilder.Append(""); return dataBuilder.ToString(); } else { return "-3";//没有相关的账户 } } /// /// 将数据集表中账户状态TopCtnStatus和应收应付类型TopCtnType的数字状态位转换成文字 /// /// 原数据源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; } /// /// 获取集装箱下拉列表 /// public string GetCodeCtn(string strCodeCtn) { StringBuilder resultBuilder = new StringBuilder(); T_ALL_DA T_ALL_DA = new T_ALL_DA(); DataSet ds = T_ALL_DA.GetTCodeCtn(); resultBuilder.Append("" + strCodeCtn); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (!ds.Tables[0].Rows[i]["CTNID"].ToString().Trim().Equals("")) { resultBuilder.Append(""); } } resultBuilder.Append(""); return resultBuilder.ToString(); } /// /// 获取集装箱件数包装下拉列表 /// public string GetKINDPKGS(string strKINDPKGS) { StringBuilder resultBuilder = new StringBuilder(); T_ALL_DA T_ALL_DA = new T_ALL_DA(); DataSet ds = T_ALL_DA.GetTCodePackage(); resultBuilder.Append("" + strKINDPKGS); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (!ds.Tables[0].Rows[i]["PKGS"].ToString().Trim().Equals("")) { resultBuilder.Append(""); } } resultBuilder.Append(""); return resultBuilder.ToString(); } } }