private void btnUpdate_Click(object sender, EventArgs e)
        {
            bool status = true;

            if (txtFirstName.Text == string.Empty)
            {
                pnlError.Visible   = true;
                pnlError.BackColor = System.Drawing.ColorTranslator.FromHtml("#f5b7b7");
                pnlError.Location  = new Point((this.Width - pnlError.ClientSize.Width) / 2, 12);
                lblError.Text      = "First Name is required";
                lblError.Location  = new Point((pnlError.Width - lblError.ClientSize.Width) / 2, (pnlError.Height - lblError.ClientSize.Height) / 2);
                status             = false;
                txtFirstName.Focus();
                return;
            }
            if (txtLastName.Text == string.Empty)
            {
                pnlError.Visible   = true;
                pnlError.BackColor = System.Drawing.ColorTranslator.FromHtml("#f5b7b7");
                pnlError.Location  = new Point((this.Width - pnlError.ClientSize.Width) / 2, 12);
                lblError.Text      = "Last Name is required";
                lblError.Location  = new Point((pnlError.Width - lblError.ClientSize.Width) / 2, (pnlError.Height - lblError.ClientSize.Height) / 2);
                status             = false;
                txtLastName.Focus();
                return;
            }
            if (txtUserName.Text == string.Empty)
            {
                pnlError.Visible   = true;
                pnlError.BackColor = System.Drawing.ColorTranslator.FromHtml("#f5b7b7");
                pnlError.Location  = new Point((this.Width - pnlError.ClientSize.Width) / 2, 12);
                lblError.Text      = "User Name is required";
                lblError.Location  = new Point((pnlError.Width - lblError.ClientSize.Width) / 2, (pnlError.Height - lblError.ClientSize.Height) / 2);
                status             = false;
                txtUserName.Focus();
                return;
            }
            if (txtPassword.Text == string.Empty)
            {
                pnlError.Visible   = true;
                pnlError.BackColor = System.Drawing.ColorTranslator.FromHtml("#f5b7b7");
                pnlError.Location  = new Point((this.Width - pnlError.ClientSize.Width) / 2, 12);
                lblError.Text      = "Password is required";
                lblError.Location  = new Point((pnlError.Width - lblError.ClientSize.Width) / 2, (pnlError.Height - lblError.ClientSize.Height) / 2);
                status             = false;
                txtPassword.Focus();
                return;
            }
            if (txtConfirmPassword.Text == string.Empty)
            {
                pnlError.Visible   = true;
                pnlError.BackColor = System.Drawing.ColorTranslator.FromHtml("#f5b7b7");
                pnlError.Location  = new Point((this.Width - pnlError.ClientSize.Width) / 2, 12);
                lblError.Text      = "Please confirm Password";
                lblError.Location  = new Point((pnlError.Width - lblError.ClientSize.Width) / 2, (pnlError.Height - lblError.ClientSize.Height) / 2);
                status             = false;
                txtConfirmPassword.Focus();
                return;
            }
            if (cmbRoles.Text == "Choose Role" || cmbRoles.Text.Length == 0)
            {
                pnlError.Visible   = true;
                pnlError.Location  = new Point((this.Width - pnlError.ClientSize.Width) / 2, 12);
                pnlError.BackColor = System.Drawing.ColorTranslator.FromHtml("#f5b7b7");
                lblError.Text      = "Select a Role";
                lblError.Location  = new Point((pnlError.Width - lblError.ClientSize.Width) / 2, (pnlError.Height - lblError.ClientSize.Height) / 2);
                status             = false;
                cmbRoles.Focus();
                return;
            }
            if (cmbStatus.Text == "-Choose a Status-")
            {
                pnlError.Visible   = true;
                pnlError.Location  = new Point((this.Width - pnlError.ClientSize.Width) / 2, 12);
                pnlError.BackColor = System.Drawing.ColorTranslator.FromHtml("#f5b7b7");
                lblError.Text      = "Select a Status";
                lblError.Location  = new Point((pnlError.Width - lblError.ClientSize.Width) / 2, (pnlError.Height - lblError.ClientSize.Height) / 2);
                status             = false;
                cmbStatus.Focus();
                return;
            }
            if (txtPassword.Text != txtConfirmPassword.Text)
            {
                pnlError.Visible   = true;
                pnlError.BackColor = System.Drawing.ColorTranslator.FromHtml("#f5b7b7");
                pnlError.Location  = new Point((this.Width - pnlError.ClientSize.Width) / 2, 12);
                lblError.Text      = "Password and Confirm Password does not match, try again";
                lblError.Location  = new Point((pnlError.Width - lblError.ClientSize.Width) / 2, (pnlError.Height - lblError.ClientSize.Height) / 2);
                status             = false;
                return;
            }
            if (!status)
            {
                MessageBox.Show("Please Enter Required Data");
            }
            else
            {
                try
                {
                    //* Updating User details in Users table *//

                    Boolean Status = Convert.ToBoolean(0);
                    if (cmbStatus.Text == "Active")
                    {
                        Status = Convert.ToBoolean(1);
                    }
                    else if (cmbStatus.Text == "InActive")
                    {
                        Status = Convert.ToBoolean(0);
                    }
                    NewUserManager objNewUserManager = new NewUserManager();
                    NandanaResult  insertUserValues  = objNewUserManager.UpdateUserDetails(UserID, txtFirstName.Text.Trim(), txtLastName.Text.Trim(), txtMiddleName.Text.Trim(), txtAddress.Text.Trim(), txtCity.Text.Trim(), txtState.Text.Trim(), txtCountry.Text.Trim(), txtZip.Text.Trim(), txtMobile.Text.Trim(), txtHomePhone.Text.Trim(), txtUserName.Text.Trim(), this.Encrypt(txtPassword.Text.Trim()), cmbRoles.SelectedValue.ToString(), Status);

                    //* End  *//

                    SaveSuccess objSaveSuccess = new SaveSuccess();
                    objSaveSuccess.FormName = "NewUser";
                    objSaveSuccess.ShowDialog();

                    EmptyControls();

                    GetUsersDetails();

                    txtUserName.ReadOnly = false;

                    btnUpdate.Visible = false;
                    btnSave.Visible   = true;
                }
                catch (Exception x)
                {
                    MessageBox.Show(x.Message, "Error while Inserting Data from InsertUserValues SP");
                }
            }
        }
        public void GetUsersDetails()
        {
            dgvUsers.Columns.Clear();
            dgvUsers.AutoGenerateColumns = false;
            dgvUsers.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgvUsers.ColumnHeadersDefaultCellStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#444444");
            this.dgvUsers.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("Segoe UI", 11.00F);


            DataGridViewColumn clnDocumentID = new DataGridViewTextBoxColumn();

            clnDocumentID.DataPropertyName = "User_ID";
            clnDocumentID.Name             = "User_ID";
            dgvUsers.Columns.Add(clnDocumentID);
            clnDocumentID.Visible = false;

            DataGridViewLinkColumn clnDocumentName = new DataGridViewLinkColumn();

            clnDocumentName.LinkBehavior     = System.Windows.Forms.LinkBehavior.NeverUnderline;
            clnDocumentName.LinkColor        = Color.Blue;
            clnDocumentName.DataPropertyName = "Name";
            clnDocumentName.Name             = "Name";
            dgvUsers.Columns.Add(clnDocumentName);
            dgvUsers.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable;

            DataGridViewColumn clnDocumentPath = new DataGridViewTextBoxColumn();

            clnDocumentPath.DataPropertyName = "Address";
            clnDocumentPath.Name             = "Address";
            dgvUsers.Columns.Add(clnDocumentPath);

            DataGridViewColumn clnKeyword = new DataGridViewTextBoxColumn();

            clnKeyword.DataPropertyName = "State";
            clnKeyword.Name             = "State";
            dgvUsers.Columns.Add(clnKeyword);

            DataGridViewColumn clnKeywordID = new DataGridViewTextBoxColumn();

            clnKeywordID.DataPropertyName = "Country";
            clnKeywordID.Name             = "Country";
            dgvUsers.Columns.Add(clnKeywordID);


            DataGridViewColumn clnProcesstype = new DataGridViewTextBoxColumn();

            clnProcesstype.DataPropertyName = "MobileNo";
            clnProcesstype.Name             = "MobileNo";
            dgvUsers.Columns.Add(clnProcesstype);

            DataGridViewColumn clnUsername = new DataGridViewTextBoxColumn();

            clnUsername.DataPropertyName = "User_Name";
            clnUsername.Name             = "UserName";
            dgvUsers.Columns.Add(clnUsername);
            dgvUsers.Columns[6].HeaderCell.SortGlyphDirection = SortOrder.None;

            DataGridViewColumn clnRole = new DataGridViewTextBoxColumn();

            clnRole.DataPropertyName = "Role_Name";
            clnRole.Name             = "Role";
            dgvUsers.Columns.Add(clnRole);

            DataGridViewImageColumn img = new DataGridViewImageColumn();

            img.Image = global::DocSort_CPA.Properties.Resources.delete1;
            dgvUsers.Columns.Add(img);
            img.HeaderText   = "";
            img.Name         = "img";
            img.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
            img.Width        = 40;

            Dttemp.Clear();

            try
            {
                NewUserManager objShowDocumentsManager            = new NewUserManager();
                NandanaResult  dsgetScannedDocumentResultsdetails = objShowDocumentsManager.GetUsers();
                UserManager    objUserManager = new UserManager();
                NandanaResult  dsUserData     = objUserManager.GetRoles();
                if (dsgetScannedDocumentResultsdetails.resultDS != null && dsgetScannedDocumentResultsdetails.resultDS.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in dsgetScannedDocumentResultsdetails.resultDS.Tables[0].Rows)
                    {
                        DataRow[] drResult = dsUserData.resultDS.Tables[0].Select("Role_ID =" + dr["Role_ID"].ToString() + "");
                        if (drResult.Count() != 0)
                        {
                            DataRow drtemp = Dttemp.NewRow();

                            drtemp["User_ID"]   = dr["User_ID"].ToString();
                            drtemp["Name"]      = dr["Name"].ToString();
                            drtemp["Address"]   = dr["Address"].ToString();
                            drtemp["State"]     = dr["State"].ToString();
                            drtemp["Country"]   = dr["Country"].ToString();
                            drtemp["MobileNo"]  = dr["MobileNo"].ToString();
                            drtemp["User_Name"] = dr["User_Name"].ToString();
                            drtemp["Role_Name"] = drResult[0].ItemArray[1].ToString();

                            Dttemp.Rows.Add(drtemp);
                        }
                    }
                    dgvUsers.DataSource = Dttemp;
                }
                else
                {
                    dgvUsers.DataSource = null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error While retriving data from GetUsers table");
            }
        }
        private void dgvUsers_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            NewUserManager objNewUserManager = new NewUserManager();

            if (dgvUsers.Rows.Count > 0)
            {
                if (e.ColumnIndex == 8)
                {
                    int row;
                    row = e.RowIndex;

                    DeleteConfirmation objDeleteConfirmation = new DeleteConfirmation();
                    objDeleteConfirmation.UserName = dgvUsers.Rows[row].Cells[1].Value.ToString();
                    objDeleteConfirmation.ShowDialog();

                    if (objDeleteConfirmation.DeleteConfirmationRequest == "Yes")
                    {
                        if (row >= 0)
                        {
                            UserID = dgvUsers.Rows[row].Cells[0].Value.ToString();
                            try
                            {
                                NandanaResult result = new NandanaResult();
                                result = objNewUserManager.DeleteUserDetails(UserID);
                            }
                            catch (Exception x)
                            {
                                MessageBox.Show(x.Message, "Error while Deleting Data from DeletePayslip SP");
                            }
                            GetUsersDetails();
                        }
                    }
                }
                if (e.ColumnIndex == 1)
                {
                    int row;
                    row = e.RowIndex;
                    if (row >= 0)
                    {
                        UserID = dgvUsers.Rows[row].Cells[0].Value.ToString();
                    }
                    if (UserID != null && UserID != string.Empty)
                    {
                        Boolean Status = false;
                        try
                        {
                            NandanaResult dsUserdetailValues = objNewUserManager.GetUserDetailsUsingUserID(UserID);
                            if (dsUserdetailValues.resultDS != null && dsUserdetailValues.resultDS.Tables[0].Rows.Count > 0)
                            {
                                DataRow dr = dsUserdetailValues.resultDS.Tables[0].Rows[0];
                                txtFirstName.Text       = dr["FirstName"].ToString();
                                txtLastName.Text        = dr["LastName"].ToString();
                                txtMiddleName.Text      = dr["MiddleName"].ToString();
                                txtAddress.Text         = dr["Address"].ToString();
                                txtCity.Text            = dr["City"].ToString();
                                txtState.Text           = dr["State"].ToString();
                                txtCountry.Text         = dr["Country"].ToString();
                                txtZip.Text             = dr["Zip"].ToString();
                                txtMobile.Text          = dr["MobileNo"].ToString();
                                txtHomePhone.Text       = dr["AlternateMobileNo"].ToString();
                                txtUserName.Text        = dr["User_Name"].ToString();
                                txtPassword.Text        = this.Decrypt(dr["Password"].ToString());
                                txtConfirmPassword.Text = this.Decrypt(dr["Password"].ToString());
                                cmbRoles.SelectedValue  = dr["Role_ID"].ToString();
                                Status = Convert.ToBoolean(dr["Status"]);
                            }

                            txtUserName.ReadOnly = true;

                            if (Status == true)
                            {
                                cmbStatus.Text = "Active";
                            }
                            else
                            {
                                cmbStatus.Text = "InActive";
                            }

                            btnSave.Visible    = false;
                            btnUpdate.Visible  = true;
                            btnUpdate.Location = new Point(471, 301);
                        }
                        catch (Exception x)
                        {
                            MessageBox.Show(x.Message, "Error while Retreiving Data from GetUserDetailsUsingUserID SP");
                        }

                        txtFirstName.Focus();
                    }
                }
            }
        }
Exemplo n.º 4
0
 public BaseController(GameManager gameManager, NewUserManager userManager)
 {
     GameManager = gameManager;
     UserManager = userManager;
 }