/// <summary>
 /// Function for call from productRegister
 /// </summary>
 public void CallFromProductRegister(decimal decId, frmProductRegister frmProRegister)
 {
     try
     {
         base.Show();
         this.frmProductRegisterObj = frmProRegister;
         frmProductRegisterObj.Enabled = false;
         ProductCreationBll BllProductCreation = new ProductCreationBll();
         ProductInfo infoProduct = new ProductInfo();
         StockPostingInfo infoStockPosting = new StockPostingInfo();
         BatchInfo infoBatch = new BatchInfo();
         StockPostingBll BllStockPosting = new StockPostingBll();
         BatchBll BllBatch = new BatchBll();
         UnitBll bllUnit = new UnitBll();
         List<DataTable> ListObj = new List<DataTable>();
         decProductIdForEdit = decId;
         infoProduct = BllProductCreation.ProductView(decId);
         strUnitNameForGrid = bllUnit.UnitName(infoProduct.UnitId);
         btnSave.Text = "Update";
         btnDelete.Enabled = true;
         txtName.Text = infoProduct.ProductName;
         txtProductCode.Text = infoProduct.ProductCode;
         cmbGroup.SelectedValue = infoProduct.GroupId;
         cmbBrand.SelectedValue = infoProduct.BrandId;
         cmbUnit.SelectedValue = infoProduct.UnitId;
         if (BllProductCreation.ProductReferenceCheck(decId))
         {
             cmbUnit.Enabled = false;
         }
         decUnitIdForUpdate = infoProduct.UnitId;
         cmbSize.SelectedValue = infoProduct.SizeId;
         cmbModalNo.SelectedValue = infoProduct.ModelNoId;
         cmbTax.SelectedValue = infoProduct.TaxId;
         cmbTaxApplicableOn.SelectedItem = infoProduct.TaxapplicableOn;
         txtPurchaseRate.Text = infoProduct.PurchaseRate.ToString();
         txtSalesRate.Text = infoProduct.SalesRate.ToString();
         txtMrp.Text = infoProduct.Mrp.ToString();
         txtMinimumStock.Text = infoProduct.MinimumStock.ToString();
         txtMaximumStock.Text = infoProduct.MaximumStock.ToString();
         txtReorderLevel.Text = infoProduct.ReorderLevel.ToString();
         txtPartNo.Text = infoProduct.PartNo;
         cmbDefaultGodown.SelectedValue = infoProduct.GodownId;
         cmbDefaultRack.SelectedValue = infoProduct.RackId;
         if (infoProduct.IsBom)
         {
             cmbBom.SelectedIndex = 1;
             isBomFromRegister = true;
         }
         if (infoProduct.Ismultipleunit)
         {
             cmbMultipleUnit.SelectedIndex = 1;
             isMulUnitFromRgister = true;
         }
         if (infoProduct.Isopeningstock)
         {
             isOpeningStockForUpdate = true;
             OpeningStockGridFill();
         }
         if (infoProduct.IsallowBatch)
         {
             OpeningStockGridWithBathFill();
         }
         else
         {
             cmbAllowBatch.SelectedIndex = 0;
             txtPartNo.Text = BllBatch.PartNoReturn(decProductIdForEdit);
         }
         if (infoProduct.Ismultipleunit)
         {
             cmbMultipleUnit.SelectedIndex = 1;
         }
         else
         {
             cmbMultipleUnit.SelectedIndex = 0;
         }
         if (infoProduct.IsBom)
         {
             cmbBom.SelectedIndex = 1;
         }
         else
         {
             cmbBom.SelectedIndex = 0;
         }
         if (infoProduct.Isopeningstock)
         {
             cmbOpeningStock.SelectedIndex = 1;
         }
         else
         {
             cmbOpeningStock.SelectedIndex = 0;
         }
         if (infoProduct.IsActive)
         {
             cbxActive.Checked = true;
         }
         else
         {
             cbxActive.Checked = false;
         }
         if (infoProduct.IsshowRemember)
         {
             cbxReminder.Checked = true;
         }
         else
         {
             cbxReminder.Checked = false;
         }
         txtNarration.Text = infoProduct.Narration;
     }
     catch (Exception ex)
     {
         MessageBox.Show("PC:63" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Work on cmbUnit Cell Leave
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cmbUnit_Leave(object sender, EventArgs e)
 {
     try
     {
         UnitBll bllUnit = new UnitBll();
         List<DataTable> ListObj = new List<DataTable>();
         decId = Convert.ToDecimal(cmbUnit.SelectedValue);
         strUnitNameForGrid = bllUnit.UnitName(decId);
         isSaveMulUnitCheck = false;
         if (dtblMulUnit != null)
         {
             dtblMulUnit.Clear();
         }
         if (dtblForUnitIdInOpeNingStock != null)
         {
             dtblForUnitIdInOpeNingStock.Clear();
         }
         if (dtblFromMulUnitForUpdate != null)
         {
             dtblFromMulUnitForUpdate.Clear();
         }
         if (btnSave.Text == "Update")
         {
             cmbMultipleUnit.SelectedIndex = 0;
             isMulUnitFromRgister = false;
             isCheck = true;
         }
         if (dgvProductCreation.Rows.Count != 0)
         {
             for (int inI = 0; inI <= dgvProductCreation.Rows.Count - 1; inI++)
             {
                 dgvProductCreation.Rows[inI].Cells["dgvtxtunit"].Value = strUnitNameForGrid;
                 DefaultUnitFillingInProductGrid();
             }
         }
         else
         {
             dgvProductCreation.Rows[0].Cells["dgvtxtunit"].Value = strUnitNameForGrid;
             DefaultUnitFillingInProductGrid();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PC:106" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
 /// <summary>
 /// Work on cmbOpeningStock Leave event
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cmbOpeningStock_Leave(object sender, EventArgs e)
 {
     try
     {
         if (cmbOpeningStock.SelectedIndex == 1)
         {
             if (cmbUnit.SelectedIndex == -1)
             {
                 Messages.InformationMessage("Select default unit");
                 cmbOpeningStock.SelectedIndex = 0;
                 cmbUnit.Focus();
             }
             if (!isstockPostingGridFil)
             {
                 if (isOpeningStockForUpdate)
                 {
                     OpeningStockGridFill();
                 }
                 if (isBatchForUpdate)
                 {
                     OpeningStockGridWithBathFill();
                 }
             }
             else
             {
                 if (!isGridHasToClear)
                 {
                     dgvProductCreation.Rows.Clear();
                     isOpeningStockChanged = true;
                 }
             }
             if (cmbMultipleUnit.SelectedIndex == 1 && dtblForUnitIdInOpeNingStock != null && dtblForUnitIdInOpeNingStock.Rows.Count > 0)
             {
                 UnitBll bllUnit = new UnitBll();
                 List<DataTable> ListObj = new List<DataTable>();
                 decId = Convert.ToDecimal(cmbUnit.SelectedValue);
                 strUnitNameForGrid = bllUnit.UnitName(decId);
                 DataRow dr = dtblForUnitIdInOpeNingStock.NewRow();
                 dr["dgvtxtUnitId"] = decId;
                 dr["unitName"] = strUnitNameForGrid;
                 dr["CnvertionRate"] = 0;
                 dr["quantities"] = 0;
                 dr["extra1"] = string.Empty;
                 dr["extra2"] = string.Empty;
                 dr["extraDate"] = DateTime.Now;
                 dtblForUnitIdInOpeNingStock.Rows.InsertAt(dr, (dtblForUnitIdInOpeNingStock.Rows.Count + 1));
                 dgvcmbUnit.DataSource = dtblForUnitIdInOpeNingStock;
                 dgvcmbUnit.DisplayMember = "unitName";
                 dgvcmbUnit.ValueMember = "dgvtxtunitId";
                 for (int i = 0; i < dgvProductCreation.Rows.Count; i++)
                 {
                     if (!dgvProductCreation.Rows[i].IsNewRow)
                     {
                         dgvProductCreation.Rows[i].Cells["dgvcmbUnit"].Value = dtblForUnitIdInOpeNingStock.Rows[0][1];
                     }
                 }
             }
             else if (decId != 0)
             {
                 DefaultUnitFillingInProductGrid();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PC:115" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        /// <summary>
        /// To work on cmbMultipleUnit cell leave
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmbMultipleUnit_Leave(object sender, EventArgs e)
        {
            try
            {
                if (cmbMultipleUnit.SelectedIndex == 1)
                {
                    UnitBll bllUnit = new UnitBll();
                    strProductName = txtName.Text.Trim();
                    decimal decUnitId = Convert.ToDecimal(cmbUnit.SelectedValue);
                    string strUnit = bllUnit.UnitName(Convert.ToDecimal(cmbUnit.SelectedValue));
                    frmProductMultipleUnit frmMultipleUnitObj = new frmProductMultipleUnit();
                    frmMultipleUnitObj.MdiParent = formMDI.MDIObj;
                    frmProductMultipleUnit open = Application.OpenForms["frmProductMultipleUnit"] as frmProductMultipleUnit;
                    if (open == null)
                    {
                        if (isMulUnitFromRgister && btnSave.Text == "Update")
                        {
                            if (!isCheck)
                            {
                                MultipleUnitTableForUpdate();
                                frmMultipleUnitObj.CallFromProdutCreationForUpadte(this, strProductName, decProductIdForEdit, dtblMulUnitForEdit, strUnitNameForGrid, decUnitIdForUpdate);
                                isGridHasToClear = true;
                            }
                            else
                            {
                                if (strProductName != string.Empty)
                                {
                                    if (cmbUnit.SelectedIndex != -1)
                                    {
                                        if (isSaveMulUnitCheck && (decUnitId == decUnitIdSelectedWhenMulUntCalled))
                                        {
                                            frmMultipleUnitObj.CallFromProdutCreationAgain(this, strProductName, decUnitId, strUnit, dtblMulUnit);

                                        }
                                        else
                                        {
                                            frmMultipleUnitObj.CallFromProdutCreation(this, strProductName, decUnitId, strUnit);

                                        }
                                    }
                                    else
                                    {
                                        Messages.InformationMessage("Select default unit");
                                        cmbMultipleUnit.SelectedIndex = 0;
                                        cmbUnit.Focus();
                                    }
                                }
                                else
                                {
                                    Messages.InformationMessage("Enter product name");
                                    cmbMultipleUnit.SelectedIndex = 0;
                                    txtName.Focus();
                                }
                            }
                        }
                        else
                        {
                            if (strProductName != string.Empty)
                            {
                                if (cmbUnit.SelectedIndex != -1)
                                {
                                    if (isSaveMulUnitCheck && (decUnitId == decUnitIdSelectedWhenMulUntCalled))
                                    {
                                        frmMultipleUnitObj.CallFromProdutCreationAgain(this, strProductName, decUnitId, strUnit, dtblMulUnit);

                                    }
                                    else
                                    {
                                        frmMultipleUnitObj.CallFromProdutCreation(this, strProductName, decUnitId, strUnit);

                                    }
                                }
                                else
                                {
                                    Messages.InformationMessage("Select default unit");
                                    cmbMultipleUnit.SelectedIndex = 0;
                                    cmbUnit.Focus();
                                }
                            }
                            else
                            {
                                Messages.InformationMessage("Enter product name");
                                cmbMultipleUnit.SelectedIndex = 0;
                                txtName.Focus();
                            }
                        }
                    }
                    else if (open != null)
                    {
                        if (open.WindowState == FormWindowState.Minimized)
                        {
                            open.WindowState = FormWindowState.Normal;
                        }
                    }
                    if (dtblForUnitIdInOpeNingStock != null && dtblForUnitIdInOpeNingStock.Rows.Count > 0)
                    {
                        dgvcmbUnit.DataSource = dtblForUnitIdInOpeNingStock;
                        dgvcmbUnit.DisplayMember = "unitName";
                        dgvcmbUnit.ValueMember = "dgvtxtunitId";
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("PC:103" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
 /// <summary>
 /// Function to fill default Unit
 /// </summary>
 public void DefaultUnitFillingInProductGrid()
 {
     UnitBll bllUnit = new UnitBll();
     DataTable dtbl = new DataTable();
     string strName = bllUnit.UnitName(decId);
     dtbl.Columns.Add("UnitName", typeof(string));
     dtbl.Columns.Add("UnitId", typeof(decimal));
     if (btnSave.Text == "Update")
     {
         strName = bllUnit.UnitName(Convert.ToDecimal(cmbUnit.SelectedValue));
         decId = Convert.ToDecimal(cmbUnit.SelectedValue);
     }
     DataRow dr = dtbl.NewRow();
     dr["UnitName"] = strName;
     dr["UnitId"] = decId;
     dtbl.Rows.Add(dr);
     DataRow drow = dtbl.NewRow();
     drow["UnitName"] = string.Empty;
     drow["UnitId"] = 0;
     dtbl.Rows.InsertAt(drow, 0);
     dgvcmbUnit.DataSource = dtbl;
     dgvcmbUnit.DisplayMember = "UnitName";
     dgvcmbUnit.ValueMember = "UnitId";
     for (int i = 0; i < dgvProductCreation.Rows.Count; i++)
     {
         if (!dgvProductCreation.Rows[i].IsNewRow)
         {
             dgvProductCreation.Rows[i].Cells["dgvcmbUnit"].Value = decId;
         }
     }
 }
 /// <summary>
 /// On cell end edit of dgvMultipleUnit
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dgvMultipleUnit_CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (dgvMultipleUnit.Columns[e.ColumnIndex].Name == "dgvcmbmultipleunit")
         {
             UnitBll bllUnit = new UnitBll();
             dgvMultipleUnit.Rows[e.RowIndex].Cells["dgvtxtunitname"].Value = bllUnit.UnitName(Convert.ToDecimal(dgvMultipleUnit.Rows[e.RowIndex].Cells["dgvcmbmultipleunit"].Value));
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("PMU:30" + ex.Message, "Open Miracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }