//Edit and Delete users
        private void dgvUsers_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                int userid = 0;
                userid = (int)dgvUsers.CurrentRow.Cells[0].Value;
                int difflevel = (int)dgvUsers.CurrentRow.Cells[2].Value;
                if (e.ColumnIndex == 6)  //edit record
                {
                    //  e.Handled = true;
                    // DataGridViewCell cell = dataGridView1.Rows[0].Cells[0];
                    //dataGridView1.CurrentCell = cell;
                    //dgvUsers.BeginEdit(true);
                    //int selectedRowIndex = dgvUsers.SelectedCells[0].RowIndex;
                    //DataGridViewRow selectedRow = dgvUsers.Rows[selectedRowIndex];

                    FrmAddUser objUser = new FrmAddUser();
                    //To bring the text from grid to combo box in FrmAddUser
                    Utility.LoadCodeToCB(objUser.cbDifficultyLevel, CodeEnum.DifficultyLevel);
                    Utility.LoadCodeToCB(objUser.cbRole, CodeEnum.UserRole);

                    objUser.AddUserID(userid);
                    objUser.txtUserName.Text = (string)dgvUsers.CurrentRow.Cells[1].Value;

                    objUser.cbRole.Text = (string)dgvUsers.CurrentRow.Cells[4].Value;
                    objUser.cbDifficultyLevel.SelectedText = difflevel.ToString();
                    objUser.cbUserName.Text    = (string)dgvUsers.CurrentRow.Cells[1].Value;
                    objUser.cbUserName.Enabled = false;

                    var res = objUser.ShowDialog();
                    if (!res.Equals(DialogResult.Cancel))
                    {
                        LoadUsers();
                    }
                }
                if (e.ColumnIndex == 7) //delete
                {
                    var res = Utility.Showconfirmation("Are you sure you want to DISABLE the selected user: "******"disabled User " + dgvUsers.CurrentRow.Cells[1].Value);
                    }
                    // this.Close();
                }
            }

            LoadUsers();
        }
Example #2
0
 //bindingNavigator
 private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
 {
     using (FrmAddUser aduser = new FrmAddUser())
     {
         if (aduser.ShowDialog() != DialogResult.Cancel)
         {
             //LoadUsers();
         }
     }
 }
 private void btnAddUser_Click(object sender, EventArgs e)
 {
     using (FrmAddUser aduser = new FrmAddUser())
     {
         if (aduser.ShowDialog() != DialogResult.Cancel)
         {
             LoadUsers();
         }
     }
 }
Example #4
0
        //private void btnAddUser_Click(object sender, EventArgs e)
        //{
        //    using (FrmAddUser aduser = new FrmAddUser())
        //    {
        //        if (aduser.ShowDialog() != DialogResult.Cancel)
        //        {
        //            LoadUsers();
        //        }
        //    }
        //}

        //Edit and Delete users
        private void dgvUsers_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                int userid = 0;
                userid = (int)dgvInvoice.CurrentRow.Cells[0].Value;
                int difflevel = (int)dgvInvoice.CurrentRow.Cells[2].Value;
                try
                {
                    if (e.ColumnIndex == 6)  //edit record
                    {
                        FrmAddUser objUser = new FrmAddUser();
                        //To bring the text from grid to combo box in FrmAddUser
                        Utility.LoadCodeToCB(objUser.cbDifficultyLevel, CodeEnum.DifficultyLevel);
                        Utility.LoadCodeToCB(objUser.cbRole, CodeEnum.UserRole);

                        objUser.AddUserID(userid);
                        objUser.txtUserName.Text = (string)dgvInvoice.CurrentRow.Cells[1].Value;

                        objUser.cbRole.Text            = (string)dgvInvoice.CurrentRow.Cells[4].Value;
                        objUser.cbDifficultyLevel.Text = difflevel.ToString();
                        objUser.cbUserName.Text        = (string)dgvInvoice.CurrentRow.Cells[1].Value;
                        objUser.cbUserName.Enabled     = false;
                        objUser.BringToFront();
                        var res = objUser.ShowDialog();


                        //if (!res.Equals(DialogResult.Cancel))
                        //{
                        //    LoadUsers();
                        //}
                    }
                    if (e.ColumnIndex == 7) //delete
                    {
                        var res = Utility.Showconfirmation("Are you sure you want to DISABLE the selected user: "******"disabled User " + dgvInvoice.CurrentRow.Cells[1].Value);
                            // LoadUsers();
                        }

                        // this.Close();
                    }
                }
                catch
                {
                    // Console.WriteLine("An error occurred: '{0}'", e);
                }
            }

            //LoadUsers();
        }