Esempio 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;
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Static method, which configures the form to show "Error" and opens this form as a dialog.
        /// </summary>
        /// <param name="ex">Exception object</param>
        /// <param name="parent">Parent control of the caller.</param>
        public static void ShowError(Exception ex, Control parent = null)
        {
            var form = new ErrorViewerForm
            {
                _exWrapper = new ExceptionWrapper(ex),
                Text       = parent == null
                    ? "Error -  Sql to C# Code generator"
                    : $"Error - {parent.Text}",
                errorControl =
                {
                    Text = ex.Message
                },
                moreDetails =
                {
                    Visible = true
                },
                ShowIcon    = true,
                Icon        = SystemIcons.Error,
                pictureBox1 =
                {
                    Image = SystemIcons.Error.ToBitmap()
                }
            };

            form.ShowDialog(parent);
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Static method, which configures the form to show "Warning" and opens this form as a dialog.
        /// </summary>
        /// <param name="message">Warning to be shown on form.</param>
        /// <param name="parent">Parent control of the caller.</param>
        public static void ShowWarning(string message, Form parent)
        {
            var form = new ErrorViewerForm();

            form.Text = $"Warning - {parent.Text}";
            form.errorControl.Text = message;
            form.Icon = SystemIcons.Warning;
            form.pictureBox1.Image = SystemIcons.Warning.ToBitmap();
            form.ShowDialog(parent);
        }
Esempio n. 5
0
        /// <summary>
        /// Static method, which configures the form to show "Information" and opens this form as a dialog.
        /// </summary>
        /// <param name="message">Information to be shown on form.</param>
        /// <param name="parent">Parent control of the caller.</param>
        public static void ShowInformation(string message, Control parent)
        {
            var form = new ErrorViewerForm();

            form.Text = $"Information - {parent.Text}";
            form.errorControl.Text = message;
            form.Icon = SystemIcons.Information;
            form.pictureBox1.Image = SystemIcons.Information.ToBitmap();
            form.ShowDialog(parent);
        }
Esempio n. 6
0
        /// <summary>
        /// Static method, which configures the form to show "Success" and opens this form as a dialog.
        /// </summary>
        /// <param name="message">Success message to be shown on form.</param>
        /// <param name="parent">Parent control of the caller.</param>
        public static void ShowSuccess(string message, Form parent)
        {
            var form = new ErrorViewerForm();

            form.Text = $"Success - {parent.Text}";
            form.errorControl.Text = message;
            form.Icon = Resources.ok;
            form.pictureBox1.Image = Resources.ok.ToBitmap();
            form.ShowDialog(parent);
        }
Esempio n. 7
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);
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Static method, which configures the form to show "Error" and opens this form as a dialog.
        /// </summary>
        /// <param name="ex">Exception object</param>
        /// <param name="parent">Parent control of the caller.</param>
        public static void ShowError(Exception ex, Control parent = null)
        {
            var form = new ErrorViewerForm();

            form.exWrapper           = new ExceptionWrapper(ex);
            form.Text                = parent == null ? "Error -  Sql to C# Code generator" : $"Error - {parent.Text}";
            form.errorControl.Text   = ex.Message;
            form.moreDetails.Visible = true;
            form.ShowIcon            = true;
            form.Icon                = SystemIcons.Error;
            form.pictureBox1.Image   = SystemIcons.Error.ToBitmap();
            form.ShowDialog(parent);
        }
Esempio n. 9
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);
     }
 }
Esempio n. 10
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);
            }
        }
Esempio n. 11
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);
            }
        }
Esempio n. 12
0
        /// <summary>
        ///     Static method, which configures the form to show "Warning" and opens this form as a dialog.
        /// </summary>
        /// <param name="message">Warning to be shown on form.</param>
        /// <param name="parent">Parent control of the caller.</param>
        public static void ShowWarning(string message, Form parent)
        {
            var form = new ErrorViewerForm
            {
                Text         = $@"Warning - {parent.Text}",
                errorControl =
                {
                    Text = message
                },
                Icon        = SystemIcons.Warning,
                pictureBox1 =
                {
                    Image = SystemIcons.Warning.ToBitmap()
                }
            };

            form.ShowDialog(parent);
        }
Esempio n. 13
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;
            }
        }
Esempio n. 14
0
        /// <summary>
        ///     Static method, which configures the form to show "Information" and opens this form as a dialog.
        /// </summary>
        /// <param name="message">Information to be shown on form.</param>
        /// <param name="parent">Parent control of the caller.</param>
        public static void ShowInformation(string message, Control parent)
        {
            var form = new ErrorViewerForm
            {
                Text         = $@"Information - {parent.Text}",
                errorControl =
                {
                    Text = message
                },
                Icon        = SystemIcons.Information,
                pictureBox1 =
                {
                    Image = SystemIcons.Information.ToBitmap()
                }
            };

            form.ShowDialog(parent);
        }
Esempio n. 15
0
        /// <summary>
        ///     Static method, which configures the form to show "Success" and opens this form as a dialog.
        /// </summary>
        /// <param name="message">Success message to be shown on form.</param>
        /// <param name="parent">Parent control of the caller.</param>
        public static void ShowSuccess(string message, Form parent)
        {
            var form = new ErrorViewerForm
            {
                Text         = $@"Success - {parent.Text}",
                errorControl =
                {
                    Text = message
                },
                Icon        = Resources.ok,
                pictureBox1 =
                {
                    Image = Resources.ok.ToBitmap()
                }
            };

            form.ShowDialog(parent);
        }
Esempio n. 16
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);
            }
        }
Esempio n. 17
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);
            }
        }
Esempio n. 18
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;
            }
        }
Esempio n. 19
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);
            }
        }