Exemplo n.º 1
0
        public Fee GetFeeData(Fee returnValue)
        {
            using (OleDbConnection connection = new OleDbConnection(ConnectionString))
            {
                using (OleDbCommand sqlCommand = connection.CreateCommand())
                {
                    string fields = returnValue.GetFieldNames();

                    sqlCommand.CommandText = "SELECT " + fields + ", Adjustment, AdjustmentExplanation, IsPriority, IsEmergency, IsRapidResponse FROM tblFees WHERE ID = " + returnValue.ID;
                    connection.Open();

                    OleDbDataReader reader = sqlCommand.ExecuteReader();
                    reader.Read();

                    int index = 0;
                    foreach (ICharge charge in returnValue.Charges)
                    {
                        switch (charge.Type)
                        {
                        case "variable":
                            VariableCharge vCharge = (VariableCharge)charge;
                            vCharge.Count = reader.GetDecimalSafe(index++);
                            break;

                        case "categorical":
                            CategoricalCharge cCharge = (CategoricalCharge)charge;
                            cCharge.Count = reader.GetDecimalSafe(index++);
                            break;

                        case "boolean":
                            BooleanCharge bCharge = (BooleanCharge)charge;
                            bCharge.IsIncurred = reader.GetBooleanSafe(index++);
                            break;
                        }
                    }
                    returnValue.Adjustment            = reader.GetDecimalSafe(index++);
                    returnValue.AdjustmentExplanation = reader.GetStringSafe(index++);
                    returnValue.IsPriority            = reader.GetBooleanSafe(index++);
                    returnValue.IsEmergency           = reader.GetBooleanSafe(index++);
                    returnValue.IsRapidResponse       = reader.GetBooleanSafe(index++);

                    returnValue.CalculateProjectCost();
                    return(returnValue);
                }
            }
        }