You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

259 lines
10 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Syncfusion.WinForms.Controls.Styles;
using Syncfusion.Windows.Forms.Tools;
using Syncfusion.WinForms.Controls;
using Syncfusion.WinForms.DataGrid;
using Syncfusion.WinForms.DataGrid.Interactivity;
using OnDoc.Klassen;
using System.Data.SqlClient;
using Database;
using System.Threading;
using static System.Net.Mime.MediaTypeNames;
namespace OnDoc.Diverses
{
public partial class MitarbeiterProfil : SfForm
{
private int mitarbeiternr = 0;
private bool onLoad = true;
public MitarbeiterProfil()
{
InitializeComponent();
}
public MitarbeiterProfil(int Mitarbeiternr)
{
InitializeComponent();
mitarbeiternr = Mitarbeiternr;
}
private void MitarbeiterProfil_Load(object sender, EventArgs e)
{
refresh_profile();
ribbonTab1_ActiveChanged(sender, e);
refresh_unterschriften_team();
onLoad = false;
lbprofile.SelectedIndex = 0;
}
private void refresh_profile()
{
DB db = new DB(AppParams.connectionstring);
db.Get_Tabledata("Select * from profil where aktiv=1 and mitarbeiternr=" + mitarbeiternr.ToString(), false, true);
lbprofile.DataSource = db.dsdaten.Tables[0];
lbprofile.DisplayMember = "Bezeichnung";
lbprofile.ValueMember = "profilnr";
db = null;
}
private void refresh_unterschriften_team()
{
DB db = new DB(AppParams.connectionstring);
db.clear_parameter();
db.Get_Tabledata("SP_Dokumentbearbeitung_Mitarbeiter", true, false);
cbboxUnterschriftLinks.DataSource = db.dsdaten.Tables[0];
cbboxUnterschriftLinks.DisplayMember = "name";
cbboxUnterschriftLinks.ValueMember = "mitarbeiternr";
cbboxUnterschriftRechts.DataSource = db.dsdaten.Tables[0];
cbboxUnterschriftRechts.DisplayMember = "name";
cbboxUnterschriftRechts.ValueMember = "mitarbeiternr";
db.clear_parameter();
db.add_parameter("@profilnr", 0.ToString());
db.add_parameter("@mitarbeiternr", mitarbeiternr.ToString());
db.Get_Tabledata("sp_dokumentbearbeitung_team", true, false);
cbboxTeam.DataSource = null;
cbboxTeam.DataSource = db.dsdaten.Tables[0];
cbboxTeam.ValueMember = "teamnr";
cbboxTeam.DisplayMember = "bezeichnung";
db = null;
}
private void RibbonButtonExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void lbprofile_SelectedValueChanged(object sender, EventArgs e)
{
if (onLoad) { return; }
DB db = new DB(AppParams.connectionstring);
db.Get_Tabledata("Select * from profil where profilnr=" + lbprofile.SelectedValue, false, true);
cbboxUnterschriftLinks.SelectedValue = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["Unterschriftlinks"].ToString());
cbboxUnterschriftRechts.SelectedValue = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["Unterschriftrechts"].ToString());
cbboxTeam.SelectedValue = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["team"].ToString());
cbStandard.Checked = db.dsdaten.Tables[0].Rows[0]["standard"].ToString() == "True";
txtbezeichnung.Text = db.dsdaten.Tables[0].Rows[0]["bezeichnung"].ToString();
db = null;
}
private void btnSave_Click(object sender, EventArgs e)
{
DB db = new DB(AppParams.connectionstring);
if (cbStandard.Checked)
{
db.Exec_SQL("Update profil set standard=0 where mitarbeiternr=" + mitarbeiternr.ToString());
db.Exec_SQL("Update profil set bezeichnung='" + txtbezeichnung.Text + "', unterschriftlinks=" + cbboxUnterschriftLinks.SelectedValue.ToString() + ", unterschriftrechts=" + cbboxUnterschriftRechts.SelectedValue.ToString() + ", team=" + cbboxTeam.SelectedValue.ToString() + " ,standard=1 where profilnr=" + lbprofile.SelectedValue.ToString());
}
db.Exec_SQL("Update profil set bezeichnung='" + txtbezeichnung.Text + "',unterschriftlinks=" + cbboxUnterschriftLinks.SelectedValue.ToString() + ", unterschriftrechts=" + cbboxUnterschriftRechts.SelectedValue.ToString() + ", team=" + cbboxTeam.SelectedValue.ToString() + " where profilnr=" + lbprofile.SelectedValue.ToString());
db = null;
}
private void ribbonButtonSave_Click(object sender, EventArgs e)
{
int saveselected = Convert.ToInt32(lbprofile.SelectedValue);
DB db = new DB(AppParams.connectionstring);
if (cbStandard.Checked)
{
db.Exec_SQL("Update profil set standard=0 where mitarbeiternr=" + mitarbeiternr.ToString());
db.Exec_SQL("Update profil set bezeichnung='" + txtbezeichnung.Text + "', unterschriftlinks=" + cbboxUnterschriftLinks.SelectedValue.ToString() + ", unterschriftrechts=" + cbboxUnterschriftRechts.SelectedValue.ToString() + ", team=" + cbboxTeam.SelectedValue.ToString() + " ,standard=1 where profilnr=" + lbprofile.SelectedValue.ToString());
}
db.Exec_SQL("Update profil set bezeichnung='" + txtbezeichnung.Text + "',unterschriftlinks=" + cbboxUnterschriftLinks.SelectedValue.ToString() + ", unterschriftrechts=" + cbboxUnterschriftRechts.SelectedValue.ToString() + ", team=" + cbboxTeam.SelectedValue.ToString() + " where profilnr=" + lbprofile.SelectedValue.ToString());
db = null;
refresh_profile();
lbprofile.SelectedValue = saveselected;
}
private void ribbonButtonDelete_Click(object sender, EventArgs e)
{
DB db = new DB(AppParams.connectionstring);
if (cbStandard.Checked)
{
MessageBox.Show("Das Standardprofil kann nicht gelöscht werden.", "Profil löschen", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
db.Exec_SQL("Update profil set aktiv=0 where profilnr=" + lbprofile.SelectedValue.ToString());
}
db = null;
refresh_profile();
lbprofile.SelectedIndex = 0;
}
private void ribbonButtonNew_Click(object sender, EventArgs e)
{
DB db = new DB(AppParams.connectionstring);
db.Get_Tabledata("Select * from profil where profilnr=0", false, true);
int newkey = Convert.ToInt32(db.get_dbkey("Profil").ToString());
db.dsdaten.Tables[0].Rows[0]["PROFILnr"] = newkey;
db.dsdaten.Tables[0].Rows[0]["Mitarbeiternr"] = AppParams.CurrentMitarbieter;
db.dsdaten.Tables[0].TableName = "Profil";
var res = db.InsertDataRow(db.dsdaten.Tables[0].Rows[0], AppParams.connectionstring);
//SqlCommand sqlq = db.CreateInsertCommand(db.dsdaten.Tables[0].Rows[0]);
//db.InsertDataRow(sqlq);
//string sql1 = db.BuildAllFieldsSQL(db.dsdaten.Tables[0]);
//MessageBox.Show(sql1);
//string sql = db.BuildInsertSQL(db.dsdaten.Tables[0]);
//MessageBox.Show(sql);
//db.Exec_SQL(sql);
db = null; ;
refresh_profile();
lbprofile.SelectedValue = newkey;
}
private void ribbonButtonNew_DoubleClick(object sender, EventArgs e)
{
}
private void MitarbeiterProfil_Activated(object sender, EventArgs e)
{
}
private void ribbonTab1_ActiveChanged(object sender, EventArgs e)
{
GrpBoxProfile.Dock = DockStyle.Left;
GrpBoxProfile.Visible = true;
GrpBoxDetails.Dock = DockStyle.Fill;
GrpBoxDetails.Visible = true;
GrpBoxMitarbeiter.Visible = false;
}
private void ribbonTab2_ActiveChanged(object sender, EventArgs e)
{
GrpBoxProfile.Visible = false;
GrpBoxDetails.Visible = false;
GrpBoxMitarbeiter.Visible = true;
GrpBoxMitarbeiter.Dock = DockStyle.Fill;
System.Drawing.Image image = System.Drawing.Image.FromFile(@"E:\Software-Projekte\OnDoc\Images\download.png");
this.pictureBox1.Image = image;
}
protected bool validData;
string path;
protected System.Drawing.Image image;
protected Thread getImageThread;
private void pictureBox1_DragEnter(object sender, DragEventArgs e)
{
string filename;
validData = GetFilename(out filename, e);
if (validData)
{
path = filename;
getImageThread = new Thread(new ThreadStart(LoadImage));
getImageThread.Start();
e.Effect = DragDropEffects.Copy;
}
else
e.Effect = DragDropEffects.None;
}
private bool GetFilename(out string filename, DragEventArgs e)
{
bool ret = false;
filename = String.Empty;
if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy)
{
Array data = ((IDataObject)e.Data).GetData("FileDrop") as Array;
if (data != null)
{
if ((data.Length == 1) && (data.GetValue(0) is String))
{
filename = ((string[])data)[0];
string ext = System.IO.Path.GetExtension(filename).ToLower();
if ((ext == ".jpg") || (ext == ".png") || (ext == ".bmp"))
{
ret = true;
}
}
}
}
return ret;
}
protected void LoadImage()
{
image = new Bitmap(path);
}
private void pictureBox1_DragDrop(object sender, DragEventArgs e)
{
{
if (validData)
{
while (getImageThread.IsAlive)
{
System.Windows.Forms.Application.DoEvents();
Thread.Sleep(0);
}
pictureBox1.Image = image;
}
}
}
}
}