using System; using System.Collections; using System.Configuration; using System.Data; 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 System.Text; using System.Text.RegularExpressions; using DSWeb.Models; using DSWeb.EntityDA; namespace DSWeb.PriceCarrier { public partial class OpSailingDateListGridSourceHtml : System.Web.UI.Page { private int iPage; private int iRows; private string strSidx; private string strSord; private string strSearchString; private string strUserName; private string strPassWord; private string strHandle; private string strUserID; private string strSearchOper; public string strCompanyID = "";//公司GID protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["handle"] != null) { strHandle = Request.QueryString["handle"].ToString().Trim().ToLower(); } if (Request.QueryString["page"] != null) { iPage = int.Parse(Request.QueryString["page"].ToString()); } else { iPage = 0; } if (Request.QueryString["rows"] != null) { iRows = int.Parse(Request.QueryString["rows"].ToString()); } else { iRows = 0; } if (Request.QueryString["sidx"] != null) { strSidx = Request.QueryString["sidx"].ToString(); } if (Request.QueryString["sord"] != null) { strSord = Request.QueryString["sord"].ToString(); } if (Request.QueryString["searchField"] != null) { strUserID = Request.QueryString["searchField"].ToString().Trim(); } if (Request.QueryString["searchString"] != null) { UnicodeEncoding unicode = new UnicodeEncoding(); strSearchString = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["searchString"].ToString()))); } if (Request.QueryString["searchOper"] != null) { strSearchOper = Request.QueryString["searchOper"].ToString(); if (strSearchOper.Trim().Equals("0")) { strSearchOper = " and 1>2"; } else //if (strSearchOper.Trim().Equals("1")) { strSearchOper = ""; } } if (iPage > 0) { Response.Write(GetSearchSeaPrice()); } if (Request.QueryString["username"] != null) { strUserName = Request.QueryString["username"].ToString().Trim(); } if (Request.QueryString["password"] != null) { strPassWord = Request.QueryString["username"].ToString().Trim(); } if (strHandle != null) { if (strUserName != null && strPassWord != null) { } } } private bool ValidateSignIn(string strTempUserID) { bool bResult = false; UserLoginStatusDA userLoginStatusDA = new UserLoginStatusDA(); UserLoginStatusEntity userLoginStatusEntity = new UserLoginStatusEntity(); //查看是否当前登录用户是否是时效内重新登录的用户 userLoginStatusEntity = userLoginStatusDA.GetLoginStatusByUserID(strUserID); if (userLoginStatusEntity.GID != null) { DateTime signDateTime = userLoginStatusEntity.SignInTime; DateTime serverDateTime = userLoginStatusEntity.ServerDateTime; double expiresMinutes = double.Parse(userLoginStatusEntity.ExpiresMinutes.ToString()); if (signDateTime.AddMinutes(expiresMinutes).CompareTo(serverDateTime) <= 0) { //userLoginStatusDA.DeleteUserLoginStatus(userLoginStatusEntity.GID); //userLoginStatusEntity.GID = Guid.NewGuid().ToString(); //userLoginStatusEntity.SessionID = "USERID"; //userLoginStatusEntity.ExpiresMinutes = 200; //userLoginStatusDA.InsertLoginStatus(userLoginStatusEntity); bResult = false; } else { userLoginStatusDA.UpdateLoginStatusForReSign(userLoginStatusEntity); bResult = true; } } else { bResult = false;//用户未正常登录 } return bResult; } private int GetEBPriceQueryTotal() { EBPricequeryDA ebPriceQueryDA = new EBPricequeryDA(); string strSql = "SELECT COUNT(*) FROM op_sailingdate WHERE ISISSUE=1 " + strSearchOper;// and CORPID='" + strCompanyID.Trim() + "' string strCondition = ""; //if (!ValidateSignIn(strUserID)) //{ // strSql = "SELECT COUNT(*) FROM op_sailingdate WHERE 1=0"; //} //else //{ if (strSearchString != null) { if (!strSearchString.Trim().Equals("")) { string tempSearch = strSearchString; tempSearch = tempSearch.Replace("{", ""); tempSearch = tempSearch.Replace("}", ""); tempSearch = tempSearch.Replace("[", ""); tempSearch = tempSearch.Replace("]", ""); string[] searchArg = tempSearch.Split(new char[] { ',' }); for (int i = 0; i < searchArg.Length; i++) { if (i != (searchArg.Length - 1)) { if (searchArg[i + 1].IndexOf(":") < 0) { string[] strArg = (searchArg[i] + "," + searchArg[i + 1]).Split(new char[] { ':' }); if (!strArg[1].Replace("\"", "").Trim().Equals("")) { switch (strArg[0].Replace("\"", "")) { //case "companyid"://Customer // strCompanyID = strArg[1].Replace("\"", "").Replace("##", ","); // strCondition += String.Format(" AND CORPID= '{0}' ", strCompanyID.Trim()); // break; case "title"://Customer strCondition += String.Format(" AND title = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); break; case "begintime"://BillNO strCondition += String.Format(" AND BEGINTIME = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); break; case "dis"://ETD BeginDate strCondition += String.Format(" AND PORTDISCHARGE = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); break; case "load"://ETD EndDate strCondition += String.Format(" AND PODLOAD = '{0}'", strArg[1].Replace("\"", "").Replace("##", ",")); break; case "des"://ETD BeginDate strCondition += String.Format(" AND DESTINATION = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); break; default: break; } } } else { string[] strArg = searchArg[i].Split(new char[] { ':' }); if (!strArg[1].Replace("\"", "").Trim().Equals("")) { switch (strArg[0].Replace("\"", "")) { //case "companyid"://Customer // strCompanyID = strArg[1].Replace("\"", "").Replace("##", ","); // strCondition += String.Format(" AND CORPID= '{0}' ", strCompanyID.Trim()); // break; case "title"://Customer strCondition += String.Format(" AND title = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); break; case "begintime"://BillNO strCondition += String.Format(" AND BEGINTIME = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); break; case "dis"://ETD BeginDate strCondition += String.Format(" AND PORTDISCHARGE = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); break; case "load"://ETD EndDate strCondition += String.Format(" AND PODLOAD = '{0}'", strArg[1].Replace("\"", "").Replace("##", ",")); break; case "des"://ETD BeginDate strCondition += String.Format(" AND DESTINATION = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); break; default: break; } } } } else { if (searchArg[i].IndexOf(":") > 0) { string[] strArg = searchArg[i].Split(new char[] { ':' }); if (!strArg[1].Replace("\"", "").Trim().Equals("")) { switch (strArg[0].Replace("\"", "")) { //case "companyid"://Customer // strCompanyID = strArg[1].Replace("\"", "").Replace("##", ","); // strCondition += String.Format(" AND CORPID= '{0}' ", strCompanyID.Trim()); // break; case "title"://Customer strCondition += String.Format(" AND title = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); break; case "begintime"://BillNO strCondition += String.Format(" AND BEGINTIME = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); break; case "dis"://ETD BeginDate strCondition += String.Format(" AND PORTDISCHARGE = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); break; case "load"://ETD EndDate strCondition += String.Format(" AND PODLOAD = '{0}'", strArg[1].Replace("\"", "").Replace("##", ",")); break; case "des"://ETD BeginDate strCondition += String.Format(" AND DESTINATION = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); break; default: break; } } } } } strSql += strCondition; } } //} int iTotal = int.Parse(ebPriceQueryDA.GetExcuteSql(strSql).Tables[0].Rows[0][0].ToString()); return iTotal; } private string GetSearchSeaPrice() { EBPricequeryDA ebPriceQueryDA = new EBPricequeryDA(); DataTable sourceTable; int iTotalCount = GetEBPriceQueryTotal(); string strCondition = ""; string strTopNotInclude = ""; string strTopInclude = ""; string strSql = ""; int iPageTotal = 0; string strtitle = ""; string strBEGINTIME = ""; string strDischarge = ""; string strPortLoad = ""; string strDESTINATION = ""; if (strSearchString != null) { if (!strSearchString.Trim().Equals("")) { string tempSearch = strSearchString; tempSearch = tempSearch.Replace("{", ""); tempSearch = tempSearch.Replace("}", ""); tempSearch = tempSearch.Replace("[", ""); tempSearch = tempSearch.Replace("]", ""); string[] searchArg = tempSearch.Split(new char[] { ',' }); for (int i = 0; i < searchArg.Length; i++) { if (i != (searchArg.Length - 1)) { if (searchArg[i + 1].IndexOf(":") < 0) { string[] strArg = (searchArg[i] + "," + searchArg[i + 1]).Split(new char[] { ':' }); if (!strArg[1].Replace("\"", "").Trim().Equals("")) { switch (strArg[0].Replace("\"", "")) { //case "companyid"://Customer // strCompanyID = strArg[1].Replace("\"", "").Replace("##", ","); // strCondition += String.Format(" AND CORPID= '{0}' ", strCompanyID.Trim()); // break; case "title"://Customer strCondition += String.Format(" AND title = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); strtitle = strArg[1].Replace("\"", "").Replace("##", ","); break; case "begintime"://BillNO strCondition += String.Format(" AND BEGINTIME = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); strBEGINTIME = strArg[1].Replace("\"", "").Replace("##", ","); break; case "dis"://ETD BeginDate strCondition += String.Format(" AND PORTDISCHARGE = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); strDischarge = strArg[1].Replace("\"", "").Replace("##", ","); break; case "load"://ETD EndDate strCondition += String.Format(" AND PODLOAD = '{0}'", strArg[1].Replace("\"", "").Replace("##", ",")); strPortLoad = strArg[1].Replace("\"", "").Replace("##", ","); break; case "des"://ETD BeginDate strCondition += String.Format(" AND DESTINATION = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); strDESTINATION = strArg[1].Replace("\"", "").Replace("##", ","); break; default: break; } } } else { string[] strArg = searchArg[i].Split(new char[] { ':' }); if (!strArg[1].Replace("\"", "").Trim().Equals("")) { switch (strArg[0].Replace("\"", "")) { //case "companyid"://Customer // strCompanyID = strArg[1].Replace("\"", "").Replace("##", ","); // strCondition += String.Format(" AND CORPID= '{0}' ", strCompanyID.Trim()); // break; case "title"://Customer strCondition += String.Format(" AND title = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); strtitle = strArg[1].Replace("\"", "").Replace("##", ","); break; case "begintime"://BillNO strCondition += String.Format(" AND BEGINTIME = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); strBEGINTIME = strArg[1].Replace("\"", "").Replace("##", ","); break; case "dis"://ETD BeginDate strCondition += String.Format(" AND PORTDISCHARGE = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); strDischarge = strArg[1].Replace("\"", "").Replace("##", ","); break; case "load"://ETD EndDate strCondition += String.Format(" AND PODLOAD = '{0}'", strArg[1].Replace("\"", "").Replace("##", ",")); strPortLoad = strArg[1].Replace("\"", "").Replace("##", ","); break; case "des"://ETD BeginDate strCondition += String.Format(" AND DESTINATION = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); strDESTINATION = strArg[1].Replace("\"", "").Replace("##", ","); break; default: break; } } } } else { if (searchArg[i].IndexOf(":") > 0) { string[] strArg = searchArg[i].Split(new char[] { ':' }); if (!strArg[1].Replace("\"", "").Trim().Equals("")) { switch (strArg[0].Replace("\"", "")) { //case "companyid"://Customer // strCompanyID = strArg[1].Replace("\"", "").Replace("##", ","); // strCondition += String.Format(" AND CORPID= '{0}' ", strCompanyID.Trim()); // break; case "title"://Customer strCondition += String.Format(" AND title like '%{0}%' ", strArg[1].Replace("\"", "").Replace("##", ",")); strtitle = strArg[1].Replace("\"", "").Replace("##", ","); break; case "begintime"://BillNO strCondition += String.Format(" AND BEGINTIME = '{0}' ", strArg[1].Replace("\"", "").Replace("##", ",")); strBEGINTIME = strArg[1].Replace("\"", "").Replace("##", ","); break; default: break; } } } } } } } if (iTotalCount > 0) { iPageTotal = (iTotalCount % iRows) > 0 ? ((iTotalCount / iRows) + 1) : (iTotalCount / iRows); } else { iPageTotal = 0; } //if (!ValidateSignIn(strUserID)) //{ // strSql = String.Format(" SELECT GID,title,convert(char(10),BEGINTIME,20) AS BEGINTIME FROM op_sailingdate WHERE 1=0 " + strCondition + strSearchOper + " ORDER BY " + strSidx + " " + strSord + " "); //} //else //{ if (iPage > 0 && iRows > 0) { if (iPage == 1) { strSql = String.Format(" SELECT {0} GID,title,convert(char(10),BEGINTIME,20) AS BEGINTIME FROM op_sailingdate WHERE ISISSUE=1 " + strCondition + strSearchOper + " ORDER BY " + strSidx + " " + strSord + " ", "top " + iRows.ToString()); } else { strTopNotInclude = "top " + (iRows * (iPage - 1)).ToString();//RowCount*PageNum strTopInclude = "top " + iRows.ToString(); strSql = String.Format(" SELECT {0} GID,title,convert(char(10),BEGINTIME,20) AS BEGINTIME FROM op_sailingdate WHERE ISISSUE=1 and GID NOT IN (SELECT {1} GID FROM op_sailingdate WHERE ISISSUE=1 " + strCondition + strSearchOper + " ORDER BY " + strSidx + " " + strSord + " ) " + strCondition + strSearchOper + " ORDER BY " + strSidx + " " + strSord + " ", strTopInclude, strTopNotInclude); } } else { strSql = String.Format(" SELECT GID,title,convert(char(10),BEGINTIME,20) AS BEGINTIME FROM op_sailingdate " + " WHERE ISISSUE=1 " + strCondition + strSearchOper + " ORDER BY " + strSidx + " " + strSord + " "); } //} sourceTable = ebPriceQueryDA.GetExcuteSql(strSql).Tables[0]; StringBuilder sourceBuilder = new StringBuilder(); sourceBuilder.Append("{"); sourceBuilder.Append("\"griddatas\":["); for (int i = 0; i < sourceTable.Rows.Count; i++) { sourceBuilder.Append("{\"id\":\"" + sourceTable.Rows[i][0].ToString() + "\","); //sourceBuilder.Append("data:["); //sourceBuilder.Append("\"0\","); for (int j = 1; j < sourceTable.Columns.Count; j++) { if (j == sourceTable.Columns.Count - 1) { sourceBuilder.Append("\"" + sourceTable.Columns[j].ColumnName.ToString().ToLower() + "\":\"" + sourceTable.Rows[i][j].ToString() + "\""); } else { sourceBuilder.Append("\"" + sourceTable.Columns[j].ColumnName.ToString().ToLower() + "\":\"" + sourceTable.Rows[i][j].ToString() + "\","); } } if (i == sourceTable.Rows.Count - 1) { sourceBuilder.Append("}"); } else { sourceBuilder.Append("},"); } } sourceBuilder.Append("],"); sourceBuilder.Append("\"page\": " + iPage + ","); sourceBuilder.Append("\"record\":" + iTotalCount + ","); sourceBuilder.Append("\"rows\": " + iRows + ","); sourceBuilder.Append("\"total\":" + iPageTotal); sourceBuilder.Append("}"); //日志 //string alt = "'" + strPortLoad + "','" + strDischarge + "','" + strBEGINTIME + "','" + strtitle + "','" + strDESTINATION + "','FCL'"; //// //if (strtitle != "" || strBEGINTIME != "" || strDischarge != "" || strPortLoad != "" || strDESTINATION != "") //{ // T_ALL_DA T_ALL_DA = new T_ALL_DA(); // bool bl = T_ALL_DA.GetEBPricequeryListLOG(alt, strUserID, strCompanyID.Trim()); //} return sourceBuilder.ToString(); } } }