public void GetObjectsById() { UsuarioCreador = UsuarioPersistance.GetById(_usuarioCreador); Visibilidad = VisibilidadPersistance.GetById(_visibilidad); EstadoPublicacion = EstadoPublicacionPersistance.GetById(_estadoPublicacion); TipoPublicacion = TipoPublicacionPersistance.GetById(_tipoPublicacion); Rubros = RubroPersistance.GetByPublicationId(ID); Compras = CompraPersistance.GetByPublicationId(ID); }
private void FrmAdministrarUsuarios_Load(object sender, EventArgs e) { cboUsuarios.DataSource = UsuarioPersistance.GetAll(); cboUsuarios.ValueMember = "ID"; cboUsuarios.DisplayMember = "Username"; cboUsuarios.Enabled = chkActivo.Enabled = (!ModifyOwnPassword); if (ModifyOwnPassword) { cboUsuarios.Text = SessionManager.CurrentUser.Username; } }
private void DgvClientes_CellContentClick(object sender, DataGridViewCellEventArgs e) { //Only works when user clicks one of the buttons (column index 5 and 6) if (e.ColumnIndex < 13 || e.RowIndex == -1) { return; } var selectedCliente = _clientes.Find(cliente => cliente.ID == (int)DgvClientes.Rows[e.RowIndex].Cells[0].Value); if (selectedCliente != null) { //Click en el botón "Modificar" if (e.ColumnIndex == 13) { var insertUpdateCliente = new FrmABMInsertUpdateCliente(selectedCliente); insertUpdateCliente.ShowDialog(); if (insertUpdateCliente.CompleteAction) { RefreshSources(null); } } else { //Click en el botón "Des/habilitar" if (selectedCliente.Habilitado == true) { var dialogAnswer = MessageBox.Show(string.Format("¿Está seguro que quiere desactivar el cliente {0} {1}?", selectedCliente.Nombre, selectedCliente.Apellido), "Atención", MessageBoxButtons.YesNo); if (dialogAnswer == DialogResult.Yes) { UsuarioPersistance.UpdateToDisabledById(selectedCliente.IdUsuario); RefreshSources(null); } } else { var dialogAnswer = MessageBox.Show(string.Format("¿Está seguro que quiere activar el cliente {0} {1}?", selectedCliente.Nombre, selectedCliente.Apellido), "Atención", MessageBoxButtons.YesNo); if (dialogAnswer == DialogResult.Yes) { UsuarioPersistance.UpdateToActivateById(selectedCliente.IdUsuario); RefreshSources(null); } } } } }
private void DgvEmpresas_CellContentClick(object sender, DataGridViewCellEventArgs e) { //Only works when user clicks one of the buttons (column index 5 and 6) if (e.ColumnIndex < 12 || e.RowIndex == -1) { return; } var selectedEmpresa = _empresas.Find(empresa => empresa.ID == (int)DgvEmpresas.Rows[e.RowIndex].Cells[0].Value); if (selectedEmpresa != null) { //User clicked update button if (e.ColumnIndex == 12) { var insertUpdateEmpresa = new FrmABMInsertUpdateEmpresa(selectedEmpresa); insertUpdateEmpresa.ShowDialog(); if (insertUpdateEmpresa.CompleteAction) { RefreshSources(null); } } else { //User clicked delete button if (selectedEmpresa.Habilitado == true) { var dialogAnswer = MessageBox.Show(string.Format("Esta seguro que quiere desactivar la empresa {0}?", selectedEmpresa.RazonSocial), "Atención", MessageBoxButtons.YesNo); if (dialogAnswer == DialogResult.Yes) { UsuarioPersistance.UpdateToDisabledById(selectedEmpresa.IdUsuario); RefreshSources(null); } } else { var dialogAnswer = MessageBox.Show(string.Format("Esta seguro que quiere activar la empresa {0}?", selectedEmpresa.RazonSocial), "Atención", MessageBoxButtons.YesNo); if (dialogAnswer == DialogResult.Yes) { UsuarioPersistance.UpdateToActivateById(selectedEmpresa.IdUsuario); RefreshSources(null); } } } } }
private void Form1_Load(object sender, EventArgs e) { #region Precargar elementos //Cargar el combobox FormaPago var paymentMethod = FormaPagoPersistance.GetAll(); CboFormaPago.DisplayMember = "Descripcion"; CboFormaPago.ValueMember = "ID"; CboFormaPago.DataSource = paymentMethod; //Cargar la lista con las Publicaciones a rendir del usuario PublicationsList = PublicacionPersistance.GetPublicacionesARendirByUser(Session.SessionManager.CurrentUser.ID); if (PublicationsList != null && PublicationsList.Count > 0) { if (PublicationsList.Count < 10) { var listaItems = new List <string>(); foreach (Publicacion item in PublicationsList) { listaItems.Add("Descripción: " + item.Descripcion + " - " + "Fecha Venc: " + item.FechaVencimiento.ToShortDateString() + " - " + "Precio: " + String.Format("{0:$0.00}", item.Precio)); } LstPublicaciones.DataSource = listaItems; } else { MessageBox.Show("Posee 10 o más publicaciones por facturar y por lo tanto se procederá a inhabilitarlo"); UsuarioPersistance.InhabilitarUser(SessionManager.CurrentUser); UserInactive = true; Close(); } } else { MessageBox.Show("En este momento no tiene niguna publicación para facturar", "Atención!"); Close(); } #endregion }
private void LblAceptar_Click(object sender, EventArgs e) { //Valido que las contraseñas coincidan if (TxtContrasena.Text != TxtContrasenaRepetida.Text) { MessageBox.Show("Las contrasenas informadas no coinciden.", "Atención"); } else { //Encripto la nueva contraseña var hashedPassword = SHA256Helper.Encode(TxtContrasena.Text); //Impacto el cambio en la base de datos UsuarioPersistance.ChangePassword(this.currentUser, hashedPassword); //Vuelvo a traer el usuario porque cambió SessionManager.CurrentUser = UsuarioPersistance.GetByUsername(this.currentUser.Username); Close(); } }
private void chkActivo_CheckedChanged(object sender, EventArgs e) { this.currentUser.Activo = chkActivo.Checked; UsuarioPersistance.Update(this.currentUser); }
public void GetObjectsById() { Publicacion = PublicacionPersistance.GetById(IdPublicacion); Usuario = UsuarioPersistance.GetById(IdUsuario); }
private void DoLogin(string userName, string password) { try { //Realizo validaciones de datos ingresados if (string.IsNullOrEmpty(userName)) { throw new Exception("El usuario no puede ser vacío."); } if (string.IsNullOrEmpty(password)) { throw new Exception("La contraseña no puede ser vacía."); } //Valido que los datos del usuario ingresados sean correctos var user = UsuarioPersistance.Login(userName, password); //El usuario no se encuentra habilitado if (!user.Habilitado) { throw new Exception("No puede loguearse. El usuario se encuentra inhabilitado debido a que acumula más de 10 compras sin rendir. Por favor, acérquese a la oficina de administración."); } //Pregunto si por lo menos tiene un rol asignado que se encuentre activo if (user.RolesActivos != null) { //Seteo el usuario en sesion SessionManager.CurrentUser = user; //Mientras que el usuario posea una contraseña temporal, lo obligo a que la cambie while (SessionManager.CurrentUser.PassTemporal) { MessageBox.Show("Posee una contraseña temporal. Debera cambiarla a continuacion.", "Atención"); //Muestro el formulario para el cambio de contraseña var resetPassword = new FrmResetPassword(); resetPassword.ShowDialog(); //Refresco el currentUser por si ya lo modificó SessionManager.CurrentUser = UsuarioPersistance.GetByUsername(SessionManager.CurrentUser.Username); } Hide(); if (user.RolesActivos.Count > 1) { //Posee mas de un rol activo asignado, debe seleccionar uno solo var chooseRol = new FrmChooseRol(); chooseRol.ShowDialog(); } else { //Posee un unico rol asignado activo. Lo seteo en sesion. SessionManager.CurrentRol = user.RolesActivos.First(); //Muestro el formulario de home var home = new FrmHome(); home.ShowDialog(); } Close(); } else { throw new Exception("El usuario no cuenta con roles que se encuentren activos."); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Atención"); } }
public void GetObjectsById() { ItemsFactura = ItemFacturaPersistance.GetByFacturaId(ID); FormaPago = FormaPagoPersistance.GetById(_idFormaPago); Usuario = UsuarioPersistance.GetById(_idUsuario); }
public UsuarioLogic() { persistance = new UsuarioPersistance(); }
private void LblGrabar_Click(object sender, EventArgs e) { try { #region Validaciones var exceptionMessage = string.Empty; if (string.IsNullOrEmpty(TxtNombre.Text)) { exceptionMessage += "El nombre del cliente no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtApellido.Text)) { exceptionMessage += "El apellido del cliente no puede ser vacío.\n"; } if (string.IsNullOrEmpty(CboTipoDocumento.Text)) { exceptionMessage += "El tipo de documento del cliente no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtDocumento.Text)) { exceptionMessage += "El número de documento del cliente no puede ser vacío.\n"; } else { int nroDoc; if (!int.TryParse(TxtDocumento.Text, out nroDoc)) { exceptionMessage += "El número de documento del cliente no es válido.\n"; } } if (string.IsNullOrEmpty(TxtMail.Text)) { exceptionMessage += "El mail del cliente no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtTelefono.Text)) { exceptionMessage += "El teléfono del cliente no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtDireccion.Text)) { exceptionMessage += "La dirección del cliente no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtCodigoPostal.Text)) { exceptionMessage += "El código postal del cliente no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtCuil.Text)) { exceptionMessage += "El CUIL del cliente no puede ser vacío.\n"; } else { if (!TypesHelper.IsCUITValid(TxtCuil.Text)) { exceptionMessage += Environment.NewLine + "El CUIL no es válido.\n"; } } if (!string.IsNullOrEmpty(exceptionMessage)) { throw new Exception(exceptionMessage); } #endregion if (insertMode) { //Valido que no se dupliquen los telefonos ni documentos if (ClientePersistance.GetByPhone(TxtTelefono.Text, this.currentTransaction) != null) { throw new Exception("Ya existe un cliente con el teléfono ingresado."); } if (ClientePersistance.GetByDocument((int)CboTipoDocumento.SelectedValue, Int32.Parse(TxtDocumento.Text), this.currentTransaction) != null) { throw new Exception("Ya existe un cliente con el tipo y número de documento ingresados."); } #region Inserto el nuevo cliente var client = new Cliente(); client.IdUsuario = SessionManager.CurrentUser.ID; client.Nombre = TxtNombre.Text; client.Apellido = TxtApellido.Text; client.TipoDocumento = (int)CboTipoDocumento.SelectedValue; client.NroDocumento = Int32.Parse(TxtDocumento.Text); client.Mail = TxtMail.Text; client.Telefono = TxtTelefono.Text; client.Direccion = TxtDireccion.Text; client.CodigoPostal = TxtCodigoPostal.Text; client.CUIL = TxtCuil.Text; client.FechaNacimiento = DtpFechaNacimiento.Value; var dialogAnswer = MessageBox.Show("¿Está seguro que quiere insertar el nuevo cliente?", "Atencion", MessageBoxButtons.YesNo); if (dialogAnswer == DialogResult.Yes) { //Si es el administrador el que hace el Alta, se genera un usuario con password temporal if (insertDefaultUser) { var user = new Usuario(); user.Username = client.NroDocumento.ToString(); user.Password = SHA256Helper.Encode("temporal"); var userIngresado = UsuarioPersistance.InsertUserTemporal(user, this.currentTransaction); client.IdUsuario = userIngresado.ID; ClientePersistance.InsertClient(client, this.currentTransaction); this.currentTransaction.Commit(); var rol = RolPersistance.GetByName("Cliente"); RolPersistance.InsertUserRole(userIngresado, rol, null); } else { ClientePersistance.InsertClient(client, this.currentTransaction); this.currentTransaction.Commit(); } MessageBox.Show("El Cliente ha sido ingresado con éxito.", "Atención!"); this.Hide(); if (!_abmCliente) { var frmHome = new FrmHome(); frmHome.ShowDialog(); } } #endregion } else { if (TxtTelefono.Text != CurrentCliente.Telefono) { if (ClientePersistance.GetByPhone(TxtTelefono.Text, this.currentTransaction) != null) { throw new Exception("Ya existe un cliente con el teléfono ingresado."); } } var client = new Cliente(); client.IdUsuario = CurrentCliente.IdUsuario; client.Nombre = TxtNombre.Text; client.Apellido = TxtApellido.Text; client.TipoDocumento = (int)CboTipoDocumento.SelectedValue; client.NroDocumento = Convert.ToInt32(TxtDocumento.Text); client.Mail = TxtMail.Text; client.Telefono = TxtTelefono.Text; client.Direccion = TxtDireccion.Text; client.CodigoPostal = TxtCodigoPostal.Text; client.CUIL = TxtCuil.Text; client.FechaNacimiento = DtpFechaNacimiento.Value; var dialogAnswer = MessageBox.Show("¿Está seguro que quiere modificar el cliente?", "Atención", MessageBoxButtons.YesNo); if (dialogAnswer == DialogResult.Yes) { ClientePersistance.UpdateClient(client); CompleteAction = true; this.Hide(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Atención"); } }
private void LblGrabar_Click(object sender, EventArgs e) { try { #region Validations var exceptionMessage = string.Empty; if (string.IsNullOrEmpty(TxtRazonSocial.Text)) { exceptionMessage += "La razón social de la empresa no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtMail.Text)) { exceptionMessage += "El mail de la empresa no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtTelefono.Text)) { exceptionMessage += "El telefono de la empresa no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtDireccion.Text)) { exceptionMessage += "La dirección de la empresa no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtCodigoPostal.Text)) { exceptionMessage += "El código postal de la empresa no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtCiudad.Text)) { exceptionMessage += "La ciudad de la empresa no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtCuit.Text)) { exceptionMessage += "El CUIT de la empresa no puede ser vacío.\n"; } if (string.IsNullOrEmpty(TxtNombreContacto.Text)) { exceptionMessage += "El nombre de contacto de la empresa no puede ser vacío.\n"; } if (!string.IsNullOrEmpty(exceptionMessage)) { throw new Exception(exceptionMessage); } #endregion if (insertMode) { if (EmpresaPersistance.GetByBusinessName(TxtRazonSocial.Text, this.currentTransaction) != null) { throw new Exception("Ya existe una empresa con la razón social ingresada."); } if (EmpresaPersistance.GetByCUIT(TxtCuit.Text, this.currentTransaction) != null) { throw new Exception("Ya existe una empresa con el CUIT ingresado."); } #region Inserto la nueva empresa var company = new Empresa(); company.IdUsuario = SessionManager.CurrentUser.ID; company.RazonSocial = TxtRazonSocial.Text; company.Mail = TxtMail.Text; company.Telefono = TxtTelefono.Text; company.Direccion = TxtDireccion.Text; company.CodigoPostal = TxtCodigoPostal.Text; company.Ciudad = TxtCiudad.Text; company.CUIT = TxtCuit.Text; company.NombreContacto = TxtNombreContacto.Text; company.FechaCreacion = DtpFechaCreacion.Value; var dialogAnswer = MessageBox.Show("Esta seguro que quiere insertar la nueva empresa?", "Atencion", MessageBoxButtons.YesNo); if (dialogAnswer == DialogResult.Yes) { //Si es el administrador el que hace el Alta, se genera un usuario con password temporal if (insertDefaultUser) { var user = new Usuario(); user.Username = company.CUIT; user.Password = SHA256Helper.Encode("temporal"); var userIngresado = UsuarioPersistance.InsertUserTemporal(user, this.currentTransaction); company.IdUsuario = userIngresado.ID; EmpresaPersistance.InsertCompany(company, this.currentTransaction); this.currentTransaction.Commit(); var rol = RolPersistance.GetByName("Empresa"); RolPersistance.InsertUserRole(userIngresado, rol, null); } else { EmpresaPersistance.InsertCompany(company, this.currentTransaction); this.currentTransaction.Commit(); } MessageBox.Show("La Empresa ha sido ingresada con éxito.", "Atención!"); this.Hide(); if (!_abmEmpresa) { var frmHome = new FrmHome(); frmHome.ShowDialog(); } } #endregion } else { var company = new Empresa(); company.IdUsuario = CurrentEmpresa.IdUsuario; company.RazonSocial = TxtRazonSocial.Text; company.Mail = TxtMail.Text; company.Telefono = TxtTelefono.Text; company.Direccion = TxtDireccion.Text; company.CodigoPostal = TxtCodigoPostal.Text; company.Ciudad = TxtCiudad.Text; company.CUIT = TxtCuit.Text; company.NombreContacto = TxtNombreContacto.Text; company.FechaCreacion = DtpFechaCreacion.Value; var dialogAnswer = MessageBox.Show("Esta seguro que quiere modificar la empresa?", "Atencion", MessageBoxButtons.YesNo); if (dialogAnswer == DialogResult.Yes) { EmpresaPersistance.UpdateCompany(company); CompleteAction = true; this.Hide(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Atención"); } }
private void LblGrabar_Click(object sender, EventArgs e) { try { #region Validaciones var exceptionMessage = string.Empty; if (string.IsNullOrEmpty(TxtUsuario.Text)) { throw new Exception("El usuario no puede ser vacío."); } if (string.IsNullOrEmpty(TxtContrasena.Text)) { throw new Exception("La contraseña no puede ser vacía."); } if (UsuarioPersistance.GetByUsername(TxtUsuario.Text) != null) { exceptionMessage += Environment.NewLine + "Ya existe un usuario con el nombre ingresado."; } if (!string.IsNullOrEmpty(exceptionMessage)) { throw new Exception(exceptionMessage); } #endregion #region Inserto el nuevo usuario var user = new Usuario(); user.Username = TxtUsuario.Text; user.Password = SHA256Helper.Encode(TxtContrasena.Text); var dialogAnswer = MessageBox.Show("Esta seguro que quiere insertar el nuevo usuario?", "Atencion", MessageBoxButtons.YesNo); if (dialogAnswer == DialogResult.Yes) { using (var transaction = DataBaseManager.Instance().Connection.BeginTransaction(IsolationLevel.Serializable)) { if (_abmEmpresa || _abmCliente) { user = UsuarioPersistance.InsertUserTemporal(user, transaction); } else { user = UsuarioPersistance.InsertUser(user, transaction); } Rol selectedRol = (Rol)CboRoles.SelectedItem; RolPersistance.InsertUserRole(user, selectedRol, transaction); if (!_abmEmpresa && !_abmCliente) { //Cargo los datos en sesion SessionManager.CurrentUser = user; SessionManager.CurrentRol = selectedRol; SessionManager.CurrentRol.Funcionalidades = FuncionalidadPersistance.GetByRole(SessionManager.CurrentRol, transaction); } switch (selectedRol.Descripcion) { case "Cliente": this.Hide(); var frmABMInsertUpdateCliente = new FrmABMInsertUpdateCliente(transaction, _abmCliente, user); frmABMInsertUpdateCliente.ShowDialog(); break; case "Empresa": this.Hide(); var frmABMInsertUpdateEmpresa = new FrmABMInsertUpdateEmpresa(transaction, _abmEmpresa, user); frmABMInsertUpdateEmpresa.ShowDialog(); break; default: transaction.Commit(); this.Hide(); var frmHome = new FrmHome(); frmHome.ShowDialog(); break; } } } #endregion } catch (Exception ex) { MessageBox.Show(ex.Message, "Atención"); } }