public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string url = HttpContext.Current.Request.Url.Host; int port = HttpContext.Current.Request.Url.Port; HttpFileCollection files = HttpContext.Current.Request.Files; SchManagerInfoSystem.Common.UploadFile uploadf = new SchManagerInfoSystem.Common.UploadFile(); uploadf.Path = "../../UploadFileDir"; //设置上传文件路径 uploadf.FileType = "jpg|gif|bmp|jpeg|png"; //设置上传文件格式 //uploadf.Sizes = 2000;//设置上传文件的大小,默认200KB string msg = string.Empty; string error = string.Empty; string fileNewName = string.Empty; string result = string.Empty; bool resBool = false; if (files.Count > 0) { fileNewName = uploadf.SaveAs(files);//保存上传文件到服务器 if (fileNewName == "0") { error = "文件上传失败!"; result = "{ error:'上传的图片不能大于2M',status:'success01'}"; } else if (fileNewName == "1") { error = "文件上传失败!"; result = "{ error:'出现未知错误',status:'success02'}"; } else { //SchSystem.BLL.SchUserInfo suiBll = new SchSystem.BLL.SchUserInfo(); StringBuilder sbRes = new StringBuilder(); //try //{ // resBool = suiBll.UploadPicture(int.Parse(Com.Session.usertid), int.Parse(Com.Session.schid), fileNewName); // Com.Session.imgurl = fileNewName; //} //catch (Exception e) //{ // error = e.Message; //} msg = "文件上传成功!"; result = sbRes.Append("{msg:\"" + msg + "\",filenewname:\"" + fileNewName.Replace("\\", "/").Replace("../../", "/") + "\"}").ToString(); } } else { error = "文件上传失败!"; result = "{ error:'" + error + "'}"; } context.Response.Write(result); context.Response.End(); }
public void ProcessRequest(HttpContext context) { string msg = string.Empty; string error = string.Empty; string fileNewName = string.Empty; string result = string.Empty; bool resBool = false; Com.DataPack.DataRsp <Com.DataPack.UserInfo> rsp = Com.Public.UserFuncSoure(Com.SoureSession.jsid, Com.SoureSession.jstoken); if (rsp.code == "ERROR_TOKEN") { error = "登录失效!"; result = "{ error:'登录失效',status:'error'}"; } else { context.Response.ContentType = "text/plain"; HttpFileCollection files = HttpContext.Current.Request.Files; SchManagerInfoSystem.Common.UploadFile uploadf = new SchManagerInfoSystem.Common.UploadFile(); uploadf.Path = "UploadFileDir\\Users"; //设置上传文件路径 uploadf.FileType = "jpg|gif|bmp|jpeg|png"; //设置上传文件格式 uploadf.Sizes = 100; //设置上传文件的大小,默认100KB if (files.Count > 0) { fileNewName = uploadf.SaveAs(files);//保存上传文件到服务器 if (fileNewName == "0") { error = "文件上传失败!"; result = "{ error:'上传的图片不能大于100KB',status:'success01'}"; } else if (fileNewName == "1") { error = "文件上传失败!"; result = "{ error:'出现未知错误',status:'success02'}"; } else { SchSystem.BLL.SchUserInfo suiBll = new SchSystem.BLL.SchUserInfo(); try { resBool = suiBll.UploadPicture(int.Parse(Com.SoureSession.Soureusertid), int.Parse(Com.SoureSession.Soureschid), fileNewName); Com.SoureSession.Soureimgurl = fileNewName; } catch (Exception e) { error = e.Message; } if (resBool) { msg = "文件上传成功!"; result = "{msg:\"" + msg + "\",filenewname:\"" + fileNewName.Replace("\\", "/") + "\"}"; } else { error = "文件上传失败!"; result = "{ error:'" + error + "'}"; } } } else { error = "文件上传失败!"; result = "{ error:'" + error + "'}"; } } context.Response.Write(result); context.Response.End(); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string Action = context.Request.Form["Action"]; if (Action == "List") { int PageSize = int.Parse(context.Request.Form["PageSize"]); //页数 int PageIndex = 1; //当前页面 if (!string.IsNullOrEmpty(context.Request.Form["PageIndex"])) { PageIndex = int.Parse(context.Request.Form["PageIndex"]); } SchStuInfoBll ssiBll = new SchStuInfoBll(); int RowCount = 0; int PageCount = 0; //数据分页:cols,所查询的列;strWhere,所查询的条件;ordercols,排序列;orderby,降序或升序;PageIndex,当前页数;PageSize,每页条数;RowCount,记录总数;PageCount,总页数 DataSet ds = ssiBll.GetListCols("*", "Stat=1", "", "", PageIndex, PageSize, ref RowCount, ref PageCount); //数字分页 Paging pa = new Paging(PageSize, RowCount, "StudentList.aspx", PageIndex); string pages = pa.GetPageing(); context.Response.Write(SchManagerInfoSystem.Common.Function.DatasetToJson(ds, -1, pages, PageCount, RowCount, PageIndex)); //将返回的DataSet集合转换为JSON对象 } else if (Action == "null") //当没有参数时,即为添加操作 { //查询学校信息:根据用户所在学校的编号查询所属学校 SchInfoBll siBll = new SchInfoBll(); DataSet Schds = siBll.GetList("Stat = 1 and SchId=1"); string SchInfo = SchManagerInfoSystem.Common.Function.DatSetToJSON2(Schds, "SchInfo"); //查询年级信息:根据用户所在学校查询本属学校的年级信息 SchClassInfoBll sgiBll = new SchClassInfoBll(); DataSet sgids = sgiBll.GetList("sci.ClassId,sci.ClassName,sgi.GradeName", "sci.SchId=1 and sci.IsFinish=1", 2); string SchGradeInfo = SchManagerInfoSystem.Common.Function.DatSetToJSON2(sgids, "SchGradeInfo"); StringBuilder json = new StringBuilder(); json.Append("{"); json.Append(SchInfo + ","); json.Append(SchGradeInfo); json.Append("}"); context.Response.Write(json); } else if (Action == "Add")//保存添加操作时执行此方法 { SchStuInfo sgi = new SchStuInfo(); sgi.LoginName = context.Request.Form["LoginName"]; sgi.Pwd = context.Request.Form["Pwd"]; sgi.StuName = context.Request.Form["StuName"]; sgi.StuNo = context.Request.Form["StuNo"]; sgi.Sex = int.Parse(context.Request.Form["Sex"]); sgi.ClassId = int.Parse(context.Request.Form["ClassId"]); sgi.SchId = int.Parse(context.Request.Form["SchId"]); sgi.CardNo = context.Request.Form["CardNo"]; sgi.ImgUrl = context.Request.Form["ImgUrl"]; sgi.Birth = Convert.ToDateTime(context.Request.Form["Birth"]); sgi.StudyType = int.Parse(context.Request.Form["StudyType"]); sgi.Stat = 1; sgi.RecTime = DateTime.Now; sgi.RecUser = "******"; sgi.LastRecTime = DateTime.Now; sgi.LastRecUser = "******"; SchStuInfoBll ssiBll = new SchStuInfoBll(); int resultid = ssiBll.Add(sgi); context.Response.Write(resultid); } else if (Action == "Edit")//编辑方法 { int StuId = int.Parse(context.Request.Form["StuId"]); SchStuInfoBll sciBll = new SchStuInfoBll(); DataSet ds = sciBll.GetList("Stat=1 and StuId=" + StuId); context.Response.Write(SchManagerInfoSystem.Common.Function.DatasetToJson(ds)); } else if (Action == "EditSave") { SchStuInfo sgi = new SchStuInfo(); sgi.StuId = int.Parse(context.Request.Form["StuId"]); sgi.LoginName = context.Request.Form["LoginName"]; sgi.Pwd = context.Request.Form["Pwd"]; sgi.StuName = context.Request.Form["StuName"]; sgi.StuNo = context.Request.Form["StuNo"]; sgi.Sex = int.Parse(context.Request.Form["Sex"]); sgi.ClassId = int.Parse(context.Request.Form["ClassId"]); sgi.SchId = int.Parse(context.Request.Form["SchId"]); sgi.CardNo = context.Request.Form["CardNo"]; sgi.ImgUrl = context.Request.Form["ImgUrl"]; sgi.Birth = Convert.ToDateTime(context.Request.Form["Birth"]); sgi.StudyType = int.Parse(context.Request.Form["StudyType"]); sgi.LastRecTime = DateTime.Now; sgi.LastRecUser = "******"; SchStuInfoBll ssiBll = new SchStuInfoBll(); context.Response.Write(ssiBll.Update(sgi)); } else if (Action == "Delete") { int StudentId = int.Parse(context.Request.Form["StudentId"]); SchStuInfoBll sgiBll = new SchStuInfoBll(); bool result = sgiBll.DeleteRec(StudentId); context.Response.Write(result); } else if (Action == "FlieUpload") { SchManagerInfoSystem.Common.UploadFile uf = new SchManagerInfoSystem.Common.UploadFile(); //HttpPostedFile File = FileUpload1.PostedFile; // AllSheng.UploadObj.PhotoSave("/", FileUpload1); HttpFileCollection files = HttpContext.Current.Request.Files; uf.Path = "/UploadFileDir"; String ReStr = uf.SaveAs(files).ToString(); uf = null; } else { context.Response.Write("参数有误,请检查"); } }