private void ddlProductCode_KeyDown(object sender, KeyEventArgs e) { long productID = 0; if (e.KeyCode == Keys.Enter) { productID = Convert.ToInt64(ddlProductCode.SelectedValue); if (productID == 0) { productID = Convert.ToInt64(ddlProductName.SelectedValue); } BO.Product objProductInfo = _IProduct.GetProductList().FirstOrDefault(m => m.ProductId == productID); if (objProductList == null) { objProductInfo.Sln = 1; } else { objProductInfo.Sln = objProductList.Count + 1; } objProductList.Add(objProductInfo); grvProduct.AutoGenerateColumns = false; if (objProductList.Count > 0) { if (grvProduct.RowCount > 0) { grvProduct.DataSource = null; } grvProduct.DataSource = objProductList; } } }
private void btnSave_Click(object sender, EventArgs e) { try { BO.Product objProducts = new BO.Product(); objProducts.ProductName = txtPro_Name.Text; objProducts.ProdPackSize.ProductCode = txtProductCode.Text; objProducts.ProdPackSize.PackSizeID = Convert.ToInt32(ddlPackSize.SelectedValue); objProducts.Brand.BrandID = Convert.ToInt32(ddlBrand.SelectedValue); objProducts.ProductGeneric.PGenericID = Convert.ToInt32(ddlGenericName.SelectedValue); objProducts.ProductCategory.Id = Convert.ToInt32(ddlCategory.SelectedValue); objProducts.ProductPrice.TradePrice = Convert.ToDecimal(txtTradePrice.Text); objProducts.ProductPrice.PurchasePrice = Convert.ToDecimal(txtPurchesePrice.Text); objProducts.ProductPrice.Vat = Convert.ToDecimal(txtVat.Text); objProducts.ProductPrice.MRP = Convert.ToDecimal(txtMRP.Text); objProducts.BatchNo = Convert.ToString(txtBatch.Text); objProducts.Description = txtDescription.Text; objProducts.ProdPackSize.PPSID = pPSID; objProducts.ProductPrice.PPID = pPID; if (btnSave.Text == "Update" && txtPro_Name.Text != "") { if (_IProduct.Update(objProducts, ID) > 0) { MessageBox.Show("Successfully Update"); Reset(); GetProductList(); } } else if (btnSave.Text == "Save") { if (_IProduct.Insert(objProducts) > 0) { MessageBox.Show("Successfully Saved"); //lblMessageBox.Text = "Successfully Saved"; //lblMessageBox.ForeColor = Color.Green; GetProductList(); Reset(); } else { MessageBox.Show("Operation Failed"); //lblMessageBox.Text = "Operation Failed"; //lblMessageBox.ForeColor = Color.Red; } } else { MsgBox msgBox = new MsgBox(); msgBox.Show(); } } catch (Exception) { MsgBox msgBox = new MsgBox(); msgBox.Show(); } }
private void grvProductEntry_CellClick(object sender, DataGridViewCellEventArgs e) { try { BO.Product objProduct = new BO.Product(); if (e.ColumnIndex == grvProductEntry.Columns["Edit"].Index && e.RowIndex >= 0) { int numberRow = Convert.ToInt32(e.RowIndex); ID = Convert.ToInt32(grvProductEntry.Rows[numberRow].Cells[0].Value.ToString()); objProduct = _IProduct.GetProductList().FirstOrDefault(m => m.ProductId == ID); txtPro_Name.Text = objProduct.ProductName; txtProductCode.Text = objProduct.ProductCode; ddlPackSize.SelectedValue = objProduct.ProdPackSize.PackSizeID; ddlBrand.SelectedValue = objProduct.Brand.BrandID; ddlGenericName.SelectedValue = objProduct.ProductGeneric.PGenericID; ddlCategory.SelectedValue = objProduct.ProductCategory.Id; txtTradePrice.Text = objProduct.TradePrice.ToString(); txtPurchesePrice.Text = objProduct.PurchesePrice.ToString(); txtVat.Text = objProduct.Vat.ToString(); txtMRP.Text = objProduct.MRP.ToString(); txtBatch.Text = objProduct.BatchNo.ToString(); txtDescription.Text = objProduct.Description.ToString(); pPID = objProduct.ProductPrice.PPID; pPSID = objProduct.ProdPackSize.PPSID; btnSave.Text = "Update"; } else if (e.ColumnIndex == grvProductEntry.Columns["Delete"].Index && e.RowIndex >= 0) { int numberRow = Convert.ToInt32(e.RowIndex); //assign the value plus the desired column example 1 ID = Convert.ToInt32(grvProductEntry.Rows[numberRow].Cells[0].Value.ToString()); objProduct = _IProduct.GetProductList().FirstOrDefault(m => m.ProductId == ID); pPID = objProduct.ProductPrice.PPID; pPSID = objProduct.ProdPackSize.PPSID; if (_IProduct.DELETE(objProduct) > 0) { MessageBox.Show("Operation Success"); Reset(); } } } catch (Exception ex) { lblMessageBox.Text = ex.ToString(); lblMessageBox.Enabled = true; lblMessageBox.ForeColor = Color.Red; } }