Beispiel #1
0
 public FormVerUtentesRegistados(Enfermeiro enf, FormMenu formM)
 {
     InitializeComponent();
     conn.ConnectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=SiltesSaude;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
     enfermeiro            = enf;
     formMenu = formM;
 }
        public MenuMarcacoes(Enfermeiro enf, FormMenu formM)
        {
            InitializeComponent();
            enfermeiro            = enf;
            formMenu              = formM;
            conn.ConnectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=SiltesSaude;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";

            UpdateGridViewConsultas();

            dataConsulta.MinDate           = DateTime.Today;
            dataConsulta.Enabled           = false;
            dataConsultaAdiar.MinDate      = DateTime.Today;
            horaConsultaAdiar.Format       = DateTimePickerFormat.Custom;
            horaConsultaAdiar.CustomFormat = "HH:mm";
            horaConsultaAdiar.ShowUpDown   = true;
            errorProvider.ContainerControl = this;
            errorProvider.BlinkStyle       = System.Windows.Forms.ErrorBlinkStyle.NeverBlink;
            //dataGridViewMarcacoes.CurrentCell.RowIndex;
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                conn.Open();
                com.Connection = conn;

                byte[] hash;

                hash = new MD5CryptoServiceProvider().ComputeHash(ASCIIEncoding.ASCII.GetBytes(txtPassword.Text));

                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                for (int i = 0; i < hash.Length; i++)
                {
                    sb.Append(hash[i].ToString("X2"));
                }

                SqlCommand cmd = new SqlCommand("select * from Enfermeiro where username = @username  AND password = @password", conn);
                cmd.Parameters.AddWithValue("@username", txtUsername.Text);

                cmd.Parameters.AddWithValue("@password", sb.ToString());

                SqlDataReader reader = cmd.ExecuteReader();


                if (reader.Read())
                {
                    //string data = DateTime.ParseExact(reader["data"].ToString(), "dd/MM/yyyy HH:mm:ss", null);
                    string data = DateTime.ParseExact(reader["dataNascimento"].ToString(), "dd/MM/yyyy HH:mm:ss", null).ToString("dd/MM/yyyy");

                    Enfermeiro enfermeiro = new Enfermeiro
                    {
                        IdEnfermeiro   = (int)reader["IdEnfermeiro"],
                        nome           = (string)reader["nome"],
                        funcao         = (string)reader["funcao"],
                        username       = (string)reader["username"],
                        contacto       = Convert.ToDouble(reader["contacto"]),
                        email          = (string)reader["email"],
                        permissao      = (int)reader["permissao"],
                        DataNascimento = data
                    };

                    if ((bool)reader["passwordDefault"] == true)
                    {
                        PrimeiroAcesso redefenirPrimeiroAcesso = new PrimeiroAcesso(enfermeiro);
                        redefenirPrimeiroAcesso.Show();
                        txtUsername.Text = "";
                        txtPassword.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("Login Efetuado com Sucesso", "Parabéns", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        FormMenu formMenu = new FormMenu(enfermeiro);
                        formMenu.Show();
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Nome de utilizador ou palavra passe errados. Volte a tentar.", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                conn.Close();
            }
            catch (Exception)
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                MessageBox.Show("Por erro interno é impossível iniciar sessão!", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #4
0
 public FormDefinicoesPessoais(Enfermeiro enf, FormMenu form)
 {
     InitializeComponent();
     enfermeiro = enf;
     parent     = form;
 }