예제 #1
0
        static public List <Stone> GetCurrentSelectedStones()
        {
            List <Stone> list = new List <Stone>();

            if (ViewControl.SelectedItems.Count > 0)
            {
                foreach (var item in ViewControl.SelectedItems)
                {
                    StonesRepository rep = new StonesRepository(CurrentPath);
                    //TODO move this to  a property getter
                    string filename = (string)((StackPanel)(item)).Tag;

                    Stone stone = rep.LoadStoneByFilenameInCurrentFolder(filename);

                    if (stone != null)
                    {
                        list.Add(stone);
                    }
                }
                return(list);
            }
            else
            {
                return(list);
            }
        }
예제 #2
0
        private void ImportDetails(object sender, RoutedEventArgs e)
        {
            var dlg = new Microsoft.Win32.OpenFileDialog();

            dlg.DefaultExt = ".jpg";                                    // Default file extension
            dlg.Filter     = "Diamond image (.jpg)|*.jpg|Movies|*.mp4"; // Filter files by extension

            // Show open file dialog box
            var result = dlg.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                // Open document
                var fullFileName    = dlg.FileName;
                var filename        = Path.GetFileName(fullFileName);
                var folder          = Path.GetDirectoryName(fullFileName);
                var stoneRepository = new StonesRepository(folder);

                if (stoneRepository.IsStoneExistsInRep(filename))
                {
                    var importedStone = stoneRepository.LoadStoneByFilenameInCurrentFolder(filename);
                    LoadDetailsByStone(importedStone);
                }
            }
        }
예제 #3
0
        static public void PreformDeleteOfStone(string file)
        {
            //string filename = Path.GetFileNameWithoutExtension(file);
            //  string ext = Path.GetExtension(file);
            //     string newfilename = Microsoft.VisualBasic.Interaction.InputBox("Enter a new filename for the current stone", "Rename the stone", filename);

            if (File.Exists(file))
            {
                File.Delete(file);

                StonesRepository rep = new StonesRepository(CurrentPath);
                rep.DeleteStone(Path.GetFileName(file));

                RefreshView();
            }
        }
예제 #4
0
        static public void OpenRenameDialogAndPreformRename(string file)
        {
            string filename    = Path.GetFileNameWithoutExtension(file);
            string ext         = Path.GetExtension(file);
            string newfilename = Microsoft.VisualBasic.Interaction.InputBox("Enter a new filename for the current stone", "Rename the stone", filename);

            if (!String.IsNullOrWhiteSpace(newfilename))
            {
                File.Move(file, Path.Combine(CurrentPath, newfilename + ext));

                StonesRepository rep = new StonesRepository(CurrentPath);
                rep.RenameStone(Path.GetFileName(file), newfilename + ext);

                RefreshView();
            }
        }
예제 #5
0
        static void ViewControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (((ListBox)sender).SelectedItem != null)
            {
                string filename = (string)((StackPanel)((ListBox)sender).SelectedItem).Tag;

                StonesRepository rep = new StonesRepository(CurrentPath);

                Stone stone = rep.LoadStoneByFilenameInCurrentFolder(filename);

                if (stone != null)
                {
                    StoneInfoDisplayControl.ItemsSource = stone.InfoList;
                }
                else
                {
                    StoneInfoDisplayControl.ItemsSource = new List <StoneInfoPart>();
                }
            }
        }
예제 #6
0
        static public Stone GetCurrentSelectedStone()
        {
            if (ViewControl.SelectedItem != null)
            {
                StonesRepository rep = new StonesRepository(CurrentPath);
                //TODO move this to  a property getter
                string filename = (string)((StackPanel)(ViewControl).SelectedItem).Tag;

                Stone stone = rep.LoadStoneByFilenameInCurrentFolder(filename);

                if (stone != null)
                {
                    return(stone);
                }
                else
                {
                    return(rep.CreateAnewStoneSkeleton(filename));
                }
            }

            return(null);
        }
