public static int Insert(SoftSupplier softSupplier) { using (var connection = new DBConnection()) using (var command = DBConnection.CreateCommand()) { command.CommandText = _insertQuery; if (softSupplier == null) { MessageBox.Show("В метод Insert не передана ссылка на объект поставщика ПО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return(-1); } command.Parameters.Add(DBConnection.CreateParameter("Supplier", softSupplier.SoftSupplierName)); try { return(Convert.ToInt32(connection.SqlExecuteScalar(command), CultureInfo.InvariantCulture)); } catch (SqlException e) { connection.SqlRollbackTransaction(); MessageBox.Show(String.Format(CultureInfo.InvariantCulture, "Не удалось добавить поставщика ПО в базу данных. Подробная ошибка: {0}", e.Message), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return(-1); } } }
public static int Update(SoftSupplier softSupplier) { using (var connection = new DBConnection()) using (var command = DBConnection.CreateCommand()) { command.CommandText = _updateQuery; if (softSupplier == null) { MessageBox.Show("В метод Update не передана ссылка на объект поставщика ПО", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return(-1); } command.Parameters.Add(DBConnection.CreateParameter("Supplier", softSupplier.SoftSupplierName)); command.Parameters.Add(DBConnection.CreateParameter("IDSupplier", softSupplier.IdSoftSupplier)); try { return(connection.SqlExecuteNonQuery(command)); } catch (SqlException e) { MessageBox.Show(String.Format(CultureInfo.InvariantCulture, "Не удалось изменить данные о поставщике ПО. Подробная ошибка: {0}", e.Message), "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return(-1); } } }
private static SoftSupplier RowToSoftSupplier(DataRow row) { var softSupplier = new SoftSupplier { IdSoftSupplier = ViewportHelper.ValueOrNull <int>(row, "ID Supplier"), SoftSupplierName = ViewportHelper.ValueOrNull(row, "Supplier") }; return(softSupplier); }
private List <SoftSupplier> SoftSuppliersFromView() { var list = new List <SoftSupplier>(); for (var i = 0; i < _vSoftSuppliers.Count; i++) { var row = (DataRowView)_vSoftSuppliers[i]; var st = new SoftSupplier { IdSoftSupplier = ViewportHelper.ValueOrNull <int>(row, "ID Supplier"), SoftSupplierName = ViewportHelper.ValueOrNull(row, "Supplier") }; list.Add(st); } return(list); }
private List <SoftSupplier> SoftSuppliersFromViewport() { var list = new List <SoftSupplier>(); for (var i = 0; i < dataGridView.Rows.Count; i++) { if (dataGridView.Rows[i].IsNewRow) { continue; } var row = dataGridView.Rows[i]; var st = new SoftSupplier { IdSoftSupplier = ViewportHelper.ValueOrNull <int>(row, "idSoftSupplier"), SoftSupplierName = ViewportHelper.ValueOrNull(row, "softSupplier") }; list.Add(st); } return(list); }
public bool Equals(SoftSupplier other) { return(Equals((object)other)); }