private void Load_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.Title  = "Select a picture";
                dlg.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
                             "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
                             "Portable Network Graphic (*.png)|*.png";
                dlg.ShowDialog();

                FileStream fs = new FileStream(dlg.FileName, FileMode.Open,
                                               FileAccess.Read);

                data = new byte[fs.Length];
                fs.Read(data, 0, System.Convert.ToInt32(fs.Length));

                fs.Close();


                ImageSourceConverter imgs = new ImageSourceConverter();
                EmpPicture.SetValue(System.Windows.Controls.Image.SourceProperty, imgs.
                                    ConvertFromString(dlg.FileName.ToString()));
            }
            catch { }
        }
예제 #2
0
        private void Load_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                dlg.Title  = "Select a picture";
                dlg.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
                             "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
                             "Portable Network Graphic (*.png)|*.png";
                dlg.ShowDialog();

                FileStream fs = new FileStream(dlg.FileName, FileMode.Open,
                                               FileAccess.Read);

                data = new byte[fs.Length];
                fs.Read(data, 0, System.Convert.ToInt32(fs.Length));

                fs.Close();


                ImageSourceConverter imgs = new ImageSourceConverter();
                EmpPicture.SetValue(System.Windows.Controls.Image.SourceProperty, imgs.
                                    ConvertFromString(dlg.FileName.ToString()));
            }
            catch { }
            //OpenFileDialog op = new OpenFileDialog();
            //op.Title = "Select a picture";
            //op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
            //  "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
            //  "Portable Network Graphic (*.png)|*.png";
            //if (op.ShowDialog() == true)
            //{
            //    EmpPicture.Source = new BitmapImage(new Uri(op.FileName));


            //    //Initialize a file stream to read the image file
            //    FileStream fs = new FileStream(op.FileName, FileMode.Open, FileAccess.Read);

            //    //Initialize a byte array with size of stream
            //    byte[] imgByteArr = new byte[fs.Length];

            //    //Read data from the file stream and put into the byte array
            //    fs.Read(imgByteArr, 0, Convert.ToInt32(fs.Length));
            //    //MessageBox.Show(imgByteArr.ToString());
            //    fileUpload = imgByteArr;
            //    //file upload save as byte

            //    string attchment = Regex.Replace(System.IO.Path.GetFileName(op.FileName), @"\s", string.Empty);

            //    Picture_Filename = attchment;

            //    name = System.IO.Path.GetFileName(Picture_Filename);

            //    sourceFile = System.IO.Path.Combine(op.FileName);

            //    destFile = System.IO.Path.Combine(@"\\skpi-wpcs\c$\SKPI_System_Files\HRiS\", Picture_Filename);

            //}
        }
        private void listView1_ItemMouseHover(object sender, ListViewItemMouseHoverEventArgs e)
        {
            Rectangle er = listView1.GetItemRect(listView1.Items.IndexOf(e.Item));
            int       x  = er.X + er.Width / 2;
            int       y  = er.Y + er.Height / 2;
            Point     pt = new Point();

            if (x + EmpPL.Width <= listView1.Width)
            {
                pt.X = x;
            }
            else
            {
                pt.X = x - EmpPL.Width;
            }
            if (y + EmpPL.Height <= listView1.Height)
            {
                pt.Y = y;
            }
            else
            {
                pt.Y = y - EmpPL.Height;
            }
            //pt = listView1.PointToScreen(pt);


            //EmpPL.Size = new Size(80, 80);
            EmpPL.Location = pt;
            DataTable paneldt = new DataTable();

            paneldt = abll.Get_Mine_Panel(e.Item.Name);
            if (paneldt.Rows[0]["pic"].ToString().Trim() != "")
            {
                try
                {
                    pictureBox1.Hide();
                    System.IO.MemoryStream memoryStream = new System.IO.MemoryStream((byte[])paneldt.Rows[0]["pic"]);
                    Bitmap bmp = new Bitmap(memoryStream);
                    EmpPicture.Image = bmp;
                    EmpPicture.Show();
                }
                catch
                {
                    pictureBox1.Show();
                    EmpPicture.Hide();
                }
            }
            else
            {
                pictureBox1.Show();
                EmpPicture.Hide();
            }

            EmpLbl.Text = "标识卡:" + paneldt.Rows[0]["标识卡"].ToString() + "\n\n姓名:" + paneldt.Rows[0]["姓名"].ToString() + "\n\n部门:" + paneldt.Rows[0]["部门"].ToString() + "\n\n职务:" + paneldt.Rows[0]["职务"].ToString() + "\n\n现在位置:\n" + paneldt.Rows[0]["地址"].ToString() + "\n\n进入位置的时间:\n" + paneldt.Rows[0]["时间"].ToString();
            EmpPL.BringToFront();
            EmpPL.Show();
        }