コード例 #1
0
ファイル: ModuleController.cs プロジェクト: kickgod/lab
 public ModuleController(LabContext context, ILoadConfigFileService config, IHttpContextAnalysisService analysis, ILoggerService logger)
 {
     _context  = context;
     _config   = config;
     _analysis = analysis;
     _logger   = logger;
 }
コード例 #2
0
ファイル: PrincipalController.cs プロジェクト: kickgod/lab
 public PrincipalController(LabContext context, IEncryptionDataService encryption, IHostingEnvironment hosting, IHttpContextAnalysisService analysis)
 {
     _context    = context;
     _encryption = encryption;
     _hosting    = hosting;
     _analysis   = analysis;
 }
コード例 #3
0
 public SettingController(LabContext context, IHostingEnvironment hosting, ILoadConfigFileService config, IHttpContextAnalysisService analysis)
 {
     _context  = context;
     _hosting  = hosting;
     _config   = config;
     _analysis = analysis;
 }
コード例 #4
0
ファイル: EChartController.cs プロジェクト: kickgod/lab
 public EChartController(LabContext context, IHttpContextAnalysisService analysis, ILoggerService logger, IDataBaseService service)
 {
     _context  = context;
     _analysis = analysis;
     _logger   = logger;
     _service  = service;
 }
コード例 #5
0
        public JsonResult SaveEvents(Event e)
        {
            var status = false;

            using (LabContext db = new LabContext())
            {
                if (e.EventID > 0)
                {
                    // Update the event
                    var v = db.Events.Where(a => a.EventID == e.EventID).FirstOrDefault();
                    if (v != null)
                    {
                        v.Subject     = e.Subject;
                        v.Start       = e.Start;
                        v.End         = e.End;
                        v.Description = e.Description;
                        v.ThemeColor  = e.ThemeColor;
                        v.IsFullDay   = e.IsFullDay;
                    }
                }
                else
                {
                    db.Events.Add(e);
                }
                db.SaveChanges();
                status = true;
            }

            return(new JsonResult {
                Data = new { status = status }
            });
        }
コード例 #6
0
        public MainWindow()
        {
            InitializeComponent();
            using (LabContext db = new LabContext())
            {
                unitOfWork.CompaniesUnits.ListOfCompanies = db.Companies.ToList();
                unitOfWork.EmployeesUnits.ListOfEmployees = db.Employees.ToList();
                db.SaveChanges();
            }


            //var company1 = new Company { Name = "Mila", Cost = 50000000, Adress = "Минск, Бобруйская 6" };
            //var company2 = new Company { Name = "Electrosila", Cost = 150000000, Adress = "Минск, Бобруйская 6" };

            //using (CompaniesContext db = new CompaniesContext())
            //{
            //    db.Companies.Add(company1);
            //    db.Companies.Add(company2);
            //    db.SaveChanges();
            //}

            //using (EmployeesContext db = new EmployeesContext())
            //{
            //    var employee1 = new Employee { Id = 1, Name = "Nikolai", Age = 24, Post = "Consultant", Wage = 400, CompanyName = company1.Name };
            //    var employee2 = new Employee { Id = 2, Name = "Olga", Age = 22, Post = "Salesman", Wage = 500, CompanyName = company1.Name };

            //    db.Employees.Add(employee1);
            //    db.Employees.Add(employee2);
            //    db.SaveChanges();
            //}
        }
コード例 #7
0
ファイル: JudgeController.cs プロジェクト: kickgod/lab
 public JudgeController(IHttpContextAnalysisService analysis, IEncryptionDataService encryption, LabContext context, ILoggerService logger, ILoadConfigFileService config)
 {
     _analysis   = analysis;
     _encryption = encryption;
     _context    = context;
     _logger     = logger;
     _config     = config;
 }
コード例 #8
0
 public AccountController(IEncryptionDataService ncryption, LabContext context, IHttpContextAccessor accessor, IHttpContextAnalysisService analysis, ILoadConfigFileService config)
 {
     _ncryption = ncryption;
     _context   = context;
     _accessor  = accessor;
     _analysis  = analysis;
     _config    = config;
 }
