public void LoadGrid()
 {
     try
     {
         SMHR_DEPARTMENT_DIVISION_MAPPING _obj_Smhr_DDM = new SMHR_DEPARTMENT_DIVISION_MAPPING();
         _obj_Smhr_DDM.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]);
         DataTable DT = BLL.get_DeptMapping(_obj_Smhr_DDM);
         Rg_DDM.DataSource = DT;
         clearControls();
     }
     catch (Exception ex)
     {
         SMHR.BLL.Error_Log(Session["USER_ID"].ToString(), ex.TargetSite.ToString(), ex.Message.Replace("'", "''"), "DepartmentDivisionMapping", ex.StackTrace, DateTime.Now);
         Response.Redirect("~/Frm_ErrorPage.aspx");
     }
 }
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        try
        {
            SMHR_DEPARTMENT_DIVISION_MAPPING _obj_Smhr_DDM = new SMHR_DEPARTMENT_DIVISION_MAPPING();
            //_obj_Smhr_DDM.ERP_CODE = BLL.ReplaceQuote(rtxt_CountryCode.Text);
            _obj_Smhr_DDM.DEPARTMENT_ID   = Convert.ToInt32(ddl_Department.SelectedItem.Value);
            _obj_Smhr_DDM.DIVISION_ID     = Convert.ToInt32(ddl_Diviison.SelectedItem.Value);
            _obj_Smhr_DDM.CREATEDBY       = Convert.ToInt32(Session["USER_ID"]); // ### Need to Get the Session
            _obj_Smhr_DDM.CREATEDDATE     = DateTime.Now;
            _obj_Smhr_DDM.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]);
            _obj_Smhr_DDM.LASTMDFBY       = Convert.ToInt32(Session["USER_ID"]); // ### Need to Get the Session
            _obj_Smhr_DDM.LASTMDFDATE     = DateTime.Now;
            _obj_Smhr_DDM.BUID            = Convert.ToInt32(rcmb_BU.SelectedItem.Value);
            _obj_Smhr_DDM.STATUS          = Convert.ToString(rcmb_Status.SelectedValue);
            switch (((Button)sender).ID.ToUpper())
            {
            case "BTN_UPDATE":
                _obj_Smhr_DDM.SMHR_DEPARTMENT_DIVISION_MAPPING_ID = Convert.ToInt32(lbl_DivisionID.Text);
                _obj_Smhr_DDM.OPERATION = operation.Update;
                if (BLL.set_SMHR_DEPARTMENT_DIVISION_MAPPING(_obj_Smhr_DDM))
                {
                    BLL.ShowMessage(this, "Information Updated Successfully");
                }
                else
                {
                    BLL.ShowMessage(this, "Information Not Updated");
                }

                break;

            case "BTN_SAVE":
                _obj_Smhr_DDM.OPERATION = operation.Check;
                if (Convert.ToString(BLL.get_DeptMapping(_obj_Smhr_DDM).Rows[0]["Count"]) != "0")
                {
                    BLL.ShowMessage(this, "Mapping Already Exists for Selected Function.");
                    return;
                }
                _obj_Smhr_DDM.OPERATION = operation.Insert;
                if (BLL.set_SMHR_DEPARTMENT_DIVISION_MAPPING(_obj_Smhr_DDM))
                {
                    BLL.ShowMessage(this, "Information Saved Successfully");
                }
                else
                {
                    BLL.ShowMessage(this, "Information Not Saved");
                }
                break;

            default:
                break;
            }
            clearControls();
            Rm_DDM_page.SelectedIndex = 0;
            LoadGrid();
            Rg_DDM.DataBind();
        }
        catch (Exception ex)
        {
            SMHR.BLL.Error_Log(Session["USER_ID"].ToString(), ex.TargetSite.ToString(), ex.Message.Replace("'", "''"), "DepartmentDivisionMapping", ex.StackTrace, DateTime.Now);
            Response.Redirect("~/Frm_ErrorPage.aspx");
        }
    }
    protected void btn_Save_Click(object sender, EventArgs e)
    {
        try
        {
            SMHR_DIVISION _obj_Smhr_Division = new SMHR_DIVISION();
            _obj_Smhr_Division.DIVISION_CODE        = BLL.ReplaceQuote(rtxt_SubDepartment.Text);
            _obj_Smhr_Division.DIVISION_DESCRIPTION = BLL.ReplaceQuote(rtxt_CountryName.Text);
            _obj_Smhr_Division.ORGANISATION_ID      = Convert.ToInt32(Session["ORG_ID"]);
            _obj_Smhr_Division.BUID          = Convert.ToInt32(ddl_BusinessUnit.SelectedItem.Value);
            _obj_Smhr_Division.DEPARTMENT_ID = Convert.ToInt32(rad_Department.SelectedItem.Value);
            _obj_Smhr_Division.CREATEDBY     = Convert.ToInt32(Session["USER_ID"]); // ### Need to Get the Session
            _obj_Smhr_Division.CREATEDDATE   = DateTime.Now;

            _obj_Smhr_Division.LASTMDFBY   = Convert.ToInt32(Session["USER_ID"]); // ### Need to Get the Session
            _obj_Smhr_Division.LASTMDFDATE = DateTime.Now;

            switch (((Button)sender).ID.ToUpper())
            {
            case "BTN_UPDATE":
                _obj_Smhr_Division.DIVISION_ID = Convert.ToInt32(lbl_DivisionID.Text);
                _obj_Smhr_Division.OPERATION   = operation.Update;
                if (BLL.set_Division(_obj_Smhr_Division))
                {
                    BLL.ShowMessage(this, "Information Updated Successfully");
                }
                else
                {
                    BLL.ShowMessage(this, "Information Not Updated");
                }

                break;

            case "BTN_SAVE":
                _obj_Smhr_Division.OPERATION = operation.Check;
                if (Convert.ToString(BLL.get_Division(_obj_Smhr_Division).Rows[0]["Count"]) != "0")
                {
                    BLL.ShowMessage(this, "SubDepartment Already Exists");
                    return;
                }
                _obj_Smhr_Division.OPERATION = operation.Insert;
                if (BLL.set_Division(_obj_Smhr_Division))
                {
                    SMHR_DEPARTMENT_DIVISION_MAPPING _obj_Smhr_DDM = new SMHR_DEPARTMENT_DIVISION_MAPPING();
                    SMHR_DIVISION _obj_Smhr_Divisions = new SMHR_DIVISION();
                    _obj_Smhr_Division.OPERATION = operation.D;
                    DataTable dt = new DataTable();
                    dt = BLL.get_DivisionMapping(_obj_Smhr_Division);
                    if (dt.Rows.Count > 0)
                    {
                        _obj_Smhr_DDM.DIVISION_ID = Convert.ToInt32(dt.Rows[0][0]);
                    }
                    _obj_Smhr_DDM.Type        = "Division";
                    _obj_Smhr_DDM.ERP_CODE    = "0";
                    _obj_Smhr_DDM.OPERATION   = operation.Approve;
                    _obj_Smhr_DDM.CREATEDBY   = Convert.ToInt32(Session["USER_ID"]);   // ### Need to Get the Session
                    _obj_Smhr_DDM.CREATEDDATE = DateTime.Now;

                    _obj_Smhr_DDM.LASTMDFBY   = Convert.ToInt32(Session["USER_ID"]);   // ### Need to Get the Session
                    _obj_Smhr_DDM.LASTMDFDATE = DateTime.Now;

                    BLL.set_DivisionMapping(_obj_Smhr_DDM);
                    BLL.ShowMessage(this, "Information Saved Successfully");
                }
                else
                {
                    BLL.ShowMessage(this, "Information Not Saved");
                }
                break;

            default:
                break;
            }
            Rm_Division_page.SelectedIndex = 0;
            LoadGrid();
            Rg_Division.DataBind();
        }
        catch (Exception ex)
        {
            SMHR.BLL.Error_Log(Session["USER_ID"].ToString(), ex.TargetSite.ToString(), ex.Message.Replace("'", "''"), "DivisionMaster", ex.StackTrace, DateTime.Now);
            Response.Redirect("~/Frm_ErrorPage.aspx");
        }
    }