示例#1
0
        private void btnManageEmployye_Click(object sender, EventArgs e)
        {
            try
            {
                UpdateBorders(((Button)sender).Name);

                formEmployeeAdd form = new formEmployeeAdd();
                form.ShowDialog();
            }
            catch (Exception ex)
            {
            }
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string server     = tbServer.Text.Trim();
                string database   = tbDatabase.Text.Trim();
                string dbuserID   = tbUserID.Text.Trim();
                string dbpassword = tbPassword.Text.Trim();
                string dbpath     = tbPath.Text.Trim();


                string conString = $"Server={server};Database={database};Trusted_Connection=True;";

                if (!checkBox1.Checked)
                {
                    string userdetails = $"User Id={dbuserID};Password={dbpassword};";
                    conString = conString.Replace("Trusted_Connection=True;", userdetails);
                }

                dbHelper.WriteConfigParameter("server", server);
                dbHelper.WriteConfigParameter("database", database);
                dbHelper.WriteConfigParameter("dbuserid", dbuserID);
                dbHelper.WriteConfigParameter("dbpassword", dbpassword);
                dbHelper.WriteConfigParameter("dbpath", dbpath);
                dbHelper.WriteConfigParameter("ConString", conString);

                string scriptPath = dbHelper.ReadConfigParameter("dbscript");

                if (!File.Exists(scriptPath))
                {
                    throw new Exception("The database script not found.");
                }

                string sqlScript = File.ReadAllText(scriptPath);

                sqlScript = sqlScript.Replace("{dbName}", database);
                sqlScript = sqlScript.Replace("{primaryDbFile}", dbpath + "\\" + database);
                sqlScript = sqlScript.Replace("{logDbFile}", dbpath + "\\" + database);


                string ConStringmaster = $"Server={server};Database=master;Trusted_Connection=True;";

                if (!checkBox1.Checked)
                {
                    string userdetails = $"User Id={dbuserID};Password={dbpassword};";
                    ConStringmaster = ConStringmaster.Replace("Trusted_Connection=True;", userdetails);
                }

                dbHelper.CreateDatabase(sqlScript, ConStringmaster);
                dbHelper.WriteConfigParameter("isDBReady", "1");
                lblMessage.Text      = "Configuration is completed.";
                lblMessage.ForeColor = Color.Green;

                MessageBox.Show("Create an administrator account to login.");
                formEmployeeAdd form = new formEmployeeAdd();
                form.ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }