/// <summary> /// Fill datagrid with data /// </summary> private void FillDatagridAttachment(DBGuid AttachmentID, ProgramAttachment EditedAttachment) { try { string sSortColumn = "Name"; int nSelectedRow = -1; // Storing the previous sort order if (dtgAttachment.DataSource != null) { sSortColumn = ((DataTable) dtgAttachment.DataSource).DefaultView.Sort; } if (m_allDataAttachment == null) { // Retrieving data from BusinessServices IProgramService srv = ServiceFactory.GetProgramService(); DBGuid ProgramID = new DBGuid(new Guid(m_sCurrentID)); m_allDataAttachment = srv.SelectChildrenByAttachmentOfProgram(ProgramID); } else if (EditedAttachment != null) { // Add new document to the container ProgramAttachment entry = (ProgramAttachment) m_allDataAttachment[EditedAttachment.ID.ToString()]; if (entry == null) { m_allDataAttachment.Add(EditedAttachment); } } // Fill grid DataTable dt = m_allDataAttachment.AllAsDatatable; dt.DefaultView.Sort = sSortColumn; dtgAttachment.DataSource = dt; // Locates the row specified by ID param if (!AttachmentID.IsNull) { BindingManagerBase bm = dtgAttachment.BindingContext[dtgAttachment.DataSource, dtgAttachment.DataMember]; int nPositionStart = bm.Position; DataRow dr; for (int i = 0; i < bm.Count; i++) { dr = ((DataRowView) bm.Current).Row; if (AttachmentID.Value.Equals(dr["ID"])) { nSelectedRow = i; break; } bm.Position += 1; } bm.Position = nPositionStart; } // Makes the row selected if (nSelectedRow <= ((DataTable) dtgAttachment.DataSource).DefaultView.Count && nSelectedRow > -1) { dtgAttachment.Select(nSelectedRow); dtgAttachment.CurrentRowIndex = nSelectedRow; } else if (((DataTable) dtgAttachment.DataSource).DefaultView.Count != 0) { dtgAttachment.Select(0); } // Enabling or disabling the buttons according to record count. // And is because of previous disable state. bool bIsEmptyGrid = (((DataTable) dtgAttachment.DataSource).DefaultView.Count == 0); btnModifyAttachment.Enabled = ! bIsEmptyGrid; btnActivate.Enabled = ! bIsEmptyGrid; } catch (Exception ex) { // --- Log exception ExceptionManager.Publish(ex); // --- Display Exception ErrorHandler.DisplayError("Nem várt hiba lépett fel a csatolt állományok listája frissítése során.", ex); } }
public virtual ProgramAttachmentContainer SelectChildrenByAttachmentOfProgram(DBGuid IDVal) { TraceCallEnterEvent.Raise(); try { ProgramAttachmentContainer result; DataSet entitySet = m_DataContext.ndihdAttachmentOfProgramSelectBy(IDVal); result = new ProgramAttachmentContainer(entitySet.Tables[0]); TraceCallReturnEvent.Raise(); return result; } catch (Exception ex) { ExceptionManager.Publish(ex); TraceCallReturnEvent.Raise(false); throw; } }
public virtual ProgramAttachmentContainer ProgramAttachmentSelectAll() { TraceCallEnterEvent.Raise(); try { ProgramAttachmentContainer result; DataSet entitySet = m_DataContext.ndihdProgramAttachmentSelectAll(); result = new ProgramAttachmentContainer(entitySet.Tables[0]); TraceCallReturnEvent.Raise(); return result; } catch (Exception ex) { ExceptionManager.Publish(ex); TraceCallReturnEvent.Raise(false); throw; } }