Ejemplo n.º 1
0
        public static bool DeleteSponsorshipRecurringGift(
            Int32 ALedgerNumber,
            Int32 ABatchNumber,
            Int32 AGiftTransactionNumber,
            Int32 ADetailNumber,
            out TVerificationResultCollection AVerificationResult)
        {
            AVerificationResult = new TVerificationResultCollection();

            TDBTransaction Transaction = new TDBTransaction();
            SponsorshipTDS MainDS      = new SponsorshipTDS();
            TDataBase      DB          = DBAccess.Connect("DeleteRecurringGift");

            // load batches and their transactions based on their id / batch number
            DB.ReadTransaction(ref Transaction, delegate {
                ARecurringGiftBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, Transaction);
                ARecurringGiftAccess.LoadViaARecurringGiftBatch(MainDS, ALedgerNumber, ABatchNumber, Transaction);
                ARecurringGiftDetailAccess.LoadViaARecurringGiftBatch(MainDS, ALedgerNumber, ABatchNumber, Transaction);
            });

            try
            {
                bool LastDetail = true;
                ARecurringGiftDetailRow DetailToDelete = null;
                ARecurringGiftRow       GiftToDelete   = null;
                foreach (ARecurringGiftDetailRow CheckGiftDetailRow in MainDS.ARecurringGiftDetail.Rows)
                {
                    if (CheckGiftDetailRow.GiftTransactionNumber == AGiftTransactionNumber)
                    {
                        if (CheckGiftDetailRow.DetailNumber == ADetailNumber)
                        {
                            DetailToDelete = CheckGiftDetailRow;
                            DetailToDelete.DetailNumber = 20000;
                        }
                        else
                        {
                            LastDetail = false;
                            if (CheckGiftDetailRow.DetailNumber > ADetailNumber)
                            {
                                CheckGiftDetailRow.DetailNumber--;
                            }
                        }
                    }
                }

                foreach (ARecurringGiftRow CheckGiftRow in MainDS.ARecurringGift.Rows)
                {
                    if (CheckGiftRow.GiftTransactionNumber == AGiftTransactionNumber)
                    {
                        if (LastDetail)
                        {
                            GiftToDelete = CheckGiftRow;
                        }
                        else
                        {
                            CheckGiftRow.LastDetailNumber--;
                        }
                    }
                }

                // delete the detail
                if (DetailToDelete != null)
                {
                    DetailToDelete.Delete();
                }

                // delete the gift
                if (GiftToDelete != null)
                {
                    // we keep the gift transaction numbers, and live with gaps.
                    GiftToDelete.Delete();
                }

                SponsorshipTDSAccess.SubmitChanges(MainDS, DB);
                return(true);
            }
            catch (Exception e)
            {
                TLogging.Log(e.ToString());
                AVerificationResult.Add(new TVerificationResult("error", e.Message, TResultSeverity.Resv_Critical));
                return(false);
            }
            finally
            {
                DB.CloseDBConnection();
            }
        }
Ejemplo n.º 2
0
        public static bool MaintainSponsorshipRecurringGifts(
            Int32 ALedgerNumber,
            Int32 ABatchNumber,
            Int32 AGiftTransactionNumber,
            Int32 ADetailNumber,
            Int64 ARecipientKey,
            Int64 ADonorKey,
            String AMotivationGroupCode,
            String AMotivationDetailCode,
            decimal AGiftAmount,
            DateTime AStartDonations,
            DateTime?AEndDonations,
            out TVerificationResultCollection AVerificationResult)
        {
            AVerificationResult = new TVerificationResultCollection();

            if (ADonorKey <= 0)
            {
                AVerificationResult.Add(new TVerificationResult("error", "Please specify the donor", "",
                                                                "MaintainChildren.ErrMissingDonor", TResultSeverity.Resv_Critical));
            }

            if (AGiftAmount <= 0)
            {
                AVerificationResult.Add(new TVerificationResult("error", "Please specify a valid amount", "",
                                                                "MaintainChildren.ErrMissingAmount", TResultSeverity.Resv_Critical));
            }

            if ((AMotivationDetailCode == "") || (AMotivationDetailCode == null))
            {
                AVerificationResult.Add(new TVerificationResult("error", "Please specify the motivation", "",
                                                                "MaintainChildren.ErrMissingMotivation", TResultSeverity.Resv_Critical));
            }

            if (AVerificationResult.HasCriticalErrors)
            {
                return(false);
            }

            TDBTransaction Transaction      = new TDBTransaction();
            SponsorshipTDS MainDS           = new SponsorshipTDS();
            TDataBase      DB               = DBAccess.Connect("MaintainRecurringGifts");
            bool           MotivationExists = false;

            // load batches and their transactions based on their id / batch number
            DB.ReadTransaction(ref Transaction, delegate {
                // we overwrite the user input, since the user can't really send the right batch number on create
                ABatchNumber = GetRecurringGiftBatchForSponsorship(ALedgerNumber, Transaction);
                ARecurringGiftBatchAccess.LoadByPrimaryKey(MainDS, ALedgerNumber, ABatchNumber, Transaction);
                ARecurringGiftAccess.LoadViaARecurringGiftBatch(MainDS, ALedgerNumber, ABatchNumber, Transaction);
                MotivationExists = AMotivationDetailAccess.Exists(ALedgerNumber, AMotivationGroupCode, AMotivationDetailCode, Transaction);
            });

            if (!MotivationExists)
            {
                AVerificationResult.Add(new TVerificationResult("error", "Please specify a valid motivation", "",
                                                                "MaintainChildren.ErrMissingMotivation", TResultSeverity.Resv_Critical));
                return(false);
            }

            // try to get a row with requested id, aka edit else make a new
            ARecurringGiftRow EditGiftRow = null;

            foreach (ARecurringGiftRow CheckGiftRow in MainDS.ARecurringGift.Rows)
            {
                if (CheckGiftRow.GiftTransactionNumber == AGiftTransactionNumber)
                {
                    EditGiftRow = CheckGiftRow;
                    break;
                }
            }

            // we did not find a Transaction in this Batch, so we create one
            if (EditGiftRow == null)
            {
                // TODO: we could look for a gift transaction of the same donor???
                EditGiftRow                       = MainDS.ARecurringGift.NewRowTyped(true);
                EditGiftRow.DonorKey              = ADonorKey;
                EditGiftRow.BatchNumber           = ABatchNumber;
                EditGiftRow.LedgerNumber          = ALedgerNumber;
                EditGiftRow.GiftTransactionNumber = MainDS.ARecurringGiftBatch[0].LastGiftNumber + 1;
                MainDS.ARecurringGiftBatch[0].LastGiftNumber++;
                MainDS.ARecurringGift.Rows.Add(EditGiftRow);
            }

            // load stuff based on the current edit row
            DB.ReadTransaction(ref Transaction, delegate {
                ARecurringGiftDetailAccess.LoadViaARecurringGift(MainDS, ALedgerNumber, ABatchNumber, EditGiftRow.GiftTransactionNumber, Transaction);
            });
            DB.CloseDBConnection();

            // try to get a row with requested id, aka edit else make a new
            ARecurringGiftDetailRow EditGiftDetailRow = null;

            foreach (ARecurringGiftDetailRow CheckGiftDetailRow in MainDS.ARecurringGiftDetail.Rows)
            {
                if (CheckGiftDetailRow.DetailNumber == ADetailNumber)
                {
                    EditGiftDetailRow = CheckGiftDetailRow;
                    break;
                }
            }

            // none found, make one
            if (EditGiftDetailRow == null)
            {
                EditGiftDetailRow = MainDS.ARecurringGiftDetail.NewRowTyped(true);
                EditGiftDetailRow.LedgerNumber          = ALedgerNumber;
                EditGiftDetailRow.BatchNumber           = ABatchNumber;
                EditGiftDetailRow.RecipientKey          = ARecipientKey;
                EditGiftDetailRow.GiftTransactionNumber = EditGiftRow.GiftTransactionNumber;
                EditGiftDetailRow.DetailNumber          = EditGiftRow.LastDetailNumber + 1;
                EditGiftRow.LastDetailNumber++;
                MainDS.ARecurringGiftDetail.Rows.Add(EditGiftDetailRow);
            }

            EditGiftRow.DonorKey                   = ADonorKey;
            EditGiftDetailRow.GiftAmount           = AGiftAmount;
            EditGiftDetailRow.MotivationGroupCode  = AMotivationGroupCode;
            EditGiftDetailRow.MotivationDetailCode = AMotivationDetailCode;
            EditGiftDetailRow.EndDonations         = AEndDonations;
            EditGiftDetailRow.StartDonations       = AStartDonations;

            try
            {
                SponsorshipTDSAccess.SubmitChanges(MainDS);
                return(true);
            }
            catch (Exception e)
            {
                TLogging.Log(e.ToString());
                AVerificationResult.Add(new TVerificationResult("error", e.Message, TResultSeverity.Resv_Critical));
                return(false);
            }
        }
