/// <summary> /// Загружает тип станка. /// </summary> /// <param name="reader"></param> /// <returns></returns> private static TypeMachine LoadTypeMachine(SqlDataReader reader) { TypeMachine typeMachine = new TypeMachine(); try { typeMachine.CodeMachine = reader.GetInt32(reader.GetOrdinal("CodeMachine")); typeMachine.Mark = reader.GetString(reader.GetOrdinal("Mark")); typeMachine.YearOfIssue = reader.GetInt32(reader.GetOrdinal("YearOfIssue"));; } catch (Exception exc) { MessageBox.Show(exc.Message, "Ошибка"); } return(typeMachine); }
/// <summary> /// Добавляет текущий тип станка. /// </summary> /// <param name="typeMachine"></param> public void Add(TypeMachine typeMachine) { try { using (var conn = GetConnection()) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "INSERT INTO TypeMachine(CodeMachine, Mark, YearOfIssue) VALUES(@CodeMachine, @Mark, @YearOfIssue)"; cmd.Parameters.AddWithValue("@CodeMachine", typeMachine.CodeMachine); cmd.Parameters.AddWithValue("@Mark", typeMachine.Mark); cmd.Parameters.AddWithValue("@YearOfIssue", typeMachine.YearOfIssue); cmd.ExecuteNonQuery(); } } } catch (Exception exc) { MessageBox.Show(exc.Message, "Ошибка"); } }
/// <summary> /// Обновляет текущий тип станка. /// </summary> /// <param name="typeRepair"></param> public void Update(TypeMachine typeRepair) { try { using (var conn = GetConnection()) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = "UPDATE TypeMachine SET Mark = @Mark, YearOfIssue=@YearOfIssue WHERE CodeMachine = @ID1"; cmd.Parameters.AddWithValue("@ID1", typeRepair.CodeMachine); cmd.Parameters.AddWithValue("@Mark", typeRepair.Mark); cmd.Parameters.AddWithValue("@YearOfIssue", typeRepair.YearOfIssue); cmd.ExecuteNonQuery(); } } } catch (Exception exc) { MessageBox.Show(exc.Message, "Ошибка"); } }