/// <summary>
        /// Save or Edit Function checking invalid entries here
        /// </summary>
        public void SaveOrEdit()
        {
            try
            {
                //DeliveryNoteMasterSP spDeliveryNoteMaster = new DeliveryNoteMasterSP();
                DeliveryNoteBll bllDeliveryNote = new DeliveryNoteBll();
                string strDeliveryModeText = string.Empty;
                cmbDeliveryMode.Text = strDeliveryModeText;
                dgvProduct.ClearSelection();
                int inRow = dgvProduct.RowCount;

                if (txtDeliveryNoteNo.Text.Trim() == string.Empty && decDeliveryNoteMasterId == 0)
                {
                    Messages.InformationMessage("Enter Delivery Note Number");
                    txtDeliveryNoteNo.Focus();
                }
                else if (bllDeliveryNote.DeliveryNotNumberCheckExistence(txtDeliveryNoteNo.Text.Trim(), 0, decDeliveryNoteVoucherTypeId) == true && btnSave.Text == "Save")
                {
                    Messages.InformationMessage("Number already exist");
                    txtDeliveryNoteNo.Focus();
                }
                else if (txtDate.Text.Trim() == string.Empty && decDeliveryNoteMasterId == 0)
                {
                    Messages.InformationMessage("Select a date in between financial year");
                    txtDate.Focus();
                }
                else if (cmbCashOrParty.SelectedValue == null && decDeliveryNoteMasterId == 0)
                {
                    Messages.InformationMessage("Select Cash/Party");
                    cmbCashOrParty.Focus();
                }
                else if (cmbPricingLevel.SelectedValue == null && decDeliveryNoteMasterId == 0)
                {
                    Messages.InformationMessage("Select PricingLevel");
                    cmbPricingLevel.Focus();
                }
                else if (cmbDeliveryMode.Text == null && decDeliveryNoteMasterId == 0)
                {
                    Messages.InformationMessage("Select DeliveryMode");
                    cmbDeliveryMode.Focus();
                }
                else if (cmbDeliveryMode.SelectedIndex != 0 && cmbOrderNo.Text == string.Empty)
                {
                    Messages.InformationMessage("Select OrderNo");
                    cmbOrderNo.Focus();
                }
                else if (cmbSalesMan.SelectedValue == null && decDeliveryNoteMasterId == 0)
                {
                    Messages.InformationMessage("Select Salesman");
                    cmbSalesMan.Focus();
                }
                else if (cmbCurrency.SelectedValue == null && decDeliveryNoteMasterId == 0)
                {
                    Messages.InformationMessage("Select Currency");
                    cmbCurrency.Focus();
                }
                else if (RemoveIncompleteRowsFromGrid())
                {
                    if (dgvProduct.Rows[0].Cells["dgvcmbUnit"].Value == null || dgvProduct.Rows[0].Cells["dgvtxtProductName"].Value == null && dgvProduct.Rows[0].Cells["dgvtxtProductCode"].Value == null)
                    {
                        MessageBox.Show("Can't save Delivery note details without atleast one product with complete details", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        dgvProduct.ClearSelection();
                        dgvProduct.Focus();
                        goto Exit;
                    }
                    else
                    {
                        if (btnSave.Text == "Save")
                        {

                            if (dgvProduct.Rows[0].Cells["dgvtxtProductName"].Value == null || dgvProduct.Rows[0].Cells["dgvtxtQty"].Value == null || dgvProduct.Rows[0].Cells["dgvcmbRack"].Value == null
                                || dgvProduct.Rows[0].Cells["dgvcmbRack"].Value == null || dgvProduct.Rows[0].Cells["dgvtxtAmount"].Value == null ||
                                dgvProduct.Rows[0].Cells["dgvtxtRate"].Value == null || dgvProduct.Rows[0].Cells["dgvcmbGodown"].Value == null)
                            {
                                MessageBox.Show("Can't save Delivery note details without atleast one product with complete details", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                dgvProduct.ClearSelection();
                                dgvProduct.Focus();
                                goto Exit;
                            }

                            if (PublicVariables.isMessageAdd)
                            {
                                if (Messages.SaveMessage())
                                {
                                    SaveFunction();
                                }
                            }
                            else
                            {
                                SaveFunction();
                            }
                        }
                        else if (btnSave.Text == "Update")
                        {
                            if (dgvProduct.Rows[0].Cells["dgvtxtProductName"].Value == null || dgvProduct.Rows[0].Cells["dgvtxtQty"].Value == null || dgvProduct.Rows[0].Cells["dgvcmbRack"].Value == null
                               || dgvProduct.Rows[0].Cells["dgvcmbUnit"].Value == null || dgvProduct.Rows[0].Cells["dgvcmbRack"].Value == null || dgvProduct.Rows[0].Cells["dgvtxtAmount"].Value == null ||
                               dgvProduct.Rows[0].Cells["dgvtxtRate"].Value == null)
                            {
                                MessageBox.Show("Can't save Delivery note details without atleast one product with complete details", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                dgvProduct.ClearSelection();
                                dgvProduct.Focus();
                                goto Exit;
                            }
                            if (PublicVariables.isMessageEdit)
                            {
                                if (Messages.UpdateMessage())
                                {
                                    SaveFunction();
                                }
                            }
                            else
                            {
                                SaveFunction();
                            }
                        }
                    }
                }
            Exit: ;
            }
            catch (Exception ex)
            {
                MessageBox.Show("DN39:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }