public static bool Update_camera(Tip_camera t) { if (Verificare.Verificare_camera(t) != null) { using (MySqlConnection conn = GetConnection()) { conn.Open(); string query, id; id = Cautare_camera_pe_tip(t); if (id == null) { return(false); } query = "UPDATE camere SET " + t.ToString() + "='rezervat' WHERE ID='" + id + "';"; MySqlCommand cmd = new MySqlCommand(query, conn); MySqlDataReader myreader; myreader = cmd.ExecuteReader();//EXECUTE QUERY return(true); } } else { return(false); } }
public static void Deactualizare_baza(Model_clienti m, Tip_camera tip_vechi) { using (MySqlConnection conn = GetConnection()) { conn.Open(); string query = "UPDATE camere SET " + tip_vechi.ToString() + "='liber_curata' WHERE ID='" + m.id_camera + "';"; MySqlCommand cmd = new MySqlCommand(query, conn); MySqlDataReader myreader; myreader = cmd.ExecuteReader();//EXECUTE QUERY } }
public static void Eliberare_o_camera(Tip_camera tip_pentru_deactualizare) { Actualizare_lista_camere(); foreach (Camere c in lista_camere) { if (tip_pentru_deactualizare.ToString() == "Lux" && c.lux == Lux.rezervat) { Eliberare_camera(c.id, "Lux"); break; } if (tip_pentru_deactualizare.ToString() == "Superior" && c.sup == Superior.rezervat) { Eliberare_camera(c.id, "Superior"); break; } if (tip_pentru_deactualizare.ToString() == "Standard" && c.std == Standard.rezervat) { Eliberare_camera(c.id, "Standard"); break; } } }
public static string Cautare_camera_pe_tip(Tip_camera t) { MySqlConnection conn = new MySqlConnection(ConnectionString); string query = "select " + t.ToString() + ",ID from Camere;"; MySqlCommand cmd = new MySqlCommand(query, conn); MySqlDataAdapter adapt = new MySqlDataAdapter(); adapt.SelectCommand = cmd; DataTable dTable = new DataTable(); adapt.Fill(dTable); List <DataRow> list_camere = dTable.AsEnumerable().ToList(); foreach (DataRow stare_camere in list_camere) { if (stare_camere.ItemArray[0].ToString() == "liber_curata") { return(stare_camere.ItemArray[1].ToString()); } } return(null); }
public static bool Verificare_camera(Tip_camera t, DateTime check_in, DateTime check_out) { MySqlConnection conn = new MySqlConnection(ConnectionString); string query = "select " + t.ToString() + " from Camere;"; MySqlCommand cmd = new MySqlCommand(query, conn); MySqlDataAdapter adapt = new MySqlDataAdapter(); adapt.SelectCommand = cmd; DataTable dTable = new DataTable(); adapt.Fill(dTable); List <DataRow> list_camere = dTable.AsEnumerable().ToList(); foreach (DataRow stare_camere in list_camere) { if (stare_camere.ItemArray[0].ToString() == "liber_curata") { return(Verificare_date_valabile(check_in, check_out, t)); } } return(true); }
public static bool Verificare_date_valabile(DateTime check_in, DateTime check_out, Tip_camera t) { int ok1 = 0, a, b, c, d, e, f; bool valabil = false; int zi_in = int.Parse(check_in.ToString().Substring(0, 2)), zi_out = int.Parse(check_out.ToString().Substring(0, 2)); int luna_in = int.Parse(check_in.ToString().Substring(3, 2)), luna_out = int.Parse(check_out.ToString().Substring(3, 2)); int an_in = int.Parse(check_in.ToString().Substring(6, 4)), an_out = int.Parse(check_out.ToString().Substring(6, 4)); if (ok) { return(false); } if (an_in > an_out || luna_in > luna_out || zi_in > zi_out) { return(true); } MySqlConnection conn = new MySqlConnection(ConnectionString); string query1 = "select Check_IN,Check_OUT from Tabel_clienti WHERE Tip_camera='" + t.ToString() + "';"; MySqlCommand cmd1 = new MySqlCommand(query1, conn); MySqlDataAdapter adapt1 = new MySqlDataAdapter(); adapt1.SelectCommand = cmd1; DataTable dTable1 = new DataTable(); adapt1.Fill(dTable1); List <DataRow> list_data_check = dTable1.AsEnumerable().ToList(); foreach (DataRow data in list_data_check) { a = int.Parse(data.ItemArray[0].ToString().Substring(6, 4)); //an in b = int.Parse(data.ItemArray[1].ToString().Substring(6, 4)); //an out c = int.Parse(data.ItemArray[0].ToString().Substring(3, 2)); //luna in d = int.Parse(data.ItemArray[1].ToString().Substring(3, 2)); //luna out e = int.Parse(data.ItemArray[0].ToString().Substring(0, 2)); //zi in f = int.Parse(data.ItemArray[1].ToString().Substring(0, 2)); //zi out if ((a < an_in && an_in < b) || (a < an_out && an_out < b) || (an_in < a && b < an_out)) { valabil = true; } else { if ((c < luna_in && luna_in < d) || (c < luna_out && luna_out < d) || (luna_in < c && d < luna_out)) { valabil = true; } else { if ((e <= zi_in && zi_in <= f) || (e <= zi_out && zi_out <= f) || (zi_in <= e && f <= zi_out)) { valabil = true; } else { ok1++; } } } } if (ok1 == list_data_check.Count()) { valabil = false; } return(valabil); }
/*public static bool Verificare_camera(Tip_camera t, DateTime check_in, DateTime check_out) * { * MySqlConnection conn = new MySqlConnection(ConnectionString); * string query = "select " + t.ToString() + " from Camere;"; * MySqlCommand cmd = new MySqlCommand(query, conn); * MySqlDataAdapter adapt = new MySqlDataAdapter(); * adapt.SelectCommand = cmd; * DataTable dTable = new DataTable(); * adapt.Fill(dTable); * List<DataRow> list_camere = dTable.AsEnumerable().ToList(); * foreach (DataRow stare_camere in list_camere) * { * if (stare_camere.ItemArray[0].ToString() == "liber_curata") * { * return Verificare_date_valabile(check_in, check_out, t); * } * } * * return true; * }*/ public static bool Verificare_date_valabile(DateTime check_in, DateTime check_out, Tip_camera t, Model_clienti m) { int ok1 = 0, an_in_compare, an_out_compare, luna_in_compare, luna_out_compare, zi_in_compare, zi_out_compare; bool valabil = false; int ok2 = 0; string query1; int zi_in = int.Parse(check_in.ToString().Substring(0, 2)), zi_out = int.Parse(check_out.ToString().Substring(0, 2)); int luna_in = int.Parse(check_in.ToString().Substring(3, 2)), luna_out = int.Parse(check_out.ToString().Substring(3, 2)); int an_in = int.Parse(check_in.ToString().Substring(6, 4)), an_out = int.Parse(check_out.ToString().Substring(6, 4)); if (ok) { return(false); } if (an_in > an_out || luna_in > luna_out || zi_in > zi_out) { return(true); } MySqlConnection conn = new MySqlConnection(ConnectionString); query1 = "select Check_IN,Check_OUT from Tabel_clienti WHERE Tip_camera='" + t.ToString() + "' AND Stare NOT IN('Inactiv') AND ID NOT IN('" + m.ID + "');"; MySqlCommand cmd1 = new MySqlCommand(query1, conn); MySqlDataAdapter adapt1 = new MySqlDataAdapter(); adapt1.SelectCommand = cmd1; DataTable dTable1 = new DataTable(); adapt1.Fill(dTable1); List <DataRow> list_data_check = dTable1.AsEnumerable().ToList(); foreach (DataRow data in list_data_check) { an_in_compare = int.Parse(data.ItemArray[0].ToString().Substring(6, 4)); //an in an_out_compare = int.Parse(data.ItemArray[1].ToString().Substring(6, 4)); //an out luna_in_compare = int.Parse(data.ItemArray[0].ToString().Substring(3, 2)); //luna in luna_out_compare = int.Parse(data.ItemArray[1].ToString().Substring(3, 2)); //luna out zi_in_compare = int.Parse(data.ItemArray[0].ToString().Substring(0, 2)); //zi in zi_out_compare = int.Parse(data.ItemArray[1].ToString().Substring(0, 2)); //zi out if ((an_in_compare < an_in && an_in < an_out_compare) || (an_in_compare < an_out && an_out < an_out_compare) || (an_in < an_in_compare && an_out_compare < an_out)) { valabil = true; } else { if ((luna_in_compare < luna_in && luna_in < luna_out_compare) || (luna_in_compare < luna_out && luna_out < luna_out_compare) || (luna_in < luna_in_compare && luna_out_compare < luna_out)) { valabil = true; } else { if ((zi_in_compare <= zi_in && zi_in <= zi_out_compare - 1) || (zi_in_compare <= zi_out && zi_out <= zi_out_compare - 1) || (zi_in <= zi_in_compare && zi_out_compare - 1 <= zi_out)) { valabil = true; } else { ok1++; } if (valabil == true) { ok2++; valabil = false; } } } } Repository_camere.Actualizare_lista_camere(); if (ok2 >= Repository_camere.lista_camere.Count) { valabil = true; } return(valabil); }