Ejemplo n.º 3
0
        public static bool MaintainChildReminders(
            String AComment,
            Int32 AReminderId,
            Int64 APartnerKey,
            DateTime AEventDate,
            DateTime AFirstReminderDate,
            out TVerificationResultCollection AVerificationResult)
        {
            SponsorshipTDS CurrentEdit;

            AVerificationResult = new TVerificationResultCollection();

            if (APartnerKey == -1)
            {
                AVerificationResult.Add(new TVerificationResult("error", "no partner key", TResultSeverity.Resv_Critical));
                return(false);
            }

            string dummy = "";

            CurrentEdit = GetChildDetails(APartnerKey, -1, true, out dummy);

            PPartnerReminderRow EditReminderRow = null;

            // since we get a reminder id from the user (and i don't know how to request one of them)
            // we loop over all reminders, edit it if we found it, and if it's null we add a new one
            foreach (PPartnerReminderRow ReminderRow in CurrentEdit.PPartnerReminder.Rows)
            {
                if (ReminderRow.ReminderId == AReminderId)
                {
                    EditReminderRow = ReminderRow;
                    break;
                }
            }

            // edit
            if (EditReminderRow != null)
            {
                EditReminderRow.EventDate         = AEventDate;
                EditReminderRow.FirstReminderDate = AFirstReminderDate;
                EditReminderRow.Comment           = AComment;
            }
            else
            {
                PPartnerReminderRow NewReminderRow = CurrentEdit.PPartnerReminder.NewRowTyped(true);
                NewReminderRow.PartnerReminderId = -1;
                NewReminderRow.PartnerKey        = APartnerKey;
                NewReminderRow.EventDate         = AEventDate;
                NewReminderRow.FirstReminderDate = AFirstReminderDate;
                NewReminderRow.Comment           = AComment;
                NewReminderRow.ReminderId        = AReminderId;
                CurrentEdit.PPartnerReminder.Rows.Add(NewReminderRow);
            }

            try
            {
                SponsorshipTDSAccess.SubmitChanges(CurrentEdit);
                return(true);
            }
            catch (Exception e)
            {
                TLogging.Log(e.ToString());
                AVerificationResult.Add(new TVerificationResult("error", e.Message, TResultSeverity.Resv_Critical));
                return(false);
            }
        }
Ejemplo n.º 4
0
        public static bool MaintainChildComments(
            string AComment,
            string ACommentType,
            Int32 AIndex,
            Int64 APartnerKey,
            out TVerificationResultCollection AVerificationResult)
        {
            SponsorshipTDS CurrentEdit;

            AVerificationResult = new TVerificationResultCollection();

            if (APartnerKey == -1)
            {
                AVerificationResult.Add(new TVerificationResult("error", "no partner key", TResultSeverity.Resv_Critical));
                return(false);
            }

            string dummy = "";

            CurrentEdit = GetChildDetails(APartnerKey, -1, true, out dummy);

            PPartnerCommentRow EditCommentRow = null;

            // since we get a index from the user (and i don't know how to request one of them)
            // we loop over all comments, edit it if we found it, and if it's null we add a new one
            foreach (PPartnerCommentRow CommentRow in CurrentEdit.PPartnerComment.Rows)
            {
                if (CommentRow.Index == AIndex)
                {
                    EditCommentRow = CommentRow;
                    break;
                }
            }

            // edit
            if (EditCommentRow != null)
            {
                EditCommentRow.Comment = AComment;
            }
            else
            {
                PPartnerCommentRow NewCommentRow = CurrentEdit.PPartnerComment.NewRowTyped(true);
                NewCommentRow.PartnerKey  = APartnerKey;
                NewCommentRow.Comment     = AComment;
                NewCommentRow.CommentType = ACommentType;
                NewCommentRow.Index       = AIndex;
                NewCommentRow.Sequence    = 0; // nobody cares about this value but it must be set
                CurrentEdit.PPartnerComment.Rows.Add(NewCommentRow);
            }

            try
            {
                SponsorshipTDSAccess.SubmitChanges(CurrentEdit);
                return(true);
            }
            catch (Exception e)
            {
                TLogging.Log(e.ToString());
                AVerificationResult.Add(new TVerificationResult("error", e.Message, TResultSeverity.Resv_Critical));
                return(false);
            }
        }
