Exemplo n.º 1
0
        private void createDBbutton_Click(object sender, EventArgs e)
        {
            errorLabel.Text = "";
            try
            {
                if (currentBaseWindow != null)
                {
                    saveButton_Click(null, null);
                    DialogResult result = MessageBox.Show("This action will also drop the database with the same name if exists", "Warning Message", MessageBoxButtons.OKCancel);
                    //Check for OK Button and if cancel dont proceed
                    if (result == DialogResult.OK)
                    {
                        currentDataSet = currentBaseWindow.DatabaseDataSet;
                        string connectionString = "server= " + serverAddress.Text + " ; user id= " + userName.Text + " ; password= "******"; pooling=false;";
                        if (connection == null || connection.State != ConnectionState.Open)
                        {
                            connection = new MySqlConnection(connectionString);
                            connection.Open();
                        }
                        if (connection.State == System.Data.ConnectionState.Open && currentDataSet != null)
                        {
                            DatabaseScriptGenerator dbScriptGenerator = new DatabaseScriptGenerator();
                            dbScriptGenerator.CurrentDataSet = currentDataSet;
                            string sqlQueries = dbScriptGenerator.GenerateDatabaseScripts(currentBaseWindow);
                            if (sqlQueries == "")
                            {
                                return;
                            }

                            /* Testing code For Yash
                             */

                            TextWriter tw = new StreamWriter(EIBXMLUtilities.dataFolderName + @"\test.sql");
                            tw.Write(sqlQueries);
                            tw.Close();

                            //MessageBox.Show("Connection to MySQL opened through MySQL for .Net" + sqlQueries);
                            MySqlCommand sqlCommand         = new MySqlCommand(sqlQueries, connection);
                            int          returnQueryExecute = sqlCommand.ExecuteNonQuery();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                errorLabel.Text = ex.Message;
            }
            finally
            {
                connection.Close();
            }
            if (errorLabel.Text.Trim().Equals(""))
            {
                errorLabel.ForeColor = Color.Black;
                errorLabel.Text      = "Data Base Created.";
                //this.Close();
            }

            this.Show();
        }
Exemplo n.º 2
0
        private void createDBbutton_Click(object sender, EventArgs e)
        {
            errorLabel.Text = "";
            try
            {
                if (currentBaseWindow != null)
                {
                    saveButton_Click(null, null);
                    DialogResult result = MessageBox.Show("This action will also drop the database with the same name if exists", "Warning Message", MessageBoxButtons.OKCancel);
                    //Check for OK Button and if cancel dont proceed
                    if (result == DialogResult.OK)
                    {
                        currentDataSet = currentBaseWindow.DatabaseDataSet;
                        string connectionString = "server= " + serverAddress.Text + " ; user id= " + userName.Text + " ; password= "******"; pooling=false;";
                        if (connection == null || connection.State != ConnectionState.Open)
                        {
                            connection = new MySqlConnection(connectionString);
                            connection.Open();
                        }
                        if (connection.State == System.Data.ConnectionState.Open && currentDataSet != null)
                        {
                            DatabaseScriptGenerator dbScriptGenerator = new DatabaseScriptGenerator();
                            dbScriptGenerator.CurrentDataSet = currentDataSet;
                            string sqlQueries = dbScriptGenerator.GenerateDatabaseScripts(currentBaseWindow);
                            if (sqlQueries == "")
                            {
                                return;
                            }
                            /* Testing code For Yash
                            */

                            TextWriter tw = new StreamWriter(EIBXMLUtilities.dataFolderName + @"\test.sql");
                            tw.Write(sqlQueries);
                            tw.Close();

                            //MessageBox.Show("Connection to MySQL opened through MySQL for .Net" + sqlQueries);
                            MySqlCommand sqlCommand = new MySqlCommand(sqlQueries, connection);
                            int returnQueryExecute = sqlCommand.ExecuteNonQuery();

                            //string[] query1 = sqlQueries.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                            //foreach (string q1 in query1)
                            //{
                                //MySqlCommand sqlCommand = new MySqlCommand(q1, connection);
                                //int returnQueryExecute = sqlCommand.ExecuteNonQuery();
                            //}
                        }

                    }
                }
            }
            catch (Exception ex)
            {
                errorLabel.Text = ex.Message;

            }
            finally
            {
                connection.Close();
            }
            if (errorLabel.Text.Trim().Equals(""))
            {
                errorLabel.ForeColor = Color.Black;
                errorLabel.Text = "Data Base Created.";
                //this.Close();
            }

            this.Show();
        }