Exemplo n.º 1
0
 public void SetUser(User user)
 {
     _updatingData = true;
     txtUsername.Text = user.UserName;
     txtUsername.Enabled = false;
     txtPassword.Enabled = false;
     txtConfirmPassword.Enabled = false;
     cbxProfiles.Enabled = false;
     if (user is Cliente)
     {
         _cliente = user as Cliente;
         cbxProfiles.SelectedItem = Profile.Cliente;
         clienteUserControl.SetUser(_cliente);
     }
     else
     {
         _proveedor = user as Proveedor;
         cbxProfiles.SelectedItem = Profile.Proveedor;
         proveedorUserControl.SetUser(_proveedor);
     }
 }
Exemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!_updatingData)
            {
                if (string.IsNullOrEmpty(txtUsername.Text))
                    throw new Exception("El nombre de usuario es obligatorio!");
                if (string.IsNullOrEmpty(txtPassword.Text))
                    throw new Exception("El password es obligatorio!");
                if (txtPassword.Text != txtConfirmPassword.Text)
                    throw new Exception("Los passwords no coinciden!");
            }

            User user = null;
            if (Profile == Profile.Cliente)
            {
                _cliente = ((ClienteUserControl)clienteUserControl).GetCliente();
                _cliente.UserName = txtUsername.Text;
                var manager = new ClienteManager();
                manager.GuardarCliente(_cliente, txtPassword.Text);
                user = _cliente;
            }
            else
            {
                _proveedor = ((ProveedorUserControl)proveedorUserControl).GetProveedor();
                _proveedor.UserName = txtUsername.Text;
                var manager = new ProveedorManager();
                manager.GuardarProveedor(_proveedor, txtPassword.Text);
                user = _proveedor;
            }

            if (OnUserSaved != null)
            {
                OnUserSaved(this, new UserSavedEventArgs() { Username = this.txtUsername.Text, Password = this.txtPassword.Text, User = user });
                this.Close();
            }
        }