public void ProcessRequest(HttpContext context) { string file = context.Request.Params.Get("file"); //string File = Convert.ToString(e.CommandArgument); //获取行号 //string sql1 = "update tb_User set UserMark=UserMark-10 where UserName='******'"; DataOperate dataoper = new DataOperate(); string sql2 = "update DownAttach set count=count+1 where filesavename='" + file + "'"; DataOperate dataoper2 = new DataOperate(); if (dataoper2.DataCom(sql2)) { context.Session["Mark"] = (Convert.ToInt32(context.Session["Mark"]) - 0).ToString(); } string parentpath = HttpContext.Current.Server.MapPath("/Attach/"); string FullFileName = parentpath + file; FileInfo DownloadFile = new FileInfo(FullFileName); FullFileName = file; context.Response.Clear(); context.Response.ClearContent(); context.Response.ClearHeaders(); context.Response.Buffer = false; context.Response.ContentType = "application/octet-stream"; context.Response.AppendHeader("Content-Disposition", "attachment;filename=" + file); context.Response.AppendHeader("Content-Length", DownloadFile.Length.ToString()); context.Response.AddHeader("Content-Transfer-Encoding", "binary"); context.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); context.Response.WriteFile(DownloadFile.FullName); context.Response.Flush(); context.Response.End(); }
protected void GridViewArticle_onRowCommand(object sender, GridViewCommandEventArgs e) { string sql1 = "update tb_User set UserMark=UserMark-0 where UserName='******'"; DataOperate dataoper = new DataOperate(); if (dataoper.DataCom(sql1)) { Response.Write("<script language=javascript>alert('下载成功!');</script>"); } string File = Convert.ToString(e.CommandArgument); //获取行号 string parentpath = HttpContext.Current.Server.MapPath("/Attach/"); string FullFileName = parentpath + File; FileInfo DownloadFile = new FileInfo(FullFileName); Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.Buffer = false; Response.ContentType = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + File); Response.AppendHeader("Content-Length", DownloadFile.Length.ToString()); Response.AddHeader("Content-Transfer-Encoding", "binary"); Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); Response.WriteFile(DownloadFile.FullName); Response.Flush(); Response.End(); }
protected void Button1_Click(object sender, EventArgs e) { string sqlstr = "select * from MEMBERS where MID=00020030"; SqlConnection sqlconn = myCon.getCon(); sqlconn.Open(); SqlCommand sqlcom = new SqlCommand(sqlstr, sqlconn); SqlDataReader read = sqlcom.ExecuteReader(); read.Read(); if (this.passwordNow.Text.ToString() != this.cpasswordNow.Text.ToString()) { Response.Write(@"<script language='javascript'>alert('Please input same password!'); location='signup1.aspx'</script>"); } else { string sqlstr_signup_baseinfo = "update MEMBERS set EDU='" + this.education.Text + "',COLLEGE='" + this.college.Text + "' where MID=00020030"; string sqlstr_signup = "update LOGINFO set PASSWORD='******' where MID=00020030"; sqlBind.DataCom(sqlstr_signup); sqlBind_info.DataCom(sqlstr_signup_baseinfo); read.Close(); sqlconn.Close(); Response.Redirect("/members/Tech-department_change.aspx"); } }
protected void xiugai_Click(object sender, EventArgs e) { if (txtPwd.Text.Length == 0) { Response.Write("<script lanuage=javascript>alert('密码不能为空!');</script>"); } else { string textpwd = CJ_DBOperater.CJ.PwdSecurity(txtPwd.Text.Trim()); DataOperate dataopr = new DataOperate(); //string sql="update tb_User set UserPwd=" + textpwd.ToString() + " where UserName="******"UserName"].ToString(); string sql = string.Format("update tb_User set UserPwd='{0}' where UserName='******'", textpwd, Session["UserName"].ToString()); if (dataopr.DataCom(sql)) { Session.Clear(); Response.Write("<script lanuage=javascript>alert('密码修改成功!'); location.href='../../../login.aspx' </script>"); } else { Session.Clear(); Response.Write("<script lanuage=javascript>alert('密码修改失败!');location.href='../../../login.aspx'</script>"); } } }
protected void gvCardInfo_RowDeleting(object sender, GridViewDeleteEventArgs e) { string sqlrevert = "delete from tb_RevertCard where RevertCardID='" + gvCardInfo.DataKeys[e.RowIndex].Value + "'"; if (sqlBind.DataCom(sqlrevert)) { Response.Write("<script language=javascript>alert('删除成功');</script>"); Response.Redirect("RevertCardAdmin.aspx"); } }
protected void MembersList_RowDeleting(object sender, GridViewDeleteEventArgs e) { string sqlstr = "delete from MEMBERS where NAME='" + this.MembersList.DataKeys[e.RowIndex].Value + "'"; string sqlstr2 = "delete from LOGINFO where MID='00020030'"; string sqlstr3 = "update AIA set MEMNUM=MEMNUM-1 where PID='0002'"; SqlBind.DataCom(sqlstr); SqlBind2.DataCom(sqlstr2); SqlBind3.DataCom(sqlstr3); Response.Redirect("/members.aspx"); }
protected void btnSubmit_Click(object sender, EventArgs e) { if (txtCardContent.Text.Trim().Length == 0) { Response.Write("<script>alert('内容不能为空!');</script>"); return; } string title = Server.HtmlEncode(labCardTitle.Text); DateTime dt = Convert.ToDateTime(labCardDate.Text.Trim()); string strModuleID = hpLinkCardMod.SelectedValue; string sqlstr = "update tb_Card set CardName='" + title + "', ModuleID='" + strModuleID.ToString() + "', CardContent='" + txtCardContent.Text + "', CardDate='" + dt + "' where CardID='" + Request["CardID"].ToString() + "'"; sqlBind.DataCom(sqlstr); Response.Redirect("ManageCard.aspx"); }
protected void btnDeliver_Click(object sender, EventArgs e) { if (txtCardContent.Text.Trim().Length == 0) { Response.Write("<script>alert('内容不能为空!');</script>"); return; } string title = Server.HtmlEncode(labCardTitle.Text); string strModuleID = ddlModuleName.SelectedValue; string sqlstr = "insert into tb_Card (UserID,UserName,ModuleID,CardName,CardContent,CardIsPride,CardDate)" + " values('" + Session["UserID"].ToString() + "','" + Session["UserName"].ToString() + "','" + strModuleID.ToString() + "','" + title + "','" + txtCardContent.Text + "',0,'" + DateTime.Now + "')"; sqlBind.DataCom(sqlstr); Response.Write("<script language=javascript>alert('发表成功');</script>"); Response.Redirect("ManageCard.aspx"); }
protected void btnModify_Click(object sender, EventArgs e) { string sqlstr = ""; if (newpwd1.Text != null && newpwd1.Text != "" && newpwd1.Text == newpwd2.Text) { string newpwd = CJ_DBOperater.CJ.PwdSecurity(this.newpwd1.Text.Trim()); sqlstr = "update tb_User set UserSex='" + ddlSex.Text + "',UserPwd='" + newpwd + "',UserTel='" + txtTel.Text + "',UserEmail= '" + txtEmail.Text + "',UserAddress= '" + txtAddress.Text + "'where UserID = '" + Session["UserID"].ToString() + "'";//接受Login.aspx传值 } else { sqlstr = "update tb_User set UserSex='" + ddlSex.Text + "',UserTel='" + txtTel.Text + "',UserEmail= '" + txtEmail.Text + "',UserAddress= '" + txtAddress.Text + "'where UserID = '" + Session["UserID"].ToString() + "'";//接受Login.aspx传值 } sqlBind.DataCom(sqlstr); Response.Write("<script lanuage=javascript>alert('修改成功');location='BrowseModule.aspx'</script>"); }
protected void testUserID(object sender, EventArgs e) { string sqlstr = "select * from MEMBERS where MID=" + this.userID.Text.ToString(); SqlConnection sqlconn = myCon.getCon(); sqlconn.Open(); SqlCommand sqlcom = new SqlCommand(sqlstr, sqlconn); SqlDataReader read = sqlcom.ExecuteReader(); read.Read(); if (read.HasRows) { if (this.userID.Text.Trim() == read["MID"].ToString().Trim()) { Response.Write(@"<script language='javascript'>alert('had registered before!'); location='signup1.aspx'</script>"); } } else if (this.password.Text.ToString() != this.cpassword.Text.ToString()) { Response.Write(@"<script language='javascript'>alert('Please input same password!'); location='signup1.aspx'</script>"); } else { string sqlstr_signup_baseinfo = "insert into MEMBERS(MID,NAME,DEPARTMENT,POS)values('" + userID.Text + "','" + Name.Text + "','技术部','部员')"; string sqlstr_signup = "insert into LOGINFO(MID,PASSWORD)values('" + userID.Text + "','" + password.Text + "')"; string sqlupdateAIA = "update AIA set MEMNUM=MEMNUM+1 where PID='0002'"; sqlBind.DataCom(sqlstr_signup); sqlBind_info.DataCom(sqlstr_signup_baseinfo); sqlBind_updateAIA.DataCom(sqlupdateAIA); read.Close(); sqlconn.Close(); Response.Redirect("/members/Tech-department_login.aspx"); } }
protected void btnAdd_Click(object sender, EventArgs e) { if (UpImage.HasFile) { FileInfo file = new FileInfo(UpImage.PostedFile.FileName); if (file.Extension.ToLower() != ".bmp" && file.Extension.ToLower() != ".jpg" && file.Extension.ToLower() != ".jpeg" && file.Extension.ToLower() != ".png" && file.Extension.ToLower() != ".gif") { Response.Write("<script>alert('上传的图片格式应为bmp/jpg/jpeg/png/gif格式');history.back(-1);</script>"); return; } string filename = UpImage.PostedFile.FileName; filename = System.IO.Path.GetFileName(filename); //改文件名 int index = filename.LastIndexOf("."); string lastName = filename.Substring(index, filename.Length - index);//获得文件后缀类型 //新文件名称,以时间年月日时分秒作为文件名 string newname = "BBSSubject" + DateTime.Now.ToString("yyyyMMddhhmmss") + lastName; double size = UpImage.PostedFile.ContentLength; if (size >= 1024000) { Response.Write("<script>alert('添加失败!(图片容量请不要超过1MB)')</script>"); return; } // 客户端文件路径 ,取得图片的文件名 string webFilePath = Server.MapPath("/NewsImages/" + newname); if (!File.Exists(webFilePath)) { UpImage.SaveAs(webFilePath); // 使用 SaveAs 方法保存文件 System.Drawing.Image image = System.Drawing.Image.FromFile(webFilePath); float a = image.Width / image.Height; if (a > 5) { image.Dispose(); File.Delete(webFilePath); Response.Write("<script>alert('高宽比例不合适');</script>"); return; } System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image, 80, 80); string path = Server.MapPath("/IndexImages/" + newname); if (!File.Exists(path)) { bmp.Save(path); } image.Dispose(); bmp.Dispose(); File.Delete(webFilePath); } else { Response.Write("<script>alert('上传失败,请重试!')</script>"); return; } string title = Server.HtmlEncode(txtModuleName.Text.Trim()); string describe = Server.HtmlEncode(Describe.Text.Trim()); string sqlstr = "insert into tb_Module " + "(ModuleName,ModuleDate,ModuleImage,ModuleDescribe)" + "values('" + title + "','" + DateTime.Now.ToString() + "','" + newname + "','" + describe + "')"; if (sqlBind.DataCom(sqlstr)) { Response.Write("<script lanuage=javascript>alert('添加成功');location='ManageMudole.aspx'</script>"); } } }
//修改模块信息 protected void btnModify_Click(object sender, EventArgs e) { if (UpImage.PostedFile.ContentLength == 0) { string sqlstr = "update tb_Module set ModuleName='" + txtModTitle.Text + "',ModuleDescribe='" + Describe.Text + "' where ModuleID='" + Request["ModuleID"].ToString() + "'"; if (sqlBind.DataCom(sqlstr)) { Response.Write("<script>alert('修改成功');window.location.href='ManageMudole.aspx';</script>"); } else { Response.Write("<script>alert('修改失败');history.back();</script>"); } } else { FileInfo file1 = new FileInfo(UpImage.PostedFile.FileName); if (file1.Extension != ".bmp" && file1.Extension != ".jpg" && file1.Extension != ".jpeg" && file1.Extension != ".png" && file1.Extension != ".gif") { Response.Write("<script>alert('上传的图片格式应为bmp/jpg/jpeg/png/gif格式');history.back(-1);</script>"); return; } double size = UpImage.PostedFile.ContentLength; if (size >= 1024000) { Response.Write("<script>alert('添加失败!(图片容量请不要超过1MB)')</script>"); return; } string name = this.Image1.ImageUrl.Substring(14); //原来图片的URL string webFilePath = Server.MapPath("~/NewsImages/" + name); //用来删除原有的图片 string indexpath = Server.MapPath(this.Image1.ImageUrl); string filename = UpImage.PostedFile.FileName; filename = System.IO.Path.GetFileName(filename); //改文件名 int index = filename.LastIndexOf("."); string lastName = filename.Substring(index, filename.Length - index);//获得文件后缀类型 //新文件名称,以时间年月日时分秒作为文件名 string newname = "BBSSubject" + DateTime.Now.ToString("yyyyMMddhhmmss") + lastName; string newpath = Server.MapPath("~/NewsImages/" + newname);//用来保存新上传的图片 string newindexpath = Server.MapPath("~/IndexImages/" + newname); System.IO.FileInfo file = new System.IO.FileInfo(webFilePath); System.IO.FileInfo indexfile = new System.IO.FileInfo(indexpath); if (file.Exists) { file.Delete();//删除 } if (indexfile.Exists) { indexfile.Delete();//删除 } if (!File.Exists(newpath)) { UpImage.SaveAs(newpath);// 使用 SaveAs 方法保存文件 System.Drawing.Image image = System.Drawing.Image.FromFile(newpath); float a = image.Width / image.Height; if (a > 5) { image.Dispose(); File.Delete(newpath); Response.Write("<script>alert('高宽比例不合适');</script>"); return; } System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image, 80, 80); if (!File.Exists(newindexpath)) { bmp.Save(newindexpath); } image.Dispose(); bmp.Dispose(); File.Delete(newpath); } string title = Server.HtmlEncode(txtModTitle.Text.Trim()); string describe = Server.HtmlEncode(Describe.Text.Trim()); string sqlstr = "update tb_Module set ModuleName='" + title + "',ModuleDescribe='" + describe + "',ModuleImage='" + newname + "' where ModuleID='" + Request["ModuleID"].ToString() + "'"; if (sqlBind.DataCom(sqlstr)) { Response.Write("<script>alert('修改成功');window.location.href='ManageMudole.aspx';</script>"); } else { Response.Write("<script>alert('修改失败');history.back();</script>"); } } }