/// <summary> /// Exports to CSV2. /// </summary> /// <param name="dt">The dt.</param> /// <param name="publicityLevel">The publicity level.</param> /// <param name="ownOrgId">The own org id.</param> /// <returns></returns> private static string CreateCsvFromPrograms(DataTable dt, int publicityLevel, Guid ownOrgId) { string EndOfLine = "\n"; string separator = ";"; string separator5 = ";;;;;"; StringBuilder rtfString = new StringBuilder(); // Build csv header row rtfString.Append("Program neve;"); rtfString.Append("Program típusa;"); rtfString.Append("Szervezet;"); rtfString.Append("Felelõs;"); rtfString.Append("Koordinátor1;"); rtfString.Append("Koordinátor2;"); rtfString.Append("Program státusza;"); rtfString.Append("Program kezdete;"); rtfString.Append("Program vége;"); rtfString.Append("A program részletes leírása;"); rtfString.Append("Résztvevõ szakember neve;"); rtfString.Append("E-mail cím;"); rtfString.Append("Cím;"); rtfString.Append("Telefonszám;"); rtfString.Append("Partner szervezet neve;"); rtfString.Append("Címe;"); rtfString.Append("Honlap;"); rtfString.Append("Megye;"); rtfString.Append("Szervezeti forma;"); rtfString.Append("Csatolt dokumentum neve;"); rtfString.Append("Fájlnév;"); rtfString.Append("Dátum;"); rtfString.Append("Fájlméret;\n"); foreach (DataRow dr in dt.Rows) { Guid progId = new Guid(dr["uID"].ToString()); //Program prg = (Program)doc; StringBuilder line = new StringBuilder(); int maxCount = 0; //letároljuk a maximális elemszámot -> ennyi sora lesz az adott programnak ExpertService srvExpert = new ExpertService(); //Expert responsible = srvExpert.ExpertSelect(prg.ResponsibleRef); //Expert coordinator1 = srvExpert.ExpertSelect(prg.Coordinator1Ref); //Expert coordinator2 = srvExpert.ExpertSelect(prg.Coordinator1Ref); //elsõ sor összeállítása line.Append(Helper.CsvCheck(dr["cName"].ToString())); line.Append(separator); line.Append(Helper.CsvCheck(dr["cProgramCategory"].ToString())); line.Append(separator); line.Append(Helper.CsvCheck(dr["cOrganisationName"].ToString())); line.Append(separator); line.Append(Helper.CsvCheck(dr["cResponsibleName"].ToString())); line.Append(separator); line.Append(Helper.CsvCheck(dr["cCoord1Name"].ToString())); line.Append(separator); line.Append(Helper.CsvCheck(dr["cCoord2Name"].ToString())); line.Append(separator); line.Append(Helper.CsvCheck(dr["cProgramStatus"].ToString())); line.Append(separator); line.Append(Helper.CsvCheck(dr["cStartDate"].ToString())); line.Append(separator); line.Append(Helper.CsvCheck(dr["cFinishDate"].ToString())); line.Append(separator); line.Append(Helper.CsvCheck(dr["cDescription"].ToString())); line.Append(separator); #region Résztvevõ szakemberek lekérdezése ExpertDispsetContainer contExpert = srvExpert.ExpertSelectParticipantsOfProgram(progId); if (contExpert.AllCount > maxCount) maxCount = contExpert.AllCount; if (contExpert.AllCount > 0) { ExpertDispset firstExpert = (ExpertDispset) contExpert.All.Items[0]; line.Append(Helper.CsvCheck(firstExpert.Name)); line.Append(separator); if (publicityLevel != 0) { line.Append(Helper.CsvCheck(firstExpert.Email1 + " " + firstExpert.Email2 + " " + firstExpert.Email3)); line.Append(separator); } else { line.Append(separator); } line.Append(Helper.CsvCheck(firstExpert.Address)); line.Append(separator); line.Append(Helper.CsvCheck(firstExpert.Phone1 + " " + firstExpert.Phone2 + " " + firstExpert.Phone3)); line.Append(separator); } else { line.Append(separator); line.Append(separator); line.Append(separator); line.Append(separator); } #endregion #region Partner szervezetek lekérdezése OrganisationService srvOrg = new OrganisationService(); OrganisationDispsetContainer contDispOrg = srvOrg.OrganisationSelectPartnersOfProgram(progId); if (contDispOrg.AllCount > maxCount) maxCount = contDispOrg.AllCount; if (contDispOrg.AllCount > 0) { OrganisationDispset firstDispOrg = (OrganisationDispset) contDispOrg.All.Items[0]; line.Append(Helper.CsvCheck(firstDispOrg.Name)); line.Append(separator); line.Append(Helper.CsvCheck(firstDispOrg.Address)); line.Append(separator); line.Append(Helper.CsvCheck(firstDispOrg.HomePage)); line.Append(separator); RegionService srvRegion = new RegionService(); line.Append(Helper.CsvCheck(srvRegion.RegionSelect(firstDispOrg.RegionRef).Name)); line.Append(separator); OrganisationFormService srvOrgForm = new OrganisationFormService(); line.Append(Helper.CsvCheck(srvOrgForm.OrganisationFormSelect(firstDispOrg.OrganisationFormRef).Name)); line.Append(separator); } else { line.Append(separator); line.Append(separator); line.Append(separator); line.Append(separator); line.Append(separator); } #endregion #region Csatolt dokumentumok lekérdezése ProgramAttachmentService srvProgAttach = new ProgramAttachmentService(); ProgramAttachmentDispsetContainer contDispProgAttach = srvProgAttach.ProgramAttachmentSelectAttachmentsOfProgram(progId); if (contDispProgAttach.AllCount > maxCount) maxCount = contDispProgAttach.AllCount; if (contDispProgAttach.AllCount > 0) { ProgramAttachmentDispset firstDispProgAttach = (ProgramAttachmentDispset) contDispProgAttach.All.Items[0]; line.Append(Helper.CsvCheck(firstDispProgAttach.Name.ToString())); line.Append(separator); line.Append(Helper.CsvCheck(firstDispProgAttach.Path.ToString())); line.Append(separator); line.Append(Helper.CsvCheck(firstDispProgAttach.CreatedDate.ToString())); line.Append(separator); line.Append(Helper.CsvCheck(firstDispProgAttach.FileSize.ToString())); line.Append(separator); } else { line.Append(separator); line.Append(separator); line.Append(separator); line.Append(separator); } #endregion #region Kérdõívek lekérdezése (kérdések/válaszok) //ITemplateService srvTemplate = ServiceFactory.GetTemplateService(); TemplateContainer contTemplate = null; #endregion rtfString.Append(line); rtfString.Append(EndOfLine); line = new StringBuilder(); //új sor bool IsBinate = false; //többi sor for (int i = 1; i < maxCount; i++) { //ha nincs kérdõív akkor kiugrunk if ((maxCount == 1) && (contTemplate.AllCount == 0)) { rtfString.Append(line); rtfString.Append(EndOfLine); break; } IsBinate = !IsBinate; line.Append(separator5); line.Append(separator5); #region a többi résztvevõ szakember hozzáadása if (contExpert.AllCount > i) { ExpertDispset firstExpert = (ExpertDispset) contExpert.All.Items[i]; line.Append(Helper.CsvCheck(firstExpert.Name)); line.Append(separator); if (publicityLevel != 0) { line.Append(Helper.CsvCheck(firstExpert.Email1 + " " + firstExpert.Email2 + " " + firstExpert.Email3)); line.Append(separator); } else { line.Append(separator); } line.Append(Helper.CsvCheck(firstExpert.Address)); line.Append(separator); line.Append(Helper.CsvCheck(firstExpert.Phone1 + " " + firstExpert.Phone2 + " " + firstExpert.Phone3)); line.Append(separator); } else { line.Append(separator); line.Append(separator); line.Append(separator); line.Append(separator); } #endregion #region a többi partner szervezetek lekérdezése if (contDispOrg.AllCount > i) { OrganisationDispset firstDispOrg = (OrganisationDispset) contDispOrg.All.Items[i]; line.Append(Helper.CsvCheck(firstDispOrg.Name)); line.Append(separator); line.Append(Helper.CsvCheck(firstDispOrg.Address)); line.Append(separator); line.Append(Helper.CsvCheck(firstDispOrg.HomePage)); line.Append(separator); IRegionService srvRegion = new RegionService(); if (!firstDispOrg.RegionRef.IsNull) { line.Append(Helper.CsvCheck(srvRegion.RegionSelect(firstDispOrg.RegionRef).Name)); line.Append(separator); } IOrganisationFormService srvOrgForm = new OrganisationFormService(); line.Append(Helper.CsvCheck(srvOrgForm.OrganisationFormSelect(firstDispOrg.OrganisationFormRef).Name)); line.Append(separator); } else { line.Append(separator5); } #endregion #region a többi csatolt dokumentumok lekérdezése if (contDispProgAttach.AllCount > i) { ProgramAttachmentDispset firstDispProgAttach = (ProgramAttachmentDispset) contDispProgAttach.All.Items[i]; line.Append(Helper.CsvCheck(firstDispProgAttach.Name.ToString())); line.Append(separator); line.Append(Helper.CsvCheck(firstDispProgAttach.Path.ToString())); line.Append(separator); line.Append(Helper.CsvCheck(firstDispProgAttach.CreatedDate.ToString())); line.Append(separator); line.Append(Helper.CsvCheck(firstDispProgAttach.FileSize.ToString())); line.Append(separator); } else { line.Append(separator); line.Append(separator); line.Append(separator); line.Append(separator); } #endregion #region Kérdõívek válaszok hozzáadása #endregion rtfString.Append(line); rtfString.Append(EndOfLine); line = new StringBuilder(); //új sor } } return rtfString.ToString(); }
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; } }