//==========================================
        void showDetailOfGroup(stShareGroup g)
        {
            viewState = VIEWSTATE_1_NHOMNGANH;

            if (g.getTotal() == 1 &&
                (g.getName().CompareTo("^VNINDEX") == 0 ||
                 g.getName().CompareTo("^HASTC") == 0 ||
                 g.getName().CompareTo("^UPCOM") == 0))
            {
                int   cnt    = mContext.mShareManager.getShareCount();
                int[] market = { 0 };

                int marketID = 1;
                if (g.getName().CompareTo("^HASTC") == 0)
                {
                    marketID = 2;
                }
                else if (g.getName().CompareTo("^UPCOM") == 0)
                {
                    marketID = 3;
                }

                for (int i = 0; i < cnt; i++)
                {
                    int shareID = mContext.mShareManager.getShareIDAt(i, market);

                    if (shareID > 0 && market[0] == marketID)
                    {
                        g.addCode(mContext.mShareManager.getShareCode(shareID));
                    }
                }
            }

            chartG = new ChartTangtruongGroup();

            chartG.setGroup(g);
            chartG.setPosition(0, 0);

            chartG.onBack += dismissGroupDetail;
            //chartG.setSize(mPriceboardContainer);

            int h = getH();// chartG.estimateH(getH(), g.getTotal());

            if (h < getH())
            {
                h = getH();
            }
            //list.setSize(W_PRICEBOARD, mPriceboardH);
            chartG.setSize(getW() - 20, h);

            chartG.onBack                += dismissGroupDetail;
            chartG.onHistoryClick        += delegateShowHistoryChartOfGroup;
            chartG.onClickShare          += delegateShowHistoryChartOfShare;
            chartG.onProcessingCompleted += onProcessingCompleted;
            chartG.onProcessingStart     += onProcessingStart;

            invalidate();
        }
Exemplo n.º 2
0
        xVector shareGroupToVector()
        {
            if (_shareGroup == null)
            {
                return(new xVector());
            }
            xVector v = new xVector();

            for (int i = 0; i < _shareGroup.getTotal(); i++)
            {
                Share share = Context.getInstance().mShareManager.getShare(_shareGroup.getCodeAt(i));
                if (share != null)
                {
                    v.addElement(share);
                }
            }

            return(v);
        }
Exemplo n.º 3
0
        static public void exportGroupToCSV(stShareGroup g)
        {
            xVector v = new xVector();

            for (int i = 0; i < g.getTotal(); i++)
            {
                String code = g.getCodeAt(i);
                if (code != null)
                {
                    Share share = Context.getInstance().mShareManager.getShare(code);
                    if (share != null)
                    {
                        v.addElement(share);
                    }
                }
            }
            if (v.size() > 0)
            {
                exportGroupToCSV(v, null);
            }
        }
Exemplo n.º 4
0
        public void setShareGroupAsFilterResult(stShareGroup g, int filterType)
        {
            mTableType = TABLE_GAINLOSS;

            this.removeAllControls();

            _shareGroup = g;

            int cnt = g.getTotal();

            int y = 0;

            xLabel l;

            if (hasTitle)
            {
                Font f = Context.getInstance().getFontText();
                l = xLabel.createSingleLabel(g.getName(), f, 300);
                l.setBackgroundColor(C.COLOR_ORANGE);
                l.setSize(rowW, (int)f.GetHeight() + 4);
                l.setPosition(0, 0);
                l.setTextColor(C.COLOR_WHITE);

                y = (int)l.getBottom() + 1;

                addControl(l);
            }

            //  gia tri GD
            if (filterType <= 0)
            {
                filterType = ShareSortUtils.SORT_TRADE_VALUE;
                xVector v = shareGroupToVector();
                if (v != null && v.size() > 0)
                {
                    ShareSortUtils.evalueSortValueTrade(v);
                }
            }

            //-------------------
            for (int i = 0; i <= cnt; i++)
            {
                int idx = i - 1;
                int rH  = i == 0 ? 36 : rowH;

                RowNormalShare r = new RowFilterResult(mListener, i, rowW, rH);
                r.onShowSortMenu += delegateShowSortMenu;
                r.setSortType(filterType);

                if (idx >= 0)
                {
                    String code = g.getCodeAt(idx);

                    if (code != null && code.Length > 0)
                    {
                        r.setData(code);
                    }
                    else
                    {
                        continue;
                    }
                    //r.mAllowDelete = deletable;
                }

                r.setParent(this);

                r.setPosition(0, y);
                r.invalidate();
                addControl(r);
                vRows.addElement(r);

                y += rH + 1;
            }

            invalidate();
        }
Exemplo n.º 5
0
        void setShareGroup(stShareGroup g, int sortType)
        {
            if (mTableType == TABLE_GAINLOSS)
            {
                setShareGroupAsFilterResult(g, sortType);
                return;
            }
            //=========================
            this.removeAllControls();

            mTableType = TABLE_NORMAL_PRICEBOARD;

            if (g == null)
            {
                return;
            }

            _shareGroup = g;

            int cnt = g.getTotal();

            int y = 0;

            xLabel l;

            if (hasTitle)
            {
                Font f = Context.getInstance().getFontText();
                l = xLabel.createSingleLabel(g.getName(), f, 300);
                l.setBackgroundColor(C.COLOR_ORANGE);
                l.setSize(rowW, (int)f.GetHeight() + 4);
                l.setPosition(0, 0);
                l.setTextColor(C.COLOR_WHITE);
                addControl(l);

                y = (int)l.getBottom() + 1;
            }

            bool deletable = g.getType() == stShareGroup.ID_GROUP_FAVOR;

            if (deletable)
            {
                Utils.trace("++++++++++===============row is detelable");
            }
            for (int i = 0; i <= cnt; i++)
            {
                int idx = i - 1;
                int rH  = i == 0? 36: rowH;

                RowNormalShare r;
                if (g.getType() == stShareGroup.ID_GROUP_INDICES)
                {
                    r = new RowIndice(mListener, i, rowW, rH);
                    if (idx >= 0)
                    {
                        String code = g.getCodeAt(idx);

                        if (code != null && code.Length > 0)
                        {
                            r.setData(code);
                        }
                        else
                        {
                            continue;
                        }
                        //r.mAllowDelete = deletable;
                    }
                }
                else
                {
                    r = new RowNormalShare(mListener, i, rowW, rH);
                    r.onShowSortMenu += delegateShowSortMenu;
                    r.onSortABC      += delegateSortABC;
                    if (idx >= 0)
                    {
                        int    shareID = g.getIDAt(idx);
                        String code    = g.getCodeAt(idx);

                        if (code != null && code.Length > 0 && shareID >= 0)
                        {
                            r.setData(code);
                        }
                        else
                        {
                            continue;
                        }
                        //r.mAllowDelete = deletable;
                    }
                }
                r.setParent(this);
                r.setSortType(sortType);

                r.setPosition(0, y);
                r.invalidate();
                addControl(r);
                vRows.addElement(r);

                y += rH + 1;
            }

            if (g.getType() == stShareGroup.ID_GROUP_FAVOR)
            {
                xFillBackground bottom = xFillBackground.createFill(rowW, 1, C.COLOR_GRAY_LIGHT);
                bottom.setPosition(0, y);
                addControl(bottom);
                y += 1;

                l = xLabel.createSingleLabel("Click phím phải chuột để thêm/xóa mã hoặc nhóm");
                l.setTextColor(C.COLOR_WHITE);
                l.setPosition(l.getW() - 4, y + 3);
                addControl(l);
                int tmp = l.getX();

                //	xoa nhom
                y = (int)l.getBottom() + 4;

                /*
                 * bt = xUIButton.createButton(listener, C.ID_BUTTON_REMOVE_GROUP, " - ", bw);
                 * bt.setSize(bw, xApplication.point2Pixels(40));
                 * bt.setPosition(w - bw - 2, y+1);
                 * addControl(bt);
                 *
                 * l = xLabel.createSingleLabel("Xóa nhóm ->", AppContext.getInstance().getFontText());
                 * l.setTextColor(C.COLOR_RED);
                 * l.setPosition(bt.getX() - l.getW() - 4, y + (bt.getH()-l.getH())/2);
                 * addControl(l);
                 *
                 * y += bt.getH() + 2;
                 */
            }

            xFillBackground fillBottom = xFillBackground.createFill(rowW, 2, C.COLOR_GRAY_LIGHT);

            fillBottom.setPosition(0, y);
            addControl(fillBottom);

            invalidate();
        }
        void calcChanged(int period)
        {
            stCandle c0 = new stCandle();
            stCandle c1 = new stCandle();

            mChanges.removeAllElements();

            Utils.trace("----------------------");
            bool isNhomIndex = false;

            for (int i = 0; i < mGroups.size(); i++)
            {
                stShareGroup g  = (stShareGroup)mGroups.elementAt(i);
                GroupChanges gc = new GroupChanges();
                gc.group = g;
                mChanges.addElement(gc);
                gc.code = g.getName();

                Utils.trace(g.getName());

                double firstGTGD = 0;
                double lastGTGD  = 0;

                double totalGTGD0 = 0;
                double totalGTGD1 = 0;

                int today = 0;

                isNhomIndex = false;

                if (g.getType() == stShareGroup.ID_GROUP_MARKET_OVERVIEW &&
                    g.getTotal() == 1)
                {
                    isNhomIndex = true;
                    String code  = g.getCodeAt(0);
                    Share  share = mContext.mShareManager.getShare(code);
                    if (share == null)
                    {
                        continue;
                    }

                    share.loadShareFromFile(false);
                    share.appendTodayCandle2();

                    int last  = share.getCandleCnt() - 1;
                    int first = (last > period)?(last - period):0;
                    if (last < 0 || first < 0)
                    {
                        continue;
                    }

                    c0 = share.getCandle(last, c0);
                    c1 = share.getCandle(first, c1);

                    if (c1.close > 0)
                    {
                        double changed = 100 * (c0.close - c1.close) / c1.close;

                        gc.changedPercent += changed;
                    }

                    continue;
                }

                for (int j = 0; j < g.getTotal(); j++)
                {
                    string        code    = g.getCodeAt(j);
                    Share         share   = Context.getInstance().mShareManager.getShare(code);
                    int           shareID = Context.getInstance().mShareManager.getShareID(code);
                    stCompanyInfo info    = Context.getInstance().mShareManager.getCompanyInfo(shareID);
                    if (share != null && info != null)
                    {
                        share.loadShareFromCommonData(true);
                        int last  = share.getCandleCnt() - 1;
                        int first = (last > period)?(last - period):0;
                        if (last < 0 || first < 0)
                        {
                            continue;
                        }

                        share.getCandle(last, c0);
                        share.getCandle(first, c1);

                        double changed;
                        if (period == 1 && c0.date < today)
                        {
                            //  khong co giao dich hom nay
                            changed = 0;
                        }
                        else
                        {
                            double r = (info.volume * c1.close);
                            changed = 0;// (c0.close - c1.close) * r;

                            changed  = 100 * (c0.close - c1.close) / c1.close;
                            changed *= r;
                        }

                        totalGTGD0 += (c0.close * info.volume);
                        totalGTGD1 += (c1.close * info.volume);

                        gc.changedPercent += changed;
                        //String s = String.Format("Code: {0}, Price: Close0/Close1={1}/{2}, r={3} changed/totalChanged: {4}/{5}",
                        //share.getCode(), c0.close, c1.close, r, changed, gc.changedPercent);
                        //Utils.trace(s);
                    }

                    gc.changedPercent  = 100 * (totalGTGD0 - totalGTGD1);
                    gc.changedPercent /= totalGTGD1;
                }

                //Utils.trace(String.Format("Total changed: {0}", gc.changedPercent));
            }

            //  sort
            if (false)//isNhomIndex)
            {
                //  khong sort
            }
            else
            {
                xVector marketOverView = new xVector();
                for (int i = 0; i < mChanges.size() - 1; i++)
                {
                    GroupChanges g = (GroupChanges)mChanges.elementAt(i);
                    if (g.group.getType() == stShareGroup.ID_GROUP_MARKET_OVERVIEW || g.code.IndexOf('#') == 0)
                    {
                        marketOverView.addElement(g);
                    }
                }

                for (int i = 0; i < marketOverView.size(); i++)
                {
                    mChanges.removeElement(marketOverView.elementAt(i));
                }

                //================================

                for (int i = 0; i < mChanges.size() - 1; i++)
                {
                    GroupChanges biggest    = (GroupChanges)mChanges.elementAt(i);
                    int          biggestIdx = i;
                    for (int j = i + 1; j < mChanges.size(); j++)
                    {
                        GroupChanges gc = (GroupChanges)mChanges.elementAt(j);
                        if (gc.changedPercent > biggest.changedPercent)
                        {
                            biggest    = gc;
                            biggestIdx = j;
                        }
                    }

                    if (biggestIdx != i)
                    {
                        mChanges.swap(i, biggestIdx);
                    }
                }
                //========================
                for (int i = 0; i < mChanges.size(); i++)
                {
                    marketOverView.addElement(mChanges.elementAt(i));
                }
                mChanges.removeAllElements();
                for (int i = 0; i < marketOverView.size(); i++)
                {
                    mChanges.addElement(marketOverView.elementAt(i));
                }
            }
        }
