Exemple #1
0
        private void btnEnsure_Click(object sender, RoutedEventArgs e)
        {
            bool flag = false;

            try
            {
                Mysql ms = new Mysql(DBUrl.Text, DBName.Text, DBUser.Text, DBPwd.Text, DBPort.Text);
                ms.Open();
                ms.Close();
                flag = true;
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
            }

            if (flag == true)
            {
                GetAppCon gac = new GetAppCon();

                gac.AddUpdateAppSettings("DBName", DBName.Text);
                gac.AddUpdateAppSettings("DBUser", DBUser.Text);
                gac.AddUpdateAppSettings("DBUrl", DBUrl.Text);
                gac.AddUpdateAppSettings("DBPwd", DBPwd.Text);
                gac.AddUpdateAppSettings("DBPort", DBPort.Text);
                try
                {
                    FileInfo file = new FileInfo(@"./sql/gcxm.sql");  //filename是sql脚本文件路径。
                    string   sql  = file.OpenText().ReadToEnd();

                    Mysql ms = new Mysql();
                    ms.Open();
                    ms.Begin();

                    try
                    {
                        ms.ExecScript(sql);
                    }

                    catch (Exception error3)
                    {
                        ms.Rollback();
                        MessageBox.Show(error3.Message);
                    }

                    ms.Commit();
                    ms.Close();

                    MainWindow mw = new MainWindow();
                    Close();
                    mw.ShowDialog();
                }
                catch (Exception error2)
                {
                    MessageBox.Show(error2.Message);
                }
            }
        }
Exemple #2
0
        private void tviShowDatebase_Selected(object sender, RoutedEventArgs e)
        {
            GetAppCon gac = new GetAppCon();

            string DBName     = gac.ReadSetting("DBName");
            string DBURL      = gac.ReadSetting("DBURL");
            string DBUser     = gac.ReadSetting("DBUser");
            string DBPassword = gac.ReadSetting("DBPwd");
            string DBPort     = gac.ReadSetting("DBPort");

            MessageBox.Show($"{TryFindResource("dbName")}:{DBName}\n{TryFindResource("ipAddress")}:{DBURL}\n{TryFindResource("Username")}:{DBUser}\n{TryFindResource("Password")}:{DBPassword}\n{TryFindResource("port")}:{DBPort}\n");
        }
Exemple #3
0
        public SelectSqlWindow()
        {
            InitializeComponent();

            GetAppCon gac = new GetAppCon();

            DBName.Text = gac.ReadSetting("DBName");
            DBUser.Text = gac.ReadSetting("DBUser");
            DBUrl.Text  = gac.ReadSetting("DBUrl");
            DBPwd.Text  = gac.ReadSetting("DBPwd");
            DBPort.Text = gac.ReadSetting("DBPort");
        }
Exemple #4
0
        public Mysql()
        {
            GetAppCon gac = new GetAppCon();

            string DBName     = gac.ReadSetting("DBName");
            string DBURL      = gac.ReadSetting("DBURL");
            string DBUser     = gac.ReadSetting("DBUser");
            string DBPassword = gac.ReadSetting("DBPwd");
            string DBPort     = gac.ReadSetting("DBPort");

            string s = $"Host={DBURL};Database={DBName};Username={DBUser};Password={DBPassword};Charset=utf8;Port={DBPort}";

            cnt = new MySqlConnection(s);
        }