Esempio n. 1
0
        private void btnActDeAct_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvUsers.CurrentRow != null)
                {
                    if (dgvUsers.SortedColumn != null)
                    {
                        sortedColumn  = dgvUsers.SortedColumn;
                        sortDirection = dgvUsers.SortOrder;
                    }

                    if (dgvUsers.CurrentRow.Cells["IsActive"].Value.ToString() == "Active")
                    {
                        if ((Int64)dgvUsers.CurrentRow.Cells["UserID"].Value != CurrentUser.UserID)
                        {
                            if (MessageBox.Show("You are going to deactivate the user.\n\n Are you sure?", "Deactivate", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                            {
                                ObjUser.Activate_DeactivateUser(Convert.ToInt64(dgvUsers.CurrentRow.Cells["UserID"].Value), _CompId, 0, "usp_User_ActiveDeactive");
                                if (ObjUser.Exception == null)
                                {
                                    LoadList();
                                    //btnApply_Click(sender, e);
                                    if (sortedColumn != null)
                                    {
                                        ListSortDirection LSD;
                                        if (sortDirection == SortOrder.Ascending)
                                        {
                                            LSD = System.ComponentModel.ListSortDirection.Ascending;
                                        }
                                        else
                                        {
                                            LSD = System.ComponentModel.ListSortDirection.Descending;
                                        }

                                        dgvUsers.Sort(dgvUsers.Columns[sortedColumn.Name], LSD);
                                    }
                                    if (dgvUsers.CurrentRow != null && idgvPosition <= dgvUsers.RowCount)
                                    {
                                        if (dgvUsers.Rows.Count - 1 < idgvPosition)
                                        {
                                            dgvUsers.CurrentCell = dgvUsers.Rows[idgvPosition - 1].Cells[0];
                                        }
                                        else
                                        {
                                            dgvUsers.CurrentCell = dgvUsers.Rows[idgvPosition].Cells[0];
                                        }
                                    }
                                    dgvUsers_SelectionChanged(sender, e);
                                }
                                else
                                {
                                    MessageBox.Show(ObjUser.Exception.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("You can not deactivate this user.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else
                    {
                        if (MessageBox.Show("You are going to Activate the user.\n\n Are you sure?", "Activate", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                        {
                            ObjUser.Activate_DeactivateUser(Convert.ToInt64(dgvUsers.CurrentRow.Cells["UserID"].Value), _CompId, 1, "usp_User_ActiveDeactive");
                            if (ObjUser.Exception == null)
                            {
                                LoadList();
                                // btnApply_Click(sender, e);

                                if (sortedColumn != null)
                                {
                                    ListSortDirection LSD;
                                    if (sortDirection == SortOrder.Ascending)
                                    {
                                        LSD = System.ComponentModel.ListSortDirection.Ascending;
                                    }
                                    else
                                    {
                                        LSD = System.ComponentModel.ListSortDirection.Descending;
                                    }

                                    dgvUsers.Sort(dgvUsers.Columns[sortedColumn.Name], LSD);
                                }
                                if (dgvUsers.CurrentRow != null && idgvPosition <= dgvUsers.RowCount)
                                {
                                    if (dgvUsers.Rows.Count - 1 < idgvPosition)
                                    {
                                        dgvUsers.CurrentCell = dgvUsers.Rows[idgvPosition - 1].Cells[0];
                                    }
                                    else
                                    {
                                        dgvUsers.CurrentCell = dgvUsers.Rows[idgvPosition].Cells[0];
                                    }
                                }
                                dgvUsers_SelectionChanged(sender, e);
                            }
                            else
                            {
                                MessageBox.Show(ObjUser.Exception.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                Utill.Common.ExceptionLogger.writeException("User", exc.StackTrace);
                MessageBox.Show(Utill.Common.CommonMessage.ExceptionMesg, "Exception");
            }
        }