protected void btn_update_Click(object sender, EventArgs e)
    {
        try
        {
            SMHR_MAPING_REFERPAYITEM _OBJ_SMHR_MAPING_REFERPAYITEM = new SMHR_MAPING_REFERPAYITEM();
            _OBJ_SMHR_MAPING_REFERPAYITEM.ID              = Convert.ToInt32(Label5.Text);
            _OBJ_SMHR_MAPING_REFERPAYITEM.STATUS          = Convert.ToInt32(rcmb_status.SelectedItem.Value);
            _OBJ_SMHR_MAPING_REFERPAYITEM.PAYITEMREFERID  = Convert.ToInt32(rcmb_Payitemrefer.SelectedItem.Value);
            _OBJ_SMHR_MAPING_REFERPAYITEM.ORGANISATION_ID = Convert.ToInt32(rcmb_Organisation.SelectedItem.Value);
            _OBJ_SMHR_MAPING_REFERPAYITEM.ORGPAYITEM_ID   = Convert.ToInt32(rcmd_orgpayitem.SelectedItem.Value);
            _OBJ_SMHR_MAPING_REFERPAYITEM.BUSINESSUNIT_ID = Convert.ToInt32(rcmb_businessunit.SelectedItem.Value);

            _OBJ_SMHR_MAPING_REFERPAYITEM.MP_LSTMDFBY   = Convert.ToInt32(Session["USER_ID"]);
            _OBJ_SMHR_MAPING_REFERPAYITEM.MP_LSTMDFDATE = DateTime.Now;

            //_OBJ_SMHR_MAPING_REFERPAYITEM.OPERATION = operation.Validate;
            //DataTable dt = BLL.get_mappingrefpayitem(_OBJ_SMHR_MAPING_REFERPAYITEM);
            if (Convert.ToInt32(rcmb_status.SelectedItem.Value) == 0)
            {
                _OBJ_SMHR_MAPING_REFERPAYITEM.OPERATION = operation.Check;
                DataTable dt1 = BLL.get_mappingrefpayitem(_OBJ_SMHR_MAPING_REFERPAYITEM);
                if (Convert.ToInt32(dt1.Rows[0]["COUNT"].ToString()) > 1)
                {
                    BLL.ShowMessage(this, "Selected Payitem is Already Mapped");
                    return;
                }
                else
                {
                    _OBJ_SMHR_MAPING_REFERPAYITEM.OPERATION = operation.Validate;
                    DataTable dt = BLL.get_mappingrefpayitem(_OBJ_SMHR_MAPING_REFERPAYITEM);
                    if (dt.Rows.Count > 0 && Convert.ToString(dt.Rows[0]["ID"]) != Convert.ToString(Label5.Text))
                    {
                        BLL.ShowMessage(this, "Selected Payitem is Already Mapped");
                        return;
                    }
                }
            }

            _OBJ_SMHR_MAPING_REFERPAYITEM.OPERATION = operation.Update;

            if (BLL.set_mappingrefpayitem(_OBJ_SMHR_MAPING_REFERPAYITEM))
            {
                BLL.ShowMessage(this, "Information Updated Successfully");
            }
            else
            {
                BLL.ShowMessage(this, "Information is not Saved");
            }
            RadMultiPage1.SelectedIndex = 0;

            Load_GRID();
            rg_payrollrefitm.DataBind();
        }
        catch (Exception ex)
        {
            SMHR.BLL.Error_Log(Session["USER_ID"].ToString(), ex.TargetSite.ToString(), ex.Message.Replace("'", "''"), "frm_mapingrefpaytype", ex.StackTrace, DateTime.Now);
            Response.Redirect("~/Frm_ErrorPage.aspx");
        }
    }
    //protected void rcmb_Organisation_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
    //{
    //    //DataTable dt_payitems = new DataTable();
    //    //_OBJ_PAYROLL_REFEREPAYTYPE.ORG_ID = Convert.ToInt32(rcmb_Organisation.SelectedItem.Value);
    //    //_OBJ_PAYROLL_REFEREPAYTYPE.OPERATION = operation.Select;
    //    //dt_payitems = BLL.get_payitems(_OBJ_PAYROLL_REFEREPAYTYPE);
    //    //rcmd_orgpayitem.DataSource = dt_payitems;
    //    //rcmd_orgpayitem.DataTextField = "PAYITEM_PAYITEMNAME";
    //    //rcmd_orgpayitem.DataValueField = "PAYITEM_ID";
    //    //rcmd_orgpayitem.DataBind();

    //}

    protected void Load_GRID()
    {
        try
        {
            SMHR_MAPING_REFERPAYITEM _OBJ_SMHR_MAPING_REFERPAYITEM = new SMHR_MAPING_REFERPAYITEM();

            _OBJ_SMHR_MAPING_REFERPAYITEM.OPERATION       = operation.Check1;
            _OBJ_SMHR_MAPING_REFERPAYITEM.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]);
            DataTable dt_grid = new DataTable();
            dt_grid = BLL.get_mappingrefpayitem(_OBJ_SMHR_MAPING_REFERPAYITEM);
            rg_payrollrefitm.DataSource = dt_grid;
            // rg_payrollrefitm.DataBind();
        }
        catch (Exception ex)
        {
            //throw ex;
            SMHR.BLL.Error_Log(Session["USER_ID"].ToString(), ex.TargetSite.ToString(), ex.Message.Replace("'", "''"), "frm_mapingrefpaytype", ex.StackTrace, DateTime.Now);
            Response.Redirect("~/Frm_ErrorPage.aspx");
        }
    }
    protected void link_Edit_Command(object sender, CommandEventArgs e)
    {
        try
        {
            rcmb_Payitemrefer.Enabled = false;
            rcmd_orgpayitem.Enabled   = false;
            rcmb_Organisation.Enabled = false;
            btn_save.Visible          = false;
            rcmb_businessunit.Enabled = false;
            //btn_update.Visible = true;
            //code for security
            if (Convert.ToInt32(Session["WRITEFACILITY"]) == 2)
            {
                btn_update.Visible = false;
            }

            else
            {
                btn_update.Visible = true;
            }


            SMHR_MAPING_REFERPAYITEM _OBJ_SMHR_MAPING_REFERPAYITEM = new SMHR_MAPING_REFERPAYITEM();
            _OBJ_SMHR_MAPING_REFERPAYITEM.ID = Convert.ToInt32(e.CommandArgument);
            Label5.Text = Convert.ToString(e.CommandArgument);
            _OBJ_SMHR_MAPING_REFERPAYITEM.OPERATION = operation.Edit;
            DataTable dt_edit = new DataTable();
            dt_edit = BLL.get_mappingrefpayitem(_OBJ_SMHR_MAPING_REFERPAYITEM);

            rcmb_Payitemrefer.DataSource     = dt_edit;
            rcmb_Payitemrefer.DataTextField  = "TYPE";
            rcmb_Payitemrefer.DataValueField = "PAYITEMREFERID";
            rcmb_Payitemrefer.DataBind();

            rcmd_orgpayitem.DataSource     = dt_edit;
            rcmd_orgpayitem.DataTextField  = "PAYITEM_PAYITEMNAME";
            rcmd_orgpayitem.DataValueField = "ORGPAYITEM_ID";
            rcmd_orgpayitem.DataBind();

            rcmb_Organisation.DataSource     = dt_edit;
            rcmb_Organisation.DataTextField  = "ORGANISATION_NAME";
            rcmb_Organisation.DataValueField = "ORGANISATION_ID";
            rcmb_Organisation.DataBind();
            rcmb_businessunit.SelectedIndex = rcmb_businessunit.FindItemIndexByValue(dt_edit.Rows[0]["BUSINESSUNIT_ID"].ToString());

            //        rcmb_status.SelectedItem.Text = "ACTIVE";

            if (dt_edit.Rows[0]["STATUS"].ToString() == "0")
            {
                rcmb_status.SelectedIndex = 0;//dt_edit.Rows[0]["STATUS"].ToString();
            }
            else
            {
                rcmb_status.SelectedIndex = 1;
            }

            //rcmb_Payitemrefer.SelectedItem.Value = Convert.ToString(dt_edit.Rows[0]["PAYITEMREFERID"]);
            //rcmb_Organisation.SelectedItem.Value = Convert.ToString(dt_edit.Rows[0]["ORGANISATION_ID"]);
            //rcmd_orgpayitem.SelectedItem.Value = Convert.ToString(dt_edit.Rows[0]["ORGPAYITEM_ID"]);
            //rcmb_status.SelectedItem.Value = Convert.ToString(dt_edit.Rows[0]["STATUS"]);
            RadMultiPage1.SelectedIndex = 1;
        }
        catch (Exception ex)
        {
            SMHR.BLL.Error_Log(Session["USER_ID"].ToString(), ex.TargetSite.ToString(), ex.Message.Replace("'", "''"), "frm_mapingrefpaytype", ex.StackTrace, DateTime.Now);
            Response.Redirect("~/Frm_ErrorPage.aspx");
        }
    }