private void registerProjectBtn_Click(object sender, EventArgs e) { int id = 0; int maxHours = 0; string name = nameTextBox.Text; string description = descriptionTextBox.Text; DateTime beginDate = startDateTimePicker.Value; DateTime endDate = endDateTimePicker.Value; if (IsValidId(ref id) && IsValidName(name) && IsValidDescription(description) && IsValidHours(ref maxHours) && IsValidEndDate(beginDate, endDate)) { RegisterEventArgs args = new RegisterEventArgs(); args.Project = new Project() { ProjectId = id, ProjectName = name, ProjectBegin = beginDate, ProjectEnd = endDate, ProjectDescription = description, ProjectStatus = "O", ProjectMaxhours = maxHours }; RegisterEventHandler?.Invoke(this, args); this.Close(); } }
private void addTaskBtn_Click(object sender, EventArgs e) { int taskHours = 0; string projectName = projectComboBox.Text; string task = taskTextBox.Text; DateTime taskDate = taskDateTimePicker.Value; Project project = this.db.Projects.Include(p => p.ProjectMonths).First(p => p.ProjectName == projectName); if (project.ProjectStatus == "C") { MessageBox.Show($"Tasks cannot be added to finished project!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } decimal employeeMaxWorkingHoursOnProject = project.ProjectMaxhours != null ? (decimal)project.ProjectMaxhours : (decimal)int.MaxValue; decimal employeeCurrentWorkingHoursOnProject = this.employee.ProjectHours.Where(ph => ph.ProjectId == project.ProjectId).Sum(ph => ph.ProjectHours1); if (IsValidTask(task) && IsValidHours(ref taskHours, employeeCurrentWorkingHoursOnProject, employeeMaxWorkingHoursOnProject) && IsValidDate(taskDate, project, employee)) { var projectTask = new ProjectHours() { ProjectTask = task, ProjectHours1 = taskHours, ProjectTaskdate = taskDate }; var args = new RegisterEventArgs() { ProjectName = projectName, ProjectTask = projectTask }; RegisterEventHandler?.Invoke(this, args); this.Close(); } }
private static void RegisterHandle(ContainerBuilder builder, string startWithName, Assembly executingAssembly = null) { if (executingAssembly == null) { executingAssembly = Assembly.GetExecutingAssembly(); } var assemblies = AssemblyFinder.Instance(startWithName).FindAll().Union(new[] { executingAssembly }).ToArray(); builder.RegisterAssemblyTypes(assemblies) .Where(type => typeof(ILifetimeDependency).IsAssignableFrom(type) && !type.IsAbstract) .AsSelf() //自身服务,用于没有接口的类 .AsImplementedInterfaces() //接口服务 //.PropertiesAutowired()//属性注入 .InstancePerLifetimeScope(); builder.RegisterAssemblyTypes(assemblies) .Where(type => typeof(IRequestDependency).IsAssignableFrom(type) && !type.IsAbstract) .AsSelf() //自身服务,用于没有接口的类 .AsImplementedInterfaces() //接口服务 //.PropertiesAutowired()//属性注入 .InstancePerRequest(); //保证生命周期基于请求 builder.RegisterAssemblyTypes(assemblies) .Where(type => typeof(ISingleInstanceDependency).IsAssignableFrom(type) && !type.IsAbstract) .AsSelf() //自身服务,用于没有接口的类 .AsImplementedInterfaces() //接口服务 //.PropertiesAutowired()//属性注入 .SingleInstance(); //单例 builder.RegisterAssemblyTypes(assemblies) .Where(type => typeof(IDependency).IsAssignableFrom(type) && !type.IsAbstract) .AsSelf() //自身服务,用于没有接口的类 //.PropertiesAutowired()//属性注入 .AsImplementedInterfaces(); //接口服务 RegisterEventHandler?.Invoke(builder); }