PageRenderTime 35ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/WEB/c/user/customer/_ctrl/_cntUserList.ascx.cs

https://bitbucket.org/zzare/eko
C# | 201 lines | 110 code | 53 blank | 38 comment | 24 complexity | b4dd243d56a368ad7b74bb861fecc447 MD5 | raw file
  1. using System;
  2. using System.Collections;
  3. using System.Configuration;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Security;
  8. using System.Web.UI;
  9. using System.Web.UI.HtmlControls;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.WebControls.WebParts;
  12. using System.Xml.Linq;
  13. using System.Collections.Generic;
  14. namespace SM.UI.Controls
  15. {
  16. public partial class _customer_cntUserList : BaseControl
  17. {
  18. public Guid PageID { get; set; }
  19. public delegate void OnEditEventHandler(object sender, SM.BLL.Common.Args .IDguidEventArgs e);
  20. public event OnEditEventHandler OnEdit;
  21. public event OnEditEventHandler OnDelete;
  22. public string OnEditTarget = "_self";
  23. public bool ShowCheckboxColumn { get; set; }
  24. public bool ShowManageColumn { get; set; }
  25. public bool ShowEditColumn { get; set; }
  26. public int PageSize = 20;
  27. public bool DeleteAutomatically = true;
  28. public bool MultipleSelect = true;
  29. public Guid? CategoryID { get; set; }
  30. public int TaskID { get; set; }
  31. public string SearchText { get; set; }
  32. public bool? Active { get; set; }
  33. public string RoleID { get; set; }
  34. public int ExcludeTaskID { get; set; }
  35. public Guid ExcludeUserID { get; set; }
  36. public bool IsAdmin { get; set; }
  37. public IQueryable<CUSTOMER> dsList;
  38. public List<Guid> GetSelectedItems {
  39. get {
  40. List<Guid> list = new List<Guid>();
  41. if (!ShowCheckboxColumn ) return list;
  42. // get all selected groups
  43. foreach (ListViewItem item in lvList.Items ){
  44. CheckBox cbSelectUser = (CheckBox)item.FindControl("cbSelectUser");
  45. if (cbSelectUser == null) return list;
  46. HiddenField hfUser = (HiddenField)item.FindControl("hfUser");
  47. // add group to list
  48. if (cbSelectUser.Checked)
  49. list.Add(new Guid(hfUser.Value));
  50. }
  51. return list;
  52. }
  53. }
  54. protected void Page_Load(object sender, EventArgs e)
  55. {
  56. }
  57. protected void ldsList_OnSelecting(object sender, LinqDataSourceSelectEventArgs e)
  58. {
  59. eMenikDataContext db = new eMenikDataContext();
  60. IQueryable <CUSTOMER> list;
  61. if (dsList != null)
  62. {
  63. list = dsList;
  64. }
  65. else
  66. {
  67. list = (from l in db.CUSTOMERs where l.PageID == PageID select l);
  68. // apply filters
  69. //if (Active != null)
  70. // list = list.Where(w => w.IsApproved == Active).ToList();
  71. //if (TaskID > 0)
  72. // list = list.Join(db.USER_TASKs.Where(w => w.TaskID == TaskID ), g => g.UserId, p => p.UserId, (g, p) => g).ToList();
  73. //// exclude
  74. //if (ExcludeTaskID > 0)
  75. // list = list.Where(l => !(from p in db.USER_TASKs where l.UserId == p.UserId select p.TaskID).Contains(ExcludeTaskID)).ToList();
  76. //if (ExcludeUserID != Guid.Empty)
  77. // list = list.Where(l => l.UserId != ExcludeUserID).ToList();
  78. //if (!string.IsNullOrEmpty(RoleID))
  79. // list = list.Where(w=>Roles.IsUserInRole(w.UserName, RoleID)).ToList();
  80. }
  81. // hide admin users for non admin users
  82. //if (!Page.User.IsInRole("admin"))
  83. // list = list.Where(w => !Roles.IsUserInRole(w.USERNAME , "admin")).ToList();
  84. if (!String.IsNullOrEmpty(SearchText))
  85. list = list.Where(w => ((w.FIRST_NAME ?? "").Contains(SearchText) || (w.LAST_NAME ?? "").Contains(SearchText) || w.EMAIL.Contains(SearchText) || w.USERNAME.Contains(SearchText) ));
  86. // result
  87. e.Result = list.OrderByDescending(o => o.DATE_REG );
  88. }
  89. protected void lvList_ItemCommand(object sender, ListViewCommandEventArgs e)
  90. {
  91. if (e.CommandName == "Edit") {
  92. SM.BLL.Common.Args.IDguidEventArgs sbe = new SM.BLL.Common.Args.IDguidEventArgs();
  93. sbe.ID = new Guid(e.CommandArgument.ToString());
  94. // raise event
  95. OnEdit(this,sbe);
  96. }
  97. else if (e.CommandName == "login") {
  98. //MembershipUser user = Membership.GetUser(e.CommandArgument);
  99. Session["is_admin"] = true;
  100. SM.EM.Security.Login.LogIn(e.CommandArgument.ToString(), false, "", true);
  101. //FormsAuthentication.RedirectFromLoginPage(e.CommandArgument.ToString(), false);
  102. }
  103. }
  104. public void BindData()
  105. {
  106. lvList.DataBind();
  107. // init footer colspan
  108. HtmlTableCell footTH = (HtmlTableCell)lvList.FindControl("footTH");
  109. if (footTH == null) return; // no rows exist
  110. footTH.ColSpan = 11; //minimum cols
  111. if (ShowCheckboxColumn) footTH.ColSpan += 1;
  112. if (ShowManageColumn) footTH.ColSpan += 2;
  113. // init header
  114. HtmlTableCell headCB = (HtmlTableCell)lvList.FindControl("headCB");
  115. headCB.Visible = ShowCheckboxColumn;
  116. HtmlTableCell headManage = (HtmlTableCell)lvList.FindControl("headManage");
  117. headManage.Visible = ShowManageColumn;
  118. // init page size
  119. DataPager pager = (DataPager)lvList.FindControl("DataPager");
  120. pager.PageSize = PageSize;
  121. }
  122. protected void lvList_ItemDataBound(object sender, ListViewItemEventArgs e)
  123. {
  124. if (e.Item.ItemType != ListViewItemType.DataItem) return;
  125. if ( MultipleSelect || !ShowCheckboxColumn) return;
  126. CheckBox cbSelectUser = (CheckBox)e.Item.FindControl("cbSelectUser");
  127. string script = "SetUniqueCheckbox('lvList.*cbSelectUser',this)";
  128. cbSelectUser.Attributes.Add("onclick", script);
  129. }
  130. protected void lvList_DataBound(object sender, EventArgs e)
  131. {
  132. //// init footer colspan
  133. //HtmlTableCell footTH = (HtmlTableCell)lvList.FindControl("footTH");
  134. //if (footTH == null) return; // no rows exist
  135. //footTH.ColSpan = 6; //minimum cols
  136. //if (ShowCheckboxColumn) footTH.ColSpan += 1;
  137. //if (ShowManageColumn) footTH.ColSpan += 2;
  138. //// init header
  139. //HtmlTableCell headCB = (HtmlTableCell)lvList.FindControl("headCB");
  140. //headCB.Visible = ShowCheckboxColumn;
  141. //HtmlTableCell headManage = (HtmlTableCell)lvList.FindControl("headManage");
  142. //headManage.Visible = ShowManageColumn;
  143. //// init page size
  144. //DataPager pager = (DataPager)lvList.FindControl("DataPager");
  145. //pager.PageSize = PageSize;
  146. }
  147. }
  148. }