private void btnlogin_Click_1(object sender, EventArgs e) { if (textBox1.Text == "" || textBox2.Text == "") { label4.Visible = true; } else { label4.Visible = false; string username = textBox1.Text; string pass = textBox2.Text; int exist = DAT.DataAccess.GetUser().Where(i => i.UserEmail == username).ToList().Count; if (exist == 0) { label4.Visible = true; } else { int correct = DAT.DataAccess.GetUser().Where(i => i.UserEmail == username && i.UserPassword == pass && i.UserActivated == true).ToList().Count; if (correct == 0) { label4.Visible = true; } else { LTS.User u = DAT.DataAccess.GetUser().Where(i => i.UserEmail == username).FirstOrDefault(); ((Form1)this.Parent.Parent).loggedIn = u; ((Form1)this.Parent.Parent).ChangeView <Pages.Main>(); } } } }
//Tiaan private void StockOut_Load(object sender, EventArgs e) { try { List <LTS.Item> item = new List <LTS.Item>(); List <LTS.Barcode> barcode = new List <LTS.Barcode>(); List <LTS.BookOut> bookOut = new List <LTS.BookOut>(); List <LTS.Product> product = new List <LTS.Product>(); List <LTS.User> user = new List <LTS.User>(); item = DAT.DataAccess.GetItem().Where(y => y.ItemStatus == false).ToList(); barcode = DAT.DataAccess.GetBarcode().ToList(); bookOut = DAT.DataAccess.GetBookOut().ToList(); product = DAT.DataAccess.GetProduct(); user = DAT.DataAccess.GetUser().ToList(); for (int i = 0; i < bookOut.Count; i++) { LTS.Item it = item.Where(a => a.ItemID == bookOut[i].ItemID).FirstOrDefault(); LTS.Product p = product.Where(r => r.ProductID == it.ProductID).FirstOrDefault(); LTS.Barcode b = barcode.Where(q => q.BarcodeID == p.BarcodeID).FirstOrDefault(); LTS.User u = user.Where(w => w.UserID == bookOut[i].UserID).FirstOrDefault(); dataGridView1.Rows.Add(bookOut[i].BookOutID, it.TagEPC, b.BarcodeNumber, p.ProductName, bookOut[i].Reason, bookOut[i].Project, bookOut[i].Date, u.UserName, u.UserSurname); } dataGridView1.ClearSelection(); } catch (Exception ex) { MessageBox.Show("Sorry Something went wrong, the action was not completed!"); } }
private void btnDeactivate_Click(object sender, EventArgs e) { try { try { LTS.User user = new LTS.User(); bool activated = false; //从数据库中获取指定用户的信息并更新 List <LTS.User> userList = new List <LTS.User>(); userList = DAT.DataAccess.GetUser().Where(o => o.UserID == int.Parse(getID)).ToList(); user.UserID = userList[0].UserID; user.UserActivated = false; user.UserAdmin = DAT.DataAccess.GetUser().Where(o => o.UserID == userList[0].UserID).FirstOrDefault().UserAdmin; user.UserEmail = DAT.DataAccess.GetUser().Where(o => o.UserID == userList[0].UserID).FirstOrDefault().UserEmail; user.UserIdentityNumber = DAT.DataAccess.GetUser().Where(o => o.UserID == userList[0].UserID).FirstOrDefault().UserIdentityNumber; user.UserName = DAT.DataAccess.GetUser().Where(o => o.UserID == userList[0].UserID).FirstOrDefault().UserSurname; user.UserSurname = DAT.DataAccess.GetUser().Where(o => o.UserID == userList[0].UserID).FirstOrDefault().UserSurname; user.UserPassword = DAT.DataAccess.GetUser().Where(o => o.UserID == userList[0].UserID).FirstOrDefault().UserPassword; bool ok; //将最新的用户信息更新到数据库 ok = DAT.DataAccess.UpdateUser(user); if (ok == false) { if (DialogResult.OK == MessageBox.Show("There was something wrong, the User was not Deactivated!")) { ((Main)this.Parent.Parent).ChangeView <DeactivateUser>(); } } else { if (DialogResult.OK == MessageBox.Show("The User was Deactivated successfully!")) { ((Main)this.Parent.Parent).ChangeView <DeactivateUser>(); } } } catch (Exception ex) { MessageBox.Show("The User was not Deactivated successfully!"); ((Main)this.Parent.Parent).ChangeView <DeactivateUser>(); } } catch (Exception ex) { MessageBox.Show("Sorry Something went wrong, the action was not completed!"); } }
public static LTS.User GetUserItemByID(int?UserID) { LTS.User user = new LTS.User(); try { using (LTS.LTSBase access = new LTS.LTSDC()) { user = access.User.Where(o => o.UserID == UserID).FirstOrDefault(); } } catch (Exception ex) { } return(user); }
public static int AddUser(LTS.User user) { int?UserID = -1; try { using (LTS.LTSBase access = new LTS.LTSDC()) { access.InsertUser(user.UserActivated, user.UserAdmin, user.UserEmail, user.UserIdentityNumber, user.UserName, user.UserPassword, user.UserSurname, ref UserID); } } catch (Exception ex) { } return(UserID.Value); }
public static bool UpdateUser(LTS.User user) { bool completed = false; try { using (LTS.LTSBase access = new LTS.LTSDC()) { access.UpdateUser(user.UserActivated, user.UserAdmin, user.UserEmail, user.UserIdentityNumber, user.UserName, user.UserPassword, user.UserSurname, user.UserID); completed = true; } } catch (Exception ex) { completed = false; } return(completed); }
//将提取dgv上的信息到信息框中 private void dgvUser_SelectionChanged(object sender, EventArgs e) { try { lblAdmin.Visible = false; cbAdmin.Enabled = true; cbActivated.Enabled = true; if (dgvUser.SelectedRows.Count == 1) { using (DataGridViewRow item = this.dgvUser.SelectedRows[0]) { int i = item.Index; lblUserID.Text = dgvUser.Rows[i].Cells[0].Value.ToString(); current = DAT.DataAccess.GetUser().Where(u => u.UserID == int.Parse(lblUserID.Text)).FirstOrDefault(); List <LTS.User> getPass = DAT.DataAccess.GetUser().Where(o => o.UserID == int.Parse(lblUserID.Text)).ToList(); tbIDentityNo.Text = dgvUser.Rows[i].Cells[1].Value.ToString(); tbName.Text = dgvUser.Rows[i].Cells[2].Value.ToString(); tbSurname.Text = dgvUser.Rows[i].Cells[3].Value.ToString(); tbEmail.Text = dgvUser.Rows[i].Cells[4].Value.ToString(); tbPassword.Text = getPass[0].UserPassword; cbAdmin.SelectedItem = dgvUser.Rows[i].Cells[5].Value.ToString(); cbActivated.SelectedItem = dgvUser.Rows[i].Cells[6].Value.ToString(); int amountAdmin = us.Where(u => u.UserActivated == true && u.UserAdmin == true).ToList().Count; if (amountAdmin <= 2 && cbAdmin.SelectedItem.ToString() == "Yes" && cbActivated.SelectedItem.ToString() == "Yes") { cbAdmin.Enabled = false; cbActivated.Enabled = false; lblAdmin.Visible = true; } } } emailUpdateCheckCompare = tbEmail.Text; } catch (Exception ex) { MessageBox.Show("There is something wrong, the process can not completed."); } }
//Margo private void StockBookOutRemoval_Load(object sender, EventArgs e) { try { st = DAT.DataAccess.GetStore().ToList(); List <string> S = new List <string>(); for (int x = 0; x < st.Count; x++) { S.Add(st[x].StoreName); } comboBoxStore.DataSource = S; List <LTS.BookOut> bo = new List <LTS.BookOut>(); bo = DAT.DataAccess.GetBookOut().ToList(); for (int i = 0; i < bo.Count; i++) { BookOutMain b = new BookOutMain(); b.BookOutID = bo[i].BookOutID; b.itemID = bo[i].ItemID; b.UserID = bo[i].UserID; b.Reason = bo[i].Reason; b.Project = bo[i].Project; b.Date = bo[i].Date; LTS.Item it = new LTS.Item(); it = DAT.DataAccess.GetItem().Where(u => u.ItemID == b.itemID).FirstOrDefault(); b.ItemStatus = it.ItemStatus; b.EPC = it.TagEPC; b.ProductID = it.ProductID; b.StoreID = it.StoreID; //get the specific product and assign the info to the ItemMain object LTS.Product p = new LTS.Product(); p = DAT.DataAccess.GetProduct().Where(h => h.ProductID == b.ProductID).FirstOrDefault(); b.ProductName = p.ProductName; b.ProductDescription = p.ProductDescription; b.BrandID = p.BrandID; b.CategoryID = p.CategoryID; b.BarcodeID = p.BarcodeID; //get the specific store and assign the info to the ItemMain object LTS.Store s = new LTS.Store(); s = DAT.DataAccess.GetStore().Where(j => j.StoreID == b.StoreID).FirstOrDefault(); b.StoreName = s.StoreName; b.StoreLocation = s.StoreLocation; //get the specific brand and assign the info to the ItemMain object LTS.Brand br = new LTS.Brand(); br = DAT.DataAccess.GetBrand().Where(y => y.BrandID == b.BrandID).FirstOrDefault(); b.BrandName = br.BrandName; b.BrandDescription = br.BrandDescription; //get the sepcific category and assign the info to the ItemMain object LTS.Category c = new LTS.Category(); c = DAT.DataAccess.GetCategory().Where(z => z.CategoryID == b.CategoryID).FirstOrDefault(); b.CategoryName = c.CategoryName; b.CategoryDescription = c.CategoryDescription; //get the sepcific category and assign the info to the ItemMain object LTS.Barcode ba = new LTS.Barcode(); ba = DAT.DataAccess.GetBarcode().Where(a => a.BarcodeID == b.BarcodeID).FirstOrDefault(); b.BarcodeNumber = ba.BarcodeNumber; LTS.User us = new LTS.User(); us = DAT.DataAccess.GetUser().Where(h => h.UserID == b.UserID).FirstOrDefault(); b.UserIdentityNumber = us.UserIdentityNumber; b.UserName = us.UserName; b.UserSurname = us.UserSurname; bom.Add(b); dataGridView1.Rows.Add(b.BookOutID, b.EPC, b.BarcodeNumber, b.ProductName, b.Reason, b.Project, b.Date, b.UserName, b.UserSurname); } } catch (Exception ex) { MessageBox.Show("Sorry Something went wrong, the action was not completed!"); } }
//Marius private void UpdateMyAccount_Load(object sender, EventArgs e) { try { lblAdmin.Visible = false; lblEmail.Visible = false; lblIdentityNo.Visible = false; lblName.Visible = false; lblPassword.Visible = false; lblSurname.Visible = false; //Margo if (((Form1)this.Parent.Parent.Parent.Parent).loggedIn.UserAdmin == false) { cbAdmin.Enabled = false; cbActivated.Enabled = false; } int amountAdmin = DAT.DataAccess.GetUser().Where(u => u.UserActivated == true && u.UserAdmin == true).ToList().Count; if (amountAdmin <= 2 && ((Form1)this.Parent.Parent.Parent.Parent).loggedIn.UserAdmin == true) { cbAdmin.Enabled = false; cbActivated.Enabled = false; lblAdmin.Visible = true; } List <string> ComboVal = new List <string>(); ComboVal.Add("Yes"); ComboVal.Add("No"); List <string> ComboVal2 = new List <string>(); ComboVal2.Add("Yes"); ComboVal2.Add("No"); cbAdmin.DataSource = ComboVal; cbActivated.DataSource = ComboVal2; lblUserID.Text = ((Form1)this.Parent.Parent.Parent.Parent).loggedIn.UserID.ToString(); LTS.User user = ((Form1)this.Parent.Parent.Parent.Parent).loggedIn; tbPassword.Text = user.UserPassword; tbIdentityNo.Text = user.UserIdentityNumber; tbName.Text = user.UserName; tbSurname.Text = user.UserSurname; tbEmail.Text = user.UserEmail; string isAdminActivated = ""; string isUserActivated = ""; if (user.UserAdmin == true) { isAdminActivated = "Yes"; } else { isAdminActivated = "No"; } if (user.UserActivated == true) { isUserActivated = "Yes"; } else { isUserActivated = "No"; } cbAdmin.Text = isAdminActivated; cbActivated.Text = isUserActivated; emailUpdateCheckCompare = tbEmail.Text; } catch (Exception ex) { MessageBox.Show("Sorry Something went wrong, the action was not completed!"); } }
//Marius private void btnUpdate_Click(object sender, EventArgs e) { try { try { lblSurname.Visible = false; lblPassword.Visible = false; lblName.Visible = false; lblIdentityNo.Visible = false; lblEmail.Visible = false; LTS.User user = new LTS.User(); user.UserID = int.Parse(lblUserID.Text); user.UserName = tbName.Text; user.UserIdentityNumber = tbIdentityNo.Text; user.UserSurname = tbSurname.Text; user.UserPassword = tbPassword.Text; List <string> emailList = new List <string>(); List <LTS.User> listEmail = new List <LTS.User>(); listEmail = DAT.DataAccess.GetUser().ToList(); for (int b = 0; b < listEmail.Count; b++) { emailList.Add(listEmail[b].UserEmail); } if (!(emailList.Contains(tbEmail.Text)) || emailUpdateCheck == emailUpdateCheckCompare) { user.UserEmail = tbEmail.Text; } else { lblEmail.Visible = true; lblEmail.Text = "The email already exists"; } if (cbAdmin.SelectedItem.Equals("Yes")) { user.UserAdmin = true; } else { user.UserAdmin = false; } if (cbActivated.SelectedItem.Equals("Yes")) { user.UserActivated = true; } else { user.UserActivated = false; } //Validation checks if (tbIdentityNo.Text == "" || tbIdentityNo.Text.Length < 13 || !IsDigitsOnly(tbIdentityNo.Text)) { lblIdentityNo.Visible = true; lblIdentityNo.Text = "Please enter a valid ID number"; } if (tbName.Text == "") { lblName.Visible = true; lblName.Text = "Please enter a name"; } if (tbSurname.Text == "") { lblSurname.Visible = true; lblSurname.Text = "Please enter a surname"; } if (tbEmail.Text == "" || !Regex.IsMatch(tbEmail.Text, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase)) { lblEmail.Visible = true; lblEmail.Text = "Please enter a valid email"; } if (tbPassword.Text == "") { lblPassword.Visible = true; lblPassword.Text = "Please enter a valid password"; } bool ok = false; if (lblEmail.Visible == false && lblIdentityNo.Visible == false && lblName.Visible == false && lblSurname.Visible == false && lblPassword.Visible == false) { ok = DAT.DataAccess.UpdateUser(user); } if (ok == false) { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the User was not Updated!")) { } } else { if (DialogResult.OK == MessageBox.Show("The User was updated successfully!")) { ((Main)this.Parent.Parent).ChangeView <UpdateMyAccount>(); } } } catch (Exception ex) { if (DialogResult.OK == MessageBox.Show("The User was not updated successfully!")) { ((Main)this.Parent.Parent).ChangeView <UpdateMyAccount>(); } } } catch (Exception ex) { MessageBox.Show("Sorry Something went wrong, the action was not completed!"); } }
//Devon private void btnlogin_Click(object sender, EventArgs e) { try { label11.Visible = false; lblName.Visible = false; lblSurname.Visible = false; lblEmail.Visible = false; lblPassword.Visible = false; bool itsOK = false; try { if (txtName.Text == "" || txtName.Text.Length < 13 || !IsDigitsOnly(txtName.Text)) { label11.Visible = true; } if (txtSur.Text == "") { lblName.Visible = true; } if (txtEmail.Text == "") { lblSurname.Visible = true; } if (txtUsername.Text == "" || !Regex.IsMatch(txtUsername.Text, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase)) { lblEmail.Visible = true; } if (textBox1.Text == "") { lblPassword.Visible = true; } if (label11.Visible == false && lblName.Visible == false && lblSurname.Visible == false && lblEmail.Visible == false && lblPassword.Visible == false) { LTS.User user = new LTS.User(); LTS.User checkID = DAT.DataAccess.GetUser().Where(u => u.UserIdentityNumber == txtName.Text).FirstOrDefault(); if (checkID == null) { user.UserIdentityNumber = txtName.Text; label3.Visible = false; } else { label3.Visible = true; itsOK = true; } LTS.User checkEmail = DAT.DataAccess.GetUser().Where(u => u.UserEmail.ToString() == txtUsername.Text).FirstOrDefault(); if (checkEmail == null) { label4.Visible = false; user.UserEmail = txtUsername.Text; } else { label4.Visible = true; itsOK = true; } user.UserName = txtSur.Text; user.UserSurname = txtEmail.Text; user.UserPassword = textBox1.Text; if (comboBoxAdmin.SelectedItem.Equals("Yes")) { user.UserAdmin = true; } else { user.UserAdmin = false; } if (comboBoxActiv.SelectedItem.Equals("Yes")) { user.UserActivated = true; } else { user.UserActivated = false; } if (itsOK == false) { int userID = DAT.DataAccess.AddUser(user); if (userID == -1) { if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the User was not Added!")) { } } else { MessageBox.Show("The User was added successfully!"); ((Main)this.Parent.Parent).ChangeView <Pages.Users>(); } } } } catch (Exception ex) { MessageBox.Show("Sorry Something went wrong, the action was not completed!"); } } catch (Exception ex) { MessageBox.Show("Sorry Something went wrong, the action was not completed!"); } }