Beispiel #1
0
        public Status AddWaterQuality(double ph, string comprehensiveevaluation, string remark, List <IFormFile> files)
        {
            this._logger.LogWarning("The server execute AddWaterQuality   --" + DateTime.Now.ToString());
            List <string>     filenames      = new List <string>();
            string            resultfilename = string.Empty;
            bool              flag;
            TWaterQualityInfo waterQualityInfo = new TWaterQualityInfo()
            {
                DateOfSampling          = DateTime.Now,
                Ph                      = ph,
                ComprehensiveEvaluation = comprehensiveevaluation,
                Remark                  = remark
            };

            flag = UpLoadFile.FileSave(files, DateTime.Now.ToString("yyyy-MM-dd"), out filenames);
            if (flag)
            {
                filenames.Sort();
                resultfilename         = string.Join("", filenames.ToArray());
                waterQualityInfo.Image = resultfilename;
                EFHelper <TWaterQualityInfo> eFHelper = new EFHelper <TWaterQualityInfo>();
                int result = eFHelper.Add(waterQualityInfo);
                return(result > 0 ? new Status(true) : new Status(false));
            }
            else
            {
                return(new Status(false));
            }
        }
        public Status AddStaff(string staffname, string tel, string companyname, List <IFormFile> files)
        {
            List <string>          filenames      = new List <string>();
            string                 resultfilename = string.Empty;
            bool                   flag;
            TTransportCompanyStaff staff = new TTransportCompanyStaff()
            {
                StaffName            = staffname,
                Telephone            = tel,
                TransPortCompanyName = companyname
            };

            if (staff.StaffName != "")
            {
                flag = UpLoadFile.FileSave(files, staff.StaffName, out filenames);
            }
            else
            {
                flag = UpLoadFile.FileSave(files, DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), out filenames);
            }
            filenames.Sort();
            resultfilename = string.Join("", filenames.ToArray());
            staff.Image    = resultfilename;
            EFHelper <TTransportCompanyStaff> eFHelper = new EFHelper <TTransportCompanyStaff>();
            int result = eFHelper.Add(staff);

            return(result > 0 ? new Status(true) : new Status(false));
        }
Beispiel #3
0
        public Status AddStaff(string staffname, string tel, string productionbasename, string level, List <IFormFile> file)
        {
            this._logger.LogWarning("The server excute AddStaff   --" + DateTime.Now.ToString());
            TProductionBaseStaff productionBaseStaff = new TProductionBaseStaff()
            {
                StaffName          = staffname,
                Telephone          = tel,
                ProductionBaseName = productionbasename,
                Position           = level
            };
            List <string> filenames      = new List <string>();
            string        resultfilename = string.Empty;

            if (productionBaseStaff.StaffName != "")
            {
                UpLoadFile.FileSave(file, productionBaseStaff.StaffName, out filenames);
            }
            else
            {
                UpLoadFile.FileSave(file, DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), out filenames);
            }
            filenames.Sort();
            resultfilename            = string.Join("", filenames.ToArray());
            productionBaseStaff.Image = resultfilename;
            EFHelper <TProductionBaseStaff> eFHelper = new EFHelper <TProductionBaseStaff>();
            int result = eFHelper.Add(productionBaseStaff);

            return(result > 0 ? new Status(true) : new Status(false));
        }
Beispiel #4
0
        public Status AddProductionBaseInfo(string proname, string category, string responsiblename, string tel, List <IFormFile> file)
        {
            this._logger.LogWarning("The server execute AddProductionBaseInfo   --" + DateTime.Now.ToString());
            TProductionBaseInfo productionBaseInfo = new TProductionBaseInfo()
            {
                Name            = proname,
                Category        = category,
                ResponsibleName = responsiblename,
                Telephone       = tel
            };
            List <string> filenames      = new List <string>();
            string        resultfilename = string.Empty;

            if (productionBaseInfo.Name != "")
            {
                UpLoadFile.FileSave(file, productionBaseInfo.Name, out filenames);
            }
            else
            {
                UpLoadFile.FileSave(file, DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), out filenames);
            }
            filenames.Sort();
            resultfilename           = string.Join("", filenames.ToArray());
            productionBaseInfo.Image = resultfilename;
            EFHelper <TProductionBaseInfo> eFHelper = new EFHelper <TProductionBaseInfo>();
            int result = eFHelper.Add(productionBaseInfo);

            return(result > 0 ? new Status(true) : new Status(false));
        }
        public ActionResult UpLoadfileinput(string guid, string folder)
        {
            string strjson = string.Empty;
            HttpFileCollectionBase files = HttpContext.Request.Files;
            //获取返回文件信息
            UpLoadFile file   = new UpLoadFile();
            var        result = file.UpLoad(files, 2);

            return(Json(result));
        }
        /// <summary>
        /// 单文件上传
        /// </summary>
        /// <param name="api"></param>
        /// <param name="upLoadFile"></param>
        /// <returns></returns>
        public static string HttpPostFile(string api, UpLoadFile upLoadFile)
        {
            var           requestContent = new MultipartFormDataContent();
            StreamContent streamContent  = new StreamContent(upLoadFile.Stream);

            requestContent.Add(streamContent, upLoadFile.Name);
            HttpResponseMessage response = _httpClient.PostAsync(api, requestContent).Result;

            return(response.Content.ReadAsStringAsync().Result);
        }
Beispiel #7
0
        public ActionResult GetImageList()
        {
            int pagesize  = DoRequest.GetFormInt("size", 15);
            int pageindex = DoRequest.GetFormInt("page", 1);
            //string code = DoRequest.GetFormString("path");
            DateTime startDate = DoRequest.GetFormDate("sDate", DateTime.Now.AddYears(-100));
            DateTime endDate   = DoRequest.GetFormDate("eDate", DateTime.Now);
            string   query     = DoRequest.GetFormString("query");
            int      dataCount = 0;
            int      pageCount = 0;

            List <PicFile> list = new List <PicFile>();
            var            res  = GetSysPicFile.Do(pagesize, pageindex, 3, startDate, endDate, query, ref dataCount, ref pageCount);

            if (res != null && res.Body != null && res.Body.pic_file_list != null)
            {
                list = res.Body.pic_file_list;
            }
            UpLoadFile upload = new UpLoadFile(false);

            return(Json(new { error = false, total = dataCount, size = pagesize, pages = pageCount, page = pageindex, root = base._config.UrlImages, data = list }, JsonRequestBehavior.AllowGet));
        }
Beispiel #8
0
        public Status AddProduct(string productnumber, string productinfo, string productionbase, string warehouse, List <IFormFile> files)
        {
            this._logger.LogWarning("The server excute AddProduct  --" + DateTime.Now.ToString());
            bool            flag;
            List <string>   filenames      = new List <string>();
            string          resultfilename = string.Empty;
            TProductNumInfo product        = new TProductNumInfo()
            {
                ProductNumber  = productnumber,
                ProductionBase = productionbase,
                ProductInfo    = productinfo,
                WareHouse      = warehouse
            };

            if (product.ProductInfo != "")
            {
                flag = UpLoadFile.FileSave(files, product.ProductInfo, out filenames);
            }
            else
            {
                flag = UpLoadFile.FileSave(files, DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), out filenames);
            }
            if (flag)
            {
                filenames.Sort();
                resultfilename = string.Join("", filenames.ToArray());
                product.Image  = resultfilename;
                EFHelper <TProductNumInfo> eFHelper = new EFHelper <TProductNumInfo>();
                int result = eFHelper.Add(product);
                return(result > 0 ? new Status(true) : new Status(false));
            }
            else
            {
                return(new Status(false));
            }
        }