Ejemplo n.º 5
0
        public static bool MaintainChild(
            string ASponsorshipStatus,
            string AFirstName,
            string AFamilyName,
            DateTime?ADateOfBirth,
            string APhoto,
            bool AUploadPhoto,
            string AGender,
            string AUserId,
            Int64 APartnerKey,
            Int32 ALedgerNumber,
            out TVerificationResultCollection AVerificationResult)
        {
            SponsorshipTDS CurrentEdit;

            AVerificationResult = new TVerificationResultCollection();

            if (APartnerKey == -1)
            {
                // no partner key given, so we make a new entry
                CurrentEdit = CreateNewChild();
                if (CurrentEdit.PFamily.Count > 0)
                {
                    CurrentEdit.PFamily[0].PartnerKey = CurrentEdit.PPartner[0].PartnerKey;
                }
            }
            else
            {
                // else we try to get a entry based on the partner key
                string dummy = "0";
                CurrentEdit = GetChildDetails(APartnerKey, ALedgerNumber, true, out dummy);
            }

            // we only save pictures if there is a value in the request
            if (AUploadPhoto)
            {
                CurrentEdit.PFamily[0].Photo = APhoto;
            }
            else
            {
                if ((ASponsorshipStatus == "") || (ASponsorshipStatus == null))
                {
                    AVerificationResult.Add(new TVerificationResult("error", "Please specify the status of the sponsorship", "",
                                                                    "MaintainChildren.ErrMissingSponsorshipStatus", TResultSeverity.Resv_Critical));
                }

                if ((AFirstName == "") || (AFirstName == null))
                {
                    AVerificationResult.Add(new TVerificationResult("error", "Please specify the first name of the sponsored child", "",
                                                                    "MaintainChildren.ErrMissingFirstName", TResultSeverity.Resv_Critical));
                }

                if (AVerificationResult.HasCriticalErrors)
                {
                    return(false);
                }

                CurrentEdit.PFamily[0].FirstName   = AFirstName;
                CurrentEdit.PFamily[0].FamilyName  = AFamilyName;
                CurrentEdit.PFamily[0].DateOfBirth = ADateOfBirth;
                CurrentEdit.PFamily[0].Gender      = AGender;
                CurrentEdit.PPartner[0].UserId     = AUserId;

                // only on a actual change, else skip this
                if (ASponsorshipStatus != CurrentEdit.PPartnerType[0].TypeCode)
                {
                    PPartnerTypeRow OldTypeRow = CurrentEdit.PPartnerType[0];
                    OldTypeRow.Delete();

                    PPartnerTypeRow NewTypeRow = CurrentEdit.PPartnerType.NewRowTyped(true);

                    NewTypeRow.TypeCode   = ASponsorshipStatus;
                    NewTypeRow.PartnerKey = CurrentEdit.PPartner[0].PartnerKey;

                    CurrentEdit.PPartnerType.Rows.Add(NewTypeRow);
                }
            }

            CurrentEdit.PPartner[0].PartnerShortName =
                Calculations.DeterminePartnerShortName(
                    CurrentEdit.PFamily[0].FamilyName,
                    CurrentEdit.PFamily[0].Title,
                    CurrentEdit.PFamily[0].FirstName);

            try
            {
                SponsorshipTDSAccess.SubmitChanges(CurrentEdit);
                return(true);
            }
            catch (Exception e)
            {
                TLogging.Log(e.ToString());
                AVerificationResult.Add(new TVerificationResult("error", e.Message, TResultSeverity.Resv_Critical));
                return(false);
            }
        }
Ejemplo n.º 6
0
        public static bool UploadPhoto(
            Int64 APartnerKey,
            Int32 ALedgerNumber,
            byte[] APhoto,
            string APhotoFilename,
            out TVerificationResultCollection AVerificationResult)
        {
            AVerificationResult = new TVerificationResultCollection();

            if (APartnerKey == -1)
            {
                return(false);
            }

            string         dummy       = "0";
            SponsorshipTDS CurrentEdit = GetChildDetails(APartnerKey, ALedgerNumber, true, out dummy);

            if (APhotoFilename.Length > 0)
            {
                string tempFileName = TFileHelper.GetTempFileName(
                    "photo",
                    Path.GetExtension(APhotoFilename));
                File.WriteAllBytes(tempFileName, APhoto);

                using (var srcImage = Image.FromFile(tempFileName))
                {
                    var newHeight = 256;
                    var newWidth  = (int)(srcImage.Width * ((float)newHeight / (float)srcImage.Height));

                    using (var newImage = new Bitmap(newWidth, newHeight))
                    {
                        using (var graphics = Graphics.FromImage(newImage))
                        {
                            graphics.SmoothingMode     = SmoothingMode.AntiAlias;
                            graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                            graphics.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                            graphics.DrawImage(srcImage, new Rectangle(0, 0, newWidth, newHeight));

                            using (var ms = new MemoryStream())
                            {
                                newImage.Save(ms, newImage.RawFormat);
                                CurrentEdit.PFamily[0].Photo = Convert.ToBase64String(ms.ToArray());
                            }

                            try
                            {
                                SponsorshipTDSAccess.SubmitChanges(CurrentEdit);
                                File.Delete(tempFileName);
                                return(true);
                            }
                            catch (Exception e)
                            {
                                TLogging.Log(e.ToString());
                                AVerificationResult.Add(new TVerificationResult("error", e.Message, TResultSeverity.Resv_Critical));
                            }
                        }
                    }
                }

                File.Delete(tempFileName);
            }

            return(false);
        }