示例#1
0
        public async void AddProduct(string productCode)
        {
            try
            {
                if (!await DataAccessHandler.DataAccess.IsValidKey(productCode))
                {
                    await DisplayAlert("Produktcode ungültiger", "Es wurde ein ungültiger Produktcode eingegeben. Bitte anderen code eingeben.", "Neue Eingabe");
                    return;
                }
                localFileSystem file = new localFileSystem();
                String userPath = file.AdjustPath(file.GetUser().user_Email);

                //Gets the Serveradress 
                DataAccessHandler accessHandler = new DataAccessHandler();
                string serverAdress = accessHandler.ServerAdress;

                IFtpClient client = DependencyService.Get<IFtpClient>();
                Product product = await DataAccessHandler.DataAccess.GetProductByKey(productCode);

                List<Product> listUserProducts = await DataAccessHandler.DataAccess.GetUserProducts(file.GetUser());
                foreach (var userProducts in listUserProducts)
                {
                    if (userProducts.product_ID == product.product_ID)
                    {
                        await DisplayAlert("Produkt bereits vorhanden!", "Sie besitzen dieses Produkt bereits", "OK");
                        return;
                    }
                }
                //Loads the List<PContent> of the Product from the server
                List<PContent> listPContents = await DataAccessHandler.DataAccess.GetPContent(product.product_ID);
                //Loads the List<PContent> of the Product from the the User-Folder
                List<PContent> newlistPContents = file.loadContentList(userPath);

                foreach (PContent pcontent in listPContents)
                {                    
                    //stops if the pcontent is empty
                    if (pcontent.content_ID == 0) break;
                    //adds new Pcontent if necessary
                    while (newlistPContents.Count <= pcontent.content_ID)
                    {
                        newlistPContents.Add(null);
                    }
                    //updates PContent
                    newlistPContents[pcontent.content_ID] = pcontent;
                    if (pcontent.content_Kind!=0) {
                        client.DownloadFile(@"Thumbnail/" + pcontent.content_ID + ".png",
                        DependencyService.Get<ISaveAndLoad>().Getpath(file.GetUser().user_Email + @"/Thumbnail/") + pcontent.content_ID + ".png", serverAdress, accessHandler.FtpName,
                        accessHandler.FtpPassword);
                    }

                    List<string> contentPath =
                        await DataAccessHandler.DataAccess.GetFileServerPath(pcontent.content_ID);                   

                    //creates a new p folder for the content_Kind if not exists
                    DependencyService.Get<ISaveAndLoad>().CreateFolder(DependencyService.Get<ISaveAndLoad>().PathCombine(
                    DependencyService.Get<ISaveAndLoad>().Getpath(userPath), "p" + pcontent.content_ID));

                    foreach (var path in contentPath)
                    {
                        if (pcontent.content_ID == 0) break;
                        //Download for each PContent its Files
                        DependencyService.Get<ISaveAndLoad>().CreateFolder(userPath + @"/p" + pcontent.content_ID);
                        client.DownloadFile(path,
                            DependencyService.Get<ISaveAndLoad>().Getpath(file.GetUser().user_Email) + @"/p" +
                            pcontent.content_ID + @"/" + Path.GetFileName(path), serverAdress, accessHandler.FtpName,
                            accessHandler.FtpPassword);
                    }
                }
                //Adds the Product to the Product-File from the User
                List<Product> newUserProducts = file.LoadProductList();
                //newUserProducts.Add(product);
                file.SaveModelsLocal(userPath, newUserProducts, newlistPContents);
                //Adds the Product to the User in the Database
                DataAccessHandler.DataAccess.AddProductToUser(product.product_ID, file.GetUser());
                DataAccessHandler.DataAccess.SetProductKeyInvalid(productCode);
                await DisplayAlert("Produkt aktiviert!", "Das Produkt wurde erfolgreiche aktiviert!", "OK");
                await Navigation.PushModalAsync(new NavigationPage(new MainMenuPage(file.GetUser())));
            }
            catch (Exception e)
            {
                Debug.WriteLine("Fehler beim hinzufügen von Produkt: " + e);
                await DisplayAlert("Fehler beim Downloaden", "Es gab einen Fehler beim Downloaden, bitte erneut versuchen", "OK");
            }
        }
示例#2
0
        /// <summary>
        /// Konstruktor der MainMenuPage, welcher eine Instanz der Seite erstellt.
        /// </summary>
        /// <param name="user"></param>
        public MainMenuPage(User user)
        {
            DataAccessHandler accessHandler = new DataAccessHandler();
            string serverAdress = accessHandler.ServerAdress;
            files = new localFileSystem();
            String userPath = files.AdjustPath(user.user_Email);
            files.CreateInitalFolders(userPath);

            //Toolbar
            ToolbarItem toolButton = new ToolbarItem
            {
                Name = "Hinzufügen",
                Order = ToolbarItemOrder.Primary,
                Icon = null,
                Command = new Command(() => Navigation.PushAsync(new AddProduktPage()))
            };
            this.ToolbarItems.Add(toolButton);
            //?
            //InitLogout();

            //Ende Toolbar

            //View
            ProductCollection = new Collection<Product>();
            ProductCollection = files.LoadProductList();
            List<PContent> PcontentCollection = files.loadContentList(userPath);

            ScrollView scrollView = new ScrollView();
            StackLayout stackLayout = new StackLayout();

            foreach (Product product in ProductCollection)
            {
                TapGestureRecognizer gesture = new TapGestureRecognizer();
                bool owned = files.HasContent(product, PcontentCollection);
                Color color = Color.FromHex("E2001A");
                DetailPage detailPage = new DetailPage(product, userPath);

                var test = (DependencyService.Get<ISaveAndLoad>().PathCombine(DependencyService.Get<ISaveAndLoad>().Getpath(localFileSystem.productFolderLocation), product.product_ID + product.product_Thumbnail));

                if (owned == true)
                    color = Color.FromHex("006AB3");
                Frame frame = new Frame
                {
                    BackgroundColor = color,
                    VerticalOptions = LayoutOptions.FillAndExpand,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    Content = new StackLayout
                    {
                        Orientation = StackOrientation.Horizontal,
                        VerticalOptions = LayoutOptions.Center,
                        HorizontalOptions = LayoutOptions.StartAndExpand,
                        Children =
                        {
                            new Image
                            {
                                Source = ImageSource.FromFile(DependencyService.Get<ISaveAndLoad>().PathCombine(DependencyService.Get<ISaveAndLoad>().Getpath(localFileSystem.productFolderLocation), product.product_Thumbnail)),
                                VerticalOptions = LayoutOptions.Center,
                                HorizontalOptions = LayoutOptions.Center,
                                HeightRequest = 110
                            },

                                    new Label
                                    {
                                        FormattedText = product.product_Name,
                                        TextColor = Color.Black,
                                        VerticalOptions = LayoutOptions.Center,
                                        FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                                        HorizontalOptions = LayoutOptions.Center
                                    },
                            }//ende stacklayout (innen)
                    }//ende stacklayout
                };//frame ende

                stackLayout.Children.Add(frame);
                gesture.Tapped += async (sender, e) =>
                {
                    await Navigation.PushAsync(detailPage);
                };
                frame.GestureRecognizers.Add(gesture);
            }

            scrollView.Content = stackLayout;
            Content = scrollView;
            BackgroundColor = Color.White;
            Padding = new Thickness(5, Device.OnPlatform(0, 15, 0), 5, 5);
            //View Ende
        }