//绑定结课资料规则数据 public void DataBindArchivesItems(string teacherType) { ltlAttachments.Text = string.Empty; DalOperationAboutArchivesItems doac = new DalOperationAboutArchivesItems(); DataTable dv = doac.GetArchivesItemByTeacherType(teacherType, termtag).Tables[0]; DalOperationAboutArchives doaa = new DalOperationAboutArchives(); DalOperationAttachments attachment = new DalOperationAttachments(); Literal ltl = new Literal(); if (dv.Rows.Count == 0) { ltl = new Literal(); ltl.Text = "当前暂无上传结课资料要求<br />"; phUpload.Controls.Add(ltl); } else { StringBuilder sb = new StringBuilder(); sb.Append(string.Format("<table class=\"datagrid2\"><tr><th>以下为{0}上传的结课资料:</th></tr>", teacherType)); for (int i = 0; i < dv.Rows.Count; i++) { sb.Append("<tr><td>" + dv.Rows[i]["archiveItemName"].ToString().Trim() + "</td></tr>"); DataTable dt = doaa.FindArchivesByCourseNo(courseNo, classID, termtag, teacherType, int.Parse(dv.Rows[i]["archiveItemId"].ToString().Trim())).Tables[0]; List<string> attachmentIds = new List<string>(); for (int j = 0; j < dt.Rows.Count; j++) { attachmentIds.Add(dt.Rows[j]["attachmentIds"].ToString().Trim()); } string attachments = attachment.GetAttachmentsList(string.Join(",", attachmentIds.ToArray()), ref iframeCount, false, string.Empty); sb.Append(attachments.Trim().Length == 0 ? "<tr><td>上传文件列表:未上传</td></tr>" : "<tr><td>上传文件列表:" + attachments + "</td></tr>"); } sb.Append("</table>"); ltl = new Literal(); ltl.Text = sb.ToString(); phUpload.Controls.Add(ltl); } }
protected void Page_Load(object sender, EventArgs e) { //查看结课资料 if (!IsPostBack) { DalOperationAboutCourses doac = new DalOperationAboutCourses(); course = doac.GetCoursesByNo(courseNo, classID, termtag); if (course == null) { course = new Courses { courseNo = courseNo, classID = classID, termTag = termtag }; } ltlAttachments.Text = "该课程还没有上传期末资料归档!"; DalOperationAboutArchives doaa = new DalOperationAboutArchives(); if (doaa.IsExistArchivesBycourseNoCompatible(courseNo, classID, termtag) != 0) { string attachmentIds = doaa.FindArchivesByCourseNoCompatible(courseNo, classID, termtag).attachmentIds; DalOperationAttachments attachment = new DalOperationAttachments(); string _attachmentIds = attachment.GetAttachmentsList(attachmentIds, ref iframeCount, false,string.Empty); ltlAttachments.Text = _attachmentIds.Trim().Length == 0 ? "未上传资料" : _attachmentIds; } DataBindArchivesItems("教师"); DataBindArchivesItems("助教"); } }
public int fileFolderType = (int)FileFolderType.archives; //结课资料文件 #endregion Fields #region Methods //绑定结课资料规则数据 public void DataBindArchivesItems() { DalOperationAboutArchivesItems doac = new DalOperationAboutArchivesItems(); DataTable dv = doac.GetArchivesItemByTeacherType(Master.teacherType, Master.termtag).Tables[0]; DalOperationAboutArchives doaa = new DalOperationAboutArchives(); DalOperationAttachments attachment = new DalOperationAttachments(); Literal ltl = new Literal(); if (dv.Rows.Count == 0) { btnUpload.Visible = false; ltl = new Literal(); ltl.Text = "当前暂无上传结课资料要求"; phUpload.Controls.Add(ltl); return; } Table tb = new Table(); tb.CssClass = "tableAddStyleNone"; tb.Width = Unit.Percentage(100); for (int i = 0; i < dv.Rows.Count; i++) { TableRow tr = new TableRow(); TableCell td = new TableCell(); td.HorizontalAlign = HorizontalAlign.Left; td.CssClass = "border"; td.Width = Unit.Percentage(10); HiddenField hid = new HiddenField(); hid.ID = "hid_" + dv.Rows[i]["archiveItemId"].ToString().Trim(); hid.ClientIDMode = ClientIDMode.Static; ltl = new Literal(); ltl.Text = dv.Rows[i]["archiveItemName"].ToString().Trim() + ":"; td.Controls.Add(ltl); td.Controls.Add(hid); tr.Cells.Add(td); td = new TableCell(); td.HorizontalAlign = HorizontalAlign.Left; td.CssClass = "border"; DataTable dt = doaa.FindArchivesByCourseNo(Master.courseNo, Master.classID, Master.termtag, Master.teacherType, int.Parse(dv.Rows[i]["archiveItemId"].ToString().Trim())).Tables[0]; List<string> attachmentIds = new List<string>(); for (int j = 0; j < dt.Rows.Count; j++) { attachmentIds.Add(dt.Rows[j]["attachmentIds"].ToString().Trim()); } string attachments = attachment.GetAttachmentsList(string.Join(",", attachmentIds.ToArray()), ref Master.iframeCount, true, (i + 1).ToString()); ltl = new Literal(); ltl.Text = (attachments.Trim().Length == 0 ? "未上传" : attachments)+ " <input type=\"button\" value=\"为" + dv.Rows[i]["archiveItemName"].ToString().Trim() + "添加一个附件\"" + " onclick=\"addIframe(" + fileFolderType + "," + (i + 1).ToString() + "," + (i + 1).ToString() + ");\" />" + " <b>上传文件大小不超过</b>" + ConfigurationManager.AppSettings["uploadFileLimit"] + "<div id=\"iframes" + (i + 1).ToString() + "\"></div><br />"; hid = new HiddenField(); hid.ID = "hidAttachmentId" + (i + 1).ToString(); hid.ClientIDMode = ClientIDMode.Static; hid.Value = string.Join(",", attachmentIds.ToArray()); td.Controls.Add(ltl); td.Controls.Add(hid); tr.Cells.Add(td); tb.Rows.Add(tr); } phUpload.Controls.Add(tb); }
//结课资料 protected void btnUpload_Click(object sender, EventArgs e) { List<int> listArchiveItemIds = new List<int>(); List<string> listArchivesAttachmentIds = new List<string>(); DalOperationAboutArchives doaa = new DalOperationAboutArchives(); foreach (Control ctlTable in phUpload.Controls) { foreach (Control ctlTableRow in ctlTable.Controls) { foreach (Control ctlTableCell in ctlTableRow.Controls) { foreach (Control ctl in ctlTableCell.Controls) { string _type = ctl.GetType().ToString(); if (_type == "System.Web.UI.WebControls.HiddenField") { if (ctl.ID.StartsWith("hid_")) { listArchiveItemIds.Add(int.Parse(ctl.ID.Split("_".ToCharArray())[1])); } else if (ctl.ID.StartsWith("hidAttachmentId")) { listArchivesAttachmentIds.Add(((HiddenField)ctl).Value); } } } } } } Archives archives = new Archives { courseNo = Request["courseNo"], classID = Server.UrlDecode(Request["classID"]), termTag = Request["termTag"].Trim(), teacherType = Master.teacherType }; for (int i = 0; i < listArchiveItemIds.Count; i++) { archives.archiveItemId = listArchiveItemIds[i]; archives.attachmentIds = listArchivesAttachmentIds[i]; //判断是否存在课程结课资料记录,并返回archiveId int archiveId = doaa.IsExistArchivesBycourseNo(Master.courseNo, Master.classID, Master.termtag, Master.teacherType, archives.archiveItemId); if (archiveId != 0) { archives.archiveId = archiveId; doaa.UpdateArchives(archives); Javascript.ExcuteJavascriptCode("delBeforeUnloadEvent();", Page); Javascript.AlertAndRedirect("上传成功!", "CInfoAttachment.aspx?courseNo=" + archives.courseNo + "&classID=" + Master.classID + "&termtag=" + Master.termtag + "&teacherType=" + Master.teacherType, Page); } else { doaa.AddArchives(archives); Javascript.ExcuteJavascriptCode("delBeforeUnloadEvent();", Page); Javascript.AlertAndRedirect("上传成功!", "CInfoAttachment.aspx?courseNo=" + archives.courseNo + "&classID=" + Master.classID + "&termtag=" + Master.termtag + "&teacherType=" + Master.teacherType, Page); } } }
protected string GetArchivesList(string teacherType, string courseNo, string classID, string termtag) { //已经有的附件数,页面初始化时与前端JS进行交互 int iframeCount = 0; DalOperationAboutArchivesItems doac = new DalOperationAboutArchivesItems(); DataTable dv = doac.GetArchivesItemByTeacherType(teacherType, termtag).Tables[0]; DalOperationAboutArchives doaa = new DalOperationAboutArchives(); DalOperationAttachments attachment = new DalOperationAttachments(); Literal ltl = new Literal(); if (dv.Rows.Count == 0) { return "当前暂无" + teacherType + "上传结课资料的要求<br />"; } else { StringBuilder sb = new StringBuilder(); sb.Append(string.Format("<table class=\"datagrid2\"><tr><th colspan=\"2\">以下为{0}上传的结课资料:</th></tr>", teacherType)); for (int i = 0; i < dv.Rows.Count; i++) { sb.Append("<tr><td width=\"15%\">" + dv.Rows[i]["archiveItemName"].ToString().Trim() + ":</td>"); DataTable dt = doaa.FindArchivesByCourseNo(courseNo, classID, termtag, teacherType, int.Parse(dv.Rows[i]["archiveItemId"].ToString().Trim())).Tables[0]; List<string> attachmentIds = new List<string>(); for (int j = 0; j < dt.Rows.Count; j++) { attachmentIds.Add(dt.Rows[j]["attachmentIds"].ToString().Trim()); } string attachments = attachment.GetAttachmentsList(string.Join(",", attachmentIds.ToArray()), ref iframeCount, false, string.Empty); sb.Append(attachments.Trim().Length == 0 ? "<td>上传文件列表:未上传</td></tr>" : "<td>上传文件列表:" + attachments + "</td></tr>"); } sb.Append("</table>"); return sb.ToString(); } }
//结课资料 protected void btnUpload_Click(object sender, EventArgs e) { List<int> listArchiveItemIds = new List<int>(); List<string> listArchivesAttachmentIds = new List<string>(); DalOperationAboutArchives doaa = new DalOperationAboutArchives(); foreach (Control ctlTable in phUpload.Controls) { foreach (Control ctlTableRow in ctlTable.Controls) { foreach (Control ctlTableCell in ctlTableRow.Controls) { foreach (Control ctl in ctlTableCell.Controls) { string _type = ctl.GetType().ToString(); if (_type == "System.Web.UI.WebControls.HiddenField") { if (ctl.ID.StartsWith("hid_")) { listArchiveItemIds.Add(int.Parse(ctl.ID.Split("_".ToCharArray())[1])); } else if (ctl.ID.StartsWith("hidAttachmentId")) { listArchivesAttachmentIds.Add(((HiddenField)ctl).Value); } } } } } } Archives archives = new Archives { courseNo = Request["courseNo"], classID = Server.UrlDecode(Request["classID"]), termTag = Request["termTag"].Trim(), teacherType = teacherType }; for (int i = 0; i < listArchiveItemIds.Count; i++) { archives.archiveItemId = listArchiveItemIds[i]; archives.attachmentIds = listArchivesAttachmentIds[i]; //判断是否存在课程结课资料记录,并返回archiveId int archiveId = doaa.IsExistArchivesBycourseNo(courseNo, classID, termtag, teacherType, archives.archiveItemId); if (archiveId != 0) { archives.archiveId = archiveId; doaa.UpdateArchives(archives); Javascript.RefreshParentWindow("上传成功!", "/Administrator/ArchivesManage.aspx?fragment=1&termTag=" + termtag + "&locale=" + Server.UrlEncode(locale) + "&keyword=" + Server.UrlEncode(keyword) + "#archive_" + anchor, Page); } else { doaa.AddArchives(archives); Javascript.RefreshParentWindow("上传成功!", "/Administrator/ArchivesManage.aspx?fragment=1&termTag=" + termtag + "&locale=" + Server.UrlEncode(locale) + "&keyword=" + Server.UrlEncode(keyword) + "#archive_" + anchor, Page); } } }