/// <summary> /// Refresh Outreach Code for applications and conference /// </summary> public static void RefreshOutreachCode(Int64 AConferenceKey) { TDBTransaction Transaction = new TDBTransaction(); bool SubmissionOK = true; PcConferenceTable ConferenceTable; PUnitTable UnitTable; PmShortTermApplicationTable ShortTermAppTable; ConferenceApplicationTDS MainDS; DBAccess.WriteTransaction( ref Transaction, ref SubmissionOK, delegate { ConferenceTable = new PcConferenceTable(); UnitTable = new PUnitTable(); ShortTermAppTable = new PmShortTermApplicationTable(); MainDS = new ConferenceApplicationTDS(); // get the conference in order to update the OutreachPrefix ConferenceTable = PcConferenceAccess.LoadByPrimaryKey(AConferenceKey, Transaction); if (ConferenceTable.Count == 0) { throw new Exception("Cannot find conference " + AConferenceKey.ToString("0000000000")); } // update OutreachPrefix in conference record in case it was changed in Unit record for event UnitTable = PUnitAccess.LoadByPrimaryKey(AConferenceKey, Transaction); if (UnitTable[0].OutreachCode.Length >= 5) { ConferenceTable[0].OutreachPrefix = UnitTable[0].OutreachCode.Substring(0, 5); } else { ConferenceTable[0].OutreachPrefix = UnitTable[0].OutreachCode; } MainDS.Merge(ConferenceTable); // update event code ShortTermAppTable = PmShortTermApplicationAccess.LoadViaPUnitStConfirmedOption(AConferenceKey, Transaction); foreach (PmShortTermApplicationRow ShortTermAppRow in ShortTermAppTable.Rows) { ShortTermAppRow.ConfirmedOptionCode = UnitTable[0].OutreachCode; } MainDS.Merge(ShortTermAppTable); MainDS.ThrowAwayAfterSubmitChanges = true; ConferenceApplicationTDSAccess.SubmitChanges(MainDS); }); }
/// <summary> /// Load/Refresh all Attendees for a conference /// </summary> public static void RefreshAttendees(Int64 AConferenceKey) { TDBTransaction Transaction = new TDBTransaction(); bool SubmissionOK = true; PcConferenceTable ConferenceTable; PUnitTable UnitTable; string OutreachPrefix = String.Empty; ConferenceApplicationTDS MainDS; // make sure outreach codes are up to date in case it has changed in Unit record RefreshOutreachCode(AConferenceKey); DBAccess.WriteTransaction( ref Transaction, ref SubmissionOK, delegate { ConferenceTable = new PcConferenceTable(); UnitTable = new PUnitTable(); MainDS = new ConferenceApplicationTDS(); // get the conference prefix which links all outreaches associated with a conference ConferenceTable = PcConferenceAccess.LoadByPrimaryKey(AConferenceKey, Transaction); if (ConferenceTable.Count == 0) { throw new Exception("Cannot find conference " + AConferenceKey.ToString("0000000000")); } OutreachPrefix = ConferenceTable[0].OutreachPrefix; // load application data for all conference attendees from db TApplicationManagement.GetApplications(ref MainDS, AConferenceKey, OutreachPrefix, "all", -1, true, null, false); // check a valid pcattendee record exists for each short term application foreach (PmShortTermApplicationRow ShortTermAppRow in MainDS.PmShortTermApplication.Rows) { if (!IsAttendeeValid(MainDS, OutreachPrefix, ShortTermAppRow.PartnerKey)) { // ignore deleted applications, or cancelled applications continue; } // update outreach code in application (it may have changed) UnitTable = PUnitAccess.LoadByPrimaryKey(ShortTermAppRow.StConfirmedOption, Transaction); ShortTermAppRow.ConfirmedOptionCode = ((PUnitRow)UnitTable.Rows[0]).OutreachCode; // Do we have a record for this attendee yet? bool AttendeeRecordExists = false; if (MainDS.PcAttendee.Rows.Contains(new object[] { AConferenceKey, ShortTermAppRow.PartnerKey })) { AttendeeRecordExists = true; } // create a new PcAttendee record if one does not already exist for this attendee if (!AttendeeRecordExists) { PcAttendeeRow AttendeeRow = MainDS.PcAttendee.NewRowTyped(); AttendeeRow.ConferenceKey = AConferenceKey; AttendeeRow.PartnerKey = ShortTermAppRow.PartnerKey; if (ShortTermAppRow.ConfirmedOptionCode.Length >= 11) { AttendeeRow.OutreachType = ShortTermAppRow.ConfirmedOptionCode.Substring(5, 6); } PmGeneralApplicationRow GeneralAppRow = (PmGeneralApplicationRow)MainDS.PmGeneralApplication.Rows.Find( new object[] { ShortTermAppRow.PartnerKey, ShortTermAppRow.ApplicationKey, ShortTermAppRow.RegistrationOffice }); DateTime DateAccepted = GeneralAppRow.GenAppDate; if (!GeneralAppRow.IsGenAppSendFldAcceptDateNull()) { DateAccepted = GeneralAppRow.GenAppSendFldAcceptDate.Value; } else if (!GeneralAppRow.IsGenAppRecvgFldAcceptNull()) { DateAccepted = GeneralAppRow.GenAppRecvgFldAccept.Value; } AttendeeRow.Registered = DateAccepted; // TODO: in Petra 2.x, this was calculated from pm_staff_data AttendeeRow.HomeOfficeKey = ShortTermAppRow.RegistrationOffice; if (AttendeeRow.HomeOfficeKey == 0) { AttendeeRow.HomeOfficeKey = ((int)AttendeeRow.PartnerKey / 1000000) * 1000000; } MainDS.PcAttendee.Rows.Add(AttendeeRow); } } PcRoomAllocTable RoomAllocTable = null; PcExtraCostTable ExtraCostTable = null; // now check the other way: all attendees of this conference, are they still valid? foreach (PcAttendeeRow AttendeeRow in MainDS.PcAttendee.Rows) { if ((AttendeeRow.RowState != DataRowState.Added) && !IsAttendeeValid(MainDS, OutreachPrefix, AttendeeRow.PartnerKey)) { // remove their accommodation RoomAllocTable = PcRoomAllocAccess.LoadViaPcAttendee(AttendeeRow.ConferenceKey, AttendeeRow.PartnerKey, Transaction); foreach (DataRow Row in RoomAllocTable.Rows) { Row.Delete(); } if (RoomAllocTable != null) { PcRoomAllocAccess.SubmitChanges(RoomAllocTable, Transaction); } // remove any extra costs ExtraCostTable = PcExtraCostAccess.LoadViaPcAttendee(AttendeeRow.ConferenceKey, AttendeeRow.PartnerKey, Transaction); foreach (DataRow Row in ExtraCostTable.Rows) { Row.Delete(); } if (ExtraCostTable != null) { PcExtraCostAccess.SubmitChanges(ExtraCostTable, Transaction); } // remove attendee AttendeeRow.Delete(); } } int shorttermApplicationsCount = MainDS.PmShortTermApplication.Count; int attendeeCount = MainDS.PcAttendee.Count; MainDS.ThrowAwayAfterSubmitChanges = true; ConferenceApplicationTDSAccess.SubmitChanges(MainDS); }); }
/// <summary> /// method for importing data entered on the web form /// </summary> /// <returns></returns> public static string DataImportFromForm(string AFormID, string AJSONFormData, bool ASendApplicationReceivedEmail) { if (AFormID == "TestPrintingEmail") { // This is a test for printing to PDF and sending an email, no partner is created in the database. // make sure you have a photo with name data\photos\815.jpg for the photo to appear in the pdf TApplicationFormData data = (TApplicationFormData)TJsonTools.ImportIntoTypedStructure(typeof(TApplicationFormData), AJSONFormData); data.RawData = AJSONFormData; string pdfIdentifier; string pdfFilename = GeneratePDF(0815, data.registrationcountrycode, data, out pdfIdentifier); try { if (SendEmail(0815, data.registrationcountrycode, data, pdfFilename)) { // return id of the PDF pdfIdentifier string result = "{\"success\":true,\"data\":{\"pdfPath\":\"downloadPDF.aspx?pdf-id=" + pdfIdentifier + "\"}}"; return(result); } else { string message = String.Format(Catalog.GetString("We were not able to send the email to {0}"), data.email); TLogging.Log("returning: " + "{\"failure\":true, \"data\":{\"result\":\"" + message + "\"}}"); return("{\"failure\":true, \"data\":{\"result\":\"" + message + "\"}}"); } } catch (Exception e) { TLogging.Log(e.Message); TLogging.Log(e.StackTrace); } } if (AFormID == "RegisterPerson") { TApplicationFormData data = (TApplicationFormData)TJsonTools.ImportIntoTypedStructure(typeof(TApplicationFormData), AJSONFormData); data.RawData = AJSONFormData; Int64 NewPersonPartnerKey = -1; string imageTmpPath = String.Empty; try { PartnerEditTDS MainDS = new PartnerEditTDS(); // TODO: check that email is unique. do not allow email to be associated with 2 records. this would cause trouble with authentication // TODO: create a user for this partner Int64 NewFamilyPartnerKey = CreateFamily(ref MainDS, data); NewPersonPartnerKey = CreatePerson(ref MainDS, NewFamilyPartnerKey, data); CreateAddress(ref MainDS, data, NewFamilyPartnerKey); try { PartnerEditTDSAccess.SubmitChanges(MainDS); } catch (Exception Exc) { string message = "There is some critical error when saving to the database: " + Exc.ToString(); return("{\"failure\":true, \"data\":{\"result\":\"" + message + "\"}}"); } // add a record for the application ConferenceApplicationTDS ConfDS = new ConferenceApplicationTDS(); PmGeneralApplicationRow GeneralApplicationRow = ConfDS.PmGeneralApplication.NewRowTyped(); GeneralApplicationRow.RawApplicationData = AJSONFormData; GeneralApplicationRow.PartnerKey = NewPersonPartnerKey; GeneralApplicationRow.ApplicationKey = -1; GeneralApplicationRow.RegistrationOffice = data.registrationoffice; GeneralApplicationRow.GenAppDate = DateTime.Today; GeneralApplicationRow.AppTypeName = MConferenceConstants.APPTYPE_CONFERENCE; // TODO pm_st_basic_camp_identifier_c is quite strange. will there be an overflow soon? // see ticket https://sourceforge.net/apps/mantisbt/openpetraorg/view.php?id=161 GeneralApplicationRow.OldLink = ""; GeneralApplicationRow.GenApplicantType = ""; GeneralApplicationRow.GenApplicationStatus = MConferenceConstants.APPSTATUS_ONHOLD; ConfDS.PmGeneralApplication.Rows.Add(GeneralApplicationRow); PmShortTermApplicationRow ShortTermApplicationRow = ConfDS.PmShortTermApplication.NewRowTyped(); ShortTermApplicationRow.PartnerKey = NewPersonPartnerKey; ShortTermApplicationRow.ApplicationKey = -1; ShortTermApplicationRow.RegistrationOffice = data.registrationoffice; ShortTermApplicationRow.StAppDate = DateTime.Today; ShortTermApplicationRow.StApplicationType = MConferenceConstants.APPTYPE_CONFERENCE; ShortTermApplicationRow.StBasicOutreachId = GeneralApplicationRow.OldLink; ShortTermApplicationRow.StCongressCode = data.role; ShortTermApplicationRow.ConfirmedOptionCode = data.eventidentifier; ShortTermApplicationRow.StConfirmedOption = Convert.ToInt64(data.eventpartnerkey); ShortTermApplicationRow.StFieldCharged = data.registrationoffice; ShortTermApplicationRow.Arrival = data.dateofarrival; ShortTermApplicationRow.Departure = data.dateofdeparture; ConfDS.PmShortTermApplication.Rows.Add(ShortTermApplicationRow); // TODO ApplicationForms try { ConferenceApplicationTDSAccess.SubmitChanges(ConfDS); } catch (Exception Exc) { string message = "There is some critical error when saving to the database: " + Exc.ToString(); return("{\"failure\":true, \"data\":{\"result\":\"" + message + "\"}}"); } // process Photo imageTmpPath = TAppSettingsManager.GetValue("Server.PathTemp") + Path.DirectorySeparatorChar + Path.GetFileName(data.imageid); if (File.Exists(imageTmpPath)) { string photosPath = TAppSettingsManager.GetValue("Server.PathData") + Path.DirectorySeparatorChar + "photos"; if (!Directory.Exists(photosPath)) { Directory.CreateDirectory(photosPath); } File.Copy(imageTmpPath, photosPath + Path.DirectorySeparatorChar + NewPersonPartnerKey + Path.GetExtension(imageTmpPath).ToLower(), true); } } catch (Exception e) { TLogging.Log(e.Message); TLogging.Log(e.StackTrace); string message = "There is some critical error when saving to the database"; return("{\"failure\":true, \"data\":{\"result\":\"" + message + "\"}}"); } if (ASendApplicationReceivedEmail) { string pdfIdentifier; string pdfFilename = GeneratePDF(NewPersonPartnerKey, data.registrationcountrycode, data, out pdfIdentifier); try { if (SendEmail(NewPersonPartnerKey, data.registrationcountrycode, data, pdfFilename)) { if (File.Exists(imageTmpPath)) { // only delete the temp image after successful application. otherwise we have a problem with resending the application, because the tmp image is gone File.Delete(imageTmpPath); } // return id of the PDF pdfIdentifier string result = "{\"success\":true,\"data\":{\"pdfPath\":\"downloadPDF.aspx?pdf-id=" + pdfIdentifier + "\"}}"; return(result); } } catch (Exception e) { TLogging.Log(e.Message); TLogging.Log(e.StackTrace); } } string message2 = String.Format(Catalog.GetString("We were not able to send the email to {0}"), data.email); string result2 = "{\"failure\":true, \"data\":{\"result\":\"" + message2 + "\"}}"; if (ASendApplicationReceivedEmail) { TLogging.Log(result2); } return(result2); } else { string message = "The server does not know about a form called " + AFormID; TLogging.Log(message); return("{\"failure\":true, \"data\":{\"result\":\"" + message + "\"}}"); } }