Beispiel #1
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.");
                }
            }
        }
Beispiel #2
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));
                    }
                }
            }
        }
Beispiel #3
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);
        }