private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            string oldPass = txtPass.Password.Trim();

            if (!oldPass.Equals(_emp.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;
            }

            _emp.Pass = newPass;
            _cloudPosUnitofwork.EmployeeRepository.Update(_emp);
            _cloudPosUnitofwork.Save();

            var emplog = EmpLoginListData.emploglist.Where(x => x.Emp.Username.Equals(_emp.Username)).First();

            if (emplog != null)
            {
                emplog.Emp.Pass = newPass;
            }

            MessageBox.Show("Your password was changed!");
            this.Close();
        }
Esempio n. 2
0
        private void bntUpdate_Click(object sender, RoutedEventArgs e)
        {
            if (bntUpdate.Content.Equals("Update"))
            {
                txtName.IsEnabled      = true;
                txtPrice.IsEnabled     = true;
                cbopromotion.IsEnabled = true;
                bntUpdate.Content      = "Save";
            }
            else if (bntUpdate.Content.Equals("Save"))
            {
                Product p = _cloudPosUnitofwork.ProductRepository.GetById(txtID.Text);
                p.Discount = int.Parse(cbopromotion.SelectedValue.ToString());
                _cloudPosUnitofwork.ProductRepository.Update(p);
                _cloudPosUnitofwork.Save();


                txtName.IsEnabled      = false;
                txtPrice.IsEnabled     = false;
                cbopromotion.IsEnabled = false;
                bntUpdate.Content      = "Update";
            }
        }
