示例#1
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     = cmbBoxGender.Text;
            u.user_type  = cmbBoxUserType.Text;
            u.added_date = DateTime.Now;

            // Getting Username of the logged in user
            string  loggedUser = frmLogin.loggedIn;
            userBLL usr        = dal.GetIDFromUsername(loggedUser);

            u.added_by = usr.id;

            // Inserting Data into Database. we will declare one variable success which will take data to DAL
            bool success = dal.Inset(u);

            // now we wil ltest our condition that if data is successfully inserted, then good , otherwise it will be false

            if (success == true)
            {
                // Data Successfully inserted then the value will be true else will be false
                MessageBox.Show("User successfully Created");

                // Here we will call clear method
                clear();
            }
            else
            {
                // falied
                MessageBox.Show("Falied to add new user");
            }

            // Refreshing Data Grid View.we will create a temporary storage data table to store data.
            DataTable dt = dal.Select();

            // this will refer the data grid view
            dgvUsers.DataSource = dt;
        }