public static int Insert(SoftLicKey softLicKey) { using (var connection = new DBConnection()) using (var command = DBConnection.CreateCommand()) { command.CommandText = _insertQuery; if (softLicKey == null) { MessageBox.Show("В метод Insert не передана ссылка на объект лицензионного ключа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return(-1); } command.Parameters.Add(DBConnection.CreateParameter("IDLicense", softLicKey.IdLicense)); command.Parameters.Add(DBConnection.CreateParameter("LicKey", softLicKey.LicKey)); 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(SoftLicKey softLicKey) { using (var connection = new DBConnection()) using (var command = DBConnection.CreateCommand()) { command.CommandText = _updateQuery; if (softLicKey == null) { MessageBox.Show("В метод Update не передана ссылка на объект лицензионного ключа", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return(-1); } command.Parameters.Add(DBConnection.CreateParameter("IDLicense", softLicKey.IdLicense)); command.Parameters.Add(DBConnection.CreateParameter("LicKey", softLicKey.LicKey)); command.Parameters.Add(DBConnection.CreateParameter("IDLicenseKey", softLicKey.IdLicenseKey)); 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 SoftLicKey RowToSoftLicKey(DataRow row) { var softLicKey = new SoftLicKey { IdLicenseKey = ViewportHelper.ValueOrNull <int>(row, "ID LicenseKey"), IdLicense = ViewportHelper.ValueOrNull <int>(row, "ID License"), LicKey = ViewportHelper.ValueOrNull(row, "LicKey") }; return(softLicKey); }
private List <SoftLicKey> SoftLicKeysFromView() { var list = new List <SoftLicKey>(); for (var i = 0; i < _vSoftLicKeys.Count; i++) { var slk = new SoftLicKey(); var row = ((DataRowView)_vSoftLicKeys[i]); slk.IdLicenseKey = ViewportHelper.ValueOrNull <int>(row, "ID LicenseKey"); slk.IdLicense = ViewportHelper.ValueOrNull <int>(row, "ID License"); slk.LicKey = ViewportHelper.ValueOrNull(row, "LicKey"); list.Add(slk); } return(list); }
private List <SoftLicKey> SoftLicKeysFromViewport() { var list = new List <SoftLicKey>(); for (var i = 0; i < dataGridView.Rows.Count; i++) { if (!dataGridView.Rows[i].IsNewRow) { var slk = new SoftLicKey(); var row = dataGridView.Rows[i]; slk.IdLicenseKey = ViewportHelper.ValueOrNull <int>(row, "idLicenseKey"); slk.IdLicense = ViewportHelper.ValueOrNull <int>(row, "idLicense"); slk.LicKey = ViewportHelper.ValueOrNull(row, "LicKey"); list.Add(slk); } } return(list); }
public bool Equals(SoftLicKey other) { return(Equals((object)other)); }