コード例 #1
0
        private void BtnCreateNewAccount_Click(object sender, EventArgs e)
        {
            AdminAddAccount use = new AdminAddAccount(this);

            //Make the Save Button Visible
            use.BtnSave.Visible = true;

            //Still the Update Button will not be visible
            use.BtnUpdate.Visible = false;

            //Relocate the Save button next to Cancel Button
            use.BtnSave.Location = new System.Drawing.Point(102, 672);
            use.ShowDialog();
        }
コード例 #2
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            string colName = dataGridView1.Columns[e.ColumnIndex].Name;

            if (colName == "Edit")
            {
                AdminAddAccount cruser = new AdminAddAccount(this);
                cruser.txtFullname.Text   = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                cruser.txtUsername.Text   = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
                cruser.txtPassword.Text   = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
                cruser.txtRetypePass.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
                cruser.cmbQuestion.Text   = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
                cruser.txtAnswer.Text     = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
                cruser.cmbAccount.Text    = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();

                // pass the value of username to the label
                cruser.lblUsername.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
                cruser.lbl1.Text        = "Update User Profile";

                //Make the Save Button not visible
                cruser.BtnSave.Visible = false;

                //Make the Update Button visible
                cruser.BtnUpdate.Visible = true;
                cruser.ShowDialog();
                ShowAllAccounts();
            }
            else if (colName == "Delete")
            {
                if (MessageBox.Show("Are you sure you want to delete this Account?", "Delete Account Profile", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    cn.Open();
                    cm = new SqlCommand("Delete FROM tblUsers WHERE username like '" + dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString() + "'", cn);
                    cm.ExecuteNonQuery();
                    cn.Close();
                    MessageBox.Show("Account has been successfully Deleted", "Account Profile Deleted", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ShowAllAccounts();
                }
            }
        }