public string Add(tables table, string[] one) { if (one[0] == "") { return("Nie dodano - nieprawidłowe dane!"); } //var db = new Repository(); //Stare repo var db = new RepositoryAdapter(_path); //Nowe repo var sql = new List <string>(); switch (table) { case tables.Customers: if (Get(table, $" where Name='{one[0]}' and LastName='{one[1]}' and Number={one[2]}").Count > 0) { return("Klient istnieje w bazie!"); } sql.Add($"Insert into [{table.ToString()}] (Name, LastName, Number) Values ('{one[0]}','{one[1]}',{one[2]})"); //db.ExecuteNonQuery(_path, sql); //Stara metoda db.ExecuteNonQuery(sql); //Nowa metoda return("Dodano"); case tables.Services: if (Get(table, $" where Name='{one[0]}' and Type='{one[1]}' and Price={one[2]}").Count > 0) { return("Usługa istnieje w bazie!"); } sql.Add($"Insert into [{table.ToString()}] (Name, Type, Price) Values ('{one[0]}','{one[1]}',{one[2]})"); //db.ExecuteNonQuery(_path, sql); //Stara metoda db.ExecuteNonQuery(sql); //Nowa metoda return("Dodano"); case tables.Transactions: if (Get(tables.Customers, $" where ID={one[0]}").Count > 0 && Get(tables.Services, $" where ID={one[1]}").Count > 0) { sql.Add($"Insert into [{table.ToString()}] (CustomerID, ServiceID, Date, User) Values ({one[0]},{one[1]},'{one[2]}','{one[3]}')"); //db.ExecuteNonQuery(_path, sql); //Stara metoda db.ExecuteNonQuery(sql); //Nowa metoda return("Dodano"); } else { return("Nie dodano, błędne ID klienta lub usługi!"); } default: return("Nie dodano - błędny typ tabeli!"); } }
public void CreateTable() { try { //var db = new Repository(); //Stare repo. var db = new RepositoryAdapter(DbPath); //Nowe repo. List <string> sqlList = new List <string>(); sqlList.Add("CREATE TABLE[Customers](" + " [ID] INTEGER PRIMARY KEY AUTOINCREMENT" + ", [Name] text NULL " + ", [LastName] text NULL " + ", [Number] integer NULL )"); sqlList.Add("CREATE TABLE[Services](" + " [ID] INTEGER PRIMARY KEY AUTOINCREMENT" + ", [Name] text NULL " + ", [Type] text NULL " + ", [Price] integer NULL )"); sqlList.Add("CREATE TABLE[Transactions](" + " [ID] INTEGER PRIMARY KEY AUTOINCREMENT" + ", [CustomerID] INTEGER NULL " + ", [ServiceID] INTEGER NULL " + ", [Date] text NULL " + ", [User] text NULL )"); //db.ExecuteNonQuery(DbPath, sqlList); // Stara metoda db.ExecuteNonQuery(sqlList); // Nowa metoda } catch (Exception ex) { throw; } }