Ejemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!ValidateInputs())
            {
                return;
            }
            BusinessRules objBusinessRules = new BusinessRules();

            if (runningMode == OperationMode.AddUser)
            {
                using (DataTable dt = objBusinessRules.CreateUser(txtUserName.Text.Trim(), txtPassword.Text.Trim(),
                                                                  txtFirstName.Text.Trim(), txtLastName.Text.Trim(), chkIsAdmin.Checked))
                {
                    switch (Convert.ToInt16(dt.Rows[0][0]))
                    {
                    case -2:
                    {
                        MessageBox.Show("User Name already exists", "Information", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        break;
                    }

                    case 0:
                    {
                        MessageBox.Show("User successfully added", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtFirstName.Text = string.Empty;
                        txtLastName.Text  = string.Empty;
                        txtPassword.Text  = string.Empty;
                        txtUserName.Text  = string.Empty;
                        break;
                    }
                    }
                }
            }
            else if (runningMode == OperationMode.EditUser)
            {
                using (DataTable dt = objBusinessRules.UpdateUser(txtUserName.Text.Trim(), txtPassword.Text.Trim(),
                                                                  txtFirstName.Text.Trim(), txtLastName.Text.Trim(), chkIsAdmin.Checked))
                {
                    MessageBox.Show("User updated successfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (User.Instance.User_Name == txtUserName.Text.Trim())
                    {
                        User.Instance.First_Name = Convert.ToString(dt.Rows[0]["First_Name"]);
                        User.Instance.Last_Name  = Convert.ToString(dt.Rows[0]["Last_Name"]);
                        this.Parent.Text         = "Lakshya - Yatra ==== (Logged in User : "******" " + User.Instance.Last_Name + ")";
                    }
                    SearchUsers(string.Empty, string.Empty, string.Empty);
                }
            }
        }