public static void AddProductToGrid(IList <CustomModel.CustomProduct> lstProduct, GridControl grid) { _gridUtility = new GridUtility(grid); if (lstProduct == null) { return; } IList <CustomModel.CustomProduct> lstSource = grid.DataSource as IList <CustomModel.CustomProduct>; if (lstSource == null) { lstSource = new List <CustomModel.CustomProduct>(); } foreach (CustomModel.CustomProduct poProduct in lstProduct) { if (poProduct.QuotationPrice <= 0) { poProduct.QuotationPrice = poProduct.BasePrice; } CustomModel.CustomProduct exists = lstSource.Where(p => p.ProductId == poProduct.ProductId).FirstOrDefault(); if (exists != null) { exists.Quantity += poProduct.Quantity; } else { if (poProduct.Quantity == 0) { poProduct.Quantity = 1; } lstSource.Add(poProduct); } } _gridUtility.BindingData <CustomModel.CustomProduct>(lstSource); }
private void btnFinish_Click(object sender, EventArgs e) { IList <CustomModel.CustomProduct> lstLookProduct = new List <CustomModel.CustomProduct>(); for (int i = 0; i < gridView1.DataRowCount; i++) { CustomModel.CustomProduct lookProduct = gridView1.GetRow(i) as CustomModel.CustomProduct; if (lookProduct.Quantity != 0) { if (lookProduct.POPrice == 0) { lookProduct.POPrice = lookProduct.BasePrice; } lstLookProduct.Add(lookProduct); } } if (lstLookProduct != null && AddProductToGrid != null) { AddProductToGrid(lstLookProduct); } if (EnableForm != null) { EnableForm(true); } Close(); }