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(); } }
public void OnRegiseter(RegisterEventArgs e) { RegisterEventHandler handler = Regiseters; if (handler != null) { handler(this, e); } }
/// <summary> /// 移除事件 /// </summary> /// <param name="_key">事件ID</param> /// <param name="_func">需要移除事件对应的函数</param> public static void RemoveEvent(string _key, RegisterEventHandler _func) { if (m_eventDic.ContainsKey(_key)) { if (m_eventDic[_key].Contains(_func)) { m_eventDic[_key].Remove(_func); } else { Debug.LogError("INVALID KEY"); } } else { Debug.LogError("INVALID KEY"); } }
/// <summary> /// 消息注册 /// </summary> /// <param name="_key">事件ID</param> /// <param name="_func">相应事件函数</param> public static void RegisterEvent(string _key, RegisterEventHandler _func) { if (m_eventDic.ContainsKey(_key)) { if (m_eventDic[_key].Contains(_func)) { Debug.LogError("NO REPETITION"); } else { m_eventDic[_key].Add(_func); } } else { m_eventDic.Add(_key, new List <RegisterEventHandler>()); m_eventDic[_key].Add(_func); } }
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(); } }
/// <summary> /// 发送事件 /// </summary> /// <param name="_key">事件ID</param> /// <param name="_obj">本次事件携带的参数</param> public static void SendEvent(string _key, params object[] _obj) { if (m_eventDic.ContainsKey(_key)) { if (m_eventDic[_key].Count > 0) { for (int i = 0; i < m_eventDic[_key].Count; i++) { RegisterEventHandler t_eventAction = m_eventDic[_key][i]; t_eventAction(_obj); } } else { Debug.LogError("INVALID KEY"); } } else { Debug.LogError("INVALID KEY"); } }
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); }