Beispiel #9
0
        public ActionResult UploadImage()
        {
            //Response.Charset = "utf-8";
            //Response.ContentType = "text/javascript";
            int    typeId = DoRequest.GetFormInt("code");                      //图片分类编码
            string allow  = DoRequest.GetFormString("allow").ToLower().Trim(); //允许上传哪些后缀的图片,多个后缀使用逗号隔开,缺省为允许jpg/jpeg/gif/png/bmp
            //测试log
            //Logger.Log(DoRequest.GetFormString("name").ToLower().Trim());
            List <string> allowList = new List <string>();

            string[] arr       = allow.Split(',');
            string   _fullpath = "";

            foreach (string s in arr)
            {
                if (string.IsNullOrEmpty(s))
                {
                    continue;
                }
                string val = s.Trim();
                if (val.StartsWith("."))
                {
                    val = val.Substring(1);
                }
                allowList.Add(val);
            }

            if (!UpLoadFile.IsPostFile())
            {
                return(this.formatJson(Json(new { error = true, message = "请选择上传的文件" })));
            }
            var                returnValue = -1;
            Robots             robots      = null;
            HttpFileCollection postfiles   = System.Web.HttpContext.Current.Request.Files;

            if (postfiles[0] != null && postfiles[0].FileName != null && postfiles[0].FileName != "")
            {
                HttpPostedFile file = postfiles[0];
                try
                {
                    string ext = file.FileName.ToLower().Substring(file.FileName.LastIndexOf('.') + 1).ToLower();
                    if (ext == "jpg" || ext == "jpeg" || ext == "gif" || ext == "bmp" || ext == "png")
                    {
                    }
                    else
                    {
                        return(this.formatJson(Json(new { error = true, message = "不允许上传此类型文件" })));
                    }
                }
                catch (Exception e)
                {
                    Logger.Error(e.ToString());
                }
                NameValueCollection myCol = new NameValueCollection();
                robots = new Robots();
                //测试log
                //Logger.Log("进入上传");
                string s = robots.HttpUploadFile(config.UrlImagesUpload, file, myCol, "file");
                //测试log
                // Logger.Log("上传完毕");
                if (robots.IsError)
                {
                    return(this.formatJson(Json(new { error = true, message = robots.ErrorMsg })));
                }
                string uploadSaveMapPath = JsonHelper.JsonToObject <Response <ResponseFile> >(s).Body.fileNameList[0].fileKey;

                uploadSaveMapPath = uploadSaveMapPath.Replace("jianbao/website/", "");
                string savepath   = uploadSaveMapPath;
                string fullpathXX = JsonHelper.JsonToObject <Response <ResponseFile> >(s).Body.fileNameList[0].fileUrl;
                _fullpath = fullpathXX;
                #region 存储到数据表
                SysFilesInfo picfile = new SysFilesInfo();
                picfile.sp_type_id = typeId;//未分类
                picfile.file_name  = postfiles[0].FileName;
                picfile.save_name  = uploadSaveMapPath.Substring(uploadSaveMapPath.LastIndexOf("/") + 1);

                if (uploadSaveMapPath.StartsWith("/"))
                {
                    picfile.save_path = uploadSaveMapPath.Substring(1);
                }
                else
                {
                    picfile.save_path = uploadSaveMapPath;
                }
                picfile.user_agent = DoRequest.UserAgent;
                picfile.client_ip  = DoRequest.ClientIP;
                //测试log
                //Logger.Log("写入数据库");
                var res = AddSysPicFile.Do(picfile);
                //测试log
                //Logger.Log("写完数据库");
                if (res != null && res.Header != null && res.Header.Result != null && res.Header.Result.Code != null)
                {
                    returnValue = Utils.StrToInt(res.Header.Result.Code, -1);
                }
                #endregion
            }
            if (returnValue == 0)
            {
                return(this.formatJson(Json(new { error = false, message = "上传成功!", path = _fullpath })));
            }
            return(this.formatJson(Json(new { error = true, message = "上传失败..." })));
        }
        public Status AddStaff(string staffname, string telephone, string position, List <IFormFile> files)
        {
            List <string> filenames      = new List <string>();
            string        resultfilename = string.Empty;
            bool          flag;

            this._logger.LogWarning("The server execute AddStaff Fuction  --" + DateTime.Now.ToString());
            using (SchoolCookHouseContext dbcontext = new SchoolCookHouseContext())
            {
                TStaff staff = new TStaff()
                {
                    StaffName = staffname,
                    Telephone = telephone,
                    Position  = position,
                };
                if (staffname != "")
                {
                    flag = UpLoadFile.FileSave(files, staffname, out filenames);
                }
                else
                {
                    flag = UpLoadFile.FileSave(files, DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), out filenames);
                }
                try
                {
                    if (flag)
                    {
                        filenames.Sort();
                        resultfilename = string.Join("", filenames.ToArray());
                        staff.Image    = resultfilename;
                        dbcontext.Add(staff);
                        dbcontext.SaveChanges();
                        Status status = new Status()
                        {
                            StatusCode = 200,
                            Message    = "添加成功",
                            ReturnTime = DateTime.Now
                        };
                        return(status);
                    }
                    else
                    {
                        Status status = new Status()
                        {
                            StatusCode = 0,
                            Message    = "添加失败",
                            ReturnTime = DateTime.Now
                        };
                        return(status);
                    }
                }
                catch (Exception ex)
                {
                    this._logger.LogWarning("The server execute AddStaff Fuction  --" + ex.Message + DateTime.Now.ToString());
                    Status status = new Status()
                    {
                        StatusCode = 0,
                        Message    = "添加失败",
                        ReturnTime = DateTime.Now
                    };
                    return(status);
                }
            }
        }
        /// <summary>
        /// 表单+文件同时上传,成功了一般
        /// </summary>
        /// <param name="api"></param>
        /// <param name="paramter"></param>
        /// <param name="upLoadFile"></param>
        /// <returns></returns>
        public static string HttpPostMultipartFormData(string api, Dictionary <string, string> paramter, UpLoadFile upLoadFile)
        {
            var requestContent = new MultipartFormDataContent();

            foreach (var item in paramter)
            {
                requestContent.Add(new StringContent(item.Value), item.Key);
            }
            //追加文件
            StreamContent streamContent = new StreamContent(upLoadFile.Stream);

            requestContent.Add(streamContent, upLoadFile.Name);
            HttpResponseMessage response = _httpClient.PostAsync(api, requestContent).Result;

            return(response.Content.ReadAsStringAsync().Result);
        }