private void checkChair(int tab)
        {
            var chairOfFirst  = _unitofwork.ChairRepository.Get(x => x.TableOwned.Equals(first.TableId)).ToList();
            var chairOfSecond = _unitofwork.ChairRepository.Get(x => x.TableOwned.Equals(second.TableId)).ToList();

            if (tab == 1)
            {
                int count = 0;
                foreach (var ch in chairOfFirst)
                {
                    var chair = orderDetailsOfFirst.Where(x => x.ChairId.Equals(ch.ChairId)).ToList();
                    if (chair == null)
                    {
                        continue;
                    }

                    count++;
                }

                foreach (var ch in chairOfSecond)
                {
                    Entities.Chair newch = new Entities.Chair();
                    newch.ChairNumber = ch.ChairNumber;
                    newch.TableOwned  = second.TableId;
                    _unitofwork.ChairRepository.Insert(newch);

                    var chair = orderDetailsOfSecond.Where(x => x.ChairId.Equals(ch.ChairId)).ToList();
                    if (chair == null)
                    {
                        continue;
                    }

                    foreach (var chod in chair)
                    {
                        _unitofwork.OrderDetailsTempRepository.Delete(chod);
                        _unitofwork.Save();
                        chod.OrdertempId = orderOfFirst.OrdertempId;
                        _unitofwork.OrderDetailsTempRepository.Insert(chod);
                    }

                    _unitofwork.Save();

                    ch.ChairNumber = ++count;
                    ch.TableOwned  = first.TableId;
                    _unitofwork.ChairRepository.Update(ch);
                }
            }

            if (tab == 2)
            {
                int count = 0;
                foreach (var ch in chairOfSecond)
                {
                    var chair = orderDetailsOfSecond.Where(x => x.ChairId.Equals(ch.ChairId)).ToList();
                    if (chair == null)
                    {
                        continue;
                    }

                    count++;
                }

                foreach (var ch in chairOfFirst)
                {
                    Entities.Chair newch = new Entities.Chair();
                    newch.ChairNumber = ch.ChairNumber;
                    newch.TableOwned  = second.TableId;
                    _unitofwork.ChairRepository.Insert(newch);

                    var chair = orderDetailsOfSecond.Where(x => x.ChairId.Equals(ch.ChairId)).ToList();
                    if (chair == null)
                    {
                        continue;
                    }

                    foreach (var chod in chair)
                    {
                        _unitofwork.OrderDetailsTempRepository.Delete(chod);
                        chod.OrdertempId = orderOfSecond.OrdertempId;
                        _unitofwork.OrderDetailsTempRepository.Insert(chod);
                    }

                    _unitofwork.Save();

                    ch.ChairNumber = count++;
                    ch.TableOwned  = second.TableId;
                    _unitofwork.ChairRepository.Update(ch);
                }
            }
        }
        //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");
            }
        }
Esempio n. 3
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();
        }