private static Dish Read(SqlDataReader dishReader) { Dish newOne = new Dish(); newOne.iddish = dishReader.GetInt32(0); newOne.title = dishReader.GetString(1); newOne.quantily = dishReader.GetInt32(2); newOne.cafe = Cafe.Get(dishReader.GetInt32(3)); return(newOne); }
private static Serve Read(SqlDataReader serReader) { Serve newOne = new Serve(); newOne.idserve = serReader.GetInt32(0); newOne.name = serReader.GetString(1); newOne.passport = serReader.GetInt32(2); try { newOne.education = serReader.GetString(3); } catch (System.Data.SqlTypes.SqlNullValueException) { newOne.education = null; } newOne.experience = serReader.GetInt32(4); newOne.cafe = Cafe.Get(serReader.GetInt32(5)); //newOne.cafe_idcafe = serReader.GetInt32(5); return(newOne); }
//--------------------ФУНКЦИИ ДЛЯ ИМПОРТА-------------------------------------- public void change(int id, Cafe newCafe) { ConnectionString str = new ConnectionString(); SqlConnection conn = new SqlConnection(); str.Open(conn); SqlCommand cmd = new SqlCommand("", conn); cmd.CommandText = "Update cafe SET owner = @_owner, title = @_title, address = @_address"; cmd.Parameters.AddWithValue("_owner", newCafe.owner); cmd.Parameters.AddWithValue("_title", newCafe.title); cmd.Parameters.AddWithValue("_address", newCafe.address); if (newCafe.phone != null) { cmd.CommandText += ", phone = @_phone"; cmd.Parameters.AddWithValue("_phone", newCafe.phone); } else { cmd.CommandText += ", phone = NULL"; } if (newCafe.rating != null) { cmd.CommandText += ", rating = @_rating"; cmd.Parameters.AddWithValue("_rating", newCafe.rating); } else { cmd.CommandText += ", rating = NULL"; } cmd.CommandText += " WHERE idcafe = @id"; cmd.Parameters.AddWithValue("id", id); //conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); }