コード例 #1
0
        private async void BookParkingButton_Click(object sender, RoutedEventArgs e)
        {
            if (p != null)
            {
                int userId   = UserView.userID;
                int userType = UserView.userType;

                DateTime odD = OdDate.Date.Date;
                DateTime doD = DoDate.Date.Date;

                double hours  = (doD - odD).TotalHours + (DoTime.Time - OdTime.Time).TotalHours;
                double valuta = p.Price;
                try
                {
                    if (userType == 0)
                    {
                        List <Azure.User> lista = await App.MobileService.GetTable <Azure.User>().ToListAsync();

                        Azure.User u = lista.Find(x => x.id == Convert.ToString(userId));
                        if (Convert.ToDouble(u.stanje_kredita) < hours * valuta)
                        {
                            throw new IOException("Nemate dovoljno kredita!");
                        }
                        else
                        {
                            u.stanje_kredita = Convert.ToString(Convert.ToDouble(u.stanje_kredita) - hours * valuta);
                        }
                        IMobileServiceTable <Azure.User> userTableObj = App.MobileService.GetTable <Azure.User>();
                        await userTableObj.UpdateAsync(u);
                    }
                    else
                    {
                        List <Azure.Owner> listaVlasnika = await App.MobileService.GetTable <Azure.Owner>().ToListAsync();

                        Azure.Owner u = listaVlasnika.Find(x => x.id == Convert.ToString(userId));
                        if (Convert.ToDouble(u.stanje_kredita) < hours * valuta)
                        {
                            throw new IOException("Nemate dovoljno kredita!");
                        }
                        else
                        {
                            u.stanje_kredita = Convert.ToString(Convert.ToDouble(u.stanje_kredita) - hours * valuta);
                        }
                        IMobileServiceTable <Azure.Owner> ownerTableObj = App.MobileService.GetTable <Azure.Owner>();
                        await ownerTableObj.UpdateAsync(u);
                    }
                    IMobileServiceTable <Azure.Parking> parkingTableObj = App.MobileService.GetTable <Azure.Parking>();
                    List <Azure.Parking> listaParkinga = await App.MobileService.GetTable <Azure.Parking>().ToListAsync();

                    Azure.Parking i = listaParkinga.Find(x => x.id == Convert.ToString(p.Id));
                    i.MonthlyProfit  = i.MonthlyProfit + hours * valuta;
                    i.TodaysProfit   = i.TodaysProfit + hours * valuta;
                    i.NumTakenSpaces = i.NumTakenSpaces + 1;
                    await parkingTableObj.UpdateAsync(i);

                    MessageDialog msgDialogError = new MessageDialog("Uspješno ste rezervisali parking!");
                    await msgDialogError.ShowAsync();
                }
                catch (IOException ex)
                {
                    MessageDialog msgDialogError = new MessageDialog("Greška : " + ex.Message);
                    await msgDialogError.ShowAsync();
                }
            }
        }
コード例 #2
0
        private async void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                using (var db = new SPARK.Model.SPARKDbContext())
                {
                    /*  var parking = new SPARK.Model.Parking
                     * {
                     *    Name = TextBoxName.Text,
                     *    Zone = Convert.ToInt16(TextBoxParkingZone.Text),
                     *    Price = Convert.ToDouble(TextBoxPrice.Text),
                     *    Address = TextBoxAddress.Text,
                     *    //working hours ???
                     *    WorkingHours = new KeyValuePair<DateTime, DateTime>(Convert.ToDateTime("1.1.2017"), Convert.ToDateTime("5.2.2017")),
                     *    CoordX = (double)lokacijaParkinga.Location.Position.Longitude,
                     *    CoordY = (double)lokacijaParkinga.Location.Position.Longitude,
                     * };
                     * db.Parkings.Add(parking);
                     * db.SaveChanges();
                     *
                     * var dialog1 = new MessageDialog("Uspješno registrovan parking '" + TextBoxName.Text + "'");
                     * dialog1.Commands.Add(new UICommand { Label = "Ok" });
                     * await dialog1.ShowAsync();*/

                    IMobileServiceTable <Azure.Parking> userTableObj = App.MobileService.GetTable <Azure.Parking>();

                    List <Azure.Parking> lista = await App.MobileService.GetTable <Azure.Parking>().ToListAsync();

                    try
                    {
                        Azure.Parking obj = new Azure.Parking();
                        obj.Name        = TextBoxName.Text.ToString();
                        obj.id          = Convert.ToString(lista.Count + 1);
                        obj.Address     = TextBoxAddress.Text;
                        obj.WorkingFrom = Convert.ToString(openingTime.Time.Hours) + ":" + Convert.ToString(openingTime.Time.Minutes);
                        obj.WorkingTo   = Convert.ToString(closingTime.Time.Hours) + ":" + Convert.ToString(closingTime.Time.Minutes);
                        obj.CoordY      = (double)lokacijaParkinga.Location.Position.Longitude;
                        obj.CoordX      = (double)lokacijaParkinga.Location.Position.Latitude;

                        try
                        {
                            obj.Capacity = Convert.ToInt32(TextBoxCapacity.Text.ToString());
                        }catch (Exception ee)
                        {
                            throw new IOException("Neispravan kapacitet!");
                        }
                        try
                        {
                            obj.Zone = Convert.ToInt32(TextBoxParkingZone.Text);
                        }
                        catch (Exception ee)
                        {
                            throw new IOException("Neispravna zona!");
                        }
                        try
                        {
                            obj.MinCredits = Convert.ToInt32(TextBoxParkingMinCredits.Text.ToString());
                        }
                        catch (Exception ee)
                        {
                            throw new IOException("Neispravno napisan broj minimalnih kredita!");
                        }
                        try
                        {
                            obj.Price = Convert.ToDouble(TextBoxPrice.Text);
                        }
                        catch (Exception ee)
                        {
                            throw new IOException("Neispravno napisana cijena!");
                        }
                        obj.id_vlasnika    = userID;
                        obj.NumTakenSpaces = 0;
                        obj.TodaysProfit   = 0;
                        obj.MonthlyProfit  = 0;
                        await userTableObj.InsertAsync(obj);

                        MessageDialog msgDialog = new MessageDialog("Uspješno ste unijeli novi parking.");
                        await msgDialog.ShowAsync();
                    }
                    catch (IOException ex)
                    {
                        MessageDialog msgDialogError = new MessageDialog("Error : " + ex.Message);
                        await msgDialogError.ShowAsync();
                    }

                    TextBoxName.Text              = string.Empty;
                    TextBoxParkingZone.Text       = string.Empty;
                    TextBoxPrice.Text             = string.Empty;
                    TextBoxAddress.Text           = string.Empty;
                    TextBoxParkingMinCredits.Text = string.Empty;
                    TextBoxCapacity.Text          = string.Empty;
                }
            }
            catch (Exception izuzetak)
            {
                var dialog1 = new MessageDialog(izuzetak.Message);
                dialog1.Commands.Add(new UICommand {
                    Label = "Ok"
                });
                await dialog1.ShowAsync();
            }
        }