示例#1
0
        public static void save(UsuarioDatos userData, Int32 hotel, string rol, String password)
        {
            SqlCommand sp_save_or_update_user = new SqlCommand();

            sp_save_or_update_user.CommandType = CommandType.StoredProcedure;
            sp_save_or_update_user.CommandText = "PUNTO_ZIP.sp_user_save_update";

            sp_save_or_update_user.Parameters.AddWithValue("@p_user_name", userData.username);
            sp_save_or_update_user.Parameters.AddWithValue("@p_name_lastName", userData.nameLastname);
            sp_save_or_update_user.Parameters.AddWithValue("@p_id_type_document", userData.typeDocument);
            sp_save_or_update_user.Parameters.AddWithValue("@p_document_number", userData.documentNumber);
            sp_save_or_update_user.Parameters.AddWithValue("@p_mail", userData.mail);
            sp_save_or_update_user.Parameters.AddWithValue("@p_telephone", userData.telephone);
            sp_save_or_update_user.Parameters.AddWithValue("@p_address", userData.address);
            sp_save_or_update_user.Parameters.AddWithValue("@p_birthdate", userData.birthDate);

            if (userData.enabled)
            {
                sp_save_or_update_user.Parameters.AddWithValue("@p_enabled", 1);
            }
            else
            {
                sp_save_or_update_user.Parameters.AddWithValue("@p_enabled", 0);
            }

            sp_save_or_update_user.Parameters.AddWithValue("@p_id_hotel", hotel);
            sp_save_or_update_user.Parameters.AddWithValue("@p_description_rol", rol);
            if (password != null)
            {
                sp_save_or_update_user.Parameters.AddWithValue("@p_password", Encrypt.Sha256(password));
            }

            ProcedureHelper.execute(sp_save_or_update_user, "save or update user data", false);
        }
示例#2
0
        public static UsuarioDatos getUserData(String user)
        {
            UsuarioDatos userData = new UsuarioDatos();

            SqlConnection conn = Connection.getConnection();

            SqlCommand command = new SqlCommand();

            command.Connection  = conn;
            command.CommandText = "PUNTO_ZIP.sp_user_data_get_by_user";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.AddWithValue("@p_user_name", user);

            SqlDataReader reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                reader.Read();
                userData.username                = user;
                userData.address                 = Convert.ToString(reader["Direccion"]);
                userData.birthDate               = Convert.ToDateTime(reader["Fecha_Nacimiento"]);
                userData.documentNumber          = Convert.ToInt32(reader["Nro_DNI"]);
                userData.mail                    = reader["mail"].ToString();
                userData.nameLastname            = reader["Nombre_Apellido"].ToString();
                userData.telephone               = reader["Telefono"].ToString();
                userData.typeDocument            = Convert.ToInt16(reader["Tipo_DNI"]);
                userData.typeDocumentDescription = reader["Descripcion"].ToString();

                int enable = Convert.ToInt16(reader["Habilitado"]);

                if (enable == 1)
                {
                    userData.enabled = true;
                }
                else
                {
                    userData.enabled = false;
                }
            }

            conn.Close();

            return(userData);
        }
示例#3
0
        private void buttonAccept_Click(object sender, EventArgs e)
        {
            UsuarioDatos userData = this.getDataFromForm();
            string       rol      = "";

            if (userData != null)
            {
                if (txtPassword.Text != "" || edit)
                {
                    if (!edit && UsuarioHelper.existUser(userData.username))
                    {
                        MessageBox.Show("El nombre de usuario ingresado ya existe");
                        return;
                    }
                    if (rolesList.CheckedItems.Count > 0)
                    {
                        UsuarioHelper.disableAll(userData.username, VarGlobal.usuario.hotel);
                        for (int i = 0; i <= rolesList.CheckedItems.Count - 1; i++)
                        {
                            rol = rolesList.GetItemText(rolesList.CheckedItems[i]);
                            UsuarioDatosHelper.save(userData, VarGlobal.usuario.hotel, rol, txtPassword.Text);
                        }
                        if (edit)
                        {
                            MessageBox.Show("Modificacion de usuario realizada con exito");
                        }
                        else
                        {
                            MessageBox.Show("Creacion de usuario realizada con exito");
                        }
                        this.closeWindow();
                    }
                    else
                    {
                        MessageBox.Show("Debe seleciconar algun rol");
                    }
                }
            }
        }
