checkDBExist() public méthode

public checkDBExist ( ) : bool
Résultat bool
Exemple #1
0
 private void dbConnect_Click(object sender, EventArgs e)
 {
     if (dbServerBox.Text.Length * dbAcoountBox.Text.Length * dbPasswordBox.Text.Length * dbTableBox.Text.Length == 0)
     {
         MessageBox.Show("資料庫資訊不得為空!");
         return;
     }
     dbInfo.Clear();
     dbInfo.Add(dbServerBox.Text);
     dbInfo.Add(dbAcoountBox.Text);
     dbInfo.Add(dbPasswordBox.Text);
     dbInfo.Add(dbTableBox.Text);
     string errorMessage = "";
     DBConnection conn = new DBConnection(dbInfo);
     if (!conn.checkDBExist())
     {
         MessageBox.Show("資料庫連線資訊錯誤!!");
         return;
     }
     errorMessage = conn.MySqlConnect();
     if (errorMessage.Length > 0)
     {
         MessageBox.Show(errorMessage);
         return;
     }
     else
     {
         accessTokenGroup.Enabled = true;
         string sql = "select count(*) from access_token where 1";
         MySqlDataReader res = conn.mysql_query(sql);
         res.Read();
         if (res.GetInt32(0) > 0)
         {
             res.Close();
             sql = "select access_token from access_token where 1";
             res = conn.mysql_query(sql);
             res.Read();
             accessTokenBox.Text = res.GetString(0);
             pagesEditGroup.Enabled = true;
             res.Close();
             checkCanUpdate();
             init_Timer();
         }
         else
         {
             res.Close();
             MessageBox.Show("請先指定Access Token");
         }
     }
     FileStream stream = new FileStream(dbInfoFileName, FileMode.OpenOrCreate);
     StreamWriter writer = new StreamWriter(stream);
     string baseServer = Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(dbServerBox.Text));
     string baseAccount = Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(dbAcoountBox.Text));
     string basePWD = Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(dbPasswordBox.Text));
     string baseTable = Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(dbTableBox.Text));
     writer.WriteLine(baseServer + ":" + baseAccount + ":" + basePWD + ":" + baseTable);
     writer.Close();
     stream.Close();
     updatePageIDList();
     conn.closeMySqlConnection();
     dbConnInfo.Enabled = false;
 }