Ejemplo n.º 1
0
        /// <summary>
        /// 获得分页列表,无论是否是缓存实体都从数据库直接拿取数据
        /// </summary>
        /// <param name="pPageIndex">页数</param>
        /// <param name="pPageSize">每页列表</param>
        /// <param name="pOrderBy">排序</param>
        /// <param name="pSortExpression">排序字段</param>
        /// <param name="pRecordCount">列表行数</param>
        /// <returns>数据分页</returns>
        public static List <ContractFileInfo> GetPagedList(int pPageIndex, int pPageSize, SortDirection pOrderBy, string pSortExpression, out int pRecordCount)
        {
            if (pPageIndex <= 1)
            {
                pPageIndex = 1;
            }
            List <ContractFileInfo> list = new List <ContractFileInfo>();

            Query q = ContractFile.CreateQuery();

            q.PageIndex = pPageIndex;
            q.PageSize  = pPageSize;
            q.ORDER_BY(pSortExpression, pOrderBy.ToString());
            ContractFileCollection collection = new  ContractFileCollection();

            collection.LoadAndCloseReader(q.ExecuteReader());

            foreach (ContractFile contractFile  in collection)
            {
                ContractFileInfo contractFileInfo = new ContractFileInfo();
                LoadFromDAL(contractFileInfo, contractFile);
                list.Add(contractFileInfo);
            }
            pRecordCount = q.GetRecordCount();

            return(list);
        }
        private void BrowseBtn1_Click(object sender, RoutedEventArgs e)
        {
            if (EditBtn.IsEnabled == false)
            {
                ErrorHandler.NotifyUser("برای بارگذاری فایل  پس از تکمیل سند و ثبت آن از طریق جستجو وارد شوید");
                return;
            }
            if (dataGrid1.SelectedIndex == -1)
            {
                return;
            }
            if ((dataGrid1.SelectedItem as ContractFile).FileId > 0)
            {
                return;
            }
            if (CurrentContract.PermanentRecord == true)
            {
                ErrorHandler.NotifyUser("سند به ثبت نهایی رسیده است");
                return;
            }
            FileDataObject temp = FilingManager.GetFileDataObject();

            if (temp == null)
            {
                return;
            }
            ContractFile t = dataGrid1.SelectedItem as ContractFile;

            t.FileContent  = temp.FileContent;
            t.Name         = temp.FileName;
            t.AttachedDate = DateTime.Now;
            DataManagement.AddContractFile(CurrentContract.Contractid, ContractIndex.ComplementOrExtend, t);
            ErrorHandler.NotifyUser(Errors.Saved);
        }
Ejemplo n.º 3
0
        //数据持久化
        internal static void  SaveToDb(ContractFileInfo pContractFileInfo, ContractFile pContractFile, bool pIsNew)
        {
            pContractFile.ContractFileId   = pContractFileInfo.contractFileId;
            pContractFile.ContractFileName = pContractFileInfo.contractFileName;
            pContractFile.PhyFileName      = pContractFileInfo.phyFileName;
            pContractFile.IsNew            = pIsNew;
            string UserName = SubsonicHelper.GetUserName();

            try
            {
                pContractFile.Save(UserName);
            }
            catch (Exception ex)
            {
                LogManager.getInstance().getLogger(typeof(ContractFileInfo)).Error(ex);
                if (ex.Message.Contains("插入重复键"))               //违反了唯一键
                {
                    throw new AppException("此对象已经存在");          //此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示
                }
                throw new AppException("保存失败");
            }
            pContractFileInfo.contractFileId = pContractFile.ContractFileId;
            //如果缓存存在,更新缓存
            if (CachedEntityCommander.IsTypeRegistered(typeof(ContractFileInfo)))
            {
                ResetCache();
            }
        }
Ejemplo n.º 4
0
 //从后台获取数据
 internal static void  LoadFromDAL(ContractFileInfo pContractFileInfo, ContractFile pContractFile)
 {
     pContractFileInfo.contractFileId   = pContractFile.ContractFileId;
     pContractFileInfo.contractFileName = pContractFile.ContractFileName;
     pContractFileInfo.phyFileName      = pContractFile.PhyFileName;
     pContractFileInfo.Loaded           = true;
 }
Ejemplo n.º 5
0
        public IActionResult UpdateContractWorkFiles(ContractFileModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageContract))
            {
                return(JsonErrorMessage());
            }
            if (string.IsNullOrEmpty(model.FileIds))
            {
                return(JsonErrorMessage());
            }
            var contract = _contractService.GetContractByGuid(model.ContractGuid);

            if (contract == null)
            {
                return(JsonNotFoundMessage());
            }
            var ids = model.FileIds.Split(',');

            foreach (var id in ids)
            {
                var item = new ContractFile();
                item.ContractId       = contract.Id;
                item.FileId           = Convert.ToInt32(id);
                item.contractFileType = model.contractFileType;
                if (item.contractFileType == ContractFileType.All)
                {
                    item.contractFileType = ContractFileType.Common;
                }
                item.EntityId = model.EntityId;
                _contractService.InsertContractFile(item);
            }
            return(JsonSuccessMessage());
        }
