public MultiFileUpdateEntity()
 {
     documentManagerContext = new Web.DocumentManagerDomainContext();
     TaxPayerDocumentEntity = new TaxPayerDocumentEntity();
     TaxPayerDocumentEntity.TaxPayerDocument = new Web.Model.taxpayerdocument();
     UserFile = new UserFile();
     Status = "就绪";
     MultiFileUpdateStatus = Entities.MultiFileUpdateStatus.PREPARE;
     UserFile.FinishUpdates += UserFile_FinishUpdate;
     OnMove = new DelegateCommand(onMove);
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="file"></param>
        /// <param name="httpHandlerName"></param>
        /// <param name="uiDispatcher"></param>
        public HttpFileUploader(UserFile file, Dispatcher uiDispatcher)
        {
            _file = file;
            _uiDispatcher = uiDispatcher;

            _dataLength = _file.FileStream.Length;
            _dataSent = 0;

            string httpHandlerName = "HttpUploadHandler.ashx";
            if (string.IsNullOrEmpty(httpHandlerName))
                httpHandlerName = "HttpUploadHandler.ashx";

            UploadUrl = new CustomUri(httpHandlerName).ToString();
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="file"></param>
        /// <param name="httpHandlerName"></param>
        /// <param name="uiDispatcher"></param>
        public HttpFileUploader(UserFile file, Dispatcher uiDispatcher)
        {
            _file         = file;
            _uiDispatcher = uiDispatcher;

            _dataLength = _file.FileStream.Length;
            _dataSent   = 0;

            string httpHandlerName = "HttpUploadHandler.ashx";

            if (string.IsNullOrEmpty(httpHandlerName))
            {
                httpHandlerName = "HttpUploadHandler.ashx";
            }

            UploadUrl = new CustomUri(httpHandlerName).ToString();
        }
        private void onOpenStandBookFile()
        {
            OpenFileDialog oFile = new OpenFileDialog();
            // .xls filter specified to select only .xls file.
            oFile.Filter = "Excel (*.xls)|*.xls";

            if (oFile.ShowDialog() == true)
            {
                HasShowTemp = Visibility.Collapsed;
                try
                {
                    FileStream fs = oFile.File.OpenRead();
                    Workbook book = Workbook.Open(fs);
                    bool lIsSuccessRead = ReadSheet(book.Worksheets[0]);
                    if (lIsSuccessRead)
                    {
                        fs.Close();
                        HasShowTemp = Visibility.Visible;
                        CanInput = CheckVaild();
                        if (CanInput)
                        {
                            String fileName = oFile.File.Name;
                            UserFile = new UserFile();
                            DateTime lDateTime = DateTime.Now;
                            UserFile.FileName = lDateTime.ToString("yyyyMMdd_HHmmss_") + fileName;
                            UserFile.FileFolder = currentTaxPayerEntity.TaxPayerId.ToString();
                            UserFile.FileStream = oFile.File.OpenRead();

                            taxPayerDocumentEntity = new TaxPayerDocumentEntity();
                            taxPayerDocumentEntity.TaxPayerDocumentBytes = UserFile.FileStream.Length;
                        }

                        UpdateChanged("StandBookEntity");
                    }
                }
                catch (Exception ex)
                {
                    NotifyWindow lNotifyWindow = new NotifyWindow("打开文件出错", "请检查文件是否被其他程序打开或者文件中是否有自定义数据类型,请与模板比对!");
                    lNotifyWindow.Show();
                }
                UpdateChanged("HasShowTemp");
            }
        }
        private void onOpenFile()
        {
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == true)
            {
                String fileName = ofd.File.Name;

                if (fileName.Contains("\"")
                    || fileName.Contains("#")
                    || fileName.Contains("%")
                    || fileName.Contains("&")
                    || fileName.Contains("\'")
                    || fileName.Contains("~")
                    || fileName.Contains("|")
                    || fileName.Contains(">")
                    || fileName.Contains("<")
                    || fileName.Contains("[")
                    || fileName.Contains("]")
                    || fileName.Contains("^")
                    || fileName.Contains("{")
                    || fileName.Contains("}"))
                {
                    NotifyWindow notificationWindow = new NotifyWindow("错误", "文件名包含 \"#%&\'~|><[]^{} 等非法字符!");
                    notificationWindow.Show();
                    return;
                }

                FileName = fileName;
                UserFile = new UserFile();
                UserFile.FileName = fileName;
                UserFile.FileFolder = taxPayerEntity.TaxPayerId.ToString();
                UserFile.FileStream = ofd.File.OpenRead();
                taxPayerDocumentEntity = new TaxPayerDocumentEntity();
                taxPayerDocumentEntity.TaxPayerDocumentBytes = UserFile.FileStream.Length;
                //ProjectFilesEntity.FileBytes = UserFile.FileStream.Length;
                (OnUpdate as DelegateCommand).RaiseCanExecuteChanged();
                UpdateChanged("UserFile");
            }
        }
        private void onCreatePDFFile()
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                NotifyWindow notifyWindow = new NotifyWindow("错误", "请先输入生成PDF文件名称!");
                notifyWindow.Show();
                return;
            }

            if (ImagesList.Count == 0)
            {
                NotifyWindow notifyWindow = new NotifyWindow("错误", "请先添加文件!");
                notifyWindow.Show();
                return;
            }

            pdfDocument doc = new pdfDocument(fileName, "", false);
            bool getIamge = false;
            foreach (AddImageEntity imageEntity in ImagesList)
            {
                try
                {
                    WriteableBitmap bitmap;
                    using (FileStream fs = new FileStream(imageEntity.FilePath, FileMode.Open))
                    {
                        BitmapImage bi = new BitmapImage();
                        bi.SetSource(fs);
                        bitmap = new WriteableBitmap(bi);
                    }

                    if (null != bitmap)
                    {
                        pdfPage page = doc.addPage((int)bitmap.PixelHeight, (int)bitmap.PixelWidth);
                        page.addImage(bitmap, 0, 0);
                        getIamge = true;
                        createPDFFileSuccess = true;
                    }
                    else
                    {
                        createPDFFileSuccess = false;
                    }
                }
                catch
                {
                    createPDFFileSuccess = false;

                    NotifyWindow notifyWindow = new NotifyWindow("错误", string.Format("打开图片文件{0}失败,请检查文件!!!", imageEntity.FilePath));
                    notifyWindow.Show();
                }

            }

            if (getIamge)
            {
                tempPDFFile = System.IO.Path.GetTempFileName();

                using (FileStream fs = new FileStream(tempPDFFile, FileMode.Create))
                {
                    doc.createPDF(fs);
                }

                UserFile = new UserFile();
                UserFile.FileName = fileName;
                UserFile.FileFolder = taxPayerEntity.TaxPayerId.ToString();
                UserFile.FileStream = (new FileInfo(tempPDFFile)).OpenRead();

                taxPayerDocumentEntity = new TaxPayerDocumentEntity();
                taxPayerDocumentEntity.TaxPayerDocumentBytes = UserFile.FileStream.Length;

                (OnUpdate as DelegateCommand).RaiseCanExecuteChanged();

                UpdateChanged("UserFile");
            }
        }