예제 #1
0
        /// <summary>
        /// Обновление [Nu65]
        /// </summary>
        public static long Update(long id, long productId, string codeProduct, long measureId, string oldDbCodeMeasure,
                                  long materialId, string codeMaterial, string auxiliaryMaterialConsumptionRate, string workGuildId,
                                  string signMaterial, string parcelId, string unitValidation, DateTime date, string flowRate, string oldWorkGuildId,
                                  string oldParcelId)
        {
            var mssqlServer = Properties.Settings.Default.SqlServerNu65;
            var mssqlDb     = Properties.Settings.Default.SqlDbNu65Db;

            try
            {
                using (var mssqlConnection = DbControl.GetConnection(mssqlServer, mssqlDb))
                {
                    mssqlConnection.TryConnectOpen();
                    using (var mssqlTransaction = mssqlConnection.BeginTransaction())
                    {
                        // Обновление [Nu65Table] в MSSQL
                        Nu65StorageMssql.Update(id, measureId, auxiliaryMaterialConsumptionRate, workGuildId,
                                                signMaterial, parcelId, unitValidation, flowRate, mssqlConnection, mssqlTransaction);

                        var foxproDbPath = Properties.Settings.Default.FoxproDbFolder_Fox60_Arm_Base;
                        using (var oleDbConnection = DbControl.GetConnection(foxproDbPath))
                        {
                            oleDbConnection.TryConnectOpen();

                            // Проверка кодировок таблиц и соединения с таблицами FoxPro
                            // Проверка соединений требуется, так как транзации с этими таблицами не работают
                            oleDbConnection.VerifyInstalledEncoding("nu65a");
                            Nu65StorageFoxpro.TestConnection(oleDbConnection);

                            // Обновление [Nu65a] в таблице FoxPro
                            Nu65StorageFoxpro.Update(oleDbConnection, codeProduct, codeMaterial,
                                                     oldDbCodeMeasure, auxiliaryMaterialConsumptionRate, workGuildId,
                                                     signMaterial, parcelId, unitValidation, 0, oldWorkGuildId, oldParcelId);

                            // Подтверждение транзакции MSSQL
                            mssqlTransaction.Commit();
                        }
                    }
                }

                return(0);
            }
            catch (DbException ex) // DbException - суперкласс для SqlException и OleDbException
            {
                throw DbControl.HandleKnownDbFoxProAndMssqlServerExceptions(ex);
            }
        }
예제 #2
0
        /// <summary>
        /// Удаление [Материала для продукта]
        /// </summary>
        public static bool Delete(Material material, Product editedProduct)
        {
            var mssqlServer = Properties.Settings.Default.SqlServerNu65;
            var mssqlDb     = Properties.Settings.Default.SqlDbNu65Db;

            try
            {
                using (var mssqlConnection = DbControl.GetConnection(mssqlServer, mssqlDb))
                {
                    mssqlConnection.TryConnectOpen();
                    using (var mssqlTransaction = mssqlConnection.BeginTransaction())
                    {
                        // Удаление записи о материале в MSSQL таблице
                        Nu65StorageMssql.DeleteById(material.Nu65TableId, mssqlConnection, mssqlTransaction);

                        var foxproDbPath = Properties.Settings.Default.FoxproDbFolder_Fox60_Arm_Base;


                        using (var oleDbConnection = DbControl.GetConnection(foxproDbPath))
                        {
                            oleDbConnection.TryConnectOpen();
                            Nu65StorageFoxpro.TestConnection(oleDbConnection);

                            // Удаление записи о материале в FoxPro таблице
                            Nu65StorageFoxpro.DeleteByMaterialCode(oleDbConnection, editedProduct.DisplayCodeString, material.CodeMaterial,
                                                                   material.WorkGuildId, material.ParcelId);

                            // Подтверждение транзакции MSSQL
                            mssqlTransaction.Commit();
                            return(true);
                        }
                    }
                }
            }
            catch (DbException ex) // DbException - суперкласс для SqlException и OleDbException
            {
                throw DbControl.HandleKnownDbFoxProAndMssqlServerExceptions(ex);
            }
        }