Exemplo n.º 1
0
        protected ValidationResult unitsAreConsistant(ITableAdapter tableAdapter)
        {
            //NOTE: tableAdapter gets rid of the last row for us so we can act like it isn't there
            if (tableAdapter.GetRowCount() == 1)
            {
                //Only one row so it must be true;
                return(ValidationResult.Empty);
            }

            string firstRowUnits = tableAdapter.GetUnitAtRow(0);

            string secondRowUnits = tableAdapter.GetUnitAtRow(1);

            //the firstRowUnits must be equal too the secondRowUnits unless secondRowUnits is wildcard
            if (firstRowUnits != secondRowUnits && secondRowUnits != "?")
            {
                return(new ValidationResult(table, ErrorMessageGenerator.GenerateMesssage(ErrorMessages.Inconsistant_Units)));
            }

            //start i at 2
            int i = 2;

            while (i < tableAdapter.GetRowCount())
            {
                //All subrows must be in percent if the second row is or match the first and second row but we know they are equal
                if (secondRowUnits != tableAdapter.GetUnitAtRow(i))
                {
                    return(new ValidationResult(table, ErrorMessageGenerator.GenerateMesssage(ErrorMessages.Inconsistant_Units)));
                }
                i++;
            }

            return(ValidationResult.Empty);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Nice helper function that tallies up compounds for a set of streams
        /// </summary>
        /// <param name="streams"></param>
        /// <returns></returns>
        protected virtual Dictionary <string, StreamComponent> TallyCompounds(IEnumerable <AbstractStream> streams)
        {
            Dictionary <string, StreamComponent> compounds = new Dictionary <string, StreamComponent>(5);

            //tally up flow rates for each compound
            foreach (AbstractStream stream in streams)
            {
                // TODO: Get the commented-out part working again
                throw new NotImplementedException();
                ITableAdapter tableAdapter = null;// TableAdapterFactory.CreateTableAdapter(stream.Table);

                //start at index value = 1 as we're assuming that 1 is the header row, which we don't
                //check in this particular rule (see CheckOverallFlowRate())
                for (int i = 1; i < tableAdapter.GetRowCount(); i++)
                {
                    string compound = tableAdapter.GetCompoundAtRow(i);
                    string quantity = tableAdapter.GetQuantityAtRow(i);
                    string units    = tableAdapter.GetUnitAtRow(i);

                    if (compound != null)
                    {
                        if (!compounds.ContainsKey(compound))
                        {
                            compounds[compound]      = new StreamComponent();
                            compounds[compound].Name = compound;
                        }
                        compounds[compound].AddValue(quantity, units);
                    }
                }
            }
            return(compounds);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This checks all the rules for the table that target points too if target does not point to a table returns does not check anything
        /// </summary>
        public void CheckRule()
        {
            //Clear the list from last time
            ValidationResults.Clear();

            // Make sure the target is not null and it is an StreamPropertiesTable
            if (target != null && target is StreamPropertiesTable)
            {
                ITableAdapter tableAdapter = TableAdapterFactory.CreateTableAdapter(
                    target as StreamPropertiesTable);

                ValidationResult vr;

                if (StreamType.Chemical == (target as StreamPropertiesTable).StreamType)
                {
                    vr = unitsAreConsistant(tableAdapter);

                    if (!vr.IsEmpty)
                    {
                        ValidationResults.Add(vr);
                    }

                    vr = sumOfPartsEqualsTotalQuantity(tableAdapter);

                    if (!vr.IsEmpty)
                    {
                        ValidationResults.Add(vr);
                    }
                }
            }
        }
Exemplo n.º 4
0
 public AsyncLoadingUIController(ITableAdapter tableAdapter, AsyncBufferredTableData <TTuple> data)
 {
     _Adapter   = tableAdapter;
     _AsyncData = data;
     _AsyncData.Source.LoadingSessionStarted += OnAsyncDataLoadingStarted;
     _AsyncData.Source.SingleTaskFinished    += OnAsyncDataSingleTaskFinished;
     _AsyncData.Source.LoadingSessionEnded   += OnAsyncDataLoadingSessionEnded;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Returns the overall flow rate for a set of streams
        /// </summary>
        /// <param name="streams">This is a list of streams whos Overall will be add together</param>
        /// <returns>Returns a StreamComponent which contains the results</returns>
        private StreamComponent TallyOverallFlowRate(IEnumerable <AbstractStream> streams)
        {
            StreamComponent component = new StreamComponent();

            //tally up flow rates coming into this compound
            foreach (AbstractStream stream in streams)
            {
                // TODO: Get the commented-out part working again
                throw new NotImplementedException();
                ITableAdapter tableAdapter = null;// TableAdapterFactory.CreateTableAdapter(stream.Table);
                if (tableAdapter.GetTableType() == TableType.Chemcial)
                {
                    component.AddValue(tableAdapter.GetQuantityAtRow(0));
                }
            }
            return(component);
        }
Exemplo n.º 6
0
        void Dispose()
        {
            // Unsubscribing from events makes this object available for GC

            if (_AsyncData != null && _AsyncData.Source != null)
            {
                _AsyncData.Source.LoadingSessionStarted -= OnAsyncDataLoadingStarted;
                _AsyncData.Source.SingleTaskFinished    -= OnAsyncDataSingleTaskFinished;
                _AsyncData.Source.LoadingSessionEnded   -= OnAsyncDataLoadingSessionEnded;
            }
            if (_Adapter != null)
            {
                _Adapter.ItemsRefreshed -= OnAdapterItemsRefreshed;
            }

            _Adapter   = null;
            _AsyncData = null;
        }
Exemplo n.º 7
0
 /* Заполняет ТекстБоксы на форме редактирования
  *                           Комбобокс с выбором ID и Текстбоксы*/
 internal void SelectDataForEdit(ITableAdapter TableAdapter, string id, TextBox[] textBoxes)
 {
     try
     {
         sqlConnection.Open();
         sqlCommand = TableAdapter.Select(sqlConnection);
         sqlCommand.Parameters.Add(new SqlParameter("@param1", id));
         sqlDataReader = sqlCommand.ExecuteReader();
         sqlDataReader.GetValues(textBoxes);
     }
     catch (Exception)
     {
         ErrorMessage();
         throw;
     }
     finally
     {
         sqlDataReader.Close();
         sqlConnection.Close();
     }
 }
Exemplo n.º 8
0
 // Удаление данных из таблицы в БД
 internal void RemoveData(ITableAdapter TableAdapter, string value)
 {
     try
     {
         sqlConnection.Open();
         sqlCommand            = TableAdapter.Delete(sqlConnection);
         sqlCommand.Connection = sqlConnection;
         sqlCommand.Parameters.Add(new SqlParameter("@param1", value));
         sqlCommand.ExecuteNonQuery();
         CongratulationMessage();
     }
     catch (Exception)
     {
         ErrorMessage();
         throw;
     }
     finally
     {
         sqlConnection.Close();
     }
 }
Exemplo n.º 9
0
        public void CheckRule()
        {
            ITableAdapter tableAdapter = TableAdapterFactory.CreateTableAdapter(table);

            ValidationResult vr;

            //Clear the list from last time
            ValidationResults.Clear();

            vr = unitsAreConsistant(tableAdapter);

            if (!vr.IsEmpty)
            {
                ValidationResults.Add(vr);
            }

            vr = sumOfPartsEqualsTotalQuantity(tableAdapter);

            if (!vr.IsEmpty)
            {
                ValidationResults.Add(vr);
            }
        }
Exemplo n.º 10
0
 // Вставка данных в таблицу в БД
 internal void InsertData(ITableAdapter TableAdapter, params string[] value)
 {
     try
     {
         sqlConnection.Open();
         sqlCommand = TableAdapter.Insert(sqlConnection);
         for (int i = 0; i < TableAdapter.InsertParams; i++)
         {
             sqlCommand.Parameters.Add(new SqlParameter(String.Format("@param{0}", i + 1), value[i]));
         }
         sqlCommand.ExecuteNonQuery();
         CongratulationMessage();
     }
     catch (Exception)
     {
         ErrorMessage();
         throw; // Убрать перед показом
     }
     finally
     {
         sqlConnection.Close();
     }
 }
Exemplo n.º 11
0
 public CellRowRecyclerViewAdapter(Context context, ITableView tableView) : base(context, null)
 {
     this.mTableAdapter = tableView.GetAdapter();
     this.mTableView    = tableView;
 }
Exemplo n.º 12
0
 public EventDataStore(ITableAdapter adapter)
 {
     Adapter = adapter;
 }
Exemplo n.º 13
0
        protected ValidationResult sumOfPartsEqualsTotalQuantity(ITableAdapter tableAdapter)
        {
            float overalQuantity;

            if (tableAdapter.GetRowCount() == 1)
            {
                //Only one row so it must be true;
                return(ValidationResult.Empty);
            }

            //? is wildcard for percent here cheating a little
            if (tableAdapter.GetUnitAtRow(0) == "?")
            {
                //using percents so the sum must at up to 100 (100%)
                overalQuantity = 100;
            }
            else
            {
                try
                {
                    overalQuantity = float.Parse(tableAdapter.GetQuantityAtRow(0));
                }
                catch
                {
                    //Not a number and the only thing the table accepts that isn't a number is ?
                    //since we do not know the total we cannot see if the sum equals the total so assume true
                    return(ValidationResult.Empty);
                }
                //So didn't return so overalQuantity must be equal to the overal Quantity
            }

            //at this point overalQuantity could equal 100 or the overal Quantity but we dont care the sume of the parts must
            //equal whatever number it is.

            bool  gotQuestionMark  = false;
            float sumPartsQuantity = 0;
            int   i = 1;

            //the adapter gets rid of the extra row
            while (i < tableAdapter.GetRowCount())
            {
                try
                {
                    sumPartsQuantity += float.Parse(tableAdapter.GetQuantityAtRow(i));
                }
                catch
                {
                    //the only thing that would make the parse fail is a questionMark
                    gotQuestionMark = true;
                }
                i++;
            }

            //Fails if either the sum is gerater than the overal or if sum does not equal overal and questionMark was not found
            if ((sumPartsQuantity > overalQuantity) || (gotQuestionMark == false && sumPartsQuantity != overalQuantity))
            {
                return(new ValidationResult(table, ErrorMessageGenerator.GenerateMesssage(ErrorMessages.Sum_Does_Not_Equal_Total_Quantity)));
            }

            return(ValidationResult.Empty);
        }
 public ColumnHeaderRecyclerViewAdapter(Context context, IList <IColumnHeader> itemList,
                                        ITableAdapter tableAdapter) : base(context, itemList)
 {
     this.mTableAdapter = tableAdapter;
     this.mTableView    = tableAdapter.GetTableView();
 }
Exemplo n.º 15
0
 public DataInterop(T tableAdapter)
 {
     this.tableAdapter = tableAdapter;
 }
Exemplo n.º 16
0
        /// <summary>
        /// This is called when we want to check the tables validity.  Then it calls buildFeedbackMessage so that,
        /// a a new EveryoneDict can be made with the new data.
        /// </summary>
        /// <param name="tables">This is a list of PropertiesWindow to be checked typically all of them</param>
        private void CheckChemicalStreamPropertiesWindowFeedback(IEnumerable <IPfdElement> tables)
        {
            IRule rule = new TableRule();

            List <string>            nonUniqueNames = new List <string>();
            List <IPropertiesWindow> listOfTables   = new List <IPropertiesWindow>();

            foreach (IPropertiesWindow table in tables)
            {
                rule.Target = table;
                rule.CheckRule();

                // TODO: fix (eventually)
                throw new NotImplementedException("Rule manager is broken");
                ITableAdapter tableAdapter = null;
                //ITableAdapter tableAdapter = TableAdapterFactory.CreateTableAdapter(table);
                int       i     = 0;
                int       items = tableAdapter.GetRowCount();
                TableType tableType;
                string    label, units, quantity, compound, temp;

                while (i < items)
                {
                    tableType = tableAdapter.GetTableType();
                    label     = tableAdapter.GetLabelAtRow(i);
                    units     = tableAdapter.GetUnitAtRow(i);
                    quantity  = tableAdapter.GetQuantityAtRow(i);
                    compound  = tableAdapter.GetCompoundAtRow(i);

                    if (currentDifficultySetting == OptionDifficultySetting.MaterialAndEnergyBalance)
                    {
                        temp = tableAdapter.GetTemperature();
                    }
                    else
                    {
                        //we dont need temp to just zero it out
                        temp = "0";
                    }

                    if (!tableDict.Keys.Contains(label))
                    {
                        tableDict.Add(label, new GenericTableData(table, tableType, label, units, quantity, compound, temp));
                    }
                    else
                    {
                        if (!nonUniqueNames.Contains(label))
                        {
                            nonUniqueNames.Add(label);
                        }
                        listOfTables.Add(table);
                    }
                    i++;
                }

                foreach (ValidationResult vr in rule.ValidationResults)
                {
                    if (!EveryoneDict.ContainsKey(vr.Target))
                    {
                        EveryoneDict.Add(vr.Target, new List <string>());
                    }
                    EveryoneDict[vr.Target].Add("[" + ruleNumber + "]\n-" + vr.Message + "\n");
                    ruleNumber++;
                }
            }
            if (nonUniqueNames.Count > 0)
            {
                ValidationResult vr = (new ValidationResult(listOfTables, ErrorMessageGenerator.GenerateMesssage(Validation.ErrorMessages.NonUniqueNames, nonUniqueNames.ToArray())));
                if (!EveryoneDict.ContainsKey(vr.Target))
                {
                    EveryoneDict.Add(vr.Target, new List <string>());
                }
                EveryoneDict[vr.Target].Add("[" + ruleNumber + "]\n-" + vr.Message + "\n");
                ruleNumber++;
            }
        }