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

            try
            {
                if (userType == 0)
                {
                    IMobileServiceTable <Azure.User> userTableObj = App.MobileService.GetTable <Azure.User>();
                    List <Azure.User> lista = await App.MobileService.GetTable <Azure.User>().ToListAsync();

                    Azure.User u = lista.Find(x => x.id == Convert.ToString(userId));
                    if (u.stanje_kredita == null)
                    {
                        u.stanje_kredita = "0";
                    }
                    u.stanje_kredita = Convert.ToString(Convert.ToDouble(u.stanje_kredita) + Convert.ToDouble(comboBox.SelectedItem));
                    iznos.Text       = u.stanje_kredita;
                    await userTableObj.UpdateAsync(u);
                }
                else
                {
                    IMobileServiceTable <Azure.Owner> ownerTableObj = App.MobileService.GetTable <Azure.Owner>();
                    List <Azure.Owner> listaVlasnika = await App.MobileService.GetTable <Azure.Owner>().ToListAsync();

                    Azure.Owner u = listaVlasnika.Find(x => x.id == Convert.ToString(userId));
                    if (u.stanje_kredita == null)
                    {
                        u.stanje_kredita = "0";
                    }
                    u.stanje_kredita = Convert.ToString(Convert.ToDouble(u.stanje_kredita) + Convert.ToDouble(comboBox.SelectedItem));
                    iznos.Text       = u.stanje_kredita;
                    await ownerTableObj.UpdateAsync(u);
                }
            }
            catch (IOException ex)
            {
                MessageDialog msgDialogError = new MessageDialog("Greška : " + ex.Message);
                await msgDialogError.ShowAsync();
            }
        }
コード例 #2
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            int userId   = UserView.userID;
            int userType = UserView.userType;

            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 (u.stanje_kredita == null)
                    {
                        u.stanje_kredita = "0";
                    }
                    iznos.Text = u.stanje_kredita;
                }
                else
                {
                    List <Azure.Owner> listaVlasnika = await App.MobileService.GetTable <Azure.Owner>().ToListAsync();

                    Azure.Owner u = listaVlasnika.Find(x => x.id == Convert.ToString(userId));
                    if (u.stanje_kredita == null)
                    {
                        u.stanje_kredita = "0";
                    }
                    iznos.Text = u.stanje_kredita;
                }
            }
            catch (IOException ex)
            {
                MessageDialog msgDialogError = new MessageDialog("Greška : " + ex.Message);
                await msgDialogError.ShowAsync();
            }
        }
コード例 #3
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();
                }
            }
        }
コード例 #4
0
        private async void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (Model.Validator.RegistrationDetailsEmpty(TextBoxName.Text.ToString(), TextBoxSurname.Text.ToString(), TextBoxPassword.Password.ToString(), TextBoxUsername.Text.ToString(), TextBoxEmail.Text.ToString()))
                {
                    throw new IOException("Nijedno polje ne smije biti prazno!");
                }
                if (!Model.Validator.EmailIsValid(TextBoxEmail.Text.ToString()))
                {
                    throw new IOException("Neispravan Email format!");
                }
                using (var db = new SPARKDbContext())
                {
                    List <Azure.User> lista = await App.MobileService.GetTable <Azure.User>().ToListAsync();

                    List <Azure.Owner> listaVlasnika = await App.MobileService.GetTable <Azure.Owner>().ToListAsync();

                    var user = new User();
                    if (isUser)
                    {
                        /*   user = new User
                         * {
                         *     Name = TextBoxName.Text.ToString(),
                         *     Surname = TextBoxSurname.Text.ToString(),
                         *     Username = TextBoxUsername.Text.ToString(),
                         *     Password = TextBoxPassword.Text.ToString(),
                         *     Email = TextBoxEmail.Text.ToString()
                         * };*/

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

                        try
                        {
                            Azure.User obj = new Azure.User();
                            obj.Name           = TextBoxName.Text.ToString();
                            obj.Surname        = TextBoxSurname.Text.ToString();
                            obj.id             = Convert.ToString(lista.Count + 1);
                            obj.Password       = TextBoxPassword.Password.ToString();
                            obj.stanje_kredita = "0";
                            obj.Username       = TextBoxUsername.Text.ToString();
                            if (lista.Find(x => x.Username == obj.Username) != null || listaVlasnika.Find(x => x.Username == obj.Username) != null)
                            {
                                throw new IOException("Korisničko ime već postoji!");
                            }
                            obj.Email = TextBoxEmail.Text.ToString();
                            await userTableObj.InsertAsync(obj);

                            MessageDialog msgDialog = new MessageDialog("Uspješno ste se registrovali na SPARK.");
                            await msgDialog.ShowAsync();
                        }
                        catch (IOException ex)
                        {
                            MessageDialog msgDialogError = new MessageDialog("Greška : " + ex.Message);
                            await msgDialogError.ShowAsync();
                        }
                    }
                    else
                    {
                        /*    user = new Owner
                         *  {
                         *      Name = TextBoxName.Text.ToString(),
                         *      Surname = TextBoxSurname.Text.ToString(),
                         *      Username = TextBoxUsername.Text.ToString(),
                         *      Password = TextBoxPassword.Text.ToString(),
                         *      Email = TextBoxEmail.Text.ToString()
                         *  };*/


                        IMobileServiceTable <Azure.Owner> userTableObj = App.MobileService.GetTable <Azure.Owner>();
                        try
                        {
                            Azure.Owner obj = new Azure.Owner();
                            obj.Name     = TextBoxName.Text.ToString();
                            obj.Surname  = TextBoxSurname.Text.ToString();
                            obj.id       = Convert.ToString(listaVlasnika.Count + 1);
                            obj.Password = TextBoxPassword.Password.ToString();
                            obj.Username = TextBoxUsername.Text.ToString();
                            if (lista.Find(x => x.Username == obj.Username) != null || listaVlasnika.Find(x => x.Username == obj.Username) != null)
                            {
                                throw new IOException("Korisničko ime već postoji!");
                            }
                            obj.Email = TextBoxEmail.Text.ToString();

                            await userTableObj.InsertAsync(obj);

                            MessageDialog msgDialog = new MessageDialog("Uspješno ste unijeli novog vlasnika.");
                            await msgDialog.ShowAsync();
                        }
                        catch (IOException ex)
                        {
                            MessageDialog msgDialogError = new MessageDialog("Greška : " + ex.Message);
                            await msgDialogError.ShowAsync();
                        }
                    }

                    db.User.Add(user);
                    db.SaveChanges();
                }
                TextBoxName.Text         = string.Empty;
                TextBoxSurname.Text      = string.Empty;
                TextBoxUsername.Text     = string.Empty;
                TextBoxPassword.Password = string.Empty;
                TextBoxEmail.Text        = string.Empty;
            }
            catch (IOException ex)
            {
                MessageDialog msgDialogError = new MessageDialog("Greška : " + ex.Message);
                msgDialogError.Commands.Add(new UICommand {
                    Label = "Ok"
                });
                await msgDialogError.ShowAsync();
            }
        }