//GridView�ؼ�RowDeleting�¼� protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { Scoresmr score = new Scoresmr(); //����Scoresmr���� int ID = int.Parse(GridView1.DataKeys[e.RowIndex].Values[0].ToString()); //ȡ��Ҫɾ����¼������ֵ if (score.DeleteByStr(ID)) { Response.Write("<script language=javascript>alert('�ɹ�ɾ����')</script>"); } else { Response.Write("<script language=javascript>alert('ɾ��ʧ�ܣ�')</script>"); } GridView1.EditIndex = -1; InitData(); }
protected void imgBtnSave_Click(object sender, ImageClickEventArgs e) { Scoresmr insertExamScore = new Scoresmr(); //����Scoresmr����� insertExamScore.UserID = Request.QueryString["UserID"].ToString(); insertExamScore.ExamTime = Convert.ToDateTime(lblExamtime.Text); insertExamScore.PaperID = int.Parse(Request.QueryString["PaperID"].ToString()); if (queScore.Text.Trim() != "") { insertExamScore.Score = Convert.ToInt32(sumScore.Text); } insertExamScore.PingYu = tbxPingyu.Text; //ʵ����������Papermr Papermr mypaper = new Papermr(); mypaper.UserID= Request.QueryString["UserID"].ToString(); mypaper.PaperID = int.Parse(Request.QueryString["PaperID"].ToString()); mypaper.state = "������"; //ʹ��CheckScore������֤�ɼ��Ƿ���� if (!insertExamScore.CheckScore(insertExamScore.UserID, insertExamScore.PaperID)) { //����InsertByProc���������ݿ��в���ɼ� if (insertExamScore.InsertByProc()) { mypaper.UpdateByProc(mypaper.UserID, mypaper.PaperID,mypaper.state); //�����ɹ���ʾ��Ϣ lblMessage.Text = "�����ɼ�����ɹ�!"; } else { lblMessage.Text = "�����ɼ�����ʧ��!"; } } else { lblMessage.Text = "���û��ijɼ��Ѵ���,����ɾ���ɼ�������!"; } }
//������Excel�¼� protected void ImageButton2_Click(object sender, ImageClickEventArgs e) { Scoresmr score = new Scoresmr(); //����Scoresmr���� DataSet ds = score.QueryScore(); //����QueryScore������ѯ�ɼ�������ѯ����ŵ�DataSet���ݼ��� DataTable DT = ds.Tables[0]; //���ɽ�Ҫ��Ž����Excel�ļ������� string NewFileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"; //ת��Ϊ����·�� NewFileName = Server.MapPath("Temp/" + NewFileName); //����ģ����ʽ���ɸ�Excel�ļ� File.Copy(Server.MapPath("../Modulemr.xls"), NewFileName, true); //����ָ���Excel�ļ������ݿ����� string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + NewFileName + ";Extended Properties='Excel 8.0;'"; OleDbConnection Conn = new OleDbConnection(strConn); //�����ӣ�Ϊ�������ļ����� Conn.Open(); OleDbCommand Cmd = new OleDbCommand("", Conn); foreach (DataRow DR in DT.Rows) { string XSqlString = "insert into [Sheet1$]"; XSqlString += "([�û�����],[�Ծ�],[�ɼ�],[����ʱ��]) values("; XSqlString += "'" + DR["UserName"] + "',"; XSqlString += "'" + DR["PaperName"] + "',"; XSqlString += "'" + DR["Score"] + "',"; XSqlString += "'" + DR["ExamTime"] + "')"; Cmd.CommandText = XSqlString; Cmd.ExecuteNonQuery(); } //�����������ر����� Conn.Close(); //��Ҫ���ص��ļ������Ѹ��ļ������FileStream�� System.IO.FileStream Reader = System.IO.File.OpenRead(NewFileName); //�ļ����͵�ʣ���ֽ�������ʼֵΪ�ļ����ܴ�С long Length = Reader.Length; Response.Buffer = false; Response.AddHeader("Connection", "Keep-Alive"); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode("ѧ���ɼ�.xls")); Response.AddHeader("Content-Length", Length.ToString()); byte[] Buffer = new Byte[10000]; //������������ݵĻ����� int ByteToRead; //ÿ��ʵ�ʶ�ȡ���ֽ��� while (Length > 0) { //ʣ���ֽ�����Ϊ�㣬�������� if (Response.IsClientConnected) { //�ͻ�������������ţ��������� ByteToRead = Reader.Read(Buffer, 0, 10000); //���������������� Response.OutputStream.Write(Buffer, 0, ByteToRead); //�ѻ�����������д��ͻ�������� Response.Flush(); //����д��ͻ��� Length -= ByteToRead; //ʣ���ֽ������� } else { //�ͻ���������Ѿ��Ͽ�����ֹ����ѭ�� Length = -1; } } //�رո��ļ� Reader.Close(); //ɾ����Excel�ļ� File.Delete(NewFileName); }
//��ʼ���ɼ���� protected void InitData() { Scoresmr score = new Scoresmr(); //����Scoresmr���� DataSet ds = score.QueryScore(); //����QueryScore������ѯ�ɼ�������ѯ����ŵ�DataSet���ݼ��� GridView1.DataSource = ds; //ΪGridView�ؼ�ָ������Դ GridView1.DataBind(); //������ }
//��ʼ���ɼ� protected void ScoreInitData() { Scoresmr score = new Scoresmr(); //����Scoresmr���� DataSet ds = score.QueryUserScore(Session["userID"].ToString()); if (ds.Tables[0].Rows.Count > 0) { GridView1.DataSource = ds; //ΪGridView�ؼ�ָ������Դ GridView1.DataBind(); //������ } else { lblScore.Text="û�гɼ�!"; } }