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.

327 lines
13 KiB

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.VisualBasic;
using NDde.Client;
namespace ARSDDE
{
class Program
{
static bool cmd_ok = false;
static string ARS_Application;
static string ARS_System;
static string ARS_User;
static string ARS_Password;
static string ARS_Foler;
static string ARS_DocID;
static string ARS_Datum;
static string ARS_Type;
static string Debug = "false";
static string ARS_Language;
static string ARS_Doctype;
static string ARS_AuftragNr;
static string ARS_Belegart;
static DdeClient Client;
static string DebugFilename;
// static DdeClient Client = new DdeClient("ARS", "ARS");
static void Main(string[] args)
{
DebugFilename = @"h:\arsdebug_" + DateTime.Now.ToString("yyyyddMMhhmmsshs") + ".txt";
Debug = Properties.Settings.Default.Debug;
Debug =Debug.ToLower();
Debug_Print("Before Parse");
cmd_ok = Parse_Commandline(args);
Debug_Print("After Parse");
if (Debug=="true")
{
Debug_Print("ARS-Client:" + Properties.Settings.Default.OnDemandClinetString);
Debug_Print(String.Format("ARS_Application: {0}", ARS_Application));
Debug_Print(String.Format("ARS_System: {0}", ARS_System));
Debug_Print(String.Format("ARS_User: {0}", ARS_User));
Debug_Print(String.Format("ARS_Password: {0}", "********"));
Debug_Print(String.Format("ARS_Folder: {0}", ARS_Foler));
Debug_Print(String.Format("ARS_DocID: {0}", ARS_DocID));
Debug_Print(String.Format("ARS_Datum: {0}", ARS_Datum));
Debug_Print(String.Format("ARS_Typ: {0}", ARS_Type));
Debug_Print(String.Format("ARS_Auftragnr: {0}", ARS_AuftragNr));
Debug_Print(String.Format("ARS_Belegart: {0}", ARS_Belegart));
}
try
{
Debug_Print("Start");
Call_OnDemand("Start");
Client = new DdeClient(Properties.Settings.Default.OnDemandClinetString, Properties.Settings.Default.OnDemandClinetString);
try
{
Client.Connect();
if (Client.IsConnected==false)
{
MessageBox.Show("Client konnte nicht verbunden werden");
}
}
catch (NDde.DdeException e)
{
MessageBox.Show(e.Message);
};
if (Client == null)
{
MessageBox.Show("Client konnte nicht alloziert werden");
}
Call_OnDemand("Logon");
Call_OnDemand("Open_Folder");
Call_OnDemand("Set_FieldData");
Call_OnDemand("Search_Folder");
Call_OnDemand("Show_Doc");
Call_OnDemand("Logoff");
if (Debug == "true") { Console.ReadLine(); }
}
catch (Exception mainex)
{
MessageBox.Show("Fehler: " + mainex.Message);
}
}
static void Debug_Print(string s)
{
if (Debug == "true")
{
//string filename;
using (StreamWriter w = File.AppendText(DebugFilename))
{
w.WriteLine(s);
w.Close();
}
};
if (Debug=="true")
{
//Console.WriteLine(s);
}
}
static void Call_OnDemand(string arg)
{
switch (arg.ToString())
{
case "Start":
if (Properties.Settings.Default.StartClient.ToLower()=="true")
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = Path.GetFileName(ARS_Application);
psi.WorkingDirectory = Path.GetDirectoryName(ARS_Application);
psi.Arguments= "/1 " + ARS_Language + " /S " + ARS_System + " /U " + ARS_User + " /P " + ARS_Password + " /I /B /V /T EDOKA COLD-Dokumentanzeige " + " /Z /Q /Y /O 1 /X";
psi.Arguments = "/1 " + ARS_Language + " /S " + ARS_System + " /I /B /V /T EDOKA COLD-Dokumentanzeige " + " /Z /Q /Y /O 1 /X";
psi.WindowStyle = ProcessWindowStyle.Maximized;
psi.UseShellExecute = false;
if (Properties.Settings.Default.UseShellExecute.ToLower()== "true")
{
psi.UseShellExecute = true;
}
Process.Start(psi);
System.Threading.Thread.Sleep(Convert.ToInt32(Properties.Settings.Default.WaitAfterStart));
}
break;
case "Logon":
int logontry;
logontry = 0;
try
{
ExecARS(string.Format("LOGON /S {0} /U {1} /P {2}", ARS_System, ARS_User, ARS_Password));
}
catch (Exception e)
{
logontry = logontry + 1;
if (logontry >= 3) {
throw new System.ArgumentException("3 Loginversuche sind fehlgeschlagen.Bitte erneut versuchen.", "LoginFehler");
}
}
System.Threading.Thread.Sleep(Convert.ToInt32(Properties.Settings.Default.DDESleep));
break;
case "Open_Folder":
// 20201019 - Erweiterung /S /C /R /D -> Buttons ausblenden
ExecARS(string.Format("OPEN_FOLDER /F {0} /S /C /R /D", ARS_Foler));
break;
case "Search_Folder":
ExecARS("SEARCH_FOLDER");
break;
case "Show_Doc":
ExecARS("OPEN_DOC /N 0");
break;
case "Set_FieldData":
switch (ARS_Foler)
{
case "TGKB Kundenoutput AGI-OMS für EDOKA User":
ExecARS(string.Format("SET_FIELD_DATA /F Dokument-Id /1 {0}", ARS_DocID),0);
ExecARS(string.Format("SET_FIELD_DATA /F Erstellung od. Valuta Datum /1 {0} /2 {1} ", FormatDate(ARS_Datum), FormatDate(ARS_Datum)),0);
ExecARS(string.Format("SET_FIELD_DATA /F Erstellung od. Valuta Datum /1 {0} /2 {1} ", FormatDate(ARS_Datum), FormatDate(ARS_Datum)),0);
break;
case "TGKB Kundenoutput ab 01.08.2008":
ExecARS(string.Format("SET_FIELD_DATA /F Dokumenten-Id /1 {0}", ARS_DocID),0);
ExecARS(string.Format("SET_FIELD_DATA /F Erstellung od. Valuta Datum /1 {0} /2 {1} ", FormatDate(ARS_Datum), FormatDate(ARS_Datum)),0);
break;
case "TGKB ZV-Scanning Belege (erweiterte Suche)":
ExecARS(string.Format("SET_FIELD_DATA /F Dokumenttyp /1 {0}", ARS_Doctype),0);
ExecARS(string.Format("SET_FIELD_DATA /F Auftrag-Nr. /1 {0}", ARS_AuftragNr),0);
ExecARS(string.Format("SET_FIELD_DATA /F Paginator /1 {0}", ARS_DocID),0);
ExecARS(string.Format("SET_FIELD_DATA /F Valuta od. Archiv Datum /1 {0} /2 {1}", "",""),0);
break;
default:
ExecARS(string.Format("SET_FIELD_DATA /F Dokument-Id /1 {0}", ARS_DocID),0);
break;
}
break;
case "Logoff":
//ExecARS("Logoff");
//Client.Execute("LOGOFF",3000);
//Client.ExecuteCommand("LOGOFF");
break;
default:
break;
}
}
static void ExecARS(string Params, int DoTimeout=1)
{
Debug_Print(Params);
Client.ExecuteCommand(Params);
//int i;
//i=Client.TryExecute(Params, Convert.ToInt32(Properties.Settings.Default.DDETimeout));
//MessageBox.Show(Convert.ToString(i));
if (DoTimeout==1)
{
System.Threading.Thread.Sleep(Convert.ToInt32(Properties.Settings.Default.DDESleep));
}
}
static string FormatDate(string datum)
{
string dd;
string mm;
string yyyy;
yyyy = datum.Substring(datum.Length - 2);
mm = datum.Substring(3, 2);
dd = datum.Substring(0, 2);
if (dd.Length<2) { dd = "0" + dd; }
if (mm.Length < 2) { mm = "0" + mm; }
return dd + "." + mm + "." + yyyy;
}
static bool Parse_Commandline(string[] args)
{
for (int i = 0; i < args.Length; i++)
{
try
{
Debug_Print(args[i].ToString());
switch (args[i].ToString())
{
case "/c":
int ii;
ii = i + 1;
string s;
s = "";
while (args[ii].Substring(0, 1) != @"/")
{
s = s + " " + args[ii];
ii = ii + 1;
}
ARS_Application = s.Trim();
//ARS_Foler = args[i + 1];
//ARS_Application = args[i + 1];
break;
case "/e":
ii = i + 1;
s = "";
while (args[ii].Substring(0, 1) != @"/")
{
s = s + " " + args[ii];
ii = ii + 1;
}
ARS_Application = s.Trim();
//ARS_Application = args[i + 1];
//ARS_Language = Properties.Settings.Default.ARS_Language;
break;
case "/S":
ARS_System = args[i + 1];
break;
case "/U":
ARS_User = args[i + 1];
break;
case "/P":
ARS_Password = args[i + 1];
break;
case "/f":
ii = i+1;
s = "";
while (args[ii].Substring(0,1) != @"/")
{
s = s + " " + args[ii];
ii = ii + 1;
}
ARS_Foler = s.Trim();
//ARS_Foler = args[i + 1];
break;
case "/d":
ARS_DocID = args[i + 1];
break;
case "/t":
ARS_Datum = args[i + 1];
break;
case "/b":
ARS_Type = args[i + 1];
break;
case "/g":
ARS_Doctype = args[i + 1];
break;
case "/a":
ARS_AuftragNr = args[i + 1];
break;
default:
break;
}
}
catch { }
}
return true;
}
}
}
static class Extensions
{
public static void ExecuteCommand(this DdeClient client, string command)
{
string answer = client.Request(command, 5000);
if (!answer.StartsWith("0"))
{
//throw new Exception("Error:");
}
}
}