void renderSnapshot2(xGraphics g)
        {
            stPriceboardState item = getPriceboard();

            if (item != null)
            {
                stCell cell = getCellAt(7);

                //  snapshot
                if (rcSnapshot == null)
                {
                    rcSnapshot = new Rectangle();
                }
                rcSnapshot.X      = cell.x;
                rcSnapshot.Y      = 0;
                rcSnapshot.Width  = cell.w;
                rcSnapshot.Height = getH();

                sharethumb.DrawAChartDelegator.renderToView(item.code, g, rcSnapshot);

                //  date
                stGainloss gainloss = (stGainloss)getUserData();
                String     s        = Utils.dateIntToStringDDMM(gainloss.date);

                g.setColor(C.COLOR_WHITE);
                g.drawStringInRect(cell.f, s, cell.x, getH() - 17, cell.w, 17, xGraphics.LEFT);
            }
        }
Exemple #2
0
        public DlgSellStock(stGainloss g)
        {
            mGainloss = g;
            InitializeComponent();

            lb_Quote.Text = g.code;
            lb_Price.Text = "" + g.price;
        }
        override public stPriceboardState getPriceboard()
        {
            stGainloss g = (stGainloss)getUserData();

            if (g != null)
            {
                return(Context.getInstance().mPriceboard.getPriceboard(g.code));
            }

            return(null);
        }
        override public String getCode()
        {
            stGainloss g = (stGainloss)getUserData();

            if (g != null)
            {
                return(g.code);
            }

            return(null);
        }
        //=================================
        xDataOutput gainlossBlock()
        {
            xDataOutput o = new xDataOutput(2 * 1024);

            o.writeInt(_gainLossManager.getTotal());
            for (int i = 0; i < _gainLossManager.getTotal(); i++)
            {
                stGainloss g = _gainLossManager.getGainLossAt(i);

                o.writeUTF(g.code);
                o.writeInt(g.date);
                o.writeInt((int)(g.price * 1000));
                o.writeInt(g.volume);
            }

            return(o);
        }
        protected void renderCandle(xGraphics g, stCell c)
        {
            int x, y;

            x = c.x;
            y = 0;

            uint color;

            object o = getUserData();
            String code;

            if (o is String)
            {
                code = (String)o;
            }
            else
            {
                stGainloss gainloss = (stGainloss)o;
                code = gainloss.code;
            }

            if (code == null)
            {
                return;
            }
            stPriceboardState ps = Context.getInstance().mPriceboard.getPriceboard(code);

            if (ps == null)
            {
                return;
            }

            Context ctx = Context.getInstance();

            float price = ps.getCurrentPrice();
            float open  = ctx.mPriceboard.getOpen(ps.getID());

            if (open == 0)
            {
                open = price;
            }

            float hi = ps.getMax();
            float lo = ps.getMin();

            //  check hi/lo valid

            if ((hi == 0 || lo == 0))
            {
                TradeHistory trade = Context.getInstance().getTradeHistory(ps.getID());
                float[]      hl    = new float[2];
                if (trade != null && trade.getHiLo(hl))
                {
                    if (hi == 0)
                    {
                        hi = hl[0];
                    }
                    if (lo == 0)
                    {
                        lo = hl[1];
                    }
                }
            }

            if (hi == lo)
            {
                hi = price;
            }

            if (hi == 0)
            {
                hi = open > price ? open : price;
            }
            if (lo == 0)
            {
                lo = open < price ? open : price;
            }
            if (lo == 0)
            {
                lo = hi;
            }
            //---------------------------------------------

            float priceLen = (float)(hi - lo);

            int y0 = 0;

            float min = ps.getRef() - (ps.getRef() / 13);       //	+-7% (7*13==100)
            float max = ps.getRef() + (ps.getRef() / 13);

            if (ps.getMarketID() == 1)
            {
                min = ps.getRef() - (ps.getRef() / 19); //	+-5%
                max = ps.getRef() + (ps.getRef() / 19);
            }

            if (min > lo && lo > 0)
            {
                min = (float)lo;
            }
            if (max < hi)
            {
                max = (float)hi;
            }

            float totalPrice = (max - min);  //(10%);

            if (totalPrice < priceLen)
            {
                totalPrice = priceLen;
            }

            if (totalPrice == 0)
            {
                return;
            }

            float ry = (float)(getH() - 2 * y0) / totalPrice;

            int totalH = (int)(ry * totalPrice);
            int bodyW  = c.w / 2;

            //================frame=============================
            //  line _ref
            g.setColor(0x70ffff00);
            y = (int)(y0 + totalH - (ps.getRef() - min) * ry);
            g.drawLineDotHorizontal(c.x + 1, y, c.w - 2);
            //===================================================
            if (price == 0)
            {
                return; //	khong co giao dich
            }
            color = price < open ? C.COLOR_RED : C.COLOR_GREEN;
            if (price == open)
            {
                color = C.COLOR_WHITE;
            }

            //  draw shadow
            g.setColor(C.COLOR_WHITE);
            x = c.x + c.w / 2;

            if (lo > 0 && hi > 0)
            {
                int minY = (int)(y0 + totalH - (lo - min) * ry);
                int maxY = (int)(y0 + totalH - (hi - min) * ry);

                g.drawLine(x, maxY, x, minY);
            }
            int centerX = x + bodyW / 2;
            //  candle's body
            int oY = (int)(y0 + totalH - (open - min) * ry);
            int cY = (int)(y0 + totalH - (price - min) * ry);

            y = oY < cY ? oY : cY;
            int bodyH = Utils.ABS_INT(cY - oY);

            if (bodyH < 2)
            {
                bodyH = 2;
            }
            g.setColor(color);
            g.fillRect(x - bodyW / 2, y, bodyW, bodyH);
        }
Exemple #7
0
        public TablePriceboard(xIEventListener listener, GainLossManager gainlosses, int w, int rowH)
            : base(listener)
        {
            setBackgroundColor(C.COLOR_BLACK);

            int cnt = gainlosses.getTotal();

            int y = 0;

            Font   f = Context.getInstance().getFontText();
            xLabel l = xLabel.createSingleLabel("Lãi lỗ");

            l.setBackgroundColor(C.COLOR_ORANGE);
            l.setSize(w, (int)f.GetHeight() + 4);
            l.setPosition(0, 0);
            l.setTextColor(C.COLOR_GREEN);
            y = l.getBottom() + 1;

            addControl(l);

            for (int i = 0; i <= cnt; i++)
            {
                int idx = i - 1;
                int rH  = rowH;
                if (idx == -1)
                {
                    rH = 20;
                }

                RowGainloss r = new RowGainloss(listener, i, w, rH);

                if (idx >= 0)
                {
                    stGainloss g = (stGainloss)gainlosses.getGainLossAt(idx);

                    r.setData(g);
                }
                r.setParent(this);
                r.setPosition(0, y);

                addControl(r);
                vRows.addElement(r);

                y += rH + 1;
            }

            //	thong ke
            {
                GainLossSumary sumary = new GainLossSumary(w);
                sumary.setPosition(0, y);
                addControl(sumary);

                y += sumary.getH();
            }
            //  Help
            {
                xFillBackground bottom = xFillBackground.createFill(w, 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);

                y += l.getH() + 4;
            }

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

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

            invalidate();
        }
        //  code | ref | KL1 | G1 |= GiaKhop | KLKhop | TongKL =| KL1 | G1 |=== TB | Cao | Thap
        override protected void updateQuote()
        {
            if (getID() < 0)
            {
                return;
            }
            Context ctx = Context.getInstance();

            if (getID() == 0)
            {
                //  code
                setCellValue(0, "Mã/TC", C.COLOR_GRAY);

                setCellValue(2, "Giá", C.COLOR_GRAY);

                setCellValue(3, "+/-", C.COLOR_GRAY);

                setCellValue(4, "GiáMua/KL", C.COLOR_GRAY);

                setCellValue(5, "Vốn (tr)", C.COLOR_WHITE);

                setCellValue(6, "Lãi  % / vnd", C.COLOR_GRAY);

                setCellValue(7, "Ngày mua", C.COLOR_WHITE);
            }

            if (getID() == 0)
            {
                return;
            }

            stGainloss gainloss = (stGainloss)getUserData();

            if (gainloss == null)
            {
                return;
            }
            String            code = gainloss.code;
            stPriceboardState item = ctx.mPriceboard.getPriceboard(code);

            if (item == null)
            {
                return;
            }

            String s;

            //  code
            uint color;

            setCellValue(0, item.getCode(), C.COLOR_WHITE);
            addCellValue1(0, String.Format("{0:F2}", item.getRef()), C.COLOR_YELLOW);
            float reference = item.getRef();
            float price     = item.getCurrentPrice();

            if (price == 0)
            {
                price = reference;
            }

            int j = 0;

            //  price
            color = ctx.valToColorF(item.getCurrentPrice(), item.getCe(), item.getRef(), item.getFloor());
            setCellValue(2, String.Format("{0:F2}", item.getCurrentPrice()), color);
            //	vol
            //s = volumeToString(item.getCurrentVolume());
            //addCellValue1(1, s);

            //  change +/-
            float v = price - reference;

            s = String.Format("{0:F2}", (float)v);
            if (item.getCurrentPrice() == 0)
            {
                s = "-";
            }
            setCellValue(3, s, color);

            //  GiaMua
            s = String.Format("{0:F2}", gainloss.price);
            setCellValue(4, s, C.COLOR_WHITE);
            //  KLMua
            s = String.Format("{0:D}", gainloss.volume);
            addCellValue1(4, s);

            //  Tien von
            double capital = gainloss.price * gainloss.volume / 1000.0f;

            s = String.Format("{0:F} tr", capital);
            setCellValue(5, s, C.COLOR_WHITE);

            //========================
            //  %GainLoss
            stPriceboardState ps           = item;
            float             currentPrice = ps.getCurrentPrice();

            if (currentPrice == 0)
            {
                currentPrice = ps.getRef();
            }

            price = gainloss.price;
            float percent = 0;

            if (price > 0)
            {
                percent = (float)(100 * (currentPrice - price)) / price;
            }
            if (percent > 0)
            {
                s = String.Format("+{0:F2} %", percent);
            }
            else
            {
                s = String.Format("{0:F2} %", percent);
            }
            if (percent > 0)
            {
                color = C.COLOR_GREEN;
            }
            else if (percent == 0)
            {
                color = C.COLOR_YELLOW;
            }
            else
            {
                color = C.COLOR_RED;
            }

            setCellValue(6, s, color);
            //  gainloss money
            double oValue  = price * gainloss.volume;
            double cValue  = currentPrice * gainloss.volume;
            double benefit = (cValue - oValue) / 1000;

            if (benefit > 0)
            {
                s = String.Format("+{0:F2} tr", benefit);
            }
            else
            {
                s = String.Format("{0:F2} tr", benefit);
            }

            addCellValue1(6, s);
            //  date
            //s = Utils.dateIntToString4(gainloss.date);
            //setCellValue(7, s, C.COLOR_WHITE);
        }
        public xDataOutput getUserDataAsStreamOldVersion()
        {
            xDataOutput o = new xDataOutput(5 * 1024);

            o.writeInt(FILE_ONLINE_USERDATA_VER);
            int i;

            xVector         v                = new xVector(10);
            xVector         mFavorGroups     = shareGroups();
            GainLossManager mGainLossManager = gainLossManager();

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

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

                bool added = false;
                for (int j = 0; j < v.size(); j++)
                {
                    stShareGroup o1 = (stShareGroup)v.elementAt(j);
                    if (o1.getName().CompareTo(p.getName()) == 0)
                    {
                        added = true;
                        break;
                    }
                }

                if (added == false)
                {
                    v.addElement(p);
                }
            }

            o.writeInt(v.size());

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

                p.save(o);
            }

            //  gainloss com.data
            o.writeInt(FILE_GAINLOSS_SIGNAL);
            o.writeInt(mGainLossManager.getTotal());
            for (i = 0; i < mGainLossManager.getTotal(); i++)
            {
                stGainloss g = mGainLossManager.getGainLossAt(i);

                o.writeUTF(g.code);
                o.writeInt(g.date);
                o.writeInt((int)g.price);
                o.writeInt(g.volume);
            }

            //  filter sets
            o.writeInt(FILE_FILTER_SET_VERSION);
            FilterManager.getInstance().saveFilterSets(o);

            //  down signal group
            //o.writeInt(FILE_DOWN_SIGNAL);
            //mAlarmGroup.save(o);

            return(o);
        }
Exemple #10
0
        public DlgBuyMore(stGainloss g)
        {
            InitializeComponent();

            lb_Quote.Text = g.code;
        }