Beispiel #1
0
        ////check file tableRuntimeHistory isExist
        //public static bool checkTableRuntimeHistoryFileExist()
        //{
        //    return File.Exists(startupProjectPath + "\\SerializedData\\tableRuntimeHistory.bin");
        //}

        //write khi add new
        public static Entities.Table writeOnAddNew(EmployeewsOfLocalPOS _unitofwork, Rectangle rec, Entities.Employee emp)
        {
            Entities.Table newTable = new Entities.Table()
            {
                TableId     = 0,
                TableNumber = int.Parse(rec.Name.Substring(5)),
                ChairAmount = 0,
                PosX        = Convert.ToInt32(rec.Margin.Left),
                PosY        = Convert.ToInt32(rec.Margin.Top),
                IsPinned    = 0,
                IsOrdered   = 0,
                IsLocked    = 0,
                TableRec    = rec
            };

            _unitofwork.TableRepository.Insert(newTable);
            _unitofwork.Save();

            Entities.OrderTemp newOrderTemp = new Entities.OrderTemp()
            {
                CusId       = "CUS0000001",
                EmpId       = emp.EmpId,
                TableOwned  = _unitofwork.TableRepository.Get(x => x.TableNumber.Equals(newTable.TableNumber)).First().TableId,
                Ordertime   = DateTime.Now,
                TotalPrice  = 0,
                CustomerPay = 0,
                PayBack     = 0
            };

            _unitofwork.OrderTempRepository.Insert(newOrderTemp);
            _unitofwork.Save();

            return(_unitofwork.TableRepository.Get(x => x.TableNumber.Equals(newTable.TableNumber)).First());
        }
Beispiel #2
0
        private void checkEmployeeCount()
        {
            if (EmpLoginListData.emploglist.Count == 0)
            {
                foreach (var table in _unitofwork.TableRepository.Get())
                {
                    var orderTemp = _unitofwork.OrderTempRepository.Get(x => x.TableOwned.Equals(table.TableId)).First();
                    orderTemp.EmpId             = "";
                    orderTemp.CusId             = "CUS0000001";
                    orderTemp.Ordertime         = DateTime.Now;
                    orderTemp.TotalPriceNonDisc = 0;
                    orderTemp.TotalPrice        = 0;
                    orderTemp.CustomerPay       = 0;
                    orderTemp.PayBack           = 0;
                    orderTemp.SubEmpId          = "";
                    orderTemp.Pax = 0;

                    table.IsOrdered = 0;
                    table.IsPrinted = 0;

                    var orderDetails = _unitofwork.OrderDetailsTempRepository.Get(x => x.OrdertempId.Equals(orderTemp.OrdertempId));
                    if (orderDetails.Count() != 0)
                    {
                        foreach (var od in orderDetails)
                        {
                            _unitofwork.OrderDetailsTempRepository.Delete(od);
                            _unitofwork.Save();
                        }
                    }
                }

                App.Current.Properties["CurrentEmpWorking"] = null;
                _main.Close();
                Login login = new Login();
                this.Close();
                login.Show();
                return;
            }
            else
            {
                _cUser.Content = EmpLoginListData.emploglist.Count + " employee(s) available";
                if (App.Current.Properties["CurrentEmpWorking"] != null)
                {
                    _cUser.Content = (App.Current.Properties["CurrentEmpWorking"] as EmpLoginList).Emp.Username;
                }
            }

            lvLoginList.ItemsSource = EmpLoginListData.emploglist;
            lvLoginList.Items.Refresh();
        }
        //ToDo: Need to update the contain in Warehouse database when new order occur
        private void lvCategory_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (App.Current.Properties["CurrentEmpWorking"] == null)
            {
                return;
            }

            orderingTable = ((MainWindow)Window.GetWindow(this)).currentTable;
            orderingChair = ((MainWindow)Window.GetWindow(this)).currentChair;
            ListBox lbSelected = sender as ListBox;

            if (orderingTable == null || orderingChair == null)
            {
                MessageBox.Show("Chair must be choice!");
                return;
            }

            orderTempCurrentTable = _unitofwork.OrderTempRepository.Get(x => x.TableOwned.Equals(orderingTable.TableId)).First();
            if (orderTempCurrentTable == null)
            {
                return;
            }

            var item = lbSelected.SelectedItem;

            if (item != null)
            {
                if (orderingTable.IsOrdered == 0)
                {
                    orderTempCurrentTable.Ordertime = DateTime.Now;
                    orderingTable.IsOrdered         = 1;
                    _unitofwork.TableRepository.Update(orderingTable);
                }

                OrderDetailsTemp o  = new OrderDetailsTemp();
                Product          it = (Product)lbSelected.SelectedItem;

                //order for each chair

                if (orderingChair != null)
                {
                    var chairorderdetailstemp        = _unitofwork.OrderDetailsTempRepository.Get(x => x.ChairId.Equals(orderingChair.ChairId)).ToList();
                    var foundinchairorderdetailstemp = chairorderdetailstemp.Where(x => x.ProductId.Equals(it.ProductId)).ToList();

                    // go to warehouse, check and get the ingredient to make product
                    if (!TakeFromWareHouseData(o, it))
                    {
                        return;
                    }

                    // add a product to order
                    if (foundinchairorderdetailstemp.Count == 0)
                    {
                        o.ChairId       = orderingChair.ChairId;
                        o.OrdertempId   = orderTempCurrentTable.OrdertempId;
                        o.ProductId     = it.ProductId;
                        o.SelectedStats = it.StandardStats;
                        o.Note          = "";
                        o.Quan          = 1;
                        o.IsPrinted     = 0;
                        o.Discount      = it.Discount;


                        _unitofwork.OrderDetailsTempRepository.Insert(o);
                        _unitofwork.Save();
                    }
                    else
                    {
                        foreach (var order in foundinchairorderdetailstemp)
                        {
                            if (!order.SelectedStats.Equals(it.StandardStats) || !order.Note.Equals("") || order.IsPrinted != 0)
                            {
                                o.ChairId       = orderingChair.ChairId;
                                o.OrdertempId   = orderTempCurrentTable.OrdertempId;
                                o.ProductId     = it.ProductId;
                                o.SelectedStats = it.StandardStats;
                                o.Note          = "";
                                o.Quan          = 1;
                                o.IsPrinted     = 0;
                                o.Discount      = it.Discount;

                                _unitofwork.OrderDetailsTempRepository.Insert(o);
                                _unitofwork.Save();

                                break;
                            }

                            if (order.SelectedStats.Equals(it.StandardStats) && order.Note.Equals("") && order.IsPrinted == 0)
                            {
                                order.ProductId = it.ProductId;
                                order.Quan++;

                                _unitofwork.OrderDetailsTempRepository.Update(order);
                                _unitofwork.Save();

                                break;
                            }
                        }
                    }
                }


                lbSelected.UnselectAll();

                checkWorkingAction(App.Current.Properties["CurrentEmpWorking"] as EmpLoginList, orderTempCurrentTable);
                ((MainWindow)Window.GetWindow(this)).initProgressTableChair();
                ((MainWindow)Window.GetWindow(this)).en.ucOrder.RefreshControl(_unitofwork, orderingTable);
                ((MainWindow)Window.GetWindow(this)).en.ucOrder.txtDay.Text = orderTempCurrentTable.Ordertime.ToString("dd/MM/yyyy H:mm:ss");
            }
        }
        private void btnSwap_Click(object sender, RoutedEventArgs e)
        {
            if (first == null || second == null)
            {
                MessageBox.Show("You must be choose two table to swap!");
                return;
            }

            loadData();

            //swap ordertemp
            orderOfFirst.TableOwned  = second.TableId;
            orderOfSecond.TableOwned = first.TableId;

            _unitofwork.OrderTempRepository.Update(orderOfFirst);
            _unitofwork.OrderTempRepository.Update(orderOfSecond);
            _unitofwork.Save();

            _currentChairList     = _unitofwork.ChairRepository.Get().ToList();
            _orderTempList        = _unitofwork.OrderTempRepository.Get().ToList();
            _orderDetailsTempList = _unitofwork.OrderDetailsTempRepository.Get().ToList();

            loadData();

            var chairOfFirst  = _currentChairList.Where(x => x.TableOwned.Equals(first.TableId)).ToList();
            var chairOfSecond = _currentChairList.Where(x => x.TableOwned.Equals(second.TableId)).ToList();

            first.ChairAmount  = chairOfSecond.Count;
            second.ChairAmount = chairOfFirst.Count;

            _unitofwork.TableRepository.Update(first);
            _unitofwork.TableRepository.Update(second);

            foreach (var ch in chairOfFirst)
            {
                ch.TableOwned = second.TableId;
                _unitofwork.ChairRepository.Update(ch);
            }

            foreach (var ch in chairOfSecond)
            {
                ch.TableOwned = first.TableId;
                _unitofwork.ChairRepository.Update(ch);
            }

            //temporary first table to swap
            Entities.Table tempFirst = new Entities.Table
            {
                TableId     = first.TableId,
                TableNumber = first.TableNumber,
                ChairAmount = first.ChairAmount,
                PosX        = first.PosX,
                PosY        = first.PosY,
                IsPinned    = first.IsPinned,
                IsOrdered   = first.IsOrdered,
                IsLocked    = first.IsLocked,
                IsPrinted   = first.IsPrinted,
                TableRec    = first.TableRec,
            };

            //temporary second table to swap
            Entities.Table tempSecond = new Entities.Table
            {
                TableId     = second.TableId,
                TableNumber = second.TableNumber,
                ChairAmount = second.ChairAmount,
                PosX        = second.PosX,
                PosY        = second.PosY,
                IsPinned    = second.IsPinned,
                IsOrdered   = second.IsOrdered,
                IsLocked    = second.IsLocked,
                IsPrinted   = second.IsPrinted,
                TableRec    = second.TableRec,
            };

            //setting new first table
            first.IsOrdered = tempSecond.IsOrdered;
            first.IsLocked  = tempSecond.IsLocked;
            first.IsPrinted = tempSecond.IsPrinted;

            //setting new second table
            second.IsOrdered = tempFirst.IsOrdered;
            second.IsLocked  = tempFirst.IsLocked;
            second.IsPrinted = tempFirst.IsPrinted;

            _unitofwork.TableRepository.Update(first);
            _unitofwork.TableRepository.Update(second);
            _unitofwork.Save();

            MessageBox.Show("Swapped Successful!");
        }
        //mothod kiem tra single or double
        private void DoClickSingleOrDouble(FrameworkElement ctrl, Rectangle rec)
        {
            int clicks = ClickAttach.GetClicks(ctrl);

            ClickAttach.SetClicks(ctrl, 0);
            if (clicks == 2)
            {
                if (App.Current.Properties["AdLogin"] != null)
                {
                    return;
                }

                EmpLoginList currentEmp = App.Current.Properties["CurrentEmpWorking"] as EmpLoginList;

                AllEmployeeLogin ael;
                Entities.Table   founded = currentTableList.Where(x => x.TableNumber.Equals(int.Parse(rec.Name.Substring(5)))).First();
                if (founded == null)
                {
                    return;
                }

                var ordertempcurrenttable = _unitofwork.OrderTempRepository.Get(x => x.TableOwned.Equals(founded.TableId)).First();

                if (founded.IsPinned == 0)
                {
                    MessageBoxResult mess = MessageBox.Show("You must be pin this table before you want to create new order. Do you want to pin now?", "Warning!", MessageBoxButton.YesNo);
                    if (mess == MessageBoxResult.Yes)
                    {
                        if (founded.ChairAmount == 0)
                        {
                            MessageBox.Show("You must be set Chair Amount greater than 0!");
                            return;
                        }

                        if (currentEmp != null)
                        {
                            if (ordertempcurrenttable != null)
                            {
                                ordertempcurrenttable.EmpId = currentEmp.Emp.EmpId;
                                _unitofwork.OrderTempRepository.Update(ordertempcurrenttable);
                                _unitofwork.Save();
                            }

                            navigateToOrder(currentEmp, founded.TableRec, founded);
                            return;
                        }

                        ael = new AllEmployeeLogin((MainWindow)Window.GetWindow(this), _unitofwork, _cloudPosUnitofwork, ((MainWindow)Window.GetWindow(this)).cUser, 4);
                        ael.ShowDialog();

                        checkCurrentEmp(currentEmp, founded.TableRec, founded, ordertempcurrenttable);
                    }
                }
                else
                {
                    if (founded.ChairAmount == 0)
                    {
                        MessageBox.Show("You must be set Chair Amount greater than 0!");
                        return;
                    }

                    if (founded.IsOrdered == 1)
                    {
                        currentEmp = App.Current.Properties["CurrentEmpWorking"] as EmpLoginList;

                        if (currentEmp != null)
                        {
                            if (currentEmp.Emp.EmpId.Equals(ordertempcurrenttable.EmpId))
                            {
                                navigateToOrder(currentEmp, founded.TableRec, founded);
                                return;
                            }
                            else
                            {
                                navigateToOrder(currentEmp, founded.TableRec, founded);
                                return;
                            }
                        }

                        ael = new AllEmployeeLogin((MainWindow)Window.GetWindow(this), _unitofwork, _cloudPosUnitofwork, ((MainWindow)Window.GetWindow(this)).cUser, 4);
                        ael.ShowDialog();

                        checkCurrentEmp(currentEmp, founded.TableRec, founded, ordertempcurrenttable);
                    }
                    else
                    {
                        currentEmp = App.Current.Properties["CurrentEmpWorking"] as EmpLoginList;

                        if (currentEmp != null)
                        {
                            if (ordertempcurrenttable != null)
                            {
                                ordertempcurrenttable.EmpId = currentEmp.Emp.EmpId;
                                _unitofwork.OrderTempRepository.Update(ordertempcurrenttable);
                                _unitofwork.Save();
                            }

                            checkCurrentEmp(currentEmp, founded.TableRec, founded, ordertempcurrenttable);
                            return;
                        }

                        ael = new AllEmployeeLogin((MainWindow)Window.GetWindow(this), _unitofwork, _cloudPosUnitofwork, ((MainWindow)Window.GetWindow(this)).cUser, 4);
                        ael.ShowDialog();

                        checkCurrentEmp(currentEmp, founded.TableRec, founded, ordertempcurrenttable);
                    }
                }
            }
        }
