Ejemplo n.º 1
0
        //
        // UpdateRecord2
        //
        // Updates the database from a typed dataset containing a row for LFS_MASTER_AREA,
        // and zero or more rows for LFS_M2_TABLES.
        //
        public void UpdateRecord2(TDSLFSRecord dataSet, int companyId, AddRecordTDS addRecordTDS, ViewFullLengthLiningTDS viewFullLengthLiningTDS, ViewJLinersheetTDS viewJLinersheetTDS, string tdsToWork)
        {
            //--- Prepare transaction
            //--- ... Open connection and start transaction
            dcConnection.Open();
            SqlTransaction transaction2 = dcConnection.BeginTransaction();

            //... Assign transaction to data adapters
            this.daLFSMasterArea.InsertCommand.Transaction = transaction2;
            this.daLFSMasterArea.UpdateCommand.Transaction = transaction2;
            this.daLFSMasterArea.DeleteCommand.Transaction = transaction2;

            this.daLFSJunctionLiner2.InsertCommand.Transaction = transaction2;
            this.daLFSJunctionLiner2.UpdateCommand.Transaction = transaction2;
            this.daLFSJunctionLiner2.DeleteCommand.Transaction = transaction2;

            this.daLfsMasterAreaRct.InsertCommand.Transaction = transaction2;
            this.daLfsMasterAreaRct.UpdateCommand.Transaction = transaction2;
            this.daLfsMasterAreaRct.DeleteCommand.Transaction = transaction2;

            this.daLfsJunctionLinerRct.InsertCommand.Transaction = transaction2;
            this.daLfsJunctionLinerRct.UpdateCommand.Transaction = transaction2;
            this.daLfsJunctionLinerRct.DeleteCommand.Transaction = transaction2;

            try
            {
                //Update database

                //... deletes
                daLFSJunctionLiner2.Update(dataSet.LFS_JUNCTION_LINER2.Select("", "", DataViewRowState.Deleted));
                daLFSMasterArea.Update(dataSet.LFS_MASTER_AREA.Select("", "", DataViewRowState.Deleted));

                //... updates
                daLFSJunctionLiner2.Update(dataSet.LFS_JUNCTION_LINER2.Select("", "", DataViewRowState.ModifiedCurrent));
                daLFSMasterArea.Update(dataSet.LFS_MASTER_AREA.Select("", "", DataViewRowState.ModifiedCurrent));

                //... inserts
                // Point Repairs
                daLFSMasterArea.Update(dataSet.LFS_MASTER_AREA.Select("", "", DataViewRowState.Added));
                daLFSJunctionLiner2.Update(dataSet.LFS_JUNCTION_LINER2.Select("", "", DataViewRowState.Added));

                //... record change tracking records
                daLfsMasterAreaRct.Update(dataSet);

                //--- Commit transaction
                transaction2.Commit();

            }
            catch (DBConcurrencyException dBConcurrencyException)
            {
                //--- Rollback transaction
                transaction2.Rollback();

                //--- Throw exception
                throw new Exception("Concurrency error: Another user already updated the data you are working on.  Your operation has been cancelled.", dBConcurrencyException);
            }
            catch (SqlException sqlException)
            {
                //--- Rollback transaction
                transaction2.Rollback();

                //--- Throw exception
                byte severityLevel = sqlException.Class;
                if (severityLevel <= 16)
                {
                    throw new Exception("Low severity error. Your operation has been cancelled.  SQL Error " + severityLevel + ".");
                }
                if ((severityLevel >= 17) && (severityLevel <= 19))
                {
                    throw new Exception("Mid severity error. Your operation has been cancelled.  SQL Error " + severityLevel + ".");
                }
                if (severityLevel >= 20)
                {
                    throw new Exception("High severity error. Your operation has been cancelled.  SQL Error " + severityLevel + ".");
                }
            }
            catch (Exception e)
            {
                //--- Rollback transaction
                transaction2.Rollback();

                //--- Throw exception
                throw new Exception("Unknow error.  Your operation has been cancelled.", e);
            }
            finally
            {
                //--- Close connection
                if (dcConnection.State == System.Data.ConnectionState.Open)
                {
                    dcConnection.Close();
                }

                object[] array = dataSet.LFS_MASTER_AREA.Rows[0].ItemArray;
                Guid newId = (Guid)array.GetValue(0);

                if (tdsToWork == "addRecord")
                {
                    AddRecordPointRepairs addRecordPointRepairs = new AddRecordPointRepairs(addRecordTDS);
                    addRecordPointRepairs.Save(companyId, newId);
                }

                if (tdsToWork == "viewFullLengthLining")
                {
                    ViewFullLengthLiningLfsM2Tables viewFullLengthLiningLfsM2Tables = new ViewFullLengthLiningLfsM2Tables(viewFullLengthLiningTDS);
                    viewFullLengthLiningLfsM2Tables.Save(companyId, newId);
                }

                if (tdsToWork == "viewJLinersheet")
                {
                    ViewJLinersheetJunctionLiner viewJLinersheetJunctionLiner = new ViewJLinersheetJunctionLiner(viewJLinersheetTDS);
                    viewJLinersheetJunctionLiner.Save(companyId, newId);
                }
            }
        }