コード例 #1
0
        //==========================================
        void loadShareGroup(xDataInput di)
        {
            int cnt = di.readInt();

            if (cnt > stShareGroup.MAX_SHARES_IN_GROUP)
            {
                cnt = stShareGroup.MAX_SHARES_IN_GROUP;
            }
            xVector v = shareGroups();

            if (cnt > 0)
            {
                v.removeAllElements();
            }
            for (int i = 0; i < cnt; i++)
            {
                stShareGroup g = new stShareGroup();
                g.load(di);

                if (g.getType() == stShareGroup.ID_GROUP_GAINLOSS || g.getName() == null || g.getName().Length == 0)
                {
                    continue;
                }
                v.addElement(g);
            }
        }
コード例 #2
0
        xDataOutput shareGroupsBlock()
        {
            xDataOutput o = new xDataOutput(5 * 1024);

            xVector v = new xVector();

            for (int i = 0; i < _shareGroups.size(); i++)
            {
                stShareGroup p = (stShareGroup)_shareGroups.elementAt(i);

                if (p.getType() == stShareGroup.ID_GROUP_GAINLOSS || p.getName() == null || p.getName().Length == 0)
                {
                    continue;
                }

                v.addElement(p);
            }
            //

            int groupCnt = v.size() < 30? v.size():30;

            o.writeInt(groupCnt);

            for (int i = 0; i < groupCnt; i++)
            {
                stShareGroup p = (stShareGroup)v.elementAt(i);

                if (p.getType() == stShareGroup.ID_GROUP_GAINLOSS || p.getName() == null || p.getName().Length == 0)
                {
                    continue;
                }

                p.save(o);
            }
            return(o);
        }
コード例 #3
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();
        }
コード例 #4
0
        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));
                }
            }
        }