コード例 #1
0
ファイル: ComplaintsList.cs プロジェクト: ebresafegaga/CSC221
        private void BunifuImageButton1_Click(object sender, EventArgs e)
        {
            // Go to facility page and pass tag around
            FacilityManager form = new FacilityManager(User);

            form.Show();
            _filters.Clear();
            Hide();
        }
コード例 #2
0
        private async void BunifuFlatButton1_Click(object sender, EventArgs e)
        {
            // Sign up
            if (this.dropUserType.Text == "Main User")
            {
                Common.Model.MainUser user = new Common.Model.MainUser
                {
                    Email         = txtEmail.Text.Trim().ToLower(),
                    UserName      = txtUserName.Text.Trim().ToLower(),
                    Password      = txtPassword.Text.Trim().GetHashCode(),
                    PasswordCheck = txtPasswordCheck.Text.Trim().GetHashCode()
                };

                if (user.Validate())
                {
                    // valid details
                    Console.WriteLine("Valid");
                    this.lblErrorSignup.Visible = false;

                    var btn = sender as BunifuFlatButton;
                    btn.BackColor  = Color.Gray;
                    btn.Enabled    = false;
                    label5.Enabled = false;

                    //signupProgress.Visible = true;
                    //Timer t = new Timer
                    //{
                    //    Interval = 10,
                    //    Enabled = true
                    //};

                    //t.Tick += (obj, args) =>
                    //{
                    //    if (signupProgress.Value <= 99)
                    //    {
                    //        signupProgress.Value += 1;
                    //    }
                    //    else
                    //    {
                    //        t.Enabled = false;
                    //    }
                    //};
                    //t.Start();


                    // Add user to  DB and log in
                    using (NorthwindContext context = new NorthwindContext())
                    {
                        await Task.Factory.StartNew(() => context.Users.Add(user));

                        //Task task = new Task(() => context.Users.Add(user));
                        await context.SaveChangesAsync();
                    }
                    // pass data to MainUser
                    MainUser form = new MainUser(user);
                    form.Show();
                    Hide();
                }
                else
                {
                    // invalid
                    Console.WriteLine("Invalid");
                    this.lblErrorSignup.Visible = true;
                }
            }
            if (this.dropUserType.Text == "Facility Manager")
            {
                Common.Model.FacilityManager user = new Common.Model.FacilityManager
                {
                    Email         = txtEmail.Text.Trim().ToLower(),
                    UserName      = txtUserName.Text.Trim().ToLower(),
                    Password      = txtPassword.Text.Trim().GetHashCode(),
                    PasswordCheck = txtPasswordCheck.Text.Trim().GetHashCode()
                };

                if (user.Validate())
                {
                    // valid
                    Console.WriteLine("Valid");
                    this.lblErrorSignup.Visible = false;

                    var btn = sender as BunifuFlatButton;
                    btn.BackColor  = Color.Gray;
                    btn.Enabled    = false;
                    label5.Enabled = false;

                    // Log user in
                    using (NorthwindContext context = new NorthwindContext())
                    {
                        // TODO: show a loading page
                        await Task.Factory.StartNew(() => context.Managers.Add(user));

                        await context.SaveChangesAsync();
                    }

                    // pass data
                    FacilityManager form = new FacilityManager(user);
                    form.Show();
                    this.Hide();
                }
                else
                {
                    // invalid

                    Console.WriteLine("Invalid");
                    this.lblErrorSignup.Visible = true;
                }
            }
            // TODO: Ask for number if facility manager.
        }
コード例 #3
0
        private async void BunifuFlatButton2_Click(object sender, EventArgs e)
        {
            //Log in
            if (dropdownLogin.Text == "Main User")
            {
                // TODO: Log in user with details from panel 2.
                if (!(string.IsNullOrWhiteSpace(loginID.Text) && string.IsNullOrWhiteSpace(loginPass.Text)))
                {
                    var btn = sender as BunifuFlatButton;
                    btn.BackColor  = Color.Gray;
                    btn.Enabled    = false;
                    label3.Enabled = false;

                    var user = new Common.Model.MainUser
                    {
                        UserName = loginID.Text.Trim(),
                        Password = loginPass.Text.GetHashCode()
                    };
                    //Remove error message
                    lblErrorLogin.Visible = false;
                    using (NorthwindContext context = new NorthwindContext())
                    {
                        //List<Common.Model.MainUser> users;
                        var users = await context.Users.Where(u => u.UserName == user.UserName).ToListAsync();

                        //Task task = new Task(() =>
                        //{
                        //    users = context.Users.Where(u => u.UserName == user.UserName).ToList();
                        //});

                        //var pUsers = from u in context.Users
                        //             where u.UserName == user.UserName
                        //             select u;

                        if (users.Count != 0)
                        {
                            // check password
                            if (user.Password == users.FirstOrDefault().Password)
                            {
                                lblBadlogin.Visible = false;
                                MainUser form = new MainUser(users.ToArray()[0]);
                                form.Show();
                                this.Hide();
                            }
                            else
                            {
                                // wrong password
                                Console.WriteLine("Wrong password");
                                lblBadlogin.Text    = "Wrong password";
                                lblBadlogin.Visible = true;
                                label3.Enabled      = true;
                                btn.Enabled         = true;
                            }
                        }
                        else
                        {
                            //user not found
                            Console.WriteLine("Invalid user name or password");
                            lblBadlogin.Text    = "Invalid Username";
                            lblBadlogin.Visible = true;
                            label3.Enabled      = true;
                            btn.Enabled         = true;
                        }
                    }
                }
                else
                {
                    //show error message
                    lblErrorLogin.Visible = true;
                }
            }
            else
            {
                // Facility manager log in

                if (!(string.IsNullOrWhiteSpace(loginID.Text) && string.IsNullOrWhiteSpace(loginPass.Text)))
                {
                    var btn = sender as BunifuFlatButton;
                    btn.BackColor  = Color.Gray;
                    btn.Enabled    = false;
                    label3.Enabled = false;

                    var user = new Common.Model.FacilityManager
                    {
                        UserName = loginID.Text.Trim(),
                        Password = loginPass.Text.GetHashCode()
                    };

                    //Remove error message
                    lblErrorLogin.Visible = false;
                    using (NorthwindContext context = new NorthwindContext())
                    {
                        var users = await context.Managers.Where(u => u.UserName == user.UserName).ToListAsync();

                        if (users.Count != 0)
                        {
                            // check password
                            if (user.Password == users.FirstOrDefault().Password)
                            {
                                lblBadlogin.Visible = false;
                                FacilityManager form = new FacilityManager(users.ToArray()[0]);
                                form.Show();
                                this.Hide();
                            }
                            else
                            {
                                // wrong password
                                Console.WriteLine("Wrong password");
                                lblBadlogin.Text    = "Wrong password";
                                lblBadlogin.Visible = true;
                                btn.Enabled         = true;
                                label3.Enabled      = true;
                            }
                        }
                        else
                        {
                            //user not found
                            Console.WriteLine("Invalid user name or password");
                            lblBadlogin.Text    = "Invalid Username";
                            lblBadlogin.Visible = true;
                            btn.Enabled         = true;
                            label3.Enabled      = true;
                        }
                    }
                }
            }
        }