Beispiel #1
0
        // 2
        public bool SyncStructureRefer()
        {
            var result = false;

            while (true)
            {
                if (!m_tableModel.HasRow)
                {
                    break;
                }

                if (m_tableModel.Row.init_title)
                {
                    result = true;
                    break;
                }

                var referList = YoConvert.ToList(m_tableModel.Row.refer);
                foreach (var table in referList)
                {
                    var tableLogic = new TableLogic(table);;
                    tableLogic.SyncStructureReferField(m_table + _id);
                }

                result = true;
                break;
            }
            return(result);
        }
Beispiel #2
0
        public ActionResult TableJson(string serverName, string databaseName)
        {
            var list = new List <IdNameModel>
            {
                new IdNameModel()
                {
                    Text  = "全部",
                    Value = ""
                }
            };

            if (serverName != "" && databaseName != "")
            {
                var tableService = new TableLogic();
                IList <TableModel> listTableModel = new List <TableModel>();
                var tableModels = tableService.GetAllTable(serverName, databaseName, "dbo").ToTableModels();
                if (tableModels != null)
                {
                    listTableModel = tableModels.ToList();
                }
                list.AddRange(listTableModel.Select(i => new IdNameModel()
                {
                    Text  = i.TableName,
                    Value = i.TableName
                }));
            }
            return(Content(JsonConvert.SerializeObject(list)));
        }
Beispiel #3
0
        public void OnlyAvailableTablesCanBeUsed()
        {
            TableLogic logic = new TableLogic();

            logic.AddTable(2, 6);
            Table firstPick  = logic.PickTable(2);
            Table secondPick = logic.PickTable(2);

            Assert.IsNotNull(firstPick, "UNO");
            Assert.IsNull(secondPick);
        }
