Exemplo n.º 1
0
        protected async override void OnAppearing()
        {
            AppDrawer.Destroy();
            TabBarCustomer.Destroy();
            TabbarStoreManager.Destroy();
            UserSettingView.Destroy();
            User user = dataProvider.GetUserByIDUser(Infor.IDUser);

            user.IsLogined = 0;


            Preferences.Set("IDLogin", "");
            //OneSignal.Current.SendTag("IsLogined", "0");

            //TEST INTERNET CONNECTTION
            var httpClient = new HttpClient();

            try
            {
                var testInternet = await httpClient.GetStringAsync(ServerDatabase.localhost + "store/getstorebyid/test");

                OneSignal.Current.SetExternalUserId("");
                await httpClient.PostAsJsonAsync(ServerDatabase.localhost + "user/update", user);
            }
            catch (Exception ex)
            {
            }

            App.Current.MainPage = new NavigationPage(LoginView.GetInstance());
        }
        private void Save_Clicked(object sender, EventArgs e)
        {
            string message = CheckInfor();

            if (message != "")
            {
                DisplayAlert("Error", message, "OK");
                return;
            }
            AddressItem newAddress = new AddressItem
            {
                Country     = CountryText.Text,
                City        = CityText.Text,
                HouseNumber = HouseNumberText.Text,
                District    = DistrictText.Text
            };

            //(App.Current.MainPage.Navigation.NavigationStack.ElementAt(0).BindingContext as StoreSetttingViewModel).ChangeAddress(newAddress);
            if (parentName == "StoreSetting")
            {
                (TabbarStoreManager.GetInstance().Children.ElementAt(4).BindingContext as StoreSetttingViewModel).ChangeAddress(newAddress);
            }
            else
            {
                (UserSettingView.GetInstance().BindingContext as UserSettingViewModel).ChangeAddress(newAddress);
            }
            App.Current.MainPage.Navigation.PopAsync();
        }
        public async void AddProduct(Product newProduct)
        {
            ProductItem newItem = new ProductItem
            {
                Product  = newProduct,
                isHidden = false
            };

            _saveProducts.Add(newItem);

            //Thêm product ở database local
            DataUpdater.AddProduct(newProduct);
            //Thêm product ở database server
            await httpClient.PostAsJsonAsync(ServerDatabase.localhost + "product/insert", newProduct);

            LoadProducts(false);
            var StoreDashBoardVM = TabbarStoreManager.GetInstance().Children.ElementAt(1).BindingContext as StoreDashBoardViewModel;

            StoreDashBoardVM.LoadData();

            //PUSH NOTI
            string datas = PushNotificationService.ConvertDataAddProduct(newProduct);

            PushNotificationService.Push(NotiNumber.AddProduct, datas, true);
        }
Exemplo n.º 4
0
        public void Goto(CategoryItem item)
        {
            int index = 0;

            switch (item.Title)
            {
            case "Manage Products":
                index = 1;
                break;

            case "Handle Orders":
                index = 2;
                break;

            case "Feedback":
                index = 3;
                break;

            case "Build store":
                index = 4;
                break;
            }
            var Tabbar = TabbarStoreManager.GetInstance();

            Tabbar.CurrentPage = Tabbar.Children[index];
        }
