Ejemplo n.º 1
0
        /// <summary>
        ///     Click event handler of Connect button.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event argument</param>
        /// <exception cref="Exception"></exception>
        private void BtnConnect_Click(object sender, EventArgs e)
        {
            try
            {
                if (ddlDb.SelectedValue == null || ddlDb.SelectedValue.ToString() == string.Empty)
                {
                    throw new InvalidOperationException("Invalid database");
                }

                var req = ddlAuth.SelectedIndex == 0
                ? new ConnectionRequest(txtServer.Text.Trim(), ddlDb.SelectedValue.ToString())
                : new ConnectionRequest(txtServer.Text.Trim(), txtUser.Text.Trim(), txtPass.Text.Trim());

                if (!req.TryConnect())
                {
                    throw new InvalidOperationException("Sql Connection failed.");
                }

                ConnectionSuccess = true;
                ConnReq           = req;

                AppStatic.DbConnectionString = req.SqlConn.ConnectionString;
                AppStatic.Database           = req.SqlConn.Database;
                AppStatic.Server             = req.SqlConn.DataSource;
                DialogResult = DialogResult.OK;
                Close();
            }
            catch (Exception ex)
            {
                ConnectionSuccess = false;
                ErrorViewerForm.ShowError(ex, this);
                DialogResult = DialogResult.Cancel;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Load event handler of Main Form.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event Argument.</param>
        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                if (AppStatic.DBConnectionString.Length == 0)
                {
                    var sqlConnForm = new SQLConnectionForm();
                    if (sqlConnForm.ShowDialog(this) == DialogResult.OK && sqlConnForm.ConnectionSuccess)
                    {
                        AppStatic.DBConnectionString = sqlConnForm.ConnReq.SqlConn.ConnectionString;
                        AppStatic.Database           = sqlConnForm.ConnReq.SqlConn.Database;
                        AppStatic.Server             = sqlConnForm.ConnReq.SqlConn.DataSource;

                        FormLoad();
                    }
                    else
                    {
                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorViewerForm.ShowError(ex, this);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Save to file menu-item click event handler.
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="e">Event Argument.</param>
 private void saveToFileToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         SaveCode();
     }
     catch (Exception ex)
     {
         ErrorViewerForm.ShowError(ex, this);
     }
 }
Ejemplo n.º 4
0
 private void cSharpCodeControl_MouseClick(object sender, MouseEventArgs e)
 {
     try
     {
         if (e.Button == MouseButtons.Right)
         {
             textBoxContextMenu.Show(cSharpCodeControl, e.Location);
         }
     }
     catch (Exception ex)
     {
         ErrorViewerForm.ShowError(ex, this);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Enter event handler of Database combobox.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event argument</param>
        private void ddlDb_Enter(object sender, EventArgs e)
        {
            try
            {
                ConnectionRequest serverConnReq = GetServerConnection();
                var sqlHelp   = new SQLHelper(serverConnReq.SqlConn.ConnectionString);
                var databases = sqlHelp.GetDatabaseList();

                ddlDb.DataSource = databases;
            }
            catch (Exception ex)
            {
                ErrorViewerForm.ShowError(ex, this);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Generate Simple Typed Datatable menu-item click evennt handler.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event Argument.</param>
        private void GenerateSimpleTypedDatatableToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                tabPage1.Text = @"Simple Typed Datatable";

                _creator = null;

                _creator = new TypedDatatableCreator();
                classGeneratorSetting.ApplySettings();
            }
            catch (Exception ex)
            {
                ErrorViewerForm.ShowError(ex, this);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Generate C# Class menu-item click event handler.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event Argument.</param>
        private void PocoGenerateMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                tabPage1.Text = @"C# Class";

                _creator = null;

                _creator = new CSharpClassCreator();
                classGeneratorSetting.ApplySettings();
            }
            catch (Exception ex)
            {
                ErrorViewerForm.ShowError(ex, this);

                throw;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Database change menu-item click event handler.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event Argument.</param>
        private void dbConnectionStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                var sqlConnForm = new SQLConnectionForm();
                if (sqlConnForm.ShowDialog(this) == DialogResult.OK && sqlConnForm.ConnectionSuccess)
                {
                    AppStatic.DBConnectionString = sqlConnForm.ConnReq.SqlConn.ConnectionString;
                    AppStatic.Database           = sqlConnForm.ConnReq.SqlConn.Database;
                    AppStatic.Server             = sqlConnForm.ConnReq.SqlConn.DataSource;

                    FormLoad();
                }
            }
            catch (Exception ex)
            {
                ErrorViewerForm.ShowError(ex, this);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        ///     Settings changed event handler.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event Argument.</param>
        private void CreatorSettings_ClassSettingChangedEventHandler(ClassGeneratorSettings sender, ClassGeneratorSettingsEventArgs e)
        {
            try
            {
                _settings = null;

                if (string.IsNullOrWhiteSpace(e.ClassName))
                {
                    e.ClassName = dbTreeView.GetSelectedDbItem().ToPascalCase();
                }

                if (_creator == null)
                {
                    return;
                }

                tabControl.Visible = true;
                _settings          = CSharpSettings.GetCSharpSettings(e);
                var sql = new SqlHelper(AppStatic.DbConnectionString);

                var code = _creator.GenerateCSharpCode
                           (
                    _settings,
                    sql.GetClrProperties
                    (
                        dbTreeView.GetSelectedDbItemSchema(),
                        dbTreeView.GetSelectedDbItem(),
                        dbTreeView.GetDbObjectType()
                    )
                           );

                cSharpCodeControl.Text = code;

                tabPage1.Text = $@"{tabPage1.Text.Split
                (new[] { " (" }, StringSplitOptions.RemoveEmptyEntries)[0]} ({dbTreeView.GetSelectedNode()})";
            }
            catch (Exception ex)
            {
                ErrorViewerForm.ShowError(ex, this);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Click event handler of Connect button.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event argument</param>
        private void btnConnect_Click(object sender, EventArgs e)
        {
            ConnectionRequest req = null;

            try
            {
                if (ddlDb.SelectedValue == null || ddlDb.SelectedValue.ToString() == string.Empty)
                {
                    throw new Exception("Invalid database");
                }

                if (this.ddlAuth.SelectedIndex == 0)//Win auth
                {
                    req = new ConnectionRequest(txtServer.Text.Trim(), ddlDb.SelectedValue.ToString());
                }
                else
                {
                    req = new ConnectionRequest(txtServer.Text.Trim(), txtUser.Text.Trim(), txtPass.Text.Trim());
                }
                if (!req.TryConnect())
                {
                    throw new Exception("Sql Connection failed.");
                }
                this.ConnectionSuccess = true;
                this.ConnReq           = req;

                AppStatic.DBConnectionString = req.SqlConn.ConnectionString;
                AppStatic.Database           = req.SqlConn.Database;
                AppStatic.Server             = req.SqlConn.DataSource;
                this.DialogResult            = DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                this.ConnectionSuccess = false;
                ErrorViewerForm.ShowError(ex, this);
                ///MessageHelper.ShowError(ex.Message, this);
                this.DialogResult = DialogResult.Cancel;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Settings changed event handler.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event Argument.</param>
        private void creatorSettings_ClassSettingChangedEventHandler(ClassGeneratorSettings sender, ClassGeneratorSettingsEventArgs e)
        {
            try
            {
                if (settings != null)
                {
                    settings = null;
                }

                if (e.ClassName.Length == 0)
                {
                    e.ClassName = dbTreeView.GetSelectedDbItem();
                }

                if (creator == null)
                {
                    return;
                }

                tabControl.Visible = true;
                settings           = CSharpSettings.GetCSharpSettings(e);
                SQLHelper sql  = new SQLHelper(AppStatic.DBConnectionString);
                var       code = creator.GenerateCSharpCode(
                    settings
                    , sql.GetClrProperties(
                        dbTreeView.GetSelectedDbItemSchema()
                        , dbTreeView.GetSelectedDbItem()
                        , dbTreeView.GetDBObjectType()
                        )
                    );
                cSharpCodeControl.Text = code;
                tabPage1.Text          = $"{tabPage1.Text.Split(new string[] { " (" }, StringSplitOptions.RemoveEmptyEntries)[0]} ({dbTreeView.GetSelectedNode()})";
            }
            catch (Exception ex)
            {
                ErrorViewerForm.ShowError(ex, this);
            }
        }