adfasdf

using System;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net.Sockets;
using System.IO;
using System.Threading;
using System.Text;
using System.Runtime.InteropServices;
using CStock;
using StockStruct;

/*
sbyte 	有®D符¤?号?8位?整?数ºy	-128-127	SByte
byte	无T符¤?号?8位?整?数ºy	0-255	Byte
short	有®D符¤?号?16位?整?数ºy	-32768-32767	Int16
ushort	无T符¤?号?16位?整?数ºy	0-65535	UInt16
Int	有®D符¤?号?32位?整?数ºy	-2147489648-2147483647	Int32
uint	无T符¤?号?32位?整?数ºy	0-42994967295	UInt32
long	有®D符¤?号?64位?整?数ºy	-263-263	Int64
ulong	无T符¤?号?64位?整?数ºy	0-264	UInt64
*/
namespace Demo1
{
    //horse
    using Nezip;
    using Demo1.DataService;
    using Demo1.Event;
    using Demo1.Tech;
    using Demo1.WebService;
    using Demo1.Forms;
    using System.Runtime.Serialization.Formatters.Binary;
    using Demo1.Log;
    using System.Diagnostics;
    using Demo1.Serialize;
    using Demo1.StockDataService;
    using Demo1.Files;
    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[] columnNames = { "i序¨°号?", "s代䨲码?", "s名?称?", "s标À¨º记?","i标À¨º记?值¦Ì","d前¡ã涨?幅¤¨´","d涨?幅¤¨´","TECHS","d涨?速¨´","d振?幅¤¨´", "d最Á?新?", "d买¨°价?","i买¨°量¢?", "d卖?价?","i卖?量¢?",
                          "d今?开a", "d最Á?高?", "d最Á?低̨ª", "d昨Á¨°收º?", "i总Á¨¹量¢?", "i现?量¢?", "s总Á¨¹额?",
                          "i持?仓?", "s行D业°¦Ì板ã?块¨¦","s市ºD场?", "s类¤¨¤型¨ª", "i自Á?选?", "scode", "s拼¡ä音°?", "i索¡Â引°y" ,
                          "d买¨°价?1","i买¨°量¢?1","d买¨°价?2","i买¨°量¢?2","d买¨°价?3","i买¨°量¢?3","d买¨°价?4","i买¨°量¢?4","d买¨°价?5","i买¨°量¢?5",
                          "d卖?价?1","i卖?量¢?1","d卖?价?2","i卖?量¢?2","d卖?价?3","i卖?量¢?3","d卖?价?4","i卖?量¢?4","d卖?价?5","i卖?量¢?5",
                      };
        String[] sw = null;//DataView显?示º?的Ì?列¢D
        List<String> listSW = new List<string>();///DataView全¨?部?列¢D表À¨ª
        public List<Demo1.Jken.jkfunc> ColumnTechList = new List<Demo1.Jken.jkfunc>();//列¢D表À¨ª中D要°a显?示º?的Ì?公?式º?

        private List<string> showingcolumns = new List<string>();
        private List<string> hidingcolumns = new List<string>();

        public List<CStock.infolist> DL = new List<CStock.infolist>();

        public static string serveraddress = "127.0.0.1";
        public static int serverport = 8080;
        public static int socketport = 8888;

        public static TcpClient clientsocket = null;
        private Thread receive = null;
        private int datetime = DateTime.Today.Year * 10000 + DateTime.Today.Month * 100 + DateTime.Today.Day;//当Ì¡À前¡ã股¨¦票¡À日¨?期¨²
        private bool connected = false;
        private Queue RecvList = new Queue(); //接¨®收º?到Ì?的Ì?数ºy据Y表À¨ª

        private int GpCount;//股¨¦票¡À总Á¨¹数ºy量¢?
        private float[] ft = new float[35];//当Ì¡À前¡ã股¨¦票¡À盘¨¬口¨²
        private int top1 = 0, top2 = 0;//轮?询¡¥当Ì¡À前¡ã位?置?

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


        private Button[] Binfo = new Button[16];
        public String[] WeekString = { "日¨?线?", "周¨¹线?", "月?线?", "5分¤?钟¨®线?", "15分¤?钟¨®线?", "30分¤?钟¨®线?", "60分¤?钟¨®线?", "120分¤?钟¨®线?", "分¤?笔À¨º线?", "1分¤?钟¨®线?" };

        //public String GCODE;//当Ì¡À前¡ã股¨¦票¡À代䨲码?
        public String GCode;//当Ì¡À前¡ã股¨¦票¡À代䨲码?
        public String GName;//当Ì¡À前¡ã股¨¦票¡À名?称?
        public double GPreclose;//昨Á¨°收º?
        public double GOpen;//今?开a
        public int GMark;//当Ì¡À前¡ã股¨¦票¡À所¨´在¨²市ºD场? 
        public string strMark;//当Ì¡À前¡ã股¨¦票¡À所¨´在¨²市ºD场? 
        public String GType;//当Ì¡À前¡ã股¨¦票¡À类¤¨¤型¨ª
        public int GZq = 1;//当Ì¡À前¡ã股¨¦票¡À周¨¹期¨²  // private String[] WeekString = { "日¨?线?", "周¨¹线?", "月?线?", "5分¤?钟¨®线?", "15分¤?钟¨®线?", "30分¤?钟¨®线?", "60分¤?钟¨®线?", "120分¤?钟¨®线?", "分¤?笔À¨º线?", "1分¤?钟¨®线?" };
        private Boolean Working = true;//开a市ºD中D 
        private Boolean keepalive = false;
       
        //SHAG上¦?海¡êA股¨¦,ê?SZAG深¦?圳¨²A股¨¦,ê?HK港?股¨¦,ê?SHSZAG沪|深¦?A股¨¦,ê?SHQH上¦?海¡ê商¦¨¬品¡¤,ê?ZZQH郑¡ê州Y商¦¨¬品¡¤,ê?DLQH大䨮连¢?商¦¨¬品¡¤,ê?ZJQH中D金e所¨´期¨²货?|股¨¦指?期¨²货? ZX自Á?选?股¨¦
        public string strNowStockMark = "ZX";
        public SelectStockMarkEvent claselectStockMarkEvent = null;

        public static readonly object lockObject = new object();
        public static readonly object lockDViewObject = new object();
        //public static Hashtable hashHangQingShuJu = System.Collections.Hashtable.Synchronized(new Hashtable());//key:stkLable,Value:HangQingStruct


        public static TStringList tStringListZiXuanGu = new TStringList();//自Á?选?股¨¦代䨲码?列¢D表À¨ª
        public static String strZiXuanGuPath = "\\GPLIST.INI";



        public DateTime Yesterday = DateTime.Now.AddDays(-7);
        public static DateTime dateLastStockWorking = DateTime.MinValue;



        GPINFO CurStockInfo;

        Flash FlashWindow = null;
        public static Jken JkenWindow = null;

