Example #1
0
        static void Main()
        {
            //UI线程异常
            Application.ThreadException += Application_ThreadException;

            //处理非UI线程异常
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            //处理未捕获的异常
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            TdxApi.OpenTdx();

#if Release
            LoginForm    LoginForm1    = new LoginForm();
            DialogResult DialogResult1 = LoginForm1.ShowDialog();
            if (DialogResult1 == DialogResult.OK)
            {
                mainForm = new MainForm();
                Application.Run(mainForm);
            }
#else
            mainForm = new MainForm();
            Application.Run(mainForm);
#endif

            TdxApi.CloseTdx();
        }
Example #2
0
        private void Logon()
        {
            try
            {
                if (!Program.appConfig.Exists("凭据"))
                {
                    string[] ServerInfo = this.comboBox交易服务器.Text.Split(new char[] { ':' });

                    StringBuilder ErrInfo  = new StringBuilder(256);
                    int           ClientID = TdxApi.Logon(ServerInfo[1], short.Parse(ServerInfo[2]), this.textBox版本号.Text, this.YybID, this.AccountNo, this.AccountNo, this.textBox交易密码.Text, string.Empty, ErrInfo);
                    if (ClientID == -1)
                    {
                        MessageBox.Show(ErrInfo.ToString());
                    }
                    else
                    {
                        TdxApi.Logoff(ClientID);
                        if (this.checkBox记住密码.Checked)
                        {
                            string 凭据 = string.Format("{0}|{1}|{2}", this.comboBox交易服务器.Text, this.textBox版本号.Text, this.textBox交易密码.Text);
                            Program.appConfig.SetValue("凭据", Cryptor.MD5Encrypt(凭据));
                        }
                        this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    }
                }
                else
                {
                    string        凭据         = Cryptor.MD5Decrypt(Program.appConfig.GetValue("凭据", string.Empty));
                    string[]      Data       = 凭据.Split('|');
                    string[]      ServerInfo = Data[0].Split(new char[] { ':' });
                    StringBuilder ErrInfo    = new StringBuilder(256);
                    int           ClientID   = TdxApi.Logon(ServerInfo[1], short.Parse(ServerInfo[2]), Data[1], this.YybID, this.AccountNo, this.AccountNo, Data[2], string.Empty, ErrInfo);
                    if (ClientID == -1)
                    {
                        MessageBox.Show(ErrInfo.ToString());
                        this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                    }
                    else
                    {
                        TdxApi.Logoff(ClientID);
                        this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }