/// <summary> /// 建立TreeView之節點;目前只做到Rank ='3',且是最原始的組字串合成 /// </summary> private void GenTreeNode() { if (dt.Rows.Count > 0) { DataRow[] MainRows = dt.Select("Rank = '1'"); StringBuilder treeString = new StringBuilder(" var tree_data ={ "); for (int i = 0; i < MainRows.Length; i++) { if (i > 0) { treeString.Append(","); } string type = "item"; if (dt.Select("ParentGroupID = '" + TrimString.trimBad(MainRows[i]["GroupID"].ToString()) + "'").Length > 0) { type = "folder"; } treeString.Append("'").Append(TrimString.trimBad(MainRows[i]["GroupID"].ToString())).Append("'"); treeString.Append(":{ text:'").Append(TrimString.trimBad(MainRows[i]["GroupName"].ToString())).Append("',type:'").Append(type).Append("',gid:'").Append(TrimString.trimBad(MainRows[i]["GroupID"].ToString())).Append("'}"); } treeString.Append("};"); for (int i = 0; i < MainRows.Length; i++) { string groupid = TrimString.trimBad(MainRows[i]["GroupID"].ToString()); if (dt.Select("ParentGroupID = '" + groupid + "'").Length > 0) { treeString.Append("tree_data['").Append(groupid).Append("']['additionalParameters']={'children': {"); DataRow[] DetailRows = dt.Select("Rank = '2' and ParentGroupID = '" + groupid + "'"); for (int di = 0; di < DetailRows.Length; di++) { if (di > 0) { treeString.Append(","); } string type = "item"; if (dt.Select("Rank = '2' and ParentGroupID = '" + groupid + "'").Length > 0) { type = "folder"; } treeString.Append("'").Append(TrimString.trimBad(DetailRows[di]["GroupID"].ToString())).Append("'"); treeString.Append(":{ text:'").Append(TrimString.trimBad(DetailRows[di]["GroupName"].ToString())).Append("',type:'").Append(type).Append("',gid:'").Append(TrimString.trimBad(DetailRows[di]["GroupID"].ToString())).Append("'}"); } treeString.Append("}"); treeString.Append("};"); } } for (int i = 0; i < MainRows.Length; i++) { string groupid = TrimString.trimBad(MainRows[i]["GroupID"].ToString()); if (dt.Select("ParentGroupID = '" + groupid + "'").Length > 0) { DataRow[] DetailRows = dt.Select("Rank = '2' and ParentGroupID = '" + groupid + "'"); for (int di = 0; di < DetailRows.Length; di++) { string deatilGroup = TrimString.trimBad(DetailRows[di]["GroupID"].ToString()); treeString.Append("tree_data['").Append(groupid) .Append("']['additionalParameters']['children']['") .Append(MDS.Utility.NUtility.trimBad(deatilGroup)).Append("']['additionalParameters']={'children': {"); DataRow[] finallRows = dt.Select("Rank = '3' and ParentGroupID = '" + deatilGroup + "'"); for (int fi = 0; fi < finallRows.Length; fi++) { if (fi > 0) { treeString.Append(","); } string type = "item"; treeString.Append("'").Append(finallRows[fi]["GroupID"].ToString()).Append("'"); treeString.Append(":{ text:'").Append(finallRows[fi]["GroupName"].ToString()).Append("',type:'").Append(type).Append("',gid:'").Append(TrimString.trimBad(DetailRows[di]["GroupID"].ToString())).Append("'}"); } treeString.Append("}"); treeString.Append("};"); } } } ReplaceString = treeString.ToString(); } }
/*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); } } }