using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Data.SqlClient;
using DataAccess;

namespace VMT
{
    public partial class SprayCycleManagement : System.Web.UI.Page
    {
        //string m_SP_SPRCM_CHECK_RATE = Properties.Settings.Default.SP_SPRCM_CHECK_RATE;
        string m_SP_SPRCM_SELECT_YR = Properties.Settings.Default.SP_SPRCM_SELECT_YR;
        string m_SP_SPRCM_SELECT_YEAR = Properties.Settings.Default.SP_SPRCM_SELECT_YEAR;
        string m_SP_SPRCM_SELECT_BU = Properties.Settings.Default.SP_SPRCM_SELECT_BU;
        string m_SP_SPRCM_SELECT_EV = Properties.Settings.Default.SP_SPRCM_SELECT_EV;
        //string m_SP_SPRCM_SELECT_WA = Properties.Settings.Default.SP_SPRCM_SELECT_WA;

        string m_SP_VDM_SELECT_CHANGE_REASON = Properties.Settings.Default.SP_VDM_SELECT_CHANGE_REASON;
        string m_SP_SPRCM_SELECT_WAYR = Properties.Settings.Default.SP_SPRCM_SELECT_WAYR;
        string m_SP_SPRCM_UPDATE_WA = Properties.Settings.Default.SP_SPRCM_UPDATE_WA;
        string m_SP_SPRCM_SELECT_MOVE_CYCLE = Properties.Settings.Default.SP_SPRCM_SELECT_MOVE_CYCLE;
        //string scanaId = System.Web.HttpContext.Current.User.Identity.Name.ToUpper();
        string userRole = string.Empty;
        string m_SP_UR_GET_USER_ACCESS = Properties.Settings.Default.SP_UR_GET_USER_ACCESS;
        string pageName = "Spray Cycle Management";

        protected void Page_Load(object sender, EventArgs e)
        {
           
            //if (userRole == "2")
            //{
            //    btnUpdate.Visible = true;
            //}
            //else
            //{
            //    btnUpdate.Visible = false;
            //}

            if (!Page.IsPostBack)
            {

                //checks user role
                //userRole = DataAccessUtility.GetRole(m_SP_UR_GET_USER_ACCESS, pageName);
                if (Properties.Settings.Default.ENVMNT.ToString() == "LOCAL")
                {
                    userRole = VMT.UserRole.CallNewUserRoleWebService(m_SP_UR_GET_USER_ACCESS, pageName, System.Environment.UserName.ToUpper());
                }
                else
                {
                    userRole = VMT.UserRole.CallNewUserRoleWebService(m_SP_UR_GET_USER_ACCESS, pageName, System.Web.HttpContext.Current.User.Identity.Name.ToUpper());
                };

                if (userRole == "0")
                {
                    System.Web.HttpContext.Current.Response.Redirect("Default.aspx");
                }

                hdn_role.Value = userRole;

                btnUpdate.Visible = false;
                BindCycle();
                BindChangeReson();

                BindBusinessUnit();
                ddlBUnit.SelectedValue = Properties.Settings.Default.SELECTED_BUNIT;
                BindYr();
                BindEventCode();
               // BindWorkArea();
                //BindWorkYear();
                BindYear(ddlSysAssnYear);
                //ddlSysAssnYear.SelectedValue = DateTime.Now.Year.ToString().Substring(DateTime.Now.Year.ToString().Length - 2);
                BindYear(ddlCycleYear);
                //BindYear(ddlFuTrimYrTarget);

                ViewState["waIds"] = "";
                //GetMoveCycleData();
                //CalculateTrimYearTgt();
                //ScriptManager.RegisterStartupScript(this, typeof(string), "alert", "validate();", true);


            }
            CheckSubmitButton();
        }

        void CheckSubmitButton()
        {
            if (ddlEventCode.SelectedIndex == 0)
            {
                btnUpdate.Visible = false;
                ClearMoveCycleData();
            }
            else if (hfWorkStatusId.Value == "1" && ddlEventCode.SelectedIndex != 0)
                btnUpdate.Visible = true;
            else
                btnUpdate.Visible = false;

            if (hdn_role.Value == "2" && ddlEventCode.SelectedIndex != 0)
            {
                btnUpdate.Visible = true;
            }
            else if (hdn_role.Value == "3" && ddlEventCode.SelectedIndex != 0)
            {
                btnUpdate.Visible = true;
            }
            else if (hdn_role.Value == "1")
            {
                btnUpdate.Visible = false;
            }
            else if (hdn_role.Value == "0")
            {
                Response.Redirect("Default.aspx");
            }
        }

        void refreshcontrol()
        {

            //BindCycle();
            BindChangeReson();
            BindYr();
            BindEventCode();
            //BindWorkArea();
        }

        //protected void ddlWorkArea_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    List<OleDbParameter> sqlParam = new List<OleDbParameter>();
        //    try
        //    {
        //        if (ddlWorkArea.SelectedIndex != 0)
        //        {
        //            sqlParam.Add(new OleDbParameter("V_WORKAREA_ID", Int32.Parse(ddlWorkArea.SelectedItem.Value)));
        //            hdnRetainWkID.Value = DataAccessUtility.InsertUpdateDeleteViaStoreProcedureParam(m_SP_SPRCM_CHECK_RATE, sqlParam).ToString();
        //            GetMoveCycleData();
        //        }
        //    }
        //    catch
        //    {
        //    }
        //}

        void BindYear(DropDownList ddlYr)
        {
            try
            {
                DataAccessUtility.BindDropdownListWithoutConditionViaProcedure(m_SP_SPRCM_SELECT_YR, ddlYr);
            }
            catch
            {
            }
        }

        void BindYr()
        {
            CheckSubmitButton();
            try
            {
                List<OleDbParameter> sqlParams = new List<OleDbParameter>();
                sqlParams.Add(new OleDbParameter("V_BUSINESS_UNIT_ID", Int32.Parse(ddlBUnit.SelectedValue)));
                DataAccessUtility.BindDropdownListWithConditionViaProcedure(m_SP_SPRCM_SELECT_YEAR, sqlParams, ddlYear);
            }
            catch
            {
            }
        }

        void BindCycle()
        {
            ddlCycle.Items.AddRange(Enumerable.Range(1, 9).Select(e => new ListItem(e.ToString())).ToArray());
            ddlCycle.Items.Insert(0, "-All-");
            //ddlCycle.SelectedValue = Properties.Settings.Default.SELECTED_CYCLE; 
        }

        void BindBusinessUnit()
        {
            try
            {
                DataAccessUtility.BindDropdownListWithoutConditionViaProcedure(m_SP_SPRCM_SELECT_BU, ddlBUnit);
            }
            catch
            {
            }
        }



        void BindEventCode()
        {
            try
            {
                List<OleDbParameter> sqlParams = new List<OleDbParameter>();
                sqlParams.Add(new OleDbParameter("V_BUSINESS_UNIT_ID", Int32.Parse(ddlBUnit.SelectedValue)));
                sqlParams.Add(new OleDbParameter("V_YEAR", Int32.Parse(ddlYear.SelectedValue)));
                DataAccessUtility.BindDropdownListWithConditionViaProcedure(m_SP_SPRCM_SELECT_EV, sqlParams, ddlEventCode);
                //if (ddlEventCode.Items.Count > 1) 
                //{ 
                //    ddlEventCode.Enabled = true; 
                //    ddlWorkArea.Enabled = true; 
                //}
                //else 
                //{ 
                //    ddlEventCode.Enabled = false; 
                //    ddlWorkArea.Enabled = false; 
                //}
            }
            catch
            {
            }
        }



        //void BindWorkArea()
        //{
        //    try
        //    {
        //        List<OleDbParameter> sqlParams = new List<OleDbParameter>();
        //        sqlParams.Add(new OleDbParameter("V_BUSINESS_UNIT_ID", Int32.Parse(ddlBUnit.SelectedValue)));
        //        sqlParams.Add(new OleDbParameter("V_YEAR", Int32.Parse(ddlYear.SelectedValue)));
        //        sqlParams.Add(new OleDbParameter("V_EVENT_CODE_ID", Int32.Parse(ddlEventCode.SelectedValue)));
        //        DataAccessUtility.BindDropdownListWithConditionViaProcedure(m_SP_SPRCM_SELECT_WA, sqlParams, ddlWorkArea);
        //        if (ddlWorkArea.Items.Count > 1) { }
        //        else
        //        {
        //            lblPrevTrimDt.Text = ""; lblSysAssnYear.Text = ""; lblCycleYear.Text = ""; lblCycle.Text = ""; lblChangeReson.Text = ""; lblFuTrimYrTarget.Text = ""; lblFuFuTrimYrTarget.Text = "";
        //            //lblmovecycle.Text = ""; 

        //            ddlSysAssnYear.SelectedIndex = 0; txtFuTrimYrTarget.Text = ""; txtFuFuTrimYrTarget.Text = ""; ddlCycle.SelectedIndex = 0;
        //            //rblMvCycle.Items[0].Selected = true;
        //        }
        //    }
        //    catch
        //    {
        //    }
        //}

        void BindChangeReson()
        {
            try
            {
                DataAccessUtility.BindDropdownListWithoutConditionViaProcedure(m_SP_VDM_SELECT_CHANGE_REASON, ddlChangeReson);
            }
            catch
            {
            }
        }

        protected void ddlBUnit_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindYr();
            BindEventCode();
            //BindWorkArea();
            CheckSubmitButton();
        }

        protected void ddlEventCode_SelectedIndexChanged(object sender, EventArgs e)
        {
            //BindWorkArea();
            GetMoveCycleData();
            CheckSubmitButton();
        }

        protected void btn_go_Click(object sender, EventArgs e)
        {
            GetMoveCycleData();
        }

        void ClearMoveCycleData()
        {
            ddlSysAssnYear.SelectedIndex = 0;
            ddlCycleYear.SelectedIndex = 0;
            ddlCycle.SelectedIndex = 0;
            ddlChangeReson.SelectedIndex = 0;

            lblPrevTrimDt.Text = "";
            lblSysAssnYear.Text = "";
            lblCycleYear.Text = "";
            lblCycle.Text = "";
            lblChangeReson.Text = "";
            txtFuTrimYrTarget.Text = "";
            lblFuTrimYrTarget.Text = "";
            txtFuFuTrimYrTarget.Text = "";
            lblFuFuTrimYrTarget.Text = "";

            lblSprayPrevTrimDt.Text = "";
            lblSpraySysAssnYear.Text = "";
            lblSprayCycleYear.Text = "";
            lblSprayCycle.Text = "";
            lblSprayChangeReson.Text = "";
            lblSprayFuTrimYrTarget.Text = "";
            lblSprayFuFuTrimYrTarget.Text = "";
        }


        void GetMoveCycleData()
        {
            //BindYear(ddlFuTrimYrTarget);

            if (ddlEventCode.SelectedIndex == 0)
                ClearMoveCycleData();
            else
            {
                List<OleDbParameter> sqlParams = new List<OleDbParameter>();
                List<OleDbParameter> sqlParams1 = new List<OleDbParameter>();
                int wkId;
                try
                {

                    //if (ddlWorkArea.SelectedIndex == 0)
                    //    wkId = Int32.Parse(ddlWorkArea.Items[1].Value);
                    //else
                    //    wkId = Int32.Parse(ddlWorkArea.SelectedValue);
                    wkId = 0;

                    sqlParams.Add(new OleDbParameter("V_EVENTCODE", ddlEventCode.SelectedValue));
                    DataSet ds = DataAccessUtility.SelectDataSetViaStoreProcedureParam(m_SP_SPRCM_SELECT_WAYR, sqlParams);
                    sqlParams1.Add(new OleDbParameter("V_EVENTCODE", ddlEventCode.SelectedValue));
                    DataSet ds1 = DataAccessUtility.SelectDataSetViaStoreProcedureParam(m_SP_SPRCM_SELECT_MOVE_CYCLE, sqlParams1);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        ddlSysAssnYear.SelectedValue = ds.Tables[0].Rows[0]["SYSTEM_ASSIGNED_YEAR"].ToString();
                        ViewState["sysAssgnYr"] = ds.Tables[0].Rows[0]["SYSTEM_ASSIGNED_YEAR"].ToString();
                        ddlCycleYear.SelectedValue = ds.Tables[0].Rows[0]["trim_year_target"].ToString();
                        ViewState["pjtWorkYr"] = ds.Tables[0].Rows[0]["trim_year_target"].ToString();
                        ddlCycle.SelectedValue = ds.Tables[0].Rows[0]["trim_cycle"].ToString();
                        //   ViewState["cycle"] = ds.Tables[0].Rows[0]["trim_cycle"].ToString();
                        ddlChangeReson.SelectedValue = ds.Tables[0].Rows[0]["change_reason_id"].ToString();
                        hfWorkStatusId.Value = ds.Tables[0].Rows[0]["work_status_id"].ToString();
                        lblPrevTrimDt.Text = ds.Tables[0].Rows[0]["previous_trim_date"].ToString();
                        lblSysAssnYear.Text = ds.Tables[0].Rows[0]["cycle_year"].ToString();
                        lblCycleYear.Text = ds.Tables[0].Rows[0]["work_year"].ToString();
                        lblCycle.Text = ds.Tables[0].Rows[0]["trim_cycle"].ToString();
                        lblChangeReson.Text = ds.Tables[0].Rows[0]["change_description"].ToString();
                        txtFuTrimYrTarget.Text = ds.Tables[0].Rows[0]["FUTURE_TRIM_YR_TGT"].ToString();
                        lblFuTrimYrTarget.Text = ds.Tables[0].Rows[0]["FUTURE_TRIM_YR_TGT"].ToString();

                        txtFuFuTrimYrTarget.Text = (Int32.Parse(txtFuTrimYrTarget.Text) + Int32.Parse(ddlCycle.SelectedValue)).ToString();
                        lblFuFuTrimYrTarget.Text = (Int32.Parse(lblFuTrimYrTarget.Text) + Int32.Parse(ddlCycle.SelectedValue)).ToString();
                    }
                    if (ds1.Tables[0].Rows.Count > 0)
                    {
                        lblSprayPrevTrimDt.Text = ds1.Tables[0].Rows[0]["previous_trim_date"].ToString();
                        lblSpraySysAssnYear.Text = ds1.Tables[0].Rows[0]["cycle_year"].ToString();
                        lblSprayCycleYear.Text = ds1.Tables[0].Rows[0]["work_year"].ToString();
                        lblSprayCycle.Text = ds1.Tables[0].Rows[0]["trim_cycle"].ToString();
                        lblSprayChangeReson.Text = ds1.Tables[0].Rows[0]["change_description"].ToString();
                        lblSprayFuTrimYrTarget.Text = ds1.Tables[0].Rows[0]["FUTURE_TRIM_YR_TGT"].ToString();
                        lblSprayFuFuTrimYrTarget.Text = (Int32.Parse(lblSprayFuTrimYrTarget.Text) + Int32.Parse(lblSprayCycle.Text)).ToString();
                    }
                    else
                    {
                        lblSprayPrevTrimDt.Text = "";
                        lblSpraySysAssnYear.Text = "";
                        lblSprayCycleYear.Text = "";
                        lblSprayCycle.Text = "";
                        lblSprayChangeReson.Text = "";
                        lblSprayFuTrimYrTarget.Text = "";
                        lblSprayFuFuTrimYrTarget.Text = "";
                    }
                    //////ddlSysAssnYear.SelectedValue = ds.Tables[0].Rows[0]["SYSTEM_ASSIGNED_YEAR"].ToString();
                    //////ViewState["sysAssgnYr"] = ds.Tables[0].Rows[0]["SYSTEM_ASSIGNED_YEAR"].ToString();
                    //////ddlCycleYear.SelectedValue = ds.Tables[0].Rows[0]["trim_year_target"].ToString();
                    //////ViewState["pjtWorkYr"] = ds.Tables[0].Rows[0]["trim_year_target"].ToString();
                    //////ddlCycle.SelectedValue = ds.Tables[0].Rows[0]["trim_cycle"].ToString();
                    ////////   ViewState["cycle"] = ds.Tables[0].Rows[0]["trim_cycle"].ToString();
                    //////ddlChangeReson.SelectedValue = ds.Tables[0].Rows[0]["change_reason_id"].ToString();

                    //////lblPrevTrimDt.Text = ds.Tables[0].Rows[0]["previous_trim_date"].ToString();
                    //////lblSysAssnYear.Text = ds.Tables[0].Rows[0]["cycle_year"].ToString(); // ddlSysAssnYear.SelectedItem.Text.ToString();
                    //////lblCycleYear.Text = ds.Tables[0].Rows[0]["work_year"].ToString(); // ddlCycleYear.SelectedItem.Text.ToString();
                    //////lblCycle.Text = ds.Tables[0].Rows[0]["trim_cycle"].ToString(); // ddlCycle.SelectedItem.Text.ToString();
                    //////lblChangeReson.Text = ds.Tables[0].Rows[0]["change_description"].ToString(); // ddlChangeReson.SelectedItem.Text.ToString();
                    ////////rblMvCycle.SelectedValue = ds.Tables[0].Rows[0]["move_cycle"].ToString();
                    //////txtFuTrimYrTarget.Text = ds.Tables[0].Rows[0]["FUTURE_TRIM_YR_TGT"].ToString();
                    //////lblFuTrimYrTarget.Text = ds.Tables[0].Rows[0]["FUTURE_TRIM_YR_TGT"].ToString();

                    //////txtFuFuTrimYrTarget.Text = (Int32.Parse(txtFuTrimYrTarget.Text) + Int32.Parse(ddlCycle.SelectedValue)).ToString();
                    //////lblFuFuTrimYrTarget.Text = (Int32.Parse(lblFuTrimYrTarget.Text) + Int32.Parse(ddlCycle.SelectedValue)).ToString();

                    //if (ds.Tables[0].Rows[0]["move_cycle"].ToString() == "N")
                    //{
                    //    //rdoOneTime.Checked = true;

                    //    lblmovecycle.Text = "One-Time";
                    //if (ddlCycle.SelectedIndex != 0)
                    //    txtFuFuTrimYrTarget.Text = (Int32.Parse(txtFuTrimYrTarget.Text) + Int32.Parse(ddlCycle.SelectedValue)).ToString();
                    //    else txtFuFuTrimYrTarget.Text = "";
                    //   // CalculateTrimYearTgt();

                    //}
                    //else
                    //{
                    //    //rdoPermanent.Checked = true;
                    //    lblmovecycle.Text = "Permanent";
                    //    CalculateTrimYearTgt();

                    //}
                    //if (ds.Tables[0].Rows[0]["move_cycle"].ToString() == "Y")
                    //{
                    //    lblFuTrimYrTarget.Text = (Int32.Parse(ddlSysAssnYear.SelectedItem.Text) + Int32.Parse(ddlCycle.SelectedValue)).ToString();
                    //}
                    //else if (ds.Tables[0].Rows[0]["move_cycle"].ToString() == "N")
                    //{
                    //    lblFuTrimYrTarget.Text = (Int32.Parse(ddlCycleYear.SelectedItem.Text) + Int32.Parse(ddlCycle.SelectedValue)).ToString();
                    //}

                    //lblFuFuTrimYrTarget.Text = (Int32.Parse(lblFuTrimYrTarget.Text) + Int32.Parse(ddlCycle.SelectedValue)).ToString();
                }

                //}

                catch
                {
                }
            }

        }


        void CalculateTrimYearTgt()
        {
            if (txtFuTrimYrTarget.Text.Trim().Length > 0 && ddlSysAssnYear.SelectedIndex != 0)
            {
                if (ddlCycle.SelectedIndex != 0)
                {
                    txtFuTrimYrTarget.Text = (Int32.Parse(ddlSysAssnYear.SelectedItem.Text) + Int32.Parse(ddlCycle.SelectedValue)).ToString();
                    txtFuFuTrimYrTarget.Text = (Int32.Parse(txtFuTrimYrTarget.Text) + Int32.Parse(ddlCycle.SelectedValue)).ToString();
                }
                else txtFuFuTrimYrTarget.Text = "";
            }

            //if (txtFuTrimYrTarget.Text.Trim().Length > 0 && ddlCycleYear.SelectedIndex != 0)
            //{
            //if (rblMvCycle.SelectedValue.ToString() == "Y")
            //{
            //    txtFuTrimYrTarget.Text = (Int32.Parse(ddlSysAssnYear.SelectedItem.Text) + Int32.Parse(ddlCycle.SelectedValue)).ToString();

            //}
            //else if (rblMvCycle.SelectedValue.ToString() == "N")
            //{
            //txtFuTrimYrTarget.Text = (Int32.Parse(ddlCycleYear.SelectedItem.Text) + Int32.Parse(ddlCycle.SelectedValue)).ToString();

            //if (lblSysAssnYear.Text.Trim() != ddlSysAssnYear.SelectedItem.Text && lblCycle.Text.Trim() != ddlCycle.SelectedItem.Text)
            //{
            //    txtFuTrimYrTarget.Text = (Int32.Parse(lblSysAssnYear.Text) + Int32.Parse(ddlCycle.SelectedValue)).ToString();
            //}
            //else
            //{
            //    txtFuTrimYrTarget.Text = (Int32.Parse(lblSysAssnYear.Text) + Int32.Parse(lblCycle.Text)).ToString();
            //}


            //txtFuTrimYrTarget.Text = (Int32.Parse(lblSysAssnYear.Text) + Int32.Parse(ddlCycle.SelectedValue)).ToString();
            ////}
            //if (ddlCycle.SelectedIndex != 0)
            //    txtFuFuTrimYrTarget.Text = (Int32.Parse(txtFuTrimYrTarget.Text) + Int32.Parse(ddlCycle.SelectedValue)).ToString();
            //else txtFuFuTrimYrTarget.Text = "";
            //}

        }


        protected void ddlCycle_SelectedIndexChanged(object sender, EventArgs e)
        {
            CalculateTrimYearTgt();
        }


        protected void ddlCycleYear_SelectedIndexChanged(object sender, EventArgs e)
        {
            //    DropDownList ddl = (DropDownList)sender;
            //    if (ddl.ID == "ddlSysAssnYear")
            //        CalculateTrimYearTgt();
        }


        protected void ddlSysAssnYear_SelectedIndexChanged(object sender, EventArgs e)
        {
            CalculateTrimYearTgt();
        }

        //void GetWaIds()
        //{
        //    ViewState["waIds"] = "";
        //    try
        //    {
        //        foreach (ListItem li in ddlWorkArea.Items)
        //        {
        //            if (ddlWorkArea.SelectedIndex != 0)
        //                ViewState["waIds"] = ddlWorkArea.SelectedValue;
        //            else
        //            {
        //                if (li.Text == "-All-") { } //skip the first wk id item with "All"
        //                else if (ViewState["waIds"].ToString().Trim().Length > 0)
        //                    ViewState["waIds"] = ViewState["waIds"] + "," + li.Value;
        //                else
        //                    ViewState["waIds"] = li.Value;
        //            }

        //        }
        //    }
        //    catch
        //    {
        //    }
        //}

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            if (ddlSysAssnYear.SelectedIndex == 0)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Select a cycle year')", true);
                ddlSysAssnYear.Focus();
                return;
            }

            string delFag = string.Empty;

            //GetWaIds();
            int retVal = 0;
            delFag = "Delete";
            string confirmValue = hfConfirmMsg.Value;
            string rdo = "";
            
            if (confirmValue == "CR")
            {
                confirmValue = "";
                ddlChangeReson.Focus();
                return;
            }

            try
            {


                List<OleDbParameter> sqlParams = new List<OleDbParameter>();
                sqlParams.Add(new OleDbParameter("V_DELETE_FLAG", delFag));
                sqlParams.Add(new OleDbParameter("V_WORKAREA_ID", ViewState["waIds"].ToString().Trim()));
                sqlParams.Add(new OleDbParameter("V_EVENTCODE", ddlEventCode.SelectedValue));
                sqlParams.Add(new OleDbParameter("V_SYSTEM_ASSIGNED_YEAR", ddlSysAssnYear.SelectedValue));
                sqlParams.Add(new OleDbParameter("V_TRIM_YEAR_TARGET", Int32.Parse(ddlCycleYear.SelectedValue)));
                sqlParams.Add(new OleDbParameter("V_FUTURE_TRIM_YR_TGT", txtFuTrimYrTarget.Text));
                sqlParams.Add(new OleDbParameter("V_MOVE_CYCLE", rdo));
                sqlParams.Add(new OleDbParameter("V_TRIM_CYCLE", ddlCycle.SelectedItem.Text.Trim()));
                sqlParams.Add(new OleDbParameter("V_LAST_UPDATED_USER_ID", System.Web.HttpContext.Current.User.Identity.Name.Replace("SCANA\\", "").ToUpper()));
                sqlParams.Add(new OleDbParameter("V_CHANGE_REASON", ddlChangeReson.SelectedValue));

                if (confirmValue == "No")
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('No update was performed')", true);
                    return;
                }

                if (confirmValue == "Yes")
                {
                    retVal = DataAccessUtility.InsertUpdateDeleteViaStoreProcedureParam(m_SP_SPRCM_UPDATE_WA, sqlParams);
                    refreshcontrol();
                    CheckSubmitButton();
                    //GetMoveCycleData();
                }
                else
                    ddlCycleYear.Focus();
            }
            catch { }
            finally
            {
            }

            if (retVal == 1)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Update successful')", true);
            }
            else if (retVal == -1)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Work ID does not exist')", true);
            }



            //rdo = rblMvCycle.SelectedValue.ToString();
            //string strMessage = "";
            //if (rdoPermanent.Checked)
            //{

            //    rdo = "Y";
            //    if (ViewState["sysAssgnYr"].ToString().Trim() != ddlSysAssnYear.SelectedValue && ViewState["pjtWorkYr"].ToString().Trim() != ddlCycleYear.SelectedValue &&
            //       ViewState["cycle"].ToString().Trim() != ddlCycle.SelectedValue)
            //        strMessage = "Scheduled Work has been moved to " + ddlSysAssnYear.SelectedItem.Text +
            //              "\\n Projected work has been moved to " + ddlCycleYear.SelectedItem.Text +
            //              "\\n Cycle changed to " + ddlCycle.SelectedItem.Text +
            //              ", and future trim dates are changing permanently.";
            //    else if (ViewState["sysAssgnYr"].ToString().Trim() != ddlSysAssnYear.SelectedValue && ViewState["pjtWorkYr"].ToString().Trim() != ddlCycleYear.SelectedValue)
            //        strMessage = "Scheduled Work has been moved to " + ddlSysAssnYear.SelectedItem.Text +
            //              "\\n Projected work has been moved to " + ddlCycleYear.SelectedItem.Text +
            //              ", and future trim dates are changing permanently.";

            //    else if (ViewState["sysAssgnYr"].ToString().Trim() != ddlSysAssnYear.SelectedValue && ViewState["cycle"].ToString().Trim() != ddlCycle.SelectedValue)
            //        strMessage = "Scheduled Work has been moved to " + ddlSysAssnYear.SelectedItem.Text +
            //              "\\n Cycle changed to " + ddlCycle.SelectedItem.Text +
            //              ", and future trim dates are changing permanently.";

            //    else if (ViewState["pjtWorkYr"].ToString().Trim() != ddlCycleYear.SelectedValue && ViewState["cycle"].ToString().Trim() != ddlCycle.SelectedValue)
            //        strMessage = " Projected work has been moved to " + ddlCycleYear.SelectedItem.Text +
            //              "\\n Cycle changed to " + ddlCycle.SelectedItem.Text +
            //              ", and future trim dates are changing permanently.";

            //    else if (ViewState["sysAssgnYr"].ToString().Trim() != ddlSysAssnYear.SelectedValue)
            //        strMessage = "Scheduled Work has been moved to " + ddlSysAssnYear.SelectedItem.Text +
            //         ", and future trim dates are changing permanently.";

            //    else if (ViewState["pjtWorkYr"].ToString().Trim() != ddlCycleYear.SelectedValue)
            //        strMessage = "Projected work has been moved to " + ddlCycleYear.SelectedItem.Text + ", and future trim dates are changing permanently.";

            //    else if (ViewState["cycle"].ToString().Trim() != ddlCycle.SelectedValue)
            //        strMessage = "Cycle changed to " + ddlCycle.SelectedItem.Text + ", and the future trim dates are going to be changed permanently.";

            //    //if (strMessage != "")
            //    //ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('" + strMessage+ "')", true);
            //    // GetMoveCycleData();
            //}
            //else if (rdoOneTime.Checked)
            //{
            //    rdo = "N";

            //    if (ViewState["sysAssgnYr"].ToString().Trim() != ddlSysAssnYear.SelectedValue && ViewState["pjtWorkYr"].ToString().Trim() != ddlCycleYear.SelectedValue &&
            //        ViewState["cycle"].ToString().Trim() != ddlCycle.SelectedValue)
            //        strMessage = "  Change the scheduled work to be done in " + ddlSysAssnYear.SelectedItem.Text +
            //         "\\n. Change the projected work to be done in " + ddlCycleYear.SelectedItem.Text + ". Future dates change. " +
            //         "\\n Cycle will be changed to " + ddlCycle.SelectedItem.Text + ", and cause the future trim dates to be impacted.";

            //    else if (ViewState["sysAssgnYr"].ToString().Trim() != ddlSysAssnYear.SelectedValue && ViewState["pjtWorkYr"].ToString().Trim() != ddlCycleYear.SelectedValue)
            //        strMessage = "  Change the scheduled work to be done in " + ddlSysAssnYear.SelectedItem.Text +
            //         "\\n. Change the projected work to be done in " + ddlCycleYear.SelectedItem.Text + ". Future dates change. ";

            //    else if (ViewState["sysAssgnYr"].ToString().Trim() != ddlSysAssnYear.SelectedValue && ViewState["cycle"].ToString().Trim() != ddlCycle.SelectedValue)
            //        strMessage = "  Change the scheduled work to be done in " + ddlSysAssnYear.SelectedItem.Text +
            //         "\\n Cycle will be changed to " + ddlCycle.SelectedItem.Text + ", and cause the future trim dates to be impacted.";

            //    else if (ViewState["pjtWorkYr"].ToString().Trim() != ddlCycleYear.SelectedValue && ViewState["cycle"].ToString().Trim() != ddlCycle.SelectedValue)
            //        strMessage = "Change the projected work to be done in " + ddlCycleYear.SelectedItem.Text + ".  Future dates change. " +
            //         "\\n Cycle will be changed to " + ddlCycle.SelectedItem.Text + ", and cause the future trim dates to be impacted.";

            //    else if (ViewState["sysAssgnYr"].ToString().Trim() != ddlSysAssnYear.SelectedValue)
            //        strMessage = "  Change the scheduled work to be done in " + ddlSysAssnYear.SelectedItem.Text + ", and keep the future trim dates the same.";

            //    else if (ViewState["pjtWorkYr"].ToString().Trim() != ddlCycleYear.SelectedValue)
            //        strMessage = "Change the projected work to be done in " + ddlCycleYear.SelectedItem.Text + ". Future dates change.";

            //    else if (ViewState["cycle"].ToString().Trim() != ddlCycle.SelectedValue)
            //        strMessage = " Cycle will be changed to " + ddlCycle.SelectedItem.Text + ", and cause the future trim dates to be impacted.";

            //    //if (strMessage != "")
            //    //ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('" + strMessage + "')", true);
            //    //GetMoveCycleData();
            //}



        }

        //private void SaveData()
        //{
        //    GetWaIds();
        //    int retVal = 0;

        //    try
        //    {


        //        List<OleDbParameter> sqlParams = new List<OleDbParameter>();
        //        sqlParams.Add(new OleDbParameter("V_DELETE_FLAG", delFag));
        //        sqlParams.Add(new OleDbParameter("V_WORKAREA_ID", ViewState["waIds"].ToString().Trim()));
        //        sqlParams.Add(new OleDbParameter("V_SYSTEM_ASSIGNED_YEAR", Int32.Parse(ddlSysAssnYear.SelectedValue)));
        //        sqlParams.Add(new OleDbParameter("V_TRIM_YEAR_TARGET", Int32.Parse(ddlCycleYear.SelectedValue)));
        //        sqlParams.Add(new OleDbParameter("V_FUTURE_TRIM_YR_TGT", txtFuTrimYrTarget.Text));
        //        sqlParams.Add(new OleDbParameter("V_MOVE_CYCLE", rdo));
        //        sqlParams.Add(new OleDbParameter("V_TRIM_CYCLE", ddlCycle.SelectedItem.Text.Trim()));
        //        sqlParams.Add(new OleDbParameter("V_LAST_UPDATED_USER_ID", System.Web.HttpContext.Current.User.Identity.Name.Replace("SCANA\\", "").ToUpper()));
        //        sqlParams.Add(new OleDbParameter("V_CHANGE_REASON", ddlChangeReson.SelectedValue));
        //        retVal = DataAccessUtility.InsertUpdateDeleteViaStoreProcedureParam("SP_VDM_UPDATE_WA_MOVE_CYCLE", sqlParams);

        //    }
        //    catch { }
        //    finally
        //    {
        //    }

        //    if (retVal == 1)
        //    {
        //        ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Update successful')", true);
        //    }
        //    else if (retVal == -1)
        //    {
        //        ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Work ID does not exist')", true);
        //    }
        //}

        protected void chkMvCycle_CheckedChanged(object sender, EventArgs e)
        {
            //BindYear(ddlFuTrimYrTarget);
            CalculateTrimYearTgt();
            //else
            //{
            //    ddlFuTrimYrTarget.Items.Clear(); 
            //    txtFuFuTrimYrTarget.Text = "";
            //}

        }

        //protected void ddlWorkArea_DataBound(object sender, EventArgs e)
        //{
        //    if (ddlEventCode.SelectedIndex != 0)
        //        GetMoveCycleData();
        //}

        protected void ddlBUnit_DataBound(object sender, EventArgs e)
        {
            BindYr();
        }

        protected void ddlYear_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindEventCode();
            CheckSubmitButton();
        }

        protected void ddlYear_DataBound(object sender, EventArgs e)
        {
            BindEventCode();
        }

        //protected void ddlEventCode_DataBound(object sender, EventArgs e)
        //{
        //    BindWorkArea();
        //}










        //public string ReturnMessage()
        //{
        //    string rdo = "";
        //    string strMessage = "";
        //    if (rblMvCycle.SelectedValue.ToString() == "Y")
        //    {

        //        rdo = "Y";
        //        if (ViewState["sysAssgnYr"].ToString().Trim() != ddlSysAssnYear.SelectedValue && ViewState["pjtWorkYr"].ToString().Trim() != ddlCycleYear.SelectedValue &&
        //           ViewState["cycle"].ToString().Trim() != ddlCycle.SelectedValue)
        //            strMessage = "Scheduled Work has been moved to " + ddlSysAssnYear.SelectedItem.Text +
        //                  "\\n Projected work has been moved to " + ddlCycleYear.SelectedItem.Text +
        //                  "\\n Cycle changed to " + ddlCycle.SelectedItem.Text +
        //                  ", and future trim dates are changing permanently.";
        //        else if (ViewState["sysAssgnYr"].ToString().Trim() != ddlSysAssnYear.SelectedValue && ViewState["pjtWorkYr"].ToString().Trim() != ddlCycleYear.SelectedValue)
        //            strMessage = "Scheduled Work has been moved to " + ddlSysAssnYear.SelectedItem.Text +
        //                  "\\n Projected work has been moved to " + ddlCycleYear.SelectedItem.Text +
        //                  ", and future trim dates are changing permanently.";

        //        else if (ViewState["sysAssgnYr"].ToString().Trim() != ddlSysAssnYear.SelectedValue && ViewState["cycle"].ToString().Trim() != ddlCycle.SelectedValue)
        //            strMessage = "Scheduled Work has been moved to " + ddlSysAssnYear.SelectedItem.Text +
        //                  "\\n Cycle changed to " + ddlCycle.SelectedItem.Text +
        //                  ", and future trim dates are changing permanently.";

        //        else if (ViewState["pjtWorkYr"].ToString().Trim() != ddlCycleYear.SelectedValue && ViewState["cycle"].ToString().Trim() != ddlCycle.SelectedValue)
        //            strMessage = " Projected work has been moved to " + ddlCycleYear.SelectedItem.Text +
        //                  "\\n Cycle changed to " + ddlCycle.SelectedItem.Text +
        //                  ", and future trim dates are changing permanently.";

        //        else if (ViewState["sysAssgnYr"].ToString().Trim() != ddlSysAssnYear.SelectedValue)
        //            strMessage = "Scheduled Work has been moved to " + ddlSysAssnYear.SelectedItem.Text +
        //             ", and future trim dates are changing permanently.";

        //        else if (ViewState["pjtWorkYr"].ToString().Trim() != ddlCycleYear.SelectedValue)
        //            strMessage = "Projected work has been moved to " + ddlCycleYear.SelectedItem.Text + ", and future trim dates are changing permanently.";

        //        else if (ViewState["cycle"].ToString().Trim() != ddlCycle.SelectedValue)
        //            strMessage = "Cycle changed to " + ddlCycle.SelectedItem.Text + ", and the future trim dates are going to be changed permanently.";

        //    }
        //    else if (rblMvCycle.SelectedValue.ToString() == "N")
        //    {
        //        rdo = "N";

        //        if (ViewState["sysAssgnYr"].ToString().Trim() != ddlSysAssnYear.SelectedValue && ViewState["pjtWorkYr"].ToString().Trim() != ddlCycleYear.SelectedValue &&
        //            ViewState["cycle"].ToString().Trim() != ddlCycle.SelectedValue)
        //            strMessage = "  Change the scheduled work to be done in " + ddlSysAssnYear.SelectedItem.Text +
        //             "\\n. Change the projected work to be done in " + ddlCycleYear.SelectedItem.Text + ". Future dates change. " +
        //             "\\n Cycle will be changed to " + ddlCycle.SelectedItem.Text + ", and cause the future trim dates to be impacted.";

        //        else if (ViewState["sysAssgnYr"].ToString().Trim() != ddlSysAssnYear.SelectedValue && ViewState["pjtWorkYr"].ToString().Trim() != ddlCycleYear.SelectedValue)
        //            strMessage = "  Change the scheduled work to be done in " + ddlSysAssnYear.SelectedItem.Text +
        //             "\\n. Change the projected work to be done in " + ddlCycleYear.SelectedItem.Text + ". Future dates change. ";

        //        else if (ViewState["sysAssgnYr"].ToString().Trim() != ddlSysAssnYear.SelectedValue && ViewState["cycle"].ToString().Trim() != ddlCycle.SelectedValue)
        //            strMessage = "  Change the scheduled work to be done in " + ddlSysAssnYear.SelectedItem.Text +
        //             "\\n Cycle will be changed to " + ddlCycle.SelectedItem.Text + ", and cause the future trim dates to be impacted.";

        //        else if (ViewState["pjtWorkYr"].ToString().Trim() != ddlCycleYear.SelectedValue && ViewState["cycle"].ToString().Trim() != ddlCycle.SelectedValue)
        //            strMessage = "Change the projected work to be done in " + ddlCycleYear.SelectedItem.Text + ".  Future dates change. " +
        //             "\\n Cycle will be changed to " + ddlCycle.SelectedItem.Text + ", and cause the future trim dates to be impacted.";

        //        else if (ViewState["sysAssgnYr"].ToString().Trim() != ddlSysAssnYear.SelectedValue)
        //            strMessage = "  Change the scheduled work to be done in " + ddlSysAssnYear.SelectedItem.Text + ", and keep the future trim dates the same.";

        //        else if (ViewState["pjtWorkYr"].ToString().Trim() != ddlCycleYear.SelectedValue)
        //            strMessage = "Change the projected work to be done in " + ddlCycleYear.SelectedItem.Text + ". Future dates change.";

        //        else if (ViewState["cycle"].ToString().Trim() != ddlCycle.SelectedValue)
        //            strMessage = " Cycle will be changed to " + ddlCycle.SelectedItem.Text + ", and cause the future trim dates to be impacted.";

        //    }

        //    return strMessage;
        //}



    }
}