public FinancialDataAdapter(OleDbDataReader dr, List<DateTime> dates, int rowNumber)
        {
            ErrorMessages = new List<string>();
            int issueId;
            string issueIdString = dr.SafeValueToString((int) FinancialColumn.IssueId);
            DateValue = new Dictionary<DateTime, decimal>();

            if (Int32.TryParse(issueIdString, out issueId))
            {
                IssueId = issueId;
            }
            else
            {
                ErrorMessages.Add(string.Format("Could not convert Issue id '{0}' to Int. Rown number '{1}'. Skipping ", issueIdString, rowNumber));
            }

            var financeTypeString = dr.SafeValueToString((int) FinancialColumn.FinanceType).Trim();

            if (financeTypeString == FinanceType.Baseline.ToString()) FinanceType = FinanceType.Baseline;
            else if (financeTypeString == FinanceType.Budget.ToString()) FinanceType = FinanceType.Budget;
            else if (financeTypeString == FinanceType.Forecast.ToString()) FinanceType = FinanceType.Forecast;
            else if (financeTypeString == FinanceType.ForecastV1.ToString()) FinanceType = FinanceType.ForecastV1;
            else if (financeTypeString == FinanceType.ForecastV2.ToString()) FinanceType = FinanceType.ForecastV2;
            else if (financeTypeString == FinanceType.ForecastV3.ToString()) FinanceType = FinanceType.ForecastV3;
            else
            {
                ErrorMessages.Add(string.Format("Could not recognise FinancialType '{0}'. Rown number '{1}'. Skipping ", financeTypeString, rowNumber));
            } //add error msg

            int dateIndex = 0;
            for (int i = (int) FinancialColumn.FinanceType + 1; i < dr.FieldCount; i++)
            {
                DateTime date = dates[dateIndex];
                dateIndex++;
                string dateStringValue = dr.SafeValueToString(i);
                dateStringValue = dateStringValue.Replace("$","");
                if (string.IsNullOrEmpty(dateStringValue)) {continue;} //Import only data that has value

                decimal dateValue;

                if (Decimal.TryParse(dateStringValue, out dateValue))
                {
                    DateValue.Add(date, Math.Round(dateValue,2));
                }
                else
                {
                    ErrorMessages.Add(string.Format("Could not convert value '{0}' for '{1}'. Rown number '{2}'. Skipping ", dateStringValue,date, rowNumber));
                }
            }
        }
        public InstrumentComponentDataAdapter(OleDbDataReader dr, List<InstrumentProperty> existingInstrumentProperties, 
            IList<string> spreadSheetComponentPropertyNames, int rowNumber, bool canCreateProperties, CommonUtils.ImportType importType)
        {
            base.PopulateCommonProperties(dr);
            RowNumber = rowNumber;

            mImportType = importType;
            int k = 0;
            const int StartColumnIndex = (int)BaseComponentColumn.Model + 1;

            for (int i = StartColumnIndex; i < StartColumnIndex + spreadSheetComponentPropertyNames.Count; i++)
            {

                if (string.IsNullOrEmpty(dr.SafeString(i)))
                {
                    continue;
                }

                string propertyName = spreadSheetComponentPropertyNames[k];
                k++;

                InstrumentProperty property = (from x in existingInstrumentProperties where x.Name.ToLower() == propertyName.ToLower() select x).FirstOrDefault();

                if (property != null)
                {
                    PropertyValues.Add(property.Name, dr.SafeValueToString(i));
                }
                else
                {
                    if (canCreateProperties)
                    {
                        if (!PropertyValues.ContainsValue(dr.SafeString(i)))
                        {
                            PropertyValues.Add(propertyName, dr.SafeString(i));
                        }
                    }
                    else
                    {
                        ErrorMessages.Add(RaiseMissingPropertyMessage(ComponentName, rowNumber, propertyName));
                        break;
                    }

                }
            }

            base.Validate(rowNumber, mImportType==CommonUtils.ImportType.CreateInstrumentComponent);
        }
Exemple #3
0
        public Cji5DataAdapter(OleDbDataReader dr, int rowNumber)
        {
            ErrorMessages = new List<string>();
            PoNumber = dr.SafeValueToString((int) PurchaseColumn.RefDocumentNumber);
            ProjectDefinition = dr.SafeValueToString((int)PurchaseColumn.ProjectDefinition);

            if (String.IsNullOrEmpty(ProjectDefinition))
            {
                ErrorMessages.Add(string.Format("{0} returned null, please check the format of this cell in Excel (set to Text). Row number '{1}'. Skipping ", PurchaseColumn.ProjectDefinition,  rowNumber));
            }

            VendorNumber = dr.SafeValueToString((int)PurchaseColumn.Vendor);
            Description = dr.SafeValueToString((int)PurchaseColumn.Name);

            decimal totalAmountValue;
            string totalAmountString = dr.SafeValueToString((int)PurchaseColumn.PlanObjectCur);

            if (Decimal.TryParse(totalAmountString, out totalAmountValue))
            {
                TotalAmount = totalAmountValue;
            }
            else
            {
                ErrorMessages.Add(string.Format("Could not convert {0} '{1}' to decimal. Row number '{2}'. Skipping ", PurchaseColumn.PlanObjectCur, totalAmountString, rowNumber));
            }

            decimal valueInObjCrcyValue;
            string valueInObjCrcyString = dr.SafeValueToString((int)PurchaseColumn.ValueInObjCrcy);

            if (Decimal.TryParse(valueInObjCrcyString, out valueInObjCrcyValue))
            {
                ValueInObjCrcy = valueInObjCrcyValue;
            }
            else
            {
                ErrorMessages.Add(string.Format("Could not convert {0} '{1}' to decimal. Row number '{2}'. Skipping ", PurchaseColumn.ValueInObjCrcy, valueInObjCrcyString, rowNumber));
            }

            WbsElement = dr.SafeValueToString((int)PurchaseColumn.WbsElement);

            if (String.IsNullOrEmpty(WbsElement))
            {
                ErrorMessages.Add(string.Format("{0} returned null, please check the format of this cell in Excel (set to Text). Row number '{1}'. Skipping ", PurchaseColumn.WbsElement, rowNumber));
            }

            int costElementValue;
            string costElementString = dr.SafeValueToString((int)PurchaseColumn.CostElement);

            if (int.TryParse(costElementString, out costElementValue))
            {
                CostElement = costElementValue;
            }
            else
            {
                ErrorMessages.Add(string.Format("Could not convert {0} '{1}' to decimal. Row number '{2}'. Skipping ", PurchaseColumn.CostElement, costElementString, rowNumber));
            }

            int referenceItemValue;
            string referenceItemString = dr.SafeValueToString((int)PurchaseColumn.ReferenceItem);

            if (int.TryParse(referenceItemString, out referenceItemValue))
            {
                ReferenceItem = referenceItemValue;
            }
            else
            {
                ErrorMessages.Add(string.Format("Could not convert {0} '{1}' to decimal. Row number '{2}'. Skipping ", PurchaseColumn.ReferenceItem, referenceItemString, rowNumber));
            }

            ReferenceDocType = dr.SafeValueToString((int)PurchaseColumn.ReferenceDocType);

            DateTime dateValue;
            string dateStringValue = dr.SafeValueToString((int)PurchaseColumn.DocumentDate);
            if (DateTime.TryParse(dateStringValue, out dateValue))
            {
                Date = dateValue;
            }
            else
            {
                ErrorMessages.Add(string.Format("Could not convert {0} '{1}' to Date. Row number '{2}'. Skipping ", PurchaseColumn.DocumentDate, dateStringValue, rowNumber));
            }
        }
Exemple #4
0
        public Cji3DataAdapter(OleDbDataReader dr, int rowNumber)
        {
            ErrorMessages = new List<string>();

            //FiscalYear
            string fiscalYearString = string.Empty;
            fiscalYearString = dr.SafeValueToString((int)Cij3Column.FiscalYear);
            int fiscalYear;

            if (int.TryParse(fiscalYearString, out fiscalYear))
            {
                FiscalYear = fiscalYear;
            }
            else
            {
                ErrorMessages.Add(string.Format("Could not convert {0} '{1}' to integer. Rown number '{2}'. Skipping ", Cij3Column.FiscalYear, fiscalYearString, rowNumber));
            }

            //Period
            string periodString = string.Empty;
            periodString = dr.SafeValueToString((int)Cij3Column.Period);
            int period;

            if (int.TryParse(periodString, out period))
            {
                Period = period;
            }
            else
            {
                ErrorMessages.Add(string.Format("Could not convert {0} '{1}' to decimal. Rown number '{2}'. Skipping ", Cij3Column.Period, periodString, rowNumber));
            }

            //Date
            Date = new DateTime(fiscalYear,period,1);

            //Project Definition
            ProjectDefinition = dr.SafeValueToString((int)Cij3Column.ProjectDefinition);
            if (String.IsNullOrEmpty(ProjectDefinition))
            {
                ErrorMessages.Add(string.Format("{0} returned null, please check the format of this cell in Excel (set to Text). Row number '{1}'. Skipping ", Cij3Column.ProjectDefinition, rowNumber));
            }

            //WBS Element
            WbsElement = dr.SafeValueToString((int)Cij3Column.WbsElement);
            if (String.IsNullOrEmpty(WbsElement))
            {
                ErrorMessages.Add(string.Format("{0} returned null, please check the format of this cell in Excel (set to Text). Row number '{1}'. Skipping ", Cij3Column.WbsElement, rowNumber));
            }

            //Purchasing Document
            PurchasingDocument = dr.SafeValueToString((int)Cij3Column.PurchasingDocument);

            //Purchase Order Text
            PurchaseOrderText = dr.SafeValueToString((int)Cij3Column.PurchaseOrderText);

            //Name
            Name = dr.SafeValueToString((int)Cij3Column.Name);

            //PartnerObject
            PartnerObject = dr.SafeValueToString((int)Cij3Column.PartnerObject);

            //CoPartnerObject
            CoPartnerObjectName = dr.SafeValueToString((int)Cij3Column.CoPartnerObjectName);

            //Posting Date
            DateTime postingDate;
            string postingDateString = dr.SafeValueToString((int)Cij3Column.PostingDate);
            if (DateTime.TryParse(postingDateString, out postingDate))
            {
                PostingDate = postingDate;
            }
            else
            {
                ErrorMessages.Add(string.Format("Could not convert {0} '{1}' to Date. Rown number '{2}'. Skipping ", Cij3Column.PostingDate, postingDateString, rowNumber));
            }

            //Value in Object Currency
            string valueCurrencyString = string.Empty;
            valueCurrencyString = dr.SafeValueToString((int)Cij3Column.ValueInObjCrcy);
            decimal valueCurrency;

            if (decimal.TryParse(valueCurrencyString, out valueCurrency))
            {
                ValueInObjectCurrency = valueCurrency;
            }
            else
            {
                ErrorMessages.Add(string.Format("Could not convert {0} '{1}' to decimal. Rown number '{2}'. Skipping ", Cij3Column.ValueInObjCrcy, valueCurrencyString, rowNumber));
            }
        }