/*ListView固定程式碼, 取得目前排序欄位, 排序方向, 頁數 END*/ /// <summary> /// 因為控制項的Init事件會比Page的Init事件還要早觸發, /// 而ListView的欄位是在ListView控制項的Init事件時動態產生, /// 所以必須在Page_PreInit時指定有哪些欄位 /// </summary> /// <param name="sendor"></param> /// <param name="e"></param> protected void Page_PreInit(object sendor, EventArgs e) { string strSQL = ""; /*取得使用者GroupID*/ myGroupID = Session["ParentGroupID"].ToString(); /*接收Request*/ if (!string.IsNullOrEmpty(Request.QueryString["TargerGroupID"])) { TargerGroupID = Request.QueryString["TargerGroupID"]; } else { TargerGroupID = myGroupID; } if (!string.IsNullOrEmpty(Request.QueryString["StrSearch"])) { mySearch = TrimString.trimBad(Request.QueryString["StrSearch"]); } if (OrganizationList == null) { ContentPlaceHolder MySecondContent = (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder1"); OrganizationList = MySecondContent.FindControl("OrganizationList") as ASP.dmscontrol_olistview_ascx; StrSearch = MySecondContent.FindControl("StrSearch") as System.Web.UI.HtmlControls.HtmlInputText; } if (StrSearch != null) { //StrSearch接Request; StrSearch.Value = mySearch; } if (OrganizationList != null) { //加入欄位Start OrganizationList.AddCol(ParseWording("B0051"), "GroupID", "CENTER"); OrganizationList.AddCol(ParseWording("B0052"), "GroupName", "LEFT"); OrganizationList.AddCol(ParseWording("A0020"), "Address", "LEFT"); OrganizationList.AddCol(ParseWording("B0053"), "GroupTotal", "RIGHT"); OrganizationList.AddCol(ParseWording("B0054"), "ContactTotal", "RIGHT"); //加入欄位End //設定Key值欄位 OrganizationList.DataKeyNames = "GroupID"; //Key以,隔開 //設定是否顯示CheckBox(預設是true); if (CheckUserRight("5A48ECDA-7E32-4CF4-9B23-B0A4764A0775") == false) { OrganizationList.IsUseCheckBox = false; } //設定SQL strSQL = "SELECT tblA.GroupID, tblA.GroupName, tblA.[Address] " + ",(SELECT COUNT(*) FROM dbo.fn_GetGroupTree(tblA.GroupID) WHERE GroupID <> tblA.GroupID) AS GroupTotal " + ",(SELECT COUNT(*) FROM SecurityGroup_ContactRelation WHERE GroupID = tblA.GroupID) AS ContactTotal " + "FROM SecurityGroup AS tblA "; string mySearchTXT = ""; if (mySearch == "") { strSQL += "INNER JOIN dbo.fn_GetGroupTree(@TargerGroupID) AS tblT ON tblA.GroupID = tblT.GroupID "; OrganizationList.putQueryParameter("TargerGroupID", (TargerGroupID)); } else { mySearchTXT = mySearch.Replace("'", "''"); strSQL += "INNER JOIN dbo.fn_GetGroupTree(@ParentGroupID) AS tblT ON tblA.GroupID = tblT.GroupID " + "WHERE tblA.GroupID LIKE '%'+@mySearchTXT_1+'%' OR tblA.GroupName LIKE '%'+@mySearchTXT_2+'%' "; OrganizationList.putQueryParameter("ParentGroupID", Session["ParentGroupID"].ToString()); OrganizationList.putQueryParameter("mySearchTXT_1", mySearchTXT); OrganizationList.putQueryParameter("mySearchTXT_2", mySearchTXT); } strSQL += "ORDER BY tblT.[Rank], tblA.GroupID "; //取得SQL; OrganizationList.SelectString = strSQL; OrganizationList.prepareStatement(); //設定每筆資料按下去的Javascript function OrganizationList.OnClickExecFunc = "DoEdt()"; //設定每頁筆數 OrganizationList.PageSize = 10; //接來自Request的排序欄位、排序方向、目前頁數 ListViewSortKey = Request.Params["ListViewSortKey"]; ListViewSortDirection = Request.Params["ListViewSortDirection"]; PageNo = Request.Params["PageNo"]; //設定排序欄位及方向 if (!string.IsNullOrEmpty(ListViewSortKey) && !string.IsNullOrEmpty(ListViewSortDirection)) { OrganizationList.ListViewSortKey = ListViewSortKey; OrganizationList.ListViewSortDirection = (SortDirection)Enum.Parse(typeof(SortDirection), ListViewSortDirection); } //設定目前頁數 if (!string.IsNullOrEmpty(PageNo)) { OrganizationList.PageNo = int.Parse(PageNo); } } }