Ejemplo n.º 1
0
 public static HluDataSet.incid_bapRow MakeAdditional(HluDataSet.incid_bapRow r)
 {
     if (r != null)
     {
         r.quality_determination = BAPDetQltyUserAdded;
     }
     return(r);
 }
Ejemplo n.º 2
0
 public BapEnvironment(bool bulkUpdateMode, bool additional, HluDataSet.incid_bapRow dataRow)
 {
     _bulkUpdateMode = bulkUpdateMode;
     _additionalBap  = additional;
     HluDataSet.incid_bapDataTable table = (HluDataSet.incid_bapDataTable)dataRow.Table;
     _bap_id                      = dataRow.bap_id;
     _incid                       = dataRow.incid;
     _bap_habitat                 = dataRow.IsNull(table.bap_habitatColumn) ? null : dataRow.bap_habitat;
     _quality_determination       = _additionalBap ? BAPDetQltyUserAdded : dataRow.IsNull(table.quality_determinationColumn) ? null : dataRow.quality_determination;
     _quality_interpretation      = dataRow.IsNull(table.quality_interpretationColumn) ? null : dataRow.quality_interpretation;
     this.interpretation_comments = dataRow.IsNull(table.interpretation_commentsColumn) ?
                                    null : dataRow.interpretation_comments;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates BAP environment rows corresponding to current incid.
        /// </summary>
        private void UpdateBap()
        {
            if (_viewModelMain.IncidBapRowsAuto == null)
            {
                _viewModelMain.IncidBapRowsAuto = new ObservableCollection <BapEnvironment>();
            }
            if (_viewModelMain.IncidBapHabitatsUser == null)
            {
                _viewModelMain.IncidBapHabitatsUser = new ObservableCollection <BapEnvironment>();
            }

            // remove duplicate codes
            IEnumerable <BapEnvironment> beAuto = from b in _viewModelMain.IncidBapRowsAuto
                                                  group b by b.bap_habitat into habs
                                                  select habs.First();

            IEnumerable <BapEnvironment> beUser = from b in _viewModelMain.IncidBapHabitatsUser
                                                  where beAuto.Count(a => a.bap_habitat == b.bap_habitat) == 0
                                                  group b by b.bap_habitat into habs
                                                  select habs.First();

            var currentBapRows = beAuto.Concat(beUser);

            List <HluDataSet.incid_bapRow> newRows    = new List <HluDataSet.incid_bapRow>();
            List <HluDataSet.incid_bapRow> updateRows = new List <HluDataSet.incid_bapRow>();

            HluDataSet.incid_bapRow updateRow;

            foreach (BapEnvironment be in currentBapRows)
            {
                if (be.bap_id == -1) // new BAP environment
                {
                    be.bap_id = _viewModelMain.RecIDs.NextIncidBapId;
                    be.incid  = _viewModelMain.Incid;
                    HluDataSet.incid_bapRow newRow = _viewModelMain.IncidBapTable.Newincid_bapRow();
                    newRow.ItemArray = be.ToItemArray();
                    newRows.Add(newRow);
                }
                else if ((updateRow = UpdateIncidBapRow(be)) != null)
                {
                    updateRows.Add(updateRow);
                }
            }

            _viewModelMain.IncidBapRows.Where(r => r.RowState != DataRowState.Deleted &&
                                              currentBapRows.Count(g => g.bap_id == r.bap_id) == 0).ToList()
            .ForEach(delegate(HluDataSet.incid_bapRow row) { row.Delete(); });

            if (_viewModelMain.HluTableAdapterManager.incid_bapTableAdapter.Update(
                    _viewModelMain.IncidBapRows.Where(r => r.RowState == DataRowState.Deleted).ToArray()) == -1)
            {
                throw new Exception(String.Format("Failed to update {0} table.", _viewModelMain.HluDataset.incid_bap.TableName));
            }

            if (updateRows.Count > 0)
            {
                if (_viewModelMain.HluTableAdapterManager.incid_bapTableAdapter.Update(updateRows.ToArray()) == -1)
                {
                    throw new Exception(String.Format("Failed to update {0} table.", _viewModelMain.HluDataset.incid_bap.TableName));
                }
            }

            foreach (HluDataSet.incid_bapRow r in newRows)
            {
                _viewModelMain.HluTableAdapterManager.incid_bapTableAdapter.Insert(r);
            }
        }