void SearchBox_ButtonSearchClick(object sender, EventArgs e) { SearchBox.SearchInputValue = ((TextBox)(SearchBox.FindControl("txtSearch"))).Text; TTSHWCFServiceClient client = new TTSHWCFServiceClient(); if (string.IsNullOrEmpty(SearchBox.ErrorString)) { Search[] lst = SearchBox.SearchOutput; try { client.Open(); string UserID = Convert.ToString(Session["UserID"]).ToUpper(); Project_DataOwner[] oDOList = client.GetProjectsByDO("Grant", UserID); DataOwner_Entity[] oDataOwner = client.GetAllDataOwner("TAdmin"); var AdminArray = (from s in oDataOwner select s.GUID).ToList(); bool IsAdmin = AdminArray.Contains(UserID); List <Search> oNewGrid = new List <Search>(); List <Search> oOldSearch = new List <Search>(); if (IsAdmin == false) { if (lst != null && lst.Count() > 0 && oDOList != null && oDOList.Count() > 0) { oOldSearch = lst.ToList(); oNewGrid = oOldSearch.Where(z => z.iRecordExists == 0).Where(z => oDOList.Any(x => x.s_DisplayProject_ID == z.s_Display_Project_ID)).ToList(); //oNewGrid.ForEach(i => i.Status = "New"); oOldSearch.RemoveAll(z => z.iRecordExists == 0); oOldSearch.AddRange(oNewGrid); foreach (var element in oOldSearch) { if (element.iRecordExists == 0) { element.Status = "New"; } else { bool flag = false; foreach (var item in oDOList) { if (item.s_DisplayProject_ID == element.s_Display_Project_ID) { flag = true; break; } else { flag = false; } } if (flag == true) { element.Status = "Edit"; } else { element.Status = "View"; } } } oOldSearch = oOldSearch.OrderByDescending(z => z.i_ID).ToList(); RptGrantGrid.DataSource = oOldSearch; /*use the object according to your need*/ RptGrantGrid.DataBind(); } else { foreach (var element in lst) { if (element.iRecordExists == 0) { element.Status = "New"; } else { bool flag = false; foreach (var item in oDOList) { if (item.s_DisplayProject_ID == element.s_Display_Project_ID) { flag = true; break; } else { flag = false; } } if (flag == true) { element.Status = "Edit"; } else { element.Status = "View"; } } } RptGrantGrid.DataSource = lst; /*use the object according to your need*/ RptGrantGrid.DataBind(); } } else { oOldSearch = lst.ToList(); oNewGrid = oOldSearch.Where(z => z.iRecordExists == 0).ToList(); oOldSearch.RemoveAll(z => z.iRecordExists == 0); oOldSearch.AddRange(oNewGrid); foreach (var element in oOldSearch) { if (element.iRecordExists == 0) { element.Status = "New"; } else { element.Status = "Edit"; } } oOldSearch = oOldSearch.OrderByDescending(z => z.i_Project_ID).ToList(); RptGrantGrid.DataSource = oOldSearch; /*use the object according to your need*/ RptGrantGrid.DataBind(); } } catch (Exception ex) { } client.Close(); } else { RptGrantGrid.DataSource = null; RptGrantGrid.DataBind(); } }
private void SearchBox_ButtonSearchClick(object sender, EventArgs e) { try { SearchBox.SearchInputValue = ((TextBox)(SearchBox.FindControl("txtSearch"))).Text; if (string.IsNullOrEmpty(SearchBox.ErrorString)) { TTSHWCFServiceClient client = new TTSHWCFServiceClient(); client.Open(); string UserID = Convert.ToString(Session["UserID"]).ToUpper(); Project_DataOwner[] oDOList = client.GetProjectsByDO("GRANT", UserID); DataOwner_Entity[] oDataOwner = client.GetAllDataOwner("TAdmin"); var AdminArray = (from s in oDataOwner select s.GUID).ToList(); bool IsAdmin = AdminArray.Contains(UserID); List <Search> lst = SearchBox.SearchOutput.ToList(); if (!IsAdmin) { List <Search> oNewGrid = new List <Search>(); //var v = cmlist.Select(z => z.Status).Distinct().ToList(); ////WHose Status Filled By Curent User oNewGrid = lst.Where(x => x.i_ID > 0).Where(z => oDOList.Any(x1 => x1.s_DisplayProject_ID == z.s_Display_Project_ID)).ToList(); oNewGrid.ForEach(x => x.Status = "Edit"); ////Whose Status Available For View Only oNewGrid.AddRange(lst.Where(x => x.i_ID > 0).Where(z => oDOList.Any(x1 => x1.s_DisplayProject_ID != z.s_Display_Project_ID)).ToList()); oNewGrid.Where(x => (string.IsNullOrEmpty(x.Status))).ToList().ForEach(x => x.Status = "View"); //Available For Add To The Current User oNewGrid.AddRange(lst.Where(x => x.i_ID == 0).Where(z => oDOList.Any(x1 => x1.s_DisplayProject_ID == z.s_Display_Project_ID)).ToList()); oNewGrid.Where(x => (string.IsNullOrEmpty(x.Status))).ToList().ForEach(x => x.Status = "New"); oNewGrid.Where(x => x.isGrantDetailsApplied == true).ToList().ForEach(x => x.Status = "View"); lst = oNewGrid; } else { lst.Where(x => x.i_ID > 0).ToList().ForEach(x => x.Status = "Edit"); lst.Where(x => x.i_ID == 0).ToList().ForEach(x => x.Status = "New"); lst.Where(x => x.isGrantDetailsApplied == true).ToList().ForEach(x => x.Status = "View"); rptrGrantMaster.DataSource = lst; rptrGrantMaster.DataBind(); } rptrGrantMaster.DataSource = lst; rptrGrantMaster.DataBind(); } else { // this.MsgBox(SearchBox.ErrorString); rptrGrantMaster.DataSource = null; rptrGrantMaster.DataBind(); } CallJS("ShowNoRecords();"); } catch (Exception ex) { this.MsgBox(ex.Message.ToString()); } }