        public MainStock()
        {
            Control.CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
            GpCount = 0;
            GCode = "000000";
            GName = "";
            GMark = 0;
            GType = "1";
            Titile.Text = "自Á?选?股¨¦";
            //初?始º?化¡¥行D情¨¦表À¨ª
            initDView();
            
            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);
            }

            claselectStockMarkEvent = new SelectStockMarkEvent(this);
            启?动¡¥接¨®收º?数ºy据Y,ê?设¦¨¨置?连¢?接¨®状Á¡ä态¬?为a已°?连¢?接¨®
            connectStateChange();

            //读¨¢取¨?自Á?选?股¨¦列¢D表À¨ª
            strZiXuanGuPath = Directory.GetCurrentDirectory() + strZiXuanGuPath;
            if (File.Exists(strZiXuanGuPath))
            {
                tStringListZiXuanGu.LoadFromFile(strZiXuanGuPath);
            }

            Block.BlockUtils.init();

        }

        private void initDView()
        {
            
            if(dt!=null){
                dt.Clear();
            }
            dView.DataSource = null;
            listSW.Clear();
            ColumnTechList.Clear();
            hidingcolumns.Clear();
            showingcolumns.Clear();
            //horse 读¨¢取¨?表À¨ª列¢D
            IniFile ini = new IniFile(Directory.GetCurrentDirectory() + "\\Stock.ini");
            String columns = ini.IniReadValue("Main", "MainColumnNames");
            String techColumns = ini.IniReadValue("Main", "MainTechColumnNames");
            String[] tech = null;
            foreach (String ss in this.columnNames)
            {
                if (ss == "TECHS")//如¨?果?为a公?式º?列¢D,ê?将?公?式º?列¢D加¨®入¨?到Ì?Column中D
                {
                    if (techColumns.Length > 2)
                    {
                        tech = techColumns.Replace(" ", "").Split(',');
                        foreach (String t in tech)
                        {
                            if (t.Length > 0)
                            {
                                listSW.Add("t" + t);
                                Demo1.Jken.jkfunc func = TechUtils.getJkFunc(t.Substring(0, t.IndexOf("-")), t.Substring(t.IndexOf("-") + 1));
                                if (func != null)
                                {
                                    ColumnTechList.Add(func);
                                }
                            }
                        }
                    }
                }
                else
                {
                    listSW.Add(ss);
                }
            }
            if (columns.Length > 0)
            {
                this.sw = columns.Replace(" ", "").Split(',');//sw中D存ä?储ä¡é的Ì?是º?要°a显?示º?的Ì?列¢D

            }
            else
            {
                MessageBox.Show("创ä¡ä建¡§行D情¨¦表À¨ª失º¡ì败㨹...");
                return;
            }

            dt = MakeTable();
            dv = new DataView(dt);
            dView.DataSource = dv;
            for (int i = 0; i < dView.ColumnCount; i++)
            {
                dView.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
            }

            dView.Columns["名?称?"].Frozen = true;
            String s;
            for (int i = 0; i < listSW.Count; i++)
            {
                s = listSW[i].Substring(1);
                if (listSW[i].StartsWith("t"))
                {
                    dView.Columns[s].Visible = true;
                    dView.Columns[s].MinimumWidth = 70;
                    dView.Columns[s].Width = 80;
                    dView.Columns[s].HeaderText = s;
                    dView.Columns[s].DefaultCellStyle.Format = "F2";
                }
                else
                {
                    dView.Columns[s].Visible = false;
                    dView.Columns[s].Width = 70;
                    dView.Columns[s].MinimumWidth = 70;
                    if(s=="涨?速¨´"){
                        dView.Columns[s].ContextMenuStrip = this.zsMenuStrip;
                        dView.Columns[s].HeaderText = "涨?速¨´(" + intZhangFuMins + ")";
                    }
                    if(s=="标À¨º记?"){
                        dView.Columns[s].MinimumWidth = 10;
                    }
                    if (dt.Columns[s].DataType == System.Type.GetType("System.Double"))
                    {
                        dView.Columns[s].DefaultCellStyle.Format = "F2";
                    }
                    else if (dt.Columns[s].DataType == System.Type.GetType("System.Int32"))
                    {
                        dView.Columns[s].DefaultCellStyle.Format = "F0";
                    }

                    if (s == "序¨°号?" || s == "code" || s == "拼¡ä音°?" || s == "自Á?选?" || s == "前¡ã涨?幅¤¨´" || s == "索¡Â引°y"||s=="标À¨º记?值¦Ì")
                    {

                    }
                    else
                    {
                        hidingcolumns.Add(s);
                    }
                }
            }
            dView.Columns["序¨°号?"].DefaultCellStyle.Format = "F0";
            dView.Columns["序¨°号?"].Width = 50;
            dView.Columns["代䨲码?"].Width = 60;
            dView.Columns["名?称?"].Width = 110;
            dView.Columns["行D业°¦Ì板ã?块¨¦"].Width = 110;
            dView.Columns["标À¨º记?"].Width = 10;
            dView.Columns["标À¨º记?"].HeaderText = "●?";

            for (int i = 0; i < sw.Length; i++)
            {
                if (dView.Columns[sw[i]] != null)
                {
                    dView.Columns[sw[i]].Visible = true;
                    hidingcolumns.Remove(sw[i]);
                    showingcolumns.Add(sw[i]);
                }
            }

            dView.GridColor = Color.FromArgb(128, 128, 128);//字Á?段?网ª?格?边À?框¨°  
            dView.EnableHeadersVisualStyles = false;
            dView.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
            dView.ColumnHeadersDefaultCellStyle.BackColor = Color.Black;
            dView.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
;
            dView.RowHeadersDefaultCellStyle.ForeColor = Color.White;
            dView.RowHeadersDefaultCellStyle.BackColor = Color.Black;
            dView.Columns["名?称?"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;

            //默?认¨?为a自Á?选?股¨¦界?面?
            if (strNowStockMark == "ZX")
            {
                dv.RowFilter = "自Á?选?>=0";
                dv.Sort = "自Á?选? asc";
            }
            else if (strNowStockMark == "ZJQH")
            {
                dView.Columns["持?仓?"].Visible = true;
                dView.Columns["总Á¨¹额?"].Visible = false;
                dv.RowFilter = "市ºD场?='ZJ'";
                dv.Sort = "code asc";
            }
            else if (strNowStockMark == "ZZQH")
            {
                dView.Columns["持?仓?"].Visible = true;
                dView.Columns["总Á¨¹额?"].Visible = false;
                dv.RowFilter = "市ºD场?='ZZ'";
                dv.Sort = "code asc";
            }
            else if (strNowStockMark == "DLQH")
            {
                dView.Columns["持?仓?"].Visible = true;
                dView.Columns["总Á¨¹额?"].Visible = false;
                dv.RowFilter = "市ºD场?='DL'";
                dv.Sort = "code asc";
            }
            else if (strNowStockMark == "SHQH")
            {
                dView.Columns["持?仓?"].Visible = true;
                dView.Columns["总Á¨¹额?"].Visible = false;
                dv.RowFilter = "市ºD场?='SQ' or 市ºD场?='SE' or 市ºD场?='SY'";
                dv.Sort = "code asc";
            }
            else if (strNowStockMark == "SHAG")
            {
                dView.Columns["持?仓?"].Visible = false;
                dView.Columns["总Á¨¹额?"].Visible = true;
                dv.RowFilter = "市ºD场?='SH' and not(code='000001')";
                dv.Sort = "code asc";
            }
            else if (strNowStockMark == "SZAG")
            {
                dView.Columns["持?仓?"].Visible = false;
                dView.Columns["总Á¨¹额?"].Visible = true;
                dv.RowFilter = "市ºD场?='SZ' and not(code='399001')";
                dv.Sort = "code asc";
            }
            else if (strNowStockMark == "HK")
            {
                dView.Columns["持?仓?"].Visible = false;
                dView.Columns["总Á¨¹额?"].Visible = true;
                dv.RowFilter = "市ºD场?='HK'";
                dv.Sort = "code asc";
            }
            else if (strNowStockMark == "SHSZAG")
            {
                dView.Columns["持?仓?"].Visible = false;
                dView.Columns["总Á¨¹额?"].Visible = true;
                dv.RowFilter = "(市ºD场?='SH' and not(code='000001')) or (市ºD场?='SZ' and not(code='399001'))";
                dv.Sort = "code asc";
            }
            else
            {
                dv.RowFilter = "自Á?选?>=0";
                dv.Sort = "自Á?选? asc";
                dView.Columns["持?仓?"].Visible = true;
                dView.Columns["总Á¨¹额?"].Visible = true;
                this.Titile.Text = "自Á?选?股¨¦";
            }
        }


        /// <summary>
        /// byte数ºy组Á¨¦转Áa结¨¢构1体¬?
        /// </summary>
        /// <param name="bytes">byte数ºy组Á¨¦</param>
        /// <param name="offset">开a始º?转Áa换?的Ì?位?置?</param>
        /// <param name="type">结¨¢构1体¬?类¤¨¤型¨ª</param>
        /// <returns>转Áa换?后¨®的Ì?结¨¢构1体¬?</returns>
        public static object BytesToStruct(byte[] bytes, int offset, Type type)
        {

            //得Ì?到Ì?结¨¢构1体¬?的Ì?大䨮小?
            int size = Marshal.SizeOf(type);
            //byte数ºy组Á¨¦长¡è度¨¨小?于®¨²结¨¢构1体¬?的Ì?大䨮小?
            if (size > (bytes.Length - offset))
            {
                //返¤¦Ì回?空?
                return null;
            }
            //分¤?配?结¨¢构1体¬?大䨮小?的Ì?内¨²存ä?空?间?
            IntPtr structPtr = Marshal.AllocHGlobal(size);
            //将?byte数ºy组Á¨¦拷?到Ì?分¤?配?好?的Ì?内¨²存ä?空?间?
            try
            {
                // 将?字Á?节¨²数ºy组Á¨¦复¡ä制?到Ì?结¨¢构1体¬?指?针?
                Marshal.Copy(bytes, offset, structPtr, size);
            }
            catch (Exception ex)
            {
                LogHelper.Write("ByteArrayToStructure FAIL: error " + ex.ToString());
            }
            //将?内¨²存ä?空?间?转Áa换?为a目?标À¨º结¨¢构1体¬?
            object obj1 = Marshal.PtrToStructure(structPtr, type);
            //释º¨ª放¤?内¨²存ä?空?间?
            Marshal.FreeHGlobal(structPtr);
            //返¤¦Ì回?结¨¢构1体¬?
            return obj1;
        }
        public static byte[] StructToBytes(object structObj)
        {
            //得Ì?到Ì?结¨¢构1体¬?的Ì?大䨮小?
            int size = Marshal.SizeOf(structObj);
            //创ä¡ä建¡§byte数ºy组Á¨¦
            byte[] bytes = new byte[size];
            //分¤?配?结¨¢构1体¬?大䨮小?的Ì?内¨²存ä?空?间?
            IntPtr structPtr = Marshal.AllocHGlobal(size);
            //将?结¨¢构1体¬?拷?到Ì?分¤?配?好?的Ì?内¨²存ä?空?间?
            Marshal.StructureToPtr(structObj, structPtr, false);
            //从䨮内¨²存ä?空?间?拷?到Ì?byte数ºy组Á¨¦
            Marshal.Copy(structPtr, bytes, 0, size);
            //释º¨ª放¤?内¨²存ä?空?间?
            Marshal.FreeHGlobal(structPtr);
            //返¤¦Ì回?byte数ºy组Á¨¦
            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;
            //hosre
            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);
            }

            string strPr10 = ini.IniReadValue("Main", "PR10");
            if (strPr10.ToLower() == "true")
            {
                Stock.PR10 = true;
            }
            else
            {
                Stock.PR10 = false;
            }


            if(User.LoginUser.marks.Contains("ALL")){
                //shagutoolStripButton.Visible = true;
                //szagutoolStripButton.Visible = true;
                //hsagutoolStripButton.Visible = true;
                //ganggtoolStripButton.Visible = true;
                shqh.Visible = true;
                dlqh.Visible = true;
                zzqh.Visible = true;
                gzqh.Visible = true;
            }else{
                if (User.LoginUser.marks.Contains("SH"))
                {
                    if (User.LoginUser.marks.Contains("SZ"))
                    {
                        hsagutoolStripButton.Visible = true;
                        shagutoolStripButton.Visible = true;
                        szagutoolStripButton.Visible = true;
                       
                    }
                    shagutoolStripButton.Visible = true;
                }
                if (User.LoginUser.marks.Contains("SZ"))
                {
                    szagutoolStripButton.Visible = true;
                }
                if (User.LoginUser.marks.Contains("HK"))
                {
                    ganggtoolStripButton.Visible = true;
                }
                if (User.LoginUser.marks.Contains("SQ"))
                {
                    shqh.Visible = true;
                } if (User.LoginUser.marks.Contains("DL"))
                {
                    dlqh.Visible = true;
                } if (User.LoginUser.marks.Contains("ZZ"))
                {
                    zzqh.Visible = true;
                } if (User.LoginUser.marks.Contains("ZJ"))
                {
                    gzqh.Visible = true;
                }
            }
           
            

            //连¢?接¨®服¤t务?端?
            clientsocket = new TcpClient();
            clientsocket.Connect(serveraddress, socketport);
            //clientsocket.ReceiveBufferSize = 8 * 1024;

            receive = new Thread(new ThreadStart(ReceiveData));
            receive.Start();

            Mintimer1.Interval = 60000;
            Mintimer1.Elapsed += new System.Timers.ElapsedEventHandler(this.Minute1DataTimer_Tick);

            DayTimer2.Interval = 60 * 60000;
            DayTimer2.Elapsed += new System.Timers.ElapsedEventHandler(this.DayTimer_Tick);


            Thread t = new Thread(new ThreadStart(RunningTimer));
            t.Start();


            //设¦¨¨置?自Á?选?股¨¦监¨¤控?
            string autorun = ini.IniReadValue("Main", "AutoRun");
            autorun = autorun.ToLower();
            if (autorun.Length > 0)
            {
                if (autorun == "true")
                {
                    if (JkenWindow == null || JkenWindow.IsDisposed)
                    {
                        JkenWindow = new Jken();
                        JkenWindow.MS = this;
                        JkenWindow.dt = dt;
                        this.Show();//为a了¢?加¨®载?load函¡¥数ºy
                        this.Hide();
                    }
                    JkenWindow.start_Click(null, null);//启?动¡¥监¨¤控?
                    JkenWindow.Focus();  //子Á¨®窗ä¡ã口¨²获?得Ì?焦1点Ì?
                }
            }


            //this.skinEngine1.SkinFile = string.Format("Skins/SteelBlack.ssk");
        }

        
        /// <summary>
        /// socket数ºy据Y接¨®收º?
        /// </summary>
        private void ReceiveData()
        {
            
            //if (User.UserInfo.username==null)
            //{
            //    keepalive = false;
            //    receive.Abort();
            //    return;
            //}

            FlashWindow.ShowString.Text = "正y在¨²初?始º?化¡¥数ºy据Y,请?稍¦?后¨®...";
            FlashWindow.JinDu.Value = 0;
            FlashWindow.JinDu.Minimum = 0;
            FlashWindow.JinDu.Maximum = 5600;
            FlashWindow.Show();

            string path = Directory.GetCurrentDirectory();
            FileStream fs=null;
            NetworkStream ns = clientsocket.GetStream();
            String message = "HangQing",pathDir="",filename="";
            Byte[] outbytes = new Byte[message.Length];
            for (int i = 0; i < message.Length; i++)
                outbytes[i] = (byte)message[i];
            ns.Write(outbytes, 0, outbytes.Length);
            keepalive = true;

            int bytesRead = 0;
            int len = 172;
            int flag = -1;
            byte[] flagBytes = new byte[4];
            byte[] lengthBytes = new byte[4];
            MyFileStream myfs = new MyFileStream();
            while (keepalive)
            {
                try
                {
                        bytesRead = ns.Read(flagBytes, 0, 4);
                        flag = BitConverter.ToInt32(flagBytes, 0);
                        if (flag == socket.SocketFlag.dataHangqing)//实º¦Ì时º¡À行D情¨¦数ºy据Y
                        {
                            if (FlashWindow != null && FlashWindow.JinDu.Value < FlashWindow.JinDu.Maximum)
                            {
                                FlashWindow.JinDu.Value++;
                            }
                            bytesRead = ns.Read(lengthBytes, 0, 4);
                            len = BitConverter.ToInt32(lengthBytes, 0);
                            byte[] responseBuffer = new byte[len];//行D情¨¦数ºy据Y是º?172个?字Á?节¨²
                            bytesRead = ns.Read(responseBuffer, 0, len);
                            StockStruct.StockStructs.HangQingStruct model = (StockStruct.StockStructs.HangQingStruct)BytesToStruct(responseBuffer, 0, typeof(StockStruct.StockStructs.HangQingStruct));
                            if(model.stkLabel.Length<3){
                                continue;
                            }
                            if (model.time != 0 && model.Date <= DateTime.Now.Date)
                            {
                                if (dateLastStockWorking.Date < model.Date)
                                {
                                    dateLastStockWorking = model.Time;
                                }
                            }
                            DataCache.AddOrUpdateHangQing(model.stkLabel,model);
                            ReceiveDataEvent.Execute(this, model);
                        }
                        else if (flag == socket.SocketFlag.endSentFlag)
                        {
                            //MessageBox.Show("数ºy据Y发¤¡é送¨ª完ª¨º毕À?!ê?");
                            if (FlashWindow != null && FlashWindow.Visible)
                            {
                                FlashWindow.JinDu.Value = FlashWindow.JinDu.Maximum; FlashWindow.Hide(); FlashWindow.Dispose(); FlashWindow = null; Stock.Focus();
                            }
                            TechUtils.init(this);
                            Thread calcThread = new Thread(new ThreadStart(runTechCalc));
                            calcThread.Start();
                        }
                        else if (flag == socket.SocketFlag.startSentFlag)//开a始º?标À¨º识º?
                        {
                            pathDir = path + "\\Data\\Temp";

                        }
                        else if (flag == socket.SocketFlag.dataZqFs)//分¤?时º¡À临¢¨´时º¡À数ºy据Y
                        {
                            
                            bytesRead = ns.Read(lengthBytes, 0, 4);
                            len = BitConverter.ToInt32(lengthBytes, 0);
                            byte[] responseBuffer = new byte[len];

                            int fcur = 0;
                            while (fcur < len)
                            {
                                bytesRead = ns.Read(responseBuffer, fcur, (len - fcur) > 2048 ? 2048 : len - fcur);
                                if (bytesRead > 0)
                                {
                                    fcur += bytesRead;
                                }
                            }
                            StockStructs.HistoryStruct44 s = (StockStructs.HistoryStruct44)DataService.Structs.BytesToStuct(responseBuffer, 0, typeof(StockStructs.HistoryStruct44));
                            
                            if (s.stkLabel.Length > 2)
                            {
                                pathDir = path + "\\Data\\Temp\\" + s.stkLabel.Substring(0, 2).ToUpper() + "\\Min1";
                            }
                            else
                            {
                                continue;
                            }
                            if (!Directory.Exists(pathDir))
                            {
                                Directory.CreateDirectory(pathDir);
                            }
                            filename = pathDir + "\\" + s.stkLabel + ".dat";
                            fs = myfs.GetFileStream(filename, FileMode.Create);
                            fs.Write(responseBuffer, 0, responseBuffer.Length);
                            fs.Close();
                            fs = null;
                            filename = null;
                            pathDir = null;
                        }
                        else if (flag == socket.SocketFlag.msg1)//推ª?荐?股¨¦票¡À信?号?
                        {
                            bytesRead = ns.Read(lengthBytes, 0, 4);
                            len = BitConverter.ToInt32(lengthBytes, 0);
                            byte[] responseBuffer = new byte[len];
                            bytesRead = ns.Read(responseBuffer, 0, len);
                            string xinhao = System.Text.Encoding.Default.GetString(responseBuffer);
                            int index = xinhao.IndexOf('‖?');
                            if(index>0){
                                string s = xinhao.Substring(0,index).ToUpper().Trim();
                                lock(DataCache.hashXinhao.SyncRoot){
                                    if (DataCache.hashXinhao.ContainsKey(s))
                                    {
                                        ((List<string>)DataCache.hashXinhao[s]).Add(xinhao);
                                    }
                                    else
                                    {
                                        List<string> list = new List<string>();
                                        list.Add(xinhao);
                                        DataCache.hashXinhao.Add(s, list);
                                    }
                                }
                                今?日¨?推ª?荐?toolStripButton.Text = "今?日¨?推ª?荐?(*)";
                                今?日¨?推ª?荐?toolStripButton.ForeColor = Color.Red;
                                //MsgForm.Coming(s+" 来¤¡ä信?号?了¢?,ê?请?注Á¡é意°a查¨¦看¡ä...");
                            }
                           

                        }
                        else
                        {
                            bytesRead = ns.Read(lengthBytes, 0, 4);
                            len = BitConverter.ToInt32(lengthBytes, 0);
                            try
                            {
                                if (len < 0)
                                {
                                    continue;
                                }
                                byte[] responseBuffer = new byte[len];
                                bytesRead = ns.Read(responseBuffer, 0, len);
                            }
                            catch (Exception ex)
                            {
                                continue;
                            }
                        }
                       
                    


                }
                catch (Exception e) { 
                    //LogHelper.Write("接¨®收º?行D情¨¦数ºy据Y出?错䨪!ê?" + e.StackTrace + "  Length:" + len); 
                }
            }
        }

      
       
        public int gptime(int v)
        {
            int j = v + 9 * 60 + 30;
            j = v + ClassStockModel.getOpenTimeAddMinute(strMark);
            if(Stock.marktype==MarkType.MarkA){
                if (v > 120)//MarkA:09:30-11:30 13:00-15:00
                    j = j + 90;
            }
            else if (Stock.marktype == MarkType.MarkHK)
            {
                if (v > 150)//MarkHK:09:30-12:00 13:00-16:00
                    j = j + 60;
            }
            else if (Stock.marktype == MarkType.MarkGuZhi)
            {
                if (v > 135)//MarkGuZhi:êo9:15-11:30  13:00-15:15
                    j = j + 90;
            }
            else if (Stock.marktype == MarkType.MarkShangHai)//21:00-02:30,09:00-11:30,13:30-15:00 
            {
                if (v > 330)
                    j = j + 6 * 60 + 30;
                if (v > 480)//9:00-11:30 13:30-15:00
                    j = j + 120;
            }
            else//09:00-11:30 13:30-15:00
            {
                if (v > 150)
                    j = j + 120;
            }
           
            int h = j / 60;
            if (h >= 24)
            {
                h = h%24;
            }
            int m = j % 60;
            return h * 100 + m;
        }

        private void 断?开a服¤t务?器¡ÂToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                //注Á¡é销¨²服¤t务?器¡Â上¦?登Ì?陆?
                string url = "http://" + serveraddress + ":" + serverport + "/Logout/username=" + User.LoginUser.username;
                Service.GetWebServiceContent(url);
                keepalive = false;
                if (clientsocket != null)
                {
                    clientsocket.Close();
                }
                if (receive != null && receive.IsAlive)
                {
                    receive.Abort();
                }

            }
            catch (Exception e2)
            {
                LogHelper.Write("断?开a服¤t务?器¡Â出?错䨪" + e2.ToString());
            }
            connectStateChange();
            
        }
        private void test_FormClosed(object sender, FormClosedEventArgs e)
        {
            try
            {
                //注Á¡é销¨²服¤t务?器¡Â上¦?登Ì?陆?
                string url = "http://" + serveraddress + ":" + serverport + "/Logout/username=" + User.LoginUser.username;
                Service.GetWebServiceContent(url);
                keepalive = false;
                TechUtils.keepalive = false;
                Thread.Sleep(200);
                if(clientsocket!=null){
                    clientsocket.Close();
                }
                if (receive != null && receive.IsAlive)
                {
                    receive.Abort();
                }
                
            }
            catch (Exception e2)
            {
                LogHelper.Write("注Á¡é销¨²出?错䨪" + e2.ToString());
            }
            if (!(JkenWindow == null || JkenWindow.IsDisposed))
            {
                JkenWindow.keepalive = false;
                JkenWindow.Close();
                JkenWindow.Dispose();
            }
            Mintimer1.Enabled = false;
            DayTimer2.Enabled = false;
        }
        private void 退ª?出?ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string url = "http://" + serveraddress + ":" + serverport + "/Logout/username=" + User.LoginUser.username;
            Service.GetWebServiceContent(url);
            this.Close();
        }
        private DataTable MakeTable()
        {
            System.Data.DataTable myDataTable = new DataTable("本À?地Ì?数ºy据Y表À¨ª");
            DataColumn myDataColumn;

            for (int i = 0; i <this.listSW.Count; i++)
            {
                myDataColumn = new DataColumn();
                string s1 = listSW[i];
                string n1 = s1.Substring(1);
                if (s1[0] == 'd')
                    myDataColumn.DataType = System.Type.GetType("System.Double");
                if (s1[0] == 's')
                    myDataColumn.DataType = System.Type.GetType("System.String");
                if (s1[0] == 'i')
                    myDataColumn.DataType = System.Type.GetType("System.Int32");
                if (s1[0] == 't')
                {
                    myDataColumn.DataType = System.Type.GetType("System.Double");
                }
                myDataColumn.ColumnName = n1;
                myDataTable.Columns.Add(myDataColumn);
            }
            DataColumn[] dcs = { myDataTable.Columns["索¡Â引°y"], myDataTable.Columns["code"], myDataTable.Columns["拼¡ä音°?"], myDataTable.Columns["行D业°¦Ì板ã?块¨¦"] };
            myDataTable.PrimaryKey = dcs;
            return myDataTable;
        }
        private void 电Ì?信?服¤t务?器¡Â一°?ToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            dt.Clear();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            dv.RowFilter = "类¤¨¤型¨ª=0";
        }
        //报À¡§价?分¤?析?
        private void TB1_Click(object sender, EventArgs e)
        {
            if (!Board.Visible)
            {
                Board.Visible = true;
                gpinfo.Visible = false;
                GPSTOCK.Visible = false;
            }
            dView.Focus();
        }
        //即¡ä时º¡À分¤?析?
        private void TB2_Click(object sender, EventArgs e)
        {
            if (!GPSTOCK.Visible)
            {
                Board.Visible = false;
                gpinfo.Visible = false;
                GPSTOCK.Visible = true;
                dView_DoubleClick(null, null);
            }
            Stock.Focus();
            if (!Stock.ShowFs)
                Stock.ShowFs = true;

        }
        //技?术º?分¤?析?
        public void TB3_Click(object sender, EventArgs e)
        {
            if (!GPSTOCK.Visible)
            {
                GPSTOCK.Visible = true;
                Board.Visible = false;
                gpinfo.Visible = false;
                dView_DoubleClick(null, null);
            }
            Stock.Focus();
            if (Stock.ShowFs)
                Stock.ShowFs = false;
        }

        //公?司?资Á¨º料¢?Menu响¨¬应®|函¡¥数ºy
        private void TB5_Click(object sender, EventArgs e)
        {
            //if (Board.Visible)
            //{
            //    DataGridViewCell dg = dView.CurrentCell;
            //    int id = dg.RowIndex;
            //    GCode = (string)dView.Rows[id].Cells["code"].Value;
            //    GName = (string)dView.Rows[id].Cells["名?称?"].Value;
            //    GMark = (String)dView.Rows[id].Cells["市ºD场?"].Value;
            //    GType = (String)dView.Rows[id].Cells["类¤¨¤型¨ª"].Value;
            //}
            //if (!gpinfo.Visible)
            //{
            //    GPSTOCK.Visible = false;
            //    Board.Visible = false;
            //    gpinfo.Visible = true;
            //}
            //if (clientsocket != null)
            //    GetInfo(GCode, GMark, GType);
            MessageBox.Show("该?功|能¨¹尚¦D未¡ä添¬¨ª加¨®!");
        }
        private void gpinfo_Resize(object sender, EventArgs e)
        {
            int ww = (gpinfo.Width - 84 * 8) / 2;
            panel3.Padding = new Padding(ww, panel3.Padding.Top, ww, panel3.Padding.Bottom);
            panel4.Padding = new Padding(ww, panel3.Padding.Top, ww, panel3.Padding.Bottom);
        }
        private void GetInfo(String code, int mark, int type)
        {
            
        }
        private void button4_Click(object sender, EventArgs e)
        {
            GetInfo(GCode, 0, 1);
        }
        private void bt1_Click(object sender, EventArgs e)
        {
            
        }


        // private String[] WeekString = { "日¨?线?", "周¨¹线?", "月?线?", "5分¤?钟¨®线?", "15分¤?钟¨®线?", "30分¤?钟¨®线?", "60分¤?钟¨®线?", "120分¤?钟¨®线?", "分¤?笔À¨º线?", "1分¤?钟¨®线?" };
        MyFileStream myfs = new MyFileStream();
        ZQDataService zqservice = new ZQDataService();
        public void GetStockinfo(String Code, string strMark, String type, int zq)
        {
            if(strMark=="SH"){
                Stock.marktype = MarkType.MarkA;
                this.Titile.Text = "上¦?证¡èA股¨¦ - "+GName;
            }
            else if (strMark == "SZ")
            {
                Stock.marktype = MarkType.MarkA;
                this.Titile.Text = "深¦?证¡èA股¨¦ - " + GName;
            }
            else if (strMark == "HK")
            {
                Stock.marktype = MarkType.MarkHK;
                this.Titile.Text = "香?港?股¨¦票¡À - " + GName;
            }
            else if (strMark == "ZJ")
            {
                Stock.marktype = MarkType.MarkGuZhi;
                this.Titile.Text = "股¨¦指?期¨²货? - " + GName;
            }
            else if (strMark == "SQ")
            {
                Stock.marktype = MarkType.MarkZhengZhoung;
                this.Titile.Text = "上¦?海¡ê商¦¨¬品¡¤ - " + GName;
            }
            else if (strMark == "SE")
            {
                Stock.marktype = MarkType.MarkShangHai;//目?前¡ã上¦?海¡ê白ã¡Á银°?和¨ª黄?金e不?支¡ì持?夜°1盘¨¬
                this.Titile.Text = "上¦?海¡ê商¦¨¬品¡¤ - " + GName;
            }
            else if (strMark == "SY")
            {
                Stock.marktype = MarkType.MarkShangHai;//目?前¡ã上¦?海¡ê白ã¡Á银°?和¨ª黄?金e不?支¡ì持?夜°1盘¨¬
                this.Titile.Text = "上¦?海¡ê商¦¨¬品¡¤ - " + GName;
            }
            else if (strMark == "ZZ")
            {
                Stock.marktype = MarkType.MarkZhengZhoung;
                this.Titile.Text = "郑¡ê州Y商¦¨¬品¡¤ - " + GName;
            }
            else if (strMark == "DL")
            {
                Stock.marktype = MarkType.MarkZhengZhoung;
                this.Titile.Text = "大䨮连¢?商¦¨¬品¡¤ - " + GName;
            }
            else
            {
                Stock.marktype = MarkType.MarkZhengZhoung;
            }
            if(this.strNowStockMark=="ZX"){
                this.Titile.Text = "自Á?选?股¨¦ - " + GName;
            }
            Stock.cleardata();
            Stock.StkCode = strMark + Code;

            

            List<StockStructs.HistoryStruct44> klist = zqservice.getDataByZQTime(strMark + Code,zq);
            UpdateHistoryData.InitStockHistoryData(this, klist);
            //if(klist.Count==0){
            //    MessageBox.Show("没?有®D查¨¦找¨°到Ì?历¤¨²史º¡¤数ºy据Y,ê?请?先¨¨下?载?再¨´查¨¦看¡ä!ê?", "提¬¨¢示º?", MessageBoxButtons.OK, MessageBoxIcon.Information);
                
            //}
            List<StockStructs.HistoryStruct44> fslist = zqservice.getDataByZQTime(strMark + Code, socket.SocketFlag.dataZqFs);
            
            UpdateHistoryData.InitStockFSData(this, fslist);


            if (DataCache.hashHangQingShuJu.ContainsKey(strMark + Code))
            {
                StockStruct.StockStructs.HangQingStruct dat = (StockStruct.StockStructs.HangQingStruct)DataCache.hashHangQingShuJu[strMark + Code];
                UpdateHistoryData.UpdateKAndFsAndInfo(this,dat);
                if (fslist.Count == 0&&dat.close!=0)
                {
                    MessageBox.Show("分¤?时º¡À数ºy据Y正y在¨²缓o冲?,ê?请?稍¦?后¨®再¨´试º?,ê?如¨?果?尝¡é试º?多¨¤次ä?失º¡ì败㨹,ê?请?重?启?软¨¨ª件t稍¦?等̨¨一°?会¨¢儿¨´!ê?", "提¬¨¢示º?", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
           
        }


        /// <summary>
        /// 取¨?得Ì?股¨¦票¡À历¤¨²史º¡¤数ºy据Y
        /// </summary>
        /// <param name="Code">代䨲码?</param>
        /// <param name="mark">市ºD场?</param>
        /// <param name="type">类¤¨¤型¨ª</param> 
        /// <param name="zq">周¨¹期¨²</param>
        /// zq(1=日¨? 2=周¨¹ 3=月? 4=5分¤?钟¨® 5=15  6=30 7=60 8=120分¤?钟¨® 9=分¤?笔À¨º 10=1分¤?钟¨®
        public void GetStockinfo(String Code, int mark, String type, int zq)
        {
           

        }

        private void button5_Click(object sender, EventArgs e)
        {
            GetStockinfo(GCode, strMark, GType, 1);
        }
        private void TypeClick_Click(object sender, EventArgs e)
        {
            
        }

        private void SzClick(object sender, EventArgs e)
        {
            
        }



       

        private void dView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {

            using (SolidBrush b = new SolidBrush(dView.RowHeadersDefaultCellStyle.ForeColor))
            {
                e.Graphics.DrawString((Convert.ToInt32(e.RowIndex) + 1).ToString(System.Globalization.CultureInfo.CurrentCulture), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 12, e.RowBounds.Location.Y + 4);
            }

        }

        private void tStock1_DoubleClick(object sender, EventArgs e)
        {
            Stock.ShowFs = Stock.ShowFs ^ true;
        }

        private void dView_DoubleClick(object sender, EventArgs e)
        {
            DataGridViewCell dg = dView.CurrentCell;
            int id = dg.RowIndex;
            GCode = (string)dView.Rows[id].Cells["code"].Value;
            
            GName = (string)dView.Rows[id].Cells["名?称?"].Value;
            GPreclose = (double)dView.Rows[id].Cells["昨Á¨°收º?"].Value;
            GOpen = (double)dView.Rows[id].Cells["今?开a"].Value;
            strMark =(string)dView.Rows[id].Cells["市ºD场?"].Value;
            GType = (String)dView.Rows[id].Cells["类¤¨¤型¨ª"].Value;

            if (!GPSTOCK.Visible)
            {
                gpinfo.Visible = false;
                Board.Visible = false;
                GPSTOCK.Visible = true;
            }
            Stock.Focus();
            
            GetStockinfo(GCode, strMark, GType, GZq);//新?建¡§函¡¥数ºy
        }

        private void Link2(object sender, EventArgs e)
        {
            if (clientsocket == null)
            {
                dt.Clear();
            }

        }
        

        private void panel6_Click(object sender, EventArgs e)
        {
            GpKey.Visible = false;
            this.KeyPreview = true;
        }

        private void test_KeyPress(object sender, KeyPressEventArgs e)
        {
            int key = e.KeyChar;
            String ks = e.KeyChar.ToString();
            ks = ks.ToUpper();
            if (((key >= '0') && (key <= '9')) || ((key >= 'A') && (key <= 'Z')) || ((key >= 'a') && (key <= 'z')))
            {
                this.KeyPreview = false;
                int h = 0;
                if (sb1.Visible)
                    h = sb1.Height;
                GpKey.SetBounds(this.ClientRectangle.Width - GpKey.Width - 3, this.ClientRectangle.Height - GpKey.Height - h, GpKey.Width, GpKey.Height);
                GpKey.Visible = true;
                KeyCode.Text = ks;
                KeyCode.Focus();
                KeyCode.SelectionStart = 1;
                KeyCode.SelectionLength = 0;
            }
            if ((e.KeyChar == 27) && (!Board.Visible))
            {
                TB1_Click(sender, null);
            }

        }

        /// <summary>
        /// 按ã¡ä键¨¹精?灵¢¨¦键¨¹盘¨¬事º?件t
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void KeyCode_TextChanged(object sender, EventArgs e)
        {
            String s1 = KeyCode.Text.ToUpper();
            if (KeyCode.Text.Length == 0)
            {
                this.KeyPreview = true;
                GpKey.Visible = false;
                return;
            }
            KeyCode.Text = KeyCode.Text.ToUpper();
            KeyCode.SelectionStart = KeyCode.Text.Length;
            KeyCode.SelectionLength = 0;
            GpListBox.Items.Clear();
            if ((s1[0] >= '0') && (s1[0] <= '9'))
            {
                DataRow[] dr = dt.Select("code like '%" + s1 + "%'");
                for (int i = 0; i < dr.Length; i++)
                {
                    string code = (string)dr[i]["代䨲码?"];
                    String s2 = code.Replace('\0', ' ') + " " + (string)dr[i]["名?称?"];
                    GpListBox.Items.Add(s2);
                }

            }
            if ((s1[0] >= 'A') && (s1[0] <= 'Z'))
            {
                DataRow[] dr = dt.Select("拼¡ä音°? like '%" + s1 + "%'");
                if (dr.Length > 0)
                {
                    for (int i = 0; i < dr.Length; i++)
                    {
                        String s2 = (string)dr[i]["拼¡ä音°?"] + " " + (string)dr[i]["名?称?"];
                        GpListBox.Items.Add(s2);
                    }
                }

                DataRow[] dr1 = dt.Select("code like '%" + s1 + "%'");
                for (int i = 0; i < dr1.Length; i++)
                {
                    string code = (string)dr1[i]["代䨲码?"];
                    string ss = code.Replace('\0', ' ');
                    String s2 = ss + " " + (string)dr1[i]["名?称?"];
                    GpListBox.Items.Add(s2);
                }

            }
            if (GpListBox.Items.Count > 0)
                GpListBox.SelectedIndex = 0;

        }
        /// <summary>
        /// 按ã¡ä键¨¹精?灵¢¨¦键¨¹盘¨¬事º?件t
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void KeyCode_KeyDown(object sender, KeyEventArgs e)
        {
            Keys kv = e.KeyCode;// e.KeyValue;

            if (kv == Keys.Escape)
            {
                this.KeyPreview = true;
                GpKey.Visible = false;
                dView.Focus();
                
            }
            if (kv == Keys.Enter)
            {
                GpKey.Visible = false;
                this.KeyPreview = true;
                GPDouble(sender, null);
            }
        }

        private void GPDouble(object sender, EventArgs e)
        {
            int fh = GpListBox.SelectedIndex;
            if (fh == -1)
                return;
            String s = (string)GpListBox.SelectedItem;
            String[] s1 = s.Split(' ');
            DataRow[] dr = dt.Select("名?称?='" + s1[1] + "'");
            if (dr.Length > 0)
            {
                gpinfo.Visible = false;
                Board.Visible = false;
                GPSTOCK.Visible = true;
                Stock.Focus();

                GCode = (string)dr[0]["code"];
                GName = (string)dr[0]["名?称?"];
                GPreclose = (double)dr[0]["昨Á¨°收º?"];
                GOpen = (double)dr[0]["今?开a"];
                strMark = (string)dr[0]["市ºD场?"];
                GType = (String)dr[0]["类¤¨¤型¨ª"];
                //MessageBox.Show("GCode:"+GCode+",Gname:"+GName+",Gopen"+GOpen+",Strmark:"+strMark+",Gtype:"+GType);

                GetStockinfo(GCode, strMark, GType, GZq);

                GpKey.Visible = false;
                this.KeyPreview = true;
            }

        }

        private void LoadWfc_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem mi = (ToolStripMenuItem)sender;
            if (Stock.curgs != null)
                Stock.curgs.LoadWfc(mi.Text);
        }

        private void LoadWfc2_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem mi = (ToolStripMenuItem)sender;
            if (Stock.curgs != null)
                Stock.curgs.LoadWfc(mi.ToolTipText);
        }

        private void ZhouQi_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem mi = (ToolStripMenuItem)sender;
            String tag = (String)mi.Tag;
            int zq = Convert.ToInt32(tag);
            GZq = zq;
            Stock.cleardata();
            GetStockinfo(GCode, strMark, GType, GZq);
            if (!GPSTOCK.Visible)
            {
                gpinfo.Visible = false;
                Board.Visible = false;
                GPSTOCK.Visible = true;
            }
            Stock.Focus();
            if (Stock.ShowFs)
                Stock.ShowFs = false;
        }

        private void TB6_Click(object sender, EventArgs e)
        {
            ToolStripButton sb = (ToolStripButton)sender;
            String tag = (String)sb.Tag;
            int zq = Convert.ToInt32(tag);
            Stock.K_cleardata();
            GZq = zq;
            Stock.cleardata();
            GetStockinfo(GCode, strMark, GType, GZq);
            if (GPSTOCK.Visible == false)
            {
                gpinfo.Visible = false;
                Board.Visible = false;
                GPSTOCK.Visible = true;
            }
            Stock.Focus();
            if (Stock.ShowFs)
                Stock.ShowFs = false;
        }

        private void TechW_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem mi = (ToolStripMenuItem)sender;
            String tag = (String)mi.Tag;
            int tw = Convert.ToInt32(tag);
            Stock.TechWindows = tw;
            if (GPSTOCK.Visible == false)
            {
                gpinfo.Visible = false;
                Board.Visible = false;
                GPSTOCK.Visible = true;
            }
            Stock.Focus();
            if (Stock.ShowFs)
                Stock.ShowFs = false;

        }

        private void CmdClick(object sender, EventArgs e)
        {
            ToolStripMenuItem mi = (ToolStripMenuItem)sender;
            Stock.Command(mi.Text);
        }

        private void dView_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                dView_DoubleClick(sender, null);
            if ((e.KeyCode == Keys.F5) && (Board.Visible))
            {
                DataGridViewCell dg = dView.CurrentCell;
                if (dg != null)
                {
                    int id = dg.RowIndex;

                    GCode = (string)dView.Rows[id].Cells["code"].Value;
                    GName = (string)dView.Rows[id].Cells["名?称?"].Value;
                    GPreclose = (double)dView.Rows[id].Cells["昨Á¨°收º?"].Value;
                    GOpen = (double)dView.Rows[id].Cells["今?开a"].Value;
                    strMark = (string)dView.Rows[id].Cells["市ºD场?"].Value;
                    GType = (String)dView.Rows[id].Cells["类¤¨¤型¨ª"].Value;

                    Stock.cleardata();
                    if (!GPSTOCK.Visible)
                    {
                        gpinfo.Visible = false;
                        Board.Visible = false;
                        GPSTOCK.Visible = true;
                    }
                    Stock.Focus();
                    Stock.ShowFs = true;
                    GetStockinfo(GCode, strMark, GType, GZq);
                }
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            DiLei.Visible = false;
            DL_SP.Visible = DiLei.Visible;
            m_dilei.Checked = DiLei.Visible;
        }

        /// <summary>
        /// 信?息¡é地Ì?雷¤¡Á响¨¬应®|函¡¥数ºy
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void m_dilei_Click(object sender, EventArgs e)
        {
            MessageBox.Show("该?功|能¨¹尚¦D未¡ä添¬¨ª加¨®!ê?");
           
        }

        private void Stock_DiLeiClicked(object sender, int DiLeiNo)
        {
            if (!DiLei.Visible)
            {
                DiLei.Visible ^= true;
                DL_SP.Visible = DiLei.Visible;
                DL_SP.Top = DiLei.Top - 4;
                m_dilei.Checked = DiLei.Visible;
            }
            DL_List.SelectedIndex = DiLeiNo;
            DL_List_Click(sender, null);
        }

        private void DL_List_Click(object sender, EventArgs e)
        {
            
        }

        private void Stock_TabClicked(object sender, int Index)
        {
           


        }

        private void KeyCode_MyKeyDown(object sender, EventArgs e)
        {
            int fh = GpListBox.Items.Count;
            if (fh - 1 > GpListBox.SelectedIndex)
            {
                GpListBox.SelectedIndex = GpListBox.SelectedIndex + 1;
            }
            KeyCode.SelectionStart = KeyCode.Text.Length;
            return;
        }

        private void KeyCode_MyKeyUp(object sender, EventArgs e)
        {
            int fh = GpListBox.SelectedIndex;
            if (fh > 0)
                GpListBox.SelectedIndex = GpListBox.SelectedIndex - 1;
            KeyCode.SelectionStart = KeyCode.Text.Length + 1;
            return;
        }

       

        private void 公?式º?管¨¹理¤¨ªToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CStock.FuncEdit fe = new FuncEdit();
            fe.ShowDialog();
            fe.Dispose();
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            Close();
        }

        private void Titile_MouseDown(object sender, MouseEventArgs e)
        {
            ReleaseCapture();
            SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
        }

        private void button4_Click_1(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Normal)
            {
                WindowState = FormWindowState.Maximized;
                max11.Image = Demo1.Properties.Resources.C2;
            }
            else
            {
                WindowState = FormWindowState.Normal;
                max11.Image = Demo1.Properties.Resources.C3;
            }
        }

        private void test_Shown(object sender, EventArgs e)
        {
            this.StartPosition = FormStartPosition.CenterScreen;
            //horse
            //FlashWindow.ShowString.Text = "初?始º?化¡¥数ºy据Y...";
            //FlashWindow.Show();
            //if (WindowState == FormWindowState.Maximized)
            //    max11.Image = Demo1.Properties.Resources.C2;
            //Link2(null, null);
        }

        private void dView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (e.ColumnIndex == 2)
                e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            if (e.ColumnIndex > 3)
                e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;

            string cs = dView.Columns[e.ColumnIndex].Name;
            if(cs=="行D业°¦Ì板ã?块¨¦"){
                e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
            }
            string ws = "今?开a 最Á?高? 最Á?低̨ª 最Á?新? 买¨°价? 卖?价?";
            if (ws.IndexOf(cs) > -1)
            {
                double prv = Convert.ToDouble(dView.Rows[e.RowIndex].Cells["昨Á¨°收º?"].Value);
                Object kk = dView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value;
                double value = 0;
                if (kk != null)
                {
                    string ss = kk.ToString();
                    if (ss.Length > 0)
                        value = Convert.ToDouble(ss);
                }
                if (value > prv)
                    e.CellStyle.ForeColor = Color.Red;
                if (value < prv)
                    e.CellStyle.ForeColor = Color.Lime;
                if ((value == prv) || (value == 0))
                    e.CellStyle.ForeColor = Color.White;
                e.CellStyle.BackColor = Color.Black;

            }
            else if (cs == "涨?幅¤¨´")
            {
                Object kk = dView.Rows[e.RowIndex].Cells["涨?幅¤¨´"].Value;
                double value = 0;
                if (kk != null)
                {
                    string ss = kk.ToString();
                    if (ss.Length > 0)
                        value = Convert.ToDouble(ss);
                }
                if (value > 0)
                    e.CellStyle.ForeColor = Color.Red;
                if (value < 0)
                    e.CellStyle.ForeColor = Color.Lime;
                if (value == 0)
                    e.CellStyle.ForeColor = Color.White;
                e.CellStyle.BackColor = Color.Black;
            }
            else if (cs == "涨?速¨´")
            {
                Object kk = dView.Rows[e.RowIndex].Cells["涨?速¨´"].Value;
                double value = 0;
                if (kk != null)
                {
                    string ss = kk.ToString();
                    if (ss.Length > 0)
                        value = Convert.ToDouble(ss);
                }
                if (value > 0)
                    e.CellStyle.ForeColor = Color.Red;
                if (value < 0)
                    e.CellStyle.ForeColor = Color.Lime;
                if (value == 0)
                    e.CellStyle.ForeColor = Color.White;
                e.CellStyle.BackColor = Color.Black;
            }
            else
            {
                e.CellStyle.BackColor = Color.Black;
                e.CellStyle.ForeColor = Color.White;

            }

        }
        private void dView_Scroll(object sender, ScrollEventArgs e)
        {
            int kk = dView.FirstDisplayedScrollingRowIndex;
            if ((topline != kk) && (Math.Abs(kk - topline) >=3))
            {
                topline = kk;
                TechUtils.init(this);
            }
            

        }

        private void dView_SizeChanged(object sender, EventArgs e)
        {
            topline = dView.FirstDisplayedScrollingRowIndex;
        }


        private void dView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.RowIndex >= 0 && e.ColumnIndex == -1)
            {
                e.Paint(e.CellBounds, DataGridViewPaintParts.All & ~DataGridViewPaintParts.ContentBackground);
                e.Handled = true;
            }
        }

        //连¢?接¨®行D情¨¦服¤t务?器¡Â响¨¬应®|函¡¥数ºy
        private void LinkServer_Click(object sender, EventArgs e)
        {
            //StartChat();
            dt.Clear();
            //启?动¡¥接¨®收º?数ºy据Y
            connectStateChange();
        }

        /// <summary>
        /// 自Á?选?股¨¦设¦¨¨置?
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void zxsetup_Click(object sender, EventArgs e)
        {
            zxsetup st = new zxsetup();
            st.Owner = this;
            st.dt = dt;
            st.ShowDialog();
            st.Dispose();
        }

        /// <summary>
        /// 数ºy据Y下?载?
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void downdata_Click(object sender, EventArgs e)
        {
            Down dw = new Down();
            dw.Owner = this;
            dw.dt = dt;
            dw.ShowDialog();

            dw.Dispose();

        }

        /// <summary>
        /// 保À¡ê存ä?数ºy据Y响¨¬应®|事º?件t
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void save_Click(object sender, EventArgs e)
        {
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                string fn = sfd.FileName;
                TStringList sl = new TStringList();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];
                    sl.Add((string)dr["市ºD场?"] + (string)dr["代䨲码?"] + " " + dr["名?称?"].ToString() + " " + (string)dr["最Á?高?"].ToString() + " " + (string)dr["今?开a"].ToString() + " " + (string)dr["最Á?低̨ª"].ToString() + " " + (string)dr["最Á?新?"].ToString() + " " + (string)dr["昨Á¨°收º?"].ToString() + " " + (string)dr["总Á¨¹量¢?"].ToString() + " " + (string)dr["总Á¨¹额?"].ToString() + " " + DateTime.Now.ToString());
                }
                if (sl.Count > 0)
                    sl.SaveToFile(fn);
            }
        }

        private void TB10_Click(object sender, EventArgs e)
        {
            if (!GPSTOCK.Visible)
            {
                Board.Visible = false;
                gpinfo.Visible = false;
                Stock.ShowFs = true;
                GPSTOCK.Visible = true;
                dView_DoubleClick(null,null);
            }
            Stock.Focus();
            Stock.PR10 ^= true;
            IniFile ini = new IniFile(Directory.GetCurrentDirectory() + "\\Stock.ini");
            ini.IniWriteValue("Main", "PR10", Stock.PR10.ToString());
        }

        private void ShowInfo_Click(object sender, EventArgs e)
        {
            NetInfo nf = new NetInfo();
            nf.Owner = this;
            nf.ShowDialog();
            nf.Dispose();
        }

        private void View6_Click(object sender, EventArgs e)
        {
            if (Board.Visible)
            {
                DataGridViewCell dg = dView.CurrentCell;
                int id = dg.RowIndex;
                GCode = (string)dView.Rows[id].Cells["code"].Value;
                GName = (string)dView.Rows[id].Cells["名?称?"].Value;
                strMark = (string)dView.Rows[id].Cells["市ºD场?"].Value;
                GType = (String)dView.Rows[id].Cells["类¤¨¤型¨ª"].Value;
            }
            if (!GPSTOCK.Visible)
            {
                Board.Visible = false;
                gpinfo.Visible = false;
                Stock.ShowFs = false;
                GPSTOCK.Visible = true;
            }
            Stock.Focus();
            Stock.ShowFs = false;
            GZq += 1;
            if (GZq > 10)
                GZq = 1;
            GetStockinfo(GCode, strMark, GType, GZq);
        }

        private void View7_Click(object sender, EventArgs e)
        {
            if (!GPSTOCK.Visible)
            {
                GPSTOCK.Visible = true;
                Board.Visible = false;
                gpinfo.Visible = false;
            }
            Stock.Focus();
            Stock.ShowFs = Stock.ShowFs ^ true;
        }

        private void View8_Click(object sender, EventArgs e)
        {
            if (!GPSTOCK.Visible)
            {
                GPSTOCK.Visible = true;
                Board.Visible = false;
                gpinfo.Visible = false;
            }
            Stock.Focus();
            Stock.ShowBoard ^= true;
        }

        private void View10_Click(object sender, EventArgs e)
        {
            TB2_Click(null, null);
            Stock.FsAll ^= true;
        }

        private void View11_Click(object sender, EventArgs e)
        {
            TB2_Click(null, null);
            Stock.FsFull ^= true;
        }

        private void View12_Click(object sender, EventArgs e)
        {
            TB2_Click(null, null);
            Stock.HighPicture ^= true;
        }

        private void dp1_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem mi = (ToolStripMenuItem)sender;
            String tag = (String)mi.Tag;
            if (tag.Length != 8)
                return;

            if (DataCache.hashHangQingShuJu.ContainsKey(tag))
            {
                StockStruct.StockStructs.HangQingStruct model = (StockStruct.StockStructs.HangQingStruct)DataCache.hashHangQingShuJu[tag];
                GCode = model.Code;
                GName = model.name;
                GPreclose = model.prev_close;
                GOpen = model.open;
                strMark = model.Mark;
            }
            else
            {
                MessageBox.Show("查¨¦询¡¥失º¡ì败㨹...","提¬¨¢示º?");
                return;
            }

            Stock.cleardata();
            if (!GPSTOCK.Visible)
            {
                gpinfo.Visible = false;
                Board.Visible = false;
                GPSTOCK.Visible = true;
            }
            if (!Stock.ShowFs)
                Stock.ShowFs = true;
            Stock.Focus();
            GetStockinfo(GCode, strMark, GType, GZq);



        }

        private void mi2_Click(object sender, EventArgs e)
        {
            if (!GPSTOCK.Visible)
            {
                gpinfo.Visible = false;
                Board.Visible = false;
                GPSTOCK.Visible = true;
            }
            Stock.Focus();
            Stock.ShowCursor ^= true;
        }
        //画-线?工¡è具?
        private void mi3_Click(object sender, EventArgs e)
        {
            if (!GPSTOCK.Visible)
            {
                gpinfo.Visible = false;
                Board.Visible = false;
                GPSTOCK.Visible = true;
            }
            Stock.Focus();
            Stock.ShowDrawBoard ^= true;
        }
        private void mi4_Click(object sender, EventArgs e)
        {
            if (!GPSTOCK.Visible)
            {
                gpinfo.Visible = false;
                Board.Visible = false;
                GPSTOCK.Visible = true;
            }
            Stock.Focus();
            //if (Stock.ShowFs)
            //    Stock.ShowFs = false;
            Stock.ShowTab ^= true;

        }

        private void mi5_Click(object sender, EventArgs e)
        {
            Tool.Visible ^= true;
        }

        private void mi6_Click(object sender, EventArgs e)
        {
            sb1.Visible ^= true;
        }

        private void mi7_Click(object sender, EventArgs e)
        {
            if (!GPSTOCK.Visible)
            {
                gpinfo.Visible = false;
                Board.Visible = false;
                GPSTOCK.Visible = true;
            }
            Stock.Focus();
            Stock.Command("恢?复¡ä默?认¨?指?标À¨º");
        }

        private void mi8_Click(object sender, EventArgs e)
        {
            if (!GPSTOCK.Visible)
            {
                gpinfo.Visible = false;
                Board.Visible = false;
                GPSTOCK.Visible = true;
            }
            Stock.Focus();
            Stock.Command("保À¡ê存ä?指?标À¨º图ª?像?");
        }

        private void mi9_Click(object sender, EventArgs e)
        {
            if (!GPSTOCK.Visible)
            {
                gpinfo.Visible = false;
                Board.Visible = false;
                GPSTOCK.Visible = true;
            }
            Stock.Focus();
            Stock.Command("保À¡ê存ä?整?个?图ª?像?");
        }
        /// <summary>
        /// 自Á?选?股¨¦监¨¤控?响¨¬应®|事º?件t
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Check_Click(object sender, EventArgs e)
        {

            //if (JkenWindow == null || JkenWindow.IsDisposed)
            //{
            //    JkenWindow = new Jken();
            //    JkenWindow.MS = this;
            //    JkenWindow.dt = dt;
            //    JkenWindow.Show();//为a了¢?加¨®载?load函¡¥数ºy
            //}
            //else
            //{
            //    JkenWindow.Show();//为a了¢?加¨®载?load函¡¥数ºy
            //}
            YuJ.YujingForm jy = new YuJ.YujingForm();
            jy.Show();
        }

        //右®¨°键¨¹菜?单Ì£¤项? 打䨰开a分¤?时º¡À
        private void pm11_Click(object sender, EventArgs e)
        {
            Stock.ShowFs = true;
            dView_DoubleClick(null,null);
            
        }
        //右®¨°键¨¹菜?单Ì£¤项? 技?术º?分¤?析?
        private void pm12_Click(object sender, EventArgs e)
        {
            Stock.ShowFs = false;
            dView_DoubleClick(null, null);
        }
        //公?司?资Á¨º料¢?
        private void pm13_Click(object sender, EventArgs e)
        {
            //DataGridViewCell dg = dView.CurrentCell;
            //if (dg == null)
            //    return;
            //int id = dg.RowIndex;
            //GCode = (string)dView.Rows[id].Cells["code"].Value;
            //GName = (string)dView.Rows[id].Cells["名?称?"].Value;
            //GPreclose = (double)dView.Rows[id].Cells["昨Á¨°收º?"].Value;
            //GOpen = (double)dView.Rows[id].Cells["今?开a"].Value;
            //strMark = (string)dView.Rows[id].Cells["市ºD场?"].Value;
            //GType = (int)dView.Rows[id].Cells["类¤¨¤型¨ª"].Value;
            //if (!gpinfo.Visible)
            //{
            //    GPSTOCK.Visible = false;
            //    Board.Visible = false;
            //    gpinfo.Visible = true;
            //}
            //Stock.Focus();
            //GetInfo(GCode, GMark, GType);//公?司?资Á¨º料¢?
            MessageBox.Show("该?功|能¨¹尚¦D未¡ä添¬¨ª加¨®...");
        }
        //加¨®入¨?自Á?选?股¨¦
        private void pm15_Click(object sender, EventArgs e)
        {
            DataGridViewCell dg = dView.CurrentCell;
            if (dg == null)
            {
                MessageBox.Show("请?选?择?一°?个?您¨²要°a加¨®入¨?自Á?选?股¨¦中D的Ì?对?象¨®!ê?", "加¨®入¨?提¬¨¢示º?");
                return;
            }
            int id = dg.RowIndex;
            String codes = (String)dView.Rows[id].Cells["代䨲码?"].Value;
            String mark = (String)dView.Rows[id].Cells["市ºD场?"].Value;
            string stkLabel = mark+codes;
            if (tStringListZiXuanGu.IndexOf(stkLabel) > -1)
            {
                MessageBox.Show("此ä?对?象¨®已°?是º?自Á?选?股¨¦对?象¨®,ê?您¨²可¨¦以°?选?择?其?他?对?象¨®!ê?", "加¨®入¨?提¬¨¢示º?");
                return;
            }
            if (tStringListZiXuanGu.InsertText(0, stkLabel) > 0)//插?入¨?到Ì?第̨²一°?行D
            {
                int ss = Convert.ToInt32(stkLabel.GetHashCode().ToString());
                DataRow myDataRow;
                DataRow[] dr = dt.Select("索¡Â引°y=" + ss);
                if (dr.Length > 0)
                {
                    myDataRow = dr[0];
                }
                else
                {
                    return;
                }
                myDataRow.BeginEdit();
                myDataRow["自Á?选?"] = 1;
                myDataRow.EndEdit();
                tStringListZiXuanGu.SaveToFile(strZiXuanGuPath);
                MessageBox.Show("此ä?对?象¨®加¨®入¨?自Á?选?股¨¦操¨´作Á¡Â已°?成¨¦功|!ê?", "加¨®入¨?提¬¨¢示º?");
            }
           
            
        }
        //删¦?除y自Á?选?股¨¦
        private void pm16_Click(object sender, EventArgs e)
        {
            DataGridViewCell dg = dView.CurrentCell;
            if (dg == null)
            {
                MessageBox.Show("请?选?择?一°?个?您¨²要°a从䨮自Á?选?股¨¦中D移°?除y的Ì?对?象¨®!ê?", "移°?除y提¬¨¢示º?");
                return;
            }
            
            int id = dg.RowIndex;
            String codes = (string)dView.Rows[id].Cells["代䨲码?"].Value;
            if (MessageBox.Show("您¨²确¨¡¤定¡§要°a将?代䨲码?:êo" + codes + " 从䨮自Á?选?股¨¦中D移°?除y吗e?ê?", "移°?除y提¬¨¢示º?", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
            {
                return;
            }
            String mark = (String)dView.Rows[id].Cells["市ºD场?"].Value;
            string stkLabel = mark+codes;
            int i = tStringListZiXuanGu.IndexOf(stkLabel);
            if (i > -1)
            {
                tStringListZiXuanGu.RemoveAt(i);
                int ss = Convert.ToInt32(stkLabel.GetHashCode().ToString());
                DataRow myDataRow;
                DataRow[] dr = dt.Select("索¡Â引°y=" + ss);
                if (dr.Length > 0)
                {
                    myDataRow = dr[0];
                }
                else
                {
                    return;
                }
                myDataRow.BeginEdit();
                myDataRow["自Á?选?"] = -1;
                myDataRow.EndEdit();
                //dView.Rows[id].Cells["自Á?选?"].Value = -1;
                if(strNowStockMark=="ZX"){
                    dv.RowFilter = "自Á?选?>=0";
                }
                tStringListZiXuanGu.SaveToFile(strZiXuanGuPath);
            }
            else
            {
                MessageBox.Show("此ä?对?象¨®不?是º?自Á?选?股¨¦对?象¨®,ê?不?需¨¨从䨮自Á?选?股¨¦中D移°?除y!ê?", "移°?除y提¬¨¢示º?");
            }

        }

        private void MainStock_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = false;
        }

        private void help02_Click(object sender, EventArgs e)
        {
            MessageBox.Show("技?术º?人¨?员¡À:êo马¨ª云?豪¨¤;ê?联¢a系¦ÌQQ:êo734245829.", "技?术º?支¡ì持?", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void setup_Click(object sender, EventArgs e)
        {
            setup st = new setup();
            st.Owner = this;
            if (st.ShowDialog() == DialogResult.OK)
            {
                IniFile ini = new IniFile(Directory.GetCurrentDirectory() + "\\Stock.ini");
                string fname = ini.IniReadValue("Main", "ListFontName");
                string fsize = ini.IniReadValue("Main", "ListFontSize");
                dView.Font = new Font(fname, Convert.ToSingle(fsize));
            }
            st.Dispose();
        }

        private void KeyCode_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 27)
            {
                this.KeyPreview = true;
                GpKey.Visible = false;
            }
            if (e.KeyChar == 13)
            {
                GpKey.Visible = false;
                this.KeyPreview = true;
                GPDouble(sender, null);
                e.Handled = true;
            }

        }

        private void dView_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter||e.KeyCode==Keys.F5)
            {
                dView_DoubleClick(null, null);
                e.Handled = true;
            }
            if (e.KeyCode == Keys.Delete && this.Titile.Text == "自Á?选?股¨¦")
            {
                pm16_Click(null, null);
            }
            if (e.Control && e.KeyCode == Keys.Down)
            {
                int i = dView.CurrentCell.RowIndex;
                if (dt.Rows.Count > i + 1)
                {

                    DataRow dr = dt.Rows[i];
                    DataRow dr0 = dt.NewRow();
                    for (int j = 0; j < dt.Columns.Count; j++)
                        dr0[j] = dr[j];
                    dt.Rows.RemoveAt(i);// .Remove(dr);
                    dt.Rows.InsertAt(dr0, i + 1);
                    dt.AcceptChanges();
                    dView.Rows[i].Selected = false;
                    dView.Rows[i + 1].Selected = true;
                    e.Handled = true;
                }
            }

            if (e.Control && e.KeyCode == Keys.Up)
            {
                int i = dView.CurrentCell.RowIndex;
                if (i > 0)
                {

                    DataRow dr = dt.Rows[i];
                    DataRow dr0 = dt.NewRow();
                    for (int j = 0; j < dt.Columns.Count; j++)
                        dr0[j] = dr[j];
                    dt.Rows.RemoveAt(i);// .Remove(dr);
                    dt.Rows.InsertAt(dr0, i - 1);
                    dt.AcceptChanges();
                    dView.Rows[i].Selected = false;
                    dView.Rows[i - 1].Selected = true;
                    e.Handled = true;
                }
            }
        }

        //分¤?时º¡ÀK线? 鼠º¨®标À¨º滚?动¡¥事º?件t
        private void Stock_MouseWheel(object sender, MouseEventArgs e)
        {
            if ((e.Delta > 0))
            {
                int i = dView.CurrentCell.RowIndex;
                if (i > 0)
                {
                    dView.Rows[i].Selected = false;
                    i--;
                }
                else
                {
                    i = 0;
                }
                dView.Rows[i].Selected = true;
                dView.CurrentCell = dView.Rows[i].Cells[2];
                dView_DoubleClick(null, null);
            }
            else
            {
                int i = dView.CurrentCell.RowIndex;
                if (i < dView.RowCount - 1)
                {
                    dView.Rows[i].Selected = false;
                    i++;
                }
                dView.Rows[i].Selected = true;
                dView.CurrentCell = dView.Rows[i].Cells[2];
                dView_DoubleClick(null, null);
            }

        }

        //分¤?时º¡À和¨ªK线? 上¦?翻¤-和¨ª下?翻¤-响¨¬应®|事º?件t
        private void Stock_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.PageDown)
            {
                int i = dView.CurrentCell.RowIndex;
                if (i < dView.RowCount - 1)
                {
                    dView.Rows[i].Selected = false;
                    i++;
                }
                dView.Rows[i].Selected = true;
                dView.CurrentCell = dView.Rows[i].Cells[2];
                dView_DoubleClick(null, null);
                e.Handled = true;
            }

            if (e.KeyCode == Keys.PageUp)
            {
                int i = dView.CurrentCell.RowIndex;
                if (i > 0)
                {
                    dView.Rows[i].Selected = false;
                    i--;
                }
                else
                {
                    i = 0;
                }
                dView.Rows[i].Selected = true;
                dView.CurrentCell = dView.Rows[i].Cells[2];
                dView_DoubleClick(null, null);
            }
        }

        private void MainStock_SizeChanged(object sender, EventArgs e)
        {
            int h = sb1.Visible ? sb1.Height : 0;
            if (GpKey.Visible)
                GpKey.SetBounds(this.ClientRectangle.Width - GpKey.Width - 3, this.ClientRectangle.Height - GpKey.Height - h, GpKey.Width, GpKey.Height);
        }




        //沪|深¦?A股¨¦Button响¨¬应®|事º?件t
        private void hsagutoolStripButton_Click(object sender, EventArgs e)
        {
            lock (lockDViewObject)
            {
                strNowStockMark = "SHSZAG";
                dView.Columns["持?仓?"].Visible = false;
                dView.Columns["总Á¨¹额?"].Visible = true;
                dv.RowFilter = "(市ºD场?='SH' and not(code='000001')) or (市ºD场?='SZ' and not(code='399001'))";
                dv.Sort = "code asc";
                dView.Focus();
                Titile.Text = "沪|深¦?A股¨¦";
                dView.ClearSelection();
            }
            TechUtils.init(this);//下?载?计?算?指?标À¨º的Ì?历¤¨²史º¡¤数ºy据Y

        }
        //上¦?海¡êA股¨¦
        private void shagutoolStripButton_Click(object sender, EventArgs e)
        {
            lock (lockDViewObject)
            {
                strNowStockMark = "SHAG";
                dView.Columns["持?仓?"].Visible = false;
                dView.Columns["总Á¨¹额?"].Visible = true;
                dv.RowFilter = "市ºD场?='SH' and not(code='000001')";
                dv.Sort = "code asc";
                dView.Focus();
                Titile.Text = "上¦?海¡êA股¨¦";
                dView.ClearSelection();
            }
            TechUtils.init(this);//下?载?计?算?指?标À¨º的Ì?历¤¨²史º¡¤数ºy据Y
        }
        //深¦?圳¨²A股¨¦
        private void ZsClick(object sender, EventArgs e)
        {
            lock (lockDViewObject)
            {
                strNowStockMark = "SZAG";
                dView.Columns["持?仓?"].Visible = false;
                dView.Columns["总Á¨¹额?"].Visible = true;
                dv.RowFilter = "市ºD场?='SZ' and not(code='399001')";
                dv.Sort = "code asc";
                dView.Focus();
                Titile.Text = "深¦?圳¨²A股¨¦";
                dView.ClearSelection();
            }
            TechUtils.init(this);//下?载?计?算?指?标À¨º的Ì?历¤¨²史º¡¤数ºy据Y
        }

        private void ganggtoolStripButton_Click(object sender, EventArgs e)
        {
            lock (lockDViewObject)
            {
                strNowStockMark = "HK";
                dView.Columns["持?仓?"].Visible = false;
                dView.Columns["总Á¨¹额?"].Visible = true;
                dv.RowFilter = "市ºD场?='HK'";
                dv.Sort = "code asc";
                dView.Focus();
                Titile.Text = "港?股¨¦";
                dView.ClearSelection();
            }
            TechUtils.init(this);//下?载?计?算?指?标À¨º的Ì?历¤¨²史º¡¤数ºy据Y
        }
        private void shqh_Click(object sender, EventArgs e)
        {
            lock (lockDViewObject)
            {
                strNowStockMark = "SHQH";
                dView.Columns["持?仓?"].Visible = true;
                dView.Columns["总Á¨¹额?"].Visible = false;
                dv.RowFilter = "市ºD场?='SQ' or 市ºD场?='SE' or 市ºD场?='SY'";
                dv.Sort = "code asc";
                dView.Focus();
                Titile.Text = "上¦?海¡ê商¦¨¬品¡¤";
                dView.ClearSelection();
            }
            TechUtils.init(this);//下?载?计?算?指?标À¨º的Ì?历¤¨²史º¡¤数ºy据Y
        }

        private void dlqh_Click(object sender, EventArgs e)
        {
            lock (lockDViewObject)
            {
                strNowStockMark = "DLQH";
                dView.Columns["持?仓?"].Visible = true;
                dView.Columns["总Á¨¹额?"].Visible = false;
                dv.RowFilter = "市ºD场?='DL'";
                dv.Sort = "code asc";
                dView.Focus();
                Titile.Text = "大䨮连¢?商¦¨¬品¡¤";
                dView.ClearSelection();
            }
            TechUtils.init(this);//下?载?计?算?指?标À¨º的Ì?历¤¨²史º¡¤数ºy据Y
        }

        private void zzqh_Click(object sender, EventArgs e)
        {
            lock (lockDViewObject)
            {
                strNowStockMark = "ZZQH";
                dView.Columns["持?仓?"].Visible = true;
                dView.Columns["总Á¨¹额?"].Visible = false;
                dv.RowFilter = "市ºD场?='ZZ'";
                dv.Sort = "code asc";
                dView.Focus();
                Titile.Text = "郑¡ê州Y商¦¨¬品¡¤";
                dView.ClearSelection();
            }
            TechUtils.init(this);//下?载?计?算?指?标À¨º的Ì?历¤¨²史º¡¤数ºy据Y
        }

        private void gzqh_Click(object sender, EventArgs e)
        {
            lock (lockDViewObject)
            {
                strNowStockMark = "ZJQH";
                dView.Columns["持?仓?"].Visible = true;
                dView.Columns["总Á¨¹额?"].Visible = false;
                dv.RowFilter = "市ºD场?='ZJ'";
                dv.Sort = "code asc";
                dView.Focus();
                Titile.Text = "股¨¦指?期¨²货?";
                dView.ClearSelection();
            }
            TechUtils.init(this);//下?载?计?算?指?标À¨º的Ì?历¤¨²史º¡¤数ºy据Y
        }

        //自Á?选?股¨¦Menu响¨¬应®|事º?件t
        private void zx_Click(object sender, EventArgs e)
        {
            lock (lockDViewObject)
            {
                strNowStockMark = "ZX";
                dView.Columns["持?仓?"].Visible = true;
                dView.Columns["总Á¨¹额?"].Visible = true;
                dv.RowFilter = "自Á?选?>=0";
                dv.Sort = "自Á?选? asc";
                if (!Board.Visible)
                {
                    Board.Visible = true;
                    gpinfo.Visible = false;
                    GPSTOCK.Visible = false;
                }
                dView.Focus();
                Titile.Text = "自Á?选?股¨¦";
                dView.ClearSelection();
            }
            //TechUtils.init(this);//下?载?计?算?指?标À¨º的Ì?历¤¨²史º¡¤数ºy据Y
           
        }


        int indexMoveBegin = -1;
        int indexMoveEnd = -1;
        private void dView_DragDrop(object sender, DragEventArgs e)
        {
            //DataGridView.HitTestInfo info = this.dView.HitTest(e.X, e.Y);
            //if (info.RowIndex > -1 && info.RowIndex != indexMoveBegin)
            //{
            //    indexMoveEnd = info.RowIndex;
            //    DataGridViewRow rowToMove = e.Data.GetData(typeof(DataGridViewRow)) as DataGridViewRow;

            //    string codes = (string)rowToMove.Cells["代䨲码?"].Value;
            //    string mk = (string)rowToMove.Cells["市ºD场?"].Value;
            //    tStringListZiXuanGu.RemoveAt(indexMoveBegin);
            //    tStringListZiXuanGu.InsertText(indexMoveEnd, mk + codes);
            //    tStringListZiXuanGu.SaveToFile(strZiXuanGuPath);
                    
            //    zx_Click(null, null);

            //    indexMoveBegin = -1;
            //    indexMoveEnd = -1;
            //}
        }

        //自Á?选?股¨¦上¦?下?移°?动¡¥排?序¨°
        private void dView_MouseDown(object sender, MouseEventArgs e)
        {
            //if (e.Button == MouseButtons.Left && this.Titile.Text.Contains("自Á?选?股¨¦"))
            //{
            //    DataGridView.HitTestInfo info = this.dView.HitTest(e.X, e.Y);
            //    if (info.RowIndex > -1)
            //    {
            //        indexMoveBegin = info.RowIndex;
            //    }
            //}

            if (e.Button == MouseButtons.Right)
            {
                DataGridView.HitTestInfo info = this.dView.HitTest(e.X, e.Y);
                if (info.RowIndex > -1&&info.RowIndex<dView.RowCount)
                {
                    dView.Rows[info.RowIndex].Cells[info.ColumnIndex].Selected = true;
                }
            }

        }

        private void dView_DragEnter(object sender, DragEventArgs e)
        {
            //e.Effect = DragDropEffects.Move;
        }

        private void dView_MouseMove(object sender, MouseEventArgs e)
        {
            //if (e.Button == MouseButtons.Left && this.Titile.Text.Contains("自Á?选?股¨¦"))
            //{
            //    if (indexMoveBegin > -1)
            //    {
            //        this.dView.DoDragDrop(this.dView.Rows[indexMoveBegin], DragDropEffects.Move);
            //    }
            //}
        }


        /// <summary>
        /// 添¬¨ª加¨®指?标À¨º栏¤?响¨¬应®|事º?件t
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddTechColumnEvent(object sender, EventArgs e)
        {
            SelectColumnTech formSTech = new SelectColumnTech();
            if (formSTech.ShowDialog() == DialogResult.OK)
            {
                string fs = formSTech.techname + "-" + formSTech.NameList.Text;
                if (dt.Columns.IndexOf(fs) > -1)
                {
                    MessageBox.Show("表À¨ª格?中D已°?有®D名?为a:êo" + fs + " 的Ì?列¢D,ê?请?确¨¡¤认¨?后¨®再¨´操¨´作Á¡Â!ê?", "重?复¡ä提¬¨¢示º?");
                    return;
                }

                Demo1.Jken.jkfunc jf = new Demo1.Jken.jkfunc();
                jf.tablename = fs;
                jf.name = formSTech.techname;
                jf.title = formSTech.techtitle;
                //jf.input = formSTech.input;//暂Y时º¡À不?用®?
                jf.bname = formSTech.NameList.Text;
                int zq = formSTech.zq;
                jf.pg = formSTech.GetStr;
                ColumnTechList.Add(jf);
                listSW.Insert(4, fs);
                String techColumns = "";
                foreach (Demo1.Jken.jkfunc jk in ColumnTechList)
                {
                    techColumns += jk.name + "-" + jk.bname + ",";
                }
                if (techColumns.EndsWith(","))
                {
                    techColumns = techColumns.Substring(0, techColumns.Length - 1);
                }
                IniFile ini = new IniFile(Directory.GetCurrentDirectory() + "\\Stock.ini");
                ini.IniWriteValue("Main", "MainTechColumnNames", techColumns);
                DataColumn col = new DataColumn(jf.tablename);
                col.ColumnName = jf.tablename;
                col.DataType = System.Type.GetType("System.Double");
                col.DefaultValue = 0;
                dt.Columns.Add(col);
                dView.Columns[jf.tablename].DefaultCellStyle.Format = "F2";
                dt.Columns[jf.tablename].SetOrdinal(4);

                dView.Columns[jf.tablename].DisplayIndex = 4;
                dView.Columns[jf.tablename].SortMode = DataGridViewColumnSortMode.NotSortable;
                TechUtils.init(this);//下?载?计?算?指?标À¨º的Ì?历¤¨²史º¡¤数ºy据Y

                Thread calcThread = new Thread(new ThreadStart(runTechCalc));
                calcThread.Start();


            }
            formSTech.Dispose();

        }


        //移°?除y指?标À¨º栏¤?
        private void RemoveTechColumnEvent(object sender, EventArgs e)
        {
            try
            {
                RemoveColumnTech rTech = new RemoveColumnTech(this);
                rTech.Show();
                if (ColumnTechList.Count==0)
                {
                    TechUtils.keepalive = false;
                }
            }
            catch (Exception ex)
            {
                LogHelper.Write(ex.Message);
            }
        }


        //改?变À?当Ì¡À前¡ã连¢?接¨®状Á¡ä态¬?
        public void connectStateChange()
        {
            if (connected)
            {
                LinkServer.Enabled = true;
                QuitServer.Enabled = false;
                connected = false;
                FConnect.Text = "未¡ä连¢?接¨®";
                FConnect.BackColor = Color.Red;
               
            }
            else
            {
                
                LinkServer.Enabled = false;
                QuitServer.Enabled = true;
                connected = true;
                FConnect.Text = "已°?连¢?接¨®";
                FConnect.BackColor = Color.Green;
               
            }
        }






        private void 修T改?密¨¹码?toolStripMenuItem_Click(object sender, EventArgs e)
        {
            UpdatePassword p = new UpdatePassword(this);
            p.Show();
        }

        private void 修T改?信?息¡étoolStripMenuItem_Click(object sender, EventArgs e)
        {
            UpdateInfo iform = new UpdateInfo();
            iform.Show();
        }

        private void 发¤¡é送¨ª信?号?toolStripMenuItem_Click(object sender, EventArgs e)
        {
            sentXinhao sform = new sentXinhao(this);
            sform.Show();
        }

        private void 发¤¡é送¨ª股¨¦评¨¤toolStripMenuItem_Click(object sender, EventArgs e)
        {
            SentGuping iform = new SentGuping(this);
            iform.Show();
        }


        string tempStr = Directory.GetCurrentDirectory() + "\\Data\\Temp";
        int intZhangFuMinsCount = 0;
        static int intZhangFuMins = 1;
        DataRow myDataRow;
        double zs = 0;
        MyFileStream myfs_min = new MyFileStream();
        //分¤?时º¡À数ºy据Y存ä?储ä¡é数ºy据Y库a
        private void Minute1DataTimer_Tick(object sender, EventArgs e)
        {
           
            DateTime pushTime = DateTime.Now;
            //LogHelper.Write(pushTime.ToString());
            int addMinutes = pushTime.Hour * 60 + pushTime.Minute;
            if (pushTime.Hour>3&&pushTime.Hour < 9)
            {
                return;
            }
            if (pushTime.Hour > 16 && pushTime.Hour<21)
            {
                return;
            }
            if (pushTime.Date == dateLastStockWorking.Date)
            {
            }
            else
            {
                return;
            }

            if (pushTime.Hour==9&&pushTime.Minute==0)
            {
                //清?除y上¦?一°?日¨?分¤?时º¡À数ºy据Y
                if (Directory.Exists(tempStr+"\\SH"))
                {
                    DirectoryInfo di = new DirectoryInfo(tempStr+"\\SH");
                    di.Delete(true);
                }
                if (Directory.Exists(tempStr + "\\SZ"))
                {
                    DirectoryInfo di = new DirectoryInfo(tempStr + "\\SZ");
                    di.Delete(true);
                }
                if (Directory.Exists(tempStr + "\\ZZ"))
                {
                    DirectoryInfo di = new DirectoryInfo(tempStr + "\\ZZ");
                    di.Delete(true);
                } if (Directory.Exists(tempStr + "\\HK"))
                {
                    DirectoryInfo di = new DirectoryInfo(tempStr + "\\HK");
                    di.Delete(true);
                } if (Directory.Exists(tempStr + "\\DL"))
                {
                    DirectoryInfo di = new DirectoryInfo(tempStr + "\\DL");
                    di.Delete(true);
                } if (Directory.Exists(tempStr + "\\ZJ"))
                {
                    DirectoryInfo di = new DirectoryInfo(tempStr + "\\ZJ");
                    di.Delete(true);
                } if (Directory.Exists(tempStr + "\\SQ"))
                {
                    DirectoryInfo di = new DirectoryInfo(tempStr + "\\SQ");
                    di.Delete(true);
                }
            }
            if (pushTime.Hour == 21 && pushTime.Minute == 0)
            {
                if (Directory.Exists(tempStr + "\\SE"))
                {
                    DirectoryInfo di = new DirectoryInfo(tempStr + "\\SE");
                    di.Delete(true);
                }
                if (Directory.Exists(tempStr + "\\SY"))
                {
                    DirectoryInfo di = new DirectoryInfo(tempStr + "\\SY");
                    di.Delete(true);
                }
            } 
            string path = Directory.GetCurrentDirectory();
            string pathDir, filename;
            FileStream fs;

           
            intZhangFuMinsCount++;
            List<string> listKey = DataCache.GetKeysList();
            for (int i = 0; i < listKey.Count; i++)
            {

                StockStruct.StockStructs.HangQingStruct model = DataCache.GetValue(listKey[i]);
                if (model.stkLabel == null || model.stkLabel.Length < 3)
                {
                    continue;
                }
                //在¨²有®D效¡ì的Ì?时º¡À间?里¤?
                if (StockStruct.StockTime.checkInWorkTime(model.Mark,addMinutes))
                {
                    StockStruct.StockStructs.HistoryStruct44 data = new StockStruct.StockStructs.HistoryStruct44();

                    if (intZhangFuMinsCount == intZhangFuMins)
                    {
                        int ss = Convert.ToInt32(model.stkLabel.GetHashCode().ToString());
                        DataRow[] dr = dt.Select("索¡Â引°y=" + ss);
                        if (dr.Length == 1)
                        {
                            myDataRow = dr[0];
                            myDataRow.BeginEdit();
                            zs = Convert.ToDouble(myDataRow["前¡ã涨?幅¤¨´"]);
                            myDataRow["涨?速¨´"] = model.Zhangfu * 100 - zs;
                            myDataRow["前¡ã涨?幅¤¨´"] = model.Zhangfu * 100;
                            myDataRow.EndEdit();
                        }

                    }
                    
                    data.open = model.open;
                    data.high = model.high;
                    data.low = model.low;
                    data.close = model.close;
                    if (pushTime.Date > model.Time.Date)//如¨?果?今?天¬¨¬写¡ä入¨?数ºy据Y,ê?但Ì?是º?内¨²存ä?中D数ºy据Y还1是º?昨Á¨°天¬¨¬的Ì?,ê?那?么¡ä将?成¨¦交?量¢?和¨ª金e额?设¦¨¨置?为a0
                    {
                        data.vol = 0;
                        data.amount = 0;
                    }
                    else
                    {
                        data.vol = model.vol;
                        data.amount = model.amount;
                    }
                    data.stkLabel = model.stkLabel;
                    if (model.Mark == "SE" || model.Mark == "SY")
                    {
                        data.intDate = model.IntDate;
                    }
                    else
                    {
                        data.intDate = pushTime.Year * 10000 + pushTime.Month * 100 + pushTime.Day;
                    }
                    data.intTime = pushTime.Hour * 100 + pushTime.Minute;

                    pathDir = path + "\\Data\\Temp\\" + model.stkLabel.Substring(0, 2) + "\\Min1";
                    if (!Directory.Exists(pathDir))
                    {
                        Directory.CreateDirectory(pathDir);
                    }
                    filename = pathDir + "\\" + model.stkLabel + ".dat";
                    if (System.IO.File.Exists(filename))
                    {
                        fs = myfs_min.GetFileStream(filename, FileMode.Append);
                    }
                    else
                    {
                        fs = myfs_min.GetFileStream(filename, FileMode.Create);
                    }
                    fs.Write(StockStruct.StructBytes.StructToBytes(data), 0, 44);
                    fs.Close();

                    fs = null;
                    filename = null;


                    
                }
                if (intZhangFuMinsCount == intZhangFuMins)
                {
                    intZhangFuMinsCount = 0;
                }
            }
        }

        //日¨?线?数ºy据Y自Á?动¡¥生¦¨²成¨¦
        MyFileStream myfs_day = new MyFileStream();
        private void DayTimer_Tick(object sender, EventArgs e)
        {
            DateTime pushTime = DateTime.Now;
            if (pushTime.Date == dateLastStockWorking.Date && pushTime.Hour == 17 && pushTime.Minute > 0)
            {

            }
            else
            {
                return;
            }
            string path = Directory.GetCurrentDirectory();
            string pathDir, filename;
            FileStream fs=null;
            List<string> listKey = DataCache.GetKeysList();
            for (int i = 0; i < listKey.Count;i++ )
            {

                StockStruct.StockStructs.HangQingStruct model = DataCache.GetValue(listKey[i]);
                if (model.stkLabel==null||model.stkLabel.Length < 3)
                {
                    continue;
                }
                //将?日¨?线?数ºy据Y存ä?储ä¡é
                StockStruct.StockStructs.HistoryStruct44 data = new StockStruct.StockStructs.HistoryStruct44();
                data.stkLabel = model.stkLabel;
                data.open = model.open;
                data.high = model.high;
                data.low = model.low;
                data.close = model.close;
                data.vol = model.vol;
                data.amount = model.amount;
                data.intDate = pushTime.Year * 10000 + pushTime.Month * 100 + pushTime.Day;
                data.intTime = model.IntTime;
                pathDir = path + "\\Data\\" + model.stkLabel.Substring(0, 2) + "\\Day";
                if (!Directory.Exists(pathDir))
                {
                    Directory.CreateDirectory(pathDir);
                }
                filename = pathDir + "\\" + model.stkLabel + ".dat";
                if (System.IO.File.Exists(filename))
                {
                    fs = myfs_day.GetFileStream(filename, FileMode.Append);
                }
                else
                {
                    fs = myfs_day.GetFileStream(filename, FileMode.Create);
                }
                fs.Write(StockStruct.StructBytes.StructToBytes(data), 0, 44);
                fs.Close();

                fs = null;
                filename = null;

            }
            
        }
        string strSort = " asc";
        private void dView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            try
            {
                lock (lockDViewObject)
                {
                    DataGridViewColumn clickedColumn = dView.Columns[e.ColumnIndex];
                    if (strSort.Equals(" asc"))
                    {
                        strSort = " desc";
                        if (clickedColumn.HeaderText.Contains("涨?速¨´"))
                        {
                            clickedColumn.HeaderText = clickedColumn.Name + "(" + intZhangFuMins + ") ↓y";
                            dv.Sort = clickedColumn.Name + strSort;
                        }
                        else if (clickedColumn.Name=="标À¨º记?")
                        {
                            clickedColumn.HeaderText = "●?" + " ↓y";
                            dv.Sort = "[标À¨º记?值¦Ì]" + strSort ;
                        }
                        else
                        {
                            clickedColumn.HeaderText = clickedColumn.Name + " ↓y";
                            dv.Sort = clickedColumn.Name + strSort;
                        }
                        for (int i = 0; i < dView.ColumnCount;i++ )
                        {
                            if (i == e.ColumnIndex)
                            {
                                continue;
                            }
                            else
                            {
                                if (dView.Columns[i].HeaderText.Contains("↑¨¹") || dView.Columns[i].HeaderText.Contains("↓y"))
                                {
                                    dView.Columns[i].HeaderText = dView.Columns[i].HeaderText.Substring(0, dView.Columns[i].HeaderText.Length - 2);
                                }
                            }
                        }
                    }
                    else
                    {
                        strSort = " asc";
                        if (clickedColumn.HeaderText.Contains("涨?速¨´"))
                        {
                            clickedColumn.HeaderText = clickedColumn.Name + "(" + intZhangFuMins + ") ↑¨¹";
                            dv.Sort = clickedColumn.Name + strSort;
                        }
                        else if (clickedColumn.Name == "标À¨º记?")
                        {
                            clickedColumn.HeaderText = "●?" + " ↑¨¹";
                            dv.Sort = "[标À¨º记?值¦Ì]" + strSort;
                        }
                        else
                        {
                            clickedColumn.HeaderText = clickedColumn.Name + " ↑¨¹";
                            dv.Sort = clickedColumn.Name + strSort;
                        }
                        for (int i = 0; i < dView.ColumnCount; i++)
                        {
                            if (i == e.ColumnIndex)
                            {
                                continue;
                            }
                            else
                            {
                                if (dView.Columns[i].HeaderText.Contains("↑¨¹") || dView.Columns[i].HeaderText.Contains("↓y"))
                                {
                                    dView.Columns[i].HeaderText = dView.Columns[i].HeaderText.Substring(0, dView.Columns[i].HeaderText.Length-2);
                                }
                                
                            }
                        }
                    }
                    
                    if (dView!=null&&dView.Rows.Count > 0)
                    {
                        dView.ClearSelection();
                        dView.FirstDisplayedScrollingRowIndex =0;
                    }
                }
                TechUtils.init(this);
            }catch(Exception ex){

            }


        }

        private void 分¤?钟¨®涨?速¨´1_Click(object sender, EventArgs e)
        {
            intZhangFuMins = 1;
            dView.Columns["涨?速¨´"].HeaderText = "涨?速¨´(1)";
        }

        private void 分¤?钟¨®涨?速¨´3_Click(object sender, EventArgs e)
        {
            intZhangFuMins = 3;
            dView.Columns["涨?速¨´"].HeaderText = "涨?速¨´(3)";
        }

        private void 分¤?钟¨®涨?速¨´5_Click(object sender, EventArgs e)
        {
            intZhangFuMins = 5;
            dView.Columns["涨?速¨´"].HeaderText = "涨?速¨´(5)";
        }

        private void 条¬?件t选?股¨¦ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Demo1.Select.SelectStockForm form = new Select.SelectStockForm();
            form.Show();
        }

        private void 用®?户¡ìtoolStripMenuItem_Click(object sender, EventArgs e)
        {
            UserMgr form = new UserMgr();
            form.Show();
        }
        private void 会¨¢员¡À级?别ÀetoolStripMenuItem_Click(object sender, EventArgs e)
        {
            VipMgr vform = new VipMgr();
            vform.Show();
        }
        

        private void tjxgStripButton_Click(object sender, EventArgs e)
        {
            String pa = Directory.GetCurrentDirectory() + "\\TIAOJIAN.INI";
            TStringList sl = new TStringList();
            sl.LoadFromFile(pa);
            if (sl.Count == 0)
            {
                MessageBox.Show("条¬?件t选?股¨¦中D并¡é没?有®D选?中D股¨¦票¡À,ê?请?检¨¬查¨¦后¨®再¨´试º?!ê?", "提¬¨¢示º?", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            string strFilter = "";
            for (int i = 0; i < sl.Count; i++)
            {
                try
                {
                    string t1 = sl[i];
                    if (t1.Length < 3)
                        continue;
                    string mk = t1.Substring(0, 2);
                    string code = t1.Substring(2);
                    strFilter = strFilter + "(市ºD场?='" + mk + "' and 代䨲码?='" + code.ToUpper() + "') or ";
                }
                catch (Exception ex) { }

            }
            sl.Dispose();
            if (strFilter.Length > 4)
            {
                strFilter = strFilter.Substring(0, strFilter.Length - 4);
            }
            try
            {
                lock(lockDViewObject){
                    dView.Columns["持?仓?"].Visible = true;
                    dView.Columns["总Á¨¹额?"].Visible = true;
                    Titile.Text = "条¬?件t选?股¨¦";
                    dView.Focus();

                    dv.RowFilter = strFilter;
                    dv.Sort = "code asc";
                }
            }
            catch (Exception ex)
            {
                LogHelper.Write("条¬?件t选?股¨¦:" + ex.StackTrace);
            }
        }

        System.Timers.Timer Mintimer1 = new System.Timers.Timer();
        System.Timers.Timer DayTimer2 = new System.Timers.Timer();
          //启?动¡¥线?程¨¬
        private void RunningTimer()
        {
            while(DateTime.Now.Second<59){
                Thread.Sleep(1000);
            }
            Mintimer1.Enabled = true;
            Mintimer1.Start();
            DayTimer2.Enabled = true;
            DayTimer2.Start();
        }



        private void 今?日¨?推ª?荐?toolStripButton_Click(object sender, EventArgs e)
        {
            int count = DataCache.hashXinhao.Count;
            if (count == 0)
            {
                MessageBox.Show("暂Y时º¡À没?有®D找¨°到Ì?今?日¨?推ª?荐?的Ì?股¨¦票¡À信?息¡é!ê?", "提¬¨¢示º?", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            string strFilter = "";

            lock (DataCache.hashXinhao.SyncRoot)
            {
                foreach(string key in DataCache.hashXinhao.Keys){
                    if (key.Length < 3)
                        continue;
                    string mk = key.Substring(0, 2);
                    string code = key.Substring(2);
                    strFilter = strFilter + "(市ºD场?='" + mk + "' and 代䨲码?='" + code.ToUpper() + "') or ";
                }
            }
            if (strFilter.Length > 4)
            {
                strFilter = strFilter.Substring(0, strFilter.Length - 4);
            }
            try
            {
                今?日¨?推ª?荐?toolStripButton.Text = "今?日¨?推ª?荐?";
                今?日¨?推ª?荐?toolStripButton.ForeColor = Color.Black;
                lock (lockDViewObject)
                {
                    dView.Columns["持?仓?"].Visible = true;
                    dView.Columns["总Á¨¹额?"].Visible = true;
                    Titile.Text = "今?天¬¨¬推ª?荐?";
                    dView.Focus();
                    dv.RowFilter = strFilter;
                    dv.Sort = "code asc";
                }
            }
            catch (Exception ex)
            {
                LogHelper.Write("今?天¬¨¬推ª?荐?:" + ex.StackTrace);
            }
        }



        private void 标À¨º记?ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;
            DataGridViewCell dg = dView.CurrentCell;
            int tag = Convert.ToInt16(item.Tag);
            int id = dg.RowIndex;
            if(tag<=-1){
                dView.Rows[id].Cells["标À¨º记?"].Value = "";
                dView.Rows[id].Cells["标À¨º记?值¦Ì"].Value = -1;
            }else if(tag<16){
                string[] ss = { "①騴", "②騲", "③é?", "④騹", "⑤éY", "⑥éT", "⑦é?", "⑧騤", "⑨騢", "⑩éa", "⑪", "⑫", "⑬", "⑭", "⑮" };

                dView.Rows[id].Cells["标À¨º记?"].Value = ss[tag-1];
                dView.Rows[id].Cells["标À¨º记?值¦Ì"].Value = tag;
                if (dView.Columns["标À¨º记?"].Visible == false)
                {
                    dView.Columns["标À¨º记?"].Visible = true;
                    showingcolumns.Add("标À¨º记?");
                    hidingcolumns.Remove("标À¨º记?");
                }
            }
            
            
        }

        private void runTechCalc()
        {
            Thread.Sleep(20000);
            TechUtils.initAll(this);
        }

        Block.BlockGridViewForm bgvf = null;
        private void 行D业°¦Ì板ã?块¨¦toolStripButton_Click(object sender, EventArgs e)
        {
            if (bgvf == null || bgvf.IsDisposed)
            {
                bgvf = new Block.BlockGridViewForm(this);
            }
            bgvf.Show();
            bgvf.Activate();
        }

        private void 添¬¨ª加¨®板ã?块¨¦类¤¨¤ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            Block.AddBlockForm  af = new Block.AddBlockForm();
            af.Show();
        }

  
       
       
        private void 加¨®入¨?板ã?块¨¦ToolStripMenuItem_MouseHover(object sender, EventArgs e)
        {
            加¨®入¨?板ã?块¨¦ToolStripMenuItem.DropDownItems.Clear();
            foreach(string block in Block.BlockUtils.getBlockList()){
                ToolStripMenuItem item = new ToolStripMenuItem();
                item.Text = block;
                item.Click += new EventHandler(加¨®入¨?板ã?块¨¦ToolStripMenuItem_Click);
                加¨®入¨?板ã?块¨¦ToolStripMenuItem.DropDownItems.Add(item);
            }
            
        }

        private void 加¨®入¨?板ã?块¨¦ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string block = ((ToolStripMenuItem)sender).Text;

            DataGridViewCell dg = dView.CurrentCell;
            if (dg == null)
            {
                MessageBox.Show("请?选?择?一°?个?您¨²要°a加¨®入¨?板ã?块¨¦的Ì?对?象¨®!ê?", "加¨®入¨?板ã?块¨¦提¬¨¢示º?");
                return;
            }

            int id = dg.RowIndex;
            String codes = (string)dView.Rows[id].Cells["代䨲码?"].Value;
            String mark = (string)dView.Rows[id].Cells["市ºD场?"].Value;
            string nowblock = (string)dView.Rows[id].Cells["行D业°¦Ì板ã?块¨¦"].Value;
            Block.BlockUtils.DelFromBlock(nowblock, mark + codes);
            int result = Block.BlockUtils.AppendToBlock(block, mark + codes);
            if ( result== 1)
            {
                MessageBox.Show("添¬¨ª加¨®成¨¦功|!ê?");
                lock (MainStock.lockDViewObject)
                {
                    dView.Rows[id].Cells["行D业°¦Ì板ã?块¨¦"].Value = block;
                }
            }
            else if (result == 0)
            {
                MessageBox.Show("板ã?块¨¦中D已°?经-存ä?在¨² " + mark + codes + ",无T需¨¨重?复¡ä添¬¨ª加¨®!ê?");
            }
            else
            {
                MessageBox.Show("未¡ä找¨°到Ì?要°a添¬¨ª加¨®进?的Ì?板ã?块¨¦,ê?请?先¨¨添¬¨ª加¨®板ã?块¨¦信?息¡é!ê?");
            }
            Block.BlockUtils.init();
           

        }
        private void 移°?除y板ã?块¨¦ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DataGridViewCell dg = dView.CurrentCell;
            if (dg == null)
            {
                MessageBox.Show("请?选?择?一°?个?您¨²要°a移°?除y板ã?块¨¦的Ì?对?象¨®!ê?", "移°?除y板ã?块¨¦提¬¨¢示º?");
                return;
            }

            int id = dg.RowIndex;
            string codes = (string)dView.Rows[id].Cells["代䨲码?"].Value;
            string mark = (string)dView.Rows[id].Cells["市ºD场?"].Value;
            string block = (string)dView.Rows[id].Cells["行D业°¦Ì板ã?块¨¦"].Value;
            int result=Block.BlockUtils.DelFromBlock(block, mark + codes);
            if (result == 1)
            {
                MessageBox.Show("移°?除y成¨¦功|!ê?");
                lock (MainStock.lockDViewObject){
                    dView.Rows[id].Cells["行D业°¦Ì板ã?块¨¦"].Value = "其?他?行D业°¦Ì";
                }
            }
            else if (result == 0)
            {
                MessageBox.Show("板ã?块¨¦中D未¡ä找¨°到Ì? " + mark + codes + ",无T需¨¨移°?除y操¨´作Á¡Â!ê?");
            }
            else
            {
                MessageBox.Show("未¡ä找¨°到Ì?要°a移°?除y的Ì?板ã?块¨¦,ê?请?先¨¨确¨¡¤定¡§板ã?块¨¦信?息¡é!ê?");
            }
            Block.BlockUtils.init();
        }

        private void 删¦?除y板ã?块¨¦类¤¨¤ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Block.DelBlockForm df = new Block.DelBlockForm();
            df.Show();
        }

        //增?加¨®显?示º?表À¨ª头ª¡¤列¢D
        private void 添¬¨ª加¨®选?项?ToolStripMenuItem_MouseHover(object sender, EventArgs e)
        {
            添¬¨ª加¨®选?项?ToolStripMenuItem.DropDownItems.Clear();
            for (int i = 0; i < hidingcolumns.Count;i++ )
            {
                    ToolStripMenuItem item = new ToolStripMenuItem();
                    item.Text = hidingcolumns[i];
                    item.Click += new EventHandler(添¬¨ª加¨®选?项?itemToolStripMenuItem_Click);
                    添¬¨ª加¨®选?项?ToolStripMenuItem.DropDownItems.Add(item);
                    
            }
        }

        private void 添¬¨ª加¨®选?项?itemToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;
            dView.Columns[item.Text].Visible = true;
            hidingcolumns.Remove(item.Text);
            showingcolumns.Add(item.Text);
            //dView.Columns[item.Text].DisplayIndex = 5;
        }


        private void 移°?除y选?项?ToolStripMenuItem_MouseHover(object sender, EventArgs e)
        {
            移°?除y选?项?ToolStripMenuItem.DropDownItems.Clear();
            for (int i = 0; i < showingcolumns.Count; i++)
            {
                    ToolStripMenuItem item = new ToolStripMenuItem();
                    item.Text = showingcolumns[i];
                    item.Click += new EventHandler(移°?除y选?项?itemToolStripMenuItem_Click);
                    移°?除y选?项?ToolStripMenuItem.DropDownItems.Add(item);

            }
        }

        private void 移°?除y选?项?itemToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem item = (ToolStripMenuItem)sender;
            dView.Columns[item.Text].Visible = false;
            showingcolumns.Remove(item.Text);
            hidingcolumns.Add(item.Text);
        }

      


    }

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值