/// <summary>
        /// 模具测试
        /// </summary>
        /// <param name="moldNR">模具号</param>
        /// <param name="operatorNR">操作员工号</param>
        /// <param name="files">文件列表</param>
        /// <returns>测试信息</returns>
        public Message MoldTest(string moldNR, string operatorNR, FileUP[] files,int currentCutTimes,bool moldNormal)
        {
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    using (IUnitOfWork unitwork = MSSqlHelper.DataContext())
                    {
                        IReportRepository reportRep = new ReportRepository(unitwork);

                        Report report = new Report();
                        report.ReportId = GuidUtil.GenerateGUID();
                        report.MoldID = moldNR;
                        report.ReportType = ReportType.TestReport;
                        report.OperatorID = operatorNR;
                        report.Date = DateTime.Now;

                        //upload files
                        FileUpLoad(files, report.ReportId.ToString());

                        reportRep.Add(report);

                        // update the last released date
                        IMoldRepository moldRep = new MoldRepository(unitwork);
                        Mold mold = moldRep.GetById(moldNR);
                        mold.LastReleasedDate = report.Date;
                        mold.Cuttedtimes += mold.CurrentCuttimes;
                        mold.CurrentCuttimes = 0;
                        if (moldNormal)
                            mold.State = MoldStateType.Normal;
                        unitwork.Submit();

                        ts.Complete();

                        return new Message() { MsgType = MsgType.OK, Content = "实验报告上传成功!" };
                    }
                }
            }
            catch (Exception ex)
            {
                  LogUtil.log.Error(ex.ToString());
                return new Message() { MsgType = MsgType.Error, Content = ex.Message };
            }
        }
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="files">文件列表</param>
        /// <param name="masterNR">附主号</param>
        /// <returns>上传信息</returns>
        public Message FileUpLoad(FileUP[] files,string masterNR)
        {
            try
            {
                if (files != null && files.Length > 0)
                {
                    using (IUnitOfWork unitwork = MSSqlHelper.DataContext())
                    {
                        string p = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Settings.Default.FileAttachmentPath);
                        if (!Directory.Exists(p))
                        {
                            Directory.CreateDirectory(p);
                        }
                        List<Attachment> reportAttaches = new List<Attachment>();
                        string type = string.Empty;
                        const int bufferLength = 4096;

                        foreach (FileUP file in files)
                        {
                            // type = file.Name.Substring(file.Name.LastIndexOf('.'), file.Name.Length - file.Name.LastIndexOf('.'));
                            string servername = GuidUtil.GenerateGUID().ToString() + file.FileType;

                            string filePath = Path.Combine(p, servername);

                            using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read))
                            {
                                using (Stream stream = new MemoryStream(file.Data))
                                {
                                    byte[] buffer = new byte[bufferLength];
                                    int readcount = 0;
                                    do
                                    {
                                        readcount = stream.Read(buffer, 0, bufferLength);
                                        if (readcount > 0)
                                        {
                                            fs.Write(buffer, 0, readcount);
                                        }
                                    } while (readcount > 0);
                                }
                            }

                            Attachment attachment = new Attachment()
                            {
                                MasterNR = masterNR,
                                Name = file.Name,
                                Path = servername,
                                Date = DateTime.Now
                            };
                            reportAttaches.Add(attachment);
                        }

                        IAttachmentRepository attachRep = new AttachmentRepository(unitwork);
                        attachRep.Add(reportAttaches);
                        unitwork.Submit();

                        return new Message() { MsgType = MsgType.OK, Content = "文件上传成功!" };
                    }
                }
                return new Message() { MsgType = MsgType.Warn, Content = "文件为空!" };
            }
            catch(Exception ex)
            {
                LogUtil.log.Error(ex.ToString());
                return new Message() { MsgType = MsgType.Error, Content = "请核实所填数据的准确性" };
            }
        }