Exemplo n.º 5
0
        protected override bool OnBackButtonPressed()
        {
            int x = App.Current.MainPage.Navigation.NavigationStack.Count;

            if (x == 1)
            {
                if (appShell.CurrentItem == flyoutShopping)
                {
                    var tabbar = TabBarCustomer.GetInstance();
                    tabbar.GoHome();
                }
                else
                if (appShell.CurrentItem == flyoutStore)
                {
                    var tabbar = TabbarStoreManager.GetInstance();
                    tabbar.GoHome();
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                base.OnBackButtonPressed();
            }

            return(true);
        }
        public async static void CancelOrderAction(string data)
        {
            OrderBill canceledOder = JsonConvert.DeserializeObject <OrderBill>(data);

            //fetch data products in server
            await ServerDatabase.FetchProductData();

            //xóa orderbill
            DataUpdater.DeleteOrderBillByID(canceledOder.IDOrderBill);

            //update list order+số lượng product cho cửa hàng bị hủy order
            if (Infor.IDStore == canceledOder.IDStore)
            {
                (TabbarStoreManager.GetInstance().Children.ElementAt(1).BindingContext as ProductManagerViewModel).LoadData(true);
                (TabbarStoreManager.GetInstance().Children.ElementAt(2).BindingContext as OrderManagerViewModel).LoadData();
            }

            if (Infor.IDUser == canceledOder.IDUser)
            {
                (TabBarCustomer.GetInstance().Children.ElementAt(3).BindingContext as ListOrdersViewModel).LoadData();
            }

            //update số lượng product cho các user khác (gồm cả user là store bị hủy)
            var ShowStoreVM = ShowStoreView.GetInstance().BindingContext as ShowStoreViewModel;

            if (ShowStoreVM != null && ShowStoreVM.IDStore == canceledOder.IDStore)
            {
                ShowStoreVM.LoadData(true);
            }
        }
Exemplo n.º 7
0
        private async void SendClick(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(AnswerEntry.Text))
            {
                await DisplayAlert("Error", "Your answer must not be blank!", "OK");

                return;
            }

            //call api update orderbill
            ReviewItem   reviewItem   = this.BindingContext as ReviewItem;
            DataProvider dataProvider = DataProvider.GetInstance();
            OrderBill    order        = dataProvider.GetOrderBillByIDOrderBill(reviewItem.IDOrderBill);

            order.StoreAnswer = AnswerEntry.Text;

            //update orderbill ở database local
            DataUpdater.UpdateStoreAnswerOrderbill(order);
            //update orderbill ở database server
            var httpClient = new HttpClient();
            await httpClient.PostAsJsonAsync(ServerDatabase.localhost + "orderbill/update", order);

            await PopupNavigation.Instance.PopAsync();

            //RELOAD REVIEW MANAGER VIEW
            var ReviewVM = TabbarStoreManager.GetInstance().Children.ElementAt(3).BindingContext as ReviewManagerViewModel;

            ReviewVM.LoadData();

            MessageService.Show("Send answer successfully", 0);
            //PUSH NOTI
            string datas = PushNotificationService.ConvertDataAnswerFeedback(order);

            PushNotificationService.Push(NotiNumber.AnswerFeedback, datas, true);
        }
        public static void UpdateStoreAction(string data)
        {
            Store store = JsonConvert.DeserializeObject <Store>(data);

            DataUpdater.UpdateStore(store);
            //load lại list store view cho tất cả user
            (TabBarCustomer.GetInstance().Children.ElementAt(1).BindingContext as ListStoresViewModel).LoadData();
            (TabbarStoreManager.GetInstance().Children.ElementAt(0).BindingContext as StoreDashBoardViewModel).LoadData();
        }
        public static void UpdateUserAction(string data)
        {
            User user = JsonConvert.DeserializeObject <User>(data);

            DataUpdater.UpdateUser(user);
            //load lại list review cho tất cả user
            (TabbarStoreManager.GetInstance().Children.ElementAt(3).BindingContext as ReviewManagerViewModel).LoadData();
            (TabbarStoreManager.GetInstance().Children.ElementAt(0).BindingContext as StoreDashBoardViewModel).LoadData();
        }
        public static void SendReviewAction(string data)
        {
            OrderBill order = JsonConvert.DeserializeObject <OrderBill>(data);

            DataUpdater.UpdateOrderBill(order);

            (TabBarCustomer.GetInstance().Children.ElementAt(3).BindingContext as ListOrdersViewModel).LoadData();
            (TabbarStoreManager.GetInstance().Children.ElementAt(0).BindingContext as StoreDashBoardViewModel).LoadData();
            (TabbarStoreManager.GetInstance().Children.ElementAt(3).BindingContext as ReviewManagerViewModel).LoadData();
        }
        public async static void InsertOrderBillAction(string data)
        {
            //fetch data products in server
            await ServerDatabase.FetchProductData();

            OrderBill newOrder = JsonConvert.DeserializeObject <OrderBill>(data);

            DataUpdater.InsertOrderBill(newOrder);
            if (Infor.IDStore == newOrder.IDStore)
            {
                (TabbarStoreManager.GetInstance().Children.ElementAt(2).BindingContext as OrderManagerViewModel).LoadData();
            }
        }
        public static void ReceiveOrderAction(string data)
        {
            OrderBill order = JsonConvert.DeserializeObject <OrderBill>(data);

            DataUpdater.UpdateOrderBill(order);
            //nếu user không phải là store của order thì thoát
            if (order.IDStore != Infor.IDStore)
            {
                return;
            }
            //update màn hình list order
            (TabbarStoreManager.GetInstance().Children.ElementAt(2).BindingContext as OrderManagerViewModel).LoadData();
            (TabbarStoreManager.GetInstance().Children.ElementAt(3).BindingContext as ReviewManagerViewModel).LoadData();
        }
        public static void AddToCartAction(string data)
        {
            List <Product> receivedProducts = JsonConvert.DeserializeObject <List <Product> >(data);

            DataUpdater.UpdateProduct(receivedProducts);
            var showStore = ShowStoreView.GetInstance();

            if (showStore.BindingContext != null)
            {
                (showStore.BindingContext as ShowStoreViewModel).LoadData(true);
            }
            if (receivedProducts[0].IDStore == Infor.IDStore)
            {
                (TabbarStoreManager.GetInstance().Children.ElementAt(1).BindingContext as ProductManagerViewModel).LoadData(false);
            }
        }
        private void Save_Clicked(object sender, EventArgs e)
        {
            string message = CheckInfor();

            if (message != "")
            {
                DisplayAlert("Error", message, "OK");
                return;
            }
            StoreInfor newInfor = new StoreInfor
            {
                StoreName        = NameEntry.Text,
                StoreDescription = DescEntry.Text
            };

            //(App.Current.MainPage.Navigation.NavigationStack.ElementAt(0).BindingContext as StoreSetttingViewModel).ChangeInfor(newInfor);
            (TabbarStoreManager.GetInstance().Children.ElementAt(4).BindingContext as StoreSetttingViewModel).ChangeInfor(newInfor);

            App.Current.MainPage.Navigation.PopAsync();
        }
        public static void ReturnProductCartAction(string data)
        {
            List <Product> products = JsonConvert.DeserializeObject <List <Product> >(data);

            DataUpdater.UpdateProduct(products[0]);
            products.RemoveAt(0);
            DataUpdater.DeleteProducts(products);
            //Load lại data cho các user đang ở trong cửa hàng đó
            var ShowStoreVM = ShowStoreView.GetInstance().BindingContext as ShowStoreViewModel;

            if (ShowStoreVM != null && ShowStoreVM.IDStore == products[0].IDStore)
            {
                ShowStoreVM.LoadData(true);
            }
            //Load lại list product cho cửa hàng đó
            if (products[0].IDStore == Infor.IDStore)
            {
                (TabbarStoreManager.GetInstance().Children.ElementAt(1).BindingContext as ProductManagerViewModel).LoadData(true);
            }
        }
Exemplo n.º 16
0
        public async void ChangeActive()
        {
            IsActive = 1 - IsActive;
            //TEST INTERNET CONNECTTION
            var    httpClient = new HttpClient();
            string x          = "";

            try
            {
                var testInternet = await httpClient.GetStringAsync(ServerDatabase.localhost + "store/getstorebyid/test");
            }
            catch (Exception ex)
            {
                IsActive = 1 - IsActive;
                await App.Current.MainPage.DisplayAlert("Error", "Action fail, check your internet connection and try again!", "OK");

                return;
            }


            if (IsActive == 1)
            {
                if (dataProvider.IsLackOfStoreInfor())
                {
                    TabbarStoreManager.GetInstance().DisplayAlert("Notice", "Store's infor is not enough, please provide more information and try again", "OK");
                    IsActive = 1 - IsActive;
                    return;
                }
                if (!dataProvider.HasProductInMyStore())
                {
                    TabbarStoreManager.GetInstance().DisplayAlert("Notice", "There is no product for selling in your store, revise your products and try again", "OK");
                    IsActive = 1 - IsActive;
                    return;
                }
            }
            changeActive     = true;
            myStore.IsActive = IsActive;
            SaveChange();
        }
Exemplo n.º 17
0
        public async void CancelOrder(OrderBill orderBill)
        {
            using (UserDialogs.Instance.Loading("Canceling order"))
            {
                var            httpClient     = new HttpClient();
                List <Product> productInOrder = dataProvider.GetProductsInBillByIDBill(orderBill.IDOrderBill);
                //update quantityinventory ở local
                List <Product> sourceProducts = DataUpdater.ReturnListProductToSource(productInOrder);
                //api update quantityinventory ở server
                foreach (Product product in sourceProducts)
                {
                    await httpClient.PostAsJsonAsync(ServerDatabase.localhost + "product/update", product);
                }

                //api delete products trong order bị xóa (ở server)
                await httpClient.PostAsJsonAsync(ServerDatabase.localhost + "product/deletebyidorderbill/" + orderBill.IDOrderBill, new { });

                //delete product ở local
                DataUpdater.DeleteProducts(productInOrder);

                //delete orderbill server
                await httpClient.PostAsJsonAsync(ServerDatabase.localhost + "orderbill/deleteorderbillbyid/" + orderBill.IDOrderBill, new { });

                //delete orderbill local
                DataUpdater.DeleteOrderBillByID(orderBill.IDOrderBill);

                //Reload data OrderManager
                LoadData();
                //Reload data ProductManager
                (TabbarStoreManager.GetInstance().Children.ElementAt(1).BindingContext as ProductManagerViewModel).LoadData(true);
            }
            MessageService.Show("Cancel order successfully", 0);

            //PUSH NOTI
            string datas = PushNotificationService.ConvertDataCancelOrder(orderBill);

            PushNotificationService.Push(NotiNumber.CancelOrderForCustomer, datas, false);
            PushNotificationService.Push(NotiNumber.CancelOrderForOther, datas, true);
        }
        public async void ChangeImage()
        {
            try
            {
                string[] types    = { "image/*" };
                FileData fileData = await CrossFilePicker.Current.PickFile(types);

                if (fileData == null)
                {
                    return; // user canceled file picking
                }
                string path = fileData.FilePath;

                ProductImage = (ImageSource)path;
                ImagePath    = path;
                isNewImage   = true;
            }
            catch (Exception ex)
            {
                var page = TabbarStoreManager.GetInstance();
                await page.DisplayAlert("Error", "Error picking file from divice, try again!", "Ok");
            }
        }
Exemplo n.º 19
0
        public void GotoReview()
        {
            var Tabbar = TabbarStoreManager.GetInstance();

            Tabbar.CurrentPage = Tabbar.Children[3];
        }
Exemplo n.º 20
0
        private AppDrawer()
        {
            InitializeComponent();

            Shell.SetTabBarIsVisible(this, false);
            Shell.SetNavBarIsVisible(this, false);
            //Item CUSTOMER
            var shoppingTabs = new ShellContent()
            {
                Content = TabBarCustomer.GetInstance(),
                Title   = "Shopping",
                Icon    = "drawercart"
            };

            tabShopping.Items.Add(shoppingTabs);
            flyoutShopping.Items.Add(tabShopping);
            appShell.Items.Add(flyoutShopping);

            //Item STORE

            var storeTabs = new ShellContent()
            {
                Content = TabbarStoreManager.GetInstance(),
                Title   = "Your store",
                Icon    = "drawerstore"
            };

            tabStore.Items.Add(storeTabs);
            flyoutStore.Items.Add(tabStore);
            appShell.Items.Add(flyoutStore);

            //Item SETTING

            var settingTab = new ShellContent()
            {
                Content = UserSettingView.GetInstance(),
                Title   = "Setting",
                Icon    = "drawersetting"
            };

            tabSetting.Items.Add(settingTab);
            flyoutUserSetting.Items.Add(tabSetting);
            appShell.Items.Add(flyoutUserSetting);

            //Item LOGOUT

            var logoutTab = new ShellContent()
            {
                Content = new LogoutView(),
                Title   = "Logout",
                Icon    = "flatlogout"
            };

            tabLogout.Items.Add(logoutTab);
            flyoutLogout.Items.Add(tabLogout);

            appShell.Items.Add(flyoutLogout);

            //appShell.CurrentItem.PropertyChanged += CurrentItem_PropertyChanged;
            flyoutShopping.PropertyChanged    += FlyoutShopping_PropertyChanged;
            flyoutStore.PropertyChanged       += FlyoutStore_PropertyChanged;
            flyoutUserSetting.PropertyChanged += FlyoutUserSetting_PropertyChanged;

            DataProvider dataProvider = DataProvider.GetInstance();
            User         user         = dataProvider.GetUserByIDUser(Infor.IDUser);

            this.BindingContext = user;
        }
