Example #1
0
        public override void Validate(DataTable proposedData, DataTransferMethod transferMethod)
        {
            base.Validate(proposedData, transferMethod);

            DataSheet StockTypeSheet          = this.Project.GetDataSheet(Constants.DATASHEET_STOCK_TYPE_NAME);
            DataSheet DiagramSheet            = this.GetDataSheet(Constants.DATASHEET_FLOW_PATHWAY_DIAGRAM_NAME);
            Dictionary <int, bool> StockTypes = LookupKeyUtilities.CreateRecordLookup(DiagramSheet, Constants.STOCK_TYPE_ID_COLUMN_NAME);

            foreach (DataRow dr in proposedData.Rows)
            {
                if (dr[Constants.FROM_STOCK_TYPE_ID_COLUMN_NAME] != DBNull.Value)
                {
                    int FromStockTypeId = Convert.ToInt32(dr[Constants.FROM_STOCK_TYPE_ID_COLUMN_NAME], CultureInfo.InvariantCulture);

                    if (!StockTypes.ContainsKey(FromStockTypeId))
                    {
                        string StockTypeName = Convert.ToString(DataTableUtilities.GetTableValue(StockTypeSheet.GetData(), StockTypeSheet.ValueMember, FromStockTypeId, StockTypeSheet.DisplayMember), CultureInfo.InvariantCulture);
                        throw new DataException(string.Format(CultureInfo.InvariantCulture, "Cannot import flow pathways because the 'From Stock' does not exist in this scenario: {0}", StockTypeName));
                    }
                }

                if (dr[Constants.TO_STOCK_TYPE_ID_COLUMN_NAME] != DBNull.Value)
                {
                    int ToStockTypeId = Convert.ToInt32(dr[Constants.TO_STOCK_TYPE_ID_COLUMN_NAME], CultureInfo.InvariantCulture);

                    if (!StockTypes.ContainsKey(ToStockTypeId))
                    {
                        string StockTypeName = Convert.ToString(DataTableUtilities.GetTableValue(StockTypeSheet.GetData(), StockTypeSheet.ValueMember, ToStockTypeId, StockTypeSheet.DisplayMember), CultureInfo.InvariantCulture);
                        throw new DataException(string.Format(CultureInfo.InvariantCulture, "Cannot import flow pathways because the 'To Stock' does not exist in this scenario: {0}", StockTypeName));
                    }
                }
            }
        }
Example #2
0
        public void AddCouplet(int?stockTypeId, int flowTypeId)
        {
#if DEBUG
            if (stockTypeId.HasValue)
            {
                Debug.Assert(stockTypeId.Value > 0);
            }

            Debug.Assert(flowTypeId > 0);
#endif
            string Key = string.Format(CultureInfo.InvariantCulture, "{0}-{1}", LookupKeyUtilities.GetOutputCollectionKey(stockTypeId), flowTypeId);

            if (!this.m_LookAside.ContainsKey(Key))
            {
                LateralFlowCouplet couplet = new LateralFlowCouplet();

                couplet.StockTypeId = stockTypeId;
                couplet.FlowTypeId  = flowTypeId;

                this.m_Couplets.Add(couplet);
                this.m_LookAside.Add(Key, couplet);
            }

            Debug.Assert(this.m_Couplets.Count == this.m_LookAside.Count);
        }
Example #3
0
        public override void Validate(DataRow proposedRow, DataTransferMethod transferMethod)
        {
            base.Validate(proposedRow, transferMethod);

            DataSheet DiagramSheet            = this.GetDataSheet(Constants.DATASHEET_FLOW_PATHWAY_DIAGRAM_NAME);
            Dictionary <int, bool> StockTypes = LookupKeyUtilities.CreateRecordLookup(DiagramSheet, Constants.STOCK_TYPE_ID_COLUMN_NAME);

            if (proposedRow[Constants.FROM_STOCK_TYPE_ID_COLUMN_NAME] != DBNull.Value)
            {
                int FromStockTypeId = Convert.ToInt32(proposedRow[Constants.FROM_STOCK_TYPE_ID_COLUMN_NAME], CultureInfo.InvariantCulture);

                if (!StockTypes.ContainsKey(FromStockTypeId))
                {
                    throw new DataException("The 'From Stock' does not exist for this scenario.");
                }
            }

            if (proposedRow[Constants.TO_STOCK_TYPE_ID_COLUMN_NAME] != DBNull.Value)
            {
                int ToStockTypeId = Convert.ToInt32(proposedRow[Constants.TO_STOCK_TYPE_ID_COLUMN_NAME], CultureInfo.InvariantCulture);

                if (!StockTypes.ContainsKey(ToStockTypeId))
                {
                    throw new DataException("The 'To Stock' does not exist for this scenario.");
                }
            }
        }
