public WorkTime GetWorkTime(Aquarium aquarium) { int aquariumId = aquarium.Id; IList <Maintenance> maintenances = fDB.Query <Maintenance>("select * from Maintenance where (AquariumId = ? and Type between 8 and 9) order by [Timestamp] desc", aquariumId); DateTime startDate = ALCore.ZeroDate; DateTime stopDate = ALCore.ZeroDate; foreach (var mtn in maintenances) { if (mtn.Type == MaintenanceType.AquariumStopped && ALCore.IsZeroDate(stopDate)) { stopDate = mtn.Timestamp; } if (mtn.Type == MaintenanceType.AquariumStarted && ALCore.IsZeroDate(startDate)) { startDate = mtn.Timestamp; break; } } return(new WorkTime(startDate, stopDate)); //return new WorkTime(aquarium.StartDate, aquarium.StopDate); }
public string GetItemStateStr(int recId, ItemType itemType, out ItemState itemState) { DateTime exclusionDate; GetItemState(recId, itemType, out itemState, out exclusionDate); string strState; if (itemState == ItemState.Unknown) { strState = string.Empty; } else { string strExclusDate = ALCore.IsZeroDate(exclusionDate) ? "-" : ALCore.GetDateStr(exclusionDate); strState = string.Format("{0} [{1}]", Localizer.LS(ALData.ItemStates[(int)itemState]), strExclusDate); } return(strState); }
public void GetInhabitantDates(int recId, ItemType itemType, out DateTime inclusionDate, out DateTime exclusionDate, out int currAqmId) { currAqmId = -1; inclusionDate = ALCore.ZeroDate; exclusionDate = ALCore.ZeroDate; IList <Transfer> transfers = QueryTransfers(recId, (int)itemType); int count = 0; foreach (var trf in transfers) { switch (trf.Type) { case TransferType.Relocation: break; case TransferType.Purchase: case TransferType.Birth: count += (int)trf.Quantity; if (ALCore.IsZeroDate(inclusionDate)) { inclusionDate = trf.Timestamp; } break; case TransferType.Sale: case TransferType.Death: count -= (int)trf.Quantity; if (count == 0) { exclusionDate = trf.Timestamp; } break; } if (trf.TargetId > 0) { currAqmId = trf.TargetId; } } }
public void GetWaterChangeIntervals(int aquariumId, WorkTime workTime, out double avgChangeDays, out double lastChangeDays) { double changesDays = 0.0d; int changesCount = 0; DateTime dtPrev = ALCore.ZeroDate; var records = fDB.Query <Maintenance>("select * from Maintenance where ((AquariumId = ?) and (Type between 0 and 3) and (Timestamp >= ?)) order by [Timestamp]", aquariumId, workTime.Start); foreach (Maintenance rec in records) { if (!ALCore.IsZeroDate(dtPrev)) { int days = (rec.Timestamp.Date - dtPrev).Days; changesDays += days; changesCount += 1; } dtPrev = rec.Timestamp.Date; } avgChangeDays = changesDays / changesCount; lastChangeDays = (DateTime.Now.Date - dtPrev).Days; }
public void GetItemState(int recId, ItemType itemType, out ItemState itemState, out DateTime exclusionDate) { itemState = ItemState.Unknown; exclusionDate = ALCore.ZeroDate; IList <Transfer> transfers = QueryTransfers(recId, (int)itemType); foreach (var trf in transfers) { switch (trf.Type) { case TransferType.Death: if (ALCore.IsZeroDate(exclusionDate)) { itemState = ItemState.Dead; exclusionDate = trf.Timestamp; } break; case TransferType.Sale: if (ALCore.IsZeroDate(exclusionDate)) { itemState = ItemState.Sold; exclusionDate = trf.Timestamp; } break; case TransferType.Exclusion: if (ALCore.IsZeroDate(exclusionDate)) { itemState = ALData.ItemTypes[(int)itemType].ExclusionState; exclusionDate = trf.Timestamp; } break; } } }