예제 #1
0
        public CardDefault(Binary b)
        {
            this.b = b;
            InitializeComponent();
            Account acc = MapPage._g;

            if (acc is Guests)
            {
                Guests g = acc as Guests;
                if (!DBActions.hasBooked(g, b.PRODUCT))
                {
                    btn.Text = "RESERVERA";
                }
            }
            lbl.Text     = b.PRODUCT.Description;
            btn.Clicked += async(s, e) => {
                if (loading)
                {
                    return;
                }
                if (MapPage._g is Admins)
                {
                    if (await DBActions.Check(MapPage._g as Admins, MapPage.mapPage))
                    {
                        return;
                    }
                }
                loading = true;
                await DBActions.LoadProducts();

                await DBActions.LoadUsers();

                var prds = DBActions.GetProductById(b.PRODUCT.ID);
                if (prds != null && prds.Quantity > 0 &&
                    DBActions.GetAdminById(prds.AdminID) != null)
                {
                    MapPage.mapPage.OpenProduct(b);
                }
                else
                {
                    App.Send("Info", "Produkten finns inte längre!", "Ok");
                    if (DBActions.GetAdminById(prds.AdminID) == null)
                    {
                        await DBActions.CheckProducts();
                    }
                    MapPage.mapPage.ReloadAll();
                }
                loading = false;
            };
        }
예제 #2
0
        private async void Btn_add(object s, EventArgs a)
        {
            if (await DBActions.Check(_g as Admins, this))
            {
                return;
            }
            if (clicked)
            {
                return;
            }
            clicked = true;
            var a1 = prd_name.Text; var a2 = oprice.Text; var a3 = price.Text;
            var a4 = quantity.Text; var a5 = tmr.Time; var a6 = desc.Text;

            if (file == null || a1 == null || a2 == null || a3 == null || a4 == null || a5 == null ||
                string.IsNullOrEmpty(a6))
            {
                App.Send("Fel", "Fyll i alla fälten!", "Avbryt");
                clicked = false;
                return;
            }
            try
            {
                double.Parse(a2); double.Parse(a3); int.Parse(a4);
            } catch (Exception e)
            {
                App.Send("Fel", "Ange ett tal!", "Avbryt");
                clicked = false;
                return;
            }
            icon_r.IsVisible = true;
            icon_r.Play();
            bool f  = false;
            int  id = 0;

            while (!f)
            {
                id = random.Next(1, 100000000);
                if (DBActions.GetProductById(id) == null)
                {
                    f = true;
                }
            }
            Products product = new Products
            {
                ID          = id,
                AdminID     = ((Admins)_g).ID,
                PName       = a1,
                OldPrice    = float.Parse(a2),
                NewPrice    = float.Parse(a3),
                Quantity    = int.Parse(a4),
                ExpireTime  = a5,
                Description = a6
            };
            await DBActions.FullyAddProduct(product, App.ImageToByte(file));

            icon_r.Pause();
            icon_r.Animation = "check.json";
            icon_r.Speed     = 0.6f;
            icon_r.Loop      = false;
            icon_r.Play();
            ReloadAll();
            ClearInputs();
            clicked = false;
        }