Example #4
0
 protected override FiveIntegerLookupKey GetKeyForItem(OutputStock item)
 {
     return(new FiveIntegerLookupKey(
                item.StratumId,
                LookupKeyUtilities.GetOutputCollectionKey(item.SecondaryStratumId),
                LookupKeyUtilities.GetOutputCollectionKey(item.TertiaryStratumId),
                item.StateClassId,
                item.StockGroupId));
 }
 internal int GetSecondaryStratumIdKey(int?value)
 {
     if (this.m_SummaryOmitSecondaryStrata)
     {
         return(Constants.OUTPUT_COLLECTION_WILDCARD_KEY);
     }
     else
     {
         return(LookupKeyUtilities.GetOutputCollectionKey(value));
     }
 }
Example #6
0
        protected override void OnRowsDeleted(object sender, SyncroSim.Core.DataSheetRowEventArgs e)
        {
            bool DeletedRows = false;
            Dictionary <int, bool> RemainingStockTypes = LookupKeyUtilities.CreateRecordLookup(this, Constants.STOCK_TYPE_ID_COLUMN_NAME);
            DataSheet FlowPathwaySheet = this.GetDataSheet(Constants.DATASHEET_FLOW_PATHWAY_NAME);
            DataTable FlowPathwayData  = FlowPathwaySheet.GetData();

            for (int i = FlowPathwayData.Rows.Count - 1; i >= 0; i--)
            {
                DataRow dr = FlowPathwayData.Rows[i];

                if (dr.RowState == DataRowState.Deleted)
                {
                    continue;
                }

                int?FromStockTypeId = null;
                if (dr[Constants.FROM_STOCK_TYPE_ID_COLUMN_NAME] != DBNull.Value)
                {
                    FromStockTypeId = Convert.ToInt32(dr[Constants.FROM_STOCK_TYPE_ID_COLUMN_NAME], CultureInfo.InvariantCulture);
                }

                int?ToStockTypeId = null;
                if (dr[Constants.TO_STOCK_TYPE_ID_COLUMN_NAME] != DBNull.Value)
                {
                    ToStockTypeId = Convert.ToInt32(dr[Constants.TO_STOCK_TYPE_ID_COLUMN_NAME], CultureInfo.InvariantCulture);
                }

                if (FromStockTypeId.HasValue && ToStockTypeId.HasValue)
                {
                    if ((!RemainingStockTypes.ContainsKey(FromStockTypeId.Value)) | (!RemainingStockTypes.ContainsKey(ToStockTypeId.Value)))
                    {
                        DataTableUtilities.DeleteTableRow(FlowPathwayData, dr);
                        DeletedRows = true;
                    }
                }
            }

            if (DeletedRows)
            {
                FlowPathwaySheet.Changes.Add(new ChangeRecord(this, "Diagram data deleted rows"));
            }

            base.OnRowsDeleted(sender, e);
        }