예제 #7
0
        private void SaveDiamond_Click(object sender, RoutedEventArgs e)
        {
            StonesRepository rep = new StonesRepository(FolderUponCaptureEvent);

            //Create the infoparts from input controls



            string filename = Path.Combine(FolderUponCaptureEvent, this.Filename.Text);

            filename = Path.ChangeExtension(filename, "jpg");

            if (rep.IsStoneExists(filename) && this.EditMode == false)
            {
                MessageBoxResult result = MessageBox.Show("The filename already exists, do you want to override the existing file", "File exists", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.No)
                {
                    return;
                }
            }

            BitmapSource source = (BitmapSource)this.CapturedImage.Source;

            List <StoneInfoPart> infoparts = new List <StoneInfoPart>();

            foreach (StackPanel panel in this.InfoPartsInputsContainer.Children)
            {
                StoneInfoPart infopart = new StoneInfoPart();
                if (panel.Children.OfType <TextBox>().SingleOrDefault() != null)
                {
                    infopart.Title          = (string)panel.Children.OfType <TextBox>().SingleOrDefault().Tag;
                    infopart.Value          = panel.Children.OfType <TextBox>().SingleOrDefault().Text;
                    infopart.TitleForReport = (string)panel.Children.OfType <Label>().SingleOrDefault().Content;
                }
                else if (panel.Children.OfType <ComboBox>().SingleOrDefault() != null)
                {
                    infopart.Title          = (string)panel.Children.OfType <ComboBox>().SingleOrDefault().Tag;
                    infopart.Value          = (string)((ComboBoxItem)panel.Children.OfType <ComboBox>().SingleOrDefault().SelectedItem).Tag;
                    infopart.TitleForReport = (string)panel.Children.OfType <Label>().SingleOrDefault().Content;
                }


                infoparts.Add(infopart);
            }

            if (this.ValidateUserInput() == false)
            {
                MessageBox.Show("Filename,Stonetype,Stone Weight,Clarity and color are mendatory fields...");
                return;
            }
            if (this.EditMode)
            {
                rep.UpdateStone(filename, infoparts);
            }
            else
            {
                rep.CreateANewStone(source, filename, infoparts);
            }

            //WebCam webcam = WebCam.GetInstance();
            // webcam.Start();

            StonesView.RefreshView();

            this.Close();
        }
예제 #8
0
        public static void LoadImagesToImageView(string path)
        {
            CurrentPath = path;

            //var files = Directory.GetFiles(path, "*.jpg");

            string[] fnsjpg = Directory.GetFiles(path, "*.jpg");
            // string[] fnswmv = Directory.GetFiles(path, "*.wmv");
            string[] fnswmv = Directory.GetFiles(path, "*.mp4");

            string[] fnsmp4 = Directory.GetFiles(path, "*.wmv");

            List <string> fns = fnsjpg.Union(fnswmv).Union(fnsmp4).ToList <string>();

            StonesRepository rep = new StonesRepository(CurrentPath);


            switch (_sortproperty)
            {
            case 1:
                if (_sortpropertydirection == 1)
                {
                    fns = fns.OrderBy(m => new FileInfo(m).Name).ToList <string>();
                }
                else
                {
                    fns = fns.OrderByDescending(m => new FileInfo(m).Name).ToList <string>();
                }

                break;

            case 2:
                if (_sortpropertydirection == 1)
                {
                    fns = fns.OrderBy(m => new FileInfo(m).LastWriteTime).ToList();
                }
                else
                {
                    fns = fns.OrderByDescending(m => new FileInfo(m).LastWriteTime).ToList <string>();
                }

                break;

            case 3:
                if (_sortpropertydirection == 1)
                {
                    fns = fns.OrderBy(m => new FileInfo(m).Extension).ToList <string>();
                }
                else
                {
                    fns = fns.OrderByDescending(m => new FileInfo(m).Extension).ToList <string>();
                }

                break;

            case 4:
                if (_sortpropertydirection == 1)
                {
                    fns = fns.OrderBy(m => new FileInfo(m).Length).ToList <string>();
                }
                else
                {
                    fns = fns.OrderByDescending(m => new FileInfo(m).Length).ToList <string>();
                }

                break;

            case 5:
                List <string> fns_withdata    = fns.Where(m => rep.LoadStoneByFilenameInCurrentFolder(Path.GetFileName(m)) != null).ToList <string>();
                List <string> fns_withoutdata = fns.Where(m => rep.LoadStoneByFilenameInCurrentFolder(Path.GetFileName(m)) == null).ToList <string>();
                if (_sortpropertydirection == 1)
                {
                    fns_withdata = fns_withdata.OrderBy(m => rep.LoadStoneByFilenameInCurrentFolder(Path.GetFileName(m)).GetInfoByTitle("CaratWeight")).ToList <string>();
                }
                else
                {
                    fns_withdata = fns_withdata.OrderByDescending(m => rep.LoadStoneByFilenameInCurrentFolder(Path.GetFileName(m)).GetInfoByTitle("CaratWeight")).ToList <string>();
                }

                fns = fns_withdata.Union(fns_withoutdata).ToList <string>();

                break;

            default:
                break;
            }



            ViewControl.Items.Clear();

            foreach (var file in fns)
            {
                StackPanel stack = new StackPanel();

                Image img = new Image();

                MemoryStream ms  = new MemoryStream();
                BitmapImage  src = new BitmapImage();

                if (Path.GetExtension(file) == ".jpg")
                {
                    FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read);
                    ms.SetLength(stream.Length);
                    stream.Read(ms.GetBuffer(), 0, (int)stream.Length);

                    ms.Flush();
                    stream.Close();



                    src.BeginInit();
                    src.StreamSource = ms;
                    src.EndInit();
                    img.Source = src;
                }
                else if (Path.GetExtension(file) == ".mp4" || Path.GetExtension(file) == ".wmv")
                {
                    //MediaPlayer mp = new MediaPlayer();
                    //mp.ScrubbingEnabled = true;
                    //mp.Open(new Uri(file,UriKind.Absolute));
                    //mp.Play();
                    //mp.MediaOpened += new EventHandler(mp_MediaOpened);
                    //mp.Position = new TimeSpan(0, 0, 2);
                    //RenderTargetBitmap rtb = new RenderTargetBitmap(640, 480, 1/200, 1/200, PixelFormats.Default);
                    //DrawingVisual dv = new DrawingVisual();
                    //DrawingContext dc = dv.RenderOpen();
                    //dc.DrawVideo(mp, new Rect(0, 0, 640, 480));
                    //dc.Close();
                    //rtb.Render(dv);
                    //img.Source = BitmapFrame.Create(rtb);
                    //mp.Stop();
                    //mp.Close();

                    //MediaPlayer _mediaPlayer = new MediaPlayer();
                    //_mediaPlayer.ScrubbingEnabled = true;
                    //_mediaPlayer.Open(new Uri(file, UriKind.Absolute));
                    //uint[] framePixels;
                    //uint[] previousFramePixels;

                    //framePixels = new uint[640 * 480];
                    //previousFramePixels = new uint[framePixels.Length];

                    //var drawingVisual = new DrawingVisual();
                    //var renderTargetBitmap = new RenderTargetBitmap(640, 480, 96, 96, PixelFormats.Default);
                    //using (var drawingContext = drawingVisual.RenderOpen())
                    //{
                    //    drawingContext.DrawVideo(_mediaPlayer, new Rect(0, 0, 640, 480));
                    //}
                    //renderTargetBitmap.Render(drawingVisual);

                    //// Copy the pixels to the specified location
                    //renderTargetBitmap.CopyPixels(previousFramePixels, 640 * 4, 0);

                    src.BeginInit();
                    src.UriSource = new Uri(@"/GemScopeWPF;component/Media/movieplaceholder.jpg", UriKind.RelativeOrAbsolute);
                    src.EndInit();

                    img.Source = src;
                }



                double[] wh = new double[] { 100, 100 };



                img.Width = wh[0];
                // img.Height = wh[1];


                img.Margin = new Thickness(5);



                TextBlock blk1 = new TextBlock();
                if (Path.GetFileNameWithoutExtension(file).Length > 20)
                {
                    blk1.Text = Path.GetFileNameWithoutExtension(file).Substring(0, 17) + "...";
                }
                else
                {
                    blk1.Text = Path.GetFileNameWithoutExtension(file);
                }

                blk1.Margin        = new Thickness(2, 0, 0, 0);
                blk1.TextAlignment = TextAlignment.Center;
                stack.Children.Add(img);
                stack.Children.Add(blk1);

                stack.Tag = Path.GetFileName(file);



                //   stack.VerticalAlignment = VerticalAlignment.Top;
                //  stack.HorizontalAlignment = HorizontalAlignment.Left;

                // stack.Width = wh[0]+10;
                //  stack.Height = wh[1] + 10;


                stack.MouseDown += new System.Windows.Input.MouseButtonEventHandler(stack_MouseDown);

                stack.MouseRightButtonDown += new MouseButtonEventHandler(stack_MouseRightButtonDown);


                ViewControl.Items.Add(stack);
            }
        }
예제 #9
0
        private void SaveDiamond_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                StonesRepository rep = new StonesRepository(FolderUponCaptureEvent);

                //Create the infoparts from input controls

                if (this.ValidateUserInput() == false)
                {
                    MessageBox.Show("Filename,Stonetype,Stone Weight,Clarity and color are mendatory fields...");
                    return;
                }

                string filename = Path.Combine(FolderUponCaptureEvent, this.Filename.Text);
                filename = Path.ChangeExtension(filename, "mp4");

                if (rep.IsStoneExists(filename) && this.EditMode == false)
                {
                    MessageBoxResult result = MessageBox.Show("The filename already exists, do you want to override the existing file", "File exists", MessageBoxButton.YesNo);
                    if (result == MessageBoxResult.No)
                    {
                        return;
                    }
                }

                if (!String.IsNullOrWhiteSpace(TempFileName))
                {
                    ICAVConverter converter = new CAVConverter();


                    converter.SetLicenseKey("*****@*****.**", "62A80CE3A6DB3F755C8C7478D44332E5928296AC08E61FCCD052D464049EDDEFCE62B2ED069F1396AC27F7DA120E6A3FDE982ACA8B49A4E8735552303198E03250EFE9D36E9E5349D2E289FF18D6C919CAB81199B4B24B13ABDF70CBB53605C844B1ED2C4164D08B1B4392C526C3D49E4100C1399C052C986BA57392042AC468BF0DDFD7BA5B12AFC4F2FFC21F9DF83D75C054DC6DBC198B091AD0E8AFD49D7A8CBA1E6B1BEA6BE3E0A3B41DA51B79E0678A7B675D3183618229AF2D50650A8505E9EA106E8507156E53ECA07973D883152F3CF4A75EBA57576B50A56117E2B129C5734150D552B7519D28AA7368895C740444BFEC403C041F4BA207F1258786");

                    converter.LoadAVLib(AppDomain.CurrentDomain.BaseDirectory + LIBAV_PATH);



                    converter.OutputOptions              = new COutputOptions();
                    converter.OutputOptions.FrameSize    = "640x480";
                    converter.OutputOptions.VideoBitrate = Convert.ToInt32(((ComboBoxItem)cmb_quality.SelectedItem).Tag);
                    converter.OutputOptions.DisableAudio = true;
                    converter.OutputOptions.FrameRate    = "30";

                    //Set output video bitrate



                    // converter.LogPath = @"c:\log.txt";
                    //  converter.LogLevel = CLogLevel.cllDebug;



                    try
                    {
                        converter.AddTask(TempFileName, filename);
                        converter.StartAndWait();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        throw;
                    }



                    // File.Move(TempFileName, filename);
                }


                List <StoneInfoPart> infoparts = new List <StoneInfoPart>();

                foreach (StackPanel panel in this.InfoPartsInputsContainer.Children)
                {
                    StoneInfoPart infopart = new StoneInfoPart();
                    if (panel.Children.OfType <TextBox>().SingleOrDefault() != null)
                    {
                        infopart.Title          = (string)panel.Children.OfType <TextBox>().SingleOrDefault().Tag;
                        infopart.Value          = panel.Children.OfType <TextBox>().SingleOrDefault().Text;
                        infopart.TitleForReport = (string)panel.Children.OfType <Label>().SingleOrDefault().Content;
                    }
                    else if (panel.Children.OfType <ComboBox>().SingleOrDefault() != null)
                    {
                        infopart.Title          = (string)panel.Children.OfType <ComboBox>().SingleOrDefault().Tag;
                        infopart.Value          = (string)((ComboBoxItem)panel.Children.OfType <ComboBox>().SingleOrDefault().SelectedItem).Tag;
                        infopart.TitleForReport = (string)panel.Children.OfType <Label>().SingleOrDefault().Content;
                    }


                    infoparts.Add(infopart);
                }

                if (this.EditMode)
                {
                    rep.UpdateStone(filename, infoparts);
                }
                else
                {
                    rep.CreateANewStoneMovie(filename, infoparts);
                }

                //WebCam webcam = WebCam.GetInstance();
                // webcam.Start();

                StonesView.RefreshView();

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
                throw;
            }
        }