Exemplo n.º 1
0
 private void toolOpenData_Click(object sender, EventArgs e)
 {
     openFileDialog1.Filter = "(txt文件)|*txt";
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         dataCenter = FileCenter.OpenFile(openFileDialog1.FileName);
         dataGridView1.DataSource = Report.GetTable(dataCenter);
     }
 }
Exemplo n.º 2
0
        public void ADDATTACH_IDTONEWTASK_ID(string NEWTASK_ID, string ATTACH_ID)
        {
            try
            {
                var newID = FileCenter.Clone(ATTACH_ID, Module.WKF);

                string connectionString = ConfigurationManager.ConnectionStrings["connectionstring"].ToString();

                StringBuilder queryString = new StringBuilder();

                //要記得改成正式-4
                queryString.AppendFormat(@"
                                        UPDATE [{0}].dbo.TB_WKF_TASK
                                        SET ATTACH_ID='{2}'
                                        WHERE DOC_NBR='{1}'
                                        ", DBNAME, NEWTASK_ID, newID.ToString());

                try
                {
                    using (SqlConnection connection = new SqlConnection(connectionString))
                    {
                        SqlCommand command = new SqlCommand(queryString.ToString(), connection);

                        command.Connection.Open();

                        int count = command.ExecuteNonQuery();

                        connection.Close();
                        connection.Dispose();
                    }
                }
                catch
                {
                }
                finally
                {
                }
            }

            catch
            {
            }
            finally
            {
            }
        }
Exemplo n.º 3
0
        public async Task <MessageModel <UploadFileModel> > DeleteThisFile(int?fileId)
        {
            var             data         = new MessageModel <UploadFileModel>();
            UploadFileModel upfileModels = new UploadFileModel();

            if (!fileId.HasValue)
            {
                data.msg = "没参数";
                return(data);
            }

            FileCenter tfile = await _fileCenterServices.QueryById(fileId.Value);

            if (tfile != null && tfile.ExterndAtt == SystemConst.FILE_EXTERNARR_THUMBONTHIS)
            {
                //检测一下,如果是主图,要重新生成主图和缩略图信息
                //下载下来这个批次中排首的图,重新生成缩略图
                FileCenter nextfile = await _fileCenterServices.GetFirstOneExceptMe(tfile.BatchId, tfile.Id);

                //更新这个图为主图
                Stream s = AliYunOss.Instance.GetFileFromAliOss(nextfile.OssKey);
                if (nextfile != null)
                {
                    string filethumbName = IdCreatorHelper.CreateIdNoTimestrap(SystemConst.PREF_THUMB_NAME_PUB_TREE, 6) + ".jpg";
                    string AliossFolder  = DateTime.Now.ToString("yyyyMMddHH");
                    string newthumbUrl   = await CreateThumb(s, nextfile.BatchId, AliossFolder + "/" + filethumbName);

                    nextfile.ExterndAtt = SystemConst.FILE_EXTERNARR_THUMBONTHIS;
                    //更新这个批次的缩略图信息

                    bool thumbok = await _fileCenterServices.UpdateThisFileUrlByBatchIdAndSeq(nextfile.BatchId, 0, newthumbUrl);

                    bool isOk = await _fileCenterServices.Update(nextfile);

                    upfileModels.MainPic      = nextfile.Url;
                    upfileModels.ThumbnailUrl = newthumbUrl;
                    data.response             = upfileModels;
                }
            }
            bool isOK = await _fileCenterServices.DeleteById(fileId.Value);

            data.msg = isOK ? "删除成功" : "删除失败";
            return(data);
        }
Exemplo n.º 4
0
        public Result UpLoadFile()
        {
            System.Web.HttpRequest request = System.Web.HttpContext.Current.Request;
            // string taskID = request["ETID"].ToString().Trim();
            //int ETClass = Convert.ToInt32(request["ETClass"].ToString().Trim());
            // int tid = int.Parse(taskID);
            //var task = service.FindEntity<MyTest>(m => m.Id == tid);
            //if (task == null) return new Result("-1", "任务为空");

            System.Web.HttpFileCollection fileCollection = request.Files;
            if (fileCollection.Count < 1)
            {
                return(new Result("-1", "上传失败,文件为空"));
            }
            var fileinfo = UploadHelper.UploadFile(fileCollection[0]);

            if (fileinfo.IsSuccess == false)
            {
                return(new Result("-1", "上传失败"));
            }

            FileCenter newfile = new FileCenter();

            newfile.CreateDT     = DateTime.Now;
            newfile.EndUserID    = 0;
            newfile.RealName     = fileinfo.OldFileName;
            newfile.FileName     = fileinfo.NewFileName;
            newfile.FileUrl      = fileinfo.FilePath;
            newfile.FileSize     = fileCollection[0].ContentLength / 1000;
            newfile.CreateUserID = service.GetPersonID(ControllerContext.Request.Properties["WorkNo"].ToString());//请求人ID
            if (service.Insert <FileCenter>(newfile))
            {
                //ET_TaskFiled ET_TaskFiled = new ET_TaskFiled();
                //ET_TaskFiled.ETID = tid;
                //ET_TaskFiled.ETClass = ETClass;
                //ET_TaskFiled.FiledID = newfile.ID;
                //if (service.Insert<ET_TaskFiled>(ET_TaskFiled))
                //{
                return(new Result("0", newfile.ID.ToString()));
                //}
            }
            return(new Result("-1", "上传失败"));
        }
Exemplo n.º 5
0
        private async Task <FileCenter> CreateThumb(IFormFile tfile, string batchId, string fileName)
        {
            string timepre    = Guid.NewGuid().ToString().Replace("-", "");
            string tempfolder = _env.WebRootPath + "/" + SystemConst.TEMP_FOLDER_NAME;

            if (!Directory.Exists(tempfolder))
            {
                Directory.CreateDirectory(tempfolder);
            }
            string tempfile      = tempfolder + "/" + timepre + SystemConst.TEMP_IMGNAME_FOR_TREE;
            string tempthumbfile = tempfolder + "/" + timepre + SystemConst.TEMP_IMGNAME_FOR_TREE_THUMB;
            var    stream        = System.IO.File.Create(tempfile);
            await tfile.CopyToAsync(stream);

            stream.Close();
            //压缩
            ImageHelper.CompressImage(tempfile, tempthumbfile, 50, 10);
            var thumbstream = System.IO.File.Open(tempthumbfile, FileMode.Open);

            AliYunOss.Instance.PutFileToOss(thumbstream, fileName);
            thumbstream.Close();

            System.IO.File.Delete(tempfile);
            System.IO.File.Delete(tempthumbfile);
            FileCenter f = new FileCenter();

            f.BatchId    = batchId;
            f.BatchSeq   = 0;//序号0 一定设置是缩略图
            f.CreateTime = DateTime.Now;
            f.FileName   = "thumb" + tfile.FileName;
            f.FileSize   = tfile.Length;
            f.Status     = 0;
            f.OssKey     = fileName;
            f.Url        = AliYunOssConfig.Endpoint + "/" + fileName;
            f.ExterndAtt = SystemConst.FILE_EXTERNARR_THUMB;
            return(f);
        }
Exemplo n.º 6
0
        public async Task <MessageModel <UploadFileModel> > PushPic()
        {
            var             data         = new MessageModel <UploadFileModel>();
            int             currentIndex = 1;
            UploadFileModel upfileModels = new UploadFileModel();
            string          batchId      = Request.Form["batchId"];

            //先检查有没有batchid,如果有,说明已开始存入过,那么不需要new batchid
            if (string.IsNullOrEmpty(batchId))
            {
                batchId = IdCreatorHelper.CreateId(SystemConst.PREF_BATCHID_FOR_PUB_TREE);
            }
            else
            {
                //找到此batchid 已累计增加的index ,用缓存缓住
                string currindex = _cacheHelper.Get <string>(batchId);
                currentIndex = int.Parse(string.IsNullOrEmpty(currindex)?"1":currindex);
            }

            IFormFileCollection cols = Request.Form.Files;

            if (cols == null || cols.Count == 0)
            {
                data.msg = "没有上传文件";
                return(data);
            }
            //上传到oss
            string            AliossFolder = DateTime.Now.ToString("yyyyMMddHH");
            List <FileCenter> dbfiles      = new List <FileCenter>();

            upfileModels.BatchId = batchId;
            List <IFormFile> postFiles = cols.ToList();

            for (int i = 0; i < postFiles.Count; i++)
            {
                var tfile = postFiles[i];

                string fileName = AliossFolder + "/" + IdCreatorHelper.CreateIdNoTimestrap(SystemConst.PREF_ALIOSS_FILENAME_FOR_TREE, 6) + ".jpg";
                AliYunOss.Instance.PutFileToOss(tfile.OpenReadStream(), fileName);
                FileCenter f = new FileCenter();
                if (currentIndex == 1)//默认第一个设置缩略图,设为主图
                {
                    string     filethumbName = IdCreatorHelper.CreateIdNoTimestrap(SystemConst.PREF_THUMB_NAME_PUB_TREE, 6) + ".jpg";
                    FileCenter thumbfile     = await  CreateThumb(tfile, batchId, AliossFolder + "/" + filethumbName);

                    dbfiles.Add(thumbfile);
                    upfileModels.ThumbnailUrl = thumbfile.Url;
                    upfileModels.MainPic      = AliYunOssConfig.Endpoint + "/" + fileName; //第一个默认主图
                    f.ExterndAtt = SystemConst.FILE_EXTERNARR_THUMBONTHIS;                 //设置浮标,标明 缩略图建立在这个图上
                }

                f.BatchId    = batchId;
                f.BatchSeq   = currentIndex;
                f.CreateTime = DateTime.Now;
                f.FileName   = tfile.FileName;
                f.FileSize   = tfile.Length;
                f.Status     = 0;
                f.OssKey     = fileName;
                f.Url        = AliYunOssConfig.Endpoint + "/" + fileName;
                dbfiles.Add(f);
                currentIndex++;
            }
            _cacheHelper.Set <string>(batchId, currentIndex.ToString(), DateTime.Now.AddHours(1));
            try
            {
                bool isok = await _fileCenterServices.AddIsIdentity(dbfiles);

                dbfiles.ForEach(u => upfileModels.files.Add(u.FileName, u.Id));
            }
            catch (Exception ex)
            {
                string e = ex.ToString();
            }
            //返回这一批次ID,返回已上传的ID

            data.response = upfileModels;
            return(data);
        }