Esempio n. 1
0
    protected void RecycleButton_Click(object sender, EventArgs e)
    {
        ClearPanels();
        //Recycle
        try
        {
            using (var bridge = ParserPool.Acquire(Database.Client))
            {
                Member User = Member.Current;
                Money  SingleOperationCost = User.Membership.RentedReferralRecycleCost;
                int    referralsDone       = 0;
                for (int i = 0; i < DirectRefsGridView.Rows.Count; i++)
                {
                    if (((HtmlInputCheckBox)DirectRefsGridView.Rows[i].FindControl("chkSelect")).Checked)
                    {
                        if (SingleOperationCost > User.PurchaseBalance)
                        {
                            throw new MsgException(L1.OPPREFPARTIAL.ToString().Replace("%n%", referralsDone.ToString()));
                        }

                        string refId = (DirectRefsGridView.Rows[i].Cells[1].Text.Trim());
                        RentReferralsSystem.RecycleReferral(Int32.Parse(refId), bridge.Instance);
                        User.SubtractFromPurchaseBalance(SingleOperationCost, "Ref: recycle");
                        User.SaveBalances();
                        referralsDone++;
                    }
                }

                RentReferralsSystem.TryForceAutopay(User.Name);

                SuccMessagePanel2.Visible = true;
                SuccMessage2.Text         = U3501.REFACTIONSUCC;
            }
        }
        catch (MsgException ex)
        {
            ErrorMessagePanel2.Visible = true;
            ErrorMessage2.Text         = ex.Message;
        }

        DirectRefsGridView.DataBind();
    }
Esempio n. 2
0
    protected void DirectRefsGridView_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //We want to obey OnSort and OnChart events
        string[] commands = new string[4] {
            "comDelete", "comRenew", "comRecycle", "comAutopay"
        };

        if (commands.Contains(e.CommandName))
        {
            int index = e.GetSelectedRowIndex();

            GridViewRow row = DirectRefsGridView.Rows[index];
            ClearPanels();

            try
            {
                using (var bridge = ParserPool.Acquire(Database.Client))
                {
                    if (e.CommandName == "comDelete")
                    {
                        string refId = (row.Cells[1].Text.Trim());
                        RentReferralsSystem.DeleteReferral(Int32.Parse(refId), bridge.Instance);
                        Response.Redirect("rented.aspx");
                    }
                    else if (e.CommandName == "comRenew")
                    {
                        Member User = Member.Logged(Context);
                        Money  SingleOperationCost = CalcRenewCost(User.Membership.RenewalDiscount, User.Membership.ReferralRentCost);

                        if (User.PurchaseBalance < SingleOperationCost)
                        {
                            throw new MsgException(L1.NOTENOUGHFUNDS);
                        }

                        User.SubtractFromPurchaseBalance(SingleOperationCost, "Ref: renew");
                        User.SaveBalances();
                        string refId = (row.Cells[1].Text.Trim());
                        RentReferralsSystem.RenewReferral(Int32.Parse(refId), bridge.Instance);
                    }
                    else if (e.CommandName == "comRecycle")
                    {
                        Member User = Member.Logged(Context);
                        Money  SingleOperationCost = User.Membership.RentedReferralRecycleCost;

                        if (User.PurchaseBalance < SingleOperationCost)
                        {
                            throw new MsgException(L1.NOTENOUGHFUNDS);
                        }

                        string refId = (row.Cells[1].Text.Trim());
                        RentReferralsSystem.RecycleReferral(Int32.Parse(refId), bridge.Instance);
                        User.SubtractFromPurchaseBalance(SingleOperationCost, "Ref: recycle");
                        User.SaveBalances();
                    }
                    else if (e.CommandName == "comAutopay")
                    {
                        bool   setOn = true;
                        string refId = (row.Cells[1].Text.Trim());

                        if (row.Cells[7].Text.Contains("img")) // I know its bad, very bad
                        {
                            setOn = false;
                        }

                        if (setOn)
                        {
                            int ExpireDays = Int32.Parse(row.Cells[4].Text.Replace(" " + L1.DAYS, ""));
                            if (ExpireDays < AppSettings.RentedReferrals.MinDaysToStartAutoPay)
                            {
                                throw new MsgException((L1.OPREFAP).ToString().Replace("%n2%", AppSettings.RentedReferrals.MinDaysToStartAutoPay.ToString()));
                            }

                            RentReferralsSystem.SetAutopayOnReferral(Int32.Parse(refId), bridge.Instance);
                        }
                        else
                        {
                            RentReferralsSystem.SetAutopayOffReferral(Int32.Parse(refId), bridge.Instance);
                        }
                    }

                    DirectRefsGridView.DataBind();
                    SuccMessagePanel2.Visible = true;
                    SuccMessage2.Text         = L1.OP_SUCCESS;
                }
            }
            catch (MsgException ex)
            {
                ErrorMessagePanel2.Visible = true;
                ErrorMessage2.Text         = ex.Message;
            }
        }
    }