Exemplo n.º 1
0
        private void copyRoles(string user1, string user2)
        {
            //copy role
            var ctx   = gen.GetNewEntity(); // khai bao new entity Framework
            var query = ctx.UserJoinRoles
                        .Where(c => c.UserName == user1 && c.CompanyCode == Globals.companycode);

            foreach (var data in query)
            {
                UserJoinRole obj = new UserJoinRole();
                obj.RoleCode    = data.RoleCode;
                obj.UserName    = user2;
                obj.CompanyCode = data.CompanyCode;
                ctx.UserJoinRoles.Add(obj); //insert
            }
            try
            {
                ctx.SaveChanges();
                XtraMessageBox.Show("Copy roles successfully", "Copy", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            //catch (DbUpdateException ex) // exception khac
            catch (DbUpdateConcurrencyException ex) // exception khac
            {
                XtraMessageBox.Show(ex.Message + ex.StackTrace + ex.TargetSite + ex.InnerException.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        private void btn_DeleteRole_Click(object sender, EventArgs e) // delete role
        {
            // delete UserJoinRole
            UserJoinRole data = new UserJoinRole();// lop UserJoinRole

            data.UserName    = txtuser.Text;
            data.CompanyCode = Globals.companycode;
            data.RoleCode    = txtRole.Text;
            var db = gen.GetNewEntity(); // khai bao new entity Framework

            try
            {
                db.Entry(data).State = System.Data.Entity.EntityState.Deleted; // delete
                db.SaveChanges();
                XtraMessageBox.Show("Deleted successfully", "btn_DeleteRole_Click", MessageBoxButtons.OK, MessageBoxIcon.Information);
                load_lai_grid_role();
            }
            catch (Exception ex) // exception khac
            {
                XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
        private void btn_AddRole_Click(object sender, EventArgs e) // add role
        {
            // insert in to UserJoinRole
            UserJoinRole data = new UserJoinRole();// lop UserJoinRole

            data.UserName    = txtuser.Text;
            data.CompanyCode = Globals.companycode;
            data.RoleCode    = txtRole.Text;

            var db = gen.GetNewEntity(); // khai bao new entity Framework

            try
            {
                db.UserJoinRoles.Add(data); //insert
                db.SaveChanges();
                XtraMessageBox.Show("Insert successfully", "tsbtsave_Click", MessageBoxButtons.OK, MessageBoxIcon.Information);
                load_lai_grid_role();
            }
            catch (Exception ex) // exception khac
            {
                XtraMessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }