/// <summary> /// Добавляет информацию о ремонте. /// </summary> /// <param name="infoRep"></param> public void Add(InfoRepair infoRep) { try { using (var conn = GetConnection()) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "INSERT INTO InfoRepair(Cost, Length, NameRepairs, Note, StartDate) VALUES(@Cost, @Length, @NameRepairs, @Note, @StartDate)"; cmd.Parameters.AddWithValue("@Cost", infoRep.Cost); cmd.Parameters.AddWithValue("@Length", infoRep.Length); cmd.Parameters.AddWithValue("@NameRepairs", infoRep.NameRepairs); cmd.Parameters.AddWithValue("@Note", infoRep.Note); cmd.Parameters.AddWithValue("@StartDate", infoRep.StartDate); //object decease = customer.Note.HasValue ? (object)customer.Note.Value : DBNull.Value; //cmd.Parameters.AddWithValue("@Note", decease); cmd.ExecuteNonQuery(); } } } catch (Exception exc) { MessageBox.Show(exc.Message, "Ошибка"); } }
/// <summary> /// Загружает информацию о ремонтах. /// </summary> /// <param name="reader"></param> /// <returns></returns> private static InfoRepair LoadInfo(SqlDataReader reader) { InfoRepair infoRepair = new InfoRepair(); try { infoRepair.StartDate = reader.GetDateTime(reader.GetOrdinal("StartDate")); infoRepair.NameRepairs = reader.GetString(reader.GetOrdinal("NameRepairs")); infoRepair.Note = reader.GetString(reader.GetOrdinal("Note")); object decease1 = reader["Cost"]; if (decease1 != DBNull.Value) { infoRepair.Cost = Convert.ToInt32(decease1); } object decease = reader["Length"]; if (decease != DBNull.Value) { infoRepair.Length = Convert.ToInt32(decease); } } catch (Exception exc) { MessageBox.Show(exc.Message, "Ошибка"); } return(infoRepair); }
/// <summary> /// Обновляет информацию о ремонте. /// </summary> /// <param name="customer"></param> public void Update(InfoRepair customer) { try { using (var conn = GetConnection()) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "UPDATE InfoRepair SET Cost = @Cost, Length = @Length, NameRepairs=@NameRepairs, Note=@Note, StartDate=@StartDate WHERE StartDate = @ID1"; cmd.Parameters.AddWithValue("@ID1", customer.StartDate); //object decease = customer.Note.HasValue ? (object)customer.Note.Value : DBNull.Value; //cmd.Parameters.AddWithValue("@Note", decease); cmd.ExecuteNonQuery(); } } } catch (Exception exc) { MessageBox.Show(exc.Message, "Ошибка"); } }