Beispiel #4
0
        public void EachTableHasAUniqueID()
        {
            TableLogic logic = new TableLogic();

            logic.AddTable(1, 4);
            Table firstTable = logic.SearchByPeople(4);

            logic.AddTable(1, 8);
            Table secondTable = logic.SearchByPeople(8);

            Assert.IsNotNull(firstTable);
            Assert.IsNull(secondTable);
        }
        private async void GetTable()
        {
            var tableLogic = new TableLogic(_dbContext);

            if (IsEditing)
            {
                var listTable = await tableLogic.GetTableByZoneAsync(ZoneBindProp.Id);

                var listVisualTable = Mapper.Map <List <VisualTableModel> >(listTable);
                foreach (var table in listVisualTable)
                {
                    table.Status = Status.Normal;
                }
                ListTableBindProp = new ObservableCollection <VisualTableModel>(listVisualTable);
            }
        }
        private async void OnSave(object obj)
        {
            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                var tableLogic = new TableLogic(_dbContext);
                var zoneLogic  = new ZoneLogic(_dbContext);
                var zone       = new Zone();
                //Neu chinh sua
                if (IsEditing)
                {
                    zone.Id       = ZoneBindProp.Id;
                    zone.ZoneName = ZoneBindProp.ZoneName;

                    await zoneLogic.UpdateAsync(zone, false);

                    foreach (var table in ListTableBindProp)
                    {
                        switch (table.Status)
                        {
                        case Status.New:
                            await tableLogic.CreateAsync(new Table
                            {
                                Id        = Guid.NewGuid().ToString(),
                                FkZone    = table.FkZone,
                                TableName = table.TableName,
                                TableSize = (int)table.TableSize,
                                TableType = (int)table.TableType
                            }, false);

                            break;

                        case Status.Normal:
                            break;

                        case Status.Modified:
                            await tableLogic.UpdateAsync(new Table
                            {
                                Id        = table.Id,
                                TableName = table.TableName,
                                TableSize = (int)table.TableSize,
                                TableType = (int)table.TableType
                            }, false);

                            break;

                        case Status.Deleted:
                            break;

                        default:
                            break;
                        }
                    }

                    foreach (var table in _listDeletedTable)
                    {
                        await tableLogic.DeleteAsync(table.Id, false);
                    }

                    await _dbContext.SaveChangesAsync().ConfigureAwait(false);

                    //gui thong tin den trang chu
                    MessagingCenter.Send(ZoneBindProp, Messages.ZONE_MESSAGE);
                    MessagingCenter.Send(ListTableBindProp, Messages.TABLE_MESSAGE);

                    await NavigationService.GoBackAsync();
                }
                else // tao moi
                {
                    zone = await zoneLogic.CreateAsync(new Zone
                    {
                        Id       = ZoneBindProp.Id,
                        ZoneName = ZoneBindProp.ZoneName,
                    }, false);

                    foreach (var table in ListTableBindProp)
                    {
                        switch (table.Status)
                        {
                        case Status.New:
                            await tableLogic.CreateAsync(new Table
                            {
                                Id        = Guid.NewGuid().ToString(),
                                FkZone    = table.FkZone,
                                TableName = table.TableName,
                                TableSize = (int)table.TableSize,
                                TableType = (int)table.TableType
                            }, false);

                            break;

                        case Status.Normal:
                            break;

                        case Status.Modified:
                            await tableLogic.CreateAsync(new Table
                            {
                                Id        = Guid.NewGuid().ToString(),
                                FkZone    = table.FkZone,
                                TableName = table.TableName,
                                TableSize = (int)table.TableSize,
                                TableType = (int)table.TableType
                            }, false);

                            break;

                        case Status.Deleted:
                            break;

                        default:
                            break;
                        }
                    }

                    await _dbContext.SaveChangesAsync().ConfigureAwait(false);

                    //gui thong tin den trang chu
                    MessagingCenter.Send(ZoneBindProp, Messages.ZONE_MESSAGE);
                    MessagingCenter.Send(ListTableBindProp, Messages.TABLE_MESSAGE);

                    var param = new NavigationParameters();
                    param.Add(Keys.ZONE, ZoneBindProp);

                    await NavigationService.GoBackAsync(param);
                }
            }
            catch (Exception e)
            {
                await ShowError(e);
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #7
0
        private async void GetAllInvoice()
        {
            try
            {
                var itemLogic        = new ItemLogic(_dbContext);
                var discountLogic    = new DiscountLogic(_dbContext);
                var invoiceLogic     = new InvoiceLogic(_dbContext);
                var invoiceItemLogic = new InvoiceItemLogic(_dbContext);
                var subItemLogic     = new ItemDiscountLogic(_dbContext);
                var tableLogic       = new TableLogic(_dbContext);
                var zoneLogic        = new ZoneLogic(_dbContext);

                var listTable = await tableLogic.GetAllAsync();

                var listInvoice = await invoiceLogic.GetAllAsync(InvoiceStatus.Paid);

                var listVisualInvoice = Mapper.Map <List <VisualInvoiceModel> >(listInvoice);
                var listZone          = await zoneLogic.GetAllAsync();

                var listItem = await itemLogic.GetAllAsync();

                var listVisualItem = Mapper.Map <List <VisualItemMenuModel> >(listItem);
                var listDiscount   = await discountLogic.GetAllAsync();

                var listVisualDiscount = Mapper.Map <List <VisualItemMenuModel> >(listDiscount);

                ListItem     = new List <VisualItemMenuModel>(listVisualItem);
                ListDiscount = new List <VisualItemMenuModel>(listVisualDiscount);

                foreach (var invoice in listVisualInvoice)
                {
                    var listInvoiceItem = await invoiceItemLogic.GetAsync(invoice.Id);

                    foreach (var invoiceItem in listInvoiceItem)
                    {
                        if (invoiceItem.IsDiscount == 1)
                        {
                            var item       = ListDiscount.First(h => h.Id == invoiceItem.FkItemOrDiscount);
                            var visualItem = new VisualItemMenuModel
                            {
                                Id       = item.Id,
                                Quantity = invoiceItem.Quantity,
                                Name     = item.Name,
                                Status   = Status.Normal,
                                Value    = invoiceItem.Value,
                            };
                            invoice.ListDiscount.Add(visualItem);
                        }
                        else
                        {
                            var item        = ListItem.First(h => h.Id == invoiceItem.FkItemOrDiscount);
                            var listSubItem = await subItemLogic.GetAsync(item.Id);

                            var visualItem = new VisualItemMenuModel
                            {
                                Id       = item.Id,
                                Quantity = invoiceItem.Quantity,
                                Name     = item.Name,
                                Status   = Status.Normal,
                                Value    = invoiceItem.Value,
                            };
                            visualItem.ListSubItem.Add(new VisualItemMenuModel
                            {
                                Name  = "Đơn giá",
                                Value = item.Value,
                            });

                            foreach (var subItem in listSubItem)
                            {
                                var visualSubItem = ListDiscount.FirstOrDefault(h => h.Id == subItem.FkDiscount);
                                visualItem.ListSubItem.Add(new VisualItemMenuModel
                                {
                                    Id     = visualSubItem.Id,
                                    Name   = visualSubItem.Name,
                                    Value  = subItem.Value,
                                    Status = Status.Normal,
                                });
                            }

                            invoice.ListItemInBill.Add(visualItem);
                            invoice.ItemCount     += invoiceItem.Quantity;
                            invoice.OriginalPrice += invoiceItem.Value;
                        }
                        if (invoice.IsTakeAway == 0)
                        {
                            var table = listTable.First(h => h.Id == invoice.FkTable);
                            var zone  = listZone.First(h => h.Id == table.FkZone);
                            invoice.TableName = $"{zone.ZoneName} - {table.TableName}";
                        }
                        else
                        {
                            invoice.TableName = $"MANG ĐI";
                        }
                    }
                }
                ListInvoiceBindProp = new ObservableCollection <VisualInvoiceModel>(listVisualInvoice);
            }
            catch (Exception ex)
            {
                await ShowError(ex);
            }
        }
Beispiel #8
0
        private async void OnCompeletePayment(object obj)
        {
            if (IsBusy)
            {
                return;
            }

            if (ReceivedMoneyBindProp < BillBindProp.TotalPrice)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                if (!IsCompletedBindProp)
                {
                    IsCompletedBindProp = true;
                }
                else
                {
                    var invoiceLogic     = new InvoiceLogic(_dbContext);
                    var invoiceItemLogic = new InvoiceItemLogic(_dbContext);
                    var tableLogic       = new TableLogic(_dbContext);
                    var subItemLogic     = new ItemDiscountLogic(_dbContext);
                    var itemLogic        = new ItemLogic(_dbContext);

                    var invoice = new Invoice
                    {
                        Id            = BillBindProp.Id,
                        Status        = (int)InvoiceStatus.Paid,
                        PaidAmount    = ReceivedMoneyBindProp,
                        Tip           = TipBindProp,
                        TotalPrice    = BillBindProp.TotalPrice,
                        IsTakeAway    = BillBindProp.IsTakeAway,
                        FkTable       = BillBindProp.FkTable,
                        CloseDate     = DateTime.Now.ToString(),
                        CustomerCount = BillBindProp.CustomerCount,
                        InvoiceNumber = await GenerateInvoiceNumber()
                    };

                    if (IsEditing)
                    {
                        await invoiceLogic.UpdateAsync(invoice, false);
                    }
                    else
                    {
                        await invoiceLogic.CreateAsync(invoice, false);
                    }

                    if (BillBindProp.IsTakeAway == 0)
                    {
                        await tableLogic.ChangeStatusAsync(new Table
                        {
                            Id         = BillBindProp.FkTable,
                            IsSelected = 0
                        }, false);
                    }

                    foreach (var item in BillBindProp.ListItemInBill)
                    {
                        if (item.Status == Status.New)
                        {
                            await invoiceItemLogic.CreateAsync(new InvoiceItemOrDiscount
                            {
                                FkInvoice        = invoice.Id,
                                FkItemOrDiscount = item.Id,
                                Quantity         = item.Quantity,
                                IsDiscount       = 0,
                                Value            = item.Value
                            }, false);

                            for (int i = 1; i < item.ListSubItem.Count; i++)
                            {
                                await subItemLogic.CreateAsync(new ItemDiscount
                                {
                                    FkItem     = item.Id,
                                    FkDiscount = item.ListSubItem[i].Id,
                                    Value      = item.ListSubItem[i].Value
                                }, false);
                            }
                        }
                        await itemLogic.ModifyQuantityAsync(item.Id, -item.Quantity, false);
                    }

                    foreach (var item in BillBindProp.ListDiscount)
                    {
                        if (item.Status == Status.New)
                        {
                            await invoiceItemLogic.CreateAsync(new InvoiceItemOrDiscount
                            {
                                FkInvoice        = invoice.Id,
                                FkItemOrDiscount = item.Id,
                                Quantity         = item.Quantity,
                                IsDiscount       = 1,
                                Value            = item.Value
                            }, false);
                        }
                    }

                    await _dbContext.SaveChangesAsync();

                    var param = new NavigationParameters();
                    param.Add(Keys.BILL, BillBindProp.Id);
                    await NavigationService.GoBackAsync(param);
                }
            }
            catch (Exception e)
            {
                await ShowError(e);
            }
            finally
            {
                IsBusy = false;
            }
        }