public static int Update(SoftInstallation softInstallation) { using (var connection = new DBConnection()) using (var command = DBConnection.CreateCommand()) { command.CommandText = _updateQuery; if (softInstallation == null) { MessageBox.Show("В метод Update не передана ссылка на объект установки программного обеспечения", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return(-1); } command.Parameters.Add(DBConnection.CreateParameter("IDLicense", softInstallation.IdLicense)); command.Parameters.Add(DBConnection.CreateParameter("IDComputer", softInstallation.IdComputer)); command.Parameters.Add(DBConnection.CreateParameter("InstallationDate", softInstallation.InstallationDate)); command.Parameters.Add(DBConnection.CreateParameter("IDLicenseKey", softInstallation.IdLicenseKey)); command.Parameters.Add(DBConnection.CreateParameter("IDInstallator", softInstallation.IdInstallator)); command.Parameters.Add(DBConnection.CreateParameter("IDInstallation", softInstallation.IdInstallation)); command.Parameters.Add(DBConnection.CreateParameter("Description", softInstallation.Description)); 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); } } }
public static int Insert(SoftInstallation softInstallation) { using (var connection = new DBConnection()) using (var command = DBConnection.CreateCommand()) { command.CommandText = _insertQuery; if (softInstallation == null) { MessageBox.Show("В метод Insert не передана ссылка на объект установки программного обеспечения", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return(-1); } command.Parameters.Add(DBConnection.CreateParameter("IDLicense", softInstallation.IdLicense)); command.Parameters.Add(DBConnection.CreateParameter("IDComputer", softInstallation.IdComputer)); command.Parameters.Add(DBConnection.CreateParameter("InstallationDate", softInstallation.InstallationDate)); command.Parameters.Add(DBConnection.CreateParameter("IDLicenseKey", softInstallation.IdLicenseKey)); command.Parameters.Add(DBConnection.CreateParameter("IDInstallator", softInstallation.IdInstallator)); command.Parameters.Add(DBConnection.CreateParameter("Description", softInstallation.Description)); 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); } } }