Example #1
0
        public List <Module> GetModules(User user, SetofBook set)
        {
            try
            {
                using (var sc = new sysContext())
                {
                    var roleids = sc.Users.Include(u => u.Partners)
                                  .FirstOrDefault(u => u.Id == user.Id).Partners.Select(r => r.Id);
                    var mods = sc.Rights.Where(r => roleids.Contains(r.RoleId) && r.SetofBookId == set.Id && r.Enabled == true)
                               .Select(r => r.LevelTwo.LevelOne.Module).Distinct().ToList();
                    return(mods);

                    #region waive
                    //var roles = sc.Users.Find(user.Id).SRoles.ToList();
                    //var roleids = roles.Select(r => r.Id);
                    //var book = sc.SetofBooks.Find(set.Id);
                    //var rights = sc.Rights.Where(r => r.SetofBooksId == book.Id && r.Enabled == true).ToList();
                    //var rightids = rights.Select(r => r.Id);
                    //var acc = sc.Accredits.Where(a => roleids.Contains(a.RoleId) && rightids.Contains(a.RightId)).ToList();
                    //rightids = acc.Select(a => a.RightId).Distinct();
                    //rights = sc.Rights.Include("LevelTwo")
                    //    .Where(r => rightids.Contains(r.Id)).ToList();
                    //var twoids = rights.Select(r => r.LevelTwoId);
                    //var oneids = sc.LevelTwos.Where(t => twoids.Contains(t.Id)).Select(t => t.LevelOneId).Distinct().ToList();
                    //var mods = sc.LevelOnes.Where(o => oneids.Contains(o.Id)).Select(o => o.Module).ToList();

                    //return mods;
                    #endregion
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Example #2
0
        public static void Run()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // 确保从配置文件中能读取到ConnectionString
            string cnn = withCnn.GetConnectionString("tingSystem");

            if (cnn == null)
            {
                var dia = withCnn.SetCnnUI();
                var r   = dia.ShowDialog();
            }
            if (withCnn.ValidateConnectionString(cnn) == false)
            {
                var dia = withCnn.SetCnnUI();
                var r   = dia.ShowDialog();
            }

            FrmLogin     login = null;
            DialogResult result;
            User         user = null;
            SetofBook    set  = null;
            mainui       main = null;

            do
            {
                login  = new FrmLogin();
                result = login.ShowDialog();
                if (result == DialogResult.No)
                {
                    return;
                }
                user = login.CurrentUser; User = user;
                set  = login.CurrentBook; Set = set; login.Dispose();
                main = new mainui(user, set);
                Application.Run(main);
            } while (main.IsCancel == true);
            #region write log
            var log = new Log()
            {
                UserAcount = user.Account,
                Date       = DateTime.Now,
                Action     = "Exit",
                Entity     = null,
                Content    = null,
                Original   = null
            };
            new sqlLogger().Write(log);
            #endregion
        }
Example #3
0
        private void btnLogin_Click(object sender, EventArgs e)     //登录
        {
            var user   = repo.GetAll <sysContext, User>().FirstOrDefault(u => u.Account == txtLoginId.Text.Trim());
            var result = withSecure.CheckPassword(user.Salt, user.SaltedHashedPassword, txtLoginPwd.Text.Trim());

            if (result)
            {
                CurrentUser       = repo.GetAll <sysContext, User>().FirstOrDefault(u => u.Account == txtLoginId.Text.Trim());
                CurrentBook       = repo.GetAll <sysContext, SetofBook>().First(s => s.Id == Convert.ToInt32(cboSetofBooks.SelectedValue));
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                withInfo.DisplayStatus("用户名或密码错误!", statusInfoLabel, false);
                txtLoginId.Focus();
            }
        }
Example #4
0
 public List <LevelOne> GetLevelOnes(User user, SetofBook set, Module module)
 {
     try
     {
         using (var sc = new sysContext())
         {
             var roleids = sc.Users.Include(u => u.Partners)
                           .FirstOrDefault(u => u.Id == user.Id).Partners.Select(r => r.Id);
             var ones = sc.Rights.Include(r => r.LevelTwo.LevelOne.Module)
                        .Where(r => roleids.Contains(r.RoleId) &&
                               r.SetofBookId == set.Id &&
                               r.Enabled == true &&
                               r.LevelTwo.LevelOne.Module.Id == module.Id)
                        .Select(r => r.LevelTwo.LevelOne).Distinct().ToList();
             return(ones);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }
Example #5
0
File: repo.cs Project: isencher/oio
        /// <summary>
        /// get operation list for specific user
        /// </summary>
        public List <Operation> GetActionButtonText(User user, SetofBook set, LevelTwo leveltwo)
        {
            try
            {
                using (var sc = new sysContext())
                {
                    var roleids = sc.Users.Include(u => u.Partners)
                                  .FirstOrDefault(u => u.Id == user.Id).Partners.Select(r => r.Id);
                    var rightids = sc.Rights.Where(r => roleids.Contains(r.RoleId) &&
                                                   r.SetofBookId == set.Id &&
                                                   r.Enabled == true &&
                                                   r.LevelTwoId == leveltwo.Id)
                                   .Select(r => r.Id).ToList();
                    var ops = sc.Accredits.Where(a => rightids.Contains(a.RightId) &&
                                                 a.Enabled == true).Select(a => a.Operation).ToList();
                    return(ops);

                    #region waive
                    //var roles = sc.Users.Where(u => u.Id == user.Id).Select(u => u.Partners).ToList();
                    //var roleids = sc.Roles.Select(r => r.Id);
                    //var rights = sc.Rights
                    //    .Where(r => r.LevelTwoId == leveltwo.Id && r.SetofBooksId == set.Id).ToList();
                    //var rightids = rights.Select(r => r.Id);
                    //var opids = sc.Accredits
                    //    .Where(a => roleids.Contains(a.RoleId) && rightids.Contains(a.RightId))
                    //    .Select(a => a.OperationId).ToList();
                    //var ops = sc.Operations.Where(o => opids.Contains(o.Id)).ToList();

                    //return ops;
                    #endregion
                }
            }
            catch (Exception ex)
            {
                return(null);

                throw;
            }
        }
Example #6
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="user"></param>
 /// <param name="set"></param>
 public mainui(User user, SetofBook set)
 {
     this.user = user;
     this.set  = set;
     laybottom();
     laytop();
     laystatusbar();
     init();
     this.Load += (sender, e) =>
     {
         #region write log
         var loginstance = new Log()
         {
             UserAcount = user.Account,
             Date       = DateTime.Now,
             Action     = "Login",
             Entity     = null,
             Content    = null,
             Original   = null
         };
         logger.Write(loginstance);
         #endregion
     };
     this.Disposed += (sender, e) =>
     {
         #region write log
         var loginstance = new Log()
         {
             UserAcount = user.Account,
             Date       = DateTime.Now,
             Action     = "Loginout",
             Entity     = null,
             Content    = null,
             Original   = null
         };
         logger.Write(loginstance);
         #endregion
     };
 }
Example #7
0
File: repo.cs Project: isencher/oio
        /// <summary>
        /// get leveltwo list for specific user
        /// </summary>
        public List <LevelTwo> GetLevelTwos(User user, SetofBook set, LevelOne levelone)
        {
            try
            {
                using (var sc = new sysContext())
                {
                    var roleids = sc.Users.Include(u => u.Partners)
                                  .FirstOrDefault(u => u.Id == user.Id).Partners.Select(r => r.Id);
                    var rightids = sc.Rights.Include(r => r.LevelTwo.LevelOne)
                                   .Where(r => roleids.Contains(r.RoleId) &&
                                          r.SetofBookId == set.Id &&
                                          r.Enabled == true &&
                                          r.LevelTwo.LevelOne.Id == levelone.Id)
                                   .Select(r => r.Id).ToList();
                    var twos = sc.LevelTwos.Where(t => rightids.Contains(t.Id)).ToList();
                    return(twos);

                    #region waive
                    //var roles = (from u in sc.Users where u.Id == user.Id select u.SRoles).ToList();
                    //var roles = sc.Users.Find(user.Id).SRoles.ToList();
                    //var roleids = roles.Select(r => r.Id);
                    //var book = sc.SetofBooks.Find(set.Id);
                    //var rightids = sc.Accredits
                    //        .Where(a => roleids.Contains(a.RoleId)).Select(a => a.RightId).ToList();
                    //var twoids = sc.Rights.Where(r => rightids.Contains(r.Id) || r.Enabled == true).Select(r => r.LevelTwoId).ToList();
                    //var twos = sc.LevelTwos.Where(t => twoids.Contains(t.Id) || t.LevelOneId == levelone.Id).ToList();

                    //return twos;
                    #endregion
                }
            }
            catch (Exception e)
            {
                return(null);

                throw;
            }
        }