/// <summary> /// Fill datagrid with data /// </summary> private void FillDatagrid(DBGuid ID) { try { string sSortColumn = "ForumThreadName"; int nSelectedRow = -1; // Storing the previous sort order if (dtgMain.DataSource != null) { sSortColumn = ((DataTable) dtgMain.DataSource).DefaultView.Sort; } // Set filter ForumItem filter = new ForumItem(Guid.Empty); filter.FilterOnIsModerated = DBInt.Null; if (cmbStatus.SelectedIndex > 0) { bool bIsModerated = (cmbStatus.SelectedValue.ToString() == "1" ? true : false); filter.FilterOnIsModerated = (DBInt) Convert.ToInt32(bIsModerated); filter.IsModerated = bIsModerated; } if (cmbForumGroup.SelectedIndex > 0) { filter.ForumGroupRef = new DBGuid(new Guid(cmbForumGroup.SelectedValue.ToString())); } if (dtpSentFrom.Checked) { filter.FilterOnSentFrom = new DBDateTime(dtpSentFrom.Value); } if (dtpSentTo.Checked) { DBDateTime dateTo = new DBDateTime(dtpSentTo.Value); filter.FilterOnSentTo = dateTo.AddDays(1).AddMilliseconds(-1); } // Retrieving data from BusinessServices IForumItemService srv = ServiceFactory.GetForumItemService(); ForumItemContainer allData = srv.ForumItemSelectFiltered(filter); DataTable dt = allData.AllAsDatatable; dt.DefaultView.Sort = sSortColumn; dtgMain.DataSource = dt; // Locates the row specified by ID param if (!ID.IsNull) { BindingManagerBase bm = dtgMain.BindingContext[dtgMain.DataSource, dtgMain.DataMember]; DataRow dr; for (int i = 0; i < bm.Count; i++) { dr = ((DataRowView) bm.Current).Row; if (ID.Value.Equals(dr["ID"])) { nSelectedRow = i; break; } bm.Position += 1; } } // Makes the row selected if (nSelectedRow <= ((DataTable) dtgMain.DataSource).DefaultView.Count && nSelectedRow > -1) { dtgMain.Select(nSelectedRow); dtgMain.CurrentRowIndex = nSelectedRow; } else if (((DataTable) dtgMain.DataSource).DefaultView.Count != 0) { dtgMain.Select(0); } // Enabling or disabling the buttons according to record count. // And is because of previous disable state. bool bIsEmptyGrid = (((DataTable) dtgMain.DataSource).DefaultView.Count == 0); tbbInactivate.Enabled = ! bIsEmptyGrid; tbbModify.Enabled = ! bIsEmptyGrid; } catch (Exception ex) { // --- Log exception ExceptionManager.Publish(ex); // --- Display Exception ErrorHandler.DisplayError("Nem várt hiba lépett fel a lista frissítése során.", ex); } }
/// <summary> /// Fill datagrid with data /// </summary> private void FillDatagrid(DBInt ID) { try { string sSortColumn = "TimeStamp DESC"; int nSelectedRow = -1; // Storing the previous sort order if (dtgMain.DataSource != null) { sSortColumn = ((DataTable) dtgMain.DataSource).DefaultView.Sort; } // Set filter Event filter = new Event(); if (cmbFunctions.SelectedIndex > 0) { filter.Method = cmbFunctions.SelectedValue.ToString(); } if (txtLoginName.Text.Length > 0) { filter.PrincipalName = txtLoginName.Text; } if (dtpFrom.Checked) { filter.FilterOnTimeStampFrom = new DBDateTime(dtpFrom.Value.Date); } if (dtpTo.Checked) { DBDateTime dateTo = new DBDateTime(dtpTo.Value); filter.FilterOnTimeStampTo = dateTo.AddDays(1).AddMilliseconds(-1); } // Retrieving data from BusinessServices IEventService srv = ServiceFactory.GetEventService(); EventContainer allData = srv.EventSelectFiltered(filter); DataTable dt = allData.AllAsDatatable; dt.DefaultView.Sort = sSortColumn; dtgMain.DataSource = dt; // Locates the row specified by ID param if (!ID.IsNull) { BindingManagerBase bm = dtgMain.BindingContext[dtgMain.DataSource, dtgMain.DataMember]; DataRow dr; for (int i = 0; i < bm.Count; i++) { dr = ((DataRowView) bm.Current).Row; if (ID.Value.Equals(dr["ID"])) { nSelectedRow = i; break; } bm.Position += 1; } } // Makes the row selected if (nSelectedRow <= ((DataTable) dtgMain.DataSource).DefaultView.Count && nSelectedRow > -1) { dtgMain.Select(nSelectedRow); dtgMain.CurrentRowIndex = nSelectedRow; } else if (((DataTable) dtgMain.DataSource).DefaultView.Count != 0) { dtgMain.Select(0); } // Enabling or disabling the buttons according to record count. // And is because of previous disable state. bool bIsEmptyGrid = (((DataTable) dtgMain.DataSource).DefaultView.Count == 0); tbbModify.Enabled = ! bIsEmptyGrid; } catch (Exception ex) { // --- Log exception ExceptionManager.Publish(ex); // --- Display Exception ErrorHandler.DisplayError("Nem várt hiba lépett fel a lista frissítése során.", ex); } }