private void btnShowBOM_Click(object sender, EventArgs e) { try { frmPopup = new Form(); frmPopup.StartPosition = FormStartPosition.CenterScreen; frmPopup.BackColor = Color.CadetBlue; frmPopup.MaximizeBox = false; frmPopup.MinimizeBox = false; frmPopup.ControlBox = false; frmPopup.FormBorderStyle = FormBorderStyle.FixedSingle; frmPopup.Size = new Size(500, 340); BOMDB bomdb = new BOMDB(); string prodID = lblProductCode.Text.Trim(); grdBomDetail = bomdb.getGridViewForBOMDetail(prodID, ModelNo); grdBomDetail.Bounds = new Rectangle(new Point(0, 0), new Size(500, 300)); grdBomDetail.Columns["PurchasePrice"].Visible = false; grdBomDetail.Columns["CustomPrice"].Visible = false; frmPopup.Controls.Add(grdBomDetail); Button lvCancel = new Button(); lvCancel.Text = "Close"; lvCancel.BackColor = Color.Tan; lvCancel.Location = new System.Drawing.Point(20, 310); lvCancel.Click += new System.EventHandler(this.grdCancel_Click1); frmPopup.Controls.Add(lvCancel); frmPopup.ShowDialog(); } catch (Exception ex) { } }
private void grdList_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex < 0) { return; } if (e.ColumnIndex == 5) { captureChange = false; int rowID = e.RowIndex; btnSave.Text = "Update"; cmbProduct.SelectedIndex = cmbProduct.FindStringExact(grdList.Rows[e.RowIndex].Cells[0].Value.ToString()); txtDetails.Text = grdList.Rows[e.RowIndex].Cells[2].Value.ToString(); txtCost.Text = grdList.Rows[e.RowIndex].Cells[3].Value.ToString(); cmbStatus.SelectedIndex = cmbStatus.FindStringExact(grdList.Rows[e.RowIndex].Cells[4].Value.ToString()); DataGridViewRow row = grdList.Rows[rowID]; //get customer bank details BOMDB bomdb = new BOMDB(); List <bomdetail> bomdetails = bomdb.getBOMDetail(grdList.Rows[e.RowIndex].Cells[0].Value.ToString()); grdBOMDetail.Rows.Clear(); int i = 0; foreach (bomdetail bd in bomdetails) { AddBOMDetailRow(); grdBOMDetail.Rows[i].Cells[0].Value = i + 1; //DataGridViewComboBoxCell ComboColumn1 = new DataGridViewComboBoxCell(); //StockItemDB.fillTaxItemGridViewCombo(ComboColumn1,""); //grdBOMDetail.Rows[i].Cells[1] = ComboColumn1; //grdBOMDetail.Rows[i].Cells[1].Value = bd.Name; DataGridViewComboBoxCell ComboColumn1 = new DataGridViewComboBoxCell(); StockItemDB.fillStockItemGridViewCombo(ComboColumn1, ""); grdBOMDetail.Rows[i].Cells[1].Value = bd.StockItemID + "-" + bd.Name; grdBOMDetail.Rows[i].Cells[2].Value = bd.Quantity; grdBOMDetail.Rows[i].Cells[3].Value = bd.PurchasePrice; grdBOMDetail.Rows[i].Cells[4].Value = bd.CustomPrice; i++; } cmbProduct.SelectedIndex = cmbProduct.FindString(grdList.Rows[e.RowIndex].Cells[0].Value.ToString()); cmbProduct.Enabled = false; verifyAndReworkBOMDetailGridRows(); btnSave.Text = "Update"; pnlBOMDetails.Visible = true; pnlBottomActions.Visible = false; captureChange = true; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private Boolean createAndUpdateBOMDetails(string productID) { Boolean status = true; try { BOMDB bomdb = new BOMDB(); bomdetail bd = new bomdetail(); List <bomdetail> BOMDetail = new List <bomdetail>(); for (int i = 0; i < grdBOMDetail.Rows.Count; i++) { try { string iid = grdBOMDetail.Rows[i].Cells[1].Value.ToString(); iid = iid.Substring(0, iid.IndexOf('-')); bd = new bomdetail(); bd.ProductID = productID; bd.StockItemID = iid; bd.Quantity = Convert.ToDouble(grdBOMDetail.Rows[i].Cells[2].Value.ToString()); bd.PurchasePrice = Convert.ToDouble(grdBOMDetail.Rows[i].Cells[3].Value.ToString()); bd.CustomPrice = Convert.ToDouble(grdBOMDetail.Rows[i].Cells[4].Value.ToString()); BOMDetail.Add(bd); } catch (Exception) { MessageBox.Show("createAndUpdateBOMDetails() : Error creating BOM Details"); status = false; } } /////*TaxCodeWorkingDB*/ customerbankdetailsdb = new CustomerBankDetailsDB(); if (!bomdb.updateBOMDetail(productID, BOMDetail)) { MessageBox.Show("createAndUpdateBOMDetails() : Failed to update BOM Details. Please check the values"); status = false; } } catch (Exception) { MessageBox.Show("createAndUpdateBOMDetails() : Error updating BOM Details"); status = false; } return(status); }
private void ListBOMHeader() { try { grdList.Rows.Clear(); BOMDB bomdb = new BOMDB(); List <bomheader> BOMHeaders = bomdb.getBOMHeader(); foreach (bomheader bh in BOMHeaders) { grdList.Rows.Add(bh.ProductID, bh.Name, bh.Details, bh.Cost, Main.getStatusString(bh.status)); } } catch (Exception) { MessageBox.Show("Error in BOM Header listing"); } pnlList.Visible = true; }
private void addGridListRows() { try { BOMDB bomdb = new BOMDB(); string[] ProductStrArr = prod.Split('-'); string ProdID = ProductStrArr[0]; string ProdName = ProductStrArr[1]; lblProductCode.Text = ProdID; lblProductname.Text = ProdName; bomList = bomdb.getBOMDetail(ProdID); txtProdQuantity.Text = prodQuant.ToString(); int QuantTOPrepare = Convert.ToInt32(txtProdQuantity.Text); lblModelNo.Text = ModelNo; foreach (bomdetail bom in bomList) { string stockID = bom.StockItemID; double totalStock = StockDB.getTotalItemWiseStock(stockID, lblModelNo.Text); grdList.Rows.Add(); grdList.Rows[grdList.Rows.Count - 1].Cells["SINO"].Value = grdList.Rows.Count; grdList.Rows[grdList.Rows.Count - 1].Cells["StockItemID"].Value = bom.StockItemID; grdList.Rows[grdList.Rows.Count - 1].Cells["StockItemName"].Value = bom.Name; grdList.Rows[grdList.Rows.Count - 1].Cells["gModelNo"].Value = "NA"; grdList.Rows[grdList.Rows.Count - 1].Cells["RequiredQuantity"].Value = bom.Quantity * QuantTOPrepare; grdList.Rows[grdList.Rows.Count - 1].Cells["StockQunatity"].Value = totalStock; if ((bom.Quantity * QuantTOPrepare) > totalStock) { grdList.Rows[grdList.Rows.Count - 1].Cells["IssueQuantity"].Value = totalStock; } else { grdList.Rows[grdList.Rows.Count - 1].Cells["IssueQuantity"].Value = bom.Quantity * QuantTOPrepare; } } } catch (Exception ex) { } }
private Boolean verifyAndReworkBOMDetailGridRows() { Boolean status = true; try { double quantity = 0; double purchaseprice = 0; double customprice = 0.0; double cost = 0.0; totalcost = 0.0; BOMDB bomdb = new BOMDB(); if (grdBOMDetail.Rows.Count <= 0) { MessageBox.Show("No entries in BOM table"); return(false); } for (int i = 0; i < grdBOMDetail.Rows.Count; i++) { grdBOMDetail.Rows[i].Cells[0].Value = (i + 1); if ((grdBOMDetail.Rows[i].Cells[2].Value == null) || ((grdBOMDetail.Rows[i].Cells[3].Value == null) && (grdBOMDetail.Rows[i].Cells[4].Value == null))) { MessageBox.Show("Fill values in row " + (i + 1)); return(false); } if (Convert.ToInt32(grdBOMDetail.Rows[i].Cells[7].Value.ToString()) == 1) { //load new purchase price or BOM cost grdBOMDetail.Rows[i].Cells[3].Value = 0.0; grdBOMDetail.Rows[i].Cells[7].Value = 0; string iid = grdBOMDetail.Rows[i].Cells[1].Value.ToString(); iid = iid.Substring(0, iid.IndexOf('-')); double BOMCost = bomdb.getBOMCost(iid); if (BOMCost == 0) { //get purchase price from stock table } else { grdBOMDetail.Rows[i].Cells[3].Value = BOMCost; } //MessageBox.Show("Item changed in this row"); } quantity = Convert.ToDouble(grdBOMDetail.Rows[i].Cells[2].Value); purchaseprice = Convert.ToDouble(grdBOMDetail.Rows[i].Cells[3].Value); customprice = Convert.ToDouble(grdBOMDetail.Rows[i].Cells[4].Value); if (purchaseprice != 0) { cost = Math.Round(quantity * purchaseprice, 2); } else if (customprice != 0) { cost = Math.Round(quantity * customprice, 2); } else { cost = 0; } grdBOMDetail.Rows[i].Cells[5].Value = cost; totalcost = totalcost + cost; } txtCost.Text = totalcost.ToString(); btnCost.Text = txtCost.Text; } catch (Exception) { return(false); } return(status); }
private void btnConfirm_Click(object sender, EventArgs e) { Boolean status = true; try { BOMDB bomdb = new BOMDB(); bomheader bh = new bomheader(); bh = new bomheader(); string iid = cmbProduct.SelectedItem.ToString(); iid = iid.Substring(0, iid.IndexOf('-')); bh.ProductID = iid; bh.Details = txtDetails.Text; bh.Cost = totalcost; bh.status = Main.getStatusCode(cmbStatus.SelectedItem.ToString()); System.Windows.Forms.Button btn = sender as System.Windows.Forms.Button; string btnText = btnSave.Text; if (!validateItems(bh.ProductID)) { return; } if (bomdb.validateBOMHeader(bh)) { if (btnText.Equals("Update")) { if (bomdb.updateBOMHeader(bh)) { if (createAndUpdateBOMDetails(iid)) { MessageBox.Show("BOM Details updated"); closeAllPanels(); ListBOMHeader(); pnlBottomActions.Visible = true; } else { status = false; } } else { status = false; } if (!status) { MessageBox.Show("Failed to update BOM Header"); } } else if (btnText.Equals("Save")) { if (bomdb.insertBOMHeader(bh)) { if (createAndUpdateBOMDetails(iid)) { MessageBox.Show("TBOM Details Added"); closeAllPanels(); ListBOMHeader(); pnlBottomActions.Visible = true; } else { status = false; bomdb.deleteBOMHeader(bh); } } else { status = false; } if (!status) { MessageBox.Show("Failed to Insert BOM Header"); } } } else { MessageBox.Show("BOM Validation failed"); } } catch (Exception) { MessageBox.Show("Failed Adding / Editing BOM"); } }