Example #1
0
        public override void OnNavigatedTo(INavigationParameters parameters)
        {
            base.OnNavigatedTo(parameters);
            switch (parameters.GetNavigationMode())
            {
            case NavigationMode.Back:
                if (parameters.ContainsKey("ZoneBindProp"))
                {
                    var zone = parameters["ZoneBindProp"] as ZoneDto;
                    ListZoneBindProp.Remove(zone);
                }
                break;

            case NavigationMode.New:
                break;

            case NavigationMode.Forward:
                break;

            case NavigationMode.Refresh:
                break;

            default:
                break;
            }
        }
Example #2
0
        private async void OnSelectZone(ZoneDto obj)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                var selectedZone = ListZoneBindProp.FindFirst(z => z.IsSelected);
                if (selectedZone != null)
                {
                    selectedZone.IsSelected = false;
                }
                obj.IsSelected                  = true;
                CurrentZone                     = obj;
                ZoneFrameVisibleBindProp        = true;
                ListInvoiceFrameVisibleBindProp = false;
            }
            catch (Exception e)
            {
                await ShowErrorAsync(e);
            }
            finally
            {
                IsBusy = false;
            }
        }
Example #3
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;
            }
        }
Example #4
0
        private async void OnAddNewZone(object obj)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                var zoneToCreate = new ZoneDto {
                    Name = "New Zone"
                };
                var json    = JsonConvert.SerializeObject(zoneToCreate);
                var content = new StringContent(json, Encoding.UTF8, "application/json");
                // Thuc hien cong viec tai day
                using (var client = new HttpClient())
                {
                    HttpResponseMessage response = new HttpResponseMessage();
                    response = await client.PostAsync(Properties.Resources.BaseUrl + "zones/", content);

                    if (response.IsSuccessStatusCode)
                    {
                        var zone = JsonConvert.DeserializeObject <ZoneDto>(await response.Content.ReadAsStringAsync());
                        ListZoneBindProp.Add(zone);
                    }
                };
            }
            catch (Exception e)
            {
                await ShowErrorAsync(e);
            }
            finally
            {
                IsBusy = false;
            }
        }
Example #5
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;
            }
        }
Example #6
0
        public async override void OnNavigatedTo(INavigationParameters parameters)
        {
            switch (parameters.GetNavigationMode())
            {
            case NavigationMode.Back:
                if (parameters.ContainsKey("item"))
                {
                    var item = parameters["item"] as ItemForInvoiceDto;
                    if (InvoiceBindProp == null)
                    {
                        InvoiceBindProp = new InvoiceDto();
                    }
                    InvoiceBindProp.Items.Add(item);
                    InvoiceBindProp.TotalPrice += item.Value;
                }
                if (parameters.ContainsKey(nameof(InvoiceBindProp)))
                {
                    var invoice = parameters[nameof(InvoiceBindProp)] as InvoiceDto;
                    await _connection.InvokeAsync("DeleteInvoice", InvoiceBindProp.Id);

                    InvoiceBindProp     = null;
                    TempInvoiceBindProp = null;
                }
                break;

            case NavigationMode.New:
                using (var client = new HttpClient())
                {
                    var categoryTask = client.GetAsync(Properties.Resources.BaseUrl + "categories/");
                    var discountTask = client.GetAsync(Properties.Resources.BaseUrl + "discounts/");
                    var invoiceTask  = client.GetAsync(Properties.Resources.BaseUrl + "invoices/");
                    var zoneTask     = client.GetAsync(Properties.Resources.BaseUrl + "zones/");

                    var allTasks = new List <Task> {
                        categoryTask, discountTask, invoiceTask, zoneTask
                    };
                    while (allTasks.Any())
                    {
                        Task finished = await Task.WhenAny(allTasks);

                        if (finished == categoryTask)
                        {
                            if (categoryTask.Result.IsSuccessStatusCode)
                            {
                                var categories = JsonConvert.DeserializeObject <IEnumerable <CategoryDto> >(await categoryTask.Result.Content.ReadAsStringAsync());
                                foreach (var category in categories)
                                {
                                    ListCategoryBindProp.Add(category);
                                }
                            }
                            else
                            {
                                await PageDialogService.DisplayAlertAsync("Lỗi", $"{await categoryTask.Result.Content.ReadAsStringAsync()}", "Đóng");
                            }
                        }
                        else if (finished == discountTask)
                        {
                            if (discountTask.Result.IsSuccessStatusCode)
                            {
                                var discounts = JsonConvert.DeserializeObject <IEnumerable <DiscountDto> >(await discountTask.Result.Content.ReadAsStringAsync());
                                foreach (var discount in discounts)
                                {
                                    ListDiscountBindProp.Add(discount);
                                }
                            }
                            else
                            {
                                await PageDialogService.DisplayAlertAsync("Lỗi", $"{await discountTask.Result.Content.ReadAsStringAsync()}", "Đóng");
                            }
                        }
                        else if (finished == invoiceTask)
                        {
                            if (invoiceTask.Result.IsSuccessStatusCode)
                            {
                                var invoices = JsonConvert.DeserializeObject <IEnumerable <InvoiceDto> >(await invoiceTask.Result.Content.ReadAsStringAsync());
                                foreach (var invoice in invoices)
                                {
                                    ListInvoiceBindProp.Add(invoice);
                                }
                            }
                            else
                            {
                                await PageDialogService.DisplayAlertAsync("Lỗi", $"{await invoiceTask.Result.Content.ReadAsStringAsync()}", "Đóng");
                            }
                        }
                        else if (finished == zoneTask)
                        {
                            if (zoneTask.Result.IsSuccessStatusCode)
                            {
                                var zones = JsonConvert.DeserializeObject <IEnumerable <ZoneDto> >(await zoneTask.Result.Content.ReadAsStringAsync());
                                foreach (var zone in zones)
                                {
                                    ListZoneBindProp.Add(zone);
                                }
                            }
                            else
                            {
                                await PageDialogService.DisplayAlertAsync("Lỗi", $"{await zoneTask.Result.Content.ReadAsStringAsync()}", "Đóng");
                            }
                        }
                        allTasks.Remove(finished);
                    }
                    var id       = Xamarin.Essentials.Preferences.Get("token", "token");
                    var response = await client.GetAsync(Properties.Resources.BaseUrl + "users/" + id);

                    if (response.IsSuccessStatusCode)
                    {
                        var user = JsonConvert.DeserializeObject <UserDto>(await response.Content.ReadAsStringAsync());
                        CurrentUserBindProp = user;
                    }
                }
                break;

            case NavigationMode.Forward:
                break;

            case NavigationMode.Refresh:
                break;

            default:
                break;
            }
        }