Esempio n. 3
0
        private async Task LoginAsync(string username, string pass)
        {
            try
            {
                await Task.Run(() =>
                {
                    List <Employee> empList = _unitofwork.EmployeeRepository.Get().ToList();

                    var emp = empList.FirstOrDefault(x => x.Username.Equals(username) && x.DecryptedPass.Equals(pass));
                    if (emp != null)
                    {
                        App.Current.Properties["EmpLogin"] = emp;
                        if (emp.EmpRole == (int)EmployeeRole.Stock)
                        {
                            Dispatcher.Invoke(() =>
                            {
                                WareHouseWindow wareHouse = new WareHouseWindow();
                                wareHouse.Show();
                            });
                        }
                        else
                        {
                            try
                            {
                                SalaryNote empSalaryNote = _unitofwork.SalaryNoteRepository.Get(sle =>
                                                                                                sle.EmpId.Equals(emp.EmpId) && sle.ForMonth.Equals(DateTime.Now.Month) &&
                                                                                                sle.ForYear.Equals(DateTime.Now.Year)).First();

                                App.Current.Properties["EmpSN"] = empSalaryNote;
                                WorkingHistory empWorkHistory   = new WorkingHistory
                                {
                                    ResultSalary = empSalaryNote.SnId,
                                    EmpId        = empSalaryNote.EmpId
                                };
                                App.Current.Properties["EmpWH"] = empWorkHistory;
                            }
                            catch (Exception ex)
                            {
                                SalaryNote empSalary = new SalaryNote
                                {
                                    EmpId       = emp.EmpId,
                                    SalaryValue = 0,
                                    WorkHour    = 0,
                                    ForMonth    = DateTime.Now.Month,
                                    ForYear     = DateTime.Now.Year,
                                    IsPaid      = 0
                                };
                                _unitofwork.SalaryNoteRepository.Insert(empSalary);
                                _unitofwork.Save();
                                WorkingHistory empWorkHistory = new WorkingHistory
                                {
                                    ResultSalary = empSalary.SnId,
                                    EmpId        = empSalary.EmpId
                                };
                                App.Current.Properties["EmpWH"] = empWorkHistory;
                                App.Current.Properties["EmpSN"] = empSalary;
                            }

                            Dispatcher.Invoke(() =>
                            {
                                EmpLoginListData.emploglist.Clear();
                                EmpLoginListData.emploglist.Add(new EmpLoginList
                                {
                                    Emp         = emp,
                                    EmpSal      = App.Current.Properties["EmpSN"] as SalaryNote,
                                    EmpWH       = App.Current.Properties["EmpWH"] as WorkingHistory,
                                    TimePercent = 0
                                });

                                EmployeeWorkSpace.MainWindow main = new EmployeeWorkSpace.MainWindow();
                                main.Show();
                            });
                        }
                    }
                    else
                    {
                        //Get Admin
                        List <AdminRe> adList = _unitofwork.AdminreRepository.Get().ToList();

                        var ad = adList.FirstOrDefault(x => x.Username.Equals(username) && x.DecryptedPass.Equals(pass));
                        if (ad != null)
                        {
                            App.Current.Properties["AdLogin"] = ad;

                            Dispatcher.Invoke(() =>
                            {
                                AdminNavWindow navwindow = new AdminNavWindow();
                                navwindow.Show();
                            });
                        }

                        if (ad == null && emp == null)
                        {
                            MessageBox.Show("incorrect username or password");
                            return;
                        }
                    }


                    Dispatcher.Invoke(() =>
                    {
                        this.Close();
                    });
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show("Something went wrong: \n" + ex.Message);
                AppLog.Error(ex);
            }
        }
        private bool TakeFromWareHouseData(OrderDetailsTemp orderDetails, Product orderingProduct)
        {
            var prodOfOrderDetails =
                _cloudPosUnitofwork.ProductRepository.Get(x => x.ProductId.Equals(orderingProduct.ProductId), includeProperties: "ProductDetails").FirstOrDefault();

            if (prodOfOrderDetails != null)
            {
                // if product have no product details
                if (prodOfOrderDetails.ProductDetails.Count == 0)
                {
                    // still allow to order but no ingredient relate to this product for tracking
                    return(true);
                }

                var wareHouseDict = new Dictionary <WareHouse, double?>();

                // going to warehouse and take the contain of each ingredient
                foreach (var prodDetails in prodOfOrderDetails.ProductDetails)
                {
                    var quan = prodDetails.Quan;
                    var ingd =
                        _cloudPosUnitofwork.IngredientRepository.Get(x => x.IgdId.Equals(prodDetails.IgdId))
                        .FirstOrDefault();
                    if (ingd == null)
                    {
                        MessageBox.Show("Something went wrong cause of the Ingredient's information");
                        return(false);
                    }
                    var wareHouse =
                        _cloudPosUnitofwork.WareHouseRepository.Get(x => x.WarehouseId.Equals(ingd.WarehouseId))
                        .FirstOrDefault();
                    if (wareHouse == null)
                    {
                        MessageBox.Show("Something went wrong cause of the WareHouse's information");
                        return(false);
                    }

                    var temple_Contain = wareHouse.Contain;

                    if (temple_Contain < quan)
                    {
                        MessageBox.Show("This Product can not order now. Please check to WareHouse for Ingredient's stock!");
                        return(false);
                    }
                    else
                    {
                        temple_Contain -= quan;
                    }

                    wareHouseDict.Add(wareHouse, temple_Contain);
                }

                // when all ingredient are enough to make product
                foreach (var item in wareHouseDict)
                {
                    item.Key.Contain = item.Value;
                }
                _cloudPosUnitofwork.Save();
            }
            else
            {
                MessageBox.Show("This Product is not existed in database! Please check the Product's information");
                return(false);
            }

            return(true);
        }
Esempio n. 5
0
        private async Task Async(string username, string pass, string code, EmpLoginList empout)
        {
            try
            {
                await Task.Run(() =>
                {
                    if (empout != null)
                    {
                        if (EmpLoginListData.emploglist.Count == 1)
                        {
                            var orderedTable = _unitofwork.TableRepository.Get(x => x.IsOrdered == 1).ToList();
                            if (orderedTable.Count != 0)
                            {
                                MessageBox.Show("You can not logout because still have Tables that in the ordering state out there. Please check again!");
                                return;
                            }
                        }

                        if ((empout.Emp.Username.Equals(username) && (empout.Emp.DecryptedPass.Equals(pass)) || empout.Emp.DecryptedCode.Equals(code)))
                        {
                            empout.EmpWH.EndTime = DateTime.Now;
                            _cloudPosUnitofwork.WorkingHistoryRepository.Insert(empout.EmpWH);
                            _cloudPosUnitofwork.Save();

                            var workH                 = empout.EmpWH.EndTime - empout.EmpWH.StartTime;
                            empout.EmpSal             = _cloudPosUnitofwork.SalaryNoteRepository.Get(sle => sle.EmpId.Equals(empout.Emp.EmpId) && sle.ForMonth.Equals(DateTime.Now.Month) && sle.ForYear.Equals(DateTime.Now.Year)).First();
                            empout.EmpSal.WorkHour   += workH.Hours + (workH.Minutes / 60.0) + (workH.Seconds / 3600.0);
                            empout.EmpSal.SalaryValue = (decimal)(empout.EmpSal.WorkHour *empout.Emp.HourWage);
                            _cloudPosUnitofwork.SalaryNoteRepository.Update(empout.EmpSal);
                            _cloudPosUnitofwork.Save();

                            EmpLoginListData.emploglist.Remove(empout);

                            Dispatcher.Invoke(() =>
                            {
                                checkEmployeeCount();
                            });

                            return;
                        }
                        else
                        {
                            MessageBox.Show("Fail! Please try again!");
                            return;
                        }
                    }

                    bool isFound = false;
                    foreach (Employee emp in _employee)
                    {
                        if ((emp.Username.Equals(username) && (emp.DecryptedPass.Equals(pass)) || emp.DecryptedCode.Equals(code)))
                        {
                            var chemp = EmpLoginListData.emploglist.Where(x => x.Emp.EmpId.Equals(emp.EmpId)).ToList();
                            if (chemp.Count != 0)
                            {
                                MessageBox.Show("This employee is already login!");
                                return;
                            }

                            try
                            {
                                SalaryNote empSalaryNote = _cloudPosUnitofwork.SalaryNoteRepository.Get(sle => sle.EmpId.Equals(emp.EmpId) && sle.ForMonth.Equals(DateTime.Now.Month) && sle.ForYear.Equals(DateTime.Now.Year)).First();

                                App.Current.Properties["EmpSN"] = empSalaryNote;
                                WorkingHistory empWorkHistory   = new WorkingHistory {
                                    ResultSalary = empSalaryNote.SnId, EmpId = empSalaryNote.EmpId
                                };
                                App.Current.Properties["EmpWH"] = empWorkHistory;
                            }
                            catch (Exception ex)
                            {
                                SalaryNote empSalary = new SalaryNote {
                                    EmpId = emp.EmpId, SalaryValue = 0, WorkHour = 0, ForMonth = DateTime.Now.Month, ForYear = DateTime.Now.Year, IsPaid = 0
                                };
                                _cloudPosUnitofwork.SalaryNoteRepository.Insert(empSalary);
                                _cloudPosUnitofwork.Save();
                                WorkingHistory empWorkHistory = new WorkingHistory {
                                    ResultSalary = empSalary.SnId, EmpId = empSalary.EmpId
                                };
                                App.Current.Properties["EmpWH"] = empWorkHistory;
                                App.Current.Properties["EmpSN"] = empSalary;
                            }

                            Dispatcher.Invoke(() =>
                            {
                                EmpLoginListData.emploglist.Add(new EmpLoginList {
                                    Emp = emp, EmpSal = App.Current.Properties["EmpSN"] as SalaryNote, EmpWH = App.Current.Properties["EmpWH"] as WorkingHistory, TimePercent = 0
                                });
                                checkEmployeeCount();
                                setControl(true);
                            });
                            isFound = true;

                            //end create

                            break;
                        }
                    }

                    if (!isFound)
                    {
                        MessageBox.Show("incorrect username or password");
                        return;
                    }
                });
            }
            catch (Exception ex)
            {
            }
        }