Example #1
0
 public static int Insert(SoftLicType softLicType)
 {
     using (var connection = new DBConnection())
         using (var command = DBConnection.CreateCommand())
         {
             command.CommandText = InsertQuery;
             if (softLicType == null)
             {
                 MessageBox.Show("В метод Insert не передана ссылка на объект вида лицензии", "Ошибка",
                                 MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                 return(-1);
             }
             command.Parameters.Add(DBConnection.CreateParameter("LicType", softLicType.LicType));
             command.Parameters.Add(DBConnection.CreateParameter("LicKeyDuplicateAllowed", softLicType.LicKeyDuplicateAllowed));
             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);
             }
         }
 }
Example #2
0
 public static int Update(SoftLicType softLicType)
 {
     using (var connection = new DBConnection())
         using (var command = DBConnection.CreateCommand())
         {
             command.CommandText = UpdateQuery;
             if (softLicType == null)
             {
                 MessageBox.Show("В метод Update не передана ссылка на объект вида лицензии", "Ошибка",
                                 MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                 return(-1);
             }
             command.Parameters.Add(DBConnection.CreateParameter("LicType", softLicType.LicType));
             command.Parameters.Add(DBConnection.CreateParameter("LicKeyDuplicateAllowed", softLicType.LicKeyDuplicateAllowed));
             command.Parameters.Add(DBConnection.CreateParameter("IDLicType", softLicType.IdLicType));
             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);
             }
         }
 }
Example #3
0
        private static SoftLicType RowToSoftLicType(DataRow row)
        {
            var softLicType = new SoftLicType
            {
                IdLicType = ViewportHelper.ValueOrNull <int>(row, "ID LicType"),
                LicType   = ViewportHelper.ValueOrNull(row, "LicType"),
                LicKeyDuplicateAllowed = ViewportHelper.ValueOrNull <bool>(row, "LicKeyDuplicateAllowed")
            };

            return(softLicType);
        }
Example #4
0
        private List <SoftLicType> SoftLicTypesFromView()
        {
            var list = new List <SoftLicType>();

            for (var i = 0; i < _vSoftLicTypes.Count; i++)
            {
                var st  = new SoftLicType();
                var row = (DataRowView)_vSoftLicTypes[i];
                st.IdLicType = ViewportHelper.ValueOrNull <int>(row, "ID LicType");
                st.LicType   = ViewportHelper.ValueOrNull(row, "LicType");
                st.LicKeyDuplicateAllowed = ViewportHelper.ValueOrNull <bool>(row, "LicKeyDuplicateAllowed") == true;
                list.Add(st);
            }
            return(list);
        }
Example #5
0
        private List <SoftLicType> SoftLicTypesFromViewport()
        {
            var list = new List <SoftLicType>();

            for (var i = 0; i < dataGridView.Rows.Count; i++)
            {
                if (dataGridView.Rows[i].IsNewRow)
                {
                    continue;
                }
                var st  = new SoftLicType();
                var row = dataGridView.Rows[i];
                st.IdLicType = ViewportHelper.ValueOrNull <int>(row, "idSoftLicType");
                st.LicType   = ViewportHelper.ValueOrNull(row, "softLicType");
                st.LicKeyDuplicateAllowed = ViewportHelper.ValueOrNull <bool>(row, "softLicKeyDuplicateAllowed") == true;
                list.Add(st);
            }
            return(list);
        }
 public bool Equals(SoftLicType other)
 {
     return(Equals((object)other));
 }