Click here to Skip to main content
15,891,976 members
Articles / Programming Languages / C#

A Tool to create N-Layer Architecture Classes

Rate me:
Please Sign up or sign in to vote.
4.87/5 (18 votes)
6 Jun 2016CPOL8 min read 68.1K   10.9K   126  
This tool is used to create N-Layer Architecture classes.
using System;
using System.Windows.Forms;
using ClassGeneratorEvents;

namespace ClassGeneratorControls
{
    /// <summary>
    /// The class that contains that contains the server box information.
    /// </summary>
    public partial class ServerBox : UserControl
    {
        private DatabaseBox databaseBox;

        /// <summary>
        /// The constructor that initializes the server box class.
        /// </summary>
        /// <param name="databaseBox">The database box object.</param>
        public ServerBox(DatabaseBox databaseBox)
        {
            InitializeComponent();
            this.databaseBox = databaseBox;
        }

        /// <summary>
        /// The instance of the server.
        /// </summary>
        public string ServerInstance
        {
            get { return txtServerName.Text; }

            set { txtServerName.Text = value; }

        }

        /// <summary>
        /// The username of the server.
        /// </summary>
        public string ServerUsername
        {
            get { return txtUsername.Text; }

            set { txtUsername.Text = value; }
        }

        /// <summary>
        /// The password of the server.
        /// </summary>
        public string ServerPassword
        {
            get { return txtPassword.Text; }

            set { txtPassword.Text = value; }
        }

        /// <summary>
        /// Checks whether the values are empty are not.
        /// </summary>
        public bool IsValuesEmpty
        {
            get { return string.IsNullOrEmpty(txtServerName.Text) || string.IsNullOrEmpty(txtUsername.Text) || string.IsNullOrEmpty(txtPassword.Text); }
        }

        private void btnConnect_Click(object sender, System.EventArgs e)
        {
            try
            {
                ServerBoxEvents serverBoxEvent = new ServerBoxEvents(this);
                if (IsValuesEmpty)
                    CommonFunctions.ShowMessageBox("Please enter Server Name, Username and Password!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else
                {
                    bool connectionResult = serverBoxEvent.Connect();
                    if (connectionResult)
                    {
                        databaseBox.Databases = CommonFunctions.SqlServerEventHandler.GetDatabases();
                        CommonFunctions.ShowMessageBox("Connection successful!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                        CommonFunctions.ShowMessageBox("Connection failed, please check whether the server name, username and password are correct!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                CommonFunctions.ShowMessageBox("Error occured while establishing a connection." + Environment.NewLine + "Please debug the error: " + ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions