0

私はかなり前からこの問題に悩まされてきました。基本的には、多くのパートナーが0から100までのスライダーでシェアを設定できる機能を含む利益分配システムを作成しました。

私が問題を抱えているのは、スライダーが非現実的な値を設定するのを防ぐことです。つまり、1人のパートナーが100%のシェアを設定している場合です。現在、Partnerクラスのスライダーイベントリスナーで次のコードを使用してテストしています。

        // check we don't use more responsibility shares than available
        if(rs_sldr.value < availableShares + rs_sldr.value) {

            // update shares value if valid
            RSShares = rs_sldr.value;
        }

availableShares値は、一般的なPartnersクラスから取得され、すべてのPartnerシェア値を合計し、使用可能なシェアの合計(100)から差し引くことにより、パートナースライダーが調整されるたびに更新されます。

ifステートメントにスライダー値を追加して、使用可能なシェア値だけを使用するかのように適切なスケールを作成します。最初のパートナーに対してスライダーが設定できるのは50を超えないため、50では50のシェアしか残っておらず、ifステートメントもあります。トリガーされます。これを行うにはもっと論理的な方法があると確信しています!!!

とにかくここに私のコードがあります、これが私を引き起こしている悲惨さから誰かが私を救うことができることを願っています。どうもありがとう。

ゼネラルパートナークラス:

package com.example.profitdistributiondiagram {

import flash.display.MovieClip;
import flash.events.Event;
import com.example.profitdistributiondiagram.events.PartnerEvent;
import flash.globalization.CurrencyFormatter;
import flash.globalization.LocaleID;

public class Partners extends MovieClip {

    public var TPGrossPerc:Number = 0;
    public var TPGrossAmount:Number = 0;

    public var RSShareValue:Number = 0;
    public var RSGrossShareAmount:Number = 0;
    public var RSGrossAmount:Number = 0;
    public var RSNetAmount:Number = 0;

    public var PPGrossPoints:Number = 0;
    public var PPGrossAmount:Number = 0;

    public var DGrossPerc:Number = 0;
    public var DGrossAmount:Number = 0;

    public var partners = new Array();
    public var FDAmount:Number = 0;
    public var totalInputRS:Number = 0;
    public var totalInputPP:Number = 0;
    public var totalInputD:Number = 0;      

    public var availableShares:Number = 100;

    private var cf:CurrencyFormatter;

    public function Partners() {

        cf = new CurrencyFormatter( "en-UK" );
        cf.setCurrency("EUR", "€");
        cf.fractionalDigits = 0;
        cf.negativeSymbol = '-';
        cf.negativeCurrencyFormat = 1;

        // set names
        partner_1.row.partner_ref.text = "P1";
        partner_2.row.partner_ref.text = "P2";
        partner_3.row.partner_ref.text = "P3";
        partner_4.row.partner_ref.text = "P4";
        partner_5.row.partner_ref.text = "P5";

        // set partner parent
        partner_1.row.addEventListener(PartnerEvent.UPDATE,partnerRowUpdateListener);
        partner_2.row.addEventListener(PartnerEvent.UPDATE,partnerRowUpdateListener);
        partner_3.row.addEventListener(PartnerEvent.UPDATE,partnerRowUpdateListener);
        partner_4.row.addEventListener(PartnerEvent.UPDATE,partnerRowUpdateListener);
        partner_5.row.addEventListener(PartnerEvent.UPDATE,partnerRowUpdateListener);

        // init partners
        partners = [partner_1,partner_2,partner_3,partner_4,partner_5];
    }
    private function partnerRowUpdateListener(e:Event) {
        updateSubtotals();
        updateMaxValues();          
        updateLabels();
        updateBarCharts();
    }
    public function update() {
        updateSubtotals();
        updateMaxValues();              
        updateLabels();
        updateBarCharts();
    }
    private function updateMaxValues() {

        var p,partner;

        // loop through partners and add values together
        for(var i:Number = 0; i < partners.length; i++) {
            partner = partners[i].row;
            partner.availableShares = availableShares;
            partner.updateNoEvent();
        }

    }
    private function updateSubtotals() {

        // reset vars
        TPGrossPerc = 0;
        TPGrossAmount = 0;
        RSGrossShareAmount = 0;
        RSGrossAmount = 0;
        RSNetAmount = 0;
        PPGrossPoints = 0;
        PPGrossAmount = 0;
        DGrossPerc = 0;
        DGrossAmount = 0;

        var p,partner;

        // loop through partners and add values together
        for(var i:Number = 0; i < partners.length ; i++) {

            partner = partners[i];

            p = partners[i].row;
            p.FDAmount = FDAmount;
            p.totalInputRS = totalInputRS;
            p.totalInputPP = totalInputPP;
            p.totalInputD = totalInputD;
            p.updateNoEvent();

            if(partner.configEnabled) {

                // add up totals
                TPGrossPerc += p.TPPerc;
                TPGrossAmount += p.TPGrossAmount;
                trace("partner: "+i+" "+p.RSShares);
                RSGrossShareAmount += p.RSShares;

                RSGrossAmount += p.RSGrossAmount;
                RSNetAmount += p.RSGrossMinusTPDrawings;

                PPGrossPoints += p.PPoints;
                PPGrossAmount += p.PPAmount;

                DGrossPerc += p.DPerc;
                DGrossAmount += p.DAmount;

            }

            //TPGrossPerc = Math.max(100,TPGrossPerc);
            //TPGrossAmount = Math.max(totalInput

            //RSNetAmount = Math.min(totalInputRS
            //RSGrossAmount = Math.min(totalInputRS,RSGrossAmount);

        }           
        trace('RSGrossShareAmount: '+RSGrossShareAmount);

        // set available shares
        availableShares = 100 - RSGrossShareAmount;
    }
    private function updateLabels() {

        // set values
        tp_gross_perc_lbl.text = String(TPGrossPerc);
        tp_gross_amount_lbl.text = cf.format(TPGrossAmount,true);

        rs_share_value_lbl.text = cf.format(totalInputRS / 100,true);
        rs_gross_shares_lbl.text = String(RSGrossShareAmount);
        rs_gross_amount_lbl.text = cf.format(RSGrossAmount,true);
        rs_net_amount_lbl.text = cf.format(RSNetAmount,true);

        pp_gross_points_lbl.text = String(PPGrossPoints);
        pp_gross_amount_lbl.text = cf.format(PPGrossAmount,true);

        d_gross_total_lbl.text = String(DGrossPerc);
        d_gross_amount_lbl.text = cf.format(DGrossAmount,true);

    }
    private function updateBarCharts() {

        var bcHeight = 190;
        var bcOnePerc = bcHeight / 100;     
        var p;
        var greatestSalary = 0;
        var maxScale = 0;

        // loop through partners and add values together
        for(var i:Number = 0; i < partners.length ; i++) {
            p = partners[i];
            if(p.row.salary > greatestSalary) {
                greatestSalary = p.row.salary;
            }
        }

        // set max scale
        maxScale = greatestSalary;

        // loop through partners and add values together
        for(i = 0; i < partners.length ; i++) {

            p = partners[i];

            // update label
            if(p.bar_chart_mc != null) {

                p.bar_chart_mc.amount_txt.text = cf.format(p.row.salary,true);

                // get percentages 
                //trace('');
                //trace('p.row.FDAmount: '+p.row.FDAmount);
                //trace('p.row.salary: '+p.row.salary);
                //trace('p.row.FDAmount / p.row.salary: '+(p.row.FDAmount / maxScale) * 100);
                var fdPerc = !((p.row.FDAmount / maxScale) * 100) ? 0 : (p.row.FDAmount / maxScale) * 100;
                var rsPerc = !((p.row.RSGrossMinusTPDrawings / maxScale) * 100) ? 0 : (p.row.RSGrossMinusTPDrawings / maxScale) * 100;
                var tpPerc = !((p.row.TPGrossAmount / maxScale ) * 100) ? 0 : (p.row.TPGrossAmount / maxScale) * 100;
                var ppPerc = !((p.row.PPAmount / maxScale) * 100) ? 0 : (p.row.PPAmount / maxScale) * 100;
                var dPerc = !((p.row.DAmount / maxScale) * 100) ? 0 : (p.row.DAmount / maxScale) * 100;

                //trace('per: '+(fdPerc + rsPerc + tpPerc + ppPerc + dPerc));

                p.bar_chart_mc.fixed_drawings_mc.height = Math.round(bcOnePerc * fdPerc);
                p.bar_chart_mc.topup_drawings_mc.height = Math.round(bcOnePerc * tpPerc);
                p.bar_chart_mc.responsibility_shares_mc.height = Math.round(bcOnePerc * rsPerc);
                p.bar_chart_mc.performance_points_mc.height = Math.round(bcOnePerc * ppPerc);
                p.bar_chart_mc.discretionary_mc.height = Math.round(bcOnePerc * dPerc);

                p.bar_chart_mc.topup_drawings_mc.y = p.bar_chart_mc.fixed_drawings_mc.y - p.bar_chart_mc.fixed_drawings_mc.height;
                p.bar_chart_mc.responsibility_shares_mc.y = p.bar_chart_mc.topup_drawings_mc.y - p.bar_chart_mc.topup_drawings_mc.height;
                p.bar_chart_mc.performance_points_mc.y = p.bar_chart_mc.responsibility_shares_mc.y - p.bar_chart_mc.responsibility_shares_mc.height;
                p.bar_chart_mc.discretionary_mc.y = p.bar_chart_mc.performance_points_mc.y - p.bar_chart_mc.performance_points_mc.height; 

                //trace('p.bar_chart_mc.fixed_drawings_mc.y: '+p.bar_chart_mc.fixed_drawings_mc.y);
                //trace('pp.bar_chart_mc.topup_drawings_mc.y: '+p.bar_chart_mc.topup_drawings_mc.y);
            }

        }
    }
}

}

