public static FlightDuration findOrFail(DateTime startDate, bool direction) { string query = direction ? "SELECT * FROM flight_durations WHERE date_mars=?date AND direction=1" : "SELECT * FROM flight_durations WHERE date_earth=?date AND direction=0"; DB.loadQuery(query); DB.Command.Parameters.Add("?date", MySqlDbType.Date).Value = startDate; DataTable dt = DB.query(); FlightDuration flightDur = null; foreach (DataRow item in dt.Rows) { int iD = Convert.ToInt32(item["id"]); DateTime dateMars = Convert.ToDateTime(item["date_mars"]); DateTime dateEarth = Convert.ToDateTime(item["date_earth"]); bool dir = Convert.ToBoolean(item["direction"]); double price = Convert.ToDouble(item["price"]); flightDur = new FlightDuration(iD, dateMars, dateEarth, dir, price); } return(flightDur); }
public static bool insertSecondDate(FlightDuration flightDuration) { try { DB.loadQuery(@"INSERT INTO flight_durations (id, date_mars, date_earth, direction, price) VALUES(NULL, ?dateMars, ?dateEarth, ?direction, ?price);"); DB.Command.Parameters.Add("?dateMars", MySqlDbType.Date).Value = flightDuration.DateMars; DB.Command.Parameters.Add("?dateEarth", MySqlDbType.Date).Value = flightDuration.DateEarth; DB.Command.Parameters.Add("?direction", MySqlDbType.Bit).Value = flightDuration.Direction; DB.Command.Parameters.Add("?price", MySqlDbType.Double).Value = flightDuration.Price; DB.execute(); return(true); } catch (Exception) { return(false); } }