update 20251113

This commit is contained in:
Stefan Hutter
2025-11-13 17:38:45 +01:00
parent ec5c61cc57
commit 10ed1e6087
6199 changed files with 8549020 additions and 308 deletions

View File

@@ -0,0 +1,67 @@
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Windows.Forms;
using BroadcastListener.Interfaces;
namespace BroadcastListener.Classes
{
public class Broadcaster
{
private readonly Collection<IMessageListener1> _listeners =
new Collection<IMessageListener1>();
/// <summary>
/// Send message
/// </summary>
/// <param name="message">Message</param>
/// <param name="sender"></param>
/// <remarks></remarks>
[DebuggerStepThrough()]
public void Broadcast(string message, SenderInfo sender)
{
foreach (IMessageListener1 listener in _listeners)
{
listener.OnListen(message, sender);
}
}
[DebuggerStepThrough()]
/// <summary>
/// Add a Listener to the Collection of Listeners
/// </summary>
/// <param name="listener"></param>
public void AddListener(IMessageListener1 listener)
{
_listeners.Add(listener);
}
/// <summary>
/// Remove a Listener from the collection
/// </summary>
/// <param name="listener"></param>
public void RemoveListener(IMessageListener1 listener)
{
for (int index = 0; index < _listeners.Count; index++)
{
if ( _listeners[index].Equals(listener) )
{
_listeners.Remove(_listeners[index]);
}
}
}
}
public class SenderInfo
{
public string SenderName { get; set; }
public string Function { get; set; }
public string Details { get; set; }
public SenderInfo(string SenderName, string Funtion, string Details)
{
this.SenderName= SenderName;
this.Function= Funtion;
this.Details= Details;
}
}
}

View File

