コード例 #1
0
ファイル: FrmOpenCompany.cs プロジェクト: Muhammadinaam/ppm
        private void FrmUserAuth_Load(object sender, EventArgs e)
        {
            DataTable ConnConfigDT = new DataTable();

            try
            {
                string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

                FileStream      fs = new FileStream(path + @"\Config.dat", FileMode.Open);
                BinaryFormatter bf = new BinaryFormatter();
                ConnConfigDT = (DataTable)bf.Deserialize(fs);
                fs.Close();

                if (ConnConfigDT.Rows[0]["Database"].ToString() != "")
                {
                    Program.currentDB      = ConnConfigDT.Rows[0]["Database"].ToString();
                    Program.IsDefaultDBset = true;
                }
                else
                {
                    Program.currentDB      = "";
                    Program.IsDefaultDBset = false;
                }
            }
            catch (Exception ex)
            {
                ExceptionMB emb = new ExceptionMB(); emb.ShowMB(ex);
            }



            if (Program.IsDefaultDBset)
            {
                label3.Text = "Current Database: " + Program.currentDB;
                lb_databases.Hide();

                this.Height = 164;
            }



            if (Program.IsDefaultDBset)
            {
                return; //dont get list of databases
            }
            lb_databases.Items.Clear();
            string          connStr = string.Format("server={0};user={1};port={2};password={3};", Program.Server, Program.SqlUser, Program.Port, Program.Password);
            MySqlConnection conn    = new MySqlConnection(connStr);
            MySqlCommand    cmd;
            string          s0;

            try
            {
                // show list of databases
                conn.Open();
                s0  = "SHOW DATABASES;";
                cmd = new MySqlCommand(s0, conn);
                MySqlDataReader Reader = cmd.ExecuteReader();

                while (Reader.Read())
                {
                    string row = "";
                    for (int i = 0; i < Reader.FieldCount; i++)
                    {
                        row = Reader.GetValue(i).ToString();
                        if (row.Length > 4)
                        {
                            if (row.Substring(0, 4) == "gbc_")
                            {
                                lb_databases.Items.Add(row.Substring(4).Replace('_', ' ').ToUpper());
                            }
                        }
                    }
                }

                if (lb_databases.Items.Count == 0)
                {
                    MessageBox.Show("No database exists. Please create new database through accounting system.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                }

                conn.Close(); conn.ClearPoolAsync(conn);
                conn.Dispose();
            }
            catch (Exception ex)
            {
                ExceptionMB emb = new ExceptionMB(); emb.ShowMB(ex);
                MessageBox.Show("Not able to connect to MySQL Server. Please Enter MySQL Server Information.", "Connection Failure", MessageBoxButtons.OK, MessageBoxIcon.Information);

                FrmConnectionConfig FCC = new FrmConnectionConfig();
                FCC.ShowDialog();

                this.Close();

                conn.Close(); conn.ClearPoolAsync(conn);
                conn.Dispose();
            }

            if (lb_databases.Items.Count > 0)
            {
                lb_databases.SetSelected(0, true);
                txb_userid.Focus();
            }
        }
コード例 #2
0
        private void connectionConfigurationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmConnectionConfig fc = new FrmConnectionConfig();

            fc.ShowDialog();
        }