private void cmbBasicProductCode_SelectedIndexChanged(object sender, EventArgs e) { txtPackType.Visible = false; lblPackType.Visible = false; txtBasicProduct.Visible = false; txtBasicQty.Visible = false; lblBasic.Visible = false; lblBasicQty.Visible = false; txtBasicProduct.Text = ""; txtBasicQty.Text = ""; txtCatergory.Text = ""; txtPackType.Text = ""; txtProductCode.Text = ""; txtProductName.Text = ""; txtProductType.Text = ""; txtProductUnit.Text = ""; txtSubCatergory.Text = ""; txtFinishProductQty.Text = "0.00"; txtBasicProductQty.Text = "0.00"; txtMaterialQty.Text = "0.00"; cmbFinishPart.SelectedIndex = -1; cmbBasicPart.SelectedIndex = -1; cmbMaterialPart.SelectedIndex = -1; try { if (cmbProductCode.Items.Count > 0 && cmbProductCode.SelectedItem != null) { if (cmbProductType.SelectedIndex == 0) { objBasicProduct = objBasicProductDL.Get(cmbProductCode.SelectedValue.ToString()); txtCatergory.Text = objBasicProduct.BasicProductCategory.Category; txtProductCode.Text = objBasicProduct.BasicProductCode; txtProductName.Text = objBasicProduct.BasicProductDescription; txtProductType.Text = objBasicProduct.BasicProductType; txtProductUnit.Text = objBasicProduct.BasicProductUnit.UnitCode; txtSubCatergory.Text = objBasicProduct.BasicProductSubCategory.Category; objFormula = objBasicProduct.BasicProductFormula; if (objBasicProduct.BasicProductFormula.FormulaID == 0) { objFormula.FormulaInstructedBy = CurrentUser.UserEmp; objFormula.FormulaInstructedDate = DateTime.Now; objFormula.FormulaQty = 1000; objFormula.FormulaUnit = objBasicProduct.BasicProductUnit; long formulaID = objFormulaDL.Add(objFormula); if (formulaID > 0) { objFormula.FormulaID = formulaID; objBasicProduct.BasicProductFormula = objFormula; objBasicProductDL.Update(objBasicProduct, objBasicProduct.BasicProductCode); } else { MessageBox.Show(this, "There are was an error occured while initializing the Formula, Please Try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } bindItemList.DataSource = objFormulaDL.GetDataView_Items(objBasicProduct.BasicProductFormula.FormulaID); } else if (cmbProductType.SelectedIndex == 1) { objBasicProduct = objBasicProductDL.Get(cmbProductCode.SelectedValue.ToString()); txtCatergory.Text = objBasicProduct.BasicProductCategory.Category; txtProductCode.Text = objBasicProduct.BasicProductCode; txtProductName.Text = objBasicProduct.BasicProductDescription; txtProductType.Text = objBasicProduct.BasicProductType; txtProductUnit.Text = objBasicProduct.BasicProductUnit.UnitCode; txtSubCatergory.Text = objBasicProduct.BasicProductSubCategory.Category; objFormula = objBasicProduct.BasicProductFormula; if (objBasicProduct.BasicProductFormula.FormulaID == 0) { objFormula.FormulaInstructedBy = CurrentUser.UserEmp; objFormula.FormulaInstructedDate = DateTime.Now; objFormula.FormulaQty = 1000; objFormula.FormulaUnit = objBasicProduct.BasicProductUnit; long formulaID = objFormulaDL.Add(objFormula); if (formulaID > 0) { objFormula.FormulaID = formulaID; objBasicProduct.BasicProductFormula = objFormula; objBasicProductDL.Update(objBasicProduct, objBasicProduct.BasicProductCode); } else { MessageBox.Show(this, "There are was an error occured while initializing the Formula, Please Try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } bindItemList.DataSource = objFormulaDL.GetDataView_Items(objBasicProduct.BasicProductFormula.FormulaID); } else if (cmbProductType.SelectedIndex == 2) { objFinishProduct = objFinishProductDL.Get(cmbProductCode.SelectedValue.ToString()); txtPackType.Visible = true; lblPackType.Visible = true; txtBasicProduct.Visible = true; txtBasicQty.Visible = true; lblBasic.Visible = true; lblBasicQty.Visible = true; txtCatergory.Text = objFinishProduct.BasicProduct.BasicProductCategory.Category; txtPackType.Text = objFinishProduct.FinishProductPackingType.PackingTitle; txtProductCode.Text = objFinishProduct.FinishProductCode; txtProductName.Text = objFinishProduct.FinishProductDescription; txtProductType.Text = "Finish"; txtProductUnit.Text = "N/A"; txtBasicProduct.Text = objFinishProduct.BasicProduct.Code; txtBasicQty.Text = objFinishProduct.BasicProductQty.ToString(); txtSubCatergory.Text = objFinishProduct.BasicProduct.BasicProductSubCategory.Category; objFormula = objFinishProduct.FinishProductFormula; if (objFormula.FormulaID == 0) { objFormula.FormulaInstructedBy = CurrentUser.UserEmp; objFormula.FormulaInstructedDate = DateTime.Now; objFormula.FormulaQty = 1000; long formulaID = objFormulaDL.Add_FG(objFormula); if (formulaID > 0) { objFormula.FormulaID = formulaID; objFinishProduct.FinishProductFormula = objFormula; objFinishProductDL.Update(objFinishProduct, objFinishProduct.FinishProductCode); } else { MessageBox.Show(this, "There are was an error occured while initializing the Formula, Please Try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); } } bindItemList.DataSource = objFormulaDL.GetDataView_Items(objFinishProduct.FinishProductFormula.FormulaID); } bindBasicProduct.DataSource = objFormulaBasicProductDL.GetDataView_FormulaID(objFormula.FormulaID); bindFinishProduct.DataSource = objFormulaFinishProductDL.GetDataView_FormulaID(objFormula.FormulaID); bindMaterialList.DataSource = objFormulaMaterialDL.GetDataView_FormulaID(objFormula.FormulaID); } else { } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }