public override void Import()
        {
            var woCheckList = ClosureWOCheckList.FirstOrDefault(e => e.Id.ToString().Equals(_closureWOCheckList.Id.ToString()));

            if (woCheckList != null)
            {
                woCheckList.RE_Original         = _closureWOCheckList.RE_Original;
                woCheckList.LHI_Original        = _closureWOCheckList.LHI_Original;
                woCheckList.ESSD_Original       = _closureWOCheckList.ESSD_Original;
                woCheckList.Equipment_Original  = _closureWOCheckList.Equipment_Original;
                woCheckList.Signage_Original    = _closureWOCheckList.Signage_Original;
                woCheckList.Seating_Original    = _closureWOCheckList.Seating_Original;
                woCheckList.Decoration_Original = _closureWOCheckList.Decoration_Original;
                woCheckList.RE_NBV              = _closureWOCheckList.RE_NBV;
                woCheckList.LHI_NBV             = _closureWOCheckList.LHI_NBV;
                woCheckList.ESSD_NBV            = _closureWOCheckList.ESSD_NBV;
                woCheckList.Equipment_NBV       = _closureWOCheckList.Equipment_NBV;
                woCheckList.Signage_NBV         = _closureWOCheckList.Signage_NBV;
                woCheckList.Seating_NBV         = _closureWOCheckList.Seating_NBV;
                woCheckList.Decoration_NBV      = _closureWOCheckList.Decoration_NBV;
                woCheckList.EquipmentTransfer   = _closureWOCheckList.EquipmentTransfer;
                woCheckList.TotalCost_Original  = _closureWOCheckList.TotalCost_Original;
                woCheckList.TotalCost_NBV       = _closureWOCheckList.TotalCost_NBV;
                woCheckList.TotalCost_WriteOFF  = _closureWOCheckList.TotalCost_WriteOFF;
                woCheckList.RECost_WriteOFF     = _closureWOCheckList.RECost_WriteOFF;
                woCheckList.LHI_WriteOFF        = _closureWOCheckList.LHI_WriteOFF;
                woCheckList.ESSD_WriteOFF       = _closureWOCheckList.ESSD_WriteOFF;
                woCheckList.Equipment_WriteOFF  = _closureWOCheckList.Equipment_WriteOFF;
                woCheckList.Signage_WriteOFF    = _closureWOCheckList.Signage_WriteOFF;
                woCheckList.Seating_WriteOFF    = _closureWOCheckList.Seating_WriteOFF;
                woCheckList.Decoration_WriteOFF = _closureWOCheckList.Decoration_WriteOFF;
                woCheckList.ClosingCost         = _closureWOCheckList.ClosingCost;

                ClosureWOCheckList.Update(woCheckList);
            }
            else
            {
                ClosureWOCheckList.Add(_closureWOCheckList);
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult UploadClosureWOCheckListTemplate(string projectid)
        {
            var request        = HttpContext.Current.Request;
            var fileCollection = request.Files;

            if (fileCollection.Count > 0)
            {
                _refId = GetRefId(projectid, ClosureWOCheckList.TableName);
                if (_refId.HasValue)
                {
                    var file          = fileCollection[0];
                    var fileExtension = Path.GetExtension(file.FileName);
                    var name          = _refId.Value.ToString() + "WriteOff";
                    var fileName      = string.Format(@"{0}UploadFiles/{1}{2}",
                                                      HttpContext.Current.Server.MapPath("~/"),
                                                      name, fileExtension);
                    file.SaveAs(fileName);

                    if (!IsMeetVersion(ExcelDataInputType.ClosureWOCheckList.ToString(), fileName))
                    {
                        PluploadHandler.WriteErrorMsg("上传的是非标准模板,请下载标准模板再上传");
                    }

                    var fileInfo       = new FileInfo(fileName);
                    var importDirector = new ExcelDataImportDirector(fileInfo, ExcelDataImportType.ClosureWOCheckList);

                    decimal RE_NBV = 0;
                    decimal.TryParse(importDirector.GetCellValue(9, "E"), out RE_NBV);
                    decimal LHI_NBV = 0;
                    decimal.TryParse(importDirector.GetCellValue(10, "E"), out LHI_NBV);
                    decimal ESSD_NBV = 0;
                    decimal.TryParse(importDirector.GetCellValue(11, "E"), out ESSD_NBV);
                    decimal Equipment_Transfer = 0;
                    decimal.TryParse(importDirector.GetCellValue(16, "E"), out Equipment_Transfer);

                    importDirector.FillEntityEvent += FillClosureWOCheckList;
                    using (TransactionScope scope = new TransactionScope())
                    {
                        importDirector.ParseAndImport();

                        AddUpdateAttachment(name + fileExtension, ClosureWOCheckList.TableName, "Template", fileCollection);

                        var currentNode = NodeInfo.GetCurrentNode(projectid, FlowCode.Closure_WOCheckList);
                        var newNode     = NodeInfo.GetNodeInfo(NodeCode.Closure_WOCheckList_ResultUpload);
                        if (newNode.Sequence > currentNode.Sequence)
                        {
                            ProjectInfo.FinishNode(projectid, FlowCode.Closure_WOCheckList, NodeCode.Closure_WOCheckList_DownLoadTemplate);
                            ProjectInfo.FinishNode(projectid, FlowCode.Closure_WOCheckList, NodeCode.Closure_WOCheckList_WriteOffData);
                            ProjectInfo.FinishNode(projectid, FlowCode.Closure_WOCheckList, NodeCode.Closure_WOCheckList_ResultUpload);
                        }

                        scope.Complete();
                    }

                    if (_woCheckList != null)
                    {
                        var closureToolHandler = new ClosureTool();

                        var oldRE_NBV            = _woCheckList.RE_NBV ?? 0;
                        var oldLHI_NBV           = _woCheckList.LHI_NBV ?? 0;
                        var oldESSD_NBV          = _woCheckList.ESSD_NBV ?? 0;
                        var oldEquipmentTransfer = _woCheckList.EquipmentTransfer ?? 0;

                        if ((RE_NBV != oldRE_NBV) || (LHI_NBV != oldLHI_NBV) || (ESSD_NBV != oldESSD_NBV) || (Equipment_Transfer != oldEquipmentTransfer))
                        {
                            var __woCheckList = ClosureWOCheckList.FirstOrDefault(e => e.Id.ToString().Equals(_woCheckList.Id.ToString()));
                            if (__woCheckList != null)
                            {
                                __woCheckList.RefreshClosureTool = true;
                                __woCheckList.Update();
                            }
                            //var closureToolController = new ClosureToolController();
                            //var toolEntity = ClosureTool.Get(projectid);
                            //if (toolEntity != null)
                            //{
                            //    //判断是否满足生成closureTools的条件
                            //    if (toolEntity.EnableReGenClosureTool())
                            //    {

                            //        closureToolController.GenClosureTool(toolEntity.Id, toolEntity.UserAccount, toolEntity.UserNameZHCN, toolEntity.UserNameENUS);
                            //        closureToolController.CallClosureTool(toolEntity.Id);

                            //        //通知Finance Specialist和Asset Actor
                            //        var closureInfo = ClosureInfo.FirstOrDefault(i => i.ProjectId == projectid);
                            //        List<string> receiverList = new List<string>();
                            //        receiverList.Add(closureInfo.AssetActorAccount);
                            //        receiverList.Add(closureInfo.FinanceAccount);
                            //        var notificationMsg = new NotificationMsg()
                            //        {
                            //            FlowCode = FlowCode.Closure_WOCheckList,
                            //            ProjectId = projectid,
                            //            SenderCode = ClientCookie.UserCode,
                            //            Title = "由于WO Tool数据发生变化,Closure Tool文件已自动更新",
                            //            RefId = _woCheckList.Id,
                            //            UsCode = _woCheckList.USCode,
                            //            IsSendEmail = false,
                            //            ReceiverCodeList = receiverList
                            //        };
                            //        Notification.Send(notificationMsg);
                            //    }
                            //}
                        }
                    }
                }
            }
            return(Ok());
        }