protected bool Save_Schedule()
    {
        try
        {
            if (ValidateAll() == true)
            {
                DataTable dtSchedule  = NewDaemonScheduleTable();
                DataTable dtSettings  = NewDaemonSettingTable();
                DataTable dtChecklist = NewDaemonChecklist();
                DataTable dtPortList  = NewDaemonPortList();
                Populate_Schedular_Table(dtSchedule);
                Populate_Settings_Table(dtSettings);
                dtSettings.DefaultView.RowFilter = "Key_Name='Onetime'";

                if (dtSettings.DefaultView.ToTable().Rows.Count > 0)
                {
                    string strdate = Convert.ToDateTime(dtSettings.DefaultView.ToTable().Rows[0]["Key_Value_Date"].ToString()).ToString("yyyy-MM-dd HH:mm:ss");

                    int response1 = 0;
                    int response  = objInsp.CheckExists_Schedule(Convert.ToInt32(dtSchedule.Rows[0]["InspectorID"].ToString()), strdate, Convert.ToInt32(dtSchedule.Rows[0]["DurJobs"].ToString()), GetSessionUserID(), response1);
                    if (response == -5)
                    {
                        string js = "alert('Schedule already exists.');";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "script1", js, true);
                        return(false);
                    }
                }

                Populate_Checklist_Table(dtChecklist);
                dtPortList.Rows.Add(drpPort.SelectedValue.ToString());
                int Res;

                if (Request.QueryString["ScheduleID"] != null)
                {
                    Res = objInsp.Save_Schedule(dtSchedule, dtSettings, dtChecklist, GetSessionUserID(), UDFLib.ConvertToInteger(Request.QueryString["SchDetailId"].ToString()), dtPortList);
                }
                else
                {
                    Res = objInsp.Save_Schedule(dtSchedule, dtSettings, dtChecklist, GetSessionUserID(), null, dtPortList);
                    if (Request.QueryString["Page"] != null && Request.QueryString["VesselID"] != null && Request.QueryString["Surv_Details_ID"] != null && Request.QueryString["Surv_Vessel_ID"] != null && Request.QueryString["OfficeID"] != null)
                    {
                        if (Res > 0)
                        {
                            objInsp = new BLL_Tec_Inspection();
                            objInsp.SurveyRenewalInspection(UDFLib.ConvertToInteger(Request.QueryString["Surv_Details_ID"]), UDFLib.ConvertToInteger(Request.QueryString["Surv_Vessel_ID"]), UDFLib.ConvertToInteger(Request.QueryString["VesselID"]), UDFLib.ConvertToInteger(Request.QueryString["OfficeID"]), Res, ref ReturnInspectionID);
                        }
                    }
                }
                if (Res == -1)
                {
                    string js = "alert('Schedule name already exists.');";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "script1", js, true);
                    return(false);
                }
                else if (Res > 0)
                {
                    ViewState["ScheduleID"] = Res.ToString();
                    ViewState["ScheduleID"] = ViewState["ScheduleID"];
                    return(true);
                }
                else
                {
                    return(false); // procedure
                }
            }
            else
            {
                return(false); // Validation false
            }
        }
        catch (Exception ex)
        {
            UDFLib.WriteExceptionLog(ex);
            return(false);
        }
    }