예제 #1
0
 private void AddAction(Action action)
 {
     //Dodanie Akcji do ObservableCollection<Action>
     Actions.Add(action);
     using (con = new SQLiteConnection(connectionString)) //Stworzenie nowego połączenia SQL
     {
         con.Open();                                      //Otworzenie tego połączenia
         try
         {
             using (SQLiteCommand insertSQL = con.CreateCommand()) //Utworzenie polecenie SQL
             {
                 insertSQL.CommandText =
                     "INSERT INTO Akcja(IdAkcji, NumerMeldunku, DataAkcji, CzasTrwania, MiejsceAkcji, LiczbaKilometrow, IdTypuAkcji) " +
                     "VALUES (@id,@number,@date,@time,@place,@km,@idtype)"; //Dodanie tekstu naszego polecenia
                 //Dodanie parametrów naszej akcji do naszego polecenia SQL
                 insertSQL.Parameters.Add(new SQLiteParameter("@id", SqlDbType.Int)
                 {
                     Value = action.Id
                 });
                 insertSQL.Parameters.Add(new SQLiteParameter("@number", SqlDbType.Int)
                 {
                     Value = action.NumberOfAction
                 });
                 insertSQL.Parameters.AddWithValue("@date", action.DateOfAction);
                 insertSQL.Parameters.Add(new SQLiteParameter("@time", SqlDbType.Int)
                 {
                     Value = action.MinutesOfAction
                 });
                 insertSQL.Parameters.AddWithValue("@place", action.PlaceOfAction);
                 insertSQL.Parameters.Add(new SQLiteParameter("@km", SqlDbType.Int)
                 {
                     Value = action.NumberOfKM
                 });
                 insertSQL.Parameters.Add(new SQLiteParameter("@idtype", SqlDbType.Int)
                 {
                     Value = action.ActionType.Id
                 });
                 insertSQL.ExecuteNonQuery(); //Wywołanie polecenia SQL
             }
             con.Close();                     //Zamknięcie połączenia
         }
         catch (Exception ex)                 //Wyłapywanie wyjatków i błędów połączeń oraz zapytań SQL
         {
             MessageBox.Show("Błąd połączenia z bazą: " + ex);
         }
     }
 }
예제 #2
0
        private void ChangeAction(Action action)
        {
            for (int i = 0; i < Actions.Count; i++)
            {
                if (Actions[i].Id == action.Id)
                {
                    Actions[i] = action.Clone();
                }
            }
            CollectionViewSource.GetDefaultView(this.Actions).Refresh();


            using (con = new SQLiteConnection(connectionString))
            {
                try
                {
                    con.Open();
                    using (SQLiteCommand command = new SQLiteCommand(con))
                    {
                        command.CommandText =
                            "UPDATE Akcja SET IdAkcji = @id, NumerMeldunku = @number, DataAkcji = @date, CzasTrwania = @time, MiejsceAkcji = @place, LiczbaKilometrow = @km, IdTypuAkcji = @idtype WHERE IdAkcji='" + action.Id.ToString() + "'";
                        command.Parameters.AddWithValue("id", action.Id);
                        command.Parameters.AddWithValue("number", action.NumberOfAction);
                        command.Parameters.AddWithValue("date", action.DateOfAction);
                        command.Parameters.AddWithValue("time", action.MinutesOfAction);
                        command.Parameters.AddWithValue("place", action.PlaceOfAction);
                        command.Parameters.Add(new SQLiteParameter("@km", SqlDbType.Int)
                        {
                            Value = action.NumberOfKM
                        });
                        command.Parameters.Add(new SQLiteParameter("@idtype", SqlDbType.Int)
                        {
                            Value = action.ActionType.Id
                        });
                        command.ExecuteNonQuery();
                    }
                    con.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Błąd połączenia z bazą: " + ex);
                }
            }
        }
예제 #3
0
        public ActionMenuViewModel(INavigationService navigationService)
        {
            RegisterMessages();

            string executable = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string path       = (System.IO.Path.GetDirectoryName(executable));

            AppDomain.CurrentDomain.SetData("DataDirectory", path);

            this.navigationService = navigationService;

            AddActionCommand    = new RelayCommand(NewAction);
            EditActionCommand   = new RelayCommand(EditAction);
            RemoveActionCommand = new RelayCommand(RemoveAction);


            windowType  = TypeOfWindow.Actions;
            windowTitle = Helpers.GetDescription(windowType);

            GetActionTypes();
            using (con)
            {
                try
                {
                    con.Open();
                    LoadActions();
                    con.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Błąd połączenia z bazą");
                }
            }

            selectedAction = Actions.ElementAt(0);
        }