/// <summary>
        /// Save Function
        /// </summary>
        public void SaveFunction()
        {
            try
            {
                PurchaseOrderMasterInfo infoPurchaseOrderMaster = new PurchaseOrderMasterInfo();
                PurchaseOrderBll BllPurchaseOrder = new  PurchaseOrderBll();
                PurchaseOrderDetailsInfo infoPurchaseOrderDetails = new PurchaseOrderDetailsInfo();

                ProductInfo infoProduct = new ProductInfo();
                ProductCreationBll BllProductCreation = new ProductCreationBll();
                SettingsBll BllSettings = new SettingsBll();
                if (cbxCancel.Checked)
                {
                    infoPurchaseOrderMaster.Cancelled = true;
                }
                else
                {
                    infoPurchaseOrderMaster.Cancelled = false;
                }
                infoPurchaseOrderMaster.Date = Convert.ToDateTime(txtDate.Text);
                infoPurchaseOrderMaster.DueDate = Convert.ToDateTime(txtDueDate.Text);
                infoPurchaseOrderMaster.LedgerId = Convert.ToDecimal(cmbCashOrParty.SelectedValue.ToString());
                if (isAutomatic == true)
                {
                    infoPurchaseOrderMaster.SuffixPrefixId = decPurchaseSuffixPrefixId;
                    infoPurchaseOrderMaster.VoucherNo = strVoucherNo;
                }
                else
                {
                    infoPurchaseOrderMaster.SuffixPrefixId = 0;
                    infoPurchaseOrderMaster.VoucherNo = BllPurchaseOrder.VoucherNoMax(decPurchaseOrderTypeId);
                }
                infoPurchaseOrderMaster.VoucherTypeId = decPurchaseOrderTypeId;
                infoPurchaseOrderMaster.InvoiceNo = txtOrderNo.Text;
                infoPurchaseOrderMaster.UserId = PublicVariables._decCurrentUserId;
                infoPurchaseOrderMaster.EmployeeId = PublicVariables._decCurrentUserId;//by default current userid used as current employeeid
                infoPurchaseOrderMaster.FinancialYearId = PublicVariables._decCurrentFinancialYearId;
                infoPurchaseOrderMaster.Narration = txtNarration.Text.Trim();
                infoPurchaseOrderMaster.TotalAmount = Convert.ToDecimal(txtTotalAmount.Text);
                infoPurchaseOrderMaster.exchangeRateId = Convert.ToDecimal(cmbCurrency.SelectedValue.ToString());
                infoPurchaseOrderMaster.Extra1 = string.Empty;
                infoPurchaseOrderMaster.Extra2 = string.Empty;
                decPurchaseOrderMasterIdentity = Convert.ToDecimal(BllPurchaseOrder.PurchaseOrderMasterAdd(infoPurchaseOrderMaster));
                int inRowcount = dgvPurchaseOrder.Rows.Count;
                for (int inI = 0; inI < inRowcount - 1; inI++)
                {
                    infoPurchaseOrderDetails.PurchaseOrderMasterId = decPurchaseOrderMasterIdentity;
                    if (dgvPurchaseOrder.Rows[inI].Cells["dgvtxtProductCode"].Value != null && dgvPurchaseOrder.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString() != "")
                    {
                        infoProduct = BllProductCreation.ProductViewByCode(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtProductCode"].Value.ToString());
                        infoPurchaseOrderDetails.ProductId = infoProduct.ProductId;
                    }
                    if (dgvPurchaseOrder.Rows[inI].Cells["dgvtxtQty"].Value != null && dgvPurchaseOrder.Rows[inI].Cells["dgvtxtQty"].Value.ToString() != "")
                    {
                        infoPurchaseOrderDetails.Qty = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtQty"].Value.ToString());
                    }
                    if (dgvPurchaseOrder.Rows[inI].Cells["dgvcmbUnit"].Value != null && dgvPurchaseOrder.Rows[inI].Cells["dgvcmbUnit"].Value.ToString() != "")
                    {
                        infoPurchaseOrderDetails.UnitId = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvcmbUnit"].Value);
                        infoPurchaseOrderDetails.UnitConversionId = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtUnitConversionId"].Value.ToString());
                    }
                    infoPurchaseOrderDetails.Rate = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtRate"].Value.ToString());
                    infoPurchaseOrderDetails.Amount = Convert.ToDecimal(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtAmount"].Value.ToString());
                    infoPurchaseOrderDetails.SlNo = Convert.ToInt32(dgvPurchaseOrder.Rows[inI].Cells["dgvtxtSlNo"].Value.ToString());
                    infoPurchaseOrderDetails.Extra1 = string.Empty;
                    infoPurchaseOrderDetails.Extra2 = string.Empty;
                    BllPurchaseOrder.PurchaseOrderDetailsAdd(infoPurchaseOrderDetails);
                }
                Messages.SavedMessage();
                if (cbxPrintAfterSave.Checked)
                {
                    if (BllSettings.SettingsStatusCheck("Printer") == "Dot Matrix")
                    {
                        PrintForDotMatrix(decPurchaseOrderMasterIdentity);
                    }
                    else
                    {
                        Print(decPurchaseOrderMasterIdentity);
                    }
                }
                Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show("PO35:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }