/*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 = Request.QueryString["StrSearch"]; } if (UserList == null) { ContentPlaceHolder MySecondContent = (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder1"); UserList = MySecondContent.FindControl("UserList") as ASP.dmscontrol_olistview_ascx; StrSearch = MySecondContent.FindControl("StrSearch") as System.Web.UI.HtmlControls.HtmlInputText; } //StrSearch接Request; if (StrSearch != null) { StrSearch.Value = mySearch; } if (UserList != null) { //加入欄位Start UserList.AddCol(ParseWording("B0005"), "GroupDesc", "LEFT"); UserList.AddCol(ParseWording("B0006"), "AccountID", "LEFT"); UserList.AddCol(ParseWording("B0007"), "Name", "LEFT"); UserList.AddCol(ParseWording("B0008"), "Description", "LEFT"); UserList.AddCol(ParseWording("B0009"), "PWLastUpdateTime", "LEFT"); UserList.AddCol(ParseWording("B0010"), "DMSRoleName", "LEFT"); UserList.AddCol(ParseWording("B0011"), "IsStartup", "CENTER", "", "True::" + ParseWording("B0070") + "^^False::" + ParseWording("B0071")); UserList.AddCol("使用狀況", "situation", "CENTER"); //加入欄位End //設定Key值欄位 UserList.DataKeyNames = "AccountID"; //Key以,隔開 //設定是否顯示CheckBox(預設是true); if ((CheckUserRight("2F8CFA99-A316-4688-B1A7-EE01B96B2D7A") == false) && (CheckUserRight("7AE558CE-BEDE-4123-A5E7-264A623E095A") == false) && (CheckUserRight("A8CB6021-BCE7-4DBC-ADB6-A666419B58A2") == false) && (CheckUserRight("49E15601-D0F6-4D03-A7D8-C0140FC6C9F3") == false)) { UserList.IsUseCheckBox = false; } //設定SQL strSQL = @"SELECT SecurityGroup.GroupID + ' ' + SecurityGroup.GroupName AS GroupDesc ,tblA.AccountID ,tblA.Name ,tblA.[Description] ,tblA.PWLastUpdateTime ,(case when tblA.dLockTime is null then '正常' else '鎖定' end) as situation ,DMSRole.DMSRoleName ,tblA.Startup AS IsStartup FROM SecurityUserAccount AS tblA INNER JOIN SecurityGroup ON tblA.GroupID = SecurityGroup.GroupID INNER JOIN DMSRole ON tblA.cRoleID = DMSRole.DMSRoleID " ; if (mySearch == "") { strSQL += "WHERE tblA.GroupID =@TargerGroupID"; UserList.putQueryParameter("TargerGroupID", TargerGroupID); } else { strSQL += " INNER JOIN dbo.fn_GetGroupTree(@ParentGroupID) AS tblT ON tblA.GroupID = tblT.GroupID " + " WHERE tblA.AccountID LIKE '%'+@mySearch_1+'%' OR tblA.Name LIKE '%'+@mySearch_2+'%' "; UserList.putQueryParameter("ParentGroupID", TargerGroupID); UserList.putQueryParameter("mySearch_1", mySearch.Replace("'", "''")); UserList.putQueryParameter("mySearch_2", mySearch.Replace("'", "''")); } strSQL += " ORDER BY tblA.AccountID "; //取得SQL; UserList.SelectString = strSQL; UserList.prepareStatement(); //設定每筆資料按下去的Javascript function UserList.OnClickExecFunc = "DoEdt()"; //設定每頁筆數 UserList.PageSize = 10; //UserList.IsUseBorder = true; //接來自Request的排序欄位、排序方向、目前頁數 ListViewSortKey = Request.Params["ListViewSortKey"]; ListViewSortDirection = Request.Params["ListViewSortDirection"]; PageNo = Request.Params["PageNo"]; //設定排序欄位及方向 if (!string.IsNullOrEmpty(ListViewSortKey) && !string.IsNullOrEmpty(ListViewSortDirection)) { UserList.ListViewSortKey = ListViewSortKey; UserList.ListViewSortDirection = (SortDirection)Enum.Parse(typeof(SortDirection), ListViewSortDirection); } //設定目前頁數 if (!string.IsNullOrEmpty(PageNo)) { UserList.PageNo = int.Parse(PageNo); } } }