/// <summary> /// ������ҵ�ļ���Id�õ���ҵ�ļ��Ķ��� /// </summary> /// <param name="iAssignmentFileID">��ҵ�ļ���Id</param> /// <returns>��ҵ�ļ��Ķ���</returns> public AssignmentFileInfo GetAssignmentFileById(int iAssignmentFileId) { SqlParameter param = new SqlParameter("@assmtFileID", iAssignmentFileId); AssignmentFileInfo assignmentFile = new AssignmentFileInfo(); using (SqlDataReader dr = SQLHelper.ExecuteReader(SQLHelper.ConnectionStringSTEduSys, CommandType.StoredProcedure, "SP_GetAssmtFileByID", param)) { if (dr.Read()) { assignmentFile.IAssignmentFileId = dr.GetInt32(0); assignmentFile.StrFileName = dr.GetString(1); assignmentFile.StrFileTrueName = dr.GetString(2); assignmentFile.DtSubmitTime = dr.GetDateTime(3); assignmentFile.StrFileURL = dr.GetString(4); assignmentFile.IGroupId = dr.GetInt32(5); assignmentFile.IAssignmentId = dr.GetInt32(6); } } return assignmentFile; }
/// <summary> /// (未上传则)上传作业/(已上传则)重新上传作业 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUp_Click(object sender, EventArgs e) { this.lbtUp.Enabled = false; this.btSubmit.Enabled = false; //贡献分 DataTable member = new Search().GetMenbersByGroupId(Convert.ToInt32(HiddenField2.Value)); List<int> members = new List<int>(); List<int> scores = new List<int>(); int sumScore = 0; for (int i = 0; i < member.Rows.Count; i++) { members.Add(Convert.ToInt32(member.Rows[i]["ID"])); string score = ((TextBox)StuScores.Controls[i].Controls[1]).Text; if (score == "") { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('成员贡献分不可为空!')</script>"); return; } scores.Add(Convert.ToInt32(score)); sumScore += scores[i]; } if (sumScore > 100) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('成员贡献分之和超出100!')</script>"); return; } else if (sumScore < 100) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('成员贡献分之和不足100!')</script>"); return; } bool fileIsValid = false; //如果确认了上传文件,则判断文件类型是否符合要求 if (this.InputFile1.HasFile) { //获取上传文件的后缀 String fileExtension = System.IO.Path.GetExtension(this.InputFile1.FileName).ToLower(); String[] restrictExtension = { ".rar", ".zip" }; //判断文件类型是否符合要求 for (int i = 0; i < restrictExtension.Length; i++) { if (fileExtension == restrictExtension[i]) { fileIsValid = true; } } //////////////////////////////////////////////////////////// /////可以增加一条,时间过期,不准再上传文件 ////其实这样子写数据库操作很不规范,真正的三层架构是不许这样子写的, ////但是时间原因和编码人员的习惯问题导致,希望后续人员能够改进 //////////////////////////////////////////////////////////// //连接数据库 SqlConnection sqlCon = CC.GetConnection(); //定义SQL语句 int assmtID = Convert.ToInt32(HiddenField1.Value); string SqlStr = "select * from Assignment where ID=" + assmtID; //实例化SqlDataAdapter对象 SqlDataAdapter da = new SqlDataAdapter(SqlStr, sqlCon); //实例化数据集DataSet DataSet ds = new DataSet(); da.Fill(ds, "GroupAssmtInfo"); DateTime deadline = Convert.ToDateTime(ds.Tables["GroupAssmtInfo"].Rows[0][4]); DateTime time = DateTime.Now; sqlCon.Close(); //连接数据库 SqlConnection sqlCon1 = CC.GetConnection(); //定义SQL语句 //int assmtID = Convert.ToInt32(HiddenField1.Value); int grpID = Convert.ToInt32(HiddenField2.Value); string SqlStr1 = "select * from Assignment_Group where assignmentID=" + assmtID + " and groupID=" + grpID; //实例化SqlDataAdapter对象 SqlDataAdapter da1 = new SqlDataAdapter(SqlStr1, sqlCon1); //实例化数据集DataSet DataSet ds1 = new DataSet(); da1.Fill(ds1, "AssmtFile"); bool n = ds1.Tables["AssmtFile"].Rows[0][7] == DBNull.Value ? false : true; sqlCon1.Close(); if (time < deadline) { //如果文件类型符合要求,调用moveto方法实现上传,并显示相关信息;在此处修改贡献分 if (fileIsValid == true) { if (new Student().AttributeScores(members, scores, Convert.ToInt32(HiddenField1.Value), Convert.ToInt32(HiddenField2.Value))) { try { //胡媛媛修改,上传大文件到服务器,2010-3-11,修改作业上传的位置,2010-6-11 string FilePath = Server.MapPath("..//") + "SiteFile" + "\\" + "homework"; // this.FileUpload1.SaveAs(FilePath + "//" + FileUpload1.FileName); string SaveFileName = FilePath + "\\" + InputFile1.FileName; // this.InputFile1.MoveTo(SaveFileName, Brettle.Web.NeatUpload.MoveToOptions.Overwrite); //胡媛媛修改,上传大文件到服务器,2010-3-11,修改作业上传的位置,2010-6-11 ///////////////////////////////////////////////////////////////////////////// /////////////向数据库里相关表里插入一条记录并改变其他表相关字段的值 //////////////////////////////////////////////////////////////////////////// if (false == n)//n=1的时候是第一次上传文件 { bool success = false; AssignmentFile afile = new AssignmentFile(); AssignmentFileInfo afileInfo = new AssignmentFileInfo(); afileInfo.StrFileName = InputFile1.FileName; afileInfo.StrFileTrueName = "[" + new AssignmentFile().GetAutoId() + "]" + InputFile1.FileName; afileInfo.StrFileURL = FilePath + "\\" + afileInfo.StrFileTrueName; afileInfo.IAssignmentId = Convert.ToInt32(HiddenField1.Value); afileInfo.IGroupId = Convert.ToInt32(HiddenField2.Value); afileInfo.DtSubmitTime = DateTime.Now; //上传文件的函数,想数据库中添加 success = afile.UploadAssignmentFile(afileInfo); if (true == success) { //胡媛媛修改,调整文件保存的位置,使其先删除后保存,2010-6-4 this.InputFile1.MoveTo(afileInfo.StrFileURL, Brettle.Web.NeatUpload.MoveToOptions.Overwrite); //胡媛媛修改,调整文件保存的位置,使其先删除后保存,2010-6-4 this.Label1.Text = "上传成功!"; Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('上传成功!');location=location;</script>"); n = true; return; } else { //回滚 string myupdate = "delete Assignment_Group where assignmentID='" + assmtID + "'and groupID=' " + grpID + "'"; sqlCon1.Open(); SqlCommand mycmd = new SqlCommand(myupdate, sqlCon1); mycmd.ExecuteNonQuery(); sqlCon1.Close(); this.Label1.Text = "上传失败!"; } } else { //重新上传 //胡媛媛添加,获取原来上传的文件ID,2010-03-03 int assmfileid = Convert.ToInt32(ds1.Tables["AssmtFile"].Rows[0][0]); //胡媛媛添加,获取原来上传的文件ID,2010-03-03 bool success = false; AssignmentFile afile = new AssignmentFile(); AssignmentFileInfo afileInfo = new AssignmentFileInfo(); afileInfo.StrFileName = InputFile1.FileName; afileInfo.StrFileTrueName = "[" + new AssignmentFile().GetAutoId() + "]" + InputFile1.FileName; afileInfo.StrFileURL = FilePath + "\\" + afileInfo.StrFileTrueName; afileInfo.IAssignmentId = Convert.ToInt32(HiddenField1.Value); afileInfo.IGroupId = Convert.ToInt32(HiddenField2.Value); afileInfo.DtSubmitTime = DateTime.Now; //胡媛媛添加,得到原来上传的文件Id,2010-03-03 afileInfo.IAssignmentFileId = assmfileid; //胡媛媛添加,得到原来上传的文件Id,2010-03-03 success = afile.ReuploadAssignmentFile(afileInfo); if (true == success) { //胡媛媛修改,调整文件保存的位置,使其先删除后保存,2010-6-4 this.InputFile1.MoveTo(afileInfo.StrFileURL, Brettle.Web.NeatUpload.MoveToOptions.Overwrite); //胡媛媛修改,调整文件保存的位置,使其先删除后保存,2010-6-4 this.Label1.Text = "上传成功!"; Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "<script>alert('上传成功!');location=location;</script>"); n = true; //Response.AddHeader("Refresh", "0"); return; } else { this.Label1.Text = "上传失败!"; n = true; } } } catch { this.Label1.Text = "文件上传不成功!"; } } else { this.Label1.Text = "服务器繁忙,请稍后再试!"; } } else { this.Label1.Text = "只能是.zip或.rar文件"; } } else { this.Label1.Text = "超过作业要求上传最后期限,不能上传!"; } } else { this.Label1.Text = "未选择需上传的文件"; } }
/// <summary> /// �ϴ���ҵʱ�����ҵ�ļ� /// </summary> /// <param name="mAssignmentFile">����ӵ���ҵ�ļ���������Ӧ�����ļ��������Id,��ҵ��Id, /// ϵͳ�Զ������ļ��ϴ�ʱ��Ϊ��ǰʱ��</param> /// <returns>����Ƿ�ɹ�����ɹ���true,����false</returns> public bool UploadAssignmentFile(AssignmentFileInfo mAssignmentFile) { SqlParameter[] parms = { new SqlParameter("@fileName",mAssignmentFile.StrFileName), new SqlParameter("@fileTrueName",mAssignmentFile.StrFileTrueName), new SqlParameter("@submitTime",DateTime.Now), new SqlParameter("@fileURL",mAssignmentFile.StrFileURL), new SqlParameter("@groupID",mAssignmentFile.IGroupId), new SqlParameter("@assmtID",mAssignmentFile.IAssignmentId) }; bool isSuccess = false; int affectedRows = SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionStringSTEduSys, CommandType.StoredProcedure, "SP_AddAssignmentFile", parms); if (affectedRows > 0) { isSuccess = true; } return isSuccess; }
/// <summary> /// ������ҵ�ļ�����Ϣ(�������ϴ�) /// </summary> /// <param name="mAssignmentFile">�����µ���ҵ�ļ�����,����Ӧ������ҵ�ļ���Id���µ��ļ���, /// ϵͳ�Զ������ļ��ϴ�ʱ��Ϊ��ǰʱ��</param> /// <returns>�����Ƿ�ɹ�,��ɹ���true,����false</returns> public bool ReuploadAssignmentFile(AssignmentFileInfo mAssignmentFile) { SqlParameter[] parms = { new SqlParameter("@assmtFileID",mAssignmentFile.IAssignmentFileId), new SqlParameter("@fileName",mAssignmentFile.StrFileName), new SqlParameter("@fileTrueName",mAssignmentFile.StrFileTrueName), new SqlParameter("@submitTime",DateTime.Now), ///��������ӣ�����һ������fileurl,2010-03-03 new SqlParameter("@fileurl",mAssignmentFile.StrFileURL), }; bool isSuccess = false; int affectedRows = SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionStringSTEduSys, CommandType.StoredProcedure, "SP_EditAssignmentFile", parms); if (affectedRows > 0) { isSuccess = true; } return isSuccess; }