Esempio n. 1
0
        private void loadPaymentHistory(AffiliateHistory[] affiliatesHistory)
        {
            DataTable dtPaymentHistory = new DataTable("PaymentHistory");

            dtPaymentHistory.Columns.Add("ID");
            dtPaymentHistory.Columns.Add("AffiliateID");
            dtPaymentHistory.Columns.Add("Amount");
            dtPaymentHistory.Columns.Add("DatePaid");
            dtPaymentHistory.Columns.Add("Notes");

            foreach (AffiliateHistory affiliateHistory in affiliatesHistory)
            {
                dtPaymentHistory.Rows.Add(new object[]
                                          {
                                              affiliateHistory.ID,
                                              affiliateHistory.AffiliateID,
                                              affiliateHistory.Amount.ToString("C"),
                                              affiliateHistory.DatePaid,
                                              affiliateHistory.Notes,
                                          });    
            }

            gvPaymentHistory.DataSource = dtPaymentHistory;
            gvPaymentHistory.DataBind();

            gvPaymentHistory.Visible = dtPaymentHistory.Rows.Count > 0;
        }
Esempio n. 2
0
        private void loadPaymentHistory(AffiliateHistory[] affiliatesHistory)
        {
            DataTable dtPaymentHistory = new DataTable("PaymentHistory");

            dtPaymentHistory.Columns.Add("ID");
            dtPaymentHistory.Columns.Add("AffiliateUsername");
            dtPaymentHistory.Columns.Add("Amount");
            dtPaymentHistory.Columns.Add("DatePaid");
            dtPaymentHistory.Columns.Add("Notes");
            dtPaymentHistory.Columns.Add("PrivateNotes");

            foreach (AffiliateHistory affiliateHistory in affiliatesHistory)
            {
                Affiliate affiliate = Affiliate.Fetch(affiliateHistory.AffiliateID);

                if (affiliate != null)
                {
                    dtPaymentHistory.Rows.Add(new object[]
                                          {
                                              affiliateHistory.ID,
                                              affiliate.Username,
                                              affiliateHistory.Amount.ToString("C"),
                                              affiliateHistory.DatePaid,
                                              affiliateHistory.Notes,
                                              affiliateHistory.PrivateNotes
                                          });    
                }
                else
                {
                    continue;
                }
            }

            gvPaymentHistory.DataSource = dtPaymentHistory;
            gvPaymentHistory.DataBind();

            gvPaymentHistory.Visible = dtPaymentHistory.Rows.Count > 0;
        }
        protected void btnPay_Click(object sender, EventArgs e)
        {
            if (!((AdminPageBase)Page).HasWriteAccess) return;

            Affiliate affiliate = Affiliate.Fetch(RecipientID);

            if (affiliate != null)
            {
                AffiliateHistory affiliateHistory = new AffiliateHistory(affiliate.ID);
                affiliateHistory.Amount = affiliate.Balance;
                affiliateHistory.DatePaid = DateTime.Now;
                affiliateHistory.Notes = txtNotes.Text.Trim();
                affiliateHistory.PrivateNotes = txtPrivateNotes.Text.Trim();
                affiliateHistory.Save();

                decimal balance = 0;
                try
                {
                    balance = Convert.ToDecimal(txtAmount.Text);
                }
                catch (FormatException)
                {
                    MessageBox.Show(Lang.TransA("Please enter a valid amount!"), Misc.MessageType.Error);
                    return;
                }
                catch (OverflowException)
                {
                    MessageBox.Show(Lang.TransA("Please enter a valid amount!"), Misc.MessageType.Error);
                    return;
                }

                if (balance > affiliate.Balance)
                {
                    MessageBox.Show(Lang.TransA("Amount cannot be greater than affiliate balance!"), Misc.MessageType.Error);
                    return;
                }

                affiliate.Balance -= balance;
                affiliate.RequestPayment = false;
                affiliate.Save();

                #region Send an email

                MiscTemplates.AffiliatePaymentSent sendChargeNotificationEmail = new MiscTemplates.AffiliatePaymentSent();
                Email.Send(Config.Urls.Home, affiliate.Email,
                                                sendChargeNotificationEmail.GetFormattedSubject(Config.Misc.SiteTitle),
                                                sendChargeNotificationEmail.GetFormattedBody(Config.Urls.Home, affiliate.Username), false);

                #endregion
            }

            loadAffiliateRequestPayments();

            mvAffiliateRequestPayments.SetActiveView(viewPaymentRequests);
        }