Example #7
0
 protected override FifteenIntegerLookupKey GetKeyForItem(OutputFlow item)
 {
     return(new FifteenIntegerLookupKey(
                item.FromStratumId,
                LookupKeyUtilities.GetOutputCollectionKey(item.FromSecondaryStratumId),
                LookupKeyUtilities.GetOutputCollectionKey(item.FromTertiaryStratumId),
                item.FromStateClassId,
                LookupKeyUtilities.GetOutputCollectionKey(item.FromStockTypeId),
                LookupKeyUtilities.GetOutputCollectionKey(item.TransitionTypeId),
                item.ToStratumId,
                item.ToStateClassId,
                LookupKeyUtilities.GetOutputCollectionKey(item.ToStockTypeId),
                item.FlowGroupId,
                LookupKeyUtilities.GetOutputCollectionKey(item.TransferToStratumId),
                LookupKeyUtilities.GetOutputCollectionKey(item.TransferToSecondaryStratumId),
                LookupKeyUtilities.GetOutputCollectionKey(item.TransferToTertiaryStratumId),
                LookupKeyUtilities.GetOutputCollectionKey(item.TransferToStateClassId),
                LookupKeyUtilities.GetOutputCollectionKey(item.TransferToMinimumAge)));
 }
        private void RecordSummaryFlowOutputData(
            int timestep,
            Cell cell,
            DeterministicTransition deterministicPathway,
            Transition probabilisticPathway,
            FlowPathway flowPathway,
            double flowAmount)
        {
            int?TransitionTypeId = null;
            int StratumIdDest    = cell.StratumId;
            int StateClassIdDest = cell.StateClassId;

            if (probabilisticPathway != null)
            {
                TransitionTypeId = probabilisticPathway.TransitionTypeId;

                if (probabilisticPathway.StratumIdDestination.HasValue)
                {
                    StratumIdDest = probabilisticPathway.StratumIdDestination.Value;
                }

                if (probabilisticPathway.StateClassIdDestination.HasValue)
                {
                    StateClassIdDest = probabilisticPathway.StateClassIdDestination.Value;
                }
            }
            else
            {
                if (deterministicPathway != null)
                {
                    if (deterministicPathway.StratumIdDestination.HasValue)
                    {
                        StratumIdDest = deterministicPathway.StratumIdDestination.Value;
                    }

                    if (deterministicPathway.StateClassIdDestination.HasValue)
                    {
                        StateClassIdDest = deterministicPathway.StateClassIdDestination.Value;
                    }
                }
            }

            if (this.m_STSimTransformer.IsOutputTimestep(
                    timestep,
                    this.m_SummaryFlowOutputTimesteps,
                    this.m_CreateSummaryFlowOutput))
            {
                FlowType t = this.m_FlowTypes[flowPathway.FlowTypeId];

                foreach (FlowGroupLinkage l in t.FlowGroupLinkages)
                {
                    if (!l.FlowGroup.OutputFilter.HasFlag(Constants.OutputFilter.Tabular))
                    {
                        continue;
                    }

                    FifteenIntegerLookupKey k = new FifteenIntegerLookupKey(
                        cell.StratumId,
                        GetSecondaryStratumIdKey(cell),
                        GetTertiaryStratumIdKey(cell),
                        cell.StateClassId,
                        LookupKeyUtilities.GetOutputCollectionKey(flowPathway.FromStockTypeId),
                        LookupKeyUtilities.GetOutputCollectionKey(TransitionTypeId),
                        StratumIdDest,
                        StateClassIdDest,
                        LookupKeyUtilities.GetOutputCollectionKey(flowPathway.ToStockTypeId),
                        l.FlowGroup.Id,
                        LookupKeyUtilities.GetOutputCollectionKey(flowPathway.TransferToStratumId),
                        LookupKeyUtilities.GetOutputCollectionKey(flowPathway.TransferToSecondaryStratumId),
                        LookupKeyUtilities.GetOutputCollectionKey(flowPathway.TransferToTertiaryStratumId),
                        LookupKeyUtilities.GetOutputCollectionKey(flowPathway.TransferToStateClassId),
                        LookupKeyUtilities.GetOutputCollectionKey(flowPathway.TransferToMinimumAge));

                    if (this.m_SummaryOutputFlowRecords.Contains(k))
                    {
                        OutputFlow r = this.m_SummaryOutputFlowRecords[k];
                        r.Amount += (flowAmount * l.Value);
                    }
                    else
                    {
                        OutputFlow r = new OutputFlow(
                            cell.StratumId,
                            GetSecondaryStratumIdValue(cell),
                            GetTertiaryStratumIdValue(cell),
                            cell.StateClassId,
                            flowPathway.FromStockTypeId,
                            TransitionTypeId,
                            StratumIdDest,
                            StateClassIdDest,
                            flowPathway.ToStockTypeId,
                            l.FlowGroup.Id,
                            flowPathway.TransferToStratumId,
                            flowPathway.TransferToSecondaryStratumId,
                            flowPathway.TransferToTertiaryStratumId,
                            flowPathway.TransferToStateClassId,
                            flowPathway.TransferToMinimumAge,
                            flowAmount * l.Value);

                        this.m_SummaryOutputFlowRecords.Add(r);
                    }
                }
            }
        }