コード例 #1
0
        public ActionResult fileUp()
        {
            #region
            var file = Request.Files["Filedata"];
            //var userID = Request.QueryString["u"];
            var foldName = Request.QueryString["foldName"].ToString();


            if (file != null)
            {
                imgUpload imgUpLoad = new imgUpload();//上传图片的类
                var       reUrl     = imgUpLoad.picUpLoad(file, foldName);
                //return new ContentResult() { Content = serverPath.imageURL + reUrl, ContentType = "text/plain", ContentEncoding = System.Text.Encoding.UTF8 };
                return(new ContentResult()
                {
                    Content = reUrl, ContentType = "text/plain", ContentEncoding = System.Text.Encoding.UTF8
                });
            }
            else
            {
                return(new ContentResult()
                {
                    Content = "0", ContentType = "text/plain", ContentEncoding = System.Text.Encoding.UTF8
                });
            }
            #endregion
        }
コード例 #2
0
        public ActionResult fileUpOfPro()
        {
            #region
            HttpPostedFileBase file = Request.Files["imgFile"];
            var foldName            = Request.QueryString["foldName"].ToString();

            Hashtable hash = new Hashtable();
            if (file != null)
            {
                imgUpload imgUpLoad = new imgUpload();//上传图片的类
                var       reUrl     = imgUpLoad.picUpLoad(file, foldName);
                hash["error"] = 0;
                hash["url"]   = reUrl;
                return(Json(hash, "text/html;charset=UTF-8"));
            }
            else
            {
                hash["error"]   = 1;
                hash["message"] = "请选择文件";
                return(Json(hash));
            }
            #endregion
        }
コード例 #3
0
        public ActionResult StuRegister(HCHEv2.Models.stuRegist.StuRegistInfo model)
        {
            ViewBag.AddResult = false;
            string upPhotePath = "";

            if (ModelState.IsValid)
            {
                try
                {
                    var file = Request.Files["Sphoto"];

                    #region 图片上传和验证
                    if (file != null)
                    {
                        imgUpload imgUpLoad = new imgUpload();//上传图片的类
                        upPhotePath = imgUpLoad.picUpLoad(file, "BmStuPic");
                    }
                    else
                    {
                        ModelState.AddModelError("noPhoto", "请上传1寸免冠照片");
                        return(View(model));
                    }
                    if (upPhotePath == "0" || upPhotePath == "1")
                    {
                        string errorMsg = "";
                        switch (upPhotePath)
                        {
                        case "0":
                            errorMsg = "图片格式错误,请重新上传";
                            break;

                        case "1":
                            errorMsg = "图片大小超出1M,请重新上传";
                            break;
                        }
                        ModelState.AddModelError("noPhoto", errorMsg);
                        return(View(model));
                    }

                    #endregion


                    #region 保存报名学生
                    var student = new HC.Data.Models.StudentInfo()
                    {
                        FatherPhone  = model.FatherPhone,
                        major        = model.major,
                        MotherPhone  = model.MotherPhone,
                        ReceiveName  = model.ReceiveName,
                        ReceivePhone = model.ReceivePhone,
                        registerNo   = model.registerNo,
                        RegisterTime = DateTime.Now,
                        Scategory    = model.Scategory,
                        SchoolName   = model.SchoolName,
                        SeflPhone    = model.SeflPhone,
                        SelfCardNo   = model.SelfCardNo,
                        SendAddress  = model.SendAddress,
                        Sex          = model.Sex,
                        Sfrom        = model.Sfrom,
                        Sphoto       = upPhotePath,
                        StudentName  = model.StudentName,
                        Stype        = model.Stype,
                        TelNum       = model.TelNum,
                        ZipCode      = model.ZipCode
                    };


                    #region 重复校验
                    if (_iEnrolsysService.isExsit(student))
                    {
                        ModelState.AddModelError("noPhoto", "您的信息已存在,请勿重复提交!");
                        return(View(model));
                    }
                    #endregion


                    _iEnrolsysService.AddStudentInfo(student);
                    #endregion

                    ViewBag.AddResult = true;
                }
                catch
                {
                }
                return(View());
            }
            else
            {
                return(View(model));
            }
        }