private void bntDel_Click(object sender, RoutedEventArgs e) { if (lvDataCustomer.SelectedItem == null) { MessageBox.Show("Customer must be selected to delete! Choose again!"); return; } var delCus = lvDataCustomer.SelectedItem as Customer; if (delCus != null) { MessageBoxResult delMess = MessageBox.Show("Do you want to delete " + delCus.Name + "(" + delCus.CusId + ")?", "Warning! Are you sure?", MessageBoxButton.YesNo); if (delMess == MessageBoxResult.Yes) { delCus.Deleted = 1; _unitofwork.CustomerRepository.Update(delCus); _unitofwork.Save(); allcus = _unitofwork.CustomerRepository.Get(x => x.Deleted.Equals(0)).ToList(); lvDataCustomer.ItemsSource = allcus; lvDataCustomer.UnselectAll(); lvDataCustomer.Items.Refresh(); } } else { MessageBox.Show("Please choose customer you want to delete and try again!"); } }
private void bntDel_Click(object sender, RoutedEventArgs e) { if (lvDataEmployee.SelectedItem == null) { MessageBox.Show("Employee must be selected to delete! Choose again!"); return; } var delEmp = lvDataEmployee.SelectedItem as Employee; if (delEmp != null) { MessageBoxResult delMess = MessageBox.Show("Do you want to delete " + delEmp.Name + "(" + delEmp.Username + ")?", "Warning! Are you sure?", MessageBoxButton.YesNo); if (delMess == MessageBoxResult.Yes) { delEmp.Deleted = 1; _unitofork.EmployeeRepository.Update(delEmp); _unitofork.Save(); empwithad = _unitofork.EmployeeRepository.Get(x => x.Manager.Equals(admin.AdId) && x.Deleted.Equals(0)).ToList(); lvDataEmployee.ItemsSource = empwithad; lvDataEmployee.UnselectAll(); lvDataEmployee.Items.Refresh(); } } else { MessageBox.Show("Please choose employee you want to delete and try again!"); } }
private void btnOk_Click(object sender, RoutedEventArgs e) { string oldPass = txtPass.Password.Trim(); if (!oldPass.Equals(_admin.Pass)) { MessageBox.Show("Your old password is incorrect!"); txtPass.Focus(); return; } string newPass = txtNewPass.Password.Trim(); if (newPass.Length == 0 || newPass.Length > 50) { MessageBox.Show("New password is not valid!"); txtNewPass.Focus(); return; } string passcon = txtConNew.Password.Trim(); if (!passcon.Equals(newPass)) { MessageBox.Show("Confirm new password is not match!"); txtConNew.Focus(); return; } _admin.Pass = newPass; _unitofwork.AdminreRepository.Update(_admin); _unitofwork.Save(); MessageBox.Show("Your password was changed!"); this.Close(); }
private void BntAdd_OnClick(object sender, RoutedEventArgs e) { try { if (ErrorDetailsItem.Count != 0) { MessageBox.Show("Something is not correct. Please check all your input again!"); return; } if (CurrentReceipt.ReceiptNoteDetails.Count == 0) { MessageBox.Show("You have to choose the ingredient you want to input before add"); return; } // check if the Receipt Note have input Other Perchagse, must require the Note foreach (var details in CurrentReceipt.ReceiptNoteDetails.ToList()) { if (details.IgdId.Equals(ORTHER_PERCHAGSE_ID) && string.IsNullOrEmpty(details.Note)) { MessageBox.Show( "You have inputed the \"Orther Purchase\" in your Receipt. Please input the detail description in note before save data!"); return; } } CurrentReceipt.Inday = DateTime.Now; _unitofwork.ReceiptNoteRepository.Insert(CurrentReceipt); //ToDo: Update the contain value in Warehouse database UpdateWareHouseContain(); _unitofwork.Save(); ReceiptDetailsList = new List <ReceiptNoteDetail>(); lvDataReceipt.ItemsSource = ReceiptDetailsList; lvDataReceipt.Items.Refresh(); CurrentReceipt = new ReceiptNote() { EmpId = (App.Current.Properties["EmpLogin"] as Employee).EmpId, ReceiptNoteDetails = ReceiptDetailsList }; LoadReceiptData(); } catch (Exception ex) { MessageBox.Show("Something went wrong when trying to input the new Receipt! May be you should reload this app or call for support!"); } }
private void bntDelPro_Click(object sender, RoutedEventArgs e) { Product delPro = lvProduct.SelectedItem as Product; if (delPro == null) { MessageBox.Show("Please choose exactly which product you want to delete!"); return; } MessageBoxResult delMess = MessageBox.Show("This action will delete all following product details! Do you want to delete " + delPro.Name + "(" + delPro.ProductId + ")?", "Warning! Are you sure?", MessageBoxButton.YesNo); if (delMess == MessageBoxResult.Yes) { delPro.Deleted = 1; var pdofingre = _unitofwork.ProductDetailsRepository.Get(x => x.ProductId.Equals(delPro.ProductId)).ToList(); if (pdofingre.Count != 0) { foreach (var pd in pdofingre) { _unitofwork.ProductDetailsRepository.Delete(pd); } _unitofwork.Save(); } _unitofwork.ProductRepository.Update(delPro); _unitofwork.Save(); lvProduct.ItemsSource = _unitofwork.ProductRepository.Get(c => c.Deleted.Equals(0)); lvDetails.ItemsSource = _unitofwork.ProductDetailsRepository.Get(includeProperties: "Product"); lvIngredient.ItemsSource = _unitofwork.IngredientRepository.Get(x => x.Deleted.Equals(0)).ToList(); lvProduct.UnselectAll(); lvProduct.Items.Refresh(); lvDetails.UnselectAll(); lvDetails.Items.Refresh(); lvIngredient.UnselectAll(); lvIngredient.Items.Refresh(); } }
private void bntUpdate_Click(object sender, RoutedEventArgs e) { //check name string namee = txtName.Text.Trim(); if (namee.Length == 0 || namee.Length > 50) { MessageBox.Show("Name is not valid!"); txtName.Focus(); return; } admin.Name = namee; //admin.Employees.Clear(); _unitofwork.AdminreRepository.Update(admin); _unitofwork.Save(); }
private void btnAddNew_Click(object sender, RoutedEventArgs e) { try { string username = txtUsername.Text.Trim(); string pass = txtPass.Password.Trim(); //check username if (username.Length == 0 || username.Length > 50) { MessageBox.Show("Username is not valid!"); txtUsername.Focus(); return; } if (_emp == null) { var newemp = _unitofwork.EmployeeRepository.Get(x => x.Username.Equals(username)).ToList(); if (newemp.Count != 0) { MessageBox.Show("Username is already exist! Please try again!"); txtUsername.Focus(); return; } } //check pass if (pass.Length == 0 || pass.Length > 50) { MessageBox.Show("Password is not valid!"); txtPass.Focus(); return; } string passcon = txtCon.Password.Trim(); if (!passcon.Equals(pass)) { MessageBox.Show("Confirm password is not match!"); txtCon.Focus(); return; } //check name string namee = txtName.Text.Trim(); if (namee.Length == 0 || namee.Length > 50) { MessageBox.Show("Name is not valid!"); txtName.Focus(); return; } //check role int role = 0; if (cboRole.SelectedValue == null) { MessageBox.Show("Role must be selected!"); return; } role = (int)cboRole.SelectedValue; //check birth if (txtBirth.SelectedDate == null) { MessageBox.Show("Birth must be selected!"); return; } DateTime birth = txtBirth.SelectedDate.Value; if (DateTime.Now.Year - birth.Year < 17) { MessageBox.Show("Employee's age must higher than 17!"); return; } //check address string addr = txtAddress.Text; if (addr.Length > 200) { MessageBox.Show("Address is not valid!"); txtAddress.Focus(); return; } //check phone string phone = txtPhone.Text; if (phone.Length > 20) { MessageBox.Show("Phone is not valid!"); txtPhone.Focus(); return; } //check email string email = txtMail.Text; if (!Regex.IsMatch(email, "[\\w\\d]+[@][\\w]+[.][\\w]+")) { MessageBox.Show("Email is not valid!"); txtMail.Focus(); return; } //check start day if (txtStartDay.SelectedDate == null) { MessageBox.Show("Start Day must be selected!"); return; } DateTime start = txtStartDay.SelectedDate.Value; //check hour wage int hourwage = int.Parse(txtHour_wage.Text.Trim()); if (hourwage <= 0 || hourwage >= int.MaxValue) { MessageBox.Show("Hour wage is not valid! Hour wage must be greater than 0 and lesser than " + int.MaxValue); txtHour_wage.Focus(); return; } //check code string code = txtCode.Password.Trim(); if (code.Length < 4) { MessageBox.Show("Employee code should be stronger!"); txtCode.Focus(); return; } // Adding if (_emp.EmpId == null) { Employee checkemp = new Employee() { EmpId = "", Username = username, Pass = pass, Name = namee, EmpRole = role, Birth = birth, Addr = addr, Phone = phone, Email = email, Startday = start, HourWage = hourwage, EmpCode = code, Deleted = 0, Manager = (App.Current.Properties["AdLogin"] as AdminRe).AdId }; _unitofwork.EmployeeRepository.Insert(checkemp); _unitofwork.Save(); MessageBox.Show("Insert " + checkemp.Name + "(" + checkemp.EmpId + ") successful!"); this.Close(); } else //Updating { _emp.Username = username; _emp.Pass = pass; _emp.Name = namee; _emp.EmpRole = role; _emp.Birth = birth; _emp.Addr = addr; _emp.Phone = phone; _emp.Email = email; _emp.Startday = start; _emp.HourWage = hourwage; _emp.EmpCode = code; _unitofwork.EmployeeRepository.Update(_emp); _unitofwork.Save(); MessageBox.Show("Update " + _emp.Name + "(" + _emp.EmpId + ") successful!"); this.Close(); } } catch (Exception ex) { MessageBox.Show("Something went wrong. Can not add or update employee. Please check the details again!"); } }
private void BtnAdd_OnClick(object sender, RoutedEventArgs e) { try { string username = txtUsername.Text.Trim(); string pass = txtPass.Password.Trim(); //check username if (username.Length == 0 || username.Length > 50) { MessageBox.Show("Username is not valid!"); txtUsername.Focus(); return; } var newemp = _unitofwork.EmployeeRepository.Get(x => x.Username.Equals(username)).ToList(); if (newemp.Count != 0) { MessageBox.Show("Username is already exist! Please try again!"); txtUsername.Focus(); return; } //check pass if (pass.Length == 0 || pass.Length > 50) { MessageBox.Show("Password is not valid!"); txtPass.Focus(); return; } string passcon = txtCon.Password.Trim(); if (!passcon.Equals(pass)) { MessageBox.Show("Confirm password is not match!"); txtCon.Focus(); return; } //check name string name = txtName.Text.Trim(); if (name.Length == 0 || name.Length > 50) { MessageBox.Show("Name is not valid!"); txtName.Focus(); return; } //check role int role = 0; if (cboRole.SelectedValue == null) { MessageBox.Show("Role must be selected!"); return; } role = (int)cboRole.SelectedValue; if (role == 0) { MessageBox.Show("Role must be selected!"); return; } // Adding AdminRe newAd = new AdminRe() { AdId = "", Username = username, Pass = pass, Name = name, AdRole = role }; _unitofwork.AdminreRepository.Insert(newAd); _unitofwork.Save(); MessageBox.Show("Insert " + newAd.Name + "(" + newAd.AdId + ") successful!"); this.Close(); } catch (Exception ex) { MessageBox.Show("Something went wrong. Can not add or update admin info. Please check the details again!"); } }
private void btnUpdate_Click(object sender, RoutedEventArgs e) { try { if (PDTempData.pdtList.Count() != 0) { foreach (var pd in PDTempData.pdtList) { if (pd.ProDe.UnitUse.Equals("") || pd.ProDe.UnitUse == null || pd.ProDe.Quan < 1) { MessageBox.Show("Please check information of " + pd.Ingre.Name + " again! Something is not valid!"); return; } } } //check name string name = txtName.Text.Trim(); if (name.Length == 0) { MessageBox.Show("Name is not valid!"); txtName.Focus(); return; } //check info string info = txtInfo.Text.Trim(); //check type int type = (int)cboType.SelectedItem; //check imagename string imgname = txtImageName.Text.Trim(); if (imgname.Length == 0) { MessageBox.Show("Please choose a image to continue!"); btnLinkImg.Focus(); return; } //check discount // //check standard status string stdstt = cboStatus.SelectedItem.ToString(); //check price decimal price = 0; if (string.IsNullOrEmpty(txtPrice.Text.Trim())) { price = decimal.Parse(txtSusggestPrice.Text.Trim()); } else { price = decimal.Parse(txtPrice.Text.Trim()); } _currentProduct.Name = name; _currentProduct.Info = info; _currentProduct.Type = type; _currentProduct.ImageLink = imgname; _currentProduct.Discount = 0; _currentProduct.StandardStats = stdstt; _currentProduct.Price = price; string destinationFile = startupProjectPath + "\\Images\\Products" + txtImageName.Text.Trim(); try { if (!string.IsNullOrEmpty(browseImagePath)) { File.Delete(destinationFile); File.Copy(browseImagePath, destinationFile); } } catch (Exception ex) { MessageBox.Show(ex.Message); } _unitofwork.ProductRepository.Update(_currentProduct); _unitofwork.Save(); if (PDTempData.pdtList.Count() != 0) { foreach (var pd in _proDe) { _unitofwork.ProductDetailsRepository.Delete(pd); } _unitofwork.Save(); foreach (var pd in PDTempData.pdtList) { pd.ProDe.ProductId = _currentProduct.ProductId; pd.ProDe.IgdId = pd.Ingre.IgdId; _unitofwork.ProductDetailsRepository.Insert(pd.ProDe); _unitofwork.Save(); } } MessageBox.Show("Update product " + _currentProduct.Name + "(" + _currentProduct.ProductId + ") successful!"); ClearAllData(); } catch (Exception ex) { MessageBox.Show("Something went wrong. Can not update product. Please check again!"); } }
private void bntAddnew_Click(object sender, RoutedEventArgs e) { //check name string namee = txtName.Text.Trim(); if (namee.Length == 0 || namee.Length > 50) { MessageBox.Show("Name is not valid!"); txtName.Focus(); return; } //check phone string phone = txtPhone.Text.Trim(); if (phone.Length == 0 || phone.Length > 20) { MessageBox.Show("Phone is not valid!"); txtPhone.Focus(); return; } //check email string email = txtMail.Text.Trim(); if (!Regex.IsMatch(email, "[\\w\\d]+[@][\\w]+[.][\\w]+")) { MessageBox.Show("Email is not valid!"); txtMail.Focus(); return; } //check discount int discount = int.Parse(txtDiscount.Text.Trim()); if (discount < 0 || discount > 100) { MessageBox.Show("Discount value is not valid!"); txtDiscount.Focus(); return; } if (_cus == null) //insert { Customer checkcus = new Customer { CusId = "", Name = namee, Email = email, Phone = phone, Discount = discount, Deleted = 0 }; _unitofwork.CustomerRepository.Insert(checkcus); _unitofwork.Save(); MessageBox.Show("Insert " + checkcus.Name + "(" + checkcus.CusId + ") successful!"); this.Close(); } else //update { _cus.Name = namee; _cus.Email = email; _cus.Phone = phone; _cus.Discount = discount; _cus.Deleted = 0; _unitofwork.CustomerRepository.Update(_cus); _unitofwork.Save(); MessageBox.Show("Update " + _cus.Name + "(" + _cus.CusId + ") successful!"); this.Close(); } }
private void btnAdd_Click(object sender, RoutedEventArgs e) { try { if (PDTempData.pdtList.Count() != 0) { foreach (var pd in PDTempData.pdtList) { if (pd.ProDe.UnitUse.Equals("") || pd.ProDe.UnitUse == null || pd.ProDe.Quan < 1) { MessageBox.Show("Please check information of " + pd.Ingre.Name + " again! Something is not valid!"); return; } } } //check name string name = txtName.Text.Trim(); if (name.Length == 0) { MessageBox.Show("Name is not valid!"); txtName.Focus(); return; } //check info string info = txtInfo.Text.Trim(); //check type int type = (int)cboType.SelectedItem; //check imagename string imgname = txtImageName.Text.Trim(); if (imgname.Length == 0) { MessageBox.Show("Please choose a image to continue!"); btnLinkImg.Focus(); return; } //check discount // //check standard status string stdstt = cboStatus.SelectedItem.ToString(); //check price decimal price = 0; if (string.IsNullOrEmpty(txtPrice.Text.Trim())) { if (string.IsNullOrEmpty(txtSusggestPrice.Text.Trim())) { MessageBox.Show("Price is not valid!"); txtPrice.Focus(); return; } else { price = decimal.Parse(txtSusggestPrice.Text.Trim()); } } else { price = decimal.Parse(txtPrice.Text.Trim()); } _currentProduct.ProductId = ""; _currentProduct.Name = name; _currentProduct.Info = info; _currentProduct.Type = type; _currentProduct.ImageLink = imgname; _currentProduct.Discount = 0; _currentProduct.StandardStats = stdstt; _currentProduct.Price = price; //C:\Program Files\ITComma\Asowel POS\Project POS\POS\POS string destinationFile = startupProjectPath + "\\Images\\Products\\" + txtImageName.Text.Trim(); try { //using (FileStream fs = new FileStream("D:\\tableImagePath.txt", FileMode.Create)) //{ // using (StreamWriter sWriter = new StreamWriter(fs, Encoding.UTF8)) // { // sWriter.WriteLine(startupProjectPath); // } //} if (File.Exists(destinationFile)) { MessageBoxResult mess = MessageBox.Show("This product's image is already exist! Do you want to replace it?", "Warning!", MessageBoxButton.YesNo); if (mess == MessageBoxResult.Yes) { File.Delete(destinationFile); } else { MessageBox.Show("Please choose another image for this product or rename new image and try again!"); return; } } File.Copy(browseImagePath, destinationFile); } catch (Exception ex) { MessageBox.Show(ex.Message); } _unitofwork.ProductRepository.Insert(_currentProduct); _unitofwork.Save(); if (PDTempData.pdtList.Count() != 0) { foreach (var pd in PDTempData.pdtList) { pd.ProDe.ProductId = _currentProduct.ProductId; _unitofwork.ProductDetailsRepository.Insert(pd.ProDe); _unitofwork.Save(); } } MessageBox.Show("Add new product " + _currentProduct.Name + "(" + _currentProduct.ProductId + ") successful!"); ClearAllData(); } catch (Exception ex) { MessageBox.Show("Something went wrong. Can not add new product. Please check again!"); } }
private void btnAddNew_Click(object sender, RoutedEventArgs e) { try { //check name string namee = txtName.Text.Trim(); if (namee.Length == 0 || namee.Length > 50) { MessageBox.Show("Name is not valid!"); txtName.Focus(); return; } //check info string info = txtInfo.Text.Trim(); //check use for int usefor = cboUsefor.SelectedIndex; //check ingredient type string ingretype = cboIngreType.SelectedItem.ToString(); //check unit buy string unitbuy = cboUnitBuy.SelectedItem.ToString(); //check price if (string.IsNullOrEmpty(txtStdPrice.Text.Trim())) { MessageBox.Show("Standard price is not valid!"); return; } decimal price = decimal.Parse(txtStdPrice.Text.Trim()); if (price < 0 || price > decimal.MaxValue) { MessageBox.Show("Standard price is not valid!"); } if (_ingre == null) //Adding { WareHouseStdContainDialog wahdia = new WareHouseStdContainDialog(); wahdia.ShowDialog(); if (App.Current.Properties["StdContain"] == null) { return; } WareHouse newWare = new WareHouse { WarehouseId = "", Contain = 0, StandardContain = (int)App.Current.Properties["StdContain"] }; _unitofwork.WareHouseRepository.Insert(newWare); _unitofwork.Save(); Ingredient newingre = new Ingredient { IgdId = "", WarehouseId = newWare.WarehouseId, Name = namee, Info = info, Usefor = byte.Parse(usefor + ""), IgdType = ingretype, UnitBuy = unitbuy, StandardPrice = price, Deleted = 0 }; _unitofwork.IngredientRepository.Insert(newingre); _unitofwork.Save(); MessageBox.Show("Insert " + newingre.Name + "(" + newingre.IgdId + ") successful!"); } else //Updating { _ingre.Name = namee; _ingre.Info = info; _ingre.Usefor = byte.Parse(usefor + ""); _ingre.IgdType = ingretype; _ingre.UnitBuy = unitbuy; _ingre.StandardPrice = price; _unitofwork.IngredientRepository.Update(_ingre); _unitofwork.Save(); MessageBox.Show("Update " + _ingre.Name + "(" + _ingre.IgdId + ") successful!"); } this.Close(); } catch (Exception ex) { MessageBox.Show("Something went wrong. Can not add or update ingredient. Please check the details again!"); } }