private void InitializeManualCode() { // show this dialog in center of screen this.StartPosition = FormStartPosition.CenterScreen; FMainDS = new PartnerEditTDS(); // now add the one subscription row to the DS that we are working with PSubscriptionTable SubscriptionTable = new PSubscriptionTable(); FMainDS.Merge(SubscriptionTable); PSubscriptionRow SubscriptionRow = FMainDS.PSubscription.NewRowTyped(true); SubscriptionRow.PublicationCode = ""; // avoid NOT NULL error message FMainDS.PSubscription.Rows.Add(SubscriptionRow); ucoSubscription.MainDS = FMainDS; ucoSubscription.SpecialInitUserControl(); FPetraUtilsObject.HasChanges = false; }
/// <summary> /// todoComment /// </summary> /// <param name="AInspectDT"></param> public void SubmitChangesAsync(PSubscriptionTable AInspectDT) { Thread TheThread; // Cleanup (might be left in a certain state from a possible earlier call) FSubmitException = null; FSubmissionDT = null; FAsyncExecProgress = null; FVerificationResult = null; FResponseDT = null; FInspectDT = null; this.FAsyncExecProgress = new TAsynchronousExecutionProgress(); this.FAsyncExecProgress.ProgressState = TAsyncExecProgressState.Aeps_ReadyToStart; FInspectDT = AInspectDT; ThreadStart ThreadStartDelegate = new ThreadStart(SubmitChangesInternal); TheThread = new Thread(ThreadStartDelegate); TheThread.Start(); TLogging.LogAtLevel(6, "TExtractsAddSubscriptionsUIConnector.SubmitChangesAsync thread started."); }
/// <summary> /// todoComment /// </summary> /// <param name="AInspectDT"></param> public void SubmitChangesAsync(PSubscriptionTable AInspectDT) { Thread TheThread; // Cleanup (might be left in a certain state from a possible earlier call) FSubmitException = null; FSubmissionDT = null; FVerificationResult = null; FResponseDT = null; FInspectDT = null; FProgressID = Guid.NewGuid().ToString(); TProgressTracker.InitProgressTracker(FProgressID, string.Empty, 100.0m); FInspectDT = AInspectDT; ThreadStart ThreadStartDelegate = new ThreadStart(SubmitChangesInternal); TheThread = new Thread(ThreadStartDelegate); TheThread.Name = "ExtractsAddSubscriptionsSubmitChanges" + Guid.NewGuid().ToString(); TheThread.Start(); TLogging.LogAtLevel(6, "TExtractsAddSubscriptionsUIConnector.SubmitChangesAsync thread started."); }
public static void ChangeSubscription(int AExtractId, ref PSubscriptionTable ATable, List <String>AFieldsToChange, out PPartnerTable APartnersWithoutSubscription, out int ASubscriptionsChanged) { PSubscriptionTable SubscriptionTable = new PSubscriptionTable(); PSubscriptionRow SubscriptionRowTemplate; PSubscriptionRow SubscriptionRow; MExtractTable ExtractTable; PPartnerTable PartnerTable; PPartnerRow PartnerRow; int SubscriptionsChanged; PPartnerTable PartnersWithoutSubscription; // only use first row in table (as rows can't be serialized as parameters) SubscriptionRowTemplate = (PSubscriptionRow)ATable.Rows[0]; PartnersWithoutSubscription = new PPartnerTable(); SubscriptionsChanged = 0; TDBTransaction Transaction = null; bool SubmissionOK = false; DBAccess.GDBAccessObj.BeginAutoTransaction(IsolationLevel.Serializable, ref Transaction, ref SubmissionOK, delegate { ExtractTable = MExtractAccess.LoadViaMExtractMaster(AExtractId, Transaction); // query all rows of given extract foreach (MExtractRow ExtractRow in ExtractTable.Rows) { // for each extract row either change subscription or add to list of partners that don't have one if (PSubscriptionAccess.Exists(SubscriptionRowTemplate.PublicationCode, ExtractRow.PartnerKey, Transaction)) { SubscriptionTable = PSubscriptionAccess.LoadByPrimaryKey(SubscriptionRowTemplate.PublicationCode, ExtractRow.PartnerKey, Transaction); SubscriptionRow = (PSubscriptionRow)SubscriptionTable.Rows[0]; // change field contents if (AFieldsToChange.Contains(PSubscriptionTable.GetSubscriptionStatusDBName())) { SubscriptionRow.SubscriptionStatus = SubscriptionRowTemplate.SubscriptionStatus; } if (AFieldsToChange.Contains(PSubscriptionTable.GetGratisSubscriptionDBName())) { SubscriptionRow.GratisSubscription = SubscriptionRowTemplate.GratisSubscription; } if (AFieldsToChange.Contains(PSubscriptionTable.GetNumberComplimentaryDBName())) { SubscriptionRow.NumberComplimentary = SubscriptionRowTemplate.NumberComplimentary; } if (AFieldsToChange.Contains(PSubscriptionTable.GetPublicationCopiesDBName())) { SubscriptionRow.PublicationCopies = SubscriptionRowTemplate.PublicationCopies; } if (AFieldsToChange.Contains(PSubscriptionTable.GetReasonSubsGivenCodeDBName())) { SubscriptionRow.ReasonSubsGivenCode = SubscriptionRowTemplate.ReasonSubsGivenCode; } if (AFieldsToChange.Contains(PSubscriptionTable.GetReasonSubsCancelledCodeDBName())) { SubscriptionRow.ReasonSubsCancelledCode = SubscriptionRowTemplate.ReasonSubsCancelledCode; } if (AFieldsToChange.Contains(PSubscriptionTable.GetGiftFromKeyDBName())) { SubscriptionRow.GiftFromKey = SubscriptionRowTemplate.GiftFromKey; } if (AFieldsToChange.Contains(PSubscriptionTable.GetStartDateDBName())) { SubscriptionRow.StartDate = SubscriptionRowTemplate.StartDate; } if (AFieldsToChange.Contains(PSubscriptionTable.GetExpiryDateDBName())) { SubscriptionRow.ExpiryDate = SubscriptionRowTemplate.ExpiryDate; } if (AFieldsToChange.Contains(PSubscriptionTable.GetSubscriptionRenewalDateDBName())) { SubscriptionRow.SubscriptionRenewalDate = SubscriptionRowTemplate.SubscriptionRenewalDate; } if (AFieldsToChange.Contains(PSubscriptionTable.GetDateNoticeSentDBName())) { SubscriptionRow.DateNoticeSent = SubscriptionRowTemplate.DateNoticeSent; } if (AFieldsToChange.Contains(PSubscriptionTable.GetDateCancelledDBName())) { SubscriptionRow.DateCancelled = SubscriptionRowTemplate.DateCancelled; } if (AFieldsToChange.Contains(PSubscriptionTable.GetNumberIssuesReceivedDBName())) { SubscriptionRow.NumberIssuesReceived = SubscriptionRowTemplate.NumberIssuesReceived; } if (AFieldsToChange.Contains(PSubscriptionTable.GetFirstIssueDBName())) { SubscriptionRow.FirstIssue = SubscriptionRowTemplate.FirstIssue; } if (AFieldsToChange.Contains(PSubscriptionTable.GetLastIssueDBName())) { SubscriptionRow.LastIssue = SubscriptionRowTemplate.LastIssue; } // submit changes to the database after each row PSubscriptionAccess.SubmitChanges(SubscriptionTable, Transaction); //SubscriptionTable.Rows.Add(SubscriptionRow); SubscriptionsChanged++; } else { // this partner does not have given subscription, therefore it cannot be changed PartnerRow = PartnersWithoutSubscription.NewRowTyped(); PartnerTable = PPartnerAccess.LoadByPrimaryKey(ExtractRow.PartnerKey, Transaction); DataUtilities.CopyAllColumnValues(PartnerTable.Rows[0], PartnerRow); PartnersWithoutSubscription.Rows.Add(PartnerRow); } } SubmissionOK = true; }); APartnersWithoutSubscription = PartnersWithoutSubscription; ASubscriptionsChanged = SubscriptionsChanged; }
public static void AddSubscription(int AExtractId, ref PSubscriptionTable ATable, out PPartnerTable AExistingSubscriptionPartners, out int ASubscriptionsAdded) { PSubscriptionTable SubscriptionTable = new PSubscriptionTable(); PSubscriptionRow SubscriptionRowTemplate; PSubscriptionRow SubscriptionRow; MExtractTable ExtractTable; PPartnerTable PartnerTable; PPartnerRow PartnerRow; PPartnerTable ExistingSubscriptionPartners; int SubscriptionsAdded = 0; // only use first row in table (as rows can't be serialized as parameters) SubscriptionRowTemplate = (PSubscriptionRow)ATable.Rows[0]; ExistingSubscriptionPartners = new PPartnerTable(); TDBTransaction Transaction = null; bool SubmissionOK = false; DBAccess.GDBAccessObj.BeginAutoTransaction(IsolationLevel.Serializable, ref Transaction, ref SubmissionOK, delegate { ExtractTable = MExtractAccess.LoadViaMExtractMaster(AExtractId, Transaction); // query all rows of given extract foreach (MExtractRow ExtractRow in ExtractTable.Rows) { // for each extract row either add subscription or add to list of partners already having one if (PSubscriptionAccess.Exists(SubscriptionRowTemplate.PublicationCode, ExtractRow.PartnerKey, Transaction)) { PartnerRow = ExistingSubscriptionPartners.NewRowTyped(); PartnerTable = PPartnerAccess.LoadByPrimaryKey(ExtractRow.PartnerKey, Transaction); DataUtilities.CopyAllColumnValues(PartnerTable.Rows[0], PartnerRow); ExistingSubscriptionPartners.Rows.Add(PartnerRow); } else { SubscriptionRow = SubscriptionTable.NewRowTyped(); DataUtilities.CopyAllColumnValues(SubscriptionRowTemplate, SubscriptionRow); SubscriptionRow.PartnerKey = ExtractRow.PartnerKey; SubscriptionTable.Rows.Add(SubscriptionRow); SubscriptionsAdded++; } } // now submit changes to the database PSubscriptionAccess.SubmitChanges(SubscriptionTable, Transaction); SubmissionOK = true; }); AExistingSubscriptionPartners = ExistingSubscriptionPartners; ASubscriptionsAdded = SubscriptionsAdded; }
public static void AddSubscription(int AExtractId, ref PSubscriptionTable ATable, out PPartnerTable AExistingSubscriptionPartners, out int ASubscriptionsAdded) { PSubscriptionTable SubscriptionTable = new PSubscriptionTable(); PSubscriptionRow SubscriptionRowTemplate; PSubscriptionRow SubscriptionRow; MExtractTable ExtractTable; PPartnerTable PartnerTable; PPartnerRow PartnerRow; // only use first row in table (as rows can't be serialized as parameters) SubscriptionRowTemplate = (PSubscriptionRow)ATable.Rows[0]; AExistingSubscriptionPartners = new PPartnerTable(); ASubscriptionsAdded = 0; TDBTransaction Transaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable); try { ExtractTable = MExtractAccess.LoadViaMExtractMaster(AExtractId, Transaction); // query all rows of given extract foreach (MExtractRow ExtractRow in ExtractTable.Rows) { // for each extract row either add subscription or add to list of partners already having one if (PSubscriptionAccess.Exists(SubscriptionRowTemplate.PublicationCode, ExtractRow.PartnerKey, Transaction)) { PartnerRow = AExistingSubscriptionPartners.NewRowTyped(); PartnerTable = PPartnerAccess.LoadByPrimaryKey(ExtractRow.PartnerKey, Transaction); DataUtilities.CopyAllColumnValues(PartnerTable.Rows[0], PartnerRow); AExistingSubscriptionPartners.Rows.Add(PartnerRow); } else { SubscriptionRow = SubscriptionTable.NewRowTyped(); DataUtilities.CopyAllColumnValues(SubscriptionRowTemplate, SubscriptionRow); SubscriptionRow.PartnerKey = ExtractRow.PartnerKey; SubscriptionTable.Rows.Add(SubscriptionRow); ASubscriptionsAdded++; } } // now submit changes to the database PSubscriptionAccess.SubmitChanges(SubscriptionTable, Transaction); DBAccess.GDBAccessObj.CommitTransaction(); } catch (Exception Exc) { TLogging.Log( "An Exception occured during the adding of subscriptions for all Partners in an Extract:" + Environment.NewLine + Exc.ToString()); DBAccess.GDBAccessObj.RollbackTransaction(); throw; } }
/// <summary> /// First loads the extractTable needed. Goes throught all the Partners in the extract, If the partner already has the subscription, returns all those partners back to client. If the partner doesn't have the subscription, saves this /// subscription to those partners. /// </summary> /// <returns>void</returns> private void SubmitChangesInternal() { TDBTransaction SubmitChangesTransaction; TSubmitChangesResult SubmissionResult = TSubmitChangesResult.scrOK; MExtractTable ExtractDT; PSubscriptionTable SubscriptionTable; PPartnerTable PartnerTable; Int32 RowCounter; Int32 PartnersInExtract; StringCollection RequiredColumns; StringCollection RequiredColumns2; if (FInspectDT != null) { // Initialisations FVerificationResult = new TVerificationResultCollection(); ExtractDT = new MExtractTable(); SubscriptionTable = new PSubscriptionTable(); FSubmissionDT = SubscriptionTable.Clone(); ((TTypedDataTable)FSubmissionDT).InitVars(); PartnerTable = new PPartnerTable(); RequiredColumns = new StringCollection(); RequiredColumns.Add(MExtractTable.GetPartnerKeyDBName()); RequiredColumns2 = new StringCollection(); RequiredColumns2.Add(PPartnerTable.GetPartnerKeyDBName()); RequiredColumns2.Add(PPartnerTable.GetPartnerShortNameDBName()); RowCounter = 0; // Set up asynchronous execution FAsyncExecProgress.ProgressState = TAsyncExecProgressState.Aeps_Executing; FAsyncExecProgress.ProgressInformation = "Checking Partners' Subscriptions..."; try { SubmitChangesTransaction = DBAccess.GDBAccessObj.BeginTransaction(IsolationLevel.Serializable); // TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: loading Subscriptions for ExtractID " + FExtractID.ToString() + "..."); ExtractDT = MExtractAccess.LoadViaMExtractMaster(FExtractID, RequiredColumns, SubmitChangesTransaction); PartnersInExtract = ExtractDT.Rows.Count; // TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: ExtractID has " + PartnersInExtract.ToString() + " Partners."); // Go throught all the Partners in the extract foreach (MExtractRow ExtractRow in ExtractDT.Rows) { RowCounter = RowCounter + 1; // Calculate how much Partners we have checked. Let all Partners be a maximum of 70%. FAsyncExecProgress.ProgressPercentage = Convert.ToInt16((((double)RowCounter / (double)PartnersInExtract) * 100) * (MAX_PERCENTAGE_CHECKS / 100.0)); TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: loadbyPrimaryKey"); SubscriptionTable = PSubscriptionAccess.LoadByPrimaryKey( FInspectDT[0].PublicationCode, ExtractRow.PartnerKey, SubmitChangesTransaction); // if the Partner does not yet have the subscription, add the subscription to this partner. if (SubscriptionTable.Rows.Count == 0) { TLogging.LogAtLevel( 7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: will add Subscription to Partner with PartnerKey " + ExtractRow.PartnerKey.ToString()); FInspectDT[0].PartnerKey = ExtractRow.PartnerKey; TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: importing Row into FSubmissionDT..."); FSubmissionDT.ImportRow(FInspectDT[0]); } else { // The partner already has this Subscription: add the partner to the ResponseTable // TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: won't add Subscription to Partner with PartnerKey " + ExtractRow.PartnerKey.ToString()); PartnerTable = PPartnerAccess.LoadByPrimaryKey(ExtractRow.PartnerKey, RequiredColumns2, SubmitChangesTransaction); if (FResponseDT == null) { FResponseDT = PartnerTable.Clone(); } FResponseDT.ImportRow(PartnerTable[0]); } } TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: Finished checking Partner's Subscriptions."); if (FSubmissionDT.Rows.Count > 0) { // Submit the Partners with new Subscriptions to the PSubscription Table. FAsyncExecProgress.ProgressInformation = "Adding Subscriptions to " + FSubmissionDT.Rows.Count.ToString() + " Partners..."; FAsyncExecProgress.ProgressPercentage = MAX_PERCENTAGE_CHECKS; // TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: " + FAsyncExecProgress.ProgressInformation); PSubscriptionAccess.SubmitChanges((PSubscriptionTable)FSubmissionDT, SubmitChangesTransaction); } else { TLogging.LogAtLevel( 7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: no Subscriptions were added to Partners because all the Partners in the Extract already had this Subscription."); } DBAccess.GDBAccessObj.CommitTransaction(); } catch (Exception Exp) { DBAccess.GDBAccessObj.RollbackTransaction(); TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: Exception occured, Transaction ROLLED BACK. Exception: " + Exp.ToString()); FSubmitResult = TSubmitChangesResult.scrError; FSubmitException = Exp; FAsyncExecProgress.ProgressState = TAsyncExecProgressState.Aeps_Stopped; return; } } else { SubmissionResult = TSubmitChangesResult.scrNothingToBeSaved; } // if no values at response table, it needs to be created. If not creates, will raise exeption at client side. if (FResponseDT == null) { FResponseDT = new DataTable(); } FAsyncExecProgress.ProgressPercentage = 100; FAsyncExecProgress.ProgressState = TAsyncExecProgressState.Aeps_Finished; FSubmitResult = SubmissionResult; }
private PSubscriptionTable GetSubscriptionsInternal(out Int32 ACount, Boolean ACountOnly) { TDBTransaction ReadTransaction; Boolean NewTransaction = false; PSubscriptionTable SubscriptionDT; SubscriptionDT = new PSubscriptionTable(); try { ReadTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.RepeatableRead, TEnforceIsolationLevel.eilMinimum, out NewTransaction); if (ACountOnly) { ACount = PSubscriptionAccess.CountViaPPartnerPartnerKey(FPartnerKey, ReadTransaction); } else { // TLogging.LogAtLevel(7, "TPartnerEditUIConnector.GetSubscriptionsInternal: loading Subscriptions for Partner " + FPartnerKey.ToString() + "..."); try { SubscriptionDT = PSubscriptionAccess.LoadViaPPartnerPartnerKey(FPartnerKey, ReadTransaction); } catch (Exception) { throw; } ACount = SubscriptionDT.Rows.Count; } } finally { if (NewTransaction) { DBAccess.GDBAccessObj.CommitTransaction(); TLogging.LogAtLevel(7, "TPartnerEditUIConnector.GetSubscriptionsInternal: committed own transaction."); } } return SubscriptionDT; }
/// <summary> /// todoComment /// </summary> /// <param name="e"></param> /// <param name="AVerificationResultCollection"></param> /// <param name="AVerificationResult"></param> /// <param name="FDataColumnComparedTo"></param> public static void VerifySubscriptionDates(DataColumnChangeEventArgs e, TVerificationResultCollection AVerificationResultCollection, out TVerificationResult AVerificationResult, out DataColumn FDataColumnComparedTo) { FDataColumnComparedTo = null; AVerificationResult = null; DateTime DateStarted = new DateTime(); DateTime DateExpired = new DateTime(); DateTime DateRenewed = new DateTime(); DateTime DateNoticeSent = new DateTime(); DateTime DateEnded = new DateTime(); DateTime DateFirstSent = new DateTime(); DateTime DateLastSent = new DateTime(); Boolean Completed; Completed = false; if (e.Column.ColumnName == PSubscriptionTable.GetStartDateDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.ProposedValue); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetExpiryDateDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.ProposedValue); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetSubscriptionRenewalDateDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.ProposedValue); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetDateNoticeSentDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.ProposedValue); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetDateCancelledDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.ProposedValue); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetFirstIssueDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.ProposedValue); DateLastSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetLastIssueDBName()]); } if (e.Column.ColumnName == PSubscriptionTable.GetLastIssueDBName()) { DateStarted = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetStartDateDBName()]); DateExpired = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetExpiryDateDBName()]); DateRenewed = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]); DateNoticeSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateNoticeSentDBName()]); DateEnded = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetDateCancelledDBName()]); DateFirstSent = TSaveConvert.ObjectToDate(e.Row[PSubscriptionTable.GetFirstIssueDBName()]); DateLastSent = TSaveConvert.ObjectToDate(e.ProposedValue); } while (!Completed) { // when the StartDate has changed, do this: if (e.Column.ColumnName == PSubscriptionTable.GetStartDateDBName()) { FDataColumnComparedTo = e.Column; TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted, DateExpired, DateRenewed, DateNoticeSent, DateEnded, DateFirstSent, DateLastSent, out AVerificationResult, out Completed); if (Completed == true) { break; } } if (e.Column.ColumnName == PSubscriptionTable.GetExpiryDateDBName()) { FDataColumnComparedTo = e.Column; TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted, DateExpired, DateRenewed, DateNoticeSent, DateEnded, DateFirstSent, DateLastSent, out AVerificationResult, out Completed); if (Completed == true) { break; } } if (e.Column.ColumnName == PSubscriptionTable.GetSubscriptionRenewalDateDBName()) { FDataColumnComparedTo = e.Column; TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted, DateExpired, DateRenewed, DateNoticeSent, DateEnded, DateFirstSent, DateLastSent, out AVerificationResult, out Completed); if (Completed == true) { break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateTime.Today, "Date Renewed", "Today") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateTime.Today, "DateRenewed", "Today"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateExpired, "Date Renewed", "Date Expired") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateExpired, "Date Renewed", "Date Expired"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateNoticeSent, "Date Renewed", "Date Notice Sent") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateRenewed, DateNoticeSent, "Date Renewed", "Date Notice Sent"); Completed = true; break; } } if (e.Column.ColumnName == PSubscriptionTable.GetDateNoticeSentDBName()) { FDataColumnComparedTo = e.Column; TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted, DateExpired, DateRenewed, DateNoticeSent, DateEnded, DateFirstSent, DateLastSent, out AVerificationResult, out Completed); if (Completed == true) { break; } } if (e.Column.ColumnName == PSubscriptionTable.GetDateCancelledDBName()) { FDataColumnComparedTo = e.Column; TPartnerSubscriptionVerification.VerifyDatesAgainstStartDate(DateStarted, DateExpired, DateRenewed, DateNoticeSent, DateEnded, DateFirstSent, DateLastSent, out AVerificationResult, out Completed); if (Completed == true) { break; } if (TDateChecks.FirstLesserThanSecondDate(DateTime.Today, DateEnded, "Today", "Cancelled") != null) { AVerificationResult = TDateChecks.FirstLesserThanSecondDate(DateTime.Today, DateEnded, "Today", "Cancelled"); Completed = true; break; } } if (e.Column.ColumnName == PSubscriptionTable.GetFirstIssueDBName()) { FDataColumnComparedTo = e.Column; if (TDateChecks.FirstGreaterOrEqualThanSecondDate(DateLastSent, DateFirstSent, "Last Sent", "First Sent") != null) { AVerificationResult = TDateChecks.FirstGreaterOrEqualThanSecondDate(DateLastSent, DateFirstSent, "Last Sent", "First Sent"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateFirstSent, "Date Started", "First Sent") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateStarted, DateFirstSent, "Date Started", "First Sent"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateFirstSent, DateTime.Today, "First Sent", "today") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateFirstSent, DateTime.Today, "First Sent", "today"); Completed = true; break; } } if (e.Column.ColumnName == PSubscriptionTable.GetLastIssueDBName()) { FDataColumnComparedTo = e.Column; if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateFirstSent, DateLastSent, "First Sent", "Last Sent") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateFirstSent, DateLastSent, "First Sent", "Last Sent"); Completed = true; break; } if (TDateChecks.FirstLesserOrEqualThanSecondDate(DateLastSent, DateTime.Today, "Last Sent", "today") != null) { AVerificationResult = TDateChecks.FirstLesserOrEqualThanSecondDate(DateLastSent, DateTime.Today, "Last Sent", "today"); Completed = true; break; } } Completed = true; } }
private void InitializeManualCode() { // show this dialog in center of screen this.StartPosition = FormStartPosition.CenterScreen; // remove validation handler for controls as we only want validation when clicking the ok button cmbPSubscriptionPublicationCode.Validated -= new System.EventHandler(this.ControlValidatedHandler); cmbPSubscriptionSubscriptionStatus.Validated -= new System.EventHandler(this.ControlValidatedHandler); chkPSubscriptionGratisSubscription.Validated -= new System.EventHandler(this.ControlValidatedHandler); txtPSubscriptionNumberComplimentary.Validated -= new System.EventHandler(this.ControlValidatedHandler); txtPSubscriptionPublicationCopies.Validated -= new System.EventHandler(this.ControlValidatedHandler); cmbPSubscriptionReasonSubsGivenCode.Validated -= new System.EventHandler(this.ControlValidatedHandler); cmbPSubscriptionReasonSubsCancelledCode.Validated -= new System.EventHandler(this.ControlValidatedHandler); txtPSubscriptionGiftFromKey.Validated -= new System.EventHandler(this.ControlValidatedHandler); dtpPSubscriptionStartDate.Validated -= new System.EventHandler(this.ControlValidatedHandler); dtpPSubscriptionExpiryDate.Validated -= new System.EventHandler(this.ControlValidatedHandler); dtpPSubscriptionDateCancelled.Validated -= new System.EventHandler(this.ControlValidatedHandler); dtpPSubscriptionDateNoticeSent.Validated -= new System.EventHandler(this.ControlValidatedHandler); dtpPSubscriptionSubscriptionRenewalDate.Validated -= new System.EventHandler(this.ControlValidatedHandler); dtpPSubscriptionFirstIssue.Validated -= new System.EventHandler(this.ControlValidatedHandler); dtpPSubscriptionLastIssue.Validated -= new System.EventHandler(this.ControlValidatedHandler); txtPSubscriptionNumberIssuesReceived.Validated -= new System.EventHandler(this.ControlValidatedHandler); FMainDS = new PartnerEditTDS(); // now add the one subscription row to the DS that we are working with PSubscriptionTable SubscriptionTable = new PSubscriptionTable(); FMainDS.Merge(SubscriptionTable); PSubscriptionRow SubscriptionRow = FMainDS.PSubscription.NewRowTyped(true); SubscriptionRow.PublicationCode = ""; // avoid NOT NULL error message FMainDS.PSubscription.Rows.Add(SubscriptionRow); FPetraUtilsObject.HasChanges = false; // initialize all check box sections so fields are disabled OnTickChangeItem(chkChangeSubscriptionStatus, null); OnTickChangeItem(chkChangeGratisSubscription, null); OnTickChangeItem(chkChangeNumberComplimentary, null); OnTickChangeItem(chkChangePublicationCopies, null); OnTickChangeItem(chkChangeReasonSubsGivenCode, null); OnTickChangeItem(chkChangeReasonSubsCancelledCode, null); OnTickChangeItem(chkChangeGiftFromKey, null); OnTickChangeItem(chkChangeStartDate, null); OnTickChangeItem(chkChangeExpiryDate, null); OnTickChangeItem(chkChangeRenewalDate, null); OnTickChangeItem(chkChangeDateNoticeSent, null); OnTickChangeItem(chkChangeDateCancelled, null); OnTickChangeItem(chkChangeNumberIssuesReceived, null); OnTickChangeItem(chkChangeFirstIssue, null); OnTickChangeItem(chkChangeLastIssue, null); // Hook up this event manually here after all initalisation has happened as otherwise // Bug #2481 would occur if the first Publication in the 'Publication Code' ComboBox is not Valid cmbPSubscriptionPublicationCode.SelectedValueChanged += new System.EventHandler(this.PublicationCodeChanged); }
/// <summary> /// Called by the instantiator of this Dialog to retrieve the values of Fields /// on the screen. /// </summary> /// <param name="ARow"></param> /// <param name="AFieldsToChange"></param> /// <returns>Boolean</returns> public Boolean GetReturnedParameters(ref PSubscriptionRow ARow, ref List <String> AFieldsToChange) { Boolean ReturnValue = true; ARow.InitValues(); AFieldsToChange.Clear(); // publication code needs to be set, otherwise change can not be performed if (cmbPSubscriptionPublicationCode.GetSelectedString() == "") { return(false); } ARow.PublicationCode = cmbPSubscriptionPublicationCode.GetSelectedString(); if (chkChangeSubscriptionStatus.Checked) { AFieldsToChange.Add(PSubscriptionTable.GetSubscriptionStatusDBName()); ARow.SubscriptionStatus = cmbPSubscriptionSubscriptionStatus.Text; } if (chkChangeGratisSubscription.Checked) { AFieldsToChange.Add(PSubscriptionTable.GetGratisSubscriptionDBName()); ARow.GratisSubscription = chkPSubscriptionGratisSubscription.Checked; } if (chkChangeNumberComplimentary.Checked && txtPSubscriptionNumberComplimentary.NumberValueInt.HasValue) { AFieldsToChange.Add(PSubscriptionTable.GetNumberComplimentaryDBName()); ARow.NumberComplimentary = txtPSubscriptionNumberComplimentary.NumberValueInt.Value; } if (chkChangePublicationCopies.Checked && txtPSubscriptionPublicationCopies.NumberValueInt.HasValue) { AFieldsToChange.Add(PSubscriptionTable.GetPublicationCopiesDBName()); ARow.PublicationCopies = txtPSubscriptionPublicationCopies.NumberValueInt.Value; } if (chkChangeReasonSubsGivenCode.Checked) { AFieldsToChange.Add(PSubscriptionTable.GetReasonSubsGivenCodeDBName()); ARow.ReasonSubsGivenCode = cmbPSubscriptionReasonSubsGivenCode.GetSelectedString(); } if (chkChangeReasonSubsCancelledCode.Checked) { AFieldsToChange.Add(PSubscriptionTable.GetReasonSubsCancelledCodeDBName()); ARow.ReasonSubsCancelledCode = cmbPSubscriptionReasonSubsCancelledCode.GetSelectedString(); } if (chkChangeGiftFromKey.Checked) { AFieldsToChange.Add(PSubscriptionTable.GetGiftFromKeyDBName()); ARow.GiftFromKey = Convert.ToInt64(txtPSubscriptionGiftFromKey.Text); } if (chkChangeStartDate.Checked && dtpPSubscriptionStartDate.Date.HasValue) { AFieldsToChange.Add(PSubscriptionTable.GetStartDateDBName()); ARow.StartDate = dtpPSubscriptionStartDate.Date.Value; } if (chkChangeExpiryDate.Checked) { AFieldsToChange.Add(PSubscriptionTable.GetExpiryDateDBName()); ARow.ExpiryDate = dtpPSubscriptionExpiryDate.Date; } if (chkChangeRenewalDate.Checked) { AFieldsToChange.Add(PSubscriptionTable.GetSubscriptionRenewalDateDBName()); ARow.SubscriptionRenewalDate = dtpPSubscriptionSubscriptionRenewalDate.Date; } if (chkChangeDateNoticeSent.Checked) { AFieldsToChange.Add(PSubscriptionTable.GetDateNoticeSentDBName()); ARow.DateNoticeSent = dtpPSubscriptionDateNoticeSent.Date; } if (chkChangeDateCancelled.Checked) { AFieldsToChange.Add(PSubscriptionTable.GetDateCancelledDBName()); ARow.DateCancelled = dtpPSubscriptionDateCancelled.Date; } if (chkChangeNumberIssuesReceived.Checked && txtPSubscriptionNumberIssuesReceived.NumberValueInt.HasValue) { AFieldsToChange.Add(PSubscriptionTable.GetNumberIssuesReceivedDBName()); ARow.NumberIssuesReceived = txtPSubscriptionNumberIssuesReceived.NumberValueInt.Value; } if (chkChangeFirstIssue.Checked) { AFieldsToChange.Add(PSubscriptionTable.GetFirstIssueDBName()); ARow.FirstIssue = dtpPSubscriptionFirstIssue.Date; } if (chkChangeLastIssue.Checked) { AFieldsToChange.Add(PSubscriptionTable.GetLastIssueDBName()); ARow.LastIssue = dtpPSubscriptionLastIssue.Date; } return(ReturnValue); }
/// <summary> /// First loads the extractTable needed. Goes throught all the Partners in the extract, If the partner already has the subscription, returns all those partners back to client. If the partner doesn't have the subscription, saves this /// subscription to those partners. /// </summary> /// <returns>void</returns> private void SubmitChangesInternal() { TDBTransaction SubmitChangesTransaction = null; TSubmitChangesResult SubmissionResult = TSubmitChangesResult.scrNothingToBeSaved; MExtractTable ExtractDT; PSubscriptionTable SubscriptionTable; PPartnerTable PartnerTable; Int32 RowCounter; Int32 PartnersInExtract; StringCollection RequiredColumns; StringCollection RequiredColumns2; if (FInspectDT != null) { // Initialisations FVerificationResult = new TVerificationResultCollection(); ExtractDT = new MExtractTable(); SubscriptionTable = new PSubscriptionTable(); FSubmissionDT = SubscriptionTable.Clone(); ((TTypedDataTable)FSubmissionDT).InitVars(); PartnerTable = new PPartnerTable(); RequiredColumns = new StringCollection(); RequiredColumns.Add(MExtractTable.GetPartnerKeyDBName()); RequiredColumns2 = new StringCollection(); RequiredColumns2.Add(PPartnerTable.GetPartnerKeyDBName()); RequiredColumns2.Add(PPartnerTable.GetPartnerShortNameDBName()); RowCounter = 0; // Set up asynchronous execution TProgressTracker.SetCurrentState(FProgressID, "Checking Partners' Subscriptions...", 0.0m); DBAccess.GDBAccessObj.BeginAutoTransaction(IsolationLevel.Serializable, ref SubmitChangesTransaction, ref SubmissionResult, delegate { try { // TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: loading Subscriptions for ExtractID " + FExtractID.ToString() + "..."); ExtractDT = MExtractAccess.LoadViaMExtractMaster(FExtractID, RequiredColumns, SubmitChangesTransaction); PartnersInExtract = ExtractDT.Rows.Count; // TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: ExtractID has " + PartnersInExtract.ToString() + " Partners."); // Go throught all the Partners in the extract foreach (MExtractRow ExtractRow in ExtractDT.Rows) { RowCounter = RowCounter + 1; // Calculate how much Partners we have checked. Let all Partners be a maximum of 70%. TProgressTracker.SetCurrentState( FProgressID, string.Empty, Convert.ToInt16((((double)RowCounter / (double)PartnersInExtract) * 100) * (MAX_PERCENTAGE_CHECKS / 100.0))); TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: loadbyPrimaryKey"); SubscriptionTable = PSubscriptionAccess.LoadByPrimaryKey( FInspectDT[0].PublicationCode, ExtractRow.PartnerKey, SubmitChangesTransaction); // if the Partner does not yet have the subscription, add the subscription to this partner. if (SubscriptionTable.Rows.Count == 0) { TLogging.LogAtLevel( 7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: will add Subscription to Partner with PartnerKey " + ExtractRow.PartnerKey.ToString()); FInspectDT[0].PartnerKey = ExtractRow.PartnerKey; TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: importing Row into FSubmissionDT..."); FSubmissionDT.ImportRow(FInspectDT[0]); } else { // The partner already has this Subscription: add the partner to the ResponseTable // TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: won't add Subscription to Partner with PartnerKey " + ExtractRow.PartnerKey.ToString()); PartnerTable = PPartnerAccess.LoadByPrimaryKey(ExtractRow.PartnerKey, RequiredColumns2, SubmitChangesTransaction); if (FResponseDT == null) { FResponseDT = PartnerTable.Clone(); } FResponseDT.ImportRow(PartnerTable[0]); } } TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: Finished checking Partner's Subscriptions."); if (FSubmissionDT.Rows.Count > 0) { // Submit the Partners with new Subscriptions to the PSubscription Table. TProgressTracker.SetCurrentState( FProgressID, "Adding Subscriptions to " + FSubmissionDT.Rows.Count.ToString() + " Partners...", MAX_PERCENTAGE_CHECKS); // TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: " + FAsyncExecProgress.ProgressInformation); PSubscriptionAccess.SubmitChanges((PSubscriptionTable)FSubmissionDT, SubmitChangesTransaction); } else { TLogging.LogAtLevel( 7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: no Subscriptions were added to Partners because all the Partners in the Extract already had this Subscription."); } SubmissionResult = TSubmitChangesResult.scrOK; } catch (Exception Exp) { TLogging.LogAtLevel(7, "TExtractsAddSubscriptionsUIConnector.SubmitChangesInternal: Exception occured, Transaction will get ROLLED BACK. Exception: " + Exp.ToString()); SubmissionResult = TSubmitChangesResult.scrError; FSubmitResult = SubmissionResult; FSubmitException = Exp; TProgressTracker.CancelJob(FProgressID); return; } }); } // if no values at response table, it needs to be created. If not creates, will raise exeption at client side. if (FResponseDT == null) { FResponseDT = new DataTable(); } TProgressTracker.FinishJob(FProgressID); FSubmitResult = SubmissionResult; }
/// <summary> /// Count the subscriptions /// </summary> /// <param name="ATable">table with subscriptions</param> /// <param name="ATotalSubscriptions">returns the total number of subscriptions</param> /// <param name="AActiveSubscriptions">returns the number of active subscriptions</param> public static void CalculateTabCountsSubscriptions(PSubscriptionTable ATable, out Int32 ATotalSubscriptions, out Int32 AActiveSubscriptions) { // Inspect only CurrentRows (this excludes Deleted DataRows) ATotalSubscriptions = new DataView(ATable, "", "", DataViewRowState.CurrentRows).Count; // Inspect only CurrentRows (this excludes Deleted DataRows) AActiveSubscriptions = new DataView(ATable, PSubscriptionTable.GetSubscriptionStatusDBName() + " <> '" + MPartnerConstants.SUBSCRIPTIONS_STATUS_CANCELLED + "' AND " + PSubscriptionTable.GetSubscriptionStatusDBName() + " <> '" + MPartnerConstants.SUBSCRIPTIONS_STATUS_EXPIRED + "'", "", DataViewRowState.CurrentRows).Count; }
/// <summary> /// todoComment /// </summary> /// <param name="Row"></param> /// <param name="AVerificationResultCollection"></param> /// <param name="VerificationResult"></param> /// <param name="AErroneousDC"></param> /// <param name="FtmpPartnerKeyValid"></param> /// <returns></returns> public static Boolean VerifySubscriptionDataFinal(PSubscriptionRow Row, out TVerificationResultCollection AVerificationResultCollection, out TVerificationResult VerificationResult, out DataColumn AErroneousDC, Boolean FtmpPartnerKeyValid) { Boolean ReturnValue; Boolean Completed; //Boolean NoErrors; TVerificationResultCollection TmpCollection = null; //TVerificationResult TmpError; DataColumn TmpDC; DataColumn NilDataColumn; String mVerifiedString; bool mPartnerExists; TPartnerClass mPartnerClass; TStdPartnerStatusCode partnerStatus; TPartnerClass[] mPartnerClassSet; Completed = false; ReturnValue = false; VerificationResult = null; AVerificationResultCollection = null; AErroneousDC = null; while (!Completed) { TmpDC = Row.Table.Columns[PSubscriptionTable.GetStartDateDBName()]; VerifySubscriptionDates(new DataColumnChangeEventArgs(Row, TmpDC, Row[PSubscriptionTable.GetStartDateDBName()]), TmpCollection, out VerificationResult, out NilDataColumn); if (VerificationResult != null) { Completed = true; ReturnValue = false; AErroneousDC = TmpDC; break; } TmpDC = Row.Table.Columns[PSubscriptionTable.GetExpiryDateDBName()]; VerifySubscriptionDates(new DataColumnChangeEventArgs(Row, TmpDC, Row[PSubscriptionTable.GetExpiryDateDBName()]), TmpCollection, out VerificationResult, out NilDataColumn); if (VerificationResult != null) { Completed = true; ReturnValue = false; AErroneousDC = TmpDC; break; } TmpDC = Row.Table.Columns[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]; VerifySubscriptionDates(new DataColumnChangeEventArgs(Row, TmpDC, Row[PSubscriptionTable.GetSubscriptionRenewalDateDBName()]), TmpCollection, out VerificationResult, out NilDataColumn); if (VerificationResult != null) { Completed = true; ReturnValue = false; AErroneousDC = TmpDC; break; } TmpDC = Row.Table.Columns[PSubscriptionTable.GetDateNoticeSentDBName()]; VerifySubscriptionDates(new DataColumnChangeEventArgs(Row, TmpDC, Row[PSubscriptionTable.GetDateNoticeSentDBName()]), TmpCollection, out VerificationResult, out NilDataColumn); if (VerificationResult != null) { Completed = true; ReturnValue = false; AErroneousDC = TmpDC; break; } TmpDC = Row.Table.Columns[PSubscriptionTable.GetDateCancelledDBName()]; VerifySubscriptionDates(new DataColumnChangeEventArgs(Row, TmpDC, Row[PSubscriptionTable.GetDateCancelledDBName()]), TmpCollection, out VerificationResult, out NilDataColumn); if (VerificationResult != null) { Completed = true; ReturnValue = false; AErroneousDC = TmpDC; break; } TmpDC = Row.Table.Columns[PSubscriptionTable.GetFirstIssueDBName()]; VerifySubscriptionDates(new DataColumnChangeEventArgs(Row, TmpDC, Row[PSubscriptionTable.GetFirstIssueDBName()]), TmpCollection, out VerificationResult, out NilDataColumn); if (VerificationResult != null) { Completed = true; ReturnValue = false; AErroneousDC = TmpDC; break; } TmpDC = Row.Table.Columns[PSubscriptionTable.GetLastIssueDBName()]; VerifySubscriptionDates(new DataColumnChangeEventArgs(Row, TmpDC, Row[PSubscriptionTable.GetLastIssueDBName()]), TmpCollection, out VerificationResult, out NilDataColumn); if (VerificationResult != null) { Completed = true; ReturnValue = false; AErroneousDC = TmpDC; break; } // if subscription status is cancelled, is there a partner that gives the gift. TmpDC = Row.Table.Columns[PSubscriptionTable.GetGiftFromKeyDBName()]; if (Row.IsSubscriptionStatusNull()) { // we go no further: VerificationResult = new TVerificationResult("", "Please select a valid subscription status", "Subscription Status Mandatory", "X_0041", TResultSeverity.Resv_Critical); Completed = true; ReturnValue = false; AErroneousDC = TmpDC; // escape before we crash return(false); } if (Row.SubscriptionStatus == "GIFT") { // validate partner key again, to be sure! mPartnerClassSet = new TPartnerClass[0]; FtmpPartnerKeyValid = TServerLookup.TMPartner.VerifyPartner(Row.GiftFromKey, mPartnerClassSet, out mPartnerExists, out mVerifiedString, out mPartnerClass, out partnerStatus); } if ((Row.SubscriptionStatus == "GIFT") && ((!FtmpPartnerKeyValid) || (Row.GiftFromKey == 00000000))) { // MessageBox.Show('FtmpPartnerKeyValid: ' + FtmpPartnerKeyValid.toString); VerificationResult = new TVerificationResult("", StrGiftGivenByMandatory, StrGiftGivenByMandatoryTitle, "", TResultSeverity.Resv_Critical); Completed = true; ReturnValue = false; AErroneousDC = TmpDC; break; } TmpDC = Row.Table.Columns[PSubscriptionTable.GetReasonSubsCancelledCodeDBName()]; if ((Row.SubscriptionStatus == "CANCELLED") && (Row.IsReasonSubsCancelledCodeNull())) { VerificationResult = new TVerificationResult("", "Please select reason for the cancellation", "Reason for Cancellation Mandatory", "X_0041", TResultSeverity.Resv_Critical); Completed = true; ReturnValue = false; AErroneousDC = TmpDC; break; } else { if ((Row.SubscriptionStatus == "CANCELLED") && (Row.ReasonSubsCancelledCode.Length < 2)) { VerificationResult = new TVerificationResult("", "Please select reason for the cancellation", "Reason for Cancellation Mandatory", "X_0041", TResultSeverity.Resv_Critical); Completed = true; ReturnValue = false; AErroneousDC = TmpDC; break; } } TmpDC = Row.Table.Columns[PSubscriptionTable.GetReasonSubsCancelledCodeDBName()]; if ((Row.SubscriptionStatus == "EXPIRED") && (Row.IsReasonSubsCancelledCodeNull())) { VerificationResult = new TVerificationResult("", "Please select reason for the cancellation", "Reason for Cancellation Mandatory", "X_0041", TResultSeverity.Resv_Critical); Completed = true; ReturnValue = false; AErroneousDC = TmpDC; break; } else { if ((Row.SubscriptionStatus == "EXPIRED") && (Row.ReasonSubsCancelledCode.Length < 2)) { VerificationResult = new TVerificationResult("", "Please select reason for the cancellation", "Reason for Cancellation Mandatory", "X_0041", TResultSeverity.Resv_Critical); Completed = true; ReturnValue = false; AErroneousDC = TmpDC; break; } } TmpDC = Row.Table.Columns[PSubscriptionTable.GetReasonSubsGivenCodeDBName()]; try { if (Row.ReasonSubsGivenCode.Length < 2) { VerificationResult = new TVerificationResult("", "Please select reason for the Gift", "Reason for Gift Mandatory", "X_0041", TResultSeverity.Resv_Critical); Completed = true; ReturnValue = false; AErroneousDC = TmpDC; break; } } catch (Exception) { VerificationResult = new TVerificationResult("", "Please select reason why the publication is given", "Reason for Gift Mandatory", "X_0041", TResultSeverity.Resv_Critical); Completed = true; ReturnValue = false; AErroneousDC = TmpDC; break; } Completed = true; ReturnValue = true; } return(ReturnValue); }
/// <summary> /// todoComment /// </summary> /// <param name="e"></param> /// <param name="AVerificationResultCollection"></param> /// <param name="AVerificationResult"></param> /// <param name="FDataColumnComparedTo"></param> /// <returns></returns> public static Boolean VerifySubscriptionData(DataColumnChangeEventArgs e, TVerificationResultCollection AVerificationResultCollection, out TVerificationResult AVerificationResult, out DataColumn FDataColumnComparedTo) { Boolean ReturnValue; AVerificationResult = null; DataColumn FDataColumnComparedTo2 = null; if ((e.Column.ColumnName == PSubscriptionTable.GetDateCancelledDBName()) || (e.Column.ColumnName == PSubscriptionTable.GetExpiryDateDBName()) || (e.Column.ColumnName == PSubscriptionTable.GetDateNoticeSentDBName()) || (e.Column.ColumnName == PSubscriptionTable.GetStartDateDBName()) || (e.Column.ColumnName == PSubscriptionTable.GetSubscriptionRenewalDateDBName()) || (e.Column.ColumnName == PSubscriptionTable.GetFirstIssueDBName()) || (e.Column.ColumnName == PSubscriptionTable.GetLastIssueDBName())) { VerifySubscriptionDates(e, AVerificationResultCollection, out AVerificationResult, out FDataColumnComparedTo2); } FDataColumnComparedTo = FDataColumnComparedTo2; // if (e.Column.Ordinal = (e.Column.Table as PPartnerLocationTable).ColumnEmailAddress.Ordinal) then // begin // VerifyEMailAddress(e, AVerificationResult); // end; if ((e.Column.ColumnName == PSubscriptionTable.GetPublicationCopiesDBName()) || (e.Column.ColumnName == PSubscriptionTable.GetNumberIssuesReceivedDBName()) || (e.Column.ColumnName == PSubscriptionTable.GetNumberComplimentaryDBName())) { VerifyInteger(e, out AVerificationResult); } // any verification errors? if (AVerificationResult == null) { ReturnValue = true; } else { ReturnValue = false; } return(ReturnValue); }
/// <summary> /// Change subscription for Partners in selected Extract /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void ChangeSubscription(System.Object sender, EventArgs e) { PSubscriptionTable SubscriptionTable = new PSubscriptionTable(); PSubscriptionRow SubscriptionRow = SubscriptionTable.NewRowTyped(); PPartnerTable PartnersWithoutSubs = new PPartnerTable(); int SubscriptionsChanged; String MessageText; List <String>FieldsToChange = new List <string>(); if (!WarnIfNotSingleSelection(Catalog.GetString("Add Subscription")) && (GetSelectedDetailRow() != null)) { TFrmUpdateExtractChangeSubscriptionDialog dialog = new TFrmUpdateExtractChangeSubscriptionDialog(this.FindForm()); dialog.SetExtractName(GetSelectedDetailRow().ExtractName); if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (dialog.GetReturnedParameters(ref SubscriptionRow, ref FieldsToChange)) { SubscriptionTable.Rows.Add(SubscriptionRow); // perform update of extract data on server side TRemote.MPartner.Partner.WebConnectors.ChangeSubscription (GetSelectedDetailRow().ExtractId, ref SubscriptionTable, FieldsToChange, out PartnersWithoutSubs, out SubscriptionsChanged); MessageText = String.Format(Catalog.GetString( "Subscription {0} successfully changed for {1} out of {2} Partner(s) in Extract {3}."), SubscriptionRow.PublicationCode, SubscriptionsChanged, GetSelectedDetailRow().KeyCount, GetSelectedDetailRow().ExtractName); if (PartnersWithoutSubs.Rows.Count > 0) { MessageText += "\r\n\r\n" + String.Format(Catalog.GetString( "See the following Dialog for the {0} Partner(s) that are not subscribed for this Publication and therefore no change was made for them."), PartnersWithoutSubs.Rows.Count); } MessageBox.Show(MessageText, Catalog.GetString("Change Subscription"), MessageBoxButtons.OK, MessageBoxIcon.Information); if (PartnersWithoutSubs.Rows.Count > 0) { TFrmSimplePartnerListDialog partnerDialog = new TFrmSimplePartnerListDialog(this.FindForm()); partnerDialog.SetExplanation("These partners do not have a Subscription for " + SubscriptionRow.PublicationCode, "The Subscription was therefore not changed for the following Partners:"); partnerDialog.SetPartnerList(PartnersWithoutSubs); partnerDialog.ShowDialog(); } } } } }
/// <summary> /// Main calculation of the publication statistical report. /// </summary> /// <param name="ACountryCode"></param> /// <param name="APublicationCodes"></param> private void CalculatePublicationStatisticalReport(String ACountryCode, string APublicationCodes) { DataTable PartnerTable = new DataTable();; PLocationTable LocationTable; PLocationRow LocationRow; // codes should be surrounded by single quotes APublicationCodes = APublicationCodes.Replace("\"", "'"); // load all active partners who have subscriptions for publications in the list, are a donor, are a church, are an applicant or are an ex-worker string Query = "SELECT DISTINCT p_partner.*," + // is partner a donor? " CASE WHEN EXISTS (SELECT * FROM PUB_a_gift" + " WHERE a_gift.p_donor_key_n = p_partner.p_partner_key_n) THEN 'yes'" + " ELSE '' END AS " + COLUMN_DONOR + "," + // is partner an ex-worker? " CASE WHEN EXISTS (SELECT * FROM p_partner_type " + " WHERE p_partner_type.p_partner_key_n = p_partner.p_partner_key_n" + " AND p_partner_type.p_type_code_c LIKE 'EX-WORKER%') THEN 'yes'" + " ELSE 'no' END AS " + COLUMN_EXPARTICIPANTS + "," + // is partner an applicant? " CASE WHEN EXISTS (SELECT * FROM p_partner_type " + " WHERE p_partner_type.p_partner_key_n = p_partner.p_partner_key_n" + " AND p_partner_type.p_type_code_c LIKE 'APPLIED%') THEN 'yes'" + " ELSE 'no' END AS " + COLUMN_APPLICANTS + " FROM p_partner" + " WHERE p_partner.p_status_code_c = 'ACTIVE'" + // if have subscriptions for publications in the list " AND (EXISTS (SELECT * FROM p_subscription" + " WHERE p_subscription.p_partner_key_n = p_partner.p_partner_key_n" + " AND p_subscription.p_publication_code_c IN (" + APublicationCodes + "))" + // if a donor " OR EXISTS (SELECT * FROM PUB_a_gift" + " WHERE a_gift.p_donor_key_n = p_partner.p_partner_key_n)" + // if a church " OR p_partner.p_partner_class_c = 'CHURCH'" + // if an applicant or an ex-worker " OR EXISTS (SELECT * FROM p_partner_type " + " WHERE p_partner_type.p_partner_key_n = p_partner.p_partner_key_n" + " AND (p_partner_type.p_type_code_c LIKE 'EX-WORKER%'" + " OR p_partner_type.p_type_code_c LIKE 'APPLIED%')))"; PartnerTable = DBAccess.GDBAccessObj.SelectDT(PartnerTable, Query, situation.GetDatabaseConnection().Transaction); // get total number of active partners FNumberOfActivePartner = PPartnerAccess.CountViaPPartnerStatus("ACTIVE", situation.GetDatabaseConnection().Transaction); PSubscriptionTable SubscriptionTable = new PSubscriptionTable(); // load all subscriptions for publications in the list Query = "SELECT * FROM p_subscription" + " WHERE p_subscription.p_publication_code_c IN (" + APublicationCodes + ")"; SubscriptionTable = (PSubscriptionTable)DBAccess.GDBAccessObj.SelectDT(SubscriptionTable, Query, situation.GetDatabaseConnection().Transaction); PPartnerLocationRow PartnerLocationRow; Dictionary <String, int>SubscriptionCounter = new Dictionary <String, int>(); InitSubscriptionCounter(ref SubscriptionCounter); Dictionary <String, int>CountyRowList = InitStatisticalReportTable(); // foreach partner that satisfied the above criteria foreach (DataRow PartnerRow in PartnerTable.Rows) { Int64 PartnerKey = Convert.ToInt64(PartnerRow[PPartnerTable.GetPartnerKeyDBName()]); if (GetPartnerBestAddressRow(PartnerKey, situation, out PartnerLocationRow)) { if (PartnerLocationRow == null) { continue; } if ((!PartnerLocationRow.IsDateGoodUntilNull()) && (PartnerLocationRow.DateGoodUntil < System.DateTime.Today)) { // Best address is no longer valid - don't use it continue; } LocationTable = PLocationAccess.LoadByPrimaryKey(PartnerLocationRow.SiteKey, PartnerLocationRow.LocationKey, situation.GetDatabaseConnection().Transaction); if (LocationTable.Rows.Count < 1) { continue; } LocationRow = LocationTable[0]; // TODO what do we do with partners that have 0 as Location key? if (LocationRow.LocationKey == 0) { continue; } String RowName = ROW_FOREIGN; // Use county if in this country, else foreign if ((!LocationRow.IsCountryCodeNull()) && (LocationRow.CountryCode == ACountryCode)) { // partner is OK if (LocationRow.County.Length > 0) { // County RowName = LocationRow.County.ToLower().Trim(); } else { // *NONE* RowName = ROW_NONE; } } // get the subscriptions that this partner receives (if any) DataRow[] Subscriptions = SubscriptionTable.Select(PPartnerTable.GetPartnerKeyDBName() + " = " + PartnerKey); foreach (DataRow Row in Subscriptions) { PSubscriptionRow SubscriptionRow = (PSubscriptionRow)Row; // if there is a cancelled date set, then don't use this subscription in the report if (SubscriptionRow.IsDateCancelledNull() && ((SubscriptionRow.SubscriptionStatus == "PROVISIONAL") || (SubscriptionRow.SubscriptionStatus == "PERMANENT") || (SubscriptionRow.SubscriptionStatus == "GIFT"))) { // Add Value to Table AddToStatisticalReportTable(CountyRowList[RowName], SubscriptionRow.PublicationCode, 1); // Add number of copies to overall "Count:" column AddToStatisticalReportTable(CountyRowList[ROW_COUNT], SubscriptionRow.PublicationCode, SubscriptionRow.PublicationCopies); } } // partner is a donor if (PartnerRow[COLUMN_DONOR].ToString() == "yes") { AddToStatisticalReportTable(CountyRowList[RowName], COLUMN_DONOR, 1); } // partner is church if (PartnerRow[PPartnerTable.GetPartnerClassDBName()].ToString() == "CHURCH") { AddToStatisticalReportTable(CountyRowList[RowName], COLUMN_CHURCH, 1); } // partner is an applicant if (PartnerRow[COLUMN_APPLICANTS].ToString() == "yes") { AddToStatisticalReportTable(CountyRowList[RowName], COLUMN_APPLICANTS, 1); } // partner is an ex-worker if (PartnerRow[COLUMN_EXPARTICIPANTS].ToString() == "yes") { AddToStatisticalReportTable(CountyRowList[RowName], COLUMN_EXPARTICIPANTS, 1); } } } // end for each CalculateTotals(); }