public ComplaintsList(Common.Model.FacilityManager user) { InitializeComponent(); User = user; using (NorthwindContext context = new NorthwindContext()) { listview.DataSource = context.Complains.Include("User").ToList(); } }
public FacilityManager(Common.Model.FacilityManager manager) { InitializeComponent(); User = manager; using (NorthwindContext context = new NorthwindContext()) { int count = 1; var complains = context.Complains.Include("User").OrderByDescending(c => c.Time).Take(5); var pCount = complains.Count(); if (pCount == 0) { //emptyComplains.Visible = true; } // Remove list items switch (pCount) { case 0: panel2.Visible = false; //label4.Visible = true; //emptyComplains.Visible = true; break; case 1: //emptyComplains.Visible = false; panel2.Visible = true; //label4.Visible = false; five.Visible = false; four.Visible = false; three.Visible = false; two.Visible = false; break; case 2: //emptyComplains.Visible = false; panel2.Visible = true; //label4.Visible = false; five.Visible = false; four.Visible = false; three.Visible = false; break; case 3: //emptyComplains.Visible = false; //label4.Visible = false; panel2.Visible = true; five.Visible = false; four.Visible = false; break; case 4: //emptyComplains.Visible = false; //label4.Visible = false; panel2.Visible = true; five.Visible = false; break; case 5: //label4.Visible = false; panel2.Visible = true; //emptyComplains.Visible = false; // do nothing break; default: break; } // Add to list view foreach (var complain in complains) { switch (count) { case 1: oneD.Text = complain.Description; oneStatus.Text = complain.Status.ToString(); oneLocation.Text = complain.Location.ToString(); oneTime.Text = complain.Time.ToString("dddd, dd MMMM yyyy"); oneType.Text = complain.Type.ToString(); oneUser.Text = complain.User.UserName; break; case 2: twoD.Text = complain.Description; twoStatus.Text = complain.Status.ToString(); twoLocation.Text = complain.Location.ToString(); twoDate.Text = complain.Time.ToString("dddd, dd MMMM yyyy"); twoType.Text = complain.Type.ToString(); twoUser.Text = complain.User.UserName; break; case 3: threeD.Text = complain.Description; threeStatus.Text = complain.Status.ToString(); threeLocation.Text = complain.Location.ToString(); threeDate.Text = complain.Time.ToString("dddd, dd MMMM yyyy"); threeType.Text = complain.Type.ToString(); threeUser.Text = complain.User.UserName; break; case 4: fourD.Text = complain.Description; fourStatus.Text = complain.Status.ToString(); fourLocation.Text = complain.Location.ToString(); fourDate.Text = complain.Time.ToString("dddd, dd MMMM yyyy"); fourType.Text = complain.Type.ToString(); fourUser.Text = complain.User.UserName; break; case 5: fiveD.Text = complain.Description; fiveStatus.Text = complain.Status.ToString(); fiveLocation.Text = complain.Location.ToString(); fiveDate.Text = complain.Time.ToString("dddd, dd MMMM yyyy"); fiveType.Text = complain.Type.ToString(); fiveUser.Text = complain.User.UserName; break; default: // just to make sure. break; } count++; } } if (User != null) { lblUsername.Text = manager.UserName; lblEmail.Text = manager.Email; } }
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. }
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; } } } } }