protected void GridView_User_List_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow gVR   = GridView_User_List.Rows[e.RowIndex];
            int         index = GridView_User_List.Rows[e.RowIndex].DataItemIndex;

            String userId = ((Label)gVR.Cells[0].FindControl("Label_User_Id")).Text;

            String userName = ((TextBox)gVR.Cells[0].FindControl("TextBox_Name_Edit")).Text;

            BackEndObjects.userDetails userObj = BackEndObjects.userDetails.getUserDetailsbyIdDB(userId);
            //Combine salt and generate the password
            byte[]        plainTextBytes = System.Text.Encoding.UTF8.GetBytes(((TextBox)gVR.Cells[0].FindControl("TextBox_Password_Edit")).Text + userObj.getSalt());
            HashAlgorithm hashConverter  = new SHA256Managed();

            byte[] hashedByteStream = hashConverter.ComputeHash(plainTextBytes);
            String encryptedAndConvertedPassword = Convert.ToBase64String(hashedByteStream);

            String passWord  = encryptedAndConvertedPassword;
            String emailId   = ((TextBox)gVR.Cells[0].FindControl("TextBox_Email_Id_Edit")).Text;
            String contactNo = ((TextBox)gVR.Cells[0].FindControl("TextBox_Contact_No_Edit")).Text;
            String reportsTo = ((DropDownList)gVR.Cells[0].FindControl("DropDownList_Reports_To")).SelectedValue;

            Dictionary <String, String> whereCls  = new Dictionary <string, string>();
            Dictionary <String, String> targetCls = new Dictionary <string, string>();

            whereCls.Add(BackEndObjects.userDetails.USER_DETAILS_COL_BUSINESS_ID, Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString());
            whereCls.Add(BackEndObjects.userDetails.USER_DETAILS_COL_USERID, userId);

            targetCls.Add(BackEndObjects.userDetails.USER_DETAILS_COL_PASSWORD, passWord);
            targetCls.Add(BackEndObjects.userDetails.USER_DETAILS_COL_NAME, userName);
            targetCls.Add(BackEndObjects.userDetails.USER_DETAILS_COL_EMAIL_ID, emailId);
            targetCls.Add(BackEndObjects.userDetails.USER_DETAILS_COL_CONTACT_NO, contactNo);
            targetCls.Add(BackEndObjects.userDetails.USER_DETAILS_COL_REPORTS_TO, reportsTo);

            try
            {
                BackEndObjects.userDetails.updateUserDetailsDB(targetCls, whereCls, DBConn.Connections.OPERATION_UPDATE);
                DataTable dt = (DataTable)Session[SessionFactory.ADMIN_PREF_USER_MGMT_BASIC_USER_DET_GRID];

                dt.Rows[index]["UserName"]  = userName;
                dt.Rows[index]["Password"]  = ((TextBox)gVR.Cells[0].FindControl("TextBox_Password_Edit")).Text;
                dt.Rows[index]["EmailId"]   = emailId;
                dt.Rows[index]["ContactNo"] = contactNo;
                dt.Rows[index]["reportsTo"] = reportsTo;

                GridView_User_List.EditIndex  = -1;
                GridView_User_List.DataSource = dt;
                GridView_User_List.DataBind();
                Session[SessionFactory.ADMIN_PREF_USER_MGMT_BASIC_USER_DET_GRID] = dt;
            }
            catch (Exception ex)
            {
            }
        }
        protected void GridView_User_List_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            Button_All_Reporting_User.Enabled        = false;
            Button_All_Direct_Reporting_User.Enabled = false;
            Button_Show_Access.Enabled = false;

            GridView_User_List.PageIndex     = e.NewPageIndex;
            GridView_User_List.SelectedIndex = -1;
            GridView_User_List.DataSource    = (DataTable)Session[SessionFactory.ADMIN_PREF_USER_MGMT_BASIC_USER_DET_GRID];
            GridView_User_List.DataBind();
        }
        protected void fillBasicUserDetailGrid(String userFilterText)
        {
            Dictionary <String, userDetails> userDetDict = BackEndObjects.MainBusinessEntity.
                                                           getUserDetailsforMainEntitybyIdDB(Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString());

            DataTable dt = new DataTable();

            dt.Columns.Add("UserName");
            dt.Columns.Add("UserId");
            dt.Columns.Add("Password");
            dt.Columns.Add("EmailId");
            dt.Columns.Add("ContactNo");
            dt.Columns.Add("AccessDet");
            dt.Columns.Add("reportsTo");

            int counter = 0;

            foreach (KeyValuePair <String, userDetails> kvp in userDetDict)
            {
                BackEndObjects.userDetails userObj = kvp.Value;

                bool considerRecord = (userFilterText != null && !userFilterText.Equals(""))? (userObj.getUserId().IndexOf(userFilterText.Trim(), StringComparison.InvariantCultureIgnoreCase) >= 0?true:false):true;

                if (considerRecord)
                {
                    dt.Rows.Add();

                    dt.Rows[counter]["UserName"]  = userObj.getName();
                    dt.Rows[counter]["UserId"]    = userObj.getUserId();
                    dt.Rows[counter]["Password"]  = "";
                    dt.Rows[counter]["EmailId"]   = userObj.getEmailId();
                    dt.Rows[counter]["ContactNo"] = userObj.getContactNo();
                    dt.Rows[counter]["AccessDet"] = userObj.getPrivilege();
                    dt.Rows[counter]["reportsTo"] = userObj.getReportsTo();
                    counter++;
                }
            }

            GridView_User_List.DataSource = dt;
            GridView_User_List.DataBind();
            GridView_User_List.SelectedIndex = -1;
            Session[SessionFactory.ADMIN_PREF_USER_MGMT_BASIC_USER_DET_GRID] = dt;
        }
        protected void GridView_Reporting_Users_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            GridViewRow gVR    = GridView_Reporting_Users.Rows[e.RowIndex];
            String      userId = ((Label)gVR.Cells[0].FindControl("Label_UserId")).Text;

            Dictionary <String, String> whereCls   = new Dictionary <string, string>();
            Dictionary <String, String> targetVals = new Dictionary <string, string>();

            whereCls.Add(BackEndObjects.userDetails.USER_DETAILS_COL_USERID, userId);
            whereCls.Add(BackEndObjects.userDetails.USER_DETAILS_COL_BUSINESS_ID, Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString());
            targetVals.Add(BackEndObjects.userDetails.USER_DETAILS_COL_REPORTS_TO, "");
            BackEndObjects.userDetails.updateUserDetailsDB(targetVals, whereCls, DBConn.Connections.OPERATION_UPDATE);

            DataTable dt    = (DataTable)Cache["userMgmtAllDirectReportingUsers"];
            int       index = GridView_Reporting_Users.Rows[e.RowIndex].DataItemIndex;

            dt.Rows[index].Delete();

            DataTable allUsers = (DataTable)Session[SessionFactory.ADMIN_PREF_USER_MGMT_BASIC_USER_DET_GRID];

            for (int i = 0; i < allUsers.Rows.Count; i++)
            {
                if (allUsers.Rows[i]["UserId"].ToString().Equals(userId))
                {
                    allUsers.Rows[i]["reportsTo"] = ""; break;
                }
            }

            Cache["userMgmtAllDirectReportingUsers"] = dt;
            GridView_Reporting_Users.DataSource      = dt;
            GridView_Reporting_Users.DataBind();

            GridView_User_List.DataSource = allUsers;
            GridView_User_List.DataBind();
            Session[SessionFactory.ADMIN_PREF_USER_MGMT_BASIC_USER_DET_GRID] = allUsers;
        }
 protected void GridView_User_List_RowEditing(object sender, GridViewEditEventArgs e)
 {
     GridView_User_List.EditIndex  = e.NewEditIndex;
     GridView_User_List.DataSource = (DataTable)Session[SessionFactory.ADMIN_PREF_USER_MGMT_BASIC_USER_DET_GRID];
     GridView_User_List.DataBind();
 }
        protected void Create_Chain_User_Click(object sender, EventArgs e)
        {
            userDetails udTest = BackEndObjects.userDetails.getUserDetailsbyIdDB(TextBox1.Text);

            if (udTest.getUserId() == null || udTest.getUserId().Equals("")) //New user id
            {
                userDetails uD = new userDetails();
                uD.setMainEntityId(Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString());

                Random ranGen         = new Random();
                int    saltInt        = ranGen.Next(1, 16);
                byte[] plainTextBytes = System.Text.Encoding.UTF8.GetBytes((TextBox2.Text.Equals("") ? TextBox2.Attributes["password"] : TextBox2.Text)
                                                                           + saltInt);
                HashAlgorithm hashConverter    = new SHA256Managed();
                byte[]        hashedByteStream = hashConverter.ComputeHash(plainTextBytes);
                String        encryptedAndConvertedPassword = Convert.ToBase64String(hashedByteStream);

                //uD.setSubEntityId(DropDownList1.SelectedValue);
                uD.setUserId(TextBox1.Text);
                uD.setPassword(encryptedAndConvertedPassword);
                uD.setSalt(saltInt.ToString());
                uD.setName(TextBox_User_Name_NewAccount.Text);

                Dictionary <String, userDetails> userList = MainBusinessEntity.getUserDetailsforMainEntitybyIdDB(uD.getMainEntityId());
                if (userList.ContainsKey(uD.getUserId()))
                {
                    Label2.Visible   = true;
                    Label2.ForeColor = System.Drawing.Color.Red;
                    Label2.Text      = "This user account is already created for your organization";
                }
                else
                {
                    ArrayList uDChains = new ArrayList();
                    uDChains.Add(uD);
                    ActionLibrary.RegistrationActions regstr = new RegistrationActions();
                    try
                    {
                        regstr.completeRegr(uDChains);
                        Label2.Visible   = true;
                        Label2.ForeColor = System.Drawing.Color.Green;
                        Label2.Text      = "Account created successfully. User can login and enter contact details and other details from user preference page.";

                        DataTable dt    = (DataTable)Session[SessionFactory.ADMIN_PREF_USER_MGMT_BASIC_USER_DET_GRID];
                        int       count = dt.Rows.Count;
                        dt.Rows.Add();
                        dt.Rows[count]["UserName"] = uD.getName();
                        dt.Rows[count]["UserId"]   = uD.getUserId();

                        GridView_User_List.DataSource = dt;
                        GridView_User_List.DataBind();
                        Session[SessionFactory.ADMIN_PREF_USER_MGMT_BASIC_USER_DET_GRID] = dt;
                    }
                    catch (Exception ex)
                    {
                        Label2.Visible   = true;
                        Label2.ForeColor = System.Drawing.Color.Red;
                        Label2.Text      = "Account creation failed";
                    }
                }
            }
            else
            {
                Label2.Visible   = true;
                Label2.ForeColor = System.Drawing.Color.Red;
                Label2.Text      = "User Id is not available..please choose another one";
            }
        }