public JsonResult Approve(int id)
        {
            BusinessCheckNotice notice = repository.FindByNotCache(id);
            if (notice == null)
            {
                return Json(new { success = false, message = "商检任务单不存在" });
            }

            string reportNumber = Request.Form["ReportNumber"];
            if (string.IsNullOrEmpty(reportNumber))
            {
                return Json(new { success = false, message = "商检报告号不能为空" });
            }

            BusinessCheckNotice tmp = repository.FindByReportNumber(reportNumber.Trim());
            if (tmp != null && !tmp.Key.Equals(notice.Key))
            {
                return Json(new { success = false, message = string.Format("商检报告号{0}已存在,请尝试使用其它报告号", reportNumber) });
            }

            #region 回滚事务
            OracleConnection conn = new Oracle.DataAccess.Client.OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PDCPDMConnection"].ConnectionString);
            conn.Open();
            OracleTransaction tran = conn.BeginTransaction();

            try
            {
            #endregion

                if (notice.Approver == null)
                {
                    notice.Approver = UserSession.OnlineAccount;
                    notice.ApproveTime = DateTime.Now;

                    IPipeRepository pipeRepository = RepositoryFactory.GetRepository<IPipeRepository, PDCPMS.Model.Common.Pipe>(unitOfWork);
                    IPipeBCRecordRepository pipeBCRecordRepository = RepositoryFactory.GetRepository<IPipeBCRecordRepository, PipeBCRecord>(unitOfWork);

                    List<PDCPMS.Model.Common.Pipe> pipes = pipeRepository.FindRandomFrom(
                        RepositoryFactory.GetRepository<IDeliverWaggonRepository, DeliverWaggon>().FindBy(notice),
                        notice.SamplingCount.Value);

                    for (int i = 0, j = pipes.Count; i < j; i++)
                    {
                        PDCPMS.Model.Common.Pipe pipe = pipes[i];
                        pipe.State |= PipeState.BusinessChecking;
                        //pipeRepository[pipe.Key] = pipe;
                        pipeRepository.UpdatedPipe(pipe, conn, tran);

                        // Add record
                        PipeBCRecord record = new PipeBCRecord(Guid.NewGuid().ToString("N"),
                            notice, pipe);
                        //pipeBCRecordRepository.Add(record);
                        pipeBCRecordRepository.AddBCRecord(record, conn, tran);
                    }
                }
                else
                {
                    return Json(new { success = false, message = string.Format("商检报告号{0}已交办,不能重复交办", reportNumber) });
                }

                notice.ReportNumber = reportNumber.Trim();
                repository.UpdateNotice(notice, conn, tran);
                //repository[notice.Key] = notice;

                //unitOfWork.Commit();

                #region 回滚事务
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                return Json(new { success = true, message = "商检报告号交办失败!" + ex });
            }
                #endregion

            return Json(new { success = true, message = string.Format("商检报告号{0}交办成功", reportNumber) });
        }
        //[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult AutoApprover(int id)
        {
            BusinessCheckNotice notice = repository.FindByNotCache(id);
            if (notice == null)
            {
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = "商检任务单不存在", Type = HintMessageType.Error };
                return RedirectToAction("Index");
            }

            #region 系统自动生成报告号
            StringBuilder sb = new StringBuilder();
            sb.Append("select max(reportnumber) as reportno from businesschecknotice where reportnumber like 'WZSYS%'");
            DataTable dt = RepositoryFactory.GetRepository<IPipeTypeRepository, PipeType>().ExcuteDs(sb.ToString());
            string reportno = dt.Rows[0]["reportno"].ToString() == "" ? "0" : dt.Rows[0]["reportno"].ToString();
            string sbz = "WZSYS-CD-" + DateTime.Now.Year.ToString() + "-";
            reportno = reportno.Replace(sbz, "");
            int a = Convert.ToInt32(reportno);
            a++;
            reportno = a.ToString("000");
            //系统自动生成商检报告号
            string reportNumber = sbz+reportno;
            #endregion

            if (string.IsNullOrEmpty(reportNumber))
            {
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = "商检报告号不能为空", Type = HintMessageType.Error };
                return RedirectToAction("Index");
            }

            #region 回滚事务
            OracleConnection conn = new Oracle.DataAccess.Client.OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PDCPDMConnection"].ConnectionString);
            conn.Open();
            OracleTransaction tran = conn.BeginTransaction();

            try
            {
            #endregion

                if (notice.Approver == null)
                {
                    //用曾友先的accountid=17去查找他的信息
                    Account account = RepositoryFactory.GetRepository<IAccountRepository, Account>().FindBy(17);

                    notice.Approver = account;
                    notice.ApproveTime = DateTime.Now;

                    IPipeRepository pipeRepository = RepositoryFactory.GetRepository<IPipeRepository, PDCPMS.Model.Common.Pipe>(unitOfWork);
                    IPipeBCRecordRepository pipeBCRecordRepository = RepositoryFactory.GetRepository<IPipeBCRecordRepository, PipeBCRecord>(unitOfWork);

                    List<PDCPMS.Model.Common.Pipe> pipes = pipeRepository.FindRandomFrom(
                        RepositoryFactory.GetRepository<IDeliverWaggonRepository, DeliverWaggon>().FindBy(notice),
                        notice.SamplingCount.Value);

                    for (int i = 0, j = pipes.Count; i < j; i++)
                    {
                        PDCPMS.Model.Common.Pipe pipe = pipes[i];
                        pipe.State |= PipeState.BusinessChecking;
                        //pipeRepository[pipe.Key] = pipe;
                        pipeRepository.UpdatedPipe(pipe, conn, tran);

                        // Add record
                        PipeBCRecord record = new PipeBCRecord(Guid.NewGuid().ToString("N"),
                            notice, pipe);
                        //pipeBCRecordRepository.Add(record);
                        pipeBCRecordRepository.AddBCRecord(record, conn, tran);
                    }
                }
                else
                {
                    TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = string.Format("商检报告号{0}已交办,不能重复交办", reportNumber) };
                    return RedirectToAction("Index");
                }

                notice.ReportNumber = reportNumber.Trim();
                repository.UpdateNotice(notice, conn, tran);

                #region 回滚事务
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = string.Format("商检报告号交办失败!{0}",ex), Type = HintMessageType.Error };
                return RedirectToAction("Index");
            }
                #endregion

            TempData["HintMessage"] = new PDCPMS.Application.HintMessage { Content = string.Format("商检报告号{0}交办成功", reportNumber) };
            return RedirectToAction("Index");
        }