protected void btnconfirm_Click(object sender, EventArgs e)
    {
        try
        {
            BLL_VET_Index objIndex = new BLL_VET_Index();
            string        sPath    = Server.MapPath("\\" + System.Configuration.ConfigurationManager.AppSettings["APP_NAME"].ToString() + "\\uploads\\Vetting\\ImportedObservation\\");

            DataSet ds = new DataSet();

            ds.ReadXml(sPath + ViewState["AttachPath"].ToString());
            ImportObservation objImportObs = new ImportObservation();

            if (string.IsNullOrWhiteSpace(objImportObs.SaveImportObservation(ds, ddlQuestionaire.SelectedValue, Convert.ToInt32(ViewState["Vetting_ID"]))))
            {
                objIndex.VET_Ins_AttatmentImport(Convert.ToInt32(ViewState["Vetting_ID"]), Path.GetFileName(FileUpXMLReport.PostedFile.FileName), AttachPath, GetSessionUserID());
                objIndex.VET_Upd_PerformVettingDetails(UDFLib.ConvertToInteger(ViewState["Vetting_ID"].ToString()), txtVettingName.Text, UDFLib.ConvertToDate(txtDate.Text), UDFLib.ConvertToInteger(ddlType.SelectedValue), ddlType.SelectedItem.Text, UDFLib.ConvertToInteger(ddlInspector.SelectedValue), UDFLib.ConvertIntegerToNull(ddlOilMajor.SelectedValue), UDFLib.ConvertToInteger(ddlPort.SelectedValues.Rows[0][0]), UDFLib.ConvertIntegerToNull(hdfPorCallID.Value), UDFLib.ConvertToInteger(txtDays.Text), UDFLib.ConvertToDate(txtResponseDate.Text), GetSessionUserID());
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert1", "alert('Perform Vetting saved successfully');", true);
                ClearFields();
                Session["VET_ImportDataset" + GUIDSession.Value.ToString()] = null;
                string js = "parent.UpdatePageAfterSave(" + ViewState["Vetting_ID"].ToString() + ");";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "js", js, true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert1", "alert('Invalid file.');", true);
            }
        }
        catch (Exception ex)
        {
            UDFLib.WriteExceptionLog(ex);
        }
    }
    protected void btnCreatVetting_Click(object sender, EventArgs e)
    {
        try
        {
            BLL_VET_Index objIndex  = new BLL_VET_Index();
            int           ddlportID = 0;


            if (ddlPort.SelectedValues.Rows.Count > 0)
            {
                if (ddlPort.SelectedValues.Rows.Count > 1)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script1", "alert('Please select only one port.');", true);
                    return;
                }
                else
                {
                    ddlportID = UDFLib.ConvertToInteger(ddlPort.SelectedValues.Rows[0][0]);
                }
            }

            if (ViewState["Vetting_ID"] != null)
            {
                if (txtResponseDate.Text != "")
                {
                    if (UDFLib.ConvertToDate(txtResponseDate.Text) < UDFLib.ConvertToDate(txtDate.Text))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "alert1", "alert('Response-Next due date is can not be less than vetting date.');", true);
                        return;
                    }
                }

                DataTable dtVetting = objIndex.VET_Get_ExistVetting(UDFLib.ConvertToInteger(ddlVessel.SelectedValue), UDFLib.ConvertToDate(txtDate.Text), UDFLib.ConvertToInteger(ddlType.SelectedValue), UDFLib.ConvertToInteger(ViewState["Vetting_ID"].ToString()));
                if (dtVetting.Rows.Count > 0)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "jsSqlError3", "alert('Vetting already exists with same vessel,same type and same date.');", true);
                    return;
                }
                else
                {
                    if (FileUpXMLReport.HasFile)
                    {
                        int Vetting_ID = Convert.ToInt32(ViewState["Vetting_ID"]);

                        int IsDataInValid = 0;
                        int IsObsExists   = 0;
                        var FileExtension = "." + Path.GetExtension(FileUpXMLReport.PostedFile.FileName).Substring(1);
                        if (FileExtension != ".xml")
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "alert1", "alert('File type should be only xml.');", true);
                        }
                        else
                        {
                            DataSet   ds    = new DataSet();
                            DataTable dt    = new DataTable();
                            string    sPath = Server.MapPath("\\" + System.Configuration.ConfigurationManager.AppSettings["APP_NAME"].ToString() + "\\uploads\\Vetting\\ImportedObservation\\");

                            if (!Directory.Exists(Server.MapPath("~/uploads/Vetting/ImportedObservation")))
                            {
                                Directory.CreateDirectory(Server.MapPath("~/uploads/Vetting/ImportedObservation"));
                            }

                            Guid   GUID       = Guid.NewGuid();
                            string AttachPath = "VET_ImportObs" + GUID.ToString() + FileExtension;
                            ViewState["AttachPath"] = AttachPath;
                            FileUpXMLReport.SaveAs(sPath + AttachPath);
                            ds.ReadXml(sPath + AttachPath);
                            Session["VET_ImportDataset" + GUIDSession.Value.ToString()] = ds;
                            if (ds.Tables.Count > 0)
                            {
                                ImportObservation objImportObs = new ImportObservation();
                                if (string.IsNullOrWhiteSpace(objImportObs.ImportValidation(ds, Vetting_ID)))
                                {
                                    Dictionary <string, string> objDicResult = objImportObs.ImportValueValidation(ds, ddlQuestionaire.SelectedValue, ddlVessel.SelectedItem.Text, ddlPort.SelectedTexts.Rows[0]["SelectedText"].ToString(), txtDate.Text, Vetting_ID, ref IsDataInValid, ref IsObsExists);
                                    if (objDicResult.Keys.Contains("QUESTIONNAIRE"))
                                    {
                                        ScriptManager.RegisterStartupScript(this, this.GetType(), "alert1", "alert('" + objDicResult["QUESTIONNAIRE"] + "');", true);
                                    }
                                    else if (string.IsNullOrWhiteSpace(objDicResult["ERRORMESSAGE"]))
                                    {
                                        if (IsDataInValid == 0 && IsObsExists == 0)
                                        {
                                            if (string.IsNullOrWhiteSpace(objImportObs.SaveImportObservation(ds, ddlQuestionaire.SelectedValue, Vetting_ID)))
                                            {
                                                objIndex.VET_Ins_AttatmentImport(Vetting_ID, Path.GetFileName(FileUpXMLReport.PostedFile.FileName), AttachPath, GetSessionUserID());
                                                objIndex.VET_Upd_PerformVettingDetails(UDFLib.ConvertToInteger(ViewState["Vetting_ID"].ToString()), txtVettingName.Text, UDFLib.ConvertToDate(txtDate.Text), UDFLib.ConvertToInteger(ddlType.SelectedValue), ddlType.SelectedItem.Text, UDFLib.ConvertToInteger(ddlInspector.SelectedValue), UDFLib.ConvertToInteger(ddlOilMajor.SelectedValue), UDFLib.ConvertToInteger(ddlPort.SelectedValues.Rows[0][0]), UDFLib.ConvertIntegerToNull(hdfPorCallID.Value), UDFLib.ConvertToInteger(txtDays.Text), UDFLib.ConvertToDate(txtResponseDate.Text), GetSessionUserID());
                                                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert1", "alert('Perform Vetting saved successfully');", true);
                                                ClearFields();
                                                Session["VET_ImportDataset" + GUIDSession.Value.ToString()] = null;
                                                string js = "parent.UpdatePageAfterSave(" + ViewState["Vetting_ID"].ToString() + ");";
                                                ScriptManager.RegisterStartupScript(this, this.GetType(), "js", js, true);
                                            }
                                            else
                                            {
                                                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert1", "alert('Error while importing.');", true);
                                            }
                                        }
                                        else
                                        {
                                            ScriptManager.RegisterStartupScript(this, typeof(Page), "Confirm", "ImportConfirm(" + IsDataInValid + "," + IsObsExists + ",'" + ddlVessel.SelectedItem.Text + "','" + ddlPort.SelectedTexts.Rows[0]["SelectedText"].ToString() + "','" + txtDate.Text + "');", true);
                                        }
                                    }
                                    else
                                    {
                                        ScriptManager.RegisterStartupScript(this, this.GetType(), "alert1", "alert('Invalid file.');", true);
                                    }
                                }
                                else
                                {
                                    ScriptManager.RegisterStartupScript(this, this.GetType(), "alert1", "alert('Invalid file.');", true);
                                }
                            }
                        }
                    }
                    else
                    {
                        objIndex.VET_Upd_PerformVettingDetails(UDFLib.ConvertToInteger(ViewState["Vetting_ID"].ToString()), txtVettingName.Text, UDFLib.ConvertToDate(txtDate.Text), UDFLib.ConvertToInteger(ddlType.SelectedValue), ddlType.SelectedItem.Text, UDFLib.ConvertToInteger(ddlInspector.SelectedValue), UDFLib.ConvertIntegerToNull(ddlOilMajor.SelectedValue), ddlportID, UDFLib.ConvertIntegerToNull(hdfPorCallID.Value), UDFLib.ConvertToInteger(txtDays.Text), UDFLib.ConvertDateToNull(txtResponseDate.Text), GetSessionUserID());
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "alert1", "alert('Perform Vetting saved successfully');", true);
                        ClearFields();
                        string js = "parent.UpdatePageAfterSave(" + ViewState["Vetting_ID"].ToString() + ");";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "js", js, true);
                    }
                }
                //}
            }
            else
            {
                DataTable dtVetting = objIndex.VET_Get_ExistVetting(UDFLib.ConvertToInteger(ddlVessel.SelectedValue), UDFLib.ConvertToDate(txtDate.Text), UDFLib.ConvertToInteger(ddlType.SelectedValue), null);
                if (dtVetting.Rows.Count > 0)
                {
                    string jsSqlError3 = "alert('Vetting already exists with same vessel,same type and same date.');";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "jsSqlError3", jsSqlError3, true);
                }
                else
                {
                    int Vetting_ID  = 0;
                    int ReturnValue = 0;
                    Vetting_ID = objIndex.VET_Ins_Vetting(UDFLib.ConvertToInteger(ddlVessel.SelectedValue), UDFLib.ConvertToDate(txtDate.Text), UDFLib.ConvertToInteger(ddlType.SelectedValue), ddlType.SelectedItem.Text, UDFLib.ConvertToInteger(ddlQuestionaire.SelectedValue), UDFLib.ConvertIntegerToNull(ddlOilMajor.SelectedValue), UDFLib.ConvertToInteger(ddlInspector.SelectedValue), ddlportID, UDFLib.ConvertIntegerToNull(hdfPorCallID.Value), GetSessionUserID(), ref ReturnValue);
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "alert1", "alert('Vetting saved successfully');", true);
                    ClearFields();
                    string js = "parent.VettingDetail(" + Vetting_ID + ");";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "js", js, true);
                }
            }
        }
        catch (Exception ex)
        {
            UDFLib.WriteExceptionLog(ex);
        }
    }