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); }
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); }