Beispiel #6
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            int amountChange = int.Parse(txtChairAmount.Text.Trim());

            if (amountChange == 0)
            {
                MessageBox.Show("Chair Amount must be greater than 0!");
                return;
            }

            if (curTable.ChairAmount == 0)
            {
                curTable.ChairAmount = amountChange;

                for (int i = 0; i < amountChange; i++)
                {
                    Entities.Chair newChair = new Entities.Chair();
                    newChair.ChairNumber = i + 1;
                    newChair.TableOwned  = curTable.TableId;

                    _uniofwork.ChairRepository.Insert(newChair);
                    _uniofwork.Save();
                }

                this.Close();

                return;
            }

            var chairOfTable = _uniofwork.ChairRepository.Get(x => x.TableOwned.Equals(curTable.TableId)).ToList();

            int orderdChairCount = 0;

            foreach (var chair in chairOfTable)
            {
                var orderDetailsOfChair = _uniofwork.OrderDetailsTempRepository.Get(x => x.ChairId.Equals(chair.ChairId));
                if (orderDetailsOfChair != null && orderDetailsOfChair.Count() > 0)
                {
                    orderdChairCount++;
                }
            }

            if (orderdChairCount > amountChange)
            {
                MessageBox.Show("Can not change Chair Amount now! This table have " + orderdChairCount + " chair(s) on order!");
                return;
            }

            if (chairOfTable.Count() < amountChange)
            {
                // increase
                for (int i = chairOfTable.Count(); i < amountChange; i++)
                {
                    Entities.Chair newChair = new Entities.Chair();
                    newChair.ChairNumber = i + 1;
                    newChair.TableOwned  = curTable.TableId;

                    _uniofwork.ChairRepository.Insert(newChair);
                    _uniofwork.Save();
                }

                curTable.ChairAmount = amountChange;
            }
            else
            {
                // decrease
                for (int i = amountChange; i < chairOfTable.Count(); i++)
                {
                    _uniofwork.ChairRepository.Delete(chairOfTable.ElementAt(i));
                    _uniofwork.Save();
                }

                curTable.ChairAmount = amountChange;
            }

            this.Close();
        }