示例#4
0
        private void FormABMUsuarioModify_Load(object sender, EventArgs e)
        {
            this.ControlBox      = false;
            this.FormBorderStyle = FormBorderStyle.None;
            this.WindowState     = FormWindowState.Maximized;

            Roles.fillCheckedListBox(rolesList);
            Documentos.fillComboBox(comboBoxDocumentType);

            if (edit)
            {
                UsuarioDatos userData = UsuarioDatosHelper.getUserData(user);
                this.txtAddress.Text                    = userData.address;
                this.txtDocumentNumber.Text             = userData.documentNumber.ToString();
                this.txtMail.Text                       = userData.mail;
                this.txtNameLastname.Text               = userData.nameLastname;
                this.txtPassword.Enabled                = false;
                this.txtTelephone.Text                  = userData.telephone;
                this.txtUsername.Text                   = userData.username;
                this.txtUsername.Enabled                = false;
                this.comboBoxDocumentType.SelectedIndex = this.comboBoxDocumentType.FindStringExact(userData.typeDocumentDescription);
                this.checkBoxEnable.Checked             = userData.enabled;

                this.dtBirthDate.Value = userData.birthDate;

                List <string> roles = UsuarioHelper.getRolByUserHotel(user, VarGlobal.usuario.hotel);
                if (roles.Count > 0)
                {
                    for (int i = 0; i <= rolesList.Items.Count - 1; i++)
                    {
                        if (roles.Contains(rolesList.GetItemText(rolesList.Items[i])))
                        {
                            rolesList.SetItemChecked(i, true);
                        }
                    }
                }
            }
        }
示例#5
0
        private UsuarioDatos getDataFromForm()
        {
            UsuarioDatos userData = new UsuarioDatos();
            Boolean      isValid;

            isValid = Validaciones.requiredString(txtAddress.Text, "La direccion es necesaria");
            if (isValid)
            {
                userData.address = txtAddress.Text;
            }

            else
            {
                return(null);
            }

            isValid = Validaciones.validAndRequiredInt32(txtDocumentNumber.Text, "El numero de documento debe ser numerico");
            if (isValid)
            {
                userData.documentNumber = Convert.ToInt32(txtDocumentNumber.Text);
            }
            else
            {
                return(null);
            }

            isValid = Validaciones.validAndRequiredMail(txtMail.Text, "El mail es requerido y debe ser valido");
            if (isValid)
            {
                userData.mail = this.txtMail.Text;
            }
            else
            {
                return(null);
            }

            isValid = Validaciones.requiredString(txtNameLastname.Text, "El nombre/apellido es necesario");
            if (isValid)
            {
                if (!System.Text.RegularExpressions.Regex.IsMatch(txtNameLastname.Text, "^[a-zA-Z ]"))
                {
                    MessageBox.Show("El nombre/apellido no puede contener numeros");
                    return(null);
                }
                userData.nameLastname = this.txtNameLastname.Text;
            }
            else
            {
                return(null);
            }

            isValid = Validaciones.validAndRequiredInt32(txtTelephone.Text, "El telefono debe ser numerico");
            if (isValid)
            {
                userData.telephone = this.txtTelephone.Text;
            }
            else
            {
                return(null);
            }

            isValid = Validaciones.requiredString(txtUsername.Text, "El usuario es necesario");
            if (isValid)
            {
                userData.username = this.txtUsername.Text;
            }
            else
            {
                return(null);
            }

            isValid = Validaciones.requiredString(this.comboBoxDocumentType.SelectedValue.ToString(), "Debe seleccionar un tipo de documento");
            if (isValid)
            {
                userData.typeDocument = Convert.ToInt32(this.comboBoxDocumentType.SelectedValue.ToString());
            }
            else
            {
                return(null);
            }

            userData.enabled = this.checkBoxEnable.Checked;

            DateTime birthDate = this.dtBirthDate.Value;

            if (birthDate > VarGlobal.FechaHoraSistema)
            {
                MessageBox.Show("La fecha de nacimiento ingresada no es valida. Hoy es: " + VarGlobal.FechaHoraSistema.Date.ToShortDateString());
                return(null);
            }

            DateHelper.truncate(birthDate);
            userData.birthDate = birthDate;

            return(userData);
        }