public void UpdateStockMaterial(T_StockMaterial stockMaterial) { StockMaterialList.Remove(StockMaterialList.Find(o => o.StockCode == stockMaterial.StockCode && o.MatCode == stockMaterial.MatCode)); StockMaterialList.Add(stockMaterial); }
private void AddButton_Click(object sender, EventArgs e) { if(this.gvPODetails.GetFocusedRow()== null) { return; } T_PurchaseOrderDetail detail = this.gvPODetails.GetFocusedRow() as T_PurchaseOrderDetail; EnteringWindow window = new EnteringWindow(); window.Material = detail.Material; window.Quantity = detail.Quantity; window.ExistQuantity = _StockMaterials.Where(o => o.PODetailId == (this.gvPODetails.GetFocusedRow() as T_PurchaseOrderDetail).Id).Sum(o => o.Quantity); window.FormClosed += (o, ee) => { if (window.DialogResult == System.Windows.Forms.DialogResult.OK) { if (_StockMaterials.Where(m => m.StockCode == window.StockCode.Code && m.MatCode == SelectedDetail.Material.MatCode).Count() > 0) { T_StockMaterial material = _StockMaterials.Find(m => m.StockCode == window.StockCode.Code && m.MatCode == SelectedDetail.Material.MatCode && m.PODetailId == SelectedDetail.Id); material.Quantity += window.EnteringQuantity; material.AvailableQuantity += window.EnteringQuantity; if (!_AddList.Contains(material)) { _EditList.Add(material); } } else { T_StockMaterial material = new T_StockMaterial() { PONo = SelectedDetail.PONo, PODetailId = SelectedDetail.Id, Unit = SelectedDetail.Unit, MatCode = SelectedDetail.Material.MatCode, MatDesc = SelectedDetail.Material.MatDesc, MatTypeCode = SelectedDetail.Material.MatTypeCode, MatModeCode = SelectedDetail.Material.MatModeCode, StockCode = window.StockCode.Code, StockDesc = window.StockCode.Desc, Quantity = window.EnteringQuantity, AvailableQuantity = window.EnteringQuantity }; (this.gcStockMaterials.DataSource as List<T_StockMaterial>).Add(material); _StockMaterials.Add(material); _AddList.Add(material); } this.gvStockMaterials.RefreshData(); } }; window.ShowDialog(); }
public List<T_StockMaterial> GetMergeStockMaterials() { List<T_StockMaterial> materialList = new List<T_StockMaterial>(); foreach (var item in StockMaterialList.GroupBy(o => new { o.MatCode, o.MatDesc, o.MatTypeCode, o.MatModeCode, o.Unit }).Select(g => new { g.Key.MatCode, g.Key.MatDesc, g.Key.MatTypeCode, g.Key.MatModeCode, g.Key.Unit, AvailableQuantity = g.Sum(t => t.AvailableQuantity) })) { T_StockMaterial material = new T_StockMaterial(); material.MatCode = item.MatCode; material.MatDesc = item.MatDesc; material.MatTypeCode = item.MatTypeCode; material.MatModeCode = item.MatModeCode; material.Unit = item.Unit; material.AvailableQuantity = item.AvailableQuantity; materialList.Add(material); } return materialList; }