コード例 #9
0
ファイル: ManagerController.cs プロジェクト: kickgod/lab
 public ManagerController(IEncryptionDataService ncryption, LabContext context, IHttpContextAccessor accessor, ILoadConfigFileService config, IHttpContextAnalysisService analysis, ILoggerService logger)
 {
     _ncryption = ncryption;
     _context   = context;
     _config    = config;
     _analysis  = analysis;
     _logger    = logger;
 }
コード例 #10
0
 public ResourceController(LabContext context, IEncryptionDataService encryption, IHostingEnvironment hosting, IHttpContextAnalysisService analysis, IHttpContextAccessor accessor, ILoggerService logger)
 {
     _context  = context;
     _hosting  = hosting;
     _analysis = analysis;
     _accessor = accessor;
     _logger   = logger;
 }
コード例 #11
0
ファイル: ReExamController.cs プロジェクト: kickgod/lab
 public ReExamController(IEmailService email, LabContext context, ILoggerService logger, ILoadConfigFileService config, IHttpContextAnalysisService analysis)
 {
     _email    = email;
     _context  = context;
     _logger   = logger;
     _config   = config;
     _analysis = analysis;
 }
コード例 #12
0
 public SingleController(LabContext context, IEncryptionDataService encryption, IHttpContextAnalysisService analysis, ILoadConfigFileService config, ILoggerService logger)
 {
     _context    = context;
     _encryption = encryption;
     _analysis   = analysis;
     _config     = config;
     _logger     = logger;
 }
コード例 #13
0
        private void SaveEmployees_Click(object sender, RoutedEventArgs e)
        {
            if (DG1 != null && DG1.Items != null && unitOfWork.EmployeesUnits != null)
            {
                using (LabContext db = new LabContext())
                {
                    unitOfWork.EmployeesUnits._EmployeesContext = db;
                    using (var transaction = unitOfWork.EmployeesUnits._EmployeesContext.Database.BeginTransaction())
                    {
                        try
                        {
                            foreach (var employee in unitOfWork.EmployeesUnits.ListOfEmployees)
                            {
                                if (employee is Employee)
                                {
                                    if (unitOfWork.EmployeesUnits._EmployeesContext.Employees.Any(x => x.Id == employee.Id))
                                    {
                                        var emp = unitOfWork.EmployeesUnits._EmployeesContext.Employees.FirstOrDefault(el => el.Id == employee.Id);
                                        if (emp != null)
                                        {
                                            unitOfWork.EmployeesUnits._EmployeesContext.Employees.Attach(emp);
                                            emp.Name        = employee.Name;
                                            emp.Post        = employee.Post;
                                            emp.Wage        = employee.Wage;
                                            emp.Age         = employee.Age;
                                            emp.CompanyName = employee.CompanyName;
                                        }
                                        unitOfWork.EmployeesUnits._EmployeesContext.SaveChanges();
                                    }
                                    else
                                    {
                                        unitOfWork.EmployeesUnits.Save(employee);
                                    }
                                }
                            }

                            foreach (var employee in unitOfWork.EmployeesUnits._EmployeesContext.Employees.ToList())
                            {
                                if (!unitOfWork.EmployeesUnits.ListOfEmployees.Any(elDG => elDG.Id == employee.Id))
                                {
                                    unitOfWork.EmployeesUnits._EmployeesContext.Employees.Remove(employee);
                                }
                            }
                            transaction.Commit();
                            unitOfWork.EmployeesUnits._EmployeesContext.SaveChanges();
                            db.SaveChangesAsync();
                        }
                        catch (Exception ex)
                        {
                            transaction.Rollback();
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
        }
コード例 #14
0
 private void ShowCompanies_Click(object sender, RoutedEventArgs e)
 {
     using (LabContext db = new LabContext())
     {
         unitOfWork.CompaniesUnits._CompaniesContext = db;
         unitOfWork.CompaniesUnits.ListOfCompanies   = unitOfWork.CompaniesUnits._CompaniesContext.Companies.ToList();
         DG2.DataContext = unitOfWork.CompaniesUnits.ListOfCompanies;
         db.SaveChangesAsync();
     }
 }
コード例 #15
0
 private void ShowEmployees_Click(object sender, RoutedEventArgs e)
 {
     using (LabContext db = new LabContext())
     {
         unitOfWork.EmployeesUnits._EmployeesContext = db;
         unitOfWork.EmployeesUnits.ListOfEmployees   = unitOfWork.EmployeesUnits._EmployeesContext.Employees.ToList();
         DG1.DataContext = unitOfWork.EmployeesUnits.ListOfEmployees;
         db.SaveChangesAsync();
     }
 }
コード例 #16
0
 public JsonResult GetEvents()
 {
     using (LabContext db = new LabContext())
     {
         var events = db.Events.ToList();
         return(new JsonResult {
             Data = events, JsonRequestBehavior = JsonRequestBehavior.AllowGet
         });
     }
 }
コード例 #17
0
ファイル: ApplicationController.cs プロジェクト: kickgod/lab
 public ApplicationController(IEmailService email, LabContext context, ILoggerService logger,
                              IHostingEnvironment hosting, IHttpContextAnalysisService analysis, IEncryptionDataService encryption, ILoadConfigFileService config)
 {
     _email      = email;
     _context    = context;
     _logger     = logger;
     _analysis   = analysis;
     _encryption = encryption;
     _config     = config;
 }
コード例 #18
0
        private void SaveCompanies_Click(object sender, RoutedEventArgs e)
        {
            if (DG2 != null && DG2.Items != null && unitOfWork.CompaniesUnits != null)
            {
                using (LabContext db = new LabContext())
                {
                    unitOfWork.CompaniesUnits._CompaniesContext = db;
                    unitOfWork.EmployeesUnits._EmployeesContext = db;
                    foreach (var company in unitOfWork.CompaniesUnits.ListOfCompanies)
                    {
                        if (company is Company)
                        {
                            if (unitOfWork.CompaniesUnits._CompaniesContext.Companies.Any(x => x.Name == company.Name))
                            {
                                var el  = unitOfWork.CompaniesUnits._CompaniesContext.Companies.FirstOrDefault(elDB => elDB.Name == company.Name);
                                var emp = unitOfWork.EmployeesUnits._EmployeesContext.Employees.FirstOrDefault(empDB => empDB.CompanyName == el.Name);
                                if (emp != null)
                                {
                                    unitOfWork.EmployeesUnits._EmployeesContext.Employees.Attach(emp);
                                    emp.CompanyName = company.Name;
                                }
                                if (el != null)
                                {
                                    unitOfWork.CompaniesUnits._CompaniesContext.Companies.Attach(el);
                                    el.Cost   = company.Cost;
                                    el.Adress = company.Adress;
                                    el.Name   = company.Name;
                                }
                                unitOfWork.EmployeesUnits._EmployeesContext.SaveChanges();
                                unitOfWork.CompaniesUnits._CompaniesContext.SaveChanges();
                            }
                            else
                            {
                                unitOfWork.CompaniesUnits.Save(company);
                            }
                        }
                    }

                    foreach (var el in unitOfWork.CompaniesUnits._CompaniesContext.Companies.ToList())
                    {
                        if (!unitOfWork.CompaniesUnits.ListOfCompanies.Any(elDG => el.Name == elDG.Name))
                        {
                            if (unitOfWork.EmployeesUnits.ListOfEmployees.Any(elDG => elDG.CompanyName == el.Name))
                            {
                                unitOfWork.EmployeesUnits._EmployeesContext.Employees.RemoveRange(unitOfWork.EmployeesUnits._EmployeesContext.Employees.Where(x => x.CompanyName == el.Name));
                            }
                            unitOfWork.CompaniesUnits._CompaniesContext.Companies.Remove(el);
                        }
                    }
                    unitOfWork.EmployeesUnits._EmployeesContext.SaveChanges();
                    unitOfWork.CompaniesUnits._CompaniesContext.SaveChanges();
                    db.SaveChangesAsync();
                }
            }
        }
コード例 #19
0
ファイル: DataBaseService.cs プロジェクト: kickgod/lab
        public void FinishPaper(ExaminationPaper paper, LabContext context)
        {
            if (paper != null)
            {
                if (!paper.IsFinish)
                {
                    if (paper.LeaveExamTime <= 1.0)
                    {
                        paper.LeaveExamTime = 0;
                    }

                    paper.IsFinish = true;

                    if (String.IsNullOrEmpty(paper.Review))
                    {
                        paper.Review = "学生未作出评价!";
                    }
                    paper.Score = GetPaperScore(paper.PaperId, context);

                    Student student = context.Student.Find(paper.StudentId);


                    if (student != null)
                    {
                        if (paper.Score >= paper.PassScore)
                        {
                            student.IsPassExam = true;
                        }

                        double middle = Math.Round((paper.Score / paper.TotleScore) * 100, 1);

                        if (middle > student.MaxExamCount)
                        {
                            student.MaxExamScore = (float)middle;
                        }
                    }
                    else
                    {
                        context.LogPricipalOperations.Add(new LogPricipalOperation
                        {
                            PrincpalOperationStatus = PrincpalOperationStatus.Success,
                            AddTime = DateTime.Now,
                            PrincpalOperationCode    = PrincpalOperationCode.SystemRuntimeError,
                            OperationIp              = "系统运行产生!",
                            PrincpalOperationName    = $"试卷ID:{paper.PaperId} ,试卷所属学生学号:{paper.StudentId}",
                            PrincpalOperationContent = "完成试卷的时候发现学生已经被删除! 考试期间管理员删除了学生导致考试异常! 请查看."
                        });
                    }


                    context.SaveChanges();
                }
            }
        }
コード例 #20
0
        public RouteLegService(LabContext db_, IConfiguration config)
        {
            this.db          = db_;
            this.dbSet       = db_.Set <RouteLeg>();
            AppConfiguration = config;

            string key = AppConfiguration["googleApi:Key"];
            string url = AppConfiguration["googleApi:DirectionsUrl"];

            googleApi = new GoogleApi.Direction(key, url);
        }
コード例 #21
0
ファイル: DataBaseService.cs プロジェクト: kickgod/lab
        public bool DeletePaper(ExaminationPaper ePaper, LabContext context)
        {
            if (ePaper != null && context.ExaminationPapers.Any(p => p.PaperId == ePaper.PaperId))
            {
                try
                {
                    context.Database.BeginTransaction();
                    context.Database.ExecuteSqlCommand("Delete from ExamJudgeChoices Where PaperId = @pid", new SqlParameter
                    {
                        Value         = ePaper.PaperId,
                        ParameterName = "@pid",
                        SqlDbType     = SqlDbType.Int
                    });

                    context.Database.ExecuteSqlCommand("Delete from ExamMultipleChoices Where PaperId = @pid", new SqlParameter
                    {
                        Value         = ePaper.PaperId,
                        ParameterName = "@pid",
                        SqlDbType     = SqlDbType.Int
                    });

                    context.Database.ExecuteSqlCommand("Delete from ExamSingleChoices Where PaperId = @pid", new SqlParameter
                    {
                        Value         = ePaper.PaperId,
                        ParameterName = "@pid",
                        SqlDbType     = SqlDbType.Int
                    });

                    context.ExaminationPapers.Remove(ePaper);
                    int result = context.SaveChanges();
                    context.Database.CommitTransaction();
                    return(result == 1);
                }
                catch (Exception e)
                {
                    context.Database.RollbackTransaction();
                    Console.WriteLine(e);
                    throw;
                }
            }
            else
            {
                return(false);
            }
        }
コード例 #22
0
        private void SearchCompanies_Click(object sender, RoutedEventArgs e)
        {
            Company findingObject = null;
            var     list          = new List <Company>();

            using (LabContext db = new LabContext())
            {
                unitOfWork.CompaniesUnits._CompaniesContext = db;
                if (CompanyNameTxtBlock.Text.Count() != 0)
                {
                    findingObject = unitOfWork.CompaniesUnits._CompaniesContext.Companies.Find(CompanyNameTxtBlock.Text);
                }

                if (CompanyCostTxtBlock.Text.Count() != 0)
                {
                    int cost = 0;
                    if (Int32.TryParse(CompanyCostTxtBlock.Text, out cost))
                    {
                        if (CompanyNameTxtBlock.Text.Count() == 0)
                        {
                            list = unitOfWork.CompaniesUnits._CompaniesContext.Companies.ToList().Where(x => x.Cost <= cost).ToList();
                        }
                        else
                        {
                            if (findingObject != null && findingObject.Cost <= cost)
                            {
                                list.Add(findingObject);
                            }
                        }
                    }
                }
                else
                {
                    if (findingObject != null)
                    {
                        list.Add(findingObject);
                    }
                }

                DG2.DataContext = list;

                unitOfWork.CompaniesUnits._CompaniesContext.SaveChangesAsync();
                db.SaveChangesAsync();
            }
        }
コード例 #23
0
        private void SearchEmployee_Click(object sender, RoutedEventArgs e)
        {
            Employee findingObject = null;
            var      list          = new List <Employee>();

            using (LabContext db = new LabContext())
            {
                unitOfWork.EmployeesUnits._EmployeesContext = db;
                if (EmpNameTxtBox.Text.Count() != 0)
                {
                    findingObject = unitOfWork.EmployeesUnits._EmployeesContext.Employees.Where(x => x.Name == EmpNameTxtBox.Text).FirstOrDefault();
                }

                if (EmpAgeTxtBox.Text.Count() != 0)
                {
                    int age = 0;
                    if (Int32.TryParse(EmpAgeTxtBox.Text, out age))
                    {
                        if (EmpNameTxtBox.Text.Count() == 0)
                        {
                            list = unitOfWork.EmployeesUnits._EmployeesContext.Employees.ToList().Where(x => x.Age <= age).ToList();
                        }
                        else
                        {
                            if (findingObject != null && findingObject.Age <= age)
                            {
                                list.Add(findingObject);
                            }
                        }
                    }
                }
                else
                {
                    if (findingObject != null)
                    {
                        list.Add(findingObject);
                    }
                }

                DG1.DataContext = list;

                unitOfWork.EmployeesUnits._EmployeesContext.SaveChangesAsync();
                db.SaveChangesAsync();
            }
        }
コード例 #24
0
        public static ICollection <Strumento> CheckTTL(LabContext context)
        {
            IEnumerable <Strumento> strumenti       = context.Strumento.ToList();
            ICollection <Strumento> strumentiLowTTL = new List <Strumento>();

            foreach (var s in strumenti)
            {
                if (s.TTL != new DateTime())
                {
                    if (DateTime.Today >= s.TTL.AddDays(-5))
                    {
                        var TTL = DateTime.Today - s.TTL;
                        strumentiLowTTL.Add(s);
                    }
                }
            }
            return(strumentiLowTTL);
        }
コード例 #25
0
        public JsonResult DeleteEvent(int eventID)
        {
            var status = false;

            using (LabContext db = new LabContext())
            {
                var v = db.Events.Where(a => a.EventID == eventID).FirstOrDefault();
                if (v != null)
                {
                    db.Events.Remove(v);
                    db.SaveChanges();
                    status = true;
                }
            }

            return(new JsonResult {
                Data = new { status = status }
            });
        }
コード例 #26
0
ファイル: DataBaseService.cs プロジェクト: kickgod/lab
        public int NotJoinSystemStudentCount(LabContext context)
        {
            String sql = "select count(*) from Student where StudentId not in(select StudentId from LogStudentOperations  )";

            if (context.Database.GetDbConnection().State == ConnectionState.Open)
            {
            }
            else
            {
                context.Database.GetDbConnection().Open();
            }
            DbCommand cmd = context.Database.GetDbConnection().CreateCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = sql;
            int result = Convert.ToInt32(cmd.ExecuteScalar());

            return(result);
        }
コード例 #27
0
ファイル: DataBaseService.cs プロジェクト: kickgod/lab
        public float GetPaperScore(int paperId, LabContext context)
        {
            ExaminationPaper paper = context.ExaminationPapers.Find(paperId);

            if (paper == null)
            {
                return(-100.0f);
            }
            else
            {
                float judgeScore = context.ExamJudgeChoices.Where(p => p.PaperId == paper.PaperId)
                                   .Where(p => p.RealAnswer == p.StudentAnswer).Sum(p => p.Score);
                float singleScore = context.ExamSingleChoices.Where(p => p.PaperId == paper.PaperId)
                                    .Where(p => p.RealAnswer == p.StudentAnswer).Sum(p => p.Score);
                float multipleScore = context.ExamMultipleChoices.Where(p => p.PaperId == paper.PaperId)
                                      .Where(p => p.RealAnswer == p.StudentAnswer).Sum(p => p.Score);

                return(judgeScore + singleScore + multipleScore);
            }
        }
コード例 #28
0
        public ActionResult Login(FormCollection form, bool rememberMe = false)
        {
            String Email       = form["Email address"].ToString();
            String EmpPassword = form["Password"].ToString();

            var db          = new LabContext();
            var currentUser = db.Database.SqlQuery <Employee>(
                "Select * " +
                "FROM Employee " +
                "WHERE Email = '" + Email + "' AND " +
                "EmpPassword = '******'");

            var SPcurrentUser = db.Database.SqlQuery <Location>(
                "Select * " +
                "FROM Employee " +
                "INNER JOIN Location On Employee.LocationID = Location.LocationID " +
                "WHERE Email = '" + Email + "' AND " +
                "EmpPassword = '******' AND " +
                "LocationDescription = 'Singapore'");


            if (currentUser.Count() > 0)
            {
                if (SPcurrentUser.Count() > 0)
                {
                    FormsAuthentication.SetAuthCookie(Email, rememberMe);
                    return(RedirectToAction("About", "Home", new { userlogin = Email }));
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(Email, rememberMe);
                    return(RedirectToAction("Index", "Worker", new { userlogin = Email }));
                }
            }
            else
            {
                return(View());
            }
        }
コード例 #29
0
 public StudentViewModel(Student student, LabContext context)
 {
     if (student == null)
     {
         throw new Exception("传入的学生为null");
     }
     this.Name            = student.Name;
     this.LearningTime    = context.Progresses.Where(s => s.StudentId == student.StudentId).Sum(v => v.StudyTime);
     this.MaxScore        = student.MaxExamScore;
     this.ExamTime        = context.ExaminationPapers.Count(p => p.StudentId == student.StudentId);
     this.Sex             = student.Sex ? "男" : "女";
     this.ApplicationTime = context.ApplicationForReExaminations.Count(a => a.StudentId == student.StudentId);
     this.StudentId       = student.StudentId;
     this.Grade           = student.Grade;
     this.IsPass          = student.IsPassExam ? "Yes" : "No";
     this.StudentType     = student.StudentType == Map.StudentType.PostGraduate ? "研究生" : "本科生";
     this.HeadPortrait    = student.Sex ? "student_nan.png" : "student_nv.png";
     this.Email           = student.Email;
     this.InstituteName   = context.Institute.Find(student.InstituteId).Name;
     this.ProfessionName  = context.Professions.Find(student.ProfessionId).Name;
     this.Phone           = student.Phone;
 }
コード例 #30
0
        public ActionResult Login(FormCollection form, bool rememberMe = false)
        {
            String email    = form["Email"].ToString();
            String password = form["Password"].ToString();

            var db          = new LabContext();
            var currentUser = db.Database.SqlQuery <Customer>(
                "Select * " +
                "FROM Customer " +
                "WHERE Email = '" + email + "' AND " +
                "Password = '******'");

            if (currentUser.Count() > 0)
            {
                FormsAuthentication.SetAuthCookie(email, rememberMe);
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View());
            }
        }