public virtual void ProgramAttachmentDelete(ProgramAttachment entity) { TraceCallEnterEvent.Raise(); try { m_DataContext.BeginNestedTran(); try { m_DataContext.ndihdProgramAttachmentDelete(entity.ID); m_DataContext.CommitNested(); } catch { m_DataContext.RollbackNested(); throw; } TraceCallReturnEvent.Raise(); return; } catch (Exception ex) { ExceptionManager.Publish(ex); TraceCallReturnEvent.Raise(false); throw; } }
// ------------------------------------------------------------------------------------- /// <summary> /// Constructor /// </summary> // ------------------------------------------------------------------------------------- public frmProgramAttachmentEdit(DBGuid ProgramID) { // Required for Windows Form Designer support InitializeComponent(); CurrentID = new DBGuid(); CurrentAttachment = null; m_ProgramID = ProgramID; m_strUrl = ""; txtUrl.ReadOnly = true; pHeader.Text2 = "Csatolt dokumentum létrehozása"; }
protected void btnCreate_Click(object sender, EventArgs e) { try { if (!Page.IsValid) { return; } string progId = Request["progId"]; Guid progGuid = new Guid(progId); if (fileUpload.PostedFile == null) { throw new ApplicationException("Nincs feltöltött fájl."); } if (fileUpload.PostedFile.ContentLength == 0) { throw new ApplicationException("Nincs feltöltött fájl."); } ProgramAttachment attachment = new ProgramAttachment(Guid.NewGuid()); attachment.ProgramRef = progGuid; attachment.Name = txtName.Text; attachment.Description = txtDescription.Text; attachment.Author = txtAuthor.Text; attachment.Publisher = txtPublisher.Text; attachment.PublishedYear = txtPublishedYear.Text; attachment.Keywords = txtKeyword.Text; string fileName = Path.GetFileName(fileUpload.PostedFile.FileName); attachment.Path = fileName; BinaryReader reader = new BinaryReader(fileUpload.PostedFile.InputStream); byte[] buffer = new byte[fileUpload.PostedFile.ContentLength]; reader.Read(buffer, 0, fileUpload.PostedFile.ContentLength); attachment.FileData = buffer; IProgramAttachmentService srv = ServiceFactory.GetProgramAttachmentService(); srv.ProgramAttachmentInsert(attachment); Response.Redirect("ProgramData.aspx?progId=" + progId); } catch (Exception ex) { errorPanel.Exception = ex; } }
protected void btnModify_Click(object sender, EventArgs e) { try { if (!Page.IsValid) { return; } ProgramAttachment attachment = new ProgramAttachment(m_AttGuid); attachment.ProgramRef = m_ProgramGuid; attachment.Name = txtName.Text; attachment.Description = txtDescription.Text; attachment.Author = txtAuthor.Text; attachment.Publisher = txtPublisher.Text; attachment.PublishedYear = txtPublishedYear.Text; attachment.Keywords = txtKeyword.Text; if (fileUpload.PostedFile != null) { if (fileUpload.PostedFile.ContentLength > 0) { string fileName = Path.GetFileName(fileUpload.PostedFile.FileName); attachment.Path = fileName; BinaryReader reader = new BinaryReader(fileUpload.PostedFile.InputStream); byte[] buffer = new byte[fileUpload.PostedFile.ContentLength]; reader.Read(buffer, 0, fileUpload.PostedFile.ContentLength); attachment.FileData = buffer; } } IProgramAttachmentService srv = ServiceFactory.GetProgramAttachmentService(); srv.ProgramAttachmentUpdate(attachment); Response.Redirect("ProgramData.aspx?progId=" + m_ProgramGuid.ToString()); } catch (Exception ex) { errorPanel.Exception = ex; } }
/// <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 void ProgramAttachmentUpdate(ProgramAttachment entity) { TraceCallEnterEvent.Raise(); try { m_DataContext.BeginNestedTran(); try { int count; m_DataContext.ndihdProgramAttachmentUpdate(entity.ID, entity.ProgramRef, entity.Path, entity.Name, entity.Description, entity.Author, entity.Publisher, entity.PublishedYear, entity.Keywords, entity.CreatedDate, entity.FileSize, entity.IsActive, out count); if (count == 0) throw new ServiceUpdateException(); m_DataContext.CommitNested(); } catch { m_DataContext.RollbackNested(); throw; } TraceCallReturnEvent.Raise(); return; } catch (Exception ex) { ExceptionManager.Publish(ex); TraceCallReturnEvent.Raise(false); throw; } }
public virtual ProgramAttachment ProgramAttachmentSelect(DBGuid IDVal) { TraceCallEnterEvent.Raise(); try { ProgramAttachment result = null; DataSet entitySet = m_DataContext.ndihdProgramAttachmentSelect(IDVal); if (entitySet.Tables[0].Rows.Count != 0) { result = new ProgramAttachment(entitySet); } TraceCallReturnEvent.Raise(); return result; } catch (Exception ex) { ExceptionManager.Publish(ex); TraceCallReturnEvent.Raise(false); throw; } }
public new void ProgramAttachmentUpdate(ProgramAttachment entity) { // check permission: admin, writer PrincipalPermission permReg = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Registered"); PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator"); permReg.Union(permAdmin).Demand(); TraceCallEnterEvent.Raise(); try { ProgramService progSrv = new ProgramService(); Program selectedProgram = progSrv.ProgramSelect(entity.ProgramRef); if (selectedProgram == null) throw new ApplicationException("A megadott azonosítóval nem létezik program."); string writerRole = selectedProgram.OrganisationRef.Value.ToString() + ".Writer"; PrincipalPermission permWriter = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, writerRole); permWriter.Union(permAdmin).Demand(); // check required fields: if (entity.Name.Length == 0) throw new ArgumentNullException("ProgramAttachment.Name", "A csatolt fájl neve nincs megadva."); if (entity.Description.Length == 0) throw new ArgumentNullException("ProgramAttachment.Description", "A csatolt fájl leírása nincs megadva."); ProgramAttachment selected = base.ProgramAttachmentSelect(entity.ID); if (selected == null) throw new ApplicationException("A csatolt dokumentum nem létezik."); if (!selected.IsActive) throw new ApplicationException("A csatolt dokumentum nem aktív."); // save data if (entity.FileData != null && entity.FileData.Length > 0) { if (entity.Path.Length == 0 || entity.Path == DBString.Null) throw new ArgumentNullException("ProgramAttachment.Path", "A fájlnév nincs megadva."); ProgramAttachment newAttachment = new ProgramAttachment(Guid.NewGuid(), entity); string fileName = newAttachment.ID.Value.ToString() + Path.GetExtension(newAttachment.Path); FileDataContext fileDataContext = new FileDataContext(); fileDataContext.ProgramAttachmentInsert(newAttachment.ProgramRef, fileName, entity.FileData); newAttachment.CreatedDate = DBDateTime.Now; newAttachment.IsActive = true; newAttachment.FileSize = entity.FileData.Length; selected.IsActive = false; m_DataContext.BeginNestedTran(); try { base.ProgramAttachmentInsert(newAttachment); base.ProgramAttachmentUpdate(selected); m_DataContext.CommitNested(); } catch { m_DataContext.RollbackNested(); throw; } } else { selected.Name = entity.Name; selected.Description = entity.Description; selected.Author = entity.Author; selected.Publisher = entity.Publisher; selected.PublishedYear = entity.PublishedYear; selected.Keywords = entity.Keywords; base.ProgramAttachmentUpdate(selected); } BusinessAuditEvent.Success( new EventParameter("ProgramAttachmentID", entity.ID.ToString()), new EventParameter("ProgramAttachmentName", entity.Name), new EventParameter("ProgramID", entity.ProgramRef.ToString()) ); TraceCallReturnEvent.Raise(); return; } catch (Exception ex) { ExceptionManager.Publish(ex); BusinessAuditEvent.Fail( new EventParameter("Exception", ex.ToString()), new EventParameter("ProgramAttachmentID", entity.ID.ToString()), new EventParameter("ProgramAttachmentName", entity.Name), new EventParameter("ProgramID", entity.ProgramRef.ToString()) ); TraceCallReturnEvent.Raise(false); throw; } }
public new void ProgramAttachmentInsert(ProgramAttachment entity) { // check permission: admin PrincipalPermission permReg = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Registered"); PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator"); permReg.Union(permAdmin).Demand(); TraceCallEnterEvent.Raise(); try { ProgramService progSrv = new ProgramService(); Program selectedProgram = progSrv.ProgramSelect(entity.ProgramRef); if (selectedProgram == null) throw new ApplicationException("A megadott azonosítóval nem létezik program."); string writerRole = selectedProgram.OrganisationRef.Value.ToString() + ".Writer"; PrincipalPermission permWriter = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, writerRole); permWriter.Union(permAdmin).Demand(); // check required fields: if (entity.Name.Length == 0) throw new ArgumentNullException("ProgramAttachment.Name", "A csatolt fájl neve nincs megadva."); if (entity.Description.Length == 0) throw new ArgumentNullException("ProgramAttachment.Description", "A csatolt fájl leírása nincs megadva."); if (entity.Path.Length == 0 || entity.Path == DBString.Null) throw new ArgumentNullException("ProgramAttachment.Path", "A fájlnév nincs megadva."); if (entity.FileData == null || entity.FileData.Length == 0) throw new ArgumentNullException("ProgramAttachment.FileData", "A fájl tartalma nincs megadva."); string fileName = entity.ID.Value.ToString() + Path.GetExtension(entity.Path); // save data FileDataContext fileDataContext = new FileDataContext(); fileDataContext.ProgramAttachmentInsert(entity.ProgramRef, fileName, entity.FileData); entity.CreatedDate = DBDateTime.Now; entity.IsActive = true; entity.FileSize = entity.FileData.Length; base.ProgramAttachmentInsert(entity); BusinessAuditEvent.Success( new EventParameter("ProgramAttachmentID", entity.ID.ToString()), new EventParameter("ProgramAttachmentName", entity.Name), new EventParameter("ProgramID", entity.ProgramRef.ToString()) ); TraceCallReturnEvent.Raise(); return; } catch (Exception ex) { ExceptionManager.Publish(ex); BusinessAuditEvent.Fail( new EventParameter("Exception", ex.ToString()), new EventParameter("ProgramAttachmentID", entity.ID.ToString()), new EventParameter("ProgramAttachmentName", entity.Name), new EventParameter("ProgramID", entity.ProgramRef.ToString()) ); TraceCallReturnEvent.Raise(false); throw; } }
// ------------------------------------------------------------------------------------- /// <summary> /// Constructor /// </summary> // ------------------------------------------------------------------------------------- public frmProgramAttachmentEdit(ProgramAttachment Attachment) { // Required for Windows Form Designer support InitializeComponent(); CurrentID = Attachment.ID; CurrentAttachment = Attachment; m_ProgramID = new DBGuid(); m_strUrl = ""; txtUrl.ReadOnly = true; pHeader.Text2 = "Csatolt dokumentum módosítása"; }
// ------------------------------------------------------------------------------------- /// <summary> /// Create new or modify existing News item /// </summary> // ------------------------------------------------------------------------------------- private void SaveData() { if (CurrentID.IsNull) { // Create a new document CurrentID = new DBGuid(Guid.NewGuid()); CurrentAttachment = new ProgramAttachment(CurrentID); CurrentAttachment.ProgramRef = m_ProgramID; } // Get control values CurrentAttachment.Name = txtName.Text; CurrentAttachment.Path = txtUrl.Text; if (txtUrl.Text.Length > 0 && m_strUrl.Length > 0 && File.Exists(m_strUrl)) { // Get file content FileStream stream = new FileStream(m_strUrl, FileMode.Open, FileAccess.Read); int fileSize = Convert.ToInt32(stream.Length); byte[] result = new byte[fileSize]; stream.Read(result, 0, fileSize); stream.Close(); CurrentAttachment.FileData = result; } CurrentAttachment.FileSize = Convert.ToInt32(txtSize.Text); CurrentAttachment.Description = txtDescription.Text; CurrentAttachment.Author = txtAuthor.Text; CurrentAttachment.Publisher = txtPublisher.Text; CurrentAttachment.PublishedYear = txtPublishedYear.Text; CurrentAttachment.Keywords = txtKeywords.Text; CurrentAttachment.CreatedDate = DBDateTime.Now; CurrentAttachment.IsActive = cbxActivate.Checked; }
public void ProgramUpdateAdmin(Program entity) { // Check permission: Admin PrincipalPermission permAdmin = new PrincipalPermission(Thread.CurrentPrincipal.Identity.Name, "Administrator"); permAdmin.Demand(); TraceCallEnterEvent.Raise(); try { // Check required fields if (entity.Name.Length == 0) throw new ArgumentNullException("Program.Name", "A program neve nincs megadva."); if (entity.Description.Length == 0) throw new ArgumentNullException("Program.Description", "A program leírása nincs megadva."); if (entity.ProgramStatus.Length == 0) throw new ArgumentNullException("Program.ProgramStatus", "A program státusza nincs megadva."); // Logical checks Program selected = base.ProgramSelect(entity.ID); if (selected == null) throw new ApplicationException("Ezzel az azonosítóval nem létezik program."); if (CheckProgramExistByName(entity.Name, selected.OrganisationRef, entity.ID)) { throw new ApplicationException("Ezzel a névvel már létezik program!"); } // Save data selected.Name = entity.Name; selected.Description = entity.Description; selected.ProgramStatus = entity.ProgramStatus; selected.StartDate = entity.StartDate; selected.FinishDate = entity.FinishDate; selected.NonregisteredPartners = entity.NonregisteredPartners; selected.ResponsibleRef = entity.ResponsibleRef; selected.Coordinator1Ref = entity.Coordinator1Ref; selected.Coordinator2Ref = entity.Coordinator2Ref; selected.ProgramStatus = entity.ProgramStatus; selected.IsActive = entity.IsActive; m_DataContext.BeginNestedTran(); try { // Program participant - delete and insert if (entity.Experts.AllCount > 0) { m_DataContext.ndihdProgramParticipantDeleteBy(entity.ID); for (int i = 0; i < entity.Experts.Deleted.Count; i++) { DBGuid ExpertRef = ((Expert) entity.Experts.Deleted.Items[i]).ID; m_DataContext.ndihdProgramParticipantInsert(ExpertRef, entity.ID); } } // Program partner - delete and insert if (entity.Organisations.AllCount > 0) { m_DataContext.ndihdPartnerProgramDeleteBy(entity.ID); for (int i = 0; i < entity.Organisations.Deleted.Count; i++) { DBGuid PartnerRef = ((Organisation) entity.Organisations.Deleted.Items[i]).ID; m_DataContext.ndihdProgramPartnerInsert(PartnerRef, entity.ID); } } #region Megyék // Program partner - delete and insert //if (entity.Regions.AllCount > 0) { //összeset letöröljük m_DataContext.ndihdRegionOfProgramDeleteBy(entity.ID); //egyesével felvesszük for (int i = 0; i < entity.Regions.All.Count; i++) { DBString regionRef = ((ProgramRegion) entity.Regions.All.Items[i]).RegionRef; m_DataContext.ndihdProgramRegionInsert(entity.ID, regionRef); } } #endregion // Program attachment if (entity.ProgramAttachments.AllCount > 0) { for (int i = 0; i < entity.ProgramAttachments.All.Count; i++) { // Get item from container ProgramAttachment attEntity = (ProgramAttachment) entity.ProgramAttachments.All.Items[i]; // Check item existance ProgramAttachmentService srv = new ProgramAttachmentService(); ProgramAttachment attSelected = srv.ProgramAttachmentSelect(attEntity.ID); if (attSelected == null) { // Insert a new attEntity.CreatedDate = DBDateTime.Now; if (attEntity.FileData != null && attEntity.FileData.Length > 0) { if (attEntity.Path.Length == 0 || attEntity.Path == DBString.Null ) throw new ArgumentNullException("ProgramAttachment.Path", "A fájlnév nincs megadva."); string fileName = attEntity.ID.Value.ToString() + Path.GetExtension(attEntity.Path); FileDataContext fileDataContext = new FileDataContext(); fileDataContext.ProgramAttachmentInsert(attEntity.ProgramRef, fileName, attEntity.FileData); } m_DataContext.ndihdProgramAttachmentInsert(attEntity.ID, attEntity.ProgramRef, attEntity.Path, attEntity.Name, attEntity.Description, attEntity.Author, attEntity.Publisher, attEntity.PublishedYear, attEntity.Keywords, attEntity.CreatedDate, attEntity.FileSize, attEntity.IsActive); } else { // Update existing if (attEntity.FileData != null && attEntity.FileData.Length > 0) { if (attEntity.Path.Length == 0 || attEntity.Path == DBString.Null) throw new ArgumentNullException("ProgramAttachment.Path", "A fájlnév nincs megadva."); ProgramAttachment newAttachment = new ProgramAttachment(Guid.NewGuid(), attEntity); string fileName = newAttachment.ID.Value.ToString() + Path.GetExtension(newAttachment.Path); FileDataContext fileDataContext = new FileDataContext(); fileDataContext.ProgramAttachmentInsert(newAttachment.ProgramRef, fileName, newAttachment.FileData); newAttachment.CreatedDate = DBDateTime.Now; m_DataContext.ndihdProgramAttachmentInsert(newAttachment.ID, newAttachment.ProgramRef, newAttachment.Path, newAttachment.Name, newAttachment.Description, newAttachment.Author, newAttachment.Publisher, newAttachment.PublishedYear, newAttachment.Keywords, newAttachment.CreatedDate, newAttachment.FileSize, newAttachment.IsActive); attSelected.IsActive = false; m_DataContext.ndihdProgramAttachmentUpdate(attSelected.ID, attSelected.ProgramRef, attSelected.Path, attSelected.Name, attSelected.Description, attSelected.Author, attSelected.Publisher, attSelected.PublishedYear, attSelected.Keywords, attSelected.CreatedDate, attSelected.FileSize, attSelected.IsActive); } else { m_DataContext.ndihdProgramAttachmentUpdate(attEntity.ID, attEntity.ProgramRef, attEntity.Path, attEntity.Name, attEntity.Description, attEntity.Author, attEntity.Publisher, attEntity.PublishedYear, attEntity.Keywords, attEntity.CreatedDate, attEntity.FileSize, attEntity.IsActive); } } } } // Program keyword - delete and insert if (entity.Thesauruses.AllCount > 0) { base.DeleteChildrenByProgramOfKeyword(entity.ID); for (int i = 0; i < entity.Thesauruses.Deleted.Count; i++) { DBString KeywordRef = ((Thesaurus) entity.Thesauruses.Deleted.Items[i]).Keyword; ProgramKeyword entityPK = new ProgramKeyword(KeywordRef, entity.ID); ProgramKeywordService srv = new ProgramKeywordService(m_DataContext); srv.ProgramKeywordInsert(entityPK); } } // Program selected.LastModifiedDate = DateTime.Now; base.ProgramUpdate(selected); //feltöltjük a szabadszöveges kereséshez a GlobalSearch táblát GlobalSearchService srvGlobalSearch = new GlobalSearchService(m_DataContext); srvGlobalSearch.SaveProgram(selected); m_DataContext.CommitNested(); } catch { m_DataContext.RollbackNested(); throw; } BusinessAuditEvent.Success( new EventParameter("ProgramID", entity.ID.ToString()), new EventParameter("ProgramName", entity.Name) ); TraceCallReturnEvent.Raise(); return; } catch (Exception ex) { ExceptionManager.Publish(ex); BusinessAuditEvent.Fail( new EventParameter("Exception", ex.ToString()), new EventParameter("ProgramID", entity.ID.ToString()), new EventParameter("ProgramName", entity.Name) ); TraceCallReturnEvent.Raise(false); throw; } }
// ------------------------------------------------------------------------------------- /// <summary> /// Copy constructor. /// </summary> /// <param name="origInstance">Original document data to copy.</param> // ------------------------------------------------------------------------------------- public ProgramAttachment(ProgramAttachment origInstance) : base(origInstance) { }
// ------------------------------------------------------------------------------------- /// <summary> /// Copy constructor. /// </summary> /// <param name="IDVal">Value of 'uID' field</param> /// <param name="origInstance">Original document data to copy.</param> // ------------------------------------------------------------------------------------- public ProgramAttachment(DBGuid IDVal, ProgramAttachment origInstance) : base(IDVal, origInstance) { }