public override void OnNavigatedTo(INavigationParameters parameters)
        {
            switch (parameters.GetNavigationMode())
            {
            case NavigationMode.Back:
                if (parameters.ContainsKey("CategoryBindProp"))
                {
                    var category = parameters["CategoryBindProp"] as CategoryDto;
                    ListCategoryBindProp.Remove(category);
                }
                break;

            case NavigationMode.New:
                break;

            case NavigationMode.Forward:
                break;

            case NavigationMode.Refresh:
                break;

            default:
                break;
            }
        }
Beispiel #2
0
        private async void OnSelectCategory(CategoryDto obj)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                var selectedCategory = ListCategoryBindProp.FindFirst(z => z.IsSelected);
                if (selectedCategory != null)
                {
                    selectedCategory.IsSelected = false;
                }
                obj.IsSelected               = true;
                CurrentCategory              = obj;
                InvoiceFrameVisibleBindProp  = false;
                MenuFrameVisibleBindProp     = true;
                ItemFrameVisibleBindProp     = true;
                DiscountFrameVisibleBindProp = false;
                SettingFrameVisibleBindProp  = false;
            }
            catch (Exception e)
            {
                await ShowErrorAsync(e);
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #3
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;
            }
        }
        private async void OnAddNewCategory(object obj)
        {
            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                var newCate = new VisualCategoryModel
                {
                    Id           = Guid.NewGuid().ToString(),
                    CategoryName = NewCategoryNameBindProp,
                    Status       = Status.New
                };
                ListCategoryBindProp.Add(newCate);
                NewCategoryNameBindProp = string.Empty;
            }
            catch (Exception e)
            {
                await ShowError(e);
            }
            finally
            {
                IsBusy = false;
            }
        }
        private async void OnDeleteCategory(object obj)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                var canDelete = await DisplayDeleteAlertAsync();

                if (canDelete)
                {
                    var cate = obj as VisualCategoryModel;

                    ListCategoryBindProp.Remove(cate);
                    _listDeleted.Add(cate);
                }
            }
            catch (Exception e)
            {
                await ShowError(e);
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #6
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;
            }
        }
        private async void OnAddNewCategory(object obj)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                var categoryToCreate = new CategoryDto {
                    Name = "New Category", Icon = FontAwesomeIcon.Coffee
                };
                var json    = JsonConvert.SerializeObject(categoryToCreate);
                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 + "categories/", content);

                    if (response.IsSuccessStatusCode)
                    {
                        var category = JsonConvert.DeserializeObject <CategoryDto>(await response.Content.ReadAsStringAsync());
                        ListCategoryBindProp.Add(category);
                    }
                };
            }
            catch (Exception e)
            {
                await ShowErrorAsync(e);
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #8
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 #9
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;
            }
        }
Beispiel #10
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;
            }
        }
        private async void OnSave(object obj)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                // Thuc hien cong viec tai day
                if (IsEditing) //neu dang o che do chinh sua
                {
                    var categoryLogic = new CategoryLogic(_dbContext);
                    // Kiem tra them xoa sua
                    foreach (var category in ListCategoryBindProp)
                    {
                        switch (category.Status)
                        {
                        case Status.New:
                            var newCategory = new Category
                            {
                                Id           = category.Id,
                                CategoryName = category.CategoryName
                            };
                            await categoryLogic.CreateAsync(newCategory, false);

                            break;

                        case Status.Normal:
                            break;

                        case Status.Modified:
                            var modCategory = new Category
                            {
                                Id           = category.Id,
                                CategoryName = category.CategoryName
                            };
                            await categoryLogic.UpdateAsync(modCategory, false);

                            break;

                        case Status.Deleted:
                            break;

                        default:
                            break;
                        }
                        MessagingCenter.Send(category, Messages.CATEGORY_MESSAGE);
                    }

                    foreach (var cate in _listDeleted)
                    {
                        cate.Status = Status.Deleted;
                        await categoryLogic.DeleteAsync(cate.Id, false);

                        MessagingCenter.Send(cate, Messages.CATEGORY_MESSAGE);
                    }
                    //neu co nhap category moi thi tao roi quay ve
                    if (!string.IsNullOrWhiteSpace(NewCategoryNameBindProp))
                    {
                        var newCate = new Category
                        {
                            Id           = Guid.NewGuid().ToString(),
                            CategoryName = NewCategoryNameBindProp,
                        };
                        var newVsCate = new VisualCategoryModel
                        {
                            Id           = newCate.Id,
                            CategoryName = newCate.CategoryName,
                            Status       = Status.New
                        };
                        await categoryLogic.CreateAsync(newCate, false);

                        ListCategoryBindProp.Add(newVsCate);
                        MessagingCenter.Send(newCate, Messages.CATEGORY_MESSAGE);
                    }

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

                    await NavigationService.GoBackAsync();
                }
                else // neu dang o che do binh thuong
                {
                    var categoryLogic = new CategoryLogic(_dbContext);
                    // Kiem tra them moi
                    foreach (var category in ListCategoryBindProp)
                    {
                        switch (category.Status)
                        {
                        case Status.New:
                            var newCategory = new Category
                            {
                                Id           = category.Id,
                                CategoryName = category.CategoryName,
                            };
                            await categoryLogic.CreateAsync(newCategory, false);

                            MessagingCenter.Send(category, Messages.CATEGORY_MESSAGE);
                            category.Status = Status.Normal;
                            break;

                        case Status.Normal:
                            break;

                        case Status.Modified:
                            break;

                        case Status.Deleted:
                            break;
                        }
                    }

                    // neu khong nhap gi
                    if (string.IsNullOrWhiteSpace(NewCategoryNameBindProp))
                    {
                        //neu co chon thi tra ve ten category
                        if (SelectedCategoryBindProp != null)
                        {
                            //truyen ten category ve trang tao item
                            var param = new NavigationParameters();
                            param.Add(Keys.CATEGORY, SelectedCategoryBindProp);

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

                            await NavigationService.GoBackAsync(param);
                        }
                        else
                        {
                            await _dbContext.SaveChangesAsync().ConfigureAwait(false);

                            return;
                        }
                    }
                    else // tao moi
                    {
                        var newCate = new Category
                        {
                            Id           = Guid.NewGuid().ToString(),
                            CategoryName = NewCategoryNameBindProp,
                        };
                        var newVsCate = new VisualCategoryModel
                        {
                            Id           = newCate.Id,
                            CategoryName = newCate.CategoryName,
                            Status       = Status.New
                        };
                        await categoryLogic.CreateAsync(newCate, false);

                        ListCategoryBindProp.Add(newVsCate);
                        MessagingCenter.Send(newCate, Messages.CATEGORY_MESSAGE);

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

                        //truyen ten category ve trang tao item
                        var param = new NavigationParameters();
                        param.Add(Keys.CATEGORY, newCate);

                        await NavigationService.GoBackAsync(param);
                    }
                }
            }
            catch (Exception e)
            {
                await ShowError(e);
            }
            finally
            {
                IsBusy = false;
            }
        }