示例#1
0
        public void DownloadBattchFile()
        {
            try
            {
                string FileID = Request["FileID"];
                if (string.IsNullOrEmpty(FileID))
                {
                    throw new Exception("无效参数调用。");
                }

                string filePath = "";
                string fileName = "";
                string fileType = "";
                using (ProxyBE pb = new ProxyBE())
                {
                    BattchFile bf = pb.Client.GetBattchFile(SenderUser, new Guid(FileID));

                    if (bf != null)
                    {
                        filePath = bf.FilePath;
                        fileName = bf.FileName;
                        fileType = bf.FileType;
                    }
                    else
                    {
                        throw new Exception("文件数据丢失,下载失败。");
                    }

                    if (!File.Exists(filePath))
                    {
                        throw new Exception("文件已经损坏,下载失败。");
                    }
                    FileStream fs    = new FileStream(filePath, FileMode.Open);
                    byte[]     bytes = new byte[(int)fs.Length];
                    fs.Read(bytes, 0, bytes.Length);
                    fs.Close();
                    Response.ContentType = "application/octet-stream";
                    //通知浏览器下载文件而不是打开
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName + "." + fileType, Encoding.UTF8));
                    Response.BinaryWrite(bytes);
                    Response.Flush();
                    //Response.End();

                    //下载完成之后,把是否状态改变

                    SaveBattchFileArgs args = new SaveBattchFileArgs();
                    args.BattchFile = bf;
                    bf.IsDownload   = true;
                    bf.ModifiedBy   = SenderUser.UserCode + "." + SenderUser.UserName;
                    pb.Client.SaveBattchFile(SenderUser, args);
                }
            }
            catch (Exception ex)
            {
                WriteError(ex.Message, ex);
            }
        }
示例#2
0
        public void SaveBattchFile(Sender sender, SaveBattchFileArgs args)
        {
            try
            {
                using (ObjectProxy op = new ObjectProxy(true))
                {
                    if (string.IsNullOrEmpty(args.BattchFile.BattchNum))
                    {
                        throw new PException("批次号不能为空。");
                    }
                    else if (BattchFileIsDuplicated(sender, args.BattchFile))
                    {
                        throw new PException("批次号【{0}】已经上传了文件", args.BattchFile.BattchNum);
                    }

                    BattchFile obj = new BattchFile();
                    obj.FileID = args.BattchFile.FileID;
                    if (op.LoadBattchFileByFileID(obj) == 0)
                    {
                        args.BattchFile.Created    = DateTime.Now;
                        args.BattchFile.CreatedBy  = string.Format("{0}.{1}", sender.UserCode, sender.UserName);
                        args.BattchFile.Modified   = DateTime.Now;
                        args.BattchFile.ModifiedBy = string.Format("{0}.{1}", sender.UserCode, sender.UserName);
                        op.InsertBattchFile(args.BattchFile);
                    }
                    else
                    {
                        args.BattchFile.Modified   = DateTime.Now;
                        args.BattchFile.ModifiedBy = string.Format("{0}.{1}", sender.UserCode, sender.UserName);
                        op.UpdateBattchFileByFileID(args.BattchFile);
                    }

                    op.CommitTransaction();
                }
            }
            catch (Exception ex)
            {
                PLogger.LogError(ex);
                throw ex;
            }
        }
示例#3
0
        public void UploadBattchFile()
        {
            try
            {
                #region CUT文件
                string filePath = Config.StorageFolder;
                IList <HttpPostedFile> cutFiles = Request.Files.GetMultiple("cutFile");

                string BattchNum     = Request["BattchNum"];
                string WorkingLineID = Request["WorkingLineID"];

                if (string.IsNullOrEmpty(WorkingLineID))
                {
                    throw new Exception("请选择生产线。");
                }
                if (string.IsNullOrEmpty(BattchNum))
                {
                    throw new Exception("请输入批次号。");
                }

                if (cutFiles.Count == 0)
                {
                    throw new Exception("请选择CUT文件。");
                }
                foreach (HttpPostedFile cutFile in cutFiles)
                {
                    string savepath = Path.Combine(filePath, "BattchFiles");
                    savepath = Path.Combine(savepath, "CUT");
                    savepath = Path.Combine(savepath, BattchNum);
                    if (!Directory.Exists(savepath))
                    {
                        Directory.CreateDirectory(savepath);
                    }
                    savepath = Path.Combine(savepath, Path.GetFileName(cutFile.FileName));
                    if (File.Exists(savepath))
                    {
                        File.Delete(savepath);
                    }
                    cutFile.SaveAs(savepath);

                    using (ProxyBE pb = new ProxyBE())
                    {
                        BattchFile bf = new BattchFile();
                        bf.FileID     = Guid.NewGuid();
                        bf.FileType   = "CUT";
                        bf.FileName   = Path.GetFileNameWithoutExtension(savepath);
                        bf.FilePath   = savepath;
                        bf.IsDownload = false;
                        bf.BattchNum  = BattchNum;
                        bf.DeviceID   = new Guid(WorkingLineID);

                        if (pb.Client.BattchFileIsDuplicated(SenderUser, bf))
                        {
                            throw new Exception("批次上传文件已经存在。");
                        }
                        SaveBattchFileArgs args = new SaveBattchFileArgs();
                        args.BattchFile = bf;
                        pb.Client.SaveBattchFile(SenderUser, args);
                    }
                }
                #endregion
                WriteSuccess();
            }
            catch (Exception ex)
            {
                WriteError(ex.Message, ex);
            }
        }