private void Scan(object sender, RoutedEventArgs e)
        {
            try
            {
                AppBarButton button = sender as AppBarButton;
                // hmmm, reusing the device doesn't work because it somehow resets itself to capture higher resolution images.
                bool hasDevice = false; //  device != null;

                GetScannerAsync(new Action(() =>
                {
                    WIA.ImageFile imageFile = null;

                    if (!hasDevice)
                    {
                        imageFile = globalDialog.ShowAcquireImage(DeviceType: WIA.WiaDeviceType.ScannerDeviceType,
                                                                  Bias: WIA.WiaImageBias.MinimizeSize, Intent: WIA.WiaImageIntent.TextIntent, AlwaysSelectDevice: false);
                    }
                    else
                    {
                        WIA.Item scannerItem      = device.Items[1];
                        const string wiaFormatPNG = "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}";
                        object scanResult         = globalDialog.ShowTransfer(scannerItem, wiaFormatPNG, false);
                        imageFile = (WIA.ImageFile)scanResult;
                    }

                    if (imageFile != null)
                    {
                        string temp = System.IO.Path.GetTempFileName();
                        if (File.Exists(temp))
                        {
                            File.Delete(temp);
                        }
                        imageFile.SaveFile(temp);
                        TempFilesManager.AddTempFile(temp);

                        AttachmentDialogImageItem image = new AttachmentDialogImageItem(temp);
                        AddItem(image);
                        LayoutContent();
                        SelectItem(image);
                        AutoCrop(image);
                    }
                }));
            }
            catch (Exception ex)
            {
                device = null;
                string message = GetWiaErrorMessage(ex);
                MessageBox.Show(this, message, "Scan Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #2
0
 public void MoveAttachments(Transaction fromTransaction, Transaction toTransaction)
 {
     foreach (string fileName in GetAttachments(fromTransaction))
     {
         toTransaction.HasAttachment = true;
         string newFileName = GetUniqueFileName(toTransaction, Path.GetExtension(fileName));
         try
         {
             File.Move(fileName, newFileName);
         }
         catch
         {
             // perhaps the old file is locked?
             File.Copy(fileName, newFileName);
             // delete it later.
             TempFilesManager.AddTempFile(fileName);
         }
         TempFilesManager.RemoveTempFile(newFileName);
     }
     fromTransaction.HasAttachment = false;
 }
Exemple #3
0
        internal void Export()
        {
            if (this.Series != null && this.Series.Count > 0)
            {
                string name = System.IO.Path.GetTempFileName() + ".csv";
                TempFilesManager.AddTempFile(name);
                using (StreamWriter writer = new StreamWriter(name))
                {
                    writer.Write("Label");
                    foreach (var series in this.Series)
                    {
                        writer.Write(", {0}", series.Name);
                    }
                    writer.WriteLine();

                    int columns = this.Series[0].Values.Count;
                    for (int i = 0; i < columns; i++)
                    {
                        for (int j = 0, n = this.Series.Count; j < n; j++)
                        {
                            var s    = this.Series[j];
                            var item = s.Values[i];
                            if (j == 0)
                            {
                                writer.Write("{0}, ", item.Label);
                            }
                            else
                            {
                                writer.Write(", ");
                            }
                            writer.Write("{0}", item.Value);
                        }
                        writer.WriteLine();
                    }
                }

                NativeMethods.ShellExecute(IntPtr.Zero, "Open", name, "", "", NativeMethods.SW_SHOWNORMAL);
            }
        }
Exemple #4
0
        private void Paste(object sender, ExecutedRoutedEventArgs e)
        {
            AttachmentDialogItem newItem = null;

            if (Clipboard.ContainsImage())
            {
                var image = Clipboard.GetImage();
                if (image != null)
                {
                    // for some reason this bitmap doesn't paint unless I save and reload it
                    // the in-memory copy from the clipboard is a bit touchy, probably comes from
                    // another process and so on, so persistence is better strategy here...
                    string path = Path.GetTempFileName();

                    AttachmentDialogImageItem item = new AttachmentDialogImageItem(image);
                    item.Save(path);

                    TempFilesManager.AddTempFile(path);

                    newItem = new AttachmentDialogImageItem(path);
                }
            }
            else if (Clipboard.ContainsData(DataFormats.XamlPackage) ||
                     Clipboard.ContainsData(DataFormats.Rtf) ||
                     Clipboard.ContainsData(DataFormats.Text))
            {
                newItem = new AttachmentDialogDocumentItem(Clipboard.GetDataObject());
            }

            if (newItem != null)
            {
                AddItem(newItem);
                LayoutContent();
                SelectItem(newItem);
                SetDirty();
            }
        }