Пример #1
0
        public static List <KPIMeasurements> GetKPIMeasurementCategoriesTimeByKpiId(int kpiId, string categoryId, string categoryItemId)
        {
            if (kpiId <= 0)
            {
                throw new ArgumentException(Resources.ImportData.ZeroKpiId);
            }

            List <KPIMeasurements> theList = new List <KPIMeasurements>();
            KPIMeasurements        theData = null;

            try
            {
                KpiMeasurementDSTableAdapters.KpiMeasurementTableAdapter localAdapter = new KpiMeasurementDSTableAdapters.KpiMeasurementTableAdapter();
                KpiMeasurementDS.KpiMeasurementDataTable theTable = localAdapter.GetKpiMeasurementCategoriesByKpiId(kpiId, categoryId, categoryItemId);
                if (theTable != null && theTable.Rows.Count > 0)
                {
                    foreach (KpiMeasurementDS.KpiMeasurementRow theRow in theTable)
                    {
                        theData          = new KPIMeasurements(theRow.measurmentID, theRow.kpiID, theRow.date, theRow.measurement);
                        theData.Detalle  = theRow.IsdetalleNull() ? "" : theRow.detalle;
                        theData.DataTime = KPIDataTimeBLL.GetKPIDataTimeFromValue(theData.Measurement);
                        theList.Add(theData);
                    }
                }
            }
            catch (Exception exc)
            {
                log.Error("Error en GetKPIMeasurementCategoriesByKpiId para kpiId: " + kpiId, exc);
                throw new ArgumentException(Resources.ImportData.GetKPIMeasurements);
            }

            return(theList);
        }
Пример #2
0
        public static void InsertKpiMeasuerementImported(int kpiId, List <KPIMeasurements> theList, string type)
        {
            if (kpiId <= 0)
            {
                throw new ArgumentException(Resources.ImportData.ZeroKpiId);
            }

            using (System.Transactions.TransactionScope transaction = new System.Transactions.TransactionScope())
            {
                try
                {
                    KpiMeasurementDSTableAdapters.QueriesTableAdapter queries = new KpiMeasurementDSTableAdapters.QueriesTableAdapter();

                    foreach (KPIMeasurements theData in theList)
                    {
                        if (theData.DataTime != null)
                        {
                            theData.Measurement = KPIDataTimeBLL.GetValueFromKPIDataTime(theData.DataTime);
                        }

                        if (!string.IsNullOrEmpty(theData.MeasurementIDsToReplace) && type.Equals("R"))
                        {
                            queries.DeleteKpiMeasurementByListIds(theData.MeasurementIDsToReplace);
                        }

                        int?newData = 0;
                        queries.InsertKpiMeasurement(ref newData, kpiId, theData.Date, theData.Measurement);

                        if (!string.IsNullOrEmpty(theData.Detalle))
                        {
                            string[] itemList     = theData.Detalle.Split(',');
                            string[] categoryList = theData.Categories.Split(',');
                            for (int i = 0; i < itemList.Length; i++)
                            {
                                queries.InsertKpiMeasurementCategories(newData.Value, itemList[i].Trim(), categoryList[i].Trim());
                            }
                        }
                    }

                    transaction.Complete();
                }
                catch (Exception exc)
                {
                    log.Error("Error en InsertKpiMeasuerementImported para kpiId: " + kpiId, exc);
                    transaction.Dispose();
                    throw new Exception(Resources.ImportData.InsertMeasurementError);
                }
            }
        }