Esempio n. 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            u.first_name = txtFirstName.Text;
            u.last_name  = txtLastName.Text;
            u.email      = txtEmail.Text;
            u.username   = txtUsername.Text;
            u.password   = txtPassword.Text;
            u.contact    = txtContact.Text;
            u.address    = txtAddress.Text;
            u.gender     = cmbGender.Text;
            u.user_type  = cmbUserType.Text;
            u.added_date = DateTime.Now;

            string  loggedUser = frmLogin.loggedIn;
            userBLL usr        = dal.GetIdFromUsername(loggedUser);

            u.added_by = usr.id;

            bool      success = dal.Insert(u);
            DataTable dt      = dal.select();

            dgvUsers.DataSource = dt;
            if (success == true)
            {
                clear();
                MessageBox.Show("New User Created Successfully");
            }
            else
            {
                MessageBox.Show("Failed To Create User");
            }
            // DataTable dt = dal.select();
            //dgvUsers.DataSource = dt;
        }
Esempio n. 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //Getting data from UI
            u.first_name = txtFirstName.Text;
            u.last_name  = txtLastName.Text;
            u.email      = txtEmail.Text;
            u.username   = txtUsername.Text;
            u.password   = txtPassword.Text;
            u.contact    = txtContact.Text;
            u.address    = txtAddress.Text;
            u.gender     = cmbGender.Text;
            u.user_type  = cmbUserType.Text;
            u.added_date = DateTime.Now;

            //Getting username of loggedin user
            string loggedUser = frmLogin.loggedIn;

            userBLL usr = dal.GetIDFromUsername(loggedUser);

            u.added_by = usr.id;

            //Inserting data into Database
            bool success = dal.Insert(u);

            //IF the data is successfully inserted then the value of success will be true else it will be false
            if (success == true)
            {
                MessageBox.Show("User Successfully Created.");
                clear();
            }
            else
            {
                MessageBox.Show("Failed to add new user");
            }

            //refreshing data grid view
            DataTable dt = dal.select();

            dgvUsers.DataSource = dt;

            error();
        }