コード例 #1
0
        private void deleteRole()
        {
            try
            {
                // If linked to a user...
                var query = from r in ctx.Users where r.RoleId == roleId select r;

                if (query.Count() == 0)
                {
                    tblRole post = ctx.tblRoles.FirstOrDefault(p => p.Id == roleId);
                    //post.RoleName = txtRolename.Text;

                    ctx.tblRoles.Remove(post);
                    ctx.SaveChanges();

                    lblError.Text      = "Role Deleted Successfully!";
                    lblError.ForeColor = Color.Lime;

                    getRoles();
                    clear();
                }
                else
                {
                    lblError.Text      = "Error : Role linked to a User";
                    lblError.ForeColor = Color.Yellow;
                }
            }
            catch (Exception)
            {
                lblError.Text      = "Error has occurred!!!";
                lblError.ForeColor = Color.Yellow;
            }
        }
コード例 #2
0
        private void updateRole()
        {
            try
            {
                tblRole p = ctx.tblRoles.FirstOrDefault(r => r.Id == roleId);
                p.Role1  = (chkProdTypeMgt.Checked ? 1 : 0);
                p.Role2  = (chkProdMgt.Checked ? 1 : 0);
                p.Role3  = (chkSalesMgt.Checked ? 1 : 0);
                p.Role4  = (chkPartPay.Checked ? 1 : 0);
                p.Role5  = (chkReturnSales.Checked ? 1 : 0);
                p.Role6  = (chkExpType.Checked ? 1 : 0);
                p.Role7  = (chkPostExp.Checked ? 1 : 0);
                p.Role8  = (chkCompany.Checked ? 1 : 0);
                p.Role9  = (chkRoleMgt.Checked ? 1 : 0);
                p.Role10 = (chkUser.Checked ? 1 : 0);
                p.Role11 = (chkBackup.Checked ? 1 : 0);
                p.Role12 = (chkFinancial.Checked ? 1 : 0);
                p.Role13 = (chkProdList.Checked ? 1 : 0);
                p.Role14 = (chkSalesHistory.Checked ? 1 : 0);
                p.Role15 = (chkExpHistory.Checked ? 1 : 0);
                p.Role16 = (chkProdSold.Checked ? 1 : 0);
                p.Role17 = (chkRetHistory.Checked ? 1 : 0);
                p.Role18 = (chkProdReturn.Checked ? 1 : 0);

                ctx.SaveChanges();
                lblError.Text = "Role updated successfully!";
                clear();
            }
            catch (Exception)
            {
                lblError.Text      = "An error has occurred!";
                lblError.ForeColor = Color.Yellow;
            }
        }
コード例 #3
0
 private void addRole()
 {
     try
     {
         tblRole role = new tblRole()
         {
             RoleName  = txtRolename.Text,
             Role1     = (chkProdTypeMgt.Checked ? 1 : 0),
             Role2     = (chkProdMgt.Checked ? 1 : 0),
             Role3     = (chkSalesMgt.Checked ? 1 : 0),
             Role4     = (chkPartPay.Checked ? 1 : 0),
             Role5     = (chkReturnSales.Checked ? 1 : 0),
             Role6     = (chkExpType.Checked ? 1 : 0),
             Role7     = (chkPostExp.Checked ? 1 : 0),
             Role8     = (chkCompany.Checked ? 1 : 0),
             Role9     = (chkRoleMgt.Checked ? 1 : 0),
             Role10    = (chkUser.Checked ? 1 : 0),
             Role11    = (chkBackup.Checked ? 1 : 0),
             Role12    = (chkFinancial.Checked ? 1 : 0),
             Role13    = (chkProdList.Checked ? 1 : 0),
             Role14    = (chkSalesHistory.Checked ? 1 : 0),
             Role15    = (chkExpHistory.Checked ? 1 : 0),
             Role16    = (chkProdSold.Checked ? 1 : 0),
             Role17    = (chkRetHistory.Checked ? 1 : 0),
             Role18    = (chkProdReturn.Checked ? 1 : 0),
             CreatedBy = Form1.userId,
             CreatedOn = System.DateTime.Now
         };
         ctx.tblRoles.Add(role);
         ctx.SaveChanges();
         lblError.Text = "Role added successfully!";
         clear();
     }
     catch (Exception)
     {
         lblError.Text      = "Database error has occurred!";
         lblError.ForeColor = Color.Yellow;
     }
 }