Ejemplo n.º 1
0
        private void AddFile_Click(object sender, RoutedEventArgs e)
        {
            if (currentEval.PermanentRecord == true)
            {
                ErrorHandler.NotifyUser("اين سند به تأييد نهايي رسيده است.");
                return;
            }
            AddBusyIndicator();
            string fileName = "";

            Task.Factory.StartNew(delegate
            {
                string fileLocation = OpenFileHandler.OpenFileToUpload();

                byte[] fileContent = OpenFileHandler.GetFileFromLocation(fileLocation);
                fileName           = System.IO.Path.GetFileName(fileLocation);
                //fileName = OpenFileHandler.UploadFileToServer(String.Format(@"Evaluations\{0}\", currentEval), "اضافه کردن فایل صورت جلسه");
                if (fileName != "")
                {
                    if (DataManagement.AddEvaluationFile(fileName, fileContent, currentEval.EvaluationId) != -1)
                    {
                        ErrorHandler.NotifyUser("ثبت با موفقیت انجام شد");
                        HasAddedDocument = true;
                    }
                    else
                    {
                        ErrorHandler.ShowErrorMessage("در حال حاضر امکان ثبت فایل وجود ندارد.");
                    }
                }
            }).ContinueWith(delegate
            {
                this.layoutRoot.Children.Remove(busy);
            }, TaskScheduler.FromCurrentSynchronizationContext());
        }
        void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            int fileId = 0;

            try
            {
                //////////////////////////////////////////////////////////////////////////
                dynamic o            = e.Argument;
                int     documentId   = (int)o.documentId;
                int     contractorId = (int)o.contractorId;
                string  version      = (string)o.version;
                if (contractorId <= 0)
                {
                    ErrorHandler.ShowErrorMessage("ابتدا اطلاعات پيمانکار را ثبت کنيد");
                    return; // error has occured contractor should be submited before commiting chnages
                }
                //////////////////////////////////////////////////////////////////////////
                string fileLocation = OpenFileHandler.OpenFileToUpload();
                byte[] fileContent  = OpenFileHandler.GetFileFromLocation(fileLocation);
                string fileName     = System.IO.Path.GetFileName(fileLocation);
                fileId      = DataManagement.AddContractorFile(fileName, version, contractorId, documentId, fileContent);
                fileContent = null;
                GC.Collect();
            }
            catch (System.Exception ex)
            {
                ErrorHandler.ShowErrorMessage("ثبت فایل با موفقیت انجام نشد لطفا دوباره سعی کنید!");
            }
        }
        private void BrowseBtn_Click(object sender, RoutedEventArgs e) //multi tasking required
        {
            if (CurrentRegulation.PermanentRecord == true)
            {
                ErrorHandler.NotifyUser("سند به ثبت نهایی رسیده است ");
                return;
            }
            if (VersionTxt.Text.Trim() == "")
            {
                ErrorHandler.ShowErrorMessage("ابتدا ورژن فایل را وارد کنید");
                return;
            }
            string fileLocation = OpenFileHandler.OpenFileToUpload();

            if (fileLocation == null)
            {
                ErrorHandler.NotifyUser("فایلی انتخاب نشد");
                return;
            }
            else
            {
                try
                {
                    layoutRoot.Children.Add(busy);
                    int    a    = CurrentRegulation.RegulationId;
                    string text = VersionTxt.Text;
                    Task.Factory.StartNew(delegate
                    {
                        byte[] fileContent = OpenFileHandler.GetFileFromLocation(fileLocation);
                        string fileName    = System.IO.Path.GetFileName(fileLocation);
                        int fileId         = DataManagement.AddRegulationFile(fileName, fileContent, text, a);
                        fileContent        = null;
                        GC.Collect();
                        ErrorHandler.NotifyUser("فایل با موفقیت ثبت شد.");
                    }).ContinueWith(delegate
                    {
                        Grid.ItemsSource = DataManagement.RetrieveRegulationFile(CurrentRegulation.RegulationId);
                        layoutRoot.Children.Remove(busy);
                    }, TaskScheduler.FromCurrentSynchronizationContext());
                }
                catch
                {
                    ErrorHandler.NotifyUser("ثبت فایل موفقیت آمیز نبود");
                }
            }
        }