public NewTravelPlan SaveData(NewTravelPlan x) { db.CreateDataBase(G.db.travelplan); if (string.IsNullOrEmpty(x.id)) { x.id = Guid.NewGuid().ToString(); } string employees = null; if (x.employees != null) { List <int> selectedEmployees = new List <int>(); foreach (var e in x.employees) { selectedEmployees.Add(e.id); } employees = string.Join(";", selectedEmployees); } using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(G.dataBase))) { connection.Open(); string sql = string.Format(@"INSERT OR REPLACE INTO travelplan (id, startLoacation, endLocation, startDate, endDate, car, employees) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}')" , x.id, x.startLoacation, x.endLocation, x.startDate, x.endDate, x.car.id, employees); using (SQLiteCommand command = new SQLiteCommand(sql, connection)) { command.ExecuteNonQuery(); } connection.Close(); } return(x); }
public string Get(string id) { NewTravelPlan x = new NewTravelPlan(); try { if (!string.IsNullOrEmpty(id)) { db.CreateDataBase(G.db.travelplan); using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(G.dataBase))) { connection.Open(); string sql = string.Format("{0} WHERE id = '{1}'", mainSql, id); using (SQLiteCommand command = new SQLiteCommand(sql, connection)) { using (SQLiteDataReader reader = command.ExecuteReader()) { while (reader.Read()) { x = ReadData(reader); } } } connection.Close(); } } else { x = cInit(); } return(JsonConvert.SerializeObject(x, Formatting.None)); } catch (Exception e) { return(JsonConvert.SerializeObject(x, Formatting.None)); } }
public string Save(NewTravelPlan x) { try { return(JsonConvert.SerializeObject(SaveData(x), Formatting.None)); } catch (Exception e) { return(JsonConvert.SerializeObject(e.Message, Formatting.None)); } }
public NewTravelPlan cInit() { NewTravelPlan x = new NewTravelPlan(); x.id = null; x.startLoacation = null; x.endLocation = null; x.startDate = DateTime.Today; x.endDate = DateTime.Today; x.car = new Cars.NewCar(); x.employees = new List <Employees.NewEmployee>(); return(x); }
public NewTravelPlan ReadData(SQLiteDataReader reader) { NewTravelPlan x = new NewTravelPlan(); x.id = G.ReadS(reader, 0); x.startLoacation = G.ReadS(reader, 1); x.endLocation = G.ReadS(reader, 2); x.startDate = G.ReadDT(reader, 3); x.endDate = G.ReadDT(reader, 4); Cars C = new Cars(); x.car = C.Get(G.ReadS(reader, 5)); Employees E = new Employees(); x.employees = E.GetSelectedEmployees(G.ReadS(reader, 6)); return(x); }
public List <NewTravelPlan> LoadData(string sql) { List <NewTravelPlan> xx = new List <NewTravelPlan>(); db.CreateDataBase(G.db.travelplan); using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + db.GetDataBasePath(G.dataBase))) { connection.Open(); using (SQLiteCommand command = new SQLiteCommand(sql, connection)) { using (SQLiteDataReader reader = command.ExecuteReader()) { while (reader.Read()) { NewTravelPlan x = ReadData(reader); xx.Add(x); } } } connection.Close(); } return(xx); }