Exemplo n.º 1
0
    protected bool UpdateSchedule(int Program_Id)
    {
        Dictionary <string, bool> VesselSelectedStates = (Dictionary <string, bool>)ViewState["VesselSelectedStates"];
        DataTable tablePIDS = new DataTable();

        tablePIDS.Columns.Add("ID", typeof(int));
        tablePIDS.Columns.Add("VALUE", typeof(string));
        string js;

        if (UDFLib.ConvertDateToNull(txtEffectiveStartDate.Text) == null)
        {
            js = "alert('Effective Start Date is required!.');LoadAfterCheckBox();";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alert2", js, true);
            return(false);
        }



        if (UDFLib.ConvertDateToNull(txtEffectiveEndDate.Text) != null)
        {
            if (UDFLib.ConvertDateToNull(txtEffectiveEndDate.Text) < UDFLib.ConvertDateToNull(txtEffectiveStartDate.Text))
            {
                js = "alert('Effective End Date should not be lesser than Effective Start Date!.');LoadAfterCheckBox();";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert2", js, true);
                return(false);
            }
            if (UDFLib.ConvertDateToNull(txtEffectiveEndDate.Text).Value.Date < DateTime.Now.Date || UDFLib.ConvertDateToNull(txtEffectiveStartDate.Text).Value.Date < DateTime.Now.Date)
            {
                js = "alert('Effective Start Date or Effective End Date should not be Past Dates!');LoadAfterCheckBox();";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert2", js, true);
                return(false);
            }
            if (UDFLib.ConvertDateToNull(txtEffectiveEndDate.Text).Value.Date == DateTime.Now.Date)
            {
                js = "alert('Effective End should not be the current Date!');LoadAfterCheckBox();";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert2", js, true);
                return(false);
            }
        }
        if (UDFLib.ConvertDateToNull(txtEffectiveStartDate.Text).Value.Date < DateTime.Now.Date)
        {
            js = "alert('Effective Start Date should not be Past Dates!');LoadAfterCheckBox();";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alert2", js, true);
            return(false);
        }
        if (rdbDaysPanel.Checked == false && rdbMontPanel.Checked == false)
        {
            js = "alert('Rule option not selected!.');LoadAfterCheckBox();";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alert2", js, true);
            return(false);
        }



        int ChekedVCount = 0;

        for (int i = 1; i < chkLstSelectVessel.Items.Count; i++)
        {
            if (chkLstSelectVessel.Items[i].Selected)
            {
                tablePIDS.Rows.Add(Convert.ToInt32(chkLstSelectVessel.Items[i].Value), "1");
                ChekedVCount++;
            }
            else
            {
                if (VesselSelectedStates[chkLstSelectVessel.Items[i].Value])
                {
                    tablePIDS.Rows.Add(Convert.ToInt32(chkLstSelectVessel.Items[i].Value), "0");
                }
            }
        }
        if (ChekedVCount == 0)
        {
            js = "alert('Please Select at least one Vessel!.');LoadAfterCheckBox();";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alert2", js, true);
            return(false);
        }

        int ChekedMCount = 0;

        foreach (ListItem liMon in lstSelectedMonth.Items)
        {
            if (liMon.Selected == true)
            {
                ChekedMCount++;
            }
        }
        if (rdbMontPanel.Checked)
        {
            if (ChekedMCount == 0)
            {
                js = "alert('Please Select at least one Month!.');LoadAfterCheckBox();";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert2", js, true);
                return(false);
            }
        }


        int ChekedRCount = 0;

        //foreach (ListItem liR in lstSelectedRules.Items)
        //{
        //    if (liR.Selected == true)
        //    {

        //        ChekedRCount++;
        //    }

        //}
        if (ddlDays.SelectedIndex != -1 && ddlDays.SelectedIndex != 0)
        {
            ChekedRCount++;
        }
        //if (ChekedRCount == 0)
        //{
        //    js = "alert('Please Select at least one Rule!.');";
        //    ScriptManager.RegisterStartupScript(this, this.GetType(), "alert2", js, true);
        //    return false;

        //}

        if (rdbMontPanel.Checked)
        {
            foreach (ListItem liMon in lstSelectedMonth.Items)
            {
                if (liMon.Selected == true)
                {
                    BLL_LMS_Training.Update_EvaluationMonths(Program_Id, tablePIDS, UDFLib.ConvertToInteger(liMon.Value), 1, GetSessionUserID());
                    ChekedMCount++;
                }
                else
                {
                    BLL_LMS_Training.Update_EvaluationMonths(Program_Id, tablePIDS, UDFLib.ConvertToInteger(liMon.Value), 0, GetSessionUserID());
                }
            }
        }



        //foreach (ListItem liRule in lstSelectedRules.Items)
        //{
        //    if (liRule.Selected == true)
        //    {
        //        BLL_LMS_Training.UPDATE_EvaluationRules(Program_Id, tablePIDS, UDFLib.ConvertToInteger(liRule.Value), 1, GetSessionUserID());
        //    }
        //    else
        //    {
        //        BLL_LMS_Training.UPDATE_EvaluationRules(Program_Id, tablePIDS, UDFLib.ConvertToInteger(liRule.Value), 0, GetSessionUserID());
        //    }
        //}

        if (rdbDaysPanel.Checked)
        {
            if (ddlDays.SelectedIndex != -1)
            {
                BLL_LMS_Training.UPDATE_EvaluationRules(Program_Id, tablePIDS, UDFLib.ConvertToInteger(ddlDays.SelectedValue), 1, GetSessionUserID());
            }
        }
        BLL_LMS_Training.Update_Program_Details(Program_Id, rdbMontPanel.Checked ? "M" : "D", UDFLib.ConvertDateToNull(txtEffectiveStartDate.Text), UDFLib.ConvertDateToNull(txtEffectiveEndDate.Text), GetSessionUserID());

        js = "alert('Schedule Planned.');LoadAfterCheckBox();";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "alert2", js, true);
        Bind_Vessel_List();

        foreach (ListItem li in lstSelectedMonth.Items)
        {
            li.Selected = false;
        }
        //foreach (ListItem li in lstSelectedRules.Items)
        //{
        //    li.Selected = false;
        //}
        ddlDays.SelectedIndex = -1;
        BindProgramItemInGrid();
        return(true);
    }