private void FrmOvertimeAddOrUpdate_Load(object sender, EventArgs e) { EmployeeBll empBll = new EmployeeBll(); ProjectBll proBll = new ProjectBll(); myTxtEmpId.SetText(this.Tag.ToString());//加载员工Id string name = empBll.QueryById(this.Tag.ToString()).Name; myTxtEmpName.SetText(name); //加载员工姓名 myTxtReason.SetText("工作需要"); //默认原因 TimePickerFrom.Value = DateTime.Parse("19:00"); //默认开始时间 TimePickerTo.Value = DateTime.Parse("21:00"); //默认结束时间 if (this.Text == "添加信息") { #region 加载该员工项目.显示到listbox中 string empId = myTxtEmpId.GetText().ToUpper().Trim(); if (empId == string.Empty) { return; } listBoxShow.Items.Clear(); ProjectBll pBll = new ProjectBll(); EPRelationBll eBll = new EPRelationBll(); List <string> need = new List <string>(); List <string> have = new List <string>(); need.Clear(); //一个员工id,他可能的项目 包括他负责的项目和他从属的项目 //从项目表中查询.负责的项目.因为关系表中每个项目没有包涵PM pl var pros = pBll.QueryWhenEmpIdLike(empId); if (pros.Count != 0) { foreach (var item in pros) { need.Add(item); } } //从关系表中查询.从属的项目 var epr = eBll.QueryLikeThis(empId); if (epr.Count != 0) { foreach (var item in epr) { have.Add(item); } } need = need.Union(have).ToList(); if (need.Count != 0) { if (need.Count == 1) { myTxtProName.SetText(need[0]); myTxtProName.Enabled = false; EmployeeBll emBll = new EmployeeBll(); ProjectBll prBll = new ProjectBll(); string pl = prBll.QueryByName(myTxtProName.GetText())[0].PLId; string plName = emBll.QueryById(pl).Name; myTxtProPLName.SetText(plName);//加载项目Pl return; } listBoxShow.Visible = true; foreach (var item in need) { listBoxShow.Items.Add(item); } } #endregion } else if (this.Text == "更新信息") { myTxtProName.SetText(thisProName); ProjectBll pb = new ProjectBll(); EmployeeBll eb = new EmployeeBll(); string plid = pb.QueryByName(thisProName)[0].PLId; string plname = eb.QueryById(plid).Name; myTxtProPLName.SetText(plname); dateTime.Value = DateTime.Parse(thisDate); } //使时间选择器值显示时间不显示日期 TimePickerFrom.Format = DateTimePickerFormat.Custom; TimePickerFrom.CustomFormat = "HH':'mm"; TimePickerTo.Format = DateTimePickerFormat.Custom; TimePickerTo.CustomFormat = "HH':'mm"; }
//点击用户控件文本框时发生,文本框显示项目名 private void myTxtProName_Enter(object sender, EventArgs e) { myTxtProPLName.Clear(); #region 加载该员工项目.显示到listbox中 string empId = myTxtEmpId.GetText().ToUpper().Trim(); if (empId == string.Empty) { return; } listBoxShow.Items.Clear(); ProjectBll pBll = new ProjectBll(); EPRelationBll eBll = new EPRelationBll(); List <string> need = new List <string>(); List <string> have = new List <string>(); need.Clear(); //一个员工id,他可能的项目 包括他负责的项目和他从属的项目 //从项目表中查询.负责的项目.因为关系表中每个项目没有包涵PM pl var pros = pBll.QueryWhenEmpIdLike(empId); if (pros != null) { foreach (var item in pros) { need.Add(item); } } //从关系表中查询.从属的项目 var epr = eBll.QueryLikeThis(empId); if (epr != null) { foreach (var item in epr) { have.Add(item); } } need = need.Union(have).ToList(); if (need != null) { if (need.Count == 1)//如果只有一个项目 { myTxtProName.SetText(need[0]); myTxtProName.Enabled = false; EmployeeBll emBll = new EmployeeBll(); ProjectBll prBll = new ProjectBll(); string pl = prBll.QueryByName(myTxtProName.GetText())[0].PLId; string plName = emBll.QueryById(pl).Name; myTxtProPLName.SetText(plName);//加载项目Pl return; } listBoxShow.Visible = true; foreach (var item in need) { listBoxShow.Items.Add(item); } } else { MessageBox.Show("您未参与任何项目"); return; } #endregion }