Exemplo n.º 7
0
        void calcChanged(int period)
        {
            stCandle _c0 = new stCandle();
            stCandle _c1 = new stCandle();

            Share vnindex = mContext.mShareManager.getShare("^VNINDEX");

            vnindex.loadShareFromFile(true);

            if (vnindex.getCandleCnt() < period)
            {
                return;
            }

            stCandle c0 = vnindex.getCandle(vnindex.getCandleCnt() - 1, _c0);
            stCandle c1 = vnindex.getCandle(vnindex.getCandleCnt() - 1 - period, _c1);

            int startDate = c1.date;
            int endDate   = c0.date;

            mChanges.removeAllElements();
            for (int i = 0; i < shareGroup.getTotal(); i++)
            {
                string code  = shareGroup.getCodeAt(i);
                Share  share = Context.getInstance().mShareManager.getShare(code);
                if (share != null)
                {
                    if (share.getShareID() == 1032)
                    {
                        Utils.trace("---");
                    }
                    share.loadShareFromCommonData(true);

                    if (share.getCandleCnt() > 0)
                    {
                        c0 = share.getCandleByDate(startDate, startDate, _c0);
                        c1 = share.getCandleByDate(endDate, startDate, _c1);

                        if (c0 == null || c1 == null)
                        {
                            continue;
                        }

                        ShareChanges change = new ShareChanges();
                        change.code           = code;
                        change.changedPercent = 100 * (c1.close - c0.close) / c0.close;

                        mChanges.addElement(change);
                    }
                }
            }

            //  sort abs
            for (int i = 0; i < mChanges.size() - 1; i++)
            {
                ShareChanges biggest    = (ShareChanges)mChanges.elementAt(i);
                int          biggestIdx = i;
                for (int j = i + 1; j < mChanges.size(); j++)
                {
                    ShareChanges gc = (ShareChanges)mChanges.elementAt(j);
                    if (Math.Abs(gc.changedPercent) > Math.Abs(biggest.changedPercent))
                    {
                        biggest    = gc;
                        biggestIdx = j;
                    }
                }

                if (biggestIdx != i)
                {
                    mChanges.swap(i, biggestIdx);
                }
            }

            while (mChanges.size() > 120)
            {
                mChanges.removeElementAt(mChanges.size() - 1);
            }

            //  sort
            for (int i = 0; i < mChanges.size() - 1; i++)
            {
                ShareChanges biggest    = (ShareChanges)mChanges.elementAt(i);
                int          biggestIdx = i;
                for (int j = i + 1; j < mChanges.size(); j++)
                {
                    ShareChanges gc = (ShareChanges)mChanges.elementAt(j);
                    if (gc.changedPercent > biggest.changedPercent)
                    {
                        biggest    = gc;
                        biggestIdx = j;
                    }
                }

                if (biggestIdx != i)
                {
                    mChanges.swap(i, biggestIdx);
                }
            }
        }