private void DocExtraDetails_FormClosing(object sender, FormClosingEventArgs e)
        {
            var homeform = new HomeForm();

            homeform.ShowDialog();
        }
Esempio n. 2
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            if (loginButton.Text == "Logout")
            {
                UserInfo.UserEmail = null;
                UserInfo.UserName  = null;
                UserInfo.UserType  = null;
                Close();
            }
            using (var databaseContext = new DatabaseContext())
            {
                User user = databaseContext.Users.Where(u => u.Email == emailTextBox.Text.ToString()).FirstOrDefault <User>();

                if (user == null)
                {
                    MessageBox.Show("User with email " + emailTextBox.Text.ToString() + " not found");
                }
                else
                {
                    //Decryption of password
                    byte[] data      = Convert.FromBase64String(user.Password.ToString());
                    byte[] decrypted = ProtectedData.Unprotect(data, null, DataProtectionScope.CurrentUser);
                    if (Encoding.Unicode.GetString(decrypted) == passwordTextBox.Text.ToString())
                    {
                        // Managing session
                        MessageBox.Show("Logging In to the app...", "Authenticated", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        UserInfo.UserEmail    = user.Email.ToString();
                        UserInfo.UserName     = user.Firstname.ToString();
                        UserInfo.UserType     = user.UserType.ToString();
                        UserInfo.UserID       = user.UniqueID.ToString();
                        UserInfo.UserLastName = user.Lastname.ToString();

                        emailTextBox.Clear();
                        passwordTextBox.Clear();


                        if (UserInfo.UserEmail != null)
                        {
                            loginButton.Text        = "Logout";
                            emailTextBox.Enabled    = false;
                            passwordTextBox.Enabled = false;
                            registerButton.Enabled  = false;
                        }

                        if (UserInfo.UserID.StartsWith("P"))
                        {
                            PatientHomeForm patientHomeForm = new PatientHomeForm();
                            patientHomeForm.Tag = this;
                            patientHomeForm.ShowDialog(this);
                        }

                        if (UserInfo.UserID.StartsWith("L"))
                        {
                            LaboratorianDetail laboratorianDetail = databaseContext.LaboratorianDetails.Where(l => l.Laboratorian == UserInfo.UserEmail).FirstOrDefault <LaboratorianDetail>();
                            if (laboratorianDetail == null)
                            {
                                LaboratorianExtraDetailsForm laboratorianExtraDetailsForm = new LaboratorianExtraDetailsForm();
                                laboratorianExtraDetailsForm.Tag = this;
                                laboratorianExtraDetailsForm.ShowDialog(this);
                            }
                            else
                            {
                                UserInfo.IsInfoFilled        = true;
                                UserInfo.LaboratorianLabName = laboratorianDetail.WorkPlace.ToString();
                                LaboratorianHomeForm laboratorianHomeForm = new LaboratorianHomeForm();
                                laboratorianHomeForm.Tag = this;
                                laboratorianHomeForm.ShowDialog(this);
                            }
                        }

                        if (UserInfo.UserID.StartsWith("D"))
                        {
                            DocDetails docDetails = databaseContext.DocDetails.Where(a => a.Doctor == UserInfo.UserEmail).FirstOrDefault <DocDetails>();
                            if (docDetails == null)
                            {
                                DocExtraDetails docExtraDetails = new DocExtraDetails();
                                docExtraDetails.Tag = this;
                                docExtraDetails.ShowDialog(this);
                                //this.Enabled = false;
                            }
                            else
                            {
                                UserInfo.IsInfoFilled = true;
                                HomeForm homeForm = new HomeForm();
                                homeForm.Tag = this;
                                homeForm.ShowDialog(this);
                                //this.Enabled = false;
                            }
                        }


                        //Redirecting to Home Form if user gets logged in.
                    }
                    else
                    {
                        MessageBox.Show("Couldn't Sign in to the app, make sure credentials are valid", "Failed to Authenticate",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        passwordTextBox.Focus();
                    }
                }
            }
        }