// Adding new user
        protected void AddNewUser(object sender, EventArgs e)
        {
            string eventLoginID  = ((TextBox)gvwUsers.FooterRow.FindControl("txtNewLoginID")).Text;
            string eventUserName = ((TextBox)gvwUsers.FooterRow.FindControl("txtNewUserName")).Text;
            string eventEmail    = ((TextBox)gvwUsers.FooterRow.FindControl("txtNewEmail")).Text;
            string eventRoles    = ((TextBox)gvwUsers.FooterRow.FindControl("txtNewUserRole")).Text;

            // below to add new event
            CMNUserDataSet courseDS = new CMNUserDataSet();

            CMNUserDataSet.T_CMN001_USERRow userRow = courseDS.T_CMN001_USER.NewT_CMN001_USERRow();
            userRow.USERID        = Utility.NewDataKey();
            userRow.LOGINID       = eventLoginID;
            userRow.USER_NAME     = eventUserName;
            userRow.EMAIL_ADDRESS = eventEmail;
            userRow.STATUS        = "A";
            userRow.USER_ROLE_ARR = eventRoles;

            Utility.UpdateCommonFields(userRow);
            courseDS.T_CMN001_USER.AddT_CMN001_USERRow(userRow);

            _userBC.UpdateTable(courseDS.T_CMN001_USER);
            // end of add new event

            // Rebind Grid view
            this.UserDataBind();
        }
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            if (IsValid && !String.IsNullOrEmpty(this.userName.Text) && pass1.Text.Equals(pass2.Text))
            {
                bool exists = checkExistsUser();

                if (!exists)
                {
                    //ProcessAuthentication(userId
                    CMNUserDataSet userDS = new CMNUserDataSet();
                    CMNUserDataSet.T_CMN001_USERRow userRow = userDS.T_CMN001_USER.NewT_CMN001_USERRow();
                    userRow.USERID        = Utility.NewDataKey();
                    userRow.LOGINID       = this.userName.Text;
                    userRow.USER_NAME     = this.displayName.Text;
                    userRow.EMAIL_ADDRESS = this.email.Text;
                    userRow.STATUS        = Constants.UserStatus.ACTIVE;
                    userRow.USER_ROLE_ARR = Constants.UserRoles.PROCESS_ROLE;
                    userRow.COMPANY_ID    = "-1";// default company

                    Utility.UpdateCommonFields(userRow);
                    userDS.T_CMN001_USER.AddT_CMN001_USERRow(userRow);

                    byte[] saltBytes    = CryptionUtil.GeneratorSalt(this.userName.Text);
                    byte[] encryptedMsg = CryptionUtil.EncryptAESSecruedMsg(pass1.Text, userName.Text, saltBytes);

                    userRow.PASSWORD_HASH      = encryptedMsg;
                    userRow.PASSWORD_HASH_SALT = saltBytes;

                    _bc.SaveUser(userDS);
                    //this.msgTxt.Text = "Successful!";

                    Response.Redirect("~/Public/Login/Login.aspx");
                }
                else
                {
                    ShowMessage("The User Name is already registered, Please using another one and retry.", MessageSeverity.Error);
                }
            }
        }
        // Updating a event
        protected void gvwDash_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            string userId   = ((Label)gvwUsers.Rows[e.RowIndex].FindControl("txtUserId")).Text;
            string loginID  = ((TextBox)gvwUsers.Rows[e.RowIndex].FindControl("txtLoginID")).Text;
            string userName = ((TextBox)gvwUsers.Rows[e.RowIndex].FindControl("txtUserName")).Text;
            string email    = ((TextBox)gvwUsers.Rows[e.RowIndex].FindControl("txtEmail")).Text;
            string userRole = ((TextBox)gvwUsers.Rows[e.RowIndex].FindControl("txtUserRole")).Text;

            // update event start
            CMNUserDataSet userDS = _userBC.getUserDataSetByUserId(userId);

            CMNUserDataSet.T_CMN001_USERRow userRow = (CMNUserDataSet.T_CMN001_USERRow)userDS.T_CMN001_USER.Rows[0];
            userRow.LOGINID       = loginID;
            userRow.USER_NAME     = userName;
            userRow.EMAIL_ADDRESS = email;
            userRow.USER_ROLE_ARR = userRole;

            _userBC.UpdateTable(userDS.T_CMN001_USER);
            // end of add new event

            gvwUsers.EditIndex = -1;
            // Rebind Grid view
            this.UserDataBind();
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Expires     = -1;

            CMNUserDataSet courseDS = new CMNUserDataSet();

            CMNUserDataSet.T_CMN001_USERRow userRow = courseDS.T_CMN001_USER.NewT_CMN001_USERRow();
            IList <UserDTO> userList = new List <UserDTO>();

            if (context.Request.QueryString.Count >= 1)
            {
                UserManageBC _userBC = new UserManageBC();

                String userID = context.Request.QueryString["UserID"];
                String Email  = context.Request.QueryString["Email"];

                if (!string.IsNullOrEmpty(userID))
                {
                    CMNUserDataSet userDS = _userBC.getUserByLoginID(userID);

                    if (userDS.T_CMN001_USER.Rows.Count >= 1)
                    {
                        userRow = (CMNUserDataSet.T_CMN001_USERRow)userDS.T_CMN001_USER.Rows[0];
                        foreach (DataRow item in userDS.T_CMN001_USER.Rows)
                        {
                            if (item["LOGINID"] == null || String.IsNullOrEmpty(item["LOGINID"].ToString()))
                            {
                                continue;
                            }
                            UserDTO user = new UserDTO
                            {
                                UserID    = item["LOGINID"].ToString(),
                                UserEmail = item["EMAIL_ADDRESS"].ToString(),
                            };

                            userList.Add(user);
                        }
                    }
                    else if (!string.IsNullOrEmpty(Email))
                    {// if have the email will insert one new user
                        userRow               = courseDS.T_CMN001_USER.NewT_CMN001_USERRow();
                        userRow.USERID        = Utility.NewDataKey();
                        userRow.LOGINID       = userID;
                        userRow.USER_NAME     = userID;
                        userRow.EMAIL_ADDRESS = Email;
                        userRow.STATUS        = "A";
                        userRow.USER_ROLE_ARR = Constants.UserRoles.MOBILE_PEDIA_ROLE;

                        Utility.UpdateCommonFields(userRow);
                        courseDS.T_CMN001_USER.AddT_CMN001_USERRow(userRow);

                        _userBC.UpdateTable(courseDS.T_CMN001_USER);

                        UserDTO user = new UserDTO
                        {
                            UserID    = userID,
                            UserEmail = Email,
                            IsCreated = "Yes"
                        };

                        userList.Add(user);
                    }
                }
            }

            System.Web.Script.Serialization.JavaScriptSerializer oSerializer =
                new System.Web.Script.Serialization.JavaScriptSerializer();
            string sJSON = oSerializer.Serialize(userList);

            context.Response.Write(sJSON);
        }