Example #1
0
    protected void BindUserInfo()
    {
        lblSearch.Text = "";
        EnableTabs();

        string      whereCondition = "";
        int         recCount       = 0;
        HiddenField hidLeftFrame   = ucUser.FindControl("hidLeftFrameBindMode") as HiddenField;

        if (ddlSearch.SelectedItem.Value == "Name")
        {
            if (hidMode.Value == "Search") // serach initiated by button
            {
                whereCondition = " and EM.EmployeeName like '" + txtSearch.Text.Trim() + "%'";
            }
            else
            {
                whereCondition = " and EM.EmployeeName ='" + txtSearch.Text.Trim() + "'";
            }

            bool      user;
            DataTable dtUser = employee.CountUser(whereCondition);
            if (dtUser.Rows.Count > 0 && dtUser != null)
            {
                User     = user = true;
                recCount = dtUser.Rows.Count;
            }
            else
            {
                User     = user = false;
                recCount = 0;
            }
            // employee.CheckUser(whereCondition);

            if (user)
            {
                if ((hidLeftFrameBindMode.Value != "Click" && hidLocSearch.Value.Trim() != "Location") || hidMode.Value == "Search")
                {
                    ucUser.UserInfo = txtSearch.Text.Trim().ToString();
                }

                hidLeftFrameBindMode.Value = "";
                hidLeftFrame.Value         = "";
                hidMode.Value = "";

                ucEmpData.EmployeeName = dtUser.Rows[0]["EmployeeName"].ToString();

                if (hidLocSearch.Value.Trim() == "Location")
                {
                    //ucLocation.BindLocation = whereCondition;
                    divLocation.Style.Add(HtmlTextWriterStyle.Display, "");
                    divUser.Style.Add(HtmlTextWriterStyle.Display, "none");
                }
                else
                {
                    ucUser.SelectedNode = ucEmpData.EmployeeName;
                }
                //ucUser.SelectedNode = ucEmpData.EmployeeName;
                ucSetting.User         = dtUser.Rows[0]["SecUserID"].ToString();
                ucSetting.EmployeeName = ucEmpData.EmployeeName;
                ucSetting.Location     = ucEmpData.EmpLocation;
                ucSecurity.UserName    = ucEmpData.EmployeeName;
                ucSecurity.UserID      = ucSetting.UserID;

                //HighLightTabsheet("employee");
                lblMessage.Text = "";
            }
            else
            {
                //HighLightTabsheet("none");
                lblMessage.Text = "No Records found";
            }
        }

        else if (ddlSearch.SelectedItem.Value == "UserName")
        {
            string whereClause = "SU.UserName like'" + txtSearch.Text.Trim() + "%'";


            string    empName = "";
            bool      user;
            DataTable dtUser    = new DataTable();
            DataTable dtEmpName = employee.GetUserName(whereClause);
            //string empName = employee.GetUserName(whereClause);
            if (dtEmpName != null && dtEmpName.Rows.Count > 0)
            {
                foreach (DataRow drName in dtEmpName.Rows)
                {
                    empName += "'" + drName["EmployeeName"].ToString() + "',";
                }



                empName = (empName != "") ? empName.Remove(empName.Length - 1, 1) : "";

                whereCondition = " and EmployeeName in (" + empName + ")";
                dtUser         = employee.CountUser(whereCondition);
            }
            if (dtUser.Rows.Count > 0 && dtUser != null)
            {
                user     = true;
                recCount = dtUser.Rows.Count;
            }
            else
            {
                user     = false;
                recCount = 0;
            }
            if (user)
            {
                if (hidLeftFrameBindMode.Value != "Click")// && hidLocSearch.Value!="Location")
                {
                    ucUser.UserInfo = txtSearch.Text.Trim().ToString();
                }


                hidLeftFrameBindMode.Value = "";
                hidLeftFrame.Value         = "";
                if (hidLocSearch.Value.Trim() == "Location")
                {
                    ucLocation.BindLocation = whereCondition;
                    divLocation.Style.Add(HtmlTextWriterStyle.Display, "");
                    divUser.Style.Add(HtmlTextWriterStyle.Display, "none");
                }
                else
                {
                    ucUser.UserInfoOnSearch = empName;
                    ucUser.SelectedNode     = ucEmpData.EmployeeName;
                }
                //ucUser.UserInfoOnSearch = empName;
                ucEmpData.EmployeeName = dtUser.Rows[0]["EmployeeName"].ToString();
                //ucUser.SelectedNode = ucEmpData.EmployeeName;
                ucSetting.User         = dtUser.Rows[0]["SecUserID"].ToString();
                ucSetting.EmployeeName = ucEmpData.EmployeeName;
                ucSetting.Location     = ucEmpData.EmpLocation;
                ucSecurity.UserName    = ucEmpData.EmployeeName;
                ucSecurity.UserID      = ucSetting.UserID;

                // HighLightTabsheet("employee");
                lblMessage.Text = "";
            }

            else
            {
                //HighLightTabsheet("none");
                employee.DisplayMessage(MessageType.Failure, "No Records Found", lblMessage);
            }
        }

        hidLocSearch.Value = "";

        lblSearch.Text = recCount.ToString() + " Records Found";
        txtSearch.Text = "";
        upnlData.Update();
        upnlMessage.Update();
        upnlSearchResult.Update();
    }