Ejemplo n.º 6
0
        public HttpResponseMessage UpdateContractFile(ContractFile contractFile)
        {
            var result = _contractFileService.UpdateContractFile(contractFile);

            if (result)
            {
                return(toJson(null, OperatingState.Success, "修改成功"));
            }
            return(toJson(null, OperatingState.Failure, "修改失败"));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Insert the ContractFile
        /// </summary>
        /// <param name="contractFile"></param>
        /// <returns></returns>
        public bool InsertContractFile(ContractFile contractFile)
        {
            if (contractFile == null)
            {
                throw new ArgumentNullException("contractFile is null");
            }

            bool result = __contractFileRepository.Insert(contractFile);

            return(result);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Delete the SubContractor
        /// </summary>
        /// <param name="contractFile"></param>
        /// <returns></returns>
        public bool DeleteContractFile(ContractFile contractFile)
        {
            if (contractFile == null)
            {
                throw new ArgumentException("contractFile is null");
            }

            bool result = __contractFileRepository.Delete(contractFile);

            return(result);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Updates the ContractFile
        /// </summary>
        /// <param name="contractFile"></param>
        /// <returns></returns>
        public bool UpdateContractFile(ContractFile contractFile)
        {
            if (contractFile == null)
            {
                throw new ArgumentNullException("contractFile is null");
            }

            bool result = __contractFileRepository.SingleUpdate(contractFile);

            return(result);
        }
        public static bool UploadContractFile(int contractId, ContractIndex docIndex, string version, Grid layoutRoot)
        {
            ContractFile f = new ContractFile();

            f.Version      = version;
            f.AttachedDate = DateTime.Now;
            f.FileGuid     = Guid.NewGuid();
            string fileLocation = OpenFileHandler.OpenFileToUpload();

            if (fileLocation == null)
            {
                return(false);
            }
            layoutRoot.Children.Add(busy);
            Task <bool> .Factory.StartNew(delegate
            {
                f.FileContent = OpenFileHandler.GetFileFromLocation(fileLocation);
                f.Name        = System.IO.Path.GetFileName(fileLocation);

                if (DataManagement.AddContractFile(contractId, docIndex, f) != -1)
                {
                    f = null;
                    GC.Collect();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }).ContinueWith(prev =>
            {
                layoutRoot.Children.Remove(busy);
                bool result = prev.Result;
                if (result)
                {
                    ErrorHandler.NotifyUser("فایل با موفقیت ثبت شد.");
                    if (TransactionFinished != null)
                    {
                        TransactionFinished();
                    }
                }
                else
                {
                    ErrorHandler.ShowErrorMessage("ثبت فایل امکان پذیر نبود لطفا دوباره سعی کنید.");
                }
            }, TaskScheduler.FromCurrentSynchronizationContext());

            return(true);
        }
Ejemplo n.º 11
0
        public ActionResult CreateFiles(ContractCreateFilesViewModel FilesViewModel, string submit)
        {
            HttpPostedFileBase tmp;
            var Contract = db.Contracts.Find(FilesViewModel.ContractId);

            foreach (var file in FilesViewModel.FilesUpload)
            {
                if (file != null)
                {
                    string ContainerName = "cristo"; //hardcoded container name.
                    tmp = file ?? Request.Files["file"];
                    string fileName    = Path.GetFileName(tmp.FileName);
                    Stream imageStream = tmp.InputStream;
                    var    result      = utility.UploadBlob(fileName, ContainerName, imageStream);
                    if (result != null)
                    {
                        ContractFile userfile = new ContractFile();
                        userfile.FileName = Path.GetFileName(tmp.FileName);
                        userfile.FileType = Path.GetExtension(tmp.FileName);
                        userfile.FileUrl  = "https://sopro16.blob.core.windows.net/cristo" + "/" + Path.GetFileName(tmp.FileName);
                        userfile.Contract = Contract;
                        db.ContractFiles.Add(userfile);
                        db.SaveChanges();
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    continue;
                }
            }

            db.Entry(Contract).State = EntityState.Modified;
            db.SaveChanges();

            if (submit == "Save File")
            {
                return(RedirectToAction("CreateFiles", new { id = Contract.Id }));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
Ejemplo n.º 12
0
 public void UploadFiles(Contract contract, List <IFormFile> formFiles)
 {
     if (formFiles != null)
     {
         foreach (var file in formFiles)
         {
             var fileName = Path.Combine(hostingEnvironment.WebRootPath + "/files/contracts/", Path.GetFileName(file.FileName));
             file.CopyTo(new FileStream(fileName, FileMode.Create));
             ContractFile contractFile = new ContractFile()
             {
                 Location = fileName, Name = file.FileName, ContractId = contract.Id
             };
             _context.CASFiles.Add(contractFile);
             _context.SaveChanges();
         }
     }
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 保存
 /// </summary>
 public override void Save()
 {
     if (!m_Loaded)           //新增
     {
         ContractFile contractFile = new ContractFile();
         SaveToDb(this, contractFile, true);
     }
     else            //修改
     {
         ContractFile contractFile = new ContractFile(contractFileId);
         if (contractFile.IsNew)
         {
             throw new AppException("该数据已经不存在了");
         }
         SaveToDb(this, contractFile, false);
     }
 }
Ejemplo n.º 14
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <returns>是否成功</returns>
        public override void Delete()
        {
            if (!m_Loaded)
            {
                throw new AppException("尚未初始化");
            }
            bool result = (ContractFile.Delete(ContractFileId) == 1);

            //更新缓存
            if (result && CachedEntityCommander.IsTypeRegistered(typeof(ContractFileInfo)))
            {
                ResetCache();
            }
            if (!result)
            {
                throw new AppException("删除失败,数据可能被删除");
            }
        }
Ejemplo n.º 15
0
        public ActionResult DeleteFile(int?id)
        {
            int ContractId;

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ContractFile userFile = db.ContractFiles.Find(id);

            ContractId = userFile.Contract.Id;
            db.ContractFiles.Remove(userFile);
            db.SaveChanges();
            string BlobNameToDelete = userFile.FileUrl.Split('/').Last();

            utility.DeleteBlob(BlobNameToDelete, "cristo");  //hardcoded container name.

            return(RedirectToAction("CreateFiles", new { id = ContractId }));
        }
Ejemplo n.º 16
0
 private void LoadFromId(int contractFileId)
 {
     if (CachedEntityCommander.IsTypeRegistered(typeof(ContractFileInfo)))
     {
         ContractFileInfo contractFileInfo = Find(GetList(), contractFileId);
         if (contractFileInfo == null)
         {
             throw new AppException("未能在缓存中找到相应的键值对象");
         }
         Copy(contractFileInfo, this);
     }
     else
     {
         ContractFile contractFile = new ContractFile(contractFileId);
         if (contractFile.IsNew)
         {
             throw new AppException("尚未初始化");
         }
         LoadFromDAL(this, contractFile);
     }
 }
Ejemplo n.º 17
0
        public HttpResponseMessage InsertContractFile(ContractFile contractFile)
        {
            var newObj = new ContractFile
            {
                Id               = Guid.NewGuid(),
                ProjectCode      = contractFile.ProjectCode,
                OrganizationCode = contractFile.OrganizationCode,
                ContractCode     = contractFile.ContractCode,
                IDCardNumber     = contractFile.IDCardNumber,
                IDCardType       = contractFile.IDCardType,
                FileName         = contractFile.FileName,
                FilePath         = contractFile.FilePath
            };

            var result = _contractFileService.InsertContractFile(newObj);

            if (result)
            {
                return(toJson(null, OperatingState.Success, "添加成功"));
            }
            return(toJson(null, OperatingState.Failure, "添加失败"));
        }
Ejemplo n.º 18
0
        private static async Task <IActionResult> UpdateContractFile(string user, HttpRequest req, IRepository <ContractFile> repository)
        {
            try
            {
                string       requestBody  = await new StreamReader(req.Body).ReadToEndAsync();
                ContractFile contractFile = JsonConvert.DeserializeObject <ContractFile>(requestBody);

                var existingContractFile = await repository.Get(contractFile.Id);

                if (existingContractFile.OwnerAddress != user)
                {
                    return(new UnauthorizedResult());
                }

                await repository.Update(contractFile);

                return(new OkObjectResult("Complete"));
            }
            catch (Exception ex)
            {
                return(new BadRequestObjectResult(ex.Message));
            }
        }
Ejemplo n.º 19
0
 private void LoadFromId(int contractFileId)
 {
     if (CachedEntityCommander.IsTypeRegistered(typeof(ContractFileInfo)))
     {
         ContractFileInfo contractFileInfo=Find(GetList(), contractFileId);
         if(contractFileInfo==null)
             throw new AppException("未能在缓存中找到相应的键值对象");
         Copy(contractFileInfo, this);
     }
     else
     {	ContractFile contractFile=new ContractFile( contractFileId);
         if(contractFile.IsNew)
         throw new AppException("尚未初始化");
        	LoadFromDAL(this, contractFile);
     }
 }
Ejemplo n.º 20
0
 //数据持久化
 internal static void SaveToDb(ContractFileInfo pContractFileInfo, ContractFile  pContractFile,bool pIsNew)
 {
     pContractFile.ContractFileId = pContractFileInfo.contractFileId;
      		pContractFile.ContractFileName = pContractFileInfo.contractFileName;
      		pContractFile.PhyFileName = pContractFileInfo.phyFileName;
     pContractFile.IsNew=pIsNew;
     string UserName = SubsonicHelper.GetUserName();
     try
     {
         pContractFile.Save(UserName);
     }
     catch(Exception ex)
     {
         LogManager.getInstance().getLogger(typeof(ContractFileInfo)).Error(ex);
         if(ex.Message.Contains("插入重复键"))//违反了唯一键
         {
             throw new AppException("此对象已经存在");//此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示
         }
         throw new AppException("保存失败");
     }
     pContractFileInfo.contractFileId = pContractFile.ContractFileId;
     //如果缓存存在,更新缓存
     if (CachedEntityCommander.IsTypeRegistered(typeof(ContractFileInfo)))
     {
         ResetCache();
     }
 }
Ejemplo n.º 21
0
 //从后台获取数据
 internal static void LoadFromDAL(ContractFileInfo pContractFileInfo, ContractFile  pContractFile)
 {
     pContractFileInfo.contractFileId = pContractFile.ContractFileId;
      		pContractFileInfo.contractFileName = pContractFile.ContractFileName;
      		pContractFileInfo.phyFileName = pContractFile.PhyFileName;
     pContractFileInfo.Loaded=true;
 }
Ejemplo n.º 22
0
 /// <summary>
 /// 保存
 /// </summary>
 public override void Save()
 {
     if(!m_Loaded)//新增
     {
         ContractFile contractFile=new ContractFile();
         SaveToDb(this, contractFile,true);
     }
     else//修改
     {
         ContractFile contractFile=new ContractFile(contractFileId);
         if(contractFile.IsNew)
             throw new AppException("该数据已经不存在了");
         SaveToDb(this, contractFile,false);
     }
 }
Ejemplo n.º 23
0
 public ContractAndCPair(ContractFile contractFile, CFile cFile)
 {
     this.contractFile = contractFile;
     this.cFile        = cFile;
 }
        public virtual IActionResult Create(ContractAcceptanceModel model)
        {
            var noti = "admin.common.Added";
            var item = new ContractAcceptance();

            if (ModelState.IsValid && model.listAcceptanceSub.Count > 0)
            {
                if (model.Id > 0)
                {
                    item = _contractService.getContractAcceptancebyId(model.Id);
                    _contractModelFactory.PrepareContractAcceptanceNoiboForUnit(model, item);
                    //remove listAcceptanceSub cu
                    _contractService.DeleteContractAcceptanceSubByAcceptanceId(AccepId: model.Id, TypeId: (int)ContractAcceptancesType.NoiBo);
                }
                // add ContractAcceptanceNoibo
                _contractModelFactory.PrepareContractAcceptanceNoiboForUnit(model, item);
                if (model.Id > 0)
                {
                    _contractService.UpdateContractAcceptance(item);
                    // Insert ContractLog
                    var contractLog = new ContractLog()
                    {
                        ContractId   = item.Id,
                        CreatedDate  = DateTime.Now,
                        CreatorId    = _workContext.CurrentCustomer.Id,
                        ContractData = item.ToModel <ContractAcceptanceModel>().toStringJson()
                    };
                    _contractLogService.InsertContractLog(contractLog, "Sửa nghiệm thu nội bộ: " + item.Name);
                    noti = "admin.common.updated";
                }
                else
                {
                    _contractService.InsertContractAcceptance(item);
                    // Insert ContractLog
                    var contractLog = new ContractLog()
                    {
                        ContractId   = item.Id,
                        CreatedDate  = DateTime.Now,
                        CreatorId    = _workContext.CurrentCustomer.Id,
                        ContractData = item.ToModel <ContractAcceptanceModel>().toStringJson()
                    };
                    _contractLogService.InsertContractLog(contractLog, "Thêm mới nghiệm thu nội bộ: " + item.Name);
                }
                //var _cas = new ContractAcceptanceSub();
                foreach (ContractAcceptanceSubModel _casModel in model.listAcceptanceSub)
                {
                    _casModel.Description = item.Name;
                    var _cas = _contractModelFactory.PrepareContractAcceptanceSubByTask(_casModel, null);
                    _cas.AcceptanceId = item.Id;
                    _contractService.InsertContractAcceptionSub(_cas);
                    if (model.SelectedListFileId.Count > 0)
                    {
                        foreach (int FileId in model.SelectedListFileId)
                        {
                            var contractFile = new ContractFile
                            {
                                ContractId = _cas.ContractId,
                                FileId     = FileId,
                                TypeId     = (int)ContractFileType.AcceptanceNoiBo,
                                EntityId   = item.Id.ToString(),
                            };
                            _contractService.InsertContractFile(contractFile);
                        }
                    }
                }
                return(JsonSuccessMessage(_localizationService.GetResource(noti)));
            }
            else
            {
                var list = ModelState.Values.Where(c => c.Errors.Count > 0).ToList();
                return(JsonErrorMessage("Error", list));
            }
        }