Esempio n. 1
0
        private void ToolStripMenuItemRegister_Click(object sender, EventArgs e)
        {
            FormRegister dlg    = new FormRegister();
            string       strMac = CGeneralFunction.GetMACaddressOne();

            SimpleScrypt SScrypt = new SimpleScrypt();

            dlg.CodeNO = SScrypt.Encrypt(strMac);
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                //实现注册代码,有待修改
                MessageBox.Show("程序必须重新启动!");
                CAppOption.RegKeyNO = dlg.KeyNO;
                CAppOption.SaveData();
                CAppOption.SaveKeyNO();

                Application.Exit();
            }
        }
Esempio n. 2
0
        private void toolStripButtonConnect_Click(object sender, EventArgs e)
        {
            MSDASC.DataLinks mydlg  = new MSDASC.DataLinks();
            CDataAdaHelper   OleCon = new CDataAdaHelper();

            ADODB._Connection ADOcon;
            bool bEdit = false;

            //OleCon.ConnectString = CAppOption.m_sDbConnectString;
            if (CAppOption.m_sDbConnectString == String.Empty)
            {
                try
                {
                    //Cast the generic object that PromptNew returns to an ADODB._Connection.
                    ADOcon = (ADODB._Connection)mydlg.PromptNew();
                    OleCon.ConnectString = ADOcon.ConnectionString;

                    bEdit = true;
                }
                catch (Exception ex)
                {
                    CGlobalInstance.Instance.WriteErrorLog(YyLogger.LogSeverity.error, "设置数据库连接", ex);
                }
            }
            else
            {
                ADOcon = new ADODB.ConnectionClass();
                ADOcon.ConnectionString = CAppOption.m_sDbConnectString;
                //set local COM compatible data type
                object oConnection = ADOcon;
                try
                {
                    //prompt user to edit the given connect string
                    if ((bool)mydlg.PromptEdit(ref oConnection))
                    {
                        //处理
                    }
                    OleCon.ConnectString = ADOcon.ConnectionString;

                    bEdit = true;
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show("服务连接不成功,请重新设置连接!");
                    CGlobalInstance.Instance.WriteErrorLog(YyLogger.LogSeverity.error, "设置数据库连接", ex);
                }
            }

            if (bEdit == true)
            {
                try
                {
                    //OleCon.Db.Open();
                    OleCon.Open();

                    if (OleCon.IsOpen)
                    {
                        CAppOption.m_sDbConnectString = OleCon.ConnectString;
                        //OleCon.Db.Close();
                        OleCon.Close();


                        CGlobalInstance.Instance.DbAdaHelper.ConnectString = CAppOption.m_sDbConnectString;
                        CAppOption.SaveData();
                    }
                    else
                    {
                        MessageBox.Show("连接无效,无法连接数据库");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("连接无效,无法连接数据库(注意请选择允许保存密码)!");
                    CGlobalInstance.Instance.WriteErrorLog(YyLogger.LogSeverity.error, "设置数据库连接", ex);
                }
            }
        }