public List <StatisticStoreDto> GetStatisticStores(string fromDate, string toDate) { var allStatisticDto = m_PersistenceManager.GetStatisticStores(fromDate, toDate); if (!String.IsNullOrEmpty(fromDate)) { var preFromDate = DateUtil.GetDateTimeAsDdmmyyyy(((DateTime)DateUtil.GetDateTime(fromDate)).AddDays(-1)); var allPreStatisticDto = m_PersistenceManager.GetStatisticStores(String.Empty, preFromDate); var mapPreStatisticStore = new Hashtable(); foreach (var dto in allPreStatisticDto) { string key = dto.MaterialName + "|" + dto.UnitName; mapPreStatisticStore.Add(key, dto); } foreach (var statisticDto in allStatisticDto) { string key = statisticDto.MaterialName + "|" + statisticDto.UnitName; if (mapPreStatisticStore.ContainsKey(key)) { StatisticStoreDto preStatisticDto = (StatisticStoreDto)mapPreStatisticStore[key]; statisticDto.PreviousInventory = preStatisticDto.Inventory; statisticDto.Inventory += preStatisticDto.Inventory; } } } return(allStatisticDto); }
private void AddOneRow(StatisticStoreDto dto) { int index = inventoryDataGridView.Rows.Add(); var r = inventoryDataGridView.Rows[index]; r.Cells["material"].Value = dto.MaterialName; r.Cells["unit"].Value = dto.UnitName; r.Cells["previousInventory"].Value = dto.PreviousInventory; r.Cells["impAmount"].Value = dto.ImpAmount; r.Cells["expAmount"].Value = dto.ExpAmount; r.Cells["inventory"].Value = dto.Inventory; }
public List <StatisticStoreDto> GetStatisticStores(string fromDate, string toDate) { using (ISession session = m_SessionFactory.OpenSession()) { string sqlQuery = "select new Store(s.Id, m.Name, s.Amount, u.Name, s.StoredStatus, s.StoredDate, s.StoredBy, s.Reason)" + " from Store s, Material m, Unit u" + " where m.Id = s.MaterialId" + " and u.Id = m.UnitId"; var mapParams = new Hashtable(); if (!String.IsNullOrEmpty(fromDate)) { sqlQuery += " and s.StoredDate >= :fromDate"; mapParams.Add("fromDate", DateUtil.GetDateTime(fromDate)); } if (!String.IsNullOrEmpty(toDate)) { sqlQuery += " and s.StoredDate < :toDate"; mapParams.Add("toDate", ((DateTime)DateUtil.GetDateTime(toDate)).AddDays(1)); } var query = session.CreateQuery(sqlQuery); foreach (DictionaryEntry param in mapParams) { query.SetParameter(param.Key.ToString(), param.Value); } // Get the matching objects var allStatisticStores = query.List(); // Update Role info var listStatisticStoreDtos = new List <StatisticStoreDto>(); var mapStore = new Hashtable(); foreach (Store store in allStatisticStores) { string key = store.MaterialName + "|" + store.UnitName; float impAmount = 0; float expAmount = 0; if (store.StoredStatus.Equals("IMPORT")) { impAmount = store.Amount; } else { expAmount = store.Amount; } float inventory = impAmount - expAmount; if (mapStore.ContainsKey(key)) { StatisticStoreDto storeDto = (StatisticStoreDto)mapStore[key]; storeDto.ImpAmount += impAmount; storeDto.ExpAmount += expAmount; storeDto.Inventory += inventory; } else { var storeDto = new StatisticStoreDto() { MaterialName = store.MaterialName, UnitName = store.UnitName, ImpAmount = impAmount, ExpAmount = expAmount, Inventory = inventory }; listStatisticStoreDtos.Add(storeDto); mapStore.Add(key, storeDto); } } return(listStatisticStoreDtos); } }