public void AddStockIn(int[] selectedIds, int[] selectedValues, string user) { StockInDetail note = new StockInDetail(); note.detailProductList = new List <Product>(); var newList = new List <StockInDetail>(); if (inList == null) { note.detailId = 1; } else { note.detailId = inList.Last().detailId + 1; newList = new List <StockInDetail>(inList); } //Assign value for new note note.detailUser = user; note.detailDateAdded = DateTime.Now; note.detailProductList = new List <Product>(); note.detailStockChange = new List <StockTracker>(); List <Product> changedProducts = new List <Product>(); (note.detailProductList, note.detailStockChange, changedProducts) = UpdateNoteProductList(selectedIds, selectedValues); if (note.detailProductList != null && note.detailStockChange != null && changedProducts != null) { newList.Add(note); //Update database UpdateProductList(changedProducts); LocalDataAccess.WriteDataStockIn(rootPath, stockInFile, newList); } }
public void UpdateStockIn(int selectedId, int[] selectedIds, int[] selectedValues, string user) { var newList = new List <StockInDetail>(inList); var index = newList.FindIndex(n => n.detailId == selectedId); if (index >= 0) { var note = newList[index]; note.detailUser = user; note.detailDateAdded = DateTime.Now; if (selectedIds.Length > 0) { //Roll back bool isRolledBack = RolledBack(note.detailProductList, note.detailStockChange); //New status if (isRolledBack) { note.detailProductList.Clear(); note.detailStockChange.Clear(); List <Product> changedProducts = new List <Product>(); (note.detailProductList, note.detailStockChange, changedProducts) = UpdateNoteProductList(selectedIds, selectedValues); if (note.detailProductList != null && note.detailStockChange != null && changedProducts != null) { UpdateProductList(note.detailProductList); LocalDataAccess.WriteDataStockIn(rootPath, stockInFile, newList); } } } } }
public void DeleteStockIn(int selectedId) { var newList = new List <StockInDetail>(inList); var note = newList.Find(n => n.detailId == selectedId); if (note != null) { //Roll back bool isRolledBack = RolledBack(note.detailProductList, note.detailStockChange); if (isRolledBack) { newList.Remove(note); LocalDataAccess.WriteDataStockIn(rootPath, stockInFile, newList); } } }