Example #1
0
        private static RaceModel UpdateRace(RaceModel race)
        {
            using (IDbConnection con = new SQLiteConnection(SQLiteDataAccess.GetConnectionString()))
            {
                SQLiteDataAccess.InstanceDB();

                sql = @"UPDATE racetable
                        SET RaceStatus = @RaceStatus,
                        Distance = @Distance,
                        Year = @Year
                        WHERE RaceId = @RaceId";
                con.Execute(sql, race);

                return(con.Query <RaceModel>("SELECT * FROM racetable").LastOrDefault());
            }
        }
        public ActionResult Delete(int id, CompanyMVCModel company)
        {
            try
            {
                if (company != null)
                {
                    SQLiteDataAccess.RemoveCompany(company.Id);
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View(company));
            }
        }
Example #3
0
        private void LoadPasswordList()
        {
            passwordList = SQLiteDataAccess.LoadPasswords();


            // swap out a special character ("*") with a random number
            foreach (var p in passwordList)
            {
                int randNum = rand.Next(10, 100);


                p.Password = p.Password.Replace("*", $"{randNum}");
            }

            WireUpPasswordList();
        }
        public static List <VehicleModel> GetFilteredVehicles(string team, int?status, int?distance, string Models = "", string date = "")
        {
            using (IDbConnection con = new SQLiteConnection(SQLiteDataAccess.GetConnectionString()))
            {
                SQLiteDataAccess.InstanceDB();

                string sql = @"SELECT * FROM vehicletable
                               WHERE TeamName = @TeamName
                               AND (@Model = '' or Model = @Model)
                               AND (@ManufacturingDate = '' or ManufacturingDate = @ManufacturingDate)
                               AND (@VehicleStatus = '' or VehicleStatus = @VehicleStatus)
                               AND (@Distance = '' or Distance = @Distance)";

                return(con.Query <VehicleModel>(sql, new{ Model = Models ?? "", ManufacturingDate = date ?? "", VehicleStatus = status ?? null, Distance = distance ?? null }).ToList());;
            }
        }
        public ActionResult Delete(int id, ClientMVCModel model)
        {
            try
            {
                if (model != null)
                {
                    SQLiteDataAccess.RemoveClient(model.Id);
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View(model));
            }
        }
Example #6
0
        private void deleteAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("Are you sure you want to delete the database and start over?",
                                              "Are you Sure?", MessageBoxButtons.YesNo);

            switch (dr)
            {
            case DialogResult.Yes:
                SQLiteDataAccess.DeleteAllPasswords();
                LoadPasswordList();    // Refresh list
                break;

            case DialogResult.No:
                break;
            }
        }
        public ActionResult Delete(int id, ItemMVCModel model)
        {
            try
            {
                if (model != null)
                {
                    SQLiteDataAccess.RemoveProduct(model);
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #8
0
        public static void CheckIfUserHasWon(RoundModel round, UserModel currentUser, IRouletteSession rouletteSessionForm, IUserWon userWonForm)
        {
            if (round.Spin > rouletteSessionForm.SessionStart)
            {
                if (round.Money >= rouletteSessionForm.Goal)
                {
                    currentUser.Won = true;

                    userWonForm = new YouWonForm(currentUser, rouletteSessionForm);
                    userWonForm.ShowDialog();
                    rouletteSessionForm.Close();

                    SQLiteDataAccess.UpdateUserWon(currentUser);
                }
            }
        }
        public ActionResult Create(CompanyMVCModel company)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    SQLiteDataAccess.SaveCompany(company);
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(RedirectToAction("Create"));
            }
        }
        private void AddProductToMagazine_Click(object sender, RoutedEventArgs e)
        {
            string  Name       = ProductName.Text;
            string  Quantity   = (ProductQuantity.Text);
            string  NetPrice   = (NetPrice1art.Text);
            string  Vat        = (ProductVat.Text);
            string  VatValue   = (ProductNettoPrice.Text);
            string  GrossValue = (ProductBruttoPrice.Text);
            Product Product    = new Product(Name, Quantity, NetPrice, Vat, VatValue, GrossValue);
            int     IdProduct  = SQLiteDataAccess.LoadAiCompanyId("Product")[0] + 1;

            SQLiteDataAccess.SaveProductToCustomer(IdProduct, 1);
            SQLiteDataAccess.SaveProduct(Product);
            CreatePDF();
            this.Close();
        }
        public ActionResult Create(ClientMVCModel client)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    SQLiteDataAccess.SaveClient(client);
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception e)
            {
                var errur = e.Message;
                return(RedirectToAction("Create"));
            }
        }
Example #12
0
        public void RemoveChart(string name)
        {
            if (Owner is ChartPage)
            {
                Charts.Remove(name);
                SQLiteDataAccess.RemoveTable(name);
                SQLiteDataAccess.RemoveRow(ChartColors.Table, ChartColors.Colomns[0], name, ConfigFile);
                SQLiteDataAccess.RemoveRow(ChartColors.CanvasTable, ChartColors.CanvasColomns[0], name, ConfigFile);

                if (Charts.Count == 0)
                {
                    GotChartData = false;
                    ((Parent as MainWindowConfig).Owner as MainWindow).EmptyTabContent(this);
                }
                (Owner as ChartPage).UpdateChartSelect(name, false);
            }
        }
        public void ExecuteSave(object o)
        {
            VaultVM.SelectedPasswordModel.Name     = this.Name;
            VaultVM.SelectedPasswordModel.Website  = this.Website;
            VaultVM.SelectedPasswordModel.Username = this.Username;

            // Encrypts and stores the password in the database
            byte[] passwordBytes     = ASCIIEncoding.ASCII.GetBytes(this.Password);
            byte[] masterKey         = CryptoUtil.MasterKey;
            byte[] encryptedPassword = CryptoUtil.AES_GCMEncrypt(passwordBytes, masterKey);

            VaultVM.SelectedPasswordModel.Password = Convert.ToBase64String(encryptedPassword);
            SQLiteDataAccess.UpdatePassword(VaultVM.SelectedPasswordModel);

            // Updates password in bindable collection
            VaultVM.SelectedPasswordModel.Password = this.Password;
            VaultVM.PassScreenType = new DisplayPasswordViewModel(SelectedPassword, VaultVM);
        }
        internal static List <string> WipeDatabaseModel()
        {
            LogMessage = new();

            MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure you want to wipe out the whole database! \nData will not be recoverable.",
                                                                "", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                SQLiteDataAccess.WipeDatabase(LogMessage);
                return(LogMessage);
            }
            else
            {
                LogMessage.Add("Wipe process cancelled.");
                return(LogMessage);
            }
        }
        private CreatorMVCModel GetCreatorInformation(CreatorMVCModel commissionCreator, int selectedCreator)
        {
            CreatorMVCModel        result   = new CreatorMVCModel();
            List <CreatorMVCModel> creators = SQLiteDataAccess.LoadCreators();

            // Gets created creator information, and save him to DB
            if (commissionCreator.Name != null && commissionCreator.Name.Length > 0)
            {
                SQLiteDataAccess.SaveCreator(commissionCreator);
                result = commissionCreator;
            }
            // Load selected creator
            else
            {
                result = creators.Where(x => x.Id == selectedCreator).FirstOrDefault();
            }
            return(result);
        }
Example #16
0
        private void BtnGemNytMedlem_Click(object sender, RoutedEventArgs e)
        {
            // Gemmer det nye medlem i databasen!
            MemberModel m = new MemberModel();

            m.forNavn   = forNavnTekst.Text;
            m.efterNavn = efterNavnTekst.Text;
            m.alias     = aliasTekst.Text;
            m.mobil     = mobilTekst.Text;
            m.email     = emailTekst.Text;

            SQLiteDataAccess.SaveMember(m);

            forNavnTekst.Text   = "";
            efterNavnTekst.Text = "";
            aliasTekst.Text     = "";
            mobilTekst.Text     = "";
            emailTekst.Text     = "";
        }
Example #17
0
        private void AddToAnimeList(AnimeModel animeToAdd)
        {
            // Saves the anime to the database
            // Sets the id of the anime to the database version
            // This ensures it has the correct id to delete or edit later if needed
            SQLiteDataAccess.SaveAnime(animeToAdd);
            animeToAdd.Id = SQLiteDataAccess.GetLastRecord().Id;

            // Inserts an anime in the first index of the bindable collection
            // This makes it appear at the top of the data grid
            _animes.Insert(0, animeToAdd);

            if (SortType != SortMethod.All)
            {
                SortAnimeByStatus();
            }

            NotifyOfPropertyChange(() => TotalAnimes);
        }
 public static bool SyncData(string userName, string userPass)
 {
     try
     {
         var products = GetProductsFromAPI(userName, userPass);
         var stock    = GetStockFromAPI(userName, userPass);
         var buyers   = GetBuyersFromAPI(userName, userPass);
         var docs     = GetDocTypesFromAPI(userName, userPass);
         RecreateDb();
         SQLiteDataAccess.SaveProducts(products);
         SQLiteDataAccess.SaveBuyers(buyers);
         SQLiteDataAccess.SaveDocTypes(docs);
         SQLiteDataAccess.SaveStockWithProductInfo(stock, products);
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }
Example #19
0
        internal static string SubmitDelete(Instrument Instrument)
        {
            if (Instrument.Id <= 0 || Instrument == null || Instrument.Id == null)
            {
                return("Please select an item to delete.");
            }

            string sqlCommand = $"delete from {TableName} where id={Instrument.Id}";

            try
            {
                SQLiteDataAccess.Delete(sqlCommand);
                return($"Id number: [{Instrument.Id}] successfully deleted. \nPress Refresh to see the result.");
            }
            catch (FileNotFoundException message)
            {
                Debug.WriteLine("Database access failed!");
                throw new FileNotFoundException($"{message}");
            }
        }
        private void Load_Tick(object sender, EventArgs e)
        {
            if (progressBar1.Value < 100)
            {
                progressBar1.Value += 1;
            }
            else
            {
                Load.Stop();
                flag = false;
            }

            if (progressBar1.Value == 15)
            {
                bunifuCustomLabel3.Text = "Collecting Data";
                firstSetupModel fsm = setData();
                SQLiteDataAccess.insertData(fsm);
            }
            if (progressBar1.Value == 30)
            {
                bunifuCustomLabel3.Text = "Creating Store Database";
                firstSetupModel fsm = setData();
                ServerDataAccess.insertDatabase(fsm);
            }
            if (progressBar1.Value == 50)
            {
                bunifuCustomLabel3.Text = "Creating Tables for your Database";
                ServerDataAccess.insertStoreTable();
            }
            if (progressBar1.Value == 70)
            {
                bunifuCustomLabel3.Text = "Creating Stored Procedures";
                ServerDataAccess.createStoredProcedure();
            }
            if (progressBar1.Value == 70)
            {
                firstSetupModel fsm = setData();
                bunifuCustomLabel3.Text = "Creating Your User Account";
                ServerDataAccess.insertUserAccountAdmin(fsm);
            }
        }
Example #21
0
        internal static string SubmitUpdate(Instrument Instrument)
        {
            if (!IsTextBoxEmpty(Instrument) || Instrument == null)
            {
                return("No empty cell is allowed for update.");
            }

            string sqlCommand = "update Instrument set ItemType=@ItemType, OperationPrinciple=@OperationPrinciple, InstallationType=@InstallationType, MediumToMeasure=@MediumToMeasure, " +
                                "Supplier=@Supplier, Manufacturer=@Manufacturer, UnitPrice=@UnitPrice where id=";

            try
            {
                SQLiteDataAccess.ActOnItem(Instrument, sqlCommand + Instrument.Id);
                return($"Id number: [{Instrument.Id}] successfully updated \nPress refresh to see the result.");
            }
            catch (FileNotFoundException message)
            {
                Debug.WriteLine("Database file not found!");
                throw new FileNotFoundException($"{message}");
            }
        }
        private List <ItemMVCModel> GetProductsInformation(List <int> selectedProducts, List <decimal> productPrices, List <int> productQuantities)
        {
            List <ItemMVCModel> products = SQLiteDataAccess.LoadProducts();
            List <ItemMVCModel> result   = new List <ItemMVCModel>();

            foreach (int id in selectedProducts)
            {
                ItemMVCModel product = products.Where(x => x.Id == id).FirstOrDefault();

                product.Quantity = productQuantities[products.IndexOf(products.Where(x => x.Id == id).FirstOrDefault())];

                //If product price loaded from application differs from price loaded from DB, change the price for this document
                if (productPrices[products.IndexOf(products.Where(x => x.Id == id).FirstOrDefault())] != products.Where(x => x.Id == id).First().Cost)
                {
                    product.Cost = productPrices[products.IndexOf(products.Where(x => x.Id == id).FirstOrDefault())];
                }

                result.Add(product);
            }
            return(result);
        }
        internal static string SubmitUpdate(Valve item)
        {
            if (!IsValveEmpty(item) || item == null)
            {
                return("No empty cell is allowed for update.");
            }

            string sqlCommand = $"update {TableName} set ItemType=@ItemType, Operation=@Operation, Size=@Size, ConnectionType=@ConnectionType, " +
                                $"Supplier=@Supplier, Manufacturer=@Manufacturer, UnitPrice=@UnitPrice where id=";

            try
            {
                SQLiteDataAccess.ActOnItem(item, sqlCommand + item.Id);
                return($"Id number: [{item.Id}] successfully updated \nPress refresh to see the result.");
            }
            catch (FileNotFoundException message)
            {
                Debug.WriteLine("Database file not found!");
                throw new FileNotFoundException($"{message}");
            }
        }
        private List <ClientMVCModel> GetClientsInformation(ClientMVCModel creationClient, List <int> selectedClients)
        {
            List <ClientMVCModel> clients = SQLiteDataAccess.LoadMVCClients();
            List <ClientMVCModel> result  = new List <ClientMVCModel>();

            if (creationClient.PhoneNumber != null)
            {
                SQLiteDataAccess.SaveClient(creationClient);
                if (creationClient.Company == false)
                {
                    creationClient.NIP         = "";
                    creationClient.CompanyName = "";
                }
                result.Add(creationClient);
            }
            foreach (int id in selectedClients)
            {
                result.Add(clients.Where(x => x.Id == id).FirstOrDefault());
            }
            return(result);
        }
Example #25
0
        private static List <Equipment> MapEquipmentList(string sqlCommand)
        {
            var equipmentData = SQLiteDataAccess.GetDb(sqlCommand, TableName);

            if (equipmentData == null)
            {
                return(null);
            }

            var dbRowNumber = equipmentData.Rows.Count;

            var list = new List <Equipment>();

            if (dbRowNumber == 0)
            {
                return(list);
            }


            for (int i = 0; i < dbRowNumber; i++)
            {
                var item = equipmentData.Rows[i];

                list.Add(
                    new Equipment
                {
                    Id               = Convert.ToInt32(item.ItemArray[0]),
                    ItemType         = Convert.ToString(item.ItemArray[1]),
                    Capacity         = Convert.ToDecimal(item.ItemArray[2]),
                    Pressure         = Convert.ToDecimal(item.ItemArray[3]),
                    PowerConsumption = Convert.ToDecimal(item.ItemArray[4]),
                    Manufacturer     = Convert.ToString(item.ItemArray[5]),
                    Model            = Convert.ToString(item.ItemArray[6]),
                    UnitPrice        = Convert.ToDecimal(item.ItemArray[7]),
                });
            }

            return(list);
        }
        public static VehicleStatisticModel GetVehicleStatistic(int id)
        {
            using (IDbConnection con = new SQLiteConnection(SQLiteDataAccess.GetConnectionString()))
            {
                SQLiteDataAccess.InstanceDB();

                VehicleStatisticModel vehicleStat = new VehicleStatisticModel();
                var vehicle = con.Query <VehicleModel>("SELECT * FROM vehicletable").FirstOrDefault(v => v.VehicleId == id);
                vehicleStat.Distance = vehicle.Distance;
                if (vehicle.VehicleStatus < (int)Enums.VehicleStatus.finishRace)
                {
                    vehicleStat.Malfunction = vehicle.VehicleStatus;
                }
                else
                {
                    vehicleStat.Status = vehicle.VehicleStatus;
                }
                vehicleStat.Time = vehicle.Time;

                return(vehicleStat);
            }
        }
Example #27
0
        private void createAccountButton_Click(object sender, EventArgs e)
        {
            if (SignUpValid())
            {
                UserModel user = new UserModel(firstNameValue.Text, lastNameValue.Text,
                                               emailAdressValue.Text, signupUsernameValue.Text, signupPasswordValue.Text);

                SQLiteDataAccess.CreateNewUser(user);

                userList.Add(user);

                loginUsernameValue.Text = signupUsernameValue.Text;
                loginPasswordValue.Text = signupPasswordValue.Text;

                firstNameValue.Clear();
                lastNameValue.Clear();
                emailAdressValue.Clear();
                signupUsernameValue.Clear();
                signupPasswordValue.Clear();
                confirmPasswordValue.Clear();
            }
        }
Example #28
0
        internal static string SubmitAdd(Instrument item)
        {
            if (!IsTextBoxEmpty(item) || item == null)
            {
                return("No empty cell is allowed for insert.");
            }

            string sqlCommand = $"insert into {TableName} (ItemType, OperationPrinciple, InstallationType, MediumToMeasure, Supplier, Manufacturer, UnitPrice) " +
                                "values (@ItemType, @OperationPrinciple, @InstallationType, @MediumToMeasure, @Supplier, @Manufacturer, @UnitPrice)";

            try
            {
                int newId = SQLiteDataAccess.ActOnItem(item, sqlCommand);

                return($"You have successfully added [{newId}] id. \nPress refresh to see the result.");
            }
            catch (FileNotFoundException message)
            {
                Debug.WriteLine("Database file not found!");
                throw new FileNotFoundException($"{message}");
            }
        }
Example #29
0
        internal static string SubmitUpdate(Equipment item)
        {
            if (!IsEquipmentEmpty(item) || item == null)
            {
                return("No empty cell is allowed for update.");
            }

            string sqlCommand =
                $"update {TableName} set ItemType=@ItemType, Capacity=@Capacity, Pressure=@Pressure, PowerConsumption=@PowerConsumption, " +
                $"Manufacturer=@Manufacturer, Model=@Model, UnitPrice=@UnitPrice where id=";

            try
            {
                SQLiteDataAccess.ActOnItem(item, sqlCommand + item.Id);
                return($"Id number: [{item.Id}] successfully updated \nPress refresh to see the result.");
            }
            catch (FileNotFoundException message)
            {
                Debug.WriteLine("Database file not found!");
                throw new FileNotFoundException($"{message}");
            }
        }
Example #30
0
        internal static string SubmitAdd(Equipment item)
        {
            if (!IsEquipmentEmpty(item) || item == null)
            {
                return("No empty cell is allowed for insert.");
            }

            string sqlCommand =
                $"insert into {TableName} (ItemType, Capacity, Pressure, PowerConsumption, Manufacturer, Model, UnitPrice) " +
                "values (@ItemType, @Capacity, @Pressure, @PowerConsumption, @Manufacturer, @Model, @UnitPrice)";

            try
            {
                int newId = SQLiteDataAccess.ActOnItem(item, sqlCommand);

                return($"You have successfully added [{newId}] id. \nPress refresh to see the result.");
            }
            catch (FileNotFoundException message)
            {
                Debug.WriteLine("Database file not found!");
                throw new FileNotFoundException($"{message}");
            }
        }