protected void btnPublish_Click(object sender, EventArgs e)
    {
        try
        {
            BLL_VET_Questionnaire objBLLQuest = new BLL_VET_Questionnaire();
            DataSet ds = new DataSet();
            ds = objBLLQuest.VET_Get_ExistQuestionForQuestionnaire(UDFLib.ConvertToInteger(ViewState["Questionnaire_ID"].ToString()));

            if (ds.Tables[0].Rows.Count == 0)
            {
                string jsSqlError2 = "alert('Add Question for this Questionnaire.');";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "jsSqlError2", jsSqlError2, true);
            }
            else
            {
                int res = objBLLQuest.VET_Upd_QuestionnaireStatus(ViewState["Version"].ToString(), ViewState["Number"].ToString(), Convert.ToInt32(Session["USERID"].ToString()), UDFLib.ConvertToInteger(ViewState["Questionnaire_ID"].ToString()));
                if (res > 0)
                {
                    string jsSqlError3 = "alert('Questionnaire published.');";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "jsSqlError3", jsSqlError3, true);
                    VET_Get_QuestionnaireDetails();
                    btnPublish.Enabled = false;
                    btnSave.Enabled    = false;
                }
            }
        }
        catch (Exception ex)
        {
            UDFLib.WriteExceptionLog(ex);
            string js = "alert('" + UDFLib.GetException("SystemError/ GeneralMessage") + "');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "error", js, true);
        }
    }
    /// <summary>
    /// To bind Questionnaire details by ID
    /// </summary>
    public void VET_Get_QuestionnaireDetailsByID()
    {
        try
        {
            BLL_VET_Questionnaire objBLLQuest = new BLL_VET_Questionnaire();
            DataTable             dtAllFields = objBLLQuest.VET_Get_QuestionnaireDetailsByID(UDFLib.ConvertToInteger(ViewState["Questionnaire_ID"].ToString()));


            if (Convert.ToString(dtAllFields.Rows[0]["Module"]) != "")
            {
                txtModule.Text = dtAllFields.Rows[0]["Module"].ToString();
            }
            if (Convert.ToString(dtAllFields.Rows[0]["VesselTypes"]) != "")
            {
                txtVesselType.Text = dtAllFields.Rows[0]["VesselTypes"].ToString();
            }

            if (Convert.ToString(dtAllFields.Rows[0]["Name"]) != "")
            {
                txtQuestionnaire.Text = dtAllFields.Rows[0]["Name"].ToString();
            }
            if (Convert.ToString(dtAllFields.Rows[0]["Vetting_Type_Name"]) != "")
            {
                txtVettingType.Text = dtAllFields.Rows[0]["Vetting_Type_Name"].ToString();
            }
            if (Convert.ToString(dtAllFields.Rows[0]["Number"]) != "")
            {
                txtNumber.Text      = dtAllFields.Rows[0]["Number"].ToString();
                ViewState["Number"] = dtAllFields.Rows[0]["Number"].ToString();
            }
            if (Convert.ToString(dtAllFields.Rows[0]["Version"]) != "")
            {
                txtVersion.Text      = dtAllFields.Rows[0]["Version"].ToString();
                ViewState["Version"] = dtAllFields.Rows[0]["Version"].ToString();
            }
            if (Convert.ToString(dtAllFields.Rows[0]["Status"]) != "")
            {
                ViewState["Status"] = dtAllFields.Rows[0]["Status"].ToString();
            }
        }
        catch (Exception ex)
        {
            UDFLib.WriteExceptionLog(ex);
            string js = "alert('" + UDFLib.GetException("SystemError/ GeneralMessage") + "');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "error", js, true);
        }
    }
 /// <summary>
 /// Get question no by section no
 /// </summary>
 public void VET_Get_QuestionNoBySectionNo()
 {
     try
     {
         BLL_VET_Questionnaire objBLLQuest = new BLL_VET_Questionnaire();
         DDLQuestion.DataSource     = objBLLQuest.VET_Get_QuestionNoBySectionNo(UDFLib.ConvertToInteger(ViewState["Questionnaire_ID"].ToString()), DDLSection.SelectedValues);
         DDLQuestion.DataTextField  = "Question_No";
         DDLQuestion.DataValueField = "ID";
         DDLQuestion.DataBind();
     }
     catch (Exception ex)
     {
         UDFLib.WriteExceptionLog(ex);
         string js = "alert('" + UDFLib.GetException("SystemError/ GeneralMessage") + "');";
         ScriptManager.RegisterStartupScript(this, this.GetType(), "error", js, true);
     }
 }
 /// <summary>
 /// To change Questionnire status to 'Archived'
 /// </summary>
 /// <param name="source"></param>
 /// <param name="e"></param>
 protected void onDelete(object source, CommandEventArgs e)
 {
     Questionnaire_ID = Convert.ToInt32(e.CommandArgument);
     try
     {
         BLL_VET_Questionnaire objBLLQuest = new BLL_VET_Questionnaire();
         int res = objBLLQuest.VET_Del_Questionnaire(Questionnaire_ID, Convert.ToInt32(Session["USERID"]));
         if (res > 0)
         {
             BindQuestionnaire();
         }
     }
     catch (Exception ex)
     {
         UDFLib.WriteExceptionLog(ex);
         string js = "alert('" + UDFLib.GetException("SystemError/ GeneralMessage") + "');";
         ScriptManager.RegisterStartupScript(this, this.GetType(), "error", js, true);
     }
 }
    /// <summary>
    /// Bind all vetting Questionnaire
    /// </summary>
    public void BindQuestionnaire()
    {
        try
        {
            BLL_VET_Questionnaire objBLLQuest = new BLL_VET_Questionnaire();
            DataSet ds            = new DataSet();
            int     rowcount      = ucCustomPagerItems.isCountRecord;
            string  sortbycoloumn = (ViewState["SORTBYCOLOUMN"] == null) ? null : (ViewState["SORTBYCOLOUMN"].ToString());
            int?    sortdirection = null; if (ViewState["SORTDIRECTION"] != null)
            {
                sortdirection = Int32.Parse(ViewState["SORTDIRECTION"].ToString());
            }

            ds = objBLLQuest.VET_Get_Questionnaire(UDFLib.ConvertIntegerToNull(DDLModule.SelectedValue), DDLVeseelType.SelectedValues, DDLVetType.SelectedValues, DDLStatus.SelectedValues, txtNumber.Text != "" ? txtNumber.Text.Trim() : null, txtVersion.Text != "" ? txtVersion.Text.Trim() : null, txtQuestionnaire.Text != "" ? txtQuestionnaire.Text.Trim() : null, sortbycoloumn, sortdirection, ucCustomPagerItems.CurrentPageIndex, ucCustomPagerItems.PageSize, ref rowcount);

            if (ucCustomPagerItems.isCountRecord == 1)
            {
                ucCustomPagerItems.CountTotalRec = rowcount.ToString();
                ucCustomPagerItems.BuildPager();
            }

            gvQuestionnaire.DataSource = ds.Tables[0];
            gvQuestionnaire.DataBind();
            if (ds.Tables[0].Rows.Count > 0)
            {
                btnExport.Enabled = true;
            }
            else
            {
                btnExport.Enabled = false;
            }
            UpdPnlGrid.Update();
            UpdPnlFilter.Update();
        }
        catch (Exception ex)
        {
            UDFLib.WriteExceptionLog(ex);
            string js = "alert('" + UDFLib.GetException("SystemError/ GeneralMessage") + "');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "error", js, true);
        }
    }
    /// <summary>
    /// To insert Questionnaire
    /// </summary>
    public void VET_Ins_Questionnaire()
    {
        try
        {
            string strQuestionnaireName       = txtQuestionnaireName.Text.Trim();
            string strNumber                  = txtNumber.Text.Trim();
            string strVersion                 = txtVersion.Text.Trim();
            BLL_VET_Questionnaire objBLLQuest = new BLL_VET_Questionnaire();
            DataSet ds = new DataSet();
            //DDLVesselType.SelectedValues added for multiple vessel type selection
            ds = objBLLQuest.VET_Get_ExistQuestinnaire(UDFLib.ConvertIntegerToNull(DDLModule.SelectedValue), UDFLib.ConvertIntegerToNull(DDLVetType.SelectedValue), DDLVesselType.SelectedValues, strNumber, strVersion);
            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    string jsSqlError2 = "alert('Questionnaire already exist.');";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "jsSqlError2", jsSqlError2, true);
                }
                else
                {
                    DataTable dtQuestionnaire = new DataTable();

                    dtQuestionnaire = objBLLQuest.VET_Ins_Questionnaire(UDFLib.ConvertIntegerToNull(DDLModule.SelectedValue), UDFLib.ConvertIntegerToNull(DDLVetType.SelectedValue), DDLVesselType.SelectedValues, strQuestionnaireName, strNumber, strVersion, Convert.ToInt32(Session["USERID"]));
                    if (dtQuestionnaire.Rows.Count > 0)
                    {
                        hdnQuestionnaireId.Value = dtQuestionnaire.Rows[0]["Questionnaire_ID"].ToString();
                        hdnQuestnirStatus.Value  = dtQuestionnaire.Rows[0]["Status"].ToString();
                    }
                    string jsSqlError2 = "alert('Questionnaire created.');";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "jsSqlError2", jsSqlError2, true);
                }
            }
        }
        catch (Exception ex)
        {
            UDFLib.WriteExceptionLog(ex);
            string js = "alert('" + UDFLib.GetException("SystemError/ GeneralMessage") + "');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "error", js, true);
        }
    }
    /// <summary>
    /// Export to excel
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnExport_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            BLL_VET_Questionnaire objBLLQuest = new BLL_VET_Questionnaire();
            DataSet ds            = new DataSet();
            int     rowcount      = ucCustomPagerItems.isCountRecord;
            string  sortbycoloumn = (ViewState["SORTBYCOLOUMN"] == null) ? null : (ViewState["SORTBYCOLOUMN"].ToString());
            int?    sortdirection = null; if (ViewState["SORTDIRECTION"] != null)
            {
                sortdirection = Int32.Parse(ViewState["SORTDIRECTION"].ToString());
            }

            ds = objBLLQuest.VET_Get_Questionnaire(UDFLib.ConvertIntegerToNull(DDLModule.SelectedValue), DDLVeseelType.SelectedValues, DDLVetType.SelectedValues, DDLStatus.SelectedValues, txtNumber.Text != "" ? txtNumber.Text.Trim() : null, txtVersion.Text != "" ? txtVersion.Text.Trim() : null, txtQuestionnaire.Text != "" ? txtQuestionnaire.Text.Trim() : null, sortbycoloumn, sortdirection, null, null, ref rowcount);

            string[] HeaderCaptions  = { "Module", "Vetting Type", "Vessel Type", "Questionnaire Name", "Number", "Version", "Status" };
            string[] DataColumnsName = { "Module", "Vetting_Type_Name", "Vessel_Type", "Questionnaire_Name", "Number", "Version", "Status" };

            string FileName = "VettingQuestionnaire" + "_" + DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss");
            string FilePath = Server.MapPath(@"~/Uploads\\Temp\\"); string ExportTempFilePath = Server.MapPath(@"~/Uploads\\ExportTemplete\\");

            if ((sender as ImageButton).CommandArgument == "ExportFrom_IE")
            {
                GridViewExportUtil.ShowExcel(ds.Tables[0], HeaderCaptions, DataColumnsName, FileName, "Vetting Questionnaire Index", "");
            }
            else
            {
                GridViewExportUtil.Export_To_Excel_Interop(ds.Tables[0], HeaderCaptions, DataColumnsName, "Vetting Questionnaire", FilePath + FileName, ExportTempFilePath, @"~\\Uploads\\Temp\\" + FileName);
            }
        }
        catch (Exception ex)
        {
            UDFLib.WriteExceptionLog(ex);
            string js = "alert('" + UDFLib.GetException("SystemError/ GeneralMessage") + "');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "error", js, true);
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            BLL_VET_Questionnaire objBLLQuest = new BLL_VET_Questionnaire();
            DataSet ds = new DataSet();
            ds = objBLLQuest.VET_Get_VersionNumber(txtNumber.Text.Trim().ToString(), txtVersion.Text.Trim().ToString());

            if (ds.Tables[0].Rows.Count > 0)
            {
                string jsSqlError2 = "alert('Version already exist.');";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "jsSqlError2", jsSqlError2, true);
            }
            else
            {
                DataTable dtQuestionnaire = new DataTable();
                dtQuestionnaire = objBLLQuest.VET_Ins_NewVersionQuestionDetails(txtNumber.Text.Trim(), ViewState["Version"].ToString(), txtVersion.Text.Trim(), UDFLib.ConvertToInteger(ViewState["Questionnaire_ID"].ToString()), ViewState["Status"].ToString(), Convert.ToInt32(Session["USERID"]));
                if (dtQuestionnaire.Rows.Count > 0)
                {
                    hfQuestionnaireID.Value       = dtQuestionnaire.Rows[0]["Questionnaire_ID"].ToString();
                    ViewState["Questionnaire_ID"] = dtQuestionnaire.Rows[0]["Questionnaire_ID"].ToString();
                    UpdatePanel1.Update();
                }
                string jsSqlError3 = "alert('Data saved successfully.');";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "jsSqlError3", jsSqlError3, true);

                VET_Get_QuestionnaireDetails();
            }
        }
        catch (Exception ex)
        {
            UDFLib.WriteExceptionLog(ex);
            string js = "alert('" + UDFLib.GetException("SystemError/ GeneralMessage") + "');";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "error", js, true);
        }
    }