/// <summary> /// 绑定全部学年信息到ComboBox /// </summary> /// <param name="comboBox"></param> public static void BindActiveYearEntitytoCombobox(ComboBox comboBox) { try { ActiveYear_BLL ActiveYearBLL = new ActiveYear_BLL(); var AllActiveYearList = ActiveYearBLL.GetActiveYearForComboBox(); CommonUIDataBindMethod.BindComboBox(comboBox, AllActiveYearList, "ATName", "ATID", "--所有学期--"); comboBox.SelectedValue = AllActiveYearList.Find(d => d.State == "当前").ATID; ActiveYearBLL = null; } catch (Exception ex) { MessageBox.Show("程序发生错误,信息: " + ex.Message); } }
private void buttonKCB2Excel_Click(object sender, EventArgs e) { if (comboBox_Activeyear.Items.Count > 0) { bool finderr = false; ActiveYear_BLL A_BLL = new ActiveYear_BLL(); int atyid = A_BLL.GetNowActvieYearID(); try { atyid = ConvertHelper.ConvertStringToInt(comboBox_Activeyear.SelectedValue.ToString()); } catch { MessageBox.Show("错误"); } string title = "大连科技学院" + A_BLL.GetAllEntityFromDAL().Find(d => d.ATID == atyid).ATName + "课程表"; string filefullname = System.Environment.CurrentDirectory + @"\" + title + ".xlsx"; MessageBox.Show(filefullname); if (System.IO.File.Exists(filefullname)) { try { System.IO.File.Delete(filefullname); } catch { finderr = true; MessageBox.Show("文件占用中无法删除!"); } } Cschedule_BLL C_BLL = new Cschedule_BLL(); try { MakeExcelModel MEM = new MakeExcelModel(); MEM.Filename = filefullname; MEM.TitleName = title; MEM.PassWord = ""; MEM.dataTable = C_BLL.GetKCBFormvw_Cschedule_ForAtyID(atyid); MEM.HeaderText = new List <string> { "课程代码", "课程名称", "教学班级名称", "人数", "任课教师", "起始周", "结束周", "单双周", "星期", "节数", "教学楼", "教室", "教室容纳人数", "学分", "考核方式", "学时", "课程类型" }; ExcelHelper.SaveToExcel(MEM); } catch { finderr = true; MessageBox.Show("文件占用中无法生成!"); } if (System.IO.File.Exists(filefullname) & finderr == false) { try { System.Diagnostics.Process.Start(filefullname); } catch { MessageBox.Show("当前系统没有安装EXCEL,或者EXCEL注册信息不全,无法自动打开生成的EXCEL,请手工打开!"); } } } }
private void buttonKCB2Excel_Click(object sender, EventArgs e) { if (comboBox_Activeyear.Items.Count>0) { bool finderr = false; ActiveYear_BLL A_BLL = new ActiveYear_BLL(); int atyid = A_BLL.GetNowActvieYearID(); try { atyid = ConvertHelper.ConvertStringToInt(comboBox_Activeyear.SelectedValue.ToString()); } catch { MessageBox.Show("错误"); } string title="大连科技学院" + A_BLL.GetAllEntityFromDAL().Find(d => d.ATID == atyid).ATName + "课程表"; string filefullname = System.Environment.CurrentDirectory +@"\"+title+".xlsx"; MessageBox.Show(filefullname); if (System.IO.File.Exists(filefullname)) { try { System.IO.File.Delete(filefullname); } catch { finderr = true; MessageBox.Show("文件占用中无法删除!"); } } Cschedule_BLL C_BLL = new Cschedule_BLL(); try { MakeExcelModel MEM = new MakeExcelModel(); MEM.Filename = filefullname; MEM.TitleName = title; MEM.PassWord = ""; MEM.dataTable = C_BLL.GetKCBFormvw_Cschedule_ForAtyID(atyid); MEM.HeaderText = new List<string> { "课程代码", "课程名称", "教学班级名称", "人数", "任课教师", "起始周", "结束周", "单双周", "星期", "节数", "教学楼", "教室", "教室容纳人数" }; ExcelHelper.SaveToExcel(MEM); } catch { finderr = true; MessageBox.Show("文件占用中无法生成!"); } if (System.IO.File.Exists(filefullname) & finderr==false) { try { System.Diagnostics.Process.Start(filefullname); } catch { MessageBox.Show("当前系统没有安装EXCEL,或者EXCEL注册信息不全,无法自动打开生成的EXCEL,请手工打开!"); } } } }
public static bool MakeTeacherKCBShowinBrowers(int AtyID, int PSID, string writefilename) { if (AtyID <= 0) { return(false); } StringBuilder filecontent = new StringBuilder(); string filefullname = System.Environment.CurrentDirectory + @"\ShowKCBForTeacher.html"; if (File.Exists(filefullname)) { try { filecontent = FileHelper.ReadFile(filefullname); } catch (Exception) { System.Windows.Forms.MessageBox.Show("读取模板失败"); return(false); } List <ReplaceTagModel> RTMList = new List <ReplaceTagModel>(); Cschedule_BLL C_BLL = new Cschedule_BLL(); ActiveYear_BLL A_BLL = new ActiveYear_BLL(); var actyearname = A_BLL.GetAllEntityFromDAL().Find(d => d.ATID == AtyID).ATName; Vw_Teacher_BLL VT_BLL = new Vw_Teacher_BLL(); Teacher_BLL T_BLL = new Teacher_BLL(); var Teacher = T_BLL.GetAllEntityFromDAL().Find(d => d.PSID == PSID); Department_BLL D_BLL = new Department_BLL(); var KCBList = C_BLL.GetKCBFormvw_Cschedule_ForAtyIandPSID(AtyID, PSID); RTMList.Add(new ReplaceTagModel { TagName = KCBForTeaecherHTMLTag.ActYear(), TagValue = actyearname }); RTMList.Add(new ReplaceTagModel { TagName = KCBForTeaecherHTMLTag.TeacherName(), TagValue = Teacher.PsName }); RTMList.Add(new ReplaceTagModel { TagName = KCBForTeaecherHTMLTag.TeacherCoder(), TagValue = Teacher.StandCode }); RTMList.Add(new ReplaceTagModel { TagName = KCBForTeaecherHTMLTag.DeptName(), TagValue = D_BLL.GetAllEntityFromDAL().Find(d => d.DeptID == Teacher.DeptId).DeptName }); RTMList.Add(new ReplaceTagModel { TagName = KCBForTeaecherHTMLTag.TITLE(), TagValue = actyearname + Teacher.PsName + "的课程表" }); var kcblist = KCBList.OrderBy(d => d.Week).ThenBy(d => d.Section).ThenBy(d => d.StartWeek); if (kcblist != null) { foreach (var kCB in kcblist) { var rtm = RTMList.Find(d => d.TagName == KCBForTeaecherHTMLTag.KCBDayAndSection(kCB.Week, kCB.Section)); if (rtm != null) { if (!string.IsNullOrWhiteSpace(rtm.TagValue)) { rtm.TagValue = rtm.TagValue + "<br>" + kCB.CourseName + "→" + kCB.TCName + " 第" + kCB.StartWeek.ToString() + "-" + kCB.EndWeek.ToString() + "周 " + kCB.RoomName; } } else { RTMList.Add(new ReplaceTagModel { TagName = KCBForTeaecherHTMLTag.KCBDayAndSection(kCB.Week, kCB.Section), TagValue = kCB.CourseName + "→" + kCB.TCName + " 第" + kCB.StartWeek.ToString() + "-" + kCB.EndWeek.ToString() + "周 " + kCB.RoomName }); } } } foreach (var item in RTMList) { filecontent.Replace(item.TagName, item.TagValue); } foreach (var item in KCBForTeaecherHTMLTag.KCBDayAndSection()) { filecontent.Replace(item, string.Empty); } try { FileHelper.WriteFile(writefilename, filecontent); } catch (Exception) { System.Windows.Forms.MessageBox.Show("写入文件失败"); return(false); } return(true); } else { System.Windows.Forms.MessageBox.Show("模板文件" + filefullname + "不存在"); return(false); } }
public static bool MakeTeacherKCBShowinBrowers(int AtyID, int PSID,string writefilename) { if (AtyID<=0) { return false; } StringBuilder filecontent = new StringBuilder(); string filefullname = System.Environment.CurrentDirectory + @"\ShowKCBForTeacher.html"; if (File.Exists(filefullname)) { try { filecontent = FileHelper.ReadFile(filefullname); } catch (Exception) { System.Windows.Forms.MessageBox.Show("读取模板失败"); return false; } List<ReplaceTagModel> RTMList = new List<ReplaceTagModel>(); Cschedule_BLL C_BLL = new Cschedule_BLL(); ActiveYear_BLL A_BLL = new ActiveYear_BLL(); var actyearname = A_BLL.GetAllEntityFromDAL().Find(d => d.ATID == AtyID).ATName; Vw_Teacher_BLL VT_BLL = new Vw_Teacher_BLL(); Teacher_BLL T_BLL = new Teacher_BLL(); var Teacher = T_BLL.GetAllEntityFromDAL().Find(d=>d.PSID==PSID); Department_BLL D_BLL = new Department_BLL(); var KCBList = C_BLL.GetKCBFormvw_Cschedule_ForAtyIandPSID(AtyID, PSID); RTMList.Add(new ReplaceTagModel { TagName =KCBForTeaecherHTMLTag.ActYear(),TagValue = actyearname}); RTMList.Add(new ReplaceTagModel { TagName = KCBForTeaecherHTMLTag.TeacherName(), TagValue = Teacher.PsName } ); RTMList.Add(new ReplaceTagModel { TagName = KCBForTeaecherHTMLTag.TeacherCoder(), TagValue = Teacher.StandCode}); RTMList.Add(new ReplaceTagModel { TagName = KCBForTeaecherHTMLTag.DeptName(), TagValue = D_BLL.GetAllEntityFromDAL().Find(d => d.DeptID ==Teacher.DeptId).DeptName }); RTMList.Add(new ReplaceTagModel { TagName = KCBForTeaecherHTMLTag.TITLE(), TagValue = actyearname + Teacher.PsName + "的课程表" }); var kcblist = KCBList.OrderBy(d => d.Week).ThenBy(d => d.Section).ThenBy(d => d.StartWeek); if (kcblist!=null) { foreach (var kCB in kcblist) { var rtm=RTMList.Find(d => d.TagName == KCBForTeaecherHTMLTag.KCBDayAndSection(kCB.Week, kCB.Section)); if (rtm!=null) { if (!string.IsNullOrWhiteSpace(rtm.TagValue)) { rtm.TagValue = rtm.TagValue + "<br>" + kCB.CourseName + "→" + kCB.TCName + " 第" + kCB.StartWeek.ToString() + "-" + kCB.EndWeek.ToString() + "周 " + kCB.RoomName; } } else { RTMList.Add(new ReplaceTagModel { TagName = KCBForTeaecherHTMLTag.KCBDayAndSection(kCB.Week, kCB.Section), TagValue = kCB.CourseName + "→" + kCB.TCName + " 第" + kCB.StartWeek.ToString() + "-" + kCB.EndWeek.ToString() + "周 " +kCB.RoomName } ) ; } } } foreach (var item in RTMList) { filecontent.Replace(item.TagName, item.TagValue); } foreach (var item in KCBForTeaecherHTMLTag.KCBDayAndSection()) { filecontent.Replace(item, string.Empty); } try { FileHelper.WriteFile(writefilename , filecontent); } catch (Exception) { System.Windows.Forms.MessageBox.Show("写入文件失败"); return false; } return true; } else { System.Windows.Forms.MessageBox.Show("模板文件"+ filefullname + "不存在"); return false; } }