161 lines
5.4 KiB
C#
161 lines
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using KlassenBIB;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
|
|
namespace SanSystem
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public partial class UCWeitereFotos : UserControl
|
|
{
|
|
SchachtAnbindung schacht = null;
|
|
string mydestination = string.Empty;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="schacht"></param>
|
|
public UCWeitereFotos(SchachtAnbindung schacht)
|
|
{
|
|
InitializeComponent();
|
|
this.schacht = schacht;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sollte nicht verwendet werden
|
|
/// </summary>
|
|
public UCWeitereFotos()
|
|
{
|
|
|
|
}
|
|
|
|
private void UCSchachtanbindung_Load(object sender, EventArgs e)
|
|
{
|
|
txt_schachtnummer.DataBindings.Add(new Binding("Text", schacht, "Schachtnummer"));
|
|
cb_erledigt.DataBindings.Add(new Binding("Checked", schacht, "Fertig"));
|
|
dt_datum.DataBindings.Add(new Binding("Value", schacht, "Datum"));
|
|
lb_pictures.DataSource = schacht.SavedBilders;
|
|
|
|
|
|
mydestination = schacht.CheckVerzeichnisse(Global.Instance.Projektpfad);
|
|
|
|
if(schacht.SavedBilders.Count > 0)
|
|
{
|
|
|
|
//pt_box.Image = Image.FromFile(Path.Combine("temp",schacht.SavedBilders[0].Speicherpfad));
|
|
|
|
}
|
|
}
|
|
|
|
private void btn_add_bild_Click(object sender, EventArgs e)
|
|
{
|
|
using (OpenFileDialog openFileDialog = new OpenFileDialog())
|
|
{
|
|
if (txt_schachtnummer.Text == "")
|
|
{
|
|
bool found = false;
|
|
try
|
|
{
|
|
IEnumerable<string> directories = Directory.EnumerateDirectories(@"C:\K2000w\BILDER");
|
|
foreach (string directory in directories)
|
|
{
|
|
if(directory.Contains(Global.Instance.ProjektNummer))
|
|
{
|
|
found = true;
|
|
openFileDialog.InitialDirectory = directory;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch(DirectoryNotFoundException)
|
|
{
|
|
// Do Nothing
|
|
}
|
|
|
|
if(!found)
|
|
{
|
|
openFileDialog.InitialDirectory = @"C:\K2000w\BILDER";
|
|
}
|
|
}
|
|
|
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
string source = openFileDialog.FileName;
|
|
SavedBilder bilder = new SavedBilder();
|
|
|
|
string targetname = string.Format("{0}.jpg",Guid.NewGuid());
|
|
|
|
try
|
|
{
|
|
string speicherpfad = Path.Combine(mydestination, targetname);
|
|
File.Copy(source, speicherpfad);
|
|
|
|
bilder.Bildname = "Anbindung";
|
|
bilder.Speicherpfad = speicherpfad;
|
|
schacht.SavedBilders.Add(bilder);
|
|
pt_box.Load(schacht.SavedBilders[0].Speicherpfad);
|
|
pt_box.SizeMode = PictureBoxSizeMode.StretchImage;
|
|
//lb_pictures.DataSource = null;
|
|
//lb_pictures.DataSource = schacht.SavedBilders;
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message.ToString());
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void lb_pictures_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
if (e.Button == MouseButtons.Right)
|
|
contextMenuStrip1.Show(Cursor.Position);
|
|
}
|
|
|
|
private void löschenToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (lb_pictures.SelectedItems.Count < 1) return;
|
|
if(MessageBox.Show("Sicher dass du diesen Eintrag löschen möchtest?","Sicher", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
|
|
{
|
|
|
|
SavedBilder bild = (lb_pictures.SelectedItem as SavedBilder);
|
|
schacht.SavedBilders.Remove(bild);
|
|
pt_box.Image = null;
|
|
pt_box.Dispose();
|
|
lb_pictures.DataSource = null;
|
|
lb_pictures.DataSource = schacht.SavedBilders;
|
|
}
|
|
|
|
}
|
|
|
|
private void lb_pictures_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
ListBox listBox = (ListBox)sender;
|
|
if (listBox == null) return;
|
|
int index = listBox.SelectedIndex;
|
|
if (index == -1) return;
|
|
|
|
string pfad = Path.Combine(schacht.SavedBilders[index].Speicherpfad);
|
|
if (!File.Exists(pfad))
|
|
{
|
|
MessageBox.Show("Bilddatei mit den Pfad " + pfad + " nicht gefunden");
|
|
return;
|
|
}
|
|
pt_box.Load(pfad);
|
|
|
|
pt_box.SizeMode = PictureBoxSizeMode.StretchImage;
|
|
}
|
|
}
|
|
}
|