115 lines
4.0 KiB
C#
115 lines
4.0 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
|
|
{
|
|
public partial class UCSchachtanbindung : UserControl
|
|
{
|
|
SchachtAnbindung schacht = null;
|
|
string mydestination = string.Empty;
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="schacht"></param>
|
|
public UCSchachtanbindung(SchachtAnbindung schacht)
|
|
{
|
|
InitializeComponent();
|
|
this.schacht = schacht;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sollte nicht verwendet werden
|
|
/// </summary>
|
|
public UCSchachtanbindung()
|
|
{
|
|
|
|
}
|
|
|
|
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));
|
|
pt_box.Load(Path.Combine(schacht.SavedBilders[0].Speicherpfad));
|
|
pt_box.SizeMode = PictureBoxSizeMode.StretchImage;
|
|
}
|
|
}
|
|
|
|
private void btn_add_bild_Click(object sender, EventArgs e)
|
|
{
|
|
using (OpenFileDialog openFileDialog = new OpenFileDialog())
|
|
{
|
|
if(openFileDialog.ShowDialog() == DialogResult.OK)
|
|
{
|
|
string source = openFileDialog.FileName;
|
|
SavedBilder bilder = new SavedBilder();
|
|
|
|
string targetname = string.Format("{0}.jpg",Guid.NewGuid());
|
|
|
|
try
|
|
{
|
|
if (pt_box == null) throw new Exception();
|
|
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();
|
|
File.Delete(Path.Combine(Global.Instance.Projektpfad, bild.Speicherpfad));
|
|
lb_pictures.DataSource = null;
|
|
lb_pictures.DataSource = schacht.SavedBilders;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|