パートナークラス:

package com.example.profitdistributiondiagram {

import flash.display.MovieClip;
import fl.events.SliderEvent;
import com.example.profitdistributiondiagram.events.PartnerEvent;
import flash.events.Event;
import flash.events.TextEvent;
import flash.globalization.CurrencyFormatter;
import flash.globalization.LocaleID;

public class PartnerRow extends MovieClip {

    public var availableShares:Number = 100;
    public var FDAmount:Number = 0;
    public var TPGrossAmount:Number = 0;
    public var TPPerc:Number = 0;

    public var RSGrossAmount:Number = 0;
    public var RSShares:Number = 0;
    public var RSGrossMinusTPDrawings:Number = 0;

    public var PPGrossAmount:Number = 0;
    public var PPoints:Number = 0;
    public var PPAmount:Number = 0;     
    public var PPGrossPoints:Number = 100;

    public var DGrossAmount:Number = 0;
    public var DPerc:Number = 0;
    public var DAmount:Number = 0;

    public var totalInputRS:Number = 0;
    public var totalInputPP:Number = 0;
    public var totalInputD:Number = 0;

    public var salary:Number = 0;

    public var enableControl;
    public var barChart:MovieClip;

    private var cf:CurrencyFormatter;

    public function PartnerRow() {

        // set currency formatter
        cf = new CurrencyFormatter( "en-UK" );
        cf.setCurrency("EUR", "€");
        cf.fractionalDigits = 0;
        cf.negativeSymbol = '-';
        cf.negativeCurrencyFormat = 1;

        // event listeners
        tp_sldr.addEventListener(SliderEvent.THUMB_DRAG, sliderDragHandler);
        rs_sldr.addEventListener(SliderEvent.THUMB_DRAG, sliderDragHandler);
        pp_sldr.addEventListener(SliderEvent.THUMB_DRAG, sliderDragHandler);
        d_sldr.addEventListener(SliderEvent.THUMB_DRAG, sliderDragHandler);

        // update
        update();

    }
    private function sliderDragHandler(event:SliderEvent):void {

        trace('availableShares: '+availableShares);
        trace(' availableShares: '+(availableShares + rs_sldr.value));
        trace('rs_sldr.value: '+rs_sldr.value);

        // check we don't use more shares than available
        if(rs_sldr.value < availableShares + rs_sldr.value) {

            // update shares value if valid
            RSShares = rs_sldr.value;
            //trace("RSShares: "+RSShares);
        }
        trace('max: '+rs_sldr.maximum);
        // update labels
        update();

    }
    public function update() {

        // update but don't dispatch an event
        updateNoEvent();

        // dispatch update event
        this.dispatchEvent(new  Event(PartnerEvent.UPDATE));            
    }
    public function updateNoEvent() {

        // set responsibility shares

        //RSShares = rs_sldr.value;
        RSGrossAmount = (totalInputRS / 100) * RSShares;
        RSGrossMinusTPDrawings = RSGrossAmount - TPGrossAmount;


        // set RS text values
        rs_shares_lbl.text = String(RSShares);
        /*rs_gross_amount_lbl.text = cf.format(RSGrossAmount,true);
        rs_net_amount_lbl.text = cf.format(RSGrossMinusTPDrawings,true);

        // set topup drawings
        TPGrossAmount = (RSGrossAmount / 100) * tp_sldr.value;
        TPPerc = tp_sldr.value;
        tp_perc_lbl.text = String(TPPerc);
        tp_gross_amount_lbl.text = cf.format(TPGrossAmount,true);

        // set performance points
        PPGrossAmount = totalInputPP;
        PPoints = pp_sldr.value;
        PPAmount = (PPGrossAmount / PPGrossPoints) * PPoints;

        // set PP text values
        pp_points_input.text = String(PPoints);
        pp_amount_lbl.text = cf.format(PPAmount,true);

        // set discretionary 
        DGrossAmount = totalInputD;
        DPerc = d_sldr.value;
        DAmount = (DGrossAmount / 100) * DPerc;

        // ser discretionary text values
        d_perc_input.text = String(DPerc);
        d_amount_input.text = cf.format(DAmount,true);
        */
        // set salary
        salary = FDAmount + RSGrossMinusTPDrawings + TPGrossAmount + PPAmount + DAmount;

    }


}

}

4

0 に答える 0