Esempio n. 1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack && !IsCallback)
     {
         UserGridView.DataBind();
     }
 }
Esempio n. 2
0
        protected void UserGridViewBind()
        {
            try
            {
                using (Storage db = new Storage())
                {
                    var users = db.Users.Select(u => new
                    {
                        Login    = u.Login,
                        Name     = u.Name,
                        Surname  = u.Surname,
                        Password = u.Password,
                        Role     = u.UserRole.Name,
                        Status   = u.Status
                    }).ToList();

                    UserGridView.DataSource = users;
                    UserGridView.DataBind();
                }
            }
            catch (Exception ex)
            {
                Loger.Log(Response, ex);
            }
        }
Esempio n. 3
0
        protected void UserGridView_SelectedIndexChanged(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                int    rowIndex = Convert.ToInt32(e.CommandArgument);
                string Login    = UserGridView.Rows[rowIndex].Cells[0].Text;


                using (Storage db = new Storage())
                {
                    DAL.User cu = db.Users.Include("UserRole").Where(u => u.Login == Login).FirstOrDefault();

                    if (cu != null)
                    {
                        cu.Status = (cu.Status) ? false : true;
                        db.SaveChanges();
                    }

                    UserGridView.DataBind();
                }
            }
            catch (Exception ex)
            {
                Loger.Log(Response, ex);
            }
        }
Esempio n. 4
0
    void deleteUser()
    {
        if (checkUserExist())
        {
            try
            {
                SqlConnection conn = new SqlConnection(strConn);
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }

                //DELETE 語法
                SqlCommand sqlCmd = new SqlCommand("DELETE FROM user_master_table WHERE user_id = @user_id", conn);

                //接收TextBox值寫入@user_id參數
                sqlCmd.Parameters.AddWithValue("@user_id", UserIDTextBox.Text.Trim()); //Trim 移除前後空白
                sqlCmd.ExecuteNonQuery();
                conn.Close();
                Response.Write("<script>alert('User delete successful!');</script>");
                clearForm();
                UserGridView.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('" + ex.Message + "');</script>");
            }
        }
        else
        {
            Response.Write("<script>alert('Invalid User ID');</script>");
        }
    }
Esempio n. 5
0
        public void LoadBranchList()
        {
            if (UserGridView.RowCount == 0)
            {
                return;
            }

            var       selected = UserGridView.GetFocusedRowCellValue(colusername);
            UserModel user     = user_coll.FirstOrDefault(u => u.username == selected.ToString());

            var UserBranches = user.UserHasBranches.Select(ub => ub.branch_name);

            var Branches    = branch_coll.Where(b => UserBranches.Contains(b));
            var NotBranches = branch_coll.Where(b => !UserBranches.Contains(b));

            BranchGridControl.DataSource = Branches;

            BranchComboBoxEdit.Properties.Items.Clear();
            foreach (BranchModel branch in NotBranches)
            {
                BranchComboBoxEdit.Properties.Items.Add(branch.branch_name);
            }

            BranchGridControl.DataSource = Branches;
        }
Esempio n. 6
0
        private void RemoveUser_Click(object sender, EventArgs e)
        {
            if (!validator.Validate())
            {
                return;
            }

            DialogResult dialog = MessageBox.Show("Yakin ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (dialog != DialogResult.Yes)
            {
                return;
            }

            try
            {
                var        selected  = UserGridView.GetFocusedRowCellValue(colusername);
                UserModel  userModel = user_coll.FirstOrDefault(u => u.username == selected.ToString());
                RolesModel roles     = roles_coll.FirstOrDefault(r => r.rolename == RolesComboBoxEdit.Text);
                userAkses.RevokeRoleFromUser(userModel, roles);
                var users = user_has_roles_coll.Where(uhr => uhr.rolename.rolename == RolesComboBoxEdit.Text).Select(uhr => uhr.username.username);
                UserGridControl.DataSource = user_coll.Where(u => users.Contains(u.username));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 7
0
 private void btnDeleteUserRepo_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
 {
     try
     {
         if (!User.UserInAction("can delete"))
         {
             return;
         }
         var res = UserGridView.GetFocusedRow();
         if (UserGridView.GetFocusedRow() is Users item)
         {
             if (MessageBox.Show("Do you want to delete this?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
             {
                 return;
             }
             UnitOfWork unitOfWork = new UnitOfWork();
             unitOfWork.UsersRepo.Delete(m => m.Id == item.Id);
             unitOfWork.Save();
             Init();
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private void LoadData()
        {
            RegisterAppLayer  ObjAppLayer = new RegisterAppLayer();
            List <RegDetails> listUser    = ObjAppLayer.GetPersonDetails();

            if (listUser.Count > 0)
            {
                UserGridView.Rows.Clear();
                DataGridViewRow row;
                int             i = 0;
                foreach (var RegDetails in listUser)
                {
                    row = new DataGridViewRow();
                    UserGridView.Rows.Add();
                    row = UserGridView.Rows[i];
                    row.Cells["ColFirstName"].Value = RegDetails.FirstName;
                    row.Cells["ColLastName"].Value  = RegDetails.LastName;
                    row.Cells["ColEmail"].Value     = RegDetails.Email;
                    row.Cells["ColMobile"].Value    = RegDetails.Mobile;
                    row.Cells["ColUserName"].Value  = RegDetails.UserName;
                    i++;
                }

                UserGridView.ClearSelection();
            }
        }
        protected void loadUser()
        {
            var conn = new MySqlConnection(strcon);

            conn.Open();
            string           getdata = "SELECT * FROM Users WHERE UserId = '" + UserIdHF.Value + "'";
            var              cmd     = new MySqlCommand(getdata, conn);
            MySqlDataAdapter da      = new MySqlDataAdapter(cmd);
            DataSet          ds      = new DataSet();

            da.Fill(ds);
            int count = ds.Tables[0].Rows.Count;

            if (ds.Tables[0].Rows.Count > 0)
            {
                UserGridView.DataSource = ds;
                UserGridView.DataBind();
            }
            else
            {
                ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
                UserGridView.DataSource = ds;
                UserGridView.DataBind();
                int columncount = UserGridView.Rows[0].Cells.Count;
                lblmsg.Text = " No data found !!!";
            }
            conn.Close();
        }
Esempio n. 10
0
        public void loadGrid()
        {
            string UserQuery = @"SELECT [Patient_ID],[Patient_Name],[Patient_Mobile],[Patient_Address] FROM [dbo].[Patient]";

            UserGridView.DataSource = db.getData(UserQuery);
            UserGridView.DataBind();
        }
        public void PopulateGridview()
        {
            DataTable dtbl = new DataTable();

            using (SqlConnection sqlCon = new SqlConnection(connectionString))
            {
                string UserQuery = @"SELECT [Patient_ID],[Patient_Name],[Patient_Mobile],[Patient_Address] FROM [dbo].[Patient]";
                sqlCon.Open();
                SqlDataAdapter sqlDa = new SqlDataAdapter(UserQuery, sqlCon);

                sqlDa.Fill(dtbl);
            }
            if (dtbl.Rows.Count > 0)
            {
                UserGridView.DataSource = dtbl;
                UserGridView.DataBind();
            }
            else
            {
                dtbl.Rows.Add(dtbl.NewRow());
                UserGridView.DataSource = dtbl;
                UserGridView.DataBind();
                UserGridView.Rows[0].Cells.Clear();
                UserGridView.Rows[0].Cells.Add(new TableCell());
                UserGridView.Rows[0].Cells[0].ColumnSpan      = dtbl.Columns.Count;
                UserGridView.Rows[0].Cells[0].Text            = "No Data Found ..!";
                UserGridView.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
            }
        }
Esempio n. 12
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();

            foreach (GridViewRow row in UserGridView.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    var chkBox = row.Cells[0].FindControl("ChkUser") as CheckBox;
                    if (chkBox.Checked)
                    {
                        string ID  = UserGridView.DataKeys[row.RowIndex].Value + "";
                        var    ddl = row.Cells[row.Cells.Count - 1].FindControl("ddlRole") as DropDownList;
                        var    val = ddl.SelectedValue;
                        sb.AppendLine(string.Format("update XK_User set RoleID=" + val + " where ID=" + ID));
                    }
                }
            }
            if (sb.Length > 0)
            {
                var userBLL = new UserBLL();
                var result  = userBLL.UpdateByCommandString(sb.ToString(), "");
                if (result > 0)
                {
                    lbTip.Text = "修改成功!!!";

                    var userList = userBLL.GetAll(new User(), "");
                    UserGridView.DataSource = userList;
                    UserGridView.DataBind();
                }
            }
        }
Esempio n. 13
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            string whereString = "";

            foreach (GridViewRow row in UserGridView.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    var chkBox = row.Cells[0].FindControl("ChkUser") as CheckBox;
                    if (chkBox.Checked)
                    {
                        string ID = UserGridView.DataKeys[row.RowIndex].Value + "";
                        whereString += ID + ",";
                    }
                }
            }
            if (whereString.Length > 0)
            {
                whereString = " where ID in(" + whereString.TrimEnd(',') + ")";
                var userBLL = new UserBLL();
                var result  = userBLL.UpdateByCommandString("delete from XK_User " + whereString, "");
                if (result > 0)
                {
                    lbTip.Text = "删除成功!!!";

                    var userList = userBLL.GetAll(new User(), "");
                    UserGridView.DataSource = userList;
                    UserGridView.DataBind();
                }
            }
        }
 private void UserGridView_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
 {
     BeginInvoke(new MethodInvoker(delegate
     {
         UserGridView.PostEditor();
         UserGridView.UpdateCurrentRow();
     }));
 }
Esempio n. 15
0
 private void btnEditUserRepo_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
 {
     if (UserGridView.GetFocusedRow() is Users item)
     {
         frmAddEditUser frm = new frmAddEditUser(MethodType.Edit, item);
         frm.ShowDialog();
         Init();
     }
 }
Esempio n. 16
0
    private void BindUserGrid()
    {
        DataTable dt = GetUserRecords();

        if (dt.Rows.Count > 0)
        {
            UserGridView.DataSource = dt;
            UserGridView.DataBind();
        }
    }
Esempio n. 17
0
        public void BindData()
        {
            string where = GetWhere();
            DataTable dt = userManager.GetAllUserMessage(where);

            UserGridView.DataSource = dt;
            UserGridView.AutoResizeColumns(
                DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
            this.UserGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
        }
Esempio n. 18
0
 protected void Page_Load(object sender, EventArgs e)
 {
     ViewState["RoleList"] = BindRole();
     if (!IsPostBack)
     {
         var userBLL  = new UserBLL();
         var userList = userBLL.GetAll(new User(), "");
         UserGridView.DataSource = userList;
         UserGridView.DataBind();
     }
 }
Esempio n. 19
0
        void BindData()
        {
            string           sql = "SELECT * FROM tbl_emp_user JOIN tbl_privilege ON emp_user_privilege=privilege_id";
            MySqlDataAdapter da  = dBScript.getDataSelect(sql);
            DataSet          ds  = new DataSet();

            da.Fill(ds);
            UserGridView.DataSource = ds.Tables[0];
            UserGridView.DataBind();
            lbUserNull.Text = "พบข้อมูลจำนวน " + ds.Tables[0].Rows.Count + " แถว";
        }
Esempio n. 20
0
    public void PopulateUserDetails()
    {
        con.Open();
        cmd = new SqlCommand("select username,Roles.role from users join roles on users.role=roles.roleid where roles.roleid <> 0", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet        ds = new DataSet();

        da.Fill(ds);
        con.Close();
        UserGridView.DataSource = ds;
        UserGridView.DataBind();
    }
        // Populate the page with entity data
        private void PopulatePage()
        {
            List <UserDto> users = UserService.GetUsers();

            if (users.Count > 0)
            {
                UserGridView.DataSource = UserService.GetUsers();
                UserGridView.DataBind();
            }
            else
            {
                hiddenDiv.Visible = true;
            }
        }
Esempio n. 22
0
 protected void UserGridView_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)
 {
     try
     {
         DBAgent = new DataAccessProvider(DataAccessProvider.ParamType.ServerCredentials, ConfigurationManager.AppSettings["DBServerName"], ConfigurationManager.AppSettings["DBUserName"], ConfigurationManager.AppSettings["DBPassword"]);
         DBAgent.AddParameter("@ParamLoginID", e.Keys[0]);
         DBAgent.AddParameter("@ParamUpdatedBy", Session["LoginID"]);
         DBAgent.ExecuteNonQuery("dbo.spDeleteUser");
         e.Cancel = true;
         UserGridView.DataBind();
     }
     catch (Exception ex)
     {
         CommonHelpers.writeLogToFile("UserGridView_RowDeleting: UserManagement.aspx", ex.Message);
     }
 }
 private void UserGridView_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
 {
     try
     {
         UserGridView.GetDataRow(UserGridView.FocusedRowHandle);
         if (UserGridView.FocusedColumn.FieldName == "MASTER")
         {
             if (Convert.ToBoolean(e.Value) == true)
             {
                 UserGridView.SetRowCellValue(UserGridView.FocusedRowHandle, UserGridView.Columns["ADMIN"], false);
                 UserGridView.SetRowCellValue(UserGridView.FocusedRowHandle, UserGridView.Columns["REPORT"], false);
                 UserGridView.SetRowCellValue(UserGridView.FocusedRowHandle, UserGridView.Columns["TRANSACTION"], false);
             }
         }
         if (UserGridView.FocusedColumn.FieldName == "TRANSACTION")
         {
             if (Convert.ToBoolean(e.Value) == true)
             {
                 UserGridView.SetRowCellValue(UserGridView.FocusedRowHandle, UserGridView.Columns["ADMIN"], false);
                 UserGridView.SetRowCellValue(UserGridView.FocusedRowHandle, UserGridView.Columns["REPORT"], false);
                 UserGridView.SetRowCellValue(UserGridView.FocusedRowHandle, UserGridView.Columns["MASTER"], false);
             }
         }
         if (UserGridView.FocusedColumn.FieldName == "ADMIN")
         {
             if (Convert.ToBoolean(e.Value) == true)
             {
                 UserGridView.SetRowCellValue(UserGridView.FocusedRowHandle, UserGridView.Columns["MASTER"], false);
                 UserGridView.SetRowCellValue(UserGridView.FocusedRowHandle, UserGridView.Columns["REPORT"], false);
                 UserGridView.SetRowCellValue(UserGridView.FocusedRowHandle, UserGridView.Columns["TRANSACTION"], false);
             }
         }
         if (UserGridView.FocusedColumn.FieldName == "REPORT")
         {
             if (Convert.ToBoolean(e.Value) == true)
             {
                 UserGridView.SetRowCellValue(UserGridView.FocusedRowHandle, UserGridView.Columns["MASTER"], false);
                 UserGridView.SetRowCellValue(UserGridView.FocusedRowHandle, UserGridView.Columns["ADMIN"], false);
                 UserGridView.SetRowCellValue(UserGridView.FocusedRowHandle, UserGridView.Columns["TRANSACTION"], false);
             }
         }
     }
     catch (Exception ex)
     {
         ProjectFunctions.SpeakError(ex.Message);
     }
 }
Esempio n. 24
0
        private void btnImpersonateRepo_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (UserGridView.GetFocusedRow() is Users item)
            {
                var th = new Thread(() =>
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);

                    BonusSkins.Register();

                    Application.Run(new Main(new string[] { item.Id }));
                });
                th.ApartmentState = ApartmentState.STA;
                th.Start();
            }
        }
Esempio n. 25
0
        //
        // Remove User Button
        //
        private void btnRemoveUser_Click(object sender, EventArgs e)
        {
            string name = UserGridView.CurrentRow.Cells["username"].FormattedValue.ToString();

            if (!name.Equals("admin"))
            {
                commandRows.Add("/user/remove");
                commandRows.Add("=numbers=" + name);
                ExecuteParameterCommand(commandRows);
            }
            else
            {
                MessageBox.Show("Couldn't change User <admin>");
            }
            UserGridView.Refresh();
            UserGridView.Rows.Clear();
            commandRows.Add("/user/print");
            displayUsers(getUsers(commandRows));
        }
Esempio n. 26
0
        private void TambahBranch_Click(object sender, EventArgs e)
        {
            if (!AssignBranchValidationProvider.Validate())
            {
                return;
            }

            if (UserGridView.RowCount == 0)
            {
                return;
            }

            var         selected = UserGridView.GetFocusedRowCellValue(colusername);
            UserModel   user     = user_coll.FirstOrDefault(u => u.username == selected.ToString());
            BranchModel branch   = branch_coll.FirstOrDefault(b => b.branch_name == BranchComboBoxEdit.Text);

            userAkses.AddBranchForUser(user, branch);
            LoadBranchList();
        }
Esempio n. 27
0
        protected void UserGridView_CustomButtonCallback(object sender, DevExpress.Web.ASPxGridViewCustomButtonCallbackEventArgs e)
        {
            try
            {
                securityAgent = new CryptoProvider();
                DBAgent       = new DataAccessProvider(DataAccessProvider.ParamType.ServerCredentials, ConfigurationManager.AppSettings["DBServerName"], ConfigurationManager.AppSettings["DBUserName"], ConfigurationManager.AppSettings["DBPassword"]);
                DBAgent.AddParameter("@ParamLoginID", UserGridView.GetRowValues(e.VisibleIndex, "LoginID"));
                DBAgent.AddParameter("@ParamNewPassword", securityAgent.GetTemporaryPassword());
                DBAgent.AddParameter("@ParamIsTempPassword", 1);
                DBAgent.AddParameter("@ParamComment", "Password reset by Admin");
                DBAgent.ExecuteNonQuery("dbo.spUpdatePassword");

                UserGridView.DataBind();
            }
            catch (Exception ex)
            {
                CommonHelpers.writeLogToFile("UserGridView_CustomButtonCallback: UserManagement.aspx", ex.Message);
            }
        }
Esempio n. 28
0
        private void HapusBranch_Click(object sender, EventArgs e)
        {
            if (!AssignBranchValidationProvider.Validate())
            {
                return;
            }

            if (UserGridView.RowCount == 0)
            {
                return;
            }

            var         selected       = UserGridView.GetFocusedRowCellValue(colusername);
            UserModel   user           = user_coll.FirstOrDefault(u => u.username == selected.ToString());
            var         selectedBranch = BranchGridView.GetFocusedRowCellValue(colbranchname);
            BranchModel branch         = branch_coll.FirstOrDefault(b => b.branch_name == selectedBranch.ToString());

            userAkses.RemoveBranchFromUser(user, branch);
            LoadBranchList();
        }
Esempio n. 29
0
 protected void UserGridView_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
 {
     try
     {
         securityAgent = new CryptoProvider();
         DBAgent       = new DataAccessProvider(DataAccessProvider.ParamType.ServerCredentials, ConfigurationManager.AppSettings["DBServerName"], ConfigurationManager.AppSettings["DBUserName"], ConfigurationManager.AppSettings["DBPassword"]);
         DBAgent.AddParameter("@ParamUserName", e.NewValues["UserName"]);
         DBAgent.AddParameter("@ParamFirstName", e.NewValues["FirstName"]);
         DBAgent.AddParameter("@ParamLastName", e.NewValues["LastName"]);
         DBAgent.AddParameter("@ParamPassword", securityAgent.GetTemporaryPassword());
         DBAgent.AddParameter("@ParamModifiedBy", Session["LoginID"]);
         DBAgent.ExecuteNonQuery("dbo.spAddUser");
         e.Cancel = true;
         UserGridView.CancelEdit();
         UserGridView.DataBind();
     }
     catch (Exception ex)
     {
         CommonHelpers.writeLogToFile("UserGridView_RowInserting: UserManagement.aspx", ex.Message);
     }
 }
Esempio n. 30
0
    protected void editUserButton_Click(object sender, EventArgs e)
    {
        string edit = "Update [dbo].[User] set FirstName = @FirstName, LastName = @LastName, PersonEmail = @Email, PersonPhone=@Phone, JobLevel = @JobLevel, Permission = @Permission, LastUpdatedBy = @LastUpdatedBy, LastUpdated = @LastUpdated where UserID = @user";

        sc.Open();
        SqlCommand edituser = new SqlCommand(edit, sc);

        edituser.Parameters.AddWithValue("@FirstName", HttpUtility.HtmlEncode(txtFirstName.Text));
        edituser.Parameters.AddWithValue("@LastName", HttpUtility.HtmlEncode(txtLastName.Text));
        edituser.Parameters.AddWithValue("@Email", HttpUtility.HtmlEncode(txtEmail.Text));
        edituser.Parameters.AddWithValue("@Phone", HttpUtility.HtmlEncode(txtPhone.Text));
        edituser.Parameters.AddWithValue("@JobLevel", txtJobLevel.SelectedItem.Text);
        edituser.Parameters.AddWithValue("@Permission", txtPermission.SelectedItem.Text);
        edituser.Parameters.AddWithValue("@LastUpdatedBy", Session["User"]);
        edituser.Parameters.AddWithValue("@LastUpdated", DateTime.Now);
        edituser.Parameters.AddWithValue("@user", UserGridView.SelectedRow.Cells[8].Text);

        edituser.ExecuteNonQuery();
        UserGridView.DataBind();
        sc.Close();
    }