/// <summary>
 /// Function to use the SaveItems to table
 /// </summary>
 public void SaveFunction()
 {
     try
     {
         decimal decSalesOrderSuffixPrefixId = 0;
         SalesOrderDetailsInfo infoSalesOrderDetails = new SalesOrderDetailsInfo();
         SalesOrderMasterInfo infoSalesOrderMaster = new SalesOrderMasterInfo();
         SalesOrderBll bllSalesOrder = new SalesOrderBll();
         SalesOrderBll bllSalesOrderMaster = new SalesOrderBll();
         infoSalesOrderMaster.Cancelled = false;
         infoSalesOrderMaster.Date = Convert.ToDateTime(txtDate.Text);
         infoSalesOrderMaster.DueDate = Convert.ToDateTime(txtDueDate.Text);
         infoSalesOrderMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
         if (isAutomatic)
         {
             infoSalesOrderMaster.SuffixPrefixId = decSalesOrderSuffixPrefixId;
             infoSalesOrderMaster.VoucherNo = strVoucherNo;
         }
         else
         {
             infoSalesOrderMaster.SuffixPrefixId = 0;
             infoSalesOrderMaster.VoucherNo = bllSalesOrderMaster.VoucherNoMax(decSalesOrderTypeId);
         }
         infoSalesOrderMaster.VoucherTypeId = decSalesOrderTypeId;
         infoSalesOrderMaster.InvoiceNo = txtOrderNo.Text;
         infoSalesOrderMaster.UserId = PublicVariables._decCurrentUserId;
         if (cmbSalesMan.SelectedIndex == -1)
         {
             infoSalesOrderMaster.SalesOrderMasterId = 0;
         }
         else
         {
             infoSalesOrderMaster.EmployeeId = Convert.ToDecimal(cmbSalesMan.SelectedValue.ToString());
         }
         infoSalesOrderMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
         if (cmbPricingLevel.SelectedIndex == -1)
         {
             infoSalesOrderMaster.PricinglevelId = 0;
         }
         else
         {
             infoSalesOrderMaster.PricinglevelId = Convert.ToDecimal(cmbPricingLevel.SelectedValue.ToString());
         }
         infoSalesOrderMaster.Narration = txtNarration.Text.Trim();
         if (cmbQuotationNo.SelectedIndex == -1)
         {
             infoSalesOrderMaster.QuotationMasterId = 0;
         }
         else
         {
             infoSalesOrderMaster.QuotationMasterId = Convert.ToDecimal(cmbQuotationNo.SelectedValue.ToString());
         }
         infoSalesOrderMaster.ExchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
         infoSalesOrderMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text);
         infoSalesOrderMaster.Extra1 = string.Empty;
         infoSalesOrderMaster.Extra2 = string.Empty;
         decSalesOrderMasterIdentity = Convert.ToDecimal(bllSalesOrderMaster.SalesOrderMasterAdd(infoSalesOrderMaster));
         int inRowcount = dgvSalesOrder.Rows.Count;
         for (int inI = 0; inI < inRowcount - 1; inI++)
         {
             infoSalesOrderDetails.SalesOrderMasterId = decSalesOrderMasterIdentity;
             if (dgvSalesOrder.Rows[inI].Cells["dgvtxtProductCode"].Value != null && dgvSalesOrder.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString() != "")
             {
                 infoProduct = new ProductCreationBll().ProductViewByCode(dgvSalesOrder.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString());
                 infoSalesOrderDetails.ProductId = infoProduct.ProductId;
             }
             if (dgvSalesOrder.Rows[inI].Cells["dgvtxtQty"].Value != null && dgvSalesOrder.Rows[inI].Cells["dgvtxtQty"].Value.ToString() != "")
             {
                 infoSalesOrderDetails.Qty = Convert.ToDecimal(dgvSalesOrder.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
             }
             if (dgvSalesOrder.Rows[inI].Cells["dgvcmbUnit"].Value != null && dgvSalesOrder.Rows[inI].Cells["dgvcmbUnit"].Value.ToString() != "")
             {
                 infoSalesOrderDetails.UnitId = Convert.ToDecimal(dgvSalesOrder.Rows[inI].Cells["dgvcmbUnit"].Value.ToString());
                 infoSalesOrderDetails.UnitConversionId = decConversionId;
             }
             if (dgvSalesOrder.Rows[inI].Cells["dgvtxtUnitConversionId"].Value != null && dgvSalesOrder.Rows[inI].Cells["dgvtxtUnitConversionId"].Value.ToString() != "")
             {
                 infoSalesOrderDetails.UnitConversionId = Convert.ToDecimal(dgvSalesOrder.Rows[inI].Cells["dgvtxtUnitConversionId"].Value.ToString());
             }
             if (dgvSalesOrder.Rows[inI].Cells["dgvcmbBatch"].Value != null && dgvSalesOrder.Rows[inI].Cells["dgvcmbBatch"].Value.ToString() != string.Empty)
             {
                 infoSalesOrderDetails.BatchId = Convert.ToDecimal(dgvSalesOrder.Rows[inI].Cells["dgvcmbBatch"].Value.ToString());
             }
             if (dgvSalesOrder.Rows[inI].Cells["dgvtxtSalesQuotationDetailsId"].Value == null || dgvSalesOrder.Rows[inI].Cells["dgvtxtSalesQuotationDetailsId"].Value.ToString() == "")
             {
                 infoSalesOrderDetails.QuotationDetailsId = Convert.ToDecimal(0);
             }
             else
             {
                 infoSalesOrderDetails.QuotationDetailsId = Convert.ToDecimal(dgvSalesOrder.Rows[inI].Cells["dgvtxtSalesQuotationDetailsId"].Value);
             }
             infoSalesOrderDetails.Rate = Convert.ToDecimal(dgvSalesOrder.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
             infoSalesOrderDetails.Amount = Convert.ToDecimal(dgvSalesOrder.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
             infoSalesOrderDetails.SlNo = Convert.ToInt32(dgvSalesOrder.Rows[inI].Cells["dgvtxtSlNo"].Value.ToString());
             infoSalesOrderDetails.UnitConversionId = Convert.ToDecimal(dgvSalesOrder.Rows[inI].Cells["dgvtxtUnitConversionId"].Value.ToString());
             infoSalesOrderDetails.Extra1 = string.Empty;
             infoSalesOrderDetails.Extra2 = string.Empty;
             bllSalesOrder.SalesOrderDetailsAdd(infoSalesOrderDetails);
         }
         Messages.SavedMessage();
         if (cbxPrintAfterSave.Checked == true)
         {
             if (new SettingsBll().SettingsStatusCheck("Printer") == "Dot Matrix")
             {
                 PrintForDotMatrix(decSalesOrderMasterIdentity);
             }
             else
             {
                 Print(decSalesOrderMasterIdentity);
             }
         }
         Clear();
     }
     catch (Exception ex)
     {
         MessageBox.Show("SO46:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }