public void SaveBlobsFromTable(string table, string idcolumn, string datacolumn, enDataType datatype, string savepath) { switch (DatabaseType) { case enDatabaseType.MySql: mysqlConnector.SaveBlobsFromTable(table, idcolumn, datacolumn, datatype.ToString(), savepath); break; case enDatabaseType.MSSql: mssqlConnector.SaveBlobsFromTable(table, idcolumn, datacolumn, datatype.ToString(), savepath); break; case enDatabaseType.FireBird: throw new NotImplementedException("Funksjon ikke tilgjengelig for FireBird-db"); } }
/// <summary> /// Ritorna gli aggregati pieces in base al tipo di aggregazione /// </summary> /// <param name="machine"></param> /// <param name="period"></param> /// <param name="dataType"></param> /// <returns>Lista dei dettagli degli stati</returns> public List <HistoryPieceModel> GetAggregationPieces(MachineInfoModel machine, PeriodModel period, enDataType dataType) { var result = new List <HistoryPieceModel>(); try { var query = _context.Set <HistoryPiece>().Where(hp => hp.MachineId == machine.Id && hp.Day >= period.StartDate && hp.Day <= period.EndDate); switch (dataType) { case enDataType.Dashboard: result = query.Where(hp => hp.Shift == null && hp.Operator == null).ToList() .GroupBy(g => g.System).Select(n => new HistoryPieceModel { Id = n.Max(i => i.Id), CompletedCount = n.Sum(i => i.CompletedCount), Day = n.Max(i => i.Day), ElapsedTime = n.Sum(i => i.ElapsedTime), ElapsedTimeProducing = n.Sum(i => i.ElapsedTimeProducing), ElapsedTimeCut = n.Sum(i => i.ElapsedTimeCut), ElapsedTimeWorking = n.Sum(i => i.ElapsedTimeWorking), ElapsedTimeTrim = n.Sum(i => i.ElapsedTimeTrim), MachineId = machine.Id, Operator = null, Period = null, PieceLengthSum = n.Sum(i => i.PieceLengthSum), RedoneCount = n.Sum(i => i.RedoneCount), Shift = null, System = n.Key, TypeHistory = "d" }).ToList(); break; case enDataType.Historical: { var queryResult = query.Where(hp => hp.Shift == null && hp.Operator == null).ToList(); switch (period.Aggregation) { case enAggregation.Day: { int?Func(HistoryPiece hs) { return(hs.Period); } const string typeHistory = "d"; var res = BuildAggregationList(queryResult, typeHistory, Func); return(res.ToList()); } case enAggregation.Week: { int?Func(HistoryPiece hs) { return(hs.WeekOfYearDay); } const string typeHistory = "w"; var res = BuildAggregationList(queryResult, typeHistory, Func); return(res.ToList()); } case enAggregation.Month: { int?Func(HistoryPiece hs) { return(hs.Day.Month); } const string typeHistory = "m"; var res = BuildAggregationList(queryResult, typeHistory, Func); return(res.ToList()); } case enAggregation.Quarter: { int?Func(HistoryPiece hs) { return(hs.QuarteOfYearDay); } const string typeHistory = "q"; var res = BuildAggregationList(queryResult, typeHistory, Func); return(res.ToList()); } case enAggregation.Year: { int?Func(HistoryPiece hs) { return(hs.Day.Year); } const string typeHistory = "y"; var res = BuildAggregationList(queryResult, typeHistory, Func); return(res.ToList()); } } break; } case enDataType.Operators: result = query.Where(hp => hp.Shift == null && hp.Operator != null).ToList() .GroupBy(g => new { g.System, g.Operator }) .Select(n => new HistoryPieceModel { Id = n.Max(i => i.Id), CompletedCount = n.Sum(i => i.CompletedCount), Day = n.Max(i => i.Day), ElapsedTime = n.Sum(i => i.ElapsedTime), ElapsedTimeProducing = n.Sum(i => i.ElapsedTimeProducing), ElapsedTimeCut = n.Sum(i => i.ElapsedTimeCut), ElapsedTimeWorking = n.Sum(i => i.ElapsedTimeWorking), ElapsedTimeTrim = n.Sum(i => i.ElapsedTimeTrim), MachineId = machine.Id, Operator = n.Key.Operator, Period = null, PieceLengthSum = n.Sum(i => i.PieceLengthSum), RedoneCount = n.Sum(i => i.RedoneCount), Shift = null, System = n.Key.System, TypeHistory = "d" }).ToList(); break; } } catch (Exception ex) { var errMessage = string.Format(ex.GetStringLog(), machine.Id.ToString(), string.Concat(period.StartDate.ToString(CultureInfo.InvariantCulture), " - ", period.EndDate.ToString(CultureInfo.InvariantCulture), " - ", period.Aggregation.ToString(), dataType.ToString())); LogService.WriteLog(errMessage, LogService.TypeLevel.Error, ex); } return(result); }
/// <summary> /// Ritorna gli allarmi n base a tipo di dati da visualizzare in base al tipo di aggregazione /// </summary> /// <param name="machine"></param> /// <param name="period"></param> /// <param name="dataType"></param> /// <param name="actualMachineGroup"></param> /// <returns>Lista dei dettagli degli stati</returns> public List <HistoryMessageModel> GetAggregationMessages(MachineInfoModel machine, PeriodModel period, enDataType dataType, string actualMachineGroup = null) { try { var cl = _languageService.GetCurrentLanguage() ?? 0; var machineGroup = _context.Set <MachineGroup>() .FirstOrDefault(n => n.MachineGroupName == actualMachineGroup)?.Id; List <int> messTypes = (new int[] { 11, 12 }).ToList(); bool limitTime = true; var role = _accountService.GetLoggedUser().Role; if (role == enRole.Assistance || role == enRole.RandD || role == enRole.Administrator) { messTypes.Add(13); limitTime = false; } var queryResult = _historyMessageRepository .GetHistoryMessage(machine.Id, period.StartDate, period.EndDate, machineGroup, messTypes, limitTime); switch (dataType) { case enDataType.Historical: switch (period.Aggregation) { case enAggregation.Day: { int?Func(HistoryMessage hs) { return(hs.Period); } const string typeHistory = "d"; var result = BuildAggregationList(queryResult, typeHistory, Func); return(result.ToList()); } case enAggregation.Week: { int?Func(HistoryMessage hs) { return(hs.Day.HasValue ? (int?)hs.Day.Value.Year * 100 + hs.Day.Value.GetWeekNumber() : null); } const string typeHistory = "w"; var result = BuildAggregationList(queryResult, typeHistory, Func); return(result.ToList()); } case enAggregation.Month: { int?Func(HistoryMessage hs) { return(hs.Day.HasValue ? (int?)hs.Day.Value.Year * 100 + hs.Day.Value.Month : null); } const string typeHistory = "m"; var result = BuildAggregationList(queryResult, typeHistory, Func); return(result.ToList()); } case enAggregation.Quarter: { int?Func(HistoryMessage hs) { return(hs.Day.HasValue ? (int?)hs.Day.Value.Year * 100 + GetQuarter(hs.Day ?? DateTime.UtcNow) : null); } const string typeHistory = "q"; var result = BuildAggregationList(queryResult, typeHistory, Func); return(result.ToList()); } case enAggregation.Year: { int?Func(HistoryMessage hs) { return(hs.Day.HasValue ? (int?)hs.Day.Value.Year * 100 + hs.Day.Value.Year : null); } const string typeHistory = "y"; var result = BuildAggregationList(queryResult, typeHistory, Func); return(result.ToList()); } } break; case enDataType.Summary: var historyMessagesSummary = _historyMessageRepository .GetHistoryMessage(machine.Id, period.StartDate, period.EndDate, machineGroup, messTypes, limitTime) .GroupBy(g => new { g.MachineId, Description = g.GetDescription(cl), g.MessagesIndex.MessageCode, g.MessagesIndex?.MessageTypeId }).ToList().Select(s => new AggregationMessageModel { Id = s.Max(m => m.Id), Code = s.Key.MessageCode, Count = s.Sum(i => i.Count), Day = s.Max(i => i.Day), MachineId = s.Key.MachineId, TypeHistory = "y", Description = s.Key.Description, Type = s.Key.MessageTypeId }).ToList(); return(historyMessagesSummary.BuildAdapter().AdaptToType <List <HistoryMessageModel> >()); } } catch (Exception ex) { var errMessage = string.Format(ex.GetStringLog(), machine.Id.ToString(), string.Concat(period.StartDate.ToString(), " - ", period.EndDate.ToString(), " - ", period.Aggregation.ToString()), dataType.ToString()); LogService.WriteLog(errMessage, LogService.TypeLevel.Error, ex); } return(new List <HistoryMessageModel>()); }
public int Compare(object x, object y) { ListViewItem lviX = x as ListViewItem; ListViewItem lviY = y as ListViewItem; string strX = lviX.SubItems[m_nSortColumn].Text; string strY = lviY.SubItems[m_nSortColumn].Text; switch (m_nDataType) { case enDataType.enDataType_String: if (SortOrder.Ascending == m_ListView.Sorting) { return(string.Compare(strX, strY)); } else if (SortOrder.Descending == m_ListView.Sorting) { return(-string.Compare(strX, strY)); } break; case enDataType.enDataType_Number: int nSign = 0; if (SortOrder.Ascending == m_ListView.Sorting) { nSign = 1; } else if (SortOrder.Descending == m_ListView.Sorting) { nSign = -1; } Regex regNum = new Regex("-?\\d+"); if (!regNum.IsMatch(strX) || !regNum.IsMatch(strY)) { return(nSign * string.Compare(strX, strY)); } long nX, nY; if (!long.TryParse(strX, out nX) || !long.TryParse(strY, out nY)) { return(nSign * string.Compare(strX, strY)); } return(nSign * Math.Sign(nX - nY)); case enDataType.enDataType_Date: DateTime dt_x, dt_y; if (DateTime.TryParse(strX, out dt_x) && DateTime.TryParse(strY, out dt_y)) { return((SortOrder.Ascending == m_ListView.Sorting ? 1 : -1) * Math.Sign(dt_x.Ticks - dt_y.Ticks)); } else { return(SortOrder.Ascending == m_ListView.Sorting ? string.Compare(strX, strY) : -string.Compare(strX, strY)); } default: MessageBox.Show("Error Column Data Type " + m_nDataType.ToString()); break; } return(0); }
/// <summary> /// Ritorna gli aggregati degli stati in mase al tipo di aggregazione /// </summary> /// <param name="machine"></param> /// <param name="period"></param> /// <param name="dataType"></param> /// <returns>Lista dei dettagli degli stati</returns> public List <HistoryStateModel> GetAggregationStates(MachineInfoModel machine, PeriodModel period, enDataType dataType) { try { IEnumerable <HistoryState> queryResult; switch (dataType) { case enDataType.Dashboard: queryResult = _historyStateRepository.Get(hs => hs.Day <= period.EndDate && hs.Day >= period.StartDate && hs.MachineId == machine.Id && hs.Shift == null && hs.Operator == null); return(BuildHistoryStateModelsOperatorDashboard(queryResult)); case enDataType.Operators: queryResult = _historyStateRepository.Get(hs => hs.Day <= period.EndDate && hs.Day >= period.StartDate && hs.MachineId == machine.Id && hs.Shift == null && hs.Operator != null); return(BuildHistoryStateModelsOperatorDashboard(queryResult)); case enDataType.Historical: { queryResult = _historyStateRepository.Get(hs => hs.Day <= period.EndDate && hs.Day >= period.StartDate && hs.MachineId == machine.Id && hs.Shift == null && hs.Operator == null, null, "State"); switch (period.Aggregation) { case enAggregation.Day: { int?Func(HistoryState hs) { return(hs.Period); } const string typeHistory = "d"; var result = BuildAggregationList(queryResult, typeHistory, Func); return(result.ToList()); } case enAggregation.Week: { int?Func(HistoryState hs) { if (hs.Day != null) { return(hs.Day.Value.Year * 100 + hs.Day.Value.GetWeekNumber()); } return(null); } const string typeHistory = "w"; var result = BuildAggregationList(queryResult, typeHistory, Func); return(result.ToList()); } case enAggregation.Month: { int?Func(HistoryState hs) { if (hs.Day != null) { return(hs.Day.Value.Year * 100 + hs.Day.Value.Month); } return(null); } const string typeHistory = "m"; var result = BuildAggregationList(queryResult, typeHistory, Func); return(result.ToList()); } case enAggregation.Quarter: { int?Func(HistoryState hs) { if (hs.Day != null) { return(hs.Day.Value.Year * 100 + hs.Day.Value.GetQuarter()); } return(null); } const string typeHistory = "q"; var result = BuildAggregationList(queryResult, typeHistory, Func); return(result.ToList()); } case enAggregation.Year: { int?Func(HistoryState hs) { if (hs.Day != null) { return(hs.Day.Value.Year * 100 + hs.Day.Value.Year); } return(null); } const string typeHistory = "y"; var result = BuildAggregationList(queryResult, typeHistory, Func); return(result.ToList()); } } break; } } } catch (Exception ex) { var errMessage = string.Format(ex.GetStringLog(), machine.Id.ToString(), string.Concat(period.StartDate.ToString(CultureInfo.InvariantCulture), " - ", period.EndDate.ToString(CultureInfo.InvariantCulture), " - ", period.Aggregation.ToString()), dataType.ToString()); LogService.WriteLog(errMessage, LogService.TypeLevel.Error, ex); } return(null); }