Exemplo n.º 21
0
        public async void SaveChange()
        {
            //TEST INTERNET CONNECTTION
            var    httpClient = new HttpClient();
            string x          = "";

            try
            {
                var testInternet = await httpClient.GetStringAsync("https://newappgroc.azurewebsites.net/store/getstorebyid/test");

                x = testInternet;
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Error", "Action fail, check your internet connection and try again!", "OK");

                return;
            }

            string message = CheckInfor();

            if (message != "")
            {
                var app = GroceryApp.Views.Drawer.AppDrawer.GetInstance();
                await app.DisplayAlert("Error", message, "OK");

                return;
            }
            if (ImagePath != "")
            {
                Account account = new Account(
                    "ungdung-grocery-xamarin-by-dk",
                    "378791526477571",
                    "scsyCxQS_C74MbAGdOutpwrzlnU"
                    );

                Cloudinary cloudinary   = new Cloudinary(account);
                var        uploadParams = new ImageUploadParams()
                {
                    File = new FileDescription(ImagePath)
                };
                try
                {
                    using (UserDialogs.Instance.Loading("Saving.."))
                    {
                        var uploadResult = await cloudinary.UploadAsync(uploadParams);

                        string url = uploadResult.SecureUri.ToString();
                        myStore.ImageURL = url;
                    }
                }
                catch (Exception ex)
                {
                    var page = TabbarStoreManager.GetInstance().Children.ElementAt(4) as StoreSettingView;
                    await page.DisplayAlert("Error", "Error upload image to server, try again!", "Ok");
                }
            }

            using (UserDialogs.Instance.Loading("Saving.."))
            {
                //update store ở database server
                await httpClient.PostAsJsonAsync(ServerDatabase.localhost + "store/update", myStore);

                //update store ở database local
                DataUpdater.UpdateStore(myStore);
            }

            if (changeActive)
            {
                if (myStore.IsActive == 0)
                {
                    MessageService.Show("Deactivate successfully", 0);
                }
                else
                {
                    MessageService.Show("Activate successfully", 0);
                }
                changeActive = false;
            }
            else
            {
                MessageService.Show("Setting store successfully", 0);
            }

            //PUSH NOTI
            string datas = PushNotificationService.ConvertDataUpdateStore(myStore);

            PushNotificationService.Push(NotiNumber.UpdateStore, datas, true);
        }
 public async void CancelOrder(OrderBill order)
 {
     (TabbarStoreManager.GetInstance().Children.ElementAt(2).BindingContext as OrderManagerViewModel).CancelOrder(order);
     await PopupNavigation.Instance.PopAsync();
 }
Exemplo n.º 23
0
        public void Goback()
        {
            var Tabbar = TabbarStoreManager.GetInstance();

            Tabbar.CurrentPage = Tabbar.Children[0];
        }
        public async void Add()
        {
            //TEST INTERNET CONNECTTION
            var    httpClient = new HttpClient();
            string x          = "";

            try
            {
                var testInternet = await httpClient.GetStringAsync(ServerDatabase.localhost + "store/getstorebyid/test");

                x = testInternet;
            }
            catch (Exception ex)
            {
                await App.Current.MainPage.DisplayAlert("Error", "Action fail, check your internet connection and try again!", "OK");

                return;
            }
            using (UserDialogs.Instance.Loading("Adding.."))
            {
                Product NewProduct = GetNewProduct();
                if (NewProduct == null)
                {
                    var app = AppDrawer.GetInstance();
                    await app.DisplayAlert("Error", "Product's infor is missing or invalid, please check again!", "OK");

                    return;
                }

                if (ImagePath != "" && isNewImage)
                {
                    Account account = new Account(
                        "ungdung-grocery-xamarin-by-dk",
                        "378791526477571",
                        "scsyCxQS_C74MbAGdOutpwrzlnU"
                        );

                    Cloudinary cloudinary   = new Cloudinary(account);
                    var        uploadParams = new ImageUploadParams()
                    {
                        File = new FileDescription(ImagePath)
                    };
                    try
                    {
                        using (UserDialogs.Instance.Loading("Saving.."))
                        {
                            var uploadResult = await cloudinary.UploadAsync(uploadParams);

                            string url = uploadResult.SecureUri.ToString();
                            NewProduct.ImageURL = url;
                            isNewImage          = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        var page = TabbarStoreManager.GetInstance();
                        await page.DisplayAlert("Error", "Error upload image to server, try again!", "Ok");
                    }
                }

                if (string.IsNullOrEmpty(NewProduct.ImageURL))
                {
                    NewProduct.ImageURL = GetDefaultImageProduct(NewProduct);
                }
                (TabbarStoreManager.GetInstance().Children.ElementAt(1).BindingContext as ProductManagerViewModel).AddProduct(NewProduct);

                await PopupNavigation.Instance.PopAsync();
            }
            MessageService.Show("Add product successfully", 0);
        }