@@ -0,0 +1,234 @@
using Microsoft.Office.Interop.Excel;
using Newtonsoft.Json.Linq;
using Syncfusion.Windows.Forms.Tools.Win32API;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using System.Xml.Serialization;
using Database;
using Microsoft.Office.Interop.Word;
using Newtonsoft.Json;
namespace OnDoc.Klassen
{
public enum EDK_ActionType
{
AnzeigePartnerdossier = 1,
DokumentAnzeige = 2,
DokumentErstellung = 3,
DokumentBearbeitung = 4,
Statusmutation = 5,
HostDokumentAnzeige = 6,
UVMDokumentanzeige = 7,
ZVDokumentanzeige = 8,
DokLoeschung = 9,
AusHyperlink = 10
}
public class EDK_Parameters
{
public string name { get; set; }
public string value { get; set; }
public EDK_Parameters(string name, string value)
{
this.name = name;
this.value = value;
}
}
public class EDK_Dokumentwerte
{
public string name { get; set; }
public string value { get; set; }
public EDK_Dokumentwerte(string name, string value)
{
this.name = name;
this.value = value;
}
}
public static class EDK_Data
{
public static EDK_ActionType action { get; set; }
public static string sourceApplication { get; set; }
public static string creatortg { get; set; }
public static string source { get; set; }
public static bool executed { get; set; }
public static bool toexecute { get; set; }
public static string verantwortlich { get; set; }
public static string unterschrift_links { get; set; }
public static string unterschrift_rechts { get; set; }
public static string AnzeigePartnernr { get; set; }
public static List<EDK_Parameters> parameters { get; set; }
public static List<EDK_Dokumentwerte> dokumentwerte { get; set; }
public static void Load_EDK_File(string filename)
{
//XmlSerializer serializer = new XmlSerializer(typeof(Action));
//using (StringReader reader = new StringReader(filename))
//{
// var test = (Action)serializer.Deserialize(reader);
//}
var doc = new XmlDocument();
try
{
doc.Load(filename);
}
catch (Exception ex)
{
Logging.Logging.Debug("Fehlerhafte EDK-Datei: " + filename, "OnDoc-EDK", "");
System.IO.File.Delete(filename);
return;
}
// read header elements
action = (EDK_ActionType)Enum.Parse(typeof(EDK_ActionType), doc.SelectSingleNode("action/actionId").InnerText, true);
sourceApplication = doc.SelectSingleNode("action/sourceApplication").InnerText;
DB db = new DB(AppParams.connectionstring);
db.Get_Tabledata("Select count(*) from Avaloq_SourceApplication where AvaloqSourceApplication='" + sourceApplication + "'", false, true);
if (Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][0]) == 0)
{
Logging.Logging.Debug("EDK-Datei für fehlerhafte Instanz:" + source, "EDK-Verarbeitung", filename);
System.IO.File.Delete(filename);
MessageBox.Show("Der EDK-Aufruf ist ungültig, da dieser nciht für die richtige DB-Instanz ist: " + sourceApplication, "EDK-Aufruf", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
switch (action)
{
case EDK_ActionType.AnzeigePartnerdossier:
AnzeigePartnernr = doc.SelectSingleNode("action/PartnerNr").InnerText;
executed = false;
toexecute = true;
break;
case EDK_ActionType.DokumentErstellung:
creatortg = doc.SelectSingleNode("action/creatorTg").InnerText;
source = doc.SelectSingleNode("action/sourceApplication").InnerText;
verantwortlich = "";
try
{
verantwortlich = doc.SelectSingleNode("action/Verantwortlich").InnerText;
}
catch { }
unterschrift_links = "";
unterschrift_rechts = "";
try { unterschrift_links = doc.SelectSingleNode("action/uslinks").InnerText; } catch { }
try { unterschrift_rechts = doc.SelectSingleNode("action/usrechts").InnerText; } catch { }
XmlElement RootNode = doc.DocumentElement;
XmlNodeList nodeList = RootNode.ChildNodes;
XmlNodeList dokwerte = RootNode.LastChild.ChildNodes;
List<EDK_Parameters> Params = new List<EDK_Parameters>();
List<EDK_Dokumentwerte> Dokwerte = new List<EDK_Dokumentwerte>();
if (nodeList.Count > 0)
{
string value;
string name;
var loopTo = nodeList.Count - 1;
for (int i = 0; i < nodeList.Count - 1; i++)
{
value = nodeList.Item(i).InnerText;
name = nodeList.Item(i).LocalName;
Params.Add(new EDK_Parameters(name, value));
}
}
parameters = Params;
if (dokwerte.Count > 0)
{
for (int i = 0; i < dokwerte.Count ; i++)
{
XmlNodeList XNode = dokwerte[i].ChildNodes;
string value;
string name;
try { value = XNode[1].InnerText; } catch { value = ""; }
try { name = XNode[0].InnerText; } catch { name = ""; }
Dokwerte.Add(new EDK_Dokumentwerte(name, value));
}
dokumentwerte = Dokwerte;
var json = JsonConvert.SerializeObject(dokumentwerte);
// System.IO.File.WriteAllText(@"H:\dokwerte.txt", json);
if (parameters.Count > 0)
{
executed = false;
toexecute = true;
} else
{
executed = false;
toexecute = true;
}
}
executed = false;
toexecute = true;
break;
default:
System.IO.File.Delete(filename);
MessageBox.Show("Der Aufruf mit Action " + action.ToString() + " ist für OnDoc ungültig.");
break;
}
}
public static string GetAVQ_Value(string name, string techname)
{
try
{
for (int i = 0; i < dokumentwerte.Count; i++)
{
EDK_Dokumentwerte d = dokumentwerte[i];
// System.IO.File.AppendAllText(@"h:\edklog.txt", Environment.NewLine + dokumentwerte[i].name);
if (dokumentwerte[i].name == name || (dokumentwerte[i].name == techname && dokumentwerte[i].name.ToString()!=""))
{
// System.IO.File.AppendAllText(@"h:\edklog.txt", Environment.NewLine + dokumentwerte[i].value);
return dokumentwerte[i].value;
}
}
return "";
}
catch { return ""; }
}
public static string GetAVQ_Parameter(string name)
{
for (int i = 0; i < parameters.Count+1; i++)
{
if (parameters[i].name.ToUpper() == name.ToUpper())
{
return parameters[i].value;
}
}
return "";
}
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OnDoc.Klassen;
namespace OnDoc.Klassen
{
public class StrukturArgs: EventArgs
{
private string message;
private int dokumentartnr;
private int partnernr;
public StrukturArgs(string message, int dokumentartnr, int partnernr)
{
this.message=message;
this.dokumentartnr=dokumentartnr;
this.partnernr=partnernr;
}
public string Message
{
get
{
return message;
}
}
public int Dokumentartnr
{ get { return dokumentartnr;} }
public int Partnernr
{ get { return partnernr; } }
}
}

View File

@@ -0,0 +1,13 @@
namespace BroadcastListener.Classes
{
public static class Factory
{
private static Broadcaster _broadcaster;
public static Broadcaster Broadcaster()
{
return _broadcaster ?? ( _broadcaster = new Broadcaster() );
}
}
}

View File

@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace OnDoc.Klassen
{
public static class StringCipher
{// This constant is used to determine the keysize of the encryption algorithm in bits.
// We divide this by 8 within the code below to get the equivalent number of bytes.
private const int Keysize = 256;
// This constant determines the number of iterations for the password bytes generation function.
private const int DerivationIterations = 1000;
public static string Encrypt(string plainText, string passPhrase)
{
// Salt and IV is randomly generated each time, but is preprended to encrypted cipher text
// so that the same Salt and IV values can be used when decrypting.
var saltStringBytes = Generate256BitsOfRandomEntropy();
var ivStringBytes = Generate256BitsOfRandomEntropy();
var plainTextBytes = Encoding.UTF8.GetBytes(plainText);
using (var password = new Rfc2898DeriveBytes(passPhrase, saltStringBytes, DerivationIterations))
{
var keyBytes = password.GetBytes(Keysize / 8);
using (var symmetricKey = new RijndaelManaged())
{
symmetricKey.BlockSize = 256;
symmetricKey.Mode = CipherMode.CBC;
symmetricKey.Padding = PaddingMode.PKCS7;
using (var encryptor = symmetricKey.CreateEncryptor(keyBytes, ivStringBytes))
{
using (var memoryStream = new MemoryStream())
{
using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
{
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
cryptoStream.FlushFinalBlock();
// Create the final bytes as a concatenation of the random salt bytes, the random iv bytes and the cipher bytes.
var cipherTextBytes = saltStringBytes;
cipherTextBytes = cipherTextBytes.Concat(ivStringBytes).ToArray();
cipherTextBytes = cipherTextBytes.Concat(memoryStream.ToArray()).ToArray();
memoryStream.Close();
cryptoStream.Close();
return Convert.ToBase64String(cipherTextBytes);
}
}
}
}
}
}
public static string Decrypt(string cipherText, string passPhrase)
{
// Get the complete stream of bytes that represent:
// [32 bytes of Salt] + [32 bytes of IV] + [n bytes of CipherText]
var cipherTextBytesWithSaltAndIv = Convert.FromBase64String(cipherText);
// Get the saltbytes by extracting the first 32 bytes from the supplied cipherText bytes.
var saltStringBytes = cipherTextBytesWithSaltAndIv.Take(Keysize / 8).ToArray();
// Get the IV bytes by extracting the next 32 bytes from the supplied cipherText bytes.
var ivStringBytes = cipherTextBytesWithSaltAndIv.Skip(Keysize / 8).Take(Keysize / 8).ToArray();
// Get the actual cipher text bytes by removing the first 64 bytes from the cipherText string.
var cipherTextBytes = cipherTextBytesWithSaltAndIv.Skip((Keysize / 8) * 2).Take(cipherTextBytesWithSaltAndIv.Length - ((Keysize / 8) * 2)).ToArray();
using (var password = new Rfc2898DeriveBytes(passPhrase, saltStringBytes, DerivationIterations))
{
var keyBytes = password.GetBytes(Keysize / 8);
using (var symmetricKey = new RijndaelManaged())
{
symmetricKey.BlockSize = 256;
symmetricKey.Mode = CipherMode.CBC;
symmetricKey.Padding = PaddingMode.PKCS7;
using (var decryptor = symmetricKey.CreateDecryptor(keyBytes, ivStringBytes))
{
using (var memoryStream = new MemoryStream(cipherTextBytes))
{
using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
using (var streamReader = new StreamReader(cryptoStream, Encoding.UTF8))
{
return streamReader.ReadToEnd();
}
}
}
}
}
}
private static byte[] Generate256BitsOfRandomEntropy()
{
var randomBytes = new byte[32]; // 32 Bytes will give us 256 bits.
using (var rngCsp = new RNGCryptoServiceProvider())
{
// Fill the array with cryptographically secure random bytes.
rngCsp.GetBytes(randomBytes);
}
return randomBytes;
}
}
}

View File

@@ -0,0 +1,364 @@
using Database;
using Syncfusion.Data.Extensions;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.Devices.Bluetooth.Advertisement;
using Windows.Media.Streaming.Adaptive;
using static System.Net.WebRequestMethods;
namespace OnDoc.Klassen
{
public static class AppParams
{
public static string connectionstring { get; set; }
public static string logconnectionstring { get; set; }
public static string tempdir { get; set; }
public static string Version { get; set; } = "6.0";
public static string UseAPI { get; set; } = "FALSE";
public static int CurrentMitarbeiter { get; set; }
public static string RESTURI { get; set; } = "";//"http://localhost:2032/";
public static string apikey { get; set; } = "";
public static string wordprintmacro { get; set; } = "";
public static string vbvorlagenmanagement { get; set; } = "No";
public static string barcodefont { get; set; } = "";
public static string barcodefontsize { get; set; } = "";
public static string barcodetextposition { get; set; } = "";
public static bool isSysadmin { get; set; } = false;
public static bool showlogin { get; set; } = false;
public static string currenttgnummer { get; set; }="";
public static string systemtgnummer { get; set; } = "";
public static string umgebung { get; set; } = "";
public static string ZusatzFont { get; set; } = "";
public static string ZusatzFontSize { get; set; } = "";
public static string EDOKAPath { get; set; } = "";
public static int OfficeSpleep1 { get; set; } = 500;
public static int OfficeSpleep2 { get; set; } = 1000;
public static string pathNativVorlagen { get; set; } = "";
public static int Office_Fill_DocIO { get; set; } = 0;
public static bool StartApp { get; set; } = false;
public static string SignatureWidth { get; set; } = "5";
public static string SignatureColor { get; set; } = "0,0,102";
public static string SignaturePassword { get; set; } = "";
public static string Environment { get; set; } = "";
public static bool versandstrassewindows_open { get; set; } = false;
public static bool AutomArchivierung { get; set; } = false;
public static string SignApp { get; set; } = "";
public static string MachinName { get; set; } = "";
public static bool O365 { get; set; } = false;
public static int MaxFileSize { get; set; } = 9000000;
public static string assemblyversion { get; set; } = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
public static Boolean check_for_updates { get; set; } = false;
public static string updatepath { get; set; } = "";
public static bool DoUpdate { get; set; } = false;
public static bool MultiThreadingSign { get; set; } = false;
public static bool MultiThreadingSB { get; set; } = false;
static AppParams()
{
}
public static void init()
{
string startuppath = AppDomain.CurrentDomain.BaseDirectory;
connectionstring = System.IO.File.ReadAllText(startuppath + @"\ondocconn.cfg");
connectionstring = StringCipher.Decrypt(connectionstring, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm");
logconnectionstring = System.IO.File.ReadAllText(startuppath + @"\logconn.cfg");
logconnectionstring = StringCipher.Decrypt(logconnectionstring, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm");
DB db = new DB(connectionstring);
db.Get_Tabledata("Select * from ondoc_appParams where usedbparams=1", false, true);
//MachinName = System.Environment.MachineName;
//O365=false;
//try
//{
// List<List<string>> groups = new List<List<string>>();
// List<string> current = null;
// foreach (var line in System.IO.File.ReadAllLines(Application.StartupPath+@"o365machines.txt"))
// {
// if (line.Contains(MachinName))
// {
// O365 = true;
// }
// }
//}
//catch { O365 = false; }
if (db.dsdaten.Tables[0].Rows.Count > 0)
{
tempdir = db.dsdaten.Tables[0].Rows[0][0].ToString();
Version = db.dsdaten.Tables[0].Rows[0][1].ToString();
UseAPI = db.dsdaten.Tables[0].Rows[0][2].ToString();
RESTURI = db.dsdaten.Tables[0].Rows[0][3].ToString();
wordprintmacro = db.dsdaten.Tables[0].Rows[0][5].ToString();
vbvorlagenmanagement = db.dsdaten.Tables[0].Rows[0][6].ToString();
barcodefont = db.dsdaten.Tables[0].Rows[0][7].ToString();
barcodefontsize = db.dsdaten.Tables[0].Rows[0][8].ToString();
barcodetextposition = db.dsdaten.Tables[0].Rows[0][9].ToString();
ZusatzFont = db.dsdaten.Tables[0].Rows[0][10].ToString();
ZusatzFontSize = db.dsdaten.Tables[0].Rows[0][11].ToString();
EDOKAPath = db.dsdaten.Tables[0].Rows[0][12].ToString();
OfficeSpleep1 = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][13]);
OfficeSpleep2 = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][14]);
pathNativVorlagen = db.dsdaten.Tables[0].Rows[0][16].ToString();
Office_Fill_DocIO= Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][17]);
SignatureWidth = db.dsdaten.Tables[0].Rows[0][18].ToString();
SignatureColor = db.dsdaten.Tables[0].Rows[0][19].ToString();
SignaturePassword = db.dsdaten.Tables[0].Rows[0][20].ToString();
Environment = db.dsdaten.Tables[0].Rows[0][21].ToString();
AutomArchivierung = db.dsdaten.Tables[0].Rows[0][22].ToString() == "TRUE";
SignApp = db.dsdaten.Tables[0].Rows[0][23].ToString();
MaxFileSize = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][24]);
check_for_updates= db.dsdaten.Tables[0].Rows[0][25].ToString() == "TRUE";
updatepath = db.dsdaten.Tables[0].Rows[0][26].ToString();
MultiThreadingSign= db.dsdaten.Tables[0].Rows[0][27].ToString() == "TRUE";
MultiThreadingSB = db.dsdaten.Tables[0].Rows[0][28].ToString() == "TRUE";
}
else
{
db.Get_Tabledata("Select * from applikation where applikationsnr = 1", false, true);
tempdir = db.dsdaten.Tables[0].Rows[0]["pfad_temporaer_dokumente"].ToString();
StaticValues.UserID = "Stefan Hutter";
UseAPI = Properties.Settings.Default.UseAPI;
RESTURI = Properties.Settings.Default.RESTURI;
//apikey = Properties.Settings.Default.apikey;
wordprintmacro = Properties.Settings.Default.StandardWordDruckMakro;
vbvorlagenmanagement = Properties.Settings.Default.VBVorlagenmanagement;
barcodefont = Properties.Settings.Default.BarcodeFont;
barcodefontsize = Properties.Settings.Default.BarcodeFontSize;
barcodetextposition = Properties.Settings.Default.BarodeTextPosition;
ZusatzFont = Properties.Settings.Default.ZusatzFont;
ZusatzFontSize = Properties.Settings.Default.ZusatzFontSize;
EDOKAPath = Properties.Settings.Default.edokapath;
pathNativVorlagen = Properties.Settings.Default.NativVorlagen;
}
apikey = System.IO.File.ReadAllText(startuppath + @"\apikey.cfg");
apikey = StringCipher.Decrypt(apikey, "PBod8b%s@c9ib7Lws#na5sGM2trugrx3h!oyB^y!Bc%fHEYUT3QvTVr6sAaAr9FoQWzb");
db = null;
EvaluatePath(AppParams.tempdir);
}
private static String EvaluatePath(String path)
{
try
{
String folder = Path.GetDirectoryName(path);
if (!Directory.Exists(folder))
{
// Try to create the directory.
DirectoryInfo di = Directory.CreateDirectory(folder);
}
}
catch (IOException ioex)
{
Console.WriteLine(ioex.Message);
return "";
}
return path;
}
}
public static class ToastMessage
{
public static void ShowToast(string title, string message)
{
return;
// new ToastContentBuilder()
//.AddArgument("Datensicherung", "Datensicherung")
//.AddText(title)
//.AddText(message)
//.Show();
}
}
public static class ExternalCall
{
public static bool executed { get; set; } = false;
public static string function { get; set; } = "";
public static string partnernr { get; set; } = "";
public static string struktur { get; set; } = "";
public static string sourceparam { get; set; } = "";
public static string dokumenttypnr { get; set; } = "0";
public static string Interaktion { get; set; } = "Yes";
public static string showdoc { get; set; } = "Yes";
public static string app { get; set; } = "";
public static string status { get; set; } = "";
public static string dokumentid { get; set; } = "";
public static string unterschriftenpruefung { get; set; } = "No";
public static Boolean parseparams()
{
if (executed) return false;
function = "";
partnernr = "";
struktur = "";
dokumenttypnr = "0";
Interaktion = "Yes";
showdoc = "Yes";
dokumentid = "";
unterschriftenpruefung = "No";
string sparam = sourceparam.Substring(sourceparam.IndexOf('?') + 1, sourceparam.Length - (sourceparam.IndexOf('?') + 1));
if (sparam.ToLower() == "ucheck")
{
unterschriftenpruefung = "Yes";
return true;
}
sparam = Uri.UnescapeDataString(sparam);
executed = true;
sourceparam = "";
string[] istring = sparam.Split('&');
string key = "";
string value = "";
foreach (string s in istring)
{
key = s;
value = key.Substring(key.IndexOf("=") + 1, key.Length - (key.IndexOf("=") + 1));
key = key.Substring(0, key.IndexOf("="));
//MessageBox.Show(key + " " + value);
switch (key.ToLower())
{
case "partnernr":
partnernr = value;
DB db = new DB(AppParams.connectionstring);
db.Get_Tabledata("Select top 1 nrpar00 from partner where nrpar00=" + partnernr.ToString(), false, true);
if (db.dsdaten.Tables[0].Rows.Count < 1)
{
MessageBox.Show("Partnernr:" + partnernr.ToString() + " ist nicht vorhanden", "Parameterfehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
db = null;
break;
case "funktion":
function = value;
if (value.ToLower() != "createdoc" && value.ToLower() != "createpac" && value.ToLower() != "ucheck" && value.ToLower() != "openclient" && value.ToLower()!="createsb" && value.ToLower() != "showdoc")
{
MessageBox.Show("Funktion ist ungültig: " + value, "Parameterfehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
break;
case "vorlagenr":
dokumenttypnr = value;
DB db1 = new DB(AppParams.connectionstring);
db1.Get_Tabledata("Select top 1 dokumenttypnr from dokumenttyp where dokumenttypnr=" + dokumenttypnr.ToString(), false, true);
if (db1.dsdaten.Tables[0].Rows.Count < 1)
{
MessageBox.Show("Dokumenttyp Nr.:" + dokumenttypnr.ToString() + " ist nicht vorhanden", "Parameterfehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
db1 = null;
break;
case "struktur":
struktur = value;
break;
case "interaktion":
Interaktion = value;
break;
case "app":
app = value;
break;
case "st":
status = value;
status = status.ToLower();
break;
case "showdoc":
showdoc = value;
break;
case "id":
try
{
dokumentid = value;
//if (dokumentid.Length > 9)
//{
// if (dokumentid.Substring(0, 9).ToUpper() == "OFFEDK008")
// {
// DB db2 = new DB(AppParams.connectionstring);
// db2.Get_Tabledata("Select count(*) from doks where dokumentid = '" + dokumentid+"'", false, true);
// if (db2.dsdaten.Tables[0].Rows.Count < 1)
// {
// dokumentid = "";
// break;
// }
// db2.Get_Tabledata("Select * from dokument where dokumentid='" + dokumentid+"'", false, true);
// if (db2.dsdaten.Tables[0].Rows.Count > 0)
// {
// if (MessageBox.Show("Das Dokument "+ Environment.NewLine+Environment.NewLine + dokumentid+Environment.NewLine + db2.dsdaten.Tables[0].Rows[0]["Bezeichnung"].ToString()+ Environment.NewLine+Environment.NewLine + " bearbeiten (Ja) oder ein neues Dokument erstellen (Nein)", "OnDoc", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
// {
// dokumentid = "";
// }
// else
// {
// db2.Get_Tabledata("Select * from dokument_trefferliste where dokumentid='"+dokumentid+"'", false, true);
// if (db2.dsdaten.Tables[0].Rows[0]["status_bezeichnungnr"].ToString() == "-1")
// {
// db2.Get_Tabledata("Select * from mitarbeiter where mitarbeiternr=" + db2.dsdaten.Tables[0].Rows[0]["verantwortlich"].ToString(), false, true);
// if (db2.dsdaten.Tables[0].Rows.Count > 0)
// {
// string user = db2.dsdaten.Tables[0].Rows[0]["name"].ToString();
// user = user + db2.dsdaten.Tables[0].Rows[0]["vorname"].ToString();
// user = user + ", "+ db2.dsdaten.Tables[0].Rows[0]["tgnummer"].ToString();
// MessageBox.Show("Das Dokument ist bereits bei " + user + " in Bearbeitung.", "OnDoc", MessageBoxButtons.OK, MessageBoxIcon.Information);
// dokumentid = "";
// }
// }
// }
// }
// db = null;
// }
//}
}
catch {
dokumentid = "";
}
break;
}
}
return true;
}
}
public static class Int_Gridsettings
{
public static DataTable Grids { get; set; }
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnDoc.Klassen
{
internal class clsExcelEdit
{
}
}

View File

@@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OnDoc.Klassen
{
internal class clsMailer
{
public bool sendmail(int Mailtyp, string empfaenger, string betreff, string message, string dokumentid, string ondoclink, string absender, string bewilligungid)
{
string URL = AppParams.RESTURI + "API/SendMail?mailid=" + Mailtyp.ToString() + "&empfaenger=" + empfaenger + "&betreff=" + betreff + "&message=" + message + "&dokumentid=" + dokumentid + "&ondoclink=" + ondoclink + "&absender=" + absender + "&bewilligungid=" + bewilligungid;
HttpWebRequest webRequest = HttpWebRequest.Create(URL) as HttpWebRequest;
webRequest.Method = WebRequestMethods.Http.Get;
webRequest.Headers["Authorization"] = "Bearer " + AppParams.apikey;
try
{
using (HttpWebResponse response = webRequest.GetResponse() as HttpWebResponse)
{
if (response.StatusCode == HttpStatusCode.OK)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string responseContent = reader.ReadToEnd();
Logging.DocLog.Info("Empfanger" + empfaenger + " / Dokumentid:" + dokumentid, "OnDoc", dokumentid, "", "Mail versandt");
return true;
}
else
{
Logging.DocLog.Info("Empfanger" + empfaenger + " / Dokumentid:" + dokumentid, "OnDoc", dokumentid, "", "Mail nicht versandt");
return false;
}
}
}
catch (Exception ex)
{
Logging.DocLog.Info("Empfanger" + empfaenger + " / Dokumentid:" + dokumentid, "OnDoc", dokumentid, "", "Fehler:" + ex.Message);
return false;
}
}
public bool SendHTMLMail(Model.EMail mail)
{
string URL = AppParams.RESTURI + "API/SendHTMLMail";
Logging.Logging.Debug("Start Save Image", "OnDoc", "");
string response;
string jsonstring = Newtonsoft.Json.JsonConvert.SerializeObject(mail);
WebRequest request;
var data = Encoding.UTF8.GetBytes(jsonstring);
request = WebRequest.Create(URL);
request.ContentLength = data.Length;
request.ContentType = "application/json";
request.Method = "POST";
request.Headers["Authorization"] = "Bearer " + AppParams.apikey;
try
{
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(data, 0, data.Length);
requestStream.Close();
using (Stream responseStream = request.GetResponse().GetResponseStream())
{
using (var reader = new StreamReader(responseStream))
{
response = reader.ReadToEnd();
}
}
}
return true;
}
catch (Exception ex)
{
Logging.Logging.Debug("HTML-Mailversand Fehler:" + ex.Message, "OnDoc", "");
return false;
}
}
}
}

View File

@@ -0,0 +1,128 @@
using Syncfusion.WinForms.DataGrid.Interactivity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Syncfusion.Styles;
using Syncfusion.Windows.Forms.Tools;
using Database;
using System.Collections;
namespace OnDoc.Klassen
{
public static class clsPartner
{
private static string Connectionstring = "";
public static DataTable partnerliste;
public static string tableleyout { get; set; } = "";
public static void set_connectionstring(string connectionstring)
{
Connectionstring = connectionstring;
}
public static DataTable search_partner(string query, int anzahl, int fnkt, bool personendokument, bool bpdokument, bool saldiert)
{
DB db = new DB(Connectionstring);
try
{
db.clear_parameter();
db.add_parameter("@query", query);
db.add_parameter("@table", "dbo.partner");
db.add_parameter("@anz", anzahl.ToString());
db.add_parameter("@fnkt", fnkt.ToString());
partnerliste = db.Get_Tabledata("sp_partner_search", true, false);
if (partnerliste.Rows.Count < 1) { return partnerliste; }
string selectstring = "";
if (saldiert == false)
{
selectstring = " saldiert = false ";
}
if (!personendokument && !bpdokument)
{
try {
DataRow[] rowsToKeep = partnerliste.Select(selectstring);
DataTable tempDataTable = rowsToKeep.CopyToDataTable();
partnerliste.Clear();
partnerliste.Merge(tempDataTable);
tempDataTable.Dispose();
}catch
{
partnerliste.Rows.Clear();
}
} else { selectstring = selectstring + " and "; }
if (personendokument)
{
try
{
DataRow[] rowsToKeep = partnerliste.Select(selectstring + "nrpar00 > 100000000");
DataTable tempDataTable = rowsToKeep.CopyToDataTable();
partnerliste.Clear();
partnerliste.Merge(tempDataTable);
tempDataTable.Dispose();
}
catch
{
partnerliste.Rows.Clear();
}
}
if (bpdokument)
{
try
{
DataRow[] rowsToKeep = partnerliste.Select(selectstring+ "nrpar00 < 100000000");
DataTable tempDataTable = rowsToKeep.CopyToDataTable();
partnerliste.Clear();
partnerliste.Merge(tempDataTable);
tempDataTable.Dispose();
}
catch
{
partnerliste.Rows.Clear();
}
}
//int i = 0;
//foreach (DataColumn dc in partnerliste.Columns)
//{
// dc.SetOrdinal(i);
// i++;
//}
//partnerliste.Columns.Add("Partnerart");
//foreach (System.Data.DataRow row in partnerliste.Rows)
//{
// if (Convert.ToInt32(row[0]) > 999999) { row["Partnerart"] = 2; } else { row["Partnerart"] = 1; }
//}
return partnerliste;
}
finally { db = null; }
}
public static DataTable partnerderperson(int partnernr, int fnkt)
{
string result = "";
DB db = new DB(Connectionstring);
db.clear_parameter();
db.add_parameter("@query", partnernr.ToString());
db.add_parameter("@table", "dbo.partner");
db.add_parameter("@anz", "5");
db.add_parameter("@fnkt", fnkt.ToString());
partnerliste = db.Get_Tabledata("sp_partner_search", true, false);
return partnerliste;
//if (db.dsdaten.Tables[0].Rows.Count > 0)
//{
// result=db.dsdaten.Tables[0].Rows[0][0].ToString();
//}
//db = null;
//return result;
}
public static DataTable get_partnerliste() { return partnerliste; }
}
}

View File

@@ -0,0 +1,306 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Management;
using System.Security.AccessControl;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
using Database;
using Syncfusion.Windows.Forms.Tools;
using Syncfusion.WinForms.Input.Enums;
namespace OnDoc.Klassen
{
public static class clsProcessWatch
{
public static System.Timers.Timer watchtimer = new System.Timers.Timer(Convert.ToInt32(Properties.Settings.Default.OfficeWatchTimerIntervall));
static List<FileToCheck> FilestoCheck = new List<FileToCheck>();
public static void AddToList(string dokumentid, string filename, string application)
{
FilestoCheck.Add(new FileToCheck(dokumentid, filename, application));
watchtimer.Elapsed += WatchProcesses;
if (watchtimer.Enabled == false) { watchtimer.Enabled = true; }
}
public static void RemoveFromList(string dokumentid)
{
foreach (FileToCheck fc in FilestoCheck)
{
if (fc.dokumentid == dokumentid)
{
FilestoCheck.Remove(fc);
try
{
System.IO.File.Delete(fc.filename);
}
catch { }
break;
}
}
if (FilestoCheck.Count == 0)
{
watchtimer.Enabled = false;
}
}
private static string GetProcessOwner(int processId)
{
string query = "SELECT * FROM Win32_Process WHERE ProcessID = " + processId;
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectCollection processList = searcher.Get();
foreach (ManagementObject obj in processList)
{
string[] argList = new string[] { string.Empty, string.Empty };
int returnVal = Convert.ToInt32(obj.InvokeMethod("GetOwner", argList));
if (returnVal == 0)
{
// return DOMAIN\user
return argList[1] + "\\" + argList[0];
}
}
searcher = null;
return "NO OWNER";
}
private static void WatchProcesses(object source, ElapsedEventArgs e)
{
bool word = false;
bool excel = false;
bool pdf = false;
bool found = false;
watchtimer.Enabled = false;
found = false;
Logging.Logging.Debug("Start Watch_Process:"+ DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "OnDoc.Processwatch","" );
try
{
foreach (FileToCheck fc in FilestoCheck)
{
if (fc.filedatetime < DateTime.Now.AddSeconds(-5))
{
found = false;
word = false;
excel = false;
pdf = false;
Logging.Logging.Debug(fc.application + " / FileChek " + fc.filename + " / " + fc.filedatetime.ToString("yyyy-MM-dd hh:mm:ss") + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "OnDoc.Processwatch", fc.dokumentid);
if (fc.application == "Word") { word = true; }
if (fc.application == "Excel") { excel = true; }
if (fc.application == "PDF") { pdf = true; }
if (word)
{
Thread.Sleep(200);
Process[] localByName = Process.GetProcessesByName("WINWORD");
foreach (Process p in localByName)
{
string owner = GetProcessOwner(p.Id);
owner = owner.ToUpper();
Logging.Logging.Debug(AppParams.systemtgnummer + "/" + AppParams.currenttgnummer + "/" + owner + "/" + fc.dokumentid + "/" + p.MainWindowTitle, "", "");
if (p.MainWindowTitle.IndexOf(fc.dokumentid) > -1 ||
(p.MainWindowTitle.Trim() == "" && owner.Contains(AppParams.systemtgnummer.ToUpper())))
{
if (p.MainWindowTitle.Trim() != "") { fc.Lastfound = DateTime.Now; }
found = true;
save_to_db(fc);
}
}
//foreach (Process p in localByName)
//{
// Logging.Logging.Debug(fc.dokumentid + "/" + p.MainWindowTitle, "", "");
// if (p.MainWindowTitle.IndexOf(fc.dokumentid) > -1 || p.MainWindowTitle.Trim() == "")
// {
// if (p.MainWindowTitle.Trim() != "") { fc.Lastfound = DateTime.Now; }
// found = true;
// save_to_db(fc);
// break;
// }
//}
}
if (excel)
{
Process[] localByName = Process.GetProcessesByName("EXCEL");
foreach (Process p in localByName)
{
string owner = GetProcessOwner(p.Id);
owner = owner.ToUpper();
if (p.MainWindowTitle.IndexOf(fc.dokumentid) > -1 ||
(p.MainWindowTitle.Trim() == "" && owner.Contains(AppParams.systemtgnummer.ToUpper())))
{
if (p.MainWindowTitle.Trim() != "") { fc.Lastfound = DateTime.Now; }
found = true;
save_to_db(fc);
}
}
//Process[] localByName = Process.GetProcessesByName("EXCEL");
//foreach (Process p in localByName)
//{
// if (p.MainWindowTitle.IndexOf(fc.dokumentid) > -1 || p.MainWindowTitle.Trim() == "")
// {
// if (p.MainWindowTitle.Trim() != "") { fc.Lastfound = DateTime.Now; }
// found = true;
// save_to_db(fc);
// }
//}
}
if (!found)
{
Logging.Logging.Debug("Not Found " + fc.filename + " / " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "OnDoc.Processwatch", fc.dokumentid);
if (Check_Modified(fc) == true)
{
Save_File(fc.dokumentid, fc.filename);
Logging.DocLog.Info("Dokument gespeichert und geschlossen", "Processwatch", fc.dokumentid, "", fc.filename);
RemoveFromList(fc.dokumentid);
Remove_Dok_in_Bearbeitung(fc.dokumentid);
Remove_Dokumentbearbeitung_Zwingend(fc.dokumentid);
Remove_Approvals(fc.dokumentid);
return;
}
else
{
Logging.DocLog.Info("Dokument ohne speichern geschlossen", "Processwatch", fc.dokumentid, "", fc.filename);
RemoveFromList(fc.dokumentid);
Remove_Dok_in_Bearbeitung(fc.dokumentid);
return;
};
}
}
}
watchtimer.Enabled = true;
}
catch (Exception ex)
{
Logging.Logging.Debug("Error Processwatch", "OnDoc", ex.Message);
}
finally
{
watchtimer.Enabled = true ;
}
}
private static void Remove_Dok_in_Bearbeitung(string dokumentid)
{
DB db = new DB(AppParams.connectionstring);
db.Dok_in_Bearbeitung(2, dokumentid, AppParams.CurrentMitarbeiter);
db = null;
}
private static void Remove_Dokumentbearbeitung_Zwingend(string dokumentid)
{
DB db = new DB(AppParams.connectionstring);
db.Exec_SQL("Update dokument set bearbeitung_zwingend=0 where dokumentid='" + dokumentid + "'");
db = null;
}
private static void Remove_Approvals(string dokumentid)
{
DB db = new DB(AppParams.connectionstring);
db.Exec_SQL("Update dokument_bewilligung set aktiv=0, mutiert_am=getdate(), mutierer=" + AppParams.CurrentMitarbeiter.ToString() + " where dokumentid='" + dokumentid + "'");
db = null;
}
private static void save_to_db(FileToCheck fc)
{
if (Check_Modified(fc))
{
try
{
System.IO.File.Copy(fc.filename, fc.filename + ".tmp");
Save_File(fc.dokumentid, fc.filename + ".tmp");
fc.filedatetime = DateTime.Now;
System.IO.File.Delete(fc.filename + ".tmp");
Logging.Logging.Debug(fc.application + " / save_to_db " + fc.filename + " / " + fc.filedatetime.ToString("yyyy-MM-dd hh:mm:ss") + "/" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "OnDoc.Processwatch", fc.dokumentid);
}
catch
{
Logging.Logging.Debug(fc.application + " / save_to_db faild " + fc.filename + " / " + fc.filedatetime.ToString("yyyy-MM-dd hh:mm:ss") + "/" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "OnDoc.Processwatch", fc.dokumentid);
}
}
}
private static void Save_File(string dokumentid, string filename)
{
DB db = new DB(AppParams.connectionstring);
db.Get_Tabledata("Select * from dokument where dokumentid='" + dokumentid + "'", false, true);
db.Save_To_DB(dokumentid, filename);
db.set_approvalstate(dokumentid, false);
db.Exec_SQL("Update dokument set mutiertam = getdate(), mutierer=" + AppParams.CurrentMitarbeiter + " where dokumentid='" + dokumentid + "'");
Logging.DocLog.Info("Dokument gespeichert", "Processwatch", dokumentid, "", filename);
db = null;
}
private static bool Check_Modified(FileToCheck fc)
{
DateTime lwt = System.IO.File.GetLastWriteTime(fc.filename);
if (lwt.Year < DateTime.Now.Year)
{
lwt = fc.filedatetime;
lwt = fc.filedatetime.AddSeconds(+5);
}
int secdiff = (int)((lwt - fc.filedatetime).TotalSeconds);
Logging.Logging.Debug("Prozesswatch - Check Modified: " + lwt.ToString() + "," + fc.filedatetime.ToString(), "OnDoc", fc.dokumentid);
//Logging.DocLog.Debug("Prozesswatch - Check Modified: " + lwt.ToString() + "," + fc.filedatetime.ToString(), "Processwatch", fc.dokumentid, "", fc.filename);
//if ((lwt- fc.filedatetime).Seconds > 2)
if (secdiff > 2)
{
return true;
}
else
{
return false;
}
}
public static int check_open_files()
{
return FilestoCheck.Count;
}
}
public class FileToCheck
{
public string dokumentid { get; set; }
public string filename { get; set; }
public string application { get; set; }
public int counter { get; set; } = 0;
public DateTime Lastfound { get; set; } = DateTime.Now;
public DateTime filedatetime { get; set; }
public FileToCheck(string dokumentid, string filename, string application)
{
this.dokumentid = dokumentid;
this.filename = filename;
this.application = application;
this.filedatetime = DateTime.Now;
//Logging.DocLog.Debug("Add Processwatch: " + DateTime.Now.ToString(), "New FileToCheck", dokumentid, "", "Add Processwatch");
Logging.Logging.Debug("Add Processwatch: " + DateTime.Now.ToString(), "OnDoc", this.dokumentid);
}
}
}

View File

@@ -0,0 +1,17 @@
using Syncfusion.Windows.Forms.Tools;
using Syncfusion.Windows.Forms.Tools.MultiColumnTreeView;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnDoc.Klassen
{
public static class StaticValues
{
public static string UserID { get; set; } = "";
public static TreeViewAdv vorlagen { get; set; } = new TreeViewAdv();
}
}

View File

@@ -0,0 +1,77 @@
using Microsoft.Office.Interop.Word;
using OnDoc.UIControls.Administrator;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Web.Security;
namespace OnDoc.Klassen
{
public class clsWordEdit
{
public string connectstring { get;set; }
public string filename { get; set; }
public string dokumentid { get; set; }
public
Microsoft.Office.Interop.Word.Application word;
Document doc = null;
public clsWordEdit(string connectstring, string filename, string dokumentid)
{
this.connectstring = connectstring;
this.filename = filename;
this.dokumentid = dokumentid;
}
public bool Start_Application()
{
try
{
//word = Interaction.CreateObject("Word.Application")
word = new Microsoft.Office.Interop.Word.Application();
return true;
}
catch
{
return false;
}
}
public void Edit_Document()
{
Start_Application();
doc = word.Documents.Open(filename);
word.Visible= true;
clsProcessWatch.AddToList(dokumentid, filename, "Word");
bool isClosed = IsDocumentClosed(word, doc);
}
public void Control_Word(string dokumentid, string filename, string application)
{
clsProcessWatch.AddToList(dokumentid, filename, application);
}
static bool IsDocumentClosed(Application wordApp, Document doc)
{
// Check if the document is still listed in the Documents collection
foreach (Document openDoc in wordApp.Documents)
{
if (openDoc.FullName == doc.FullName)
{
return false; // Document is still open
}
}
return true; // Document is closed
}
public void run_macros()
{
}
}
}

View File

@@ -0,0 +1,47 @@
using Syncfusion.Styles;
using Syncfusion.WinForms.Controls;
using Syncfusion.WinForms.Controls.Styles;
using Syncfusion.WinForms.DataGrid.RowFilter;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Media;
namespace OnDoc.Klassen
{
public static class Theaming
{
//public static string FormTitleColor = "77,79,83";
//public static string FormTitleFont = "Arial 11";
//public static string FormTitleFontColor = "191,192,195";
public static string FormTitleColor = "154,155,156";
public static string FormTitleFont = "Arial 11";
public static string FormTitleFontColor = "12,12,12";
private static int r;
private static int b;
private static int g;
public static byte ShadowOpacity = 100;
public static byte InactivShadowOpacity = 100;
public static Color Titelbar()
{
return parseColor(FormTitleColor);
}
public static Color TitelFontColor()
{
return parseColor(FormTitleFontColor);
//return Color.FromArgb(77, 79, 83);
}
static public Color parseColor(string inputcode)
{
string[] colors = inputcode.Split(',');
return Color.FromArgb(Convert.ToInt32(colors[0]), Convert.ToInt32(colors[1]), Convert.ToInt32(colors[2]));
}
}
}

View File

@@ -0,0 +1,468 @@
/*
* Author: Tony Brix, http://tonybrix.info
* License: MIT
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
public enum InputBoxButtons
{
OK,
OKCancel,
YesNo,
YesNoCancel,
Save,
SaveCancel
}
public enum InputBoxResult
{
Cancel,
OK,
Yes,
No,
Save
}
public struct InputBoxItem
{
public string Label;
public string Text;
public bool IsPassword;
public InputBoxItem(string label)
{
Label = label;
Text = "";
IsPassword = false;
}
public InputBoxItem(string label, string text)
{
Label = label;
Text = text;
IsPassword = false;
}
public InputBoxItem(string label, bool isPassword)
{
Label = label;
Text = "";
IsPassword = isPassword;
}
public InputBoxItem(string label, string text, bool isPassword)
{
Label = label;
Text = text;
IsPassword = isPassword;
}
}
//public struct InputBoxOptions
//{
// public bool ShowCloseButton = true;
//}
public class InputBox
{
private Dictionary<string, string> items;
private InputBoxResult result;
private InputBox(dialogForm dialog)
{
result = dialog.InputResult;
items = new Dictionary<string, string>();
for (int i = 0; i < dialog.label.Length; i++)
{
items.Add(dialog.label[i].Text, dialog.textBox[i].Text);
}
}
public static InputBox Show(string title, string label)
{
dialogForm dialog = new dialogForm(title, new InputBoxItem[] { new InputBoxItem(label) }, InputBoxButtons.OK);
dialog.ShowDialog();
return new InputBox(dialog);
}
public static InputBox Show(string title, string label, InputBoxButtons buttons)
{
dialogForm dialog = new dialogForm(title, new InputBoxItem[] { new InputBoxItem(label) }, buttons);
dialog.ShowDialog();
return new InputBox(dialog);
}
public static InputBox Show(string title, string label, string text)
{
dialogForm dialog = new dialogForm(title, new InputBoxItem[] { new InputBoxItem(label, text) }, InputBoxButtons.OK);
dialog.ShowDialog();
return new InputBox(dialog);
}
public static InputBox Show(string title, string label, string text, InputBoxButtons buttons)
{
dialogForm dialog = new dialogForm(title, new InputBoxItem[] { new InputBoxItem(label, text) }, buttons);
dialog.ShowDialog();
return new InputBox(dialog);
}
public static InputBox Show(string title, string[] labels)
{
InputBoxItem[] items = new InputBoxItem[labels.Length];
for (int i = 0; i < labels.Length; i++)
{
items[i] = new InputBoxItem(labels[i]);
}
dialogForm dialog = new dialogForm(title, items, InputBoxButtons.OK);
dialog.ShowDialog();
return new InputBox(dialog);
}
public static InputBox Show(string title, string[] labels, InputBoxButtons buttons)
{
InputBoxItem[] items = new InputBoxItem[labels.Length];
for (int i = 0; i < labels.Length; i++)
{
items[i] = new InputBoxItem(labels[i]);
}
dialogForm dialog = new dialogForm(title, items, buttons);
dialog.ShowDialog();
return new InputBox(dialog);
}
public static InputBox Show(string title, InputBoxItem item)
{
dialogForm dialog = new dialogForm(title, new InputBoxItem[] { item }, InputBoxButtons.OK);
dialog.ShowDialog();
return new InputBox(dialog);
}
public static InputBox Show(string title, InputBoxItem item, InputBoxButtons buttons)
{
dialogForm dialog = new dialogForm(title, new InputBoxItem[] { item }, buttons);
dialog.ShowDialog();
return new InputBox(dialog);
}
public static InputBox Show(string title, InputBoxItem[] items)
{
dialogForm dialog = new dialogForm(title, items, InputBoxButtons.OK);
dialog.ShowDialog();
return new InputBox(dialog);
}
public static InputBox Show(string title, InputBoxItem[] items, InputBoxButtons buttons)
{
dialogForm dialog = new dialogForm(title, items, buttons);
dialog.ShowDialog();
return new InputBox(dialog);
}
public static InputBox Show(IWin32Window window, string title, string label)
{
dialogForm dialog = new dialogForm(title, new InputBoxItem[] { new InputBoxItem(label) }, InputBoxButtons.OK);
dialog.ShowDialog(window);
return new InputBox(dialog);
}
public static InputBox Show(IWin32Window window, string title, string label, InputBoxButtons buttons)
{
dialogForm dialog = new dialogForm(title, new InputBoxItem[] { new InputBoxItem(label) }, buttons);
dialog.ShowDialog(window);
return new InputBox(dialog);
}
public static InputBox Show(IWin32Window window, string title, string label, string text)
{
dialogForm dialog = new dialogForm(title, new InputBoxItem[] { new InputBoxItem(label, text) }, InputBoxButtons.OK);
dialog.ShowDialog(window);
return new InputBox(dialog);
}
public static InputBox Show(IWin32Window window, string title, string label, string text, InputBoxButtons buttons)
{
dialogForm dialog = new dialogForm(title, new InputBoxItem[] { new InputBoxItem(label, text) }, buttons);
dialog.ShowDialog(window);
return new InputBox(dialog);
}
public static InputBox Show(IWin32Window window, string title, string[] labels)
{
InputBoxItem[] items = new InputBoxItem[labels.Length];
for (int i = 0; i < labels.Length; i++)
{
items[i] = new InputBoxItem(labels[i]);
}
dialogForm dialog = new dialogForm(title, items, InputBoxButtons.OK);
dialog.ShowDialog(window);
return new InputBox(dialog);
}
public static InputBox Show(IWin32Window window, string title, string[] labels, InputBoxButtons buttons)
{
InputBoxItem[] items = new InputBoxItem[labels.Length];
for (int i = 0; i < labels.Length; i++)
{
items[i] = new InputBoxItem(labels[i]);
}
dialogForm dialog = new dialogForm(title, items, buttons);
dialog.ShowDialog(window);
return new InputBox(dialog);
}
public static InputBox Show(IWin32Window window, string title, InputBoxItem item)
{
dialogForm dialog = new dialogForm(title, new InputBoxItem[] { item }, InputBoxButtons.OK);
dialog.ShowDialog(window);
return new InputBox(dialog);
}
public static InputBox Show(IWin32Window window, string title, InputBoxItem item, InputBoxButtons buttons)
{
dialogForm dialog = new dialogForm(title, new InputBoxItem[] { item }, buttons);
dialog.ShowDialog(window);
return new InputBox(dialog);
}
public static InputBox Show(IWin32Window window, string title, InputBoxItem[] items)
{
dialogForm dialog = new dialogForm(title, items, InputBoxButtons.OK);
dialog.ShowDialog(window);
return new InputBox(dialog);
}
public static InputBox Show(IWin32Window window, string title, InputBoxItem[] items, InputBoxButtons buttons)
{
dialogForm dialog = new dialogForm(title, items, buttons);
dialog.ShowDialog(window);
return new InputBox(dialog);
}
public Dictionary<string, string> Items
{
get { return items; }
}
public InputBoxResult Result
{
get { return result; }
}
private class dialogForm : Form
{
private InputBoxResult inputResult = InputBoxResult.Cancel;
public TextBox[] textBox;
public Label[] label;
private Button button1;
private Button button2;
private Button button3;
public InputBoxResult InputResult
{
get { return inputResult; }
}
public dialogForm(string title, InputBoxItem[] items, InputBoxButtons buttons)
{
int minWidth = 312;
label = new Label[items.Length];
for (int i = 0; i < label.Length; i++)
{
label[i] = new Label();
}
textBox = new TextBox[items.Length];
for (int i = 0; i < textBox.Length; i++)
{
textBox[i] = new TextBox();
}
button2 = new Button();
button3 = new Button();
button1 = new Button();
SuspendLayout();
//
// label
//
for (int i = 0; i < items.Length; i++)
{
label[i].AutoSize = true;
label[i].Location = new Point(12, 9 + (i * 39));
label[i].Name = "label[" + i + "]";
label[i].Text = items[i].Label;
if (label[i].Width > minWidth)
{
minWidth = label[i].Width;
}
}
//
// textBox
//
for (int i = 0; i < items.Length; i++)
{
textBox[i].Anchor = (AnchorStyles)(AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
textBox[i].Location = new Point(12, 25 + (i * 39));
textBox[i].Name = "textBox[" + i + "]";
textBox[i].Size = new Size(288, 20);
textBox[i].TabIndex = i;
textBox[i].Text = items[i].Text;
if (items[i].IsPassword)
{
textBox[i].UseSystemPasswordChar = true;
}
}
//
// button1
//
button1.Anchor = (AnchorStyles)(AnchorStyles.Bottom | AnchorStyles.Right);
button1.Location = new Point(208, 15 + (39 * label.Length));
button1.Name = "button1";
button1.Size = new Size(92, 23);
button1.TabIndex = items.Length + 2;
button1.Text = "button1";
button1.UseVisualStyleBackColor = true;
//
// button2
//
button2.Anchor = (AnchorStyles)(AnchorStyles.Bottom | AnchorStyles.Right);
button2.Location = new Point(110, 15 + (39 * label.Length));
button2.Name = "button2";
button2.Size = new Size(92, 23);
button2.TabIndex = items.Length + 1;
button2.Text = "button2";
button2.UseVisualStyleBackColor = true;
//
// button3
//
button3.Anchor = (AnchorStyles)(AnchorStyles.Bottom | AnchorStyles.Right);
button3.Location = new Point(12, 15 + (39 * label.Length));
button3.Name = "button3";
button3.Size = new Size(92, 23);
button3.TabIndex = items.Length;
button3.Text = "button3";
button3.UseVisualStyleBackColor = true;
//
// Evaluate MessageBoxButtons
//
switch (buttons)
{
case InputBoxButtons.OK:
button1.Text = "OK";
button1.Click += OK_Click;
button2.Visible = false;
button3.Visible = false;
AcceptButton = button1;
break;
case InputBoxButtons.OKCancel:
button1.Text = "Cancel";
button1.Click += Cancel_Click;
button2.Text = "OK";
button2.Click += OK_Click;
button3.Visible = false;
AcceptButton = button2;
break;
case InputBoxButtons.YesNo:
button1.Text = "No";
button1.Click += No_Click;
button2.Text = "Yes";
button2.Click += Yes_Click;
button3.Visible = false;
AcceptButton = button2;
break;
case InputBoxButtons.YesNoCancel:
button1.Text = "Cancel";
button1.Click += Cancel_Click;
button2.Text = "No";
button2.Click += No_Click;
button3.Text = "Yes";
button3.Click += Yes_Click;
AcceptButton = button3;
break;
case InputBoxButtons.Save:
button1.Text = "Save";
button1.Click += Save_Click;
button2.Visible = false;
button3.Visible = false;
AcceptButton = button1;
break;
case InputBoxButtons.SaveCancel:
button1.Text = "Cancel";
button1.Click += Cancel_Click;
button2.Text = "Save";
button2.Click += Save_Click;
button3.Visible = false;
AcceptButton = button2;
break;
default:
throw new Exception("Invalid InputBoxButton Value");
}
//
// dialogForm
//
AutoScaleDimensions = new SizeF(6F, 13F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(312, 47 + (39 * items.Length));
for (int i = 0; i < label.Length; i++)
{
Controls.Add(label[i]);
}
for (int i = 0; i < textBox.Length; i++)
{
Controls.Add(textBox[i]);
}
Controls.Add(button1);
Controls.Add(button2);
Controls.Add(button3);
MaximizeBox = false;
MinimizeBox = false;
MaximumSize = new Size(99999, 85 + (39 * items.Length));
Name = "dialogForm";
ShowIcon = false;
ShowInTaskbar = false;
Text = title;
ResumeLayout(false);
PerformLayout();
foreach (Label l in label)
{
if (l.Width > minWidth)
{
minWidth = l.Width;
}
}
ClientSize = new Size(minWidth + 24, 47 + (39 * items.Length));
MinimumSize = new Size(minWidth + 40, 85 + (39 * items.Length));
}
private void OK_Click(object sender, EventArgs e)
{
inputResult = InputBoxResult.OK;
Close();
}
private void Cancel_Click(object sender, EventArgs e)
{
inputResult = InputBoxResult.Cancel;
Close();
}
private void Yes_Click(object sender, EventArgs e)
{
inputResult = InputBoxResult.Yes;
Close();
}
private void No_Click(object sender, EventArgs e)
{
inputResult = InputBoxResult.No;
Close();
}
private void Save_Click(object sender, EventArgs e)
{
inputResult = InputBoxResult.Save;
Close();
}
}
}