Beispiel #1
0
        private async void OnSelectInvoice(InvoiceDto obj)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                InvoiceBindProp     = new InvoiceDto(obj);
                TempInvoiceBindProp = obj;
                var selectedCategory = ListCategoryBindProp.FirstOrDefault();
                selectedCategory.IsSelected  = true;
                CurrentCategory              = selectedCategory;
                InvoiceFrameVisibleBindProp  = false;
                MenuFrameVisibleBindProp     = true;
                ItemFrameVisibleBindProp     = true;
                DiscountFrameVisibleBindProp = false;
                SettingFrameVisibleBindProp  = false;
            }
            catch (Exception e)
            {
                await ShowErrorAsync(e);
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #2
0
        private async void OnSelectTable(object obj)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                if (obj is TableDto)
                {
                    if (InvoiceBindProp == null)
                    {
                        InvoiceBindProp = new InvoiceDto();
                    }
                    var table            = obj as TableDto;
                    var selectedCategory = ListCategoryBindProp.FirstOrDefault();
                    selectedCategory.IsSelected = true;
                    CurrentCategory             = selectedCategory;
                    InvoiceBindProp.Table       = table;
                    InvoiceBindProp.TableId     = table.Id;
                    MenuFrameVisibleBindProp    = true;
                    InvoiceFrameVisibleBindProp = false;
                }
                else
                {
                    var selectedCategory = ListCategoryBindProp.FirstOrDefault();
                    if (selectedCategory != null)
                    {
                        selectedCategory.IsSelected = false;
                    }
                    var selectedZone = ListZoneBindProp.FirstOrDefault();
                    if (selectedZone != null)
                    {
                        selectedZone.IsSelected = true;
                        CurrentZone             = selectedZone;
                    }
                    MenuFrameVisibleBindProp        = false;
                    InvoiceFrameVisibleBindProp     = true;
                    ListInvoiceFrameVisibleBindProp = false;
                    ZoneFrameVisibleBindProp        = true;
                    DiscountFrameVisibleBindProp    = false;
                }
            }
            catch (Exception e)
            {
                await ShowErrorAsync(e);
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #3
0
        private async void OnSaveInvoice(object obj)
        {
            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                if (!Application.Current.Properties.ContainsKey("session"))
                {
                    await PageDialogService.DisplayAlertAsync("Thông báo", "Chưa bắt đầu phiên làm việc!", "Đồng ý");

                    await NavigationService.NavigateAsync(nameof(SessionPage));

                    return;
                }
                if (InvoiceBindProp.Table == null)
                {
                    await PageDialogService.DisplayAlertAsync("Thông báo", "Chưa chọn bàn!", "Đồng ý");

                    var selectedCategory = ListCategoryBindProp.FirstOrDefault(z => z.IsSelected);
                    if (selectedCategory != null)
                    {
                        selectedCategory.IsSelected = false;
                    }
                    MenuFrameVisibleBindProp        = false;
                    InvoiceFrameVisibleBindProp     = true;
                    ListInvoiceFrameVisibleBindProp = false;
                    ZoneFrameVisibleBindProp        = true;
                }
                else
                {
                    var invoiceToCreate = new InvoiceForCreateDto(InvoiceBindProp);
                    var json            = JsonConvert.SerializeObject(invoiceToCreate);
                    var content         = new StringContent(json, Encoding.UTF8, "application/json");
                    // Thuc hien cong viec tai day
                    using (var client = new HttpClient())
                    {
                        HttpResponseMessage response = new HttpResponseMessage();
                        if (InvoiceBindProp.Id == Guid.Empty)
                        {
                            response = await client.PostAsync(Properties.Resources.BaseUrl + "invoices/", content);
                        }
                        else
                        {
                            response = await client.PutAsync(Properties.Resources.BaseUrl + "invoices/", content);
                        }
                        switch (response.StatusCode)
                        {
                        case HttpStatusCode.Created:
                            var invoice = JsonConvert.DeserializeObject <InvoiceDto>(await response.Content.ReadAsStringAsync());
                            await _connection.InvokeAsync("SendInvoice", invoice);

                            CurrentZone.IsSelected          = false;
                            CurrentCategory.IsSelected      = false;
                            InvoiceBindProp                 = null;
                            MenuFrameVisibleBindProp        = false;
                            ListInvoiceFrameVisibleBindProp = true;
                            ZoneFrameVisibleBindProp        = false;
                            InvoiceFrameVisibleBindProp     = true;
                            SettingFrameVisibleBindProp     = false;
                            DiscountFrameVisibleBindProp    = false;
                            break;

                        case HttpStatusCode.NoContent:
                            await _connection.InvokeAsync("UpdateInvoice", InvoiceBindProp);

                            TempInvoiceBindProp             = InvoiceBindProp;
                            TempInvoiceBindProp             = null;
                            InvoiceBindProp                 = null;
                            CurrentCategory.IsSelected      = false;
                            CurrentZone.IsSelected          = false;
                            MenuFrameVisibleBindProp        = false;
                            ListInvoiceFrameVisibleBindProp = true;
                            ZoneFrameVisibleBindProp        = false;
                            MenuFrameVisibleBindProp        = false;
                            InvoiceFrameVisibleBindProp     = true;
                            SettingFrameVisibleBindProp     = false;
                            DiscountFrameVisibleBindProp    = false;
                            break;
                        }
                    };
                }
            }
            catch (Exception e)
            {
                await ShowErrorAsync(e);
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #4
0
        private async void OnSelectFrame(string obj)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                var selectedCategory = ListCategoryBindProp.FirstOrDefault(z => z.IsSelected);
                var selectedZone     = ListZoneBindProp.FindFirst(z => z.IsSelected);
                switch (obj)
                {
                case "setting":
                    if (InvoiceBindProp != null)
                    {
                        var ok = await PageDialogService.DisplayAlertAsync("Cảnh báo", "Hủy hóa đơn?", "Đồng ý", "Không");

                        if (ok)
                        {
                            if (selectedCategory != null)
                            {
                                selectedCategory.IsSelected = false;
                            }
                            MenuFrameVisibleBindProp     = false;
                            InvoiceFrameVisibleBindProp  = false;
                            SettingFrameVisibleBindProp  = true;
                            DiscountFrameVisibleBindProp = false;
                            InvoiceBindProp     = null;
                            TempInvoiceBindProp = null;
                        }
                    }
                    else
                    {
                        MenuFrameVisibleBindProp     = false;
                        InvoiceFrameVisibleBindProp  = false;
                        SettingFrameVisibleBindProp  = true;
                        DiscountFrameVisibleBindProp = false;
                    }
                    break;

                case "invoice":
                    if (InvoiceBindProp != null)
                    {
                        var ok = await PageDialogService.DisplayAlertAsync("Cảnh báo", "Hủy hóa đơn?", "Đồng ý", "Không");

                        if (ok)
                        {
                            if (selectedZone != null)
                            {
                                selectedZone.IsSelected = false;
                            }
                            if (selectedCategory != null)
                            {
                                selectedCategory.IsSelected = false;
                            }
                            InvoiceBindProp                 = null;
                            TempInvoiceBindProp             = null;
                            MenuFrameVisibleBindProp        = false;
                            InvoiceFrameVisibleBindProp     = true;
                            SettingFrameVisibleBindProp     = false;
                            DiscountFrameVisibleBindProp    = false;
                            ListInvoiceFrameVisibleBindProp = true;
                            ZoneFrameVisibleBindProp        = false;
                        }
                    }
                    else
                    {
                        if (selectedCategory != null)
                        {
                            selectedCategory.IsSelected = false;
                        }
                        MenuFrameVisibleBindProp     = false;
                        InvoiceFrameVisibleBindProp  = true;
                        SettingFrameVisibleBindProp  = false;
                        DiscountFrameVisibleBindProp = false;
                    }
                    break;

                case "discount":
                    if (selectedCategory != null)
                    {
                        selectedCategory.IsSelected = false;
                    }
                    MenuFrameVisibleBindProp     = true;
                    InvoiceFrameVisibleBindProp  = false;
                    ItemFrameVisibleBindProp     = false;
                    DiscountFrameVisibleBindProp = true;
                    SettingFrameVisibleBindProp  = false;
                    break;

                case "invoicelist":
                    if (selectedZone != null)
                    {
                        selectedZone.IsSelected = false;
                    }
                    if (selectedCategory != null)
                    {
                        selectedCategory.IsSelected = false;
                    }
                    ListInvoiceFrameVisibleBindProp = true;
                    ZoneFrameVisibleBindProp        = false;
                    break;

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                await ShowErrorAsync(e);
            }
            finally
            {
                IsBusy = false;
            }
        }