コード例 #1
0
 //Choose image.
 private void Border_Drop(object sender, DragEventArgs e)
 {
     string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
     lPath.Content = files[0];
     FormData.SetImage(lPath.Content.ToString(), imDrag);
     brImage.Opacity = 0.4;
 }
コード例 #2
0
        //Register (visibility).
        private void Register_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            txtRName.Text        = "";
            txtRPswd.Password    = "";
            txtRCfrPswd.Password = "";
            lPath.Content        = "...";
            FormData.SetImage("pack://application:,,,/Images/ImageDrop.png", imDrag);

            stFirst.Visibility    = Visibility.Collapsed;
            stRegister.Visibility = Visibility.Visible;
        }
コード例 #3
0
        //Click.
        private void Border_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "Image Files (*.png;*.jpg;*.jpeg;*.gif;*.tif)|*.png;*.jpg;*.jpeg;*.gif;*.tif|All files (*.*)|*.*";
            if (openFileDialog.ShowDialog() == true)
            {
                lPath.Content = openFileDialog.FileName;
                FormData.SetImage(lPath.Content.ToString(), imDrag);
            }
        }
コード例 #4
0
        void SetAvatar(int id, bool edit)
        {
            string path = _proxy.GetItemPropertyAsync(id, EngServRef.ServerData.User, EngServRef.PropertyData.Imgpath).Result ?? "Wolf.png";

            if (path == "Wolf.png")
            {
                FormData.SetImage("pack://*****:*****@"Temp\Avatars"))
                        {
                            Directory.CreateDirectory(@"Temp\Avatars");
                        }
                        byte[] res = _proxy.Download(path, EngServRef.FilesType.Avatars);
                        if (res != null)
                        {
                            try
                            {
                                FileInfo file = new FileInfo($@"Temp\Avatars\{path}");
                                file.Refresh();
                                using (FileStream fs = file.OpenWrite())
                                {
                                    fs.Write(res, 0, res.Length);
                                    fs.Dispose();
                                }
                            }
                            catch (IOException)
                            {
                                if (edit)
                                {
                                    if (MessageBox.Show("The data have been uploaded to the server. It will be updated the next time you come.\nDo you want to restart now?", "Check next time", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                                    {
                                        Close();
                                    }
                                }
                            }

                            FormData.SetImage($@"pack://siteoforigin:,,,/Temp\Avatars\{path}", imUserAvatar);
                        }
                    }));
                }));
            }
        }
コード例 #5
0
        /// <summary>
        /// Downloads an image from server and presents it.
        /// </summary>
        /// <param name="id">Images id.</param>
        /// <param name="parent">The panel where an image is supposed to be added.</param>
        void AddImage(int id, Panel parent)
        {
            Thread thd = new Thread(new ThreadStart(() =>
            {
                Dispatcher.InvokeAsync(new Action(() =>
                {
                    string img = _proxy.GetItemPropertyAsync(id, ServerData.Word, PropertyData.Imgpath).Result;
                    if (img == null)
                    {
                        return;
                    }

                    if (!Directory.Exists($@"Temp\WordImages"))
                    {
                        Directory.CreateDirectory($@"Temp\WordImages");
                    }

                    byte[] res = _proxy.Download(img, FilesType.WordsImages);
                    if (res != null)
                    {
                        try
                        {
                            using (FileStream fs = File.OpenWrite($@"Temp\WordImages\{img}"))
                            {
                                Task.WaitAny(fs.WriteAsync(res, 0, res.Length));
                                fs.Dispose();
                            }
                        }
                        catch (IOException) { }
                        Image tmp = new Image {
                            Height = 110
                        };
                        FormData.SetImage($@"pack://siteoforigin:,,,/Temp\WordImages\{img}", tmp);
                        parent.Children.Insert(0, tmp);
                    }
                }));
            }))
            {
                IsBackground = true
            };

            thd.Start();
        }
コード例 #6
0
        /// <summary>
        /// 'Edit' form. Hides rating, fills fields.
        /// </summary>
        /// <param name="tmp">Host.</param>
        /// <param name="id">Books id.</param>
        /// <param name="name">Books name.</param>
        /// <param name="description">Books description.</param>
        /// <param name="year">Year (if given).</param>
        /// <param name="path">Books path.</param>
        /// <param name="isAbsolute">Is path absolute?</param>
        /// <param name="cat">Books categories.</param>
        /// <param name="auth">Books authors.</param>
        /// <param name="img">Poster.</param>
        public AddBook(EngServRef.EngServiceClient tmp, int id, string name, string description, int?year, string path, bool isAbsolute, List <int> cat, List <int> auth, string img) : this()
        {
            _proxy = tmp;

            bookId       = id;
            txtName.Text = this.name = name;
            txtDesc.Text = desc = description;
            txtPath.Text = this.path = path;
            this.year    = year;
            if (year != null)
            {
                txtYear.Text = year.ToString();
            }
            this.isAbsolute  = isAbsolute;
            chCopy.IsChecked = !this.isAbsolute;
            imgPath          = img;
            if (imgPath == "WolfB.png")
            {
                FormData.SetImage("pack://*****:*****@"Temp\BookImages\{imgPath}"))
                {
                    FormData.SetImage($@"pack://siteoforigin:,,,/Temp\BookImages\{imgPath}", imDrag);
                }
                else
                {
                    MessageBox.Show("Image can not be found!", "Something went wrong", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }

            lPath.Content = "...";
            categories    = cat;
            authors       = auth;

            stRating.Visibility = Visibility.Collapsed;
            FillAuthors(auth);
            FillCategories(cat);
        }
コード例 #7
0
        //Sort data.
        private async void btnSort_Click(object sender, RoutedEventArgs e)
        {
            FormData.SortPosition = cmbSort.SelectedIndex;
            stActions.Children.Clear();
            stActions.Children.Add(new ProgressBar {
                Template = TryFindResource("Preloader") as ControlTemplate
            });

            await Task.Run(new Action(() => {
                Dispatcher.Invoke(new Action(() => {
                    int[] lst = _proxy.GetSortedItems((ServerData)Enum.Parse(typeof(ServerData), btnSearch.Tag.ToString()), (PropertyData)Enum.Parse(typeof(PropertyData), cmbSort.Text), _desc);
                    LoadList(lst, (DataType)Enum.Parse(typeof(DataType), btnSearch.Tag.ToString()), false);

                    _desc = !_desc;
                    string pic = _desc ? "SortR" : "Sort";
                    Image tmp = new Image {
                        Margin = new Thickness(5)
                    };
                    FormData.SetImage($"pack://application:,,,/Images/{pic}.png", tmp);
                    (sender as Button).Content = tmp;
                }));
            }));
        }
コード例 #8
0
ファイル: MainParts.cs プロジェクト: goldamber/holmesClient
        /// <summary>
        /// Downloads an image from server and presents it.
        /// </summary>
        /// <param name="id">Images id.</param>
        /// <param name="defaultPath">Default path.</param>
        /// <param name="tempPath">The location of temporary files.</param>
        /// <param name="parent">The panel where an image is supposed to be added.</param>
        /// <param name="type">Data type.</param>
        void AddImage(int id, string defaultPath, string tempPath, Panel parent, ServerData type, bool edit)
        {
            Thread thd = new Thread(new ThreadStart(() =>
            {
                Dispatcher.InvokeAsync(new Action(() => {
                    string img = _proxy.GetItemPropertyAsync(id, type, PropertyData.Imgpath).Result ?? defaultPath;
                    if (img == null)
                    {
                        return;
                    }

                    if (img == defaultPath)
                    {
                        parent.Children.Add(new Image {
                            Source = new BitmapImage(new Uri($"pack://*****:*****@"Temp\{tempPath}"))
                        {
                            Directory.CreateDirectory($@"Temp\{tempPath}");
                        }

                        FilesType filesType = FilesType.Avatars;
                        switch (type)
                        {
                        case ServerData.Video:
                            filesType = FilesType.VideosImages;
                            break;

                        case ServerData.Book:
                            filesType = FilesType.BooksImages;
                            break;

                        case ServerData.User:
                            filesType = FilesType.Avatars;
                            break;

                        case ServerData.Word:
                            filesType = FilesType.WordsImages;
                            break;
                        }
                        byte[] res = _proxy.Download(img, filesType);
                        if (res != null)
                        {
                            try
                            {
                                using (FileStream fs = File.OpenWrite($@"Temp\{tempPath}\{img}"))
                                {
                                    Task.WaitAny(fs.WriteAsync(res, 0, res.Length));
                                    fs.Dispose();
                                }
                            }
                            catch (IOException)
                            {
                                if (edit)
                                {
                                    if (MessageBox.Show("The data have been uploaded to the server. It will be updated the next time you come.\nDo you want to restart now?", "Check next time", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                                    {
                                        Process.GetCurrentProcess().Kill();
                                    }
                                }
                            }

                            Image tmp = new Image {
                                Height = 110
                            };
                            FormData.SetImage($@"pack://siteoforigin:,,,/Temp\{tempPath}\{img}", tmp);
                            parent.Children.Insert(0, tmp);
                        }
                    }
                }));
            }))
            {
                IsBackground = true
            };

            thd.Start();
        }