Exemplo n.º 1
0
        private void BunifuImageButton1_Click(object sender, EventArgs e)
        {
            MainUser form = new MainUser(User);

            form.Tag = User;
            form.Show();
            this.Hide();
        }
Exemplo n.º 2
0
        private void BunifuImageButton2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtDescription.Text.Trim()))
            {
                lblError.Visible = true;
            }
            else
            {
                lblError.Visible = false;
                // Get data and send to Db.
                var complain = new Common.Model.Complain
                {
                    Description = txtDescription.Text,
                    Type        = (Common.ComplainType)Enum.Parse(typeof(Common.ComplainType), dropdownType.Text),
                    Location    = (Common.Location)Enum.Parse(typeof(Common.Location), dropdownLocaton.Text),
                    Status      = (Common.ComplainStatus)Enum.Parse(typeof(Common.ComplainStatus), dropdownStatus.Text),
                    Time        = datepickerDate.Value
                };

                using (NorthwindContext context = new NorthwindContext())
                {
                    var user = context.Users.Include("Complains").Where(u => u.UserName == User.UserName).ToList()[0];
                    user.Complains.Add(complain);
                    context.SaveChanges();
                }

                // navigate to new page.
                Timer timer = new Timer
                {
                    Interval = 3800,
                    Enabled  = true
                };
                timer.Tick += (obj, args) =>
                {
                    timer.Enabled = false;
                    MainUser form = new MainUser(User);
                    form.Show();
                    Hide();
                };
                complaintSubmitedPanel.Visible = true;
                timer.Start();
            }
        }
Exemplo n.º 3
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.
        }
Exemplo n.º 4
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;
                        }
                    }
                }
            }
        }