一个完整的c#股票分析软件源码

namespace Demo1
{
    public partial class MainStock : Form
    {

        const int WM_NCHITTEST = 0x0084;
        const int HTLEFT = 10;
        const int HTRIGHT = 11;
        const int HTTOP = 12;
        const int HTTOPLEFT = 13;
        const int HTTOPRIGHT = 14;
        const int HTBOTTOM = 15;
        const int HTBOTTOMLEFT = 0x10;
        const int HTBOTTOMRIGHT = 17;

        [DllImport("user32.dll")]
        public static extern bool ReleaseCapture();
        [DllImport("user32.dll")]
        public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_MOVE = 0xF010;
        public const int HTCAPTION = 0x0002;

        private const long WM_GETMINMAXINFO = 0x24;
        public struct POINTAPI
        {
            public int x;
            public int y;
        }
        public struct MINMAXINFO
        {
            public POINTAPI ptReserved;
            public POINTAPI ptMaxSize;
            public POINTAPI ptMaxPosition;
            public POINTAPI ptMinTrackSize;
            public POINTAPI ptMaxTrackSize;
        }


        public class RecvBuf
        {
            public int len;
            public int type1;
            public int type2;
            public Byte[] buf;
        }
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        struct StockZu
        {
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
            public byte[] code;
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 14)]
            public float[] zl;
        };

        String[] sw =
            {"i序号",
             "s代码", "s名称",
             "d涨幅" ,"d今开", "d最高", "d最低", "d最新","d昨收","s总量","d现手","d持仓","s总额", "d买入", "d卖出","d内盘","d外盘",
             "d总股本","d流通股","d总资产","d股权益",
             "d公积金","d净资产","d总利润","d净利润",
             "d主收入","d收益率","d负债比",
             "i市场","i类型","i自选","scode","itime",
             "s拼音",
             "i索引"
            };
        public List<CStock.infolist> DL = new List<CStock.infolist>();

        public string serveraddress = "119.147.80.145";
        public int serverport = 8001;
        private NetworkStream ns;
        private BinaryReader br;

        private TcpClient clientsocket = null;
        private Thread receive = null;
        private int datetime;//当前股票日期
        private bool connected = false;
        private Queue RecvList = new Queue(); //接收到的数据表

        private int GpCount;//股票总数量
        private float[] ft = new float[35];//当前股票盘口
        private int top1 = 0, top2 = 0;//轮询当前位置

        Boolean Doing = false;
        public DataTable dt;
        DataView dv;
        int topline = -1;


        private Button[] Binfo = new Button[16];
        private String[] WeekString ={ "日线", "周线", "月线", "5分钟线", "15分钟线", "30分钟线", "60分钟线", "120分钟线", "分笔线", "1分钟线" };

        private String GCODE;//当前股票代码
        private String GCode;//当前股票代码
        private String GName;//当前股票名称
        private double GPreclose;//昨收
        private int GMark;//当前股票所在市场 
        private int GType;//当前股票类型
        private int GZq = 1;//当前股票周期
        private Boolean Working = true;//开市中 

        GPINFO CurStockInfo;

        Flash FlashWindow = null;
        public Jken JkenWindow = null;
        public MainStock()
        {
            Control.CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
            serverport = 8001;
            GpCount = 0;
            GCode = "000001";
            GName = "";
            GMark = 0;
            GType = 0;
            dt = MakeTable();
            dv = new DataView(dt);

            //dView.RowsDefaultCellStyle.BackColor = Color.FromArgb(255, 255, 255);//第一行   
            //dView.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(160, 199, 250);//第二行   
            dView.GridColor = Color.FromArgb(128, 128, 128);//字段网格边框  
            dView.EnableHeadersVisualStyles = false;
            dView.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
            dView.ColumnHeadersDefaultCellStyle.BackColor = Color.Black;
            dView.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dView.RowHeadersDefaultCellStyle.ForeColor = Color.White;
            dView.RowHeadersDefaultCellStyle.BackColor = Color.Black;
            this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);

            Binfo[0] = bt1;
            Binfo[1] = bt2;
            Binfo[2] = bt3;
            Binfo[3] = bt4;
            Binfo[4] = bt5;
            Binfo[5] = bt6;
            Binfo[6] = bt7;
            Binfo[7] = bt8;
            Binfo[8] = bt9;
            Binfo[9] = bt10;
            Binfo[10] = bt11;
            Binfo[11] = bt12;
            Binfo[12] = bt13;
            Binfo[13] = bt14;
            Binfo[14] = bt15;
            Binfo[15] = bt16;
            for (int i = 0; i < 16; i++)
            {
                Binfo[i].Text = "";
                Binfo[i].TabStop = false;
                Binfo[i].Click += new System.EventHandler(bt1_Click);
            }
        }

        /// <summary>
        /// byte数组转结构体
        /// </summary>
        /// <param name="bytes">byte数组</param>
        /// <param name="offset">开始转换的位置</param>
        /// <param name="type">结构体类型</param>
        /// <returns>转换后的结构体</returns>
        public static object BytesToStuct(byte[] bytes, int offset, Type type)
        {

            //得到结构体的大小
            int size = Marshal.SizeOf(type);
            //byte数组长度小于结构体的大小
            if (size > (bytes.Length - offset))
            {
                //返回空
                return null;
            }
            //分配结构体大小的内存空间
            IntPtr structPtr = Marshal.AllocHGlobal(size);
            //将byte数组拷到分配好的内存空间
            try
            {
                // 将字节数组复制到结构体指针
                Marshal.Copy(bytes, offset, structPtr, size);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ByteArrayToStructure FAIL: error " + ex.ToString());
            }
            //将内存空间转换为目标结构体
            object obj1 = Marshal.PtrToStructure(structPtr, type);
            //释放内存空间
            Marshal.FreeHGlobal(structPtr);
            //返回结构体
            return obj1;
        }
        public static byte[] StructToBytes(object structObj)
        {
            //得到结构体的大小
            int size = Marshal.SizeOf(structObj);
            //创建byte数组
            byte[] bytes = new byte[size];
            //分配结构体大小的内存空间
            IntPtr structPtr = Marshal.AllocHGlobal(size);
            //将结构体拷到分配好的内存空间
            Marshal.StructureToPtr(structObj, structPtr, false);
            //从内存空间拷到byte数组
            Marshal.Copy(structPtr, bytes, 0, size);
            //释放内存空间
            Marshal.FreeHGlobal(structPtr);
            //返回byte数组
            return bytes;
        }
        private void tStock1_DoubleClick_1(object sender, EventArgs e)
        {
            Stock.ShowCursor = Stock.ShowCursor ^ true;
        }
        private void test_Load(object sender, EventArgs e)
        {
            panel2.Dock = System.Windows.Forms.DockStyle.Fill;
            GPSTOCK.Dock = System.Windows.Forms.DockStyle.Fill;
            Stock.Dock = System.Windows.Forms.DockStyle.Fill;
            info.Dock = System.Windows.Forms.DockStyle.Fill;
            dView.Dock = System.Windows.Forms.DockStyle.Fill;
            Board.Dock = System.Windows.Forms.DockStyle.Fill;
            gpinfo.Dock = System.Windows.Forms.DockStyle.Fill;
            Titile.Dock = System.Windows.Forms.DockStyle.Fill;
            Stock.ShowBoard = true;
            GpKey.Visible = false;
            //this.Width = 800;
            //this.Height = 600;
            FlashWindow = new Flash();
            FlashWindow.Owner = this;

            IniFile ini = new IniFile(Directory.GetCurrentDirectory() + "\\Stock.ini");
            string fname = ini.IniReadValue("Main", "ListFontName");
            string fsize = ini.IniReadValue("Main", "ListFontSize");
            if ((fname.Length > 0) && (fsize.Length > 0))
                dView.Font = new Font(fname, Convert.ToSingle(fsize));
            string maxwindow = ini.IniReadValue("Main", "MaxWindows");
            if (maxwindow.Length > 0)
            {
                maxwindow = maxwindow.ToLower();
                if (maxwindow == "true")
                    this.WindowState = FormWindowState.Maximized;
            }

            string fswindows = ini.IniReadValue("Main", "Windows");
            if (fswindows.Length > 0)
            {
                int w1 = 0;
                if (int.TryParse(fswindows, out w1))
                {
                    if ((w1 > 0) && (w1 < 11))
                        Stock.Windows = w1;
                }
            }

            string kwindows = ini.IniReadValue("Main", "KWindows");
            if (kwindows.Length > 0)
            {
                int w1 = 0;
                if (int.TryParse(kwindows, out w1))
                {
                    if ((w1 > 0) && (w1 < 11))
                        Stock.TechWindows = w1;
                }
            }


            for (int i = 1; i < 11; i++)
            {
                string techstr1 = ini.IniReadValue("Main", "Tech" + i.ToString());
                if (techstr1.Length > 0)
                    Stock.LoadMDB(techstr1, 100 + i);
            }
            for (int i = 1; i < 11; i++)
            {
                string techstr1 = ini.IniReadValue("Main", "KTech" + i.ToString());
                if (techstr1.Length > 0)
                    Stock.LoadMDB(techstr1, i);
            }

        }

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            switch (m.Msg)
            {
                case WM_NCHITTEST:
                    Point vPoint = new Point((int)m.LParam & 0xFFFF,
                        (int)m.LParam >> 16 & 0xFFFF);
                    vPoint = PointToClient(vPoint);
                    if (vPoint.X <= 5)
                        if (vPoint.Y <= 5)
                            m.Result = (IntPtr)HTTOPLEFT;
                        else if (vPoint.Y >= ClientSize.Height - 5)
                            m.Result = (IntPtr)HTBOTTOMLEFT;
                        else m.Result = (IntPtr)HTLEFT;
                    else if (vPoint.X >= ClientSize.Width - 5)
                        if (vPoint.Y <= 5)
                            m.Result = (IntPtr)HTTOPRIGHT;
                        else if (vPoint.Y >= ClientSize.Height - 5)
                            m.Result = (IntPtr)HTBOTTOMRIGHT;
                        else m.Result = (IntPtr)HTRIGHT;
                    else if (vPoint.Y <= 5)
                        m.Result = (IntPtr)HTTOP;
                    else if (vPoint.Y >= ClientSize.Height - 5)
                        m.Result = (IntPtr)HTBOTTOM;
                    break;
            }

            if (m.Msg == WM_GETMINMAXINFO)
            {
                MINMAXINFO mmi = (MINMAXINFO)m.GetLParam(typeof(MINMAXINFO));
                mmi.ptMinTrackSize.x = this.MinimumSize.Width;
                mmi.ptMinTrackSize.y = this.MinimumSize.Height;
                if (this.MaximumSize.Width != 0 || this.MaximumSize.Height != 0)
                {
                    mmi.ptMaxTrackSize.x = this.MaximumSize.Width;
                    mmi.ptMaxTrackSize.y = this.MaximumSize.Height;
                }
                mmi.ptMaxPosition.x = 1;
                mmi.ptMaxPosition.y = 1;
                System.Runtime.InteropServices.Marshal.StructureToPtr(mmi, m.LParam, true);
            }

        }
        private void StartChat()
        {
            timer1.Enabled = false;
            timer2.Enabled = false;
            RecvList.Clear();
            try
            {
                clientsocket = new TcpClient(serveraddress, serverport);
                ns = clientsocket.GetStream();
                br = new BinaryReader(ns);
                connected = true;
                String Logins = "\xFD\xFD\xFD\xFD\x30\x30\x30\x30\x30\x30\x31\x38\x00\x04\x05\x00\x67\x75\x65\x73\x74\x0D\x00\x32\x30\x31\x30\x31\x30\x32\x30\x00\x46\x4C\x32\x00\x00";
                Byte[] outbytes = new Byte[Logins.Length];
                for (int i = 0; i < Logins.Length; i++)
                    outbytes[i] = (byte)Logins[i];
                ns.Write(outbytes, 0, outbytes.Length);

            }
            catch
            {
                connected = false;
                LinkServer.Enabled = true;
                QuitServer.Enabled = false;
                return;
            }
            if (connected)
            {
                LinkServer.Enabled = false;
                QuitServer.Enabled = true;
                receive = new Thread(new ThreadStart(ReceiveChat));
                receive.Start();
                timer1.Enabled = true;
                if (connected)
                {
                    FConnect.Text = "已连接";
                    FConnect.BackColor = Color.Green;
                }

            }

        }
        private void QuitChat()
        {
            if (connected)
            {
                try
                {
                    br.Close();
                    ns.Close();
                    clientsocket.Close();
                    connected = false;
                }
                catch
                {

                }
            }
            if (receive != null && receive.IsAlive)
                receive.Abort();
            if (connected == false)
            {
                FConnect.Text = "服务器已断开";
                //FConnect.BackColor = Color.Red;
            }
            clientsocket = null;
            timer1.Enabled = false;
            timer2.Enabled = false;
            LinkServer.Enabled = true;
            QuitServer.Enabled = false;
            RecvList.Clear();
        }
        private void ReceiveChat()
        {
            bool keepalive = true;
            uint bz;
            ushort type1, type2;
            Byte[] head = new Byte[18];
            Byte[] hexlen = new Byte[8];
            Byte[] buf = new byte[2048];
            int hdlen = 0;
            while (keepalive)
            {
                try
                {
                    try
                    {
                        int Len = ns.Read(head, hdlen, 13-hdlen);
                        if (Len > 0)
                            hdlen += Len;
                        if (hdlen == 13)
                        {
                            hdlen = 0;
                            bz = (uint)(head[0] * 0x1000000 + head[1] * 0x10000 + head[2] * 0x100 + head[3]);
                            String t;
                            t = "";
                            for (int i = 0; i < 13; i++)
                                t += Convert.ToString(head[i], 16) + " ";
                            for (int i = 4; i < 12; i++)
                                hexlen[i - 4] = head[i];
                            String hl = Encoding.Default.GetString(hexlen);
                            int blen = Convert.ToInt32(hl, 16);
                            type1 = 0;
                            type2 = 0;
                            RecvBuf db = new RecvBuf();
                            db.buf = new Byte[blen];
                            if (blen > 0)
                            {
                                int fcur = 0;
                                Loading.Value = 0;
                                Loading.Minimum = 0;
                                Loading.Maximum = blen;
                                while (fcur < blen)
                                {
                                    Len = ns.Read(db.buf, fcur, (blen - fcur) > 2048 ? 2048 : blen - fcur);
                                    if (Len > 0)
                                    {
                                        fcur += Len;
                                        Loading.Value = fcur;
                                    }

                                }
                                type1 = (ushort)(db.buf[1] * 0x100 + db.buf[0]);
                                type2 = (ushort)(db.buf[3] * 0x100 + db.buf[2]);
                                db.type1 = type1;
                                db.type2 = type2;
                                db.len = blen;
                                RecvList.Enqueue(db);
                            }
                            if (type2 == 0x100)
                            {
                                String Logins = "\xFD\xFD\xFD\xFD\x30\x30\x30\x30\x30\x30\x31\x37\x00\x01\x00\x01\x0C\x34\x11\x00\x00\x55\x50\x5C\x56\x45\x52\x53\x49\x4F\x4E\x2E\x49\x4E\x49\x00";
                                Byte[] outbytes = new Byte[Logins.Length];
                                for (int i = 0; i < Logins.Length; i++)
                                {
                                    outbytes[i] = (byte)Logins[i];
                                }
                                ns.Write(outbytes, 0, outbytes.Length);
                            }
                            if (type2 == 0xc01)
                            {
                                String Logins = "\xFD\xFD\xFD\xFD\x30\x30\x30\x30\x30\x30\x30\x34\x00\x01\x00\x10\x01";
                                Logins += "\xFD\xFD\xFD\xFD\x30\x30\x30\x30\x30\x30\x30\x39\x00\x01\x00\x01\x02\x00\x00\x00\x00\x00";//
                                Logins += "\xFD\xFD\xFD\xFD\x30\x30\x30\x30\x30\x30\x30\x39\x00\x01\x00\x01\x02\x01\x00\x00\x00\x00";
                                Byte[] outbytes = new Byte[Logins.Length];
                                for (int i = 0; i < Logins.Length; i++)
                                {
                                    outbytes[i] = (byte)Logins[i];
                                }
                                ns.Write(outbytes, 0, outbytes.Length);
                            }


                        }
                    }
                    catch(Exception ee)
                    {
                        
                        break;
                    }

                }
                catch
                {
                    break;
                }
            }
            connected = false;
            FConnect.Text = "断开";
            FConnect.BackColor = Color.Red;
            br.Close();
            ns.Close();
            clientsocket.Close();
            clientsocket = null;
            timer1.Enabled = false;
            timer2.Enabled = false;
            RecvList.Clear();
        }
        private int gptime(int v)
        {
            int j = v + 9 * 60 + 30;
            if (v > 120)
                j = j + 90;
            int h = j / 60;
            int m = j % 60;
            return h * 100 + m;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (Doing)
                return;
            if (RecvList.Count == 0)
                return;
            Doing = true;
            int len, y, j;
            double[] date;
            double[] FDataTimer;
            double[] high;
            double[] low;
            double[] open;
            double[] close;
            double[] amount;
            double[] vol;
            double pvol = 0, pamount = 0;
            String s1, s2;
            byte m1;

            int mk, tp, gl;
            byte[] code2 = new byte[6];
            string code;

            DataRow myDataRow;
            //timer1.Enabled = false;
            RecvBuf db = (RecvBuf)RecvList.Dequeue();
            MemoryStream ms = new MemoryStream(db.buf);
            BinaryReader br = new BinaryReader(ms);
            ushort type1 = (ushort)br.ReadInt16();
            ushort type2 = (ushort)br.ReadInt16();

            //listBox1.Items.Add(type2.ToString("x8"));
            // FileStream fs = new FileStream("C:\\C" + type2.ToString("x4") + ".Bin", FileMode.Create, FileAccess.Write);
            //fs.Write(db.buf, 0, db.buf.Length);
            // fs.Close();

            switch (type2)
            {
                case 0x712://除权
                    ms.Seek(29 - 13, 0);
                    len = br.ReadInt16();
                    listBox1.Items.Clear();
                    Stock.ClearQuan();
                    for (int i = 0; i < len; i++)
                    {
                        ms.Seek(18 + i * 168, 0);
                        cqinfo cq = new cqinfo();
                        cq.Date = br.ReadInt32();
                        cq.Number = br.ReadInt32() / 1000.0;
                        cq.PeiNumber = br.ReadInt32() / 1000.0;
                        cq.Money = br.ReadInt32() / 1000.0;
                        cq.PeiMoney = br.ReadInt32() / 1000.0;
                        Stock.AddQuan(cq);
                        s1 = cq.Date.ToString() + " 送现金:" + cq.Money.ToString() + " 配股价:" + cq.PeiMoney.ToString() + " 送股数:" + cq.Number.ToString() + " 配股比例:" + cq.PeiNumber.ToString();
                        listBox1.Items.Add(s1);

                    }
                    if (len > 0)
                    {
                        Stock.SetQuanStyle(Stock.Quan);
                    }
                    break;
                case 0x701: //日线数据
                    ms.Seek(6, 0);
                    code2 = br.ReadBytes(6);
                    code = System.Text.Encoding.Default.GetString(code2);
                    
                    ms.Seek(21, 0);
                    len = br.ReadInt16();
                    date = new double[len + 1];
                    FDataTimer = new double[len + 1];
                    high = new double[len + 1];
                    low = new double[len + 1];
                    open = new double[len + 1];
                    close = new double[len + 1];
                    amount = new double[len + 1];
                    vol = new double[len + 1];
                    for (int i = 0; i < len; i++)
                    {
                        Application.DoEvents();
                        ms.Seek(36 + i * 28 - 13, 0);
                        int td1 = br.ReadInt32();
                        FDataTimer[i] = 930;

                        open[i] = br.ReadSingle();
                        high[i] = br.ReadSingle();
                        low[i] = br.ReadSingle();
                        close[i] = br.ReadSingle();
                        vol[i] = br.ReadSingle();
                        amount[i] = br.ReadSingle();
                        date[i] = td1;
                        if (td1 > 30081231)
                        {
                            int h = td1;
                            y = (int)((h & 0xFFF00000) >> 20);
                            int m = (h & 0x000F0000) >> 16;
                            int d = (h & 0x0000FFFF) >> 11;
                            int h1 = (h & 0x000003FF) >> 6;
                            int m2 = h & 0x0000003F;
                            date[i] = y * 10000 + m * 100 + d;
                            FDataTimer[i] = h1 * 100 + m2;
                        }
                    }
                    /*
                        if (CurStockInfo.close > 0)
                        {
                            date[len] = datetime;
                            FDataTimer[len] = 930;
                            high[len] = CurStockInfo.high;
                            low[len] = CurStockInfo.low;
                            open[len] = CurStockInfo.open;
                            close[len] = CurStockInfo.close;
                            vol[len] = CurStockInfo.vol;
                            amount[len] = CurStockInfo.amount;
                            len+=1;
                        }
                    */
                    Stock.K_cleardataAll();// .K_cleardata();
                    Stock.PreClose = GPreclose;
                    Stock.StkCode = GCODE;
                    Stock.StkName = GName;
                    Stock.StkWeek = WeekString[GZq - 1];
                    Stock.AddAll("date", date, len, false);
                    Stock.AddAll("time", FDataTimer, len, false);
                    Stock.AddAll("high", high, len, false);
                    Stock.AddAll("low", low, len, false);
                    Stock.AddAll("open", open, len, false);
                    Stock.AddAll("close", close, len, false);
                    Stock.AddAll("amount", amount, len, false);
                    Stock.AddAll("vol", vol, len, true);
                    break;
                case 0x601: //1分钟数据
                    mk = db.buf[4];
                    tp = db.buf[5];
                    Array.Copy(db.buf, 6, code2, 0, 6);
                    code = System.Text.Encoding.Default.GetString(code2);


                    ms.Seek(14, 0);
                    len = br.ReadInt16();
                    date = new double[len + 1];
                    FDataTimer = new double[len + 1];
                    high = new double[len + 1];
                    low = new double[len + 1];
                    open = new double[len + 1];
                    close = new double[len + 1];
                    amount = new double[len + 1];
                    vol = new double[len + 1];
                    pvol = 0;
                    pamount = 0;
                    for (int i = 0; i < len; i++)
                    {
                        Application.DoEvents();
                        ms.Seek(29 + i * 28 - 13, 0);
                        date[i] = datetime;
                        FDataTimer[i] = gptime(i);

                        close[i] = br.ReadSingle();//0
                        if (close[i] == 0)
                            close[i] = GPreclose;
                        float pvol1 = br.ReadSingle();//1
                        vol[i] = pvol1 - pvol;
                        float pamount1 = br.ReadSingle();//2
                        amount[i] = pamount1 - pamount;
                        pvol = pvol1;
                        pamount = pamount1;
                        high[i] = br.ReadSingle();
                        low[i] = br.ReadSingle();
                        open[i] = br.ReadSingle();
                    }
                    if ((Stock.TabValue == 2) && (tp == 0))
                    {
                        Stock.zs_Clear();
                        DataRow[] dr = dt.Select("索引=" + mk.ToString() + code);
                        if (dr.Length == 1)
                            Stock.zs_SetName(dr[0]["名称"] + "-" + code);
                        Stock.zs_AddAll("date", date, len, false);
                        Stock.zs_AddAll("time", FDataTimer, len, false);
                        Stock.zs_AddAll("amount", amount, len, false);
                        Stock.zs_AddAll("vol", vol, len, false);
                        Stock.zs_AddAll("close", close, len, true);
                    }
                    if (code == GCode)
                    {
                        Stock.FS_cleardataAll();
                        Stock.PreClose = GPreclose;
                        Stock.StkCode = GCODE;
                        Stock.StkName = GName;
                        Stock.FS_AddAll("date", date, len, false);
                        Stock.FS_AddAll("time", FDataTimer, len, false);
                        Stock.FS_AddAll("amount", amount, len, false);
                        Stock.FS_AddAll("vol", vol, len, false);
                        Stock.FS_AddAll("close", close, len, true);
                    }
                    break;
                case 0x502: //全部分笔数据
                    ms.Seek(14, 0);
                    len = br.ReadInt16();

                    if ((GZq == 9) || (Stock.TabValue == 1))
                    {
                        Stock.ClearJia();
                        date = new double[len + 1];
                        FDataTimer = new double[len + 1];
                        close = new double[len + 1];
                        amount = new double[len + 1];
                        vol = new double[len + 1];
                        pvol = 0;
                        pamount = 0;
                        for (int i = 0; i < len; i++)
                        {
                            Application.DoEvents();
                            ms.Seek(16 + i * 26, 0);
                            date[i] = datetime;
                            FDataTimer[i] = gptime((int)(br.ReadUInt16()));
                            close[i] = br.ReadSingle();
                            float pvol1 = br.ReadSingle();
                            vol[i] = pvol1 - pvol;
                            float pamount1 = br.ReadSingle();
                            float low11 = br.ReadSingle();
                            float high11 = br.ReadSingle();
                            amount[i] = pamount1 - pamount;
                            if (Stock.TabValue == 1)
                            {
                                if (close[i] <= low11)
                                    Stock.AddJia(close[i], 0, (int)(vol[i]));
                                else
                                    Stock.AddJia(close[i], (int)(vol[i]), 0);
                            }
                            pvol = pvol1;
                            pamount = pamount1;
                        }
                        if (GZq == 9)
                        {
                            Stock.K_cleardata();
                            Stock.StkCode = GCode.Replace('\0', ' ').Trim();
                            Stock.StkName = GName;
                            Stock.StkWeek = WeekString[GZq - 1];
                            Stock.AddAll("date", date, len, false);
                            Stock.AddAll("time", FDataTimer, len, false);
                            Stock.AddAll("amount", amount, len, false);
                            Stock.AddAll("vol", vol, len, false);
                            Stock.AddAll("close", close, len, true);
                        }
                    }
                    if ((Stock.TabValue == 1) && (len > 0))
                        Stock.TabPaint(1);
                    break;
                case 0x501://最后分笔数据
                    ms.Seek(25 - 13, 0);
                    len = br.ReadInt16();
                    Stock.FenBiList.Clear();
                    pvol = 0;
                    for (int i = 0; i < len; i++)
                    {
                        ms.Seek(27 + i * 26 - 13, 0);
                        int time = br.ReadUInt16();
                        time = gptime(time);
                        double close1 = br.ReadSingle();
                        double vol1 = br.ReadSingle();
                        double amount1 = br.ReadSingle();
                        double low1 = br.ReadSingle();
                        double high1 = br.ReadSingle();
                        int v2 = br.ReadInt32();
                        String s11 = String.Format("{0:d4} ", time);
                        if (close1 > 9999)
                            s11 += String.Format(" {0:F0}", close1);
                        else if (close1 > 1000)
                            s11 += String.Format(" {0:F2}", close1);
                        else
                            s11 += String.Format(" {0:F3}", close1);
                        int vol2 = (int)(vol1 - pvol);
                        if (vol2 > 100)
                            vol2 = vol2 / 100;
                        s11 += String.Format(" {0:d8}", Convert.ToInt32(vol2));
                        if (ft[0] != 0)
                        {
                            if (close1 <= low1)
                                s11 += " S";
                            else
                                s11 += " B";

                        }
                        if (i > 0)
                        {
                            if (close1 <= low1)
                                Stock.AddTick(time, close1, vol2, 0);
                            else
                                Stock.AddTick(time, close1, vol2, 1);
                        }
                        pvol = vol1;
                    }
                    break;
                case 0x301://盘口资料
                    len = db.buf[5] * 256 + db.buf[4];
                    GPINFO gp = new GPINFO();
                    ZSINFO zs = new ZSINFO();
                    gl = Marshal.SizeOf(gp.GetType());
                    for (int i = 0; i < len; i++)
                    {
                        gp = (GPINFO)BytesToStuct(db.buf, 6 + i * gl, gp.GetType());
                        if (gp.time > 240)
                            Working = false;
                        if (gp.ftype == 0)
                        {
                            zs = (ZSINFO)BytesToStuct(db.buf, 6 + i * gl, zs.GetType());
                        }
                        String tcode = System.Text.Encoding.ASCII.GetString(gp.code);
                        mk = gp.fmark;
                        tp = gp.ftype;
                        if ((mk == 0) && (tcode == "000001"))
                        {
                            shzs.Text = string.Format("{0:F2}  {1:F2}  {2:F2}亿", gp.close, gp.close - gp.prev_close, gp.amount / 100000000);
                            if (gp.close > gp.prev_close)
                                shzs.ForeColor = Color.Red;
                            else
                                shzs.ForeColor = Color.Green;
                        }

                        if ((mk == 1) && (tcode == "399001"))
                        {
                            szzs.Text = string.Format("{0:F2}  {1:F2}  {2:F2}亿", gp.close, gp.close - gp.prev_close, gp.amount / 100000000);
                            if (gp.close > gp.prev_close)
                                szzs.ForeColor = Color.Red;
                            else
                                szzs.ForeColor = Color.Green;
                        }

                        if ((GMark == mk) && (GType == tp) && (GCode == tcode) && (Stock.ShowBoard))
                        {
                            CurStockInfo = (GPINFO)BytesToStuct(db.buf, 6 + i * gl, gp.GetType());
                            Stock.PreClose = gp.prev_close;
                            if (gp.ftype != 0)
                                Stock.SetStockInfo(gp);
                            else
                                Stock.SetStockInfo(zs);
                        }
                        string ss = mk.ToString() + tcode.Replace('\0', ' ').Trim().ToUpper(); ;
                        ss = ss.GetHashCode().ToString("D10");
                        DataRow[] dr = dt.Select("索引=" + ss);
                        if (dr.Length == 1)
                        {
                            DataRow dr1 = dr[0];
                            dr1.BeginEdit();
                            dr1["今开"] = gp.open;
                            dr1["最高"] = gp.high;
                            dr1["最低"] = gp.low;
                            dr1["最新"] = gp.close;
                            dr1["内盘"] = gp.mai3pan;
                            dr1["外盘"] = gp.mai4pan;
                            dr1["持仓"] = gp.t2;
                            int ll1 = (int)gp.vol;
                            if (gp.fmark < 0x40)//股票
                                ll1 = ll1 / 100;
                            ss = ll1.ToString("F0");
                            if (ll1 > 10000000)
                            {
                                ll1 = ll1 / 10000;
                                ss = ll1.ToString("F0") + "万";
                            }
                            dr1["总量"] = ss;// ft[6] / 100;
                            double ll = gp.amount / 10000;
                            ss = ll.ToString("F0");
                            if (ll > 100000000)
                            {
                                ll = ll / 100000000;
                                ss = ll.ToString("F0") + "亿";
                            }
                            dr1["总额"] = ss;// ft[7] / 10000;
                            if (ft[0] == 1)
                                ft[0] = 1;
                            if (mk < 0x40)
                                dr1["现手"] = gp.xl / 100;
                            else
                                dr1["现手"] = gp.xl;
                            if (gp.close == 0)
                                dr1["涨幅"] = 0;
                            else
                                dr1["涨幅"] = (gp.close - gp.prev_close) * 100 / gp.prev_close;
                            if (tp == 0)
                            {
                                dr1["买入"] = zs.ups;
                                dr1["卖出"] = zs.downs;
                            }
                            else
                            {
                                dr1["买入"] = gp.mai3[0];
                                dr1["卖出"] = gp.mai4[0];
                            }
                            dr1.EndEdit();
                        }
                    }
                    break;
              

    }


}


 

  • 0
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

筱璦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值