Files
EDOKA_Tools/OnDemandDDE/ARSDDE/Program.cs
2020-10-21 10:43:18 +02:00

313 lines
14 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 DdeClient Client = new DdeClient("ARS", "ARS");
static void Main(string[] args)
{
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));
}
Debug_Print("Start");
Call_OnDemand("Start");
Client = new DdeClient(Properties.Settings.Default.OnDemandClinetString, Properties.Settings.Default.OnDemandClinetString);
Client.Connect();
Debug_Print("Logon");
Call_OnDemand("Logon");
Debug_Print("Open_Folder");
Call_OnDemand("Open_Folder");
Debug_Print("Set_FieldData");
Call_OnDemand("Set_FieldData");
Debug_Print("Search_Folder");
Call_OnDemand("Search_Folder");
Debug_Print("Show_Doc");
Call_OnDemand("Show_Doc");
Debug_Print("Logoff");
Call_OnDemand("Logoff");
if (Debug == "true") { Console.ReadLine(); }
}
static void Debug_Print(string s)
{
if (Debug == "true")
{
using (StreamWriter w = File.AppendText(@"h:\arsddedebug.txt"))
{
w.WriteLine(s);
}
};
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";
Debug_Print(ARS_Application + " /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.WindowStyle = ProcessWindowStyle.Maximized;
psi.UseShellExecute = true;
Process.Start(psi);
// Process.Start(""+ARS_Application+"" + " /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 /W N");
System.Threading.Thread.Sleep(Convert.ToInt32(Properties.Settings.Default.WaitAfterStart));
}
break;
case "Logon":
Debug_Print(String.Format("LOGON /S {0} /U {1} /P {2}", ARS_System,ARS_User, ARS_Password));
//Client.Execute(string.Format("LOGON /S Test_System_NOVA /U {0} /P {1}", ARS_User, ARS_Password), 3000);
Client.ExecuteCommand(string.Format("LOGON /S {0} /U {1} /P {2}", ARS_System, ARS_User, ARS_Password));
break;
case "Open_Folder":
// 20201019 - Erweiterung /S /C /R /D -> Buttons ausblenden
Debug_Print(string.Format("OPEN_FOLDER /F {0} /S /C /R /D", ARS_Foler));
//Client.Execute(string.Format("OPEN_FOLDER / F {0})", ARS_Foler), 3000);
Client.ExecuteCommand(string.Format("OPEN_FOLDER /F {0} /S /C /R /D", ARS_Foler));
break;
case "Search_Folder":
Debug_Print("SEARCH_FOLDER");
//Client.Execute("SEARCH_FOLDER", 3000);
Client.ExecuteCommand("SEARCH_FOLDER");
break;
case "Show_Doc":
Client.ExecuteCommand("OPEN_DOC /N 0");
//Client.ExecuteCommand("SHOW_WINDOW /W 0,0,75,100");
break;
case "Set_FieldData":
switch (ARS_Foler)
{
case "TGKB Kundenoutput AGI-OMS für EDOKA User":
Debug_Print("TGKB Kundenoutput AGI-OMS für EDOKA User");
Debug_Print(string.Format("SET_FIELD_DATA /F Dokument-Id /1 {0}", ARS_DocID));
//Client.Execute(string.Format("SET_FIELD_DATA /F Dokument-Id /1 {0})", ARS_DocID), 3000);
Client.ExecuteCommand(string.Format("SET_FIELD_DATA /F Dokument-Id /1 {0}", ARS_DocID));
Debug_Print(string.Format("SET_FIELD_DATA /F Erstellung od. Valuta Datum /1 {0} /2 {1} ", FormatDate(ARS_Datum), FormatDate(ARS_Datum)));
//Client.Execute(string.Format("SET_FIELD_DATA / F Erstellung od. Valuta Datum /1 {0} /2 {1} ", FormatDate(ARS_Datum), FormatDate(ARS_Datum)), 3000);
Client.ExecuteCommand(string.Format("SET_FIELD_DATA /F Erstellung od. Valuta Datum /1 {0} /2 {1} ", FormatDate(ARS_Datum), FormatDate(ARS_Datum)));
break;
case "TGKB Kundenoutput ab 01.08.2008":
Debug_Print("TGKB Kundenoutput ab 01.08.2008");
Debug_Print(string.Format("SET_FIELD_DATA /F Dokumenten-Id /1 {0}", ARS_DocID));
//Client.Execute(string.Format("SET_FIELD_DATA /F Dokument-Id /1 {0})", ARS_DocID), 3000);
Client.ExecuteCommand(string.Format("SET_FIELD_DATA /F Dokumenten-Id /1 {0}", ARS_DocID));
Debug_Print(string.Format("SET_FIELD_DATA /F Erstellung od. Valuta Datum /1 {0} /2 {1} ", FormatDate(ARS_Datum), FormatDate(ARS_Datum)));
Client.ExecuteCommand(string.Format("SET_FIELD_DATA /F Erstellung od. Valuta Datum /1 {0} /2 {1} ", FormatDate(ARS_Datum), FormatDate(ARS_Datum)));
break;
case "TGKB ZV-Scanning Belege (erweiterte Suche)":
Debug_Print(string.Format("SET_FIELD_DATA /F Dokumenttyp /1 {0}", ARS_Doctype));
//Client.Execute(string.Format("SET_FIELD_DATA /F Dokumenttyp /1 {0})", ARS_Doctype), 3000);
Client.ExecuteCommand(string.Format("SET_FIELD_DATA /F Dokumenttyp /1 {0}", ARS_Doctype));
Debug_Print(string.Format("SET_FIELD_DATA /F Auftrag-Nr. /1 {0}", ARS_AuftragNr));
//Client.Execute(string.Format("SET_FIELD_DATA /F Auftrag-Nr. /1 {0})", ARS_AuftragNr), 3000);
Client.ExecuteCommand(string.Format("SET_FIELD_DATA /F Auftrag-Nr. /1 {0}", ARS_AuftragNr));
Debug_Print(string.Format("SET_FIELD_DATA /F Paginator /1 {0}", ARS_DocID));
//Client.Execute(string.Format("SET_FIELD_DATA /F Paginator /1 {0})", ARS_DocID), 3000);
Client.ExecuteCommand(string.Format("SET_FIELD_DATA /F Paginator /1 {0}", ARS_DocID));
Client.ExecuteCommand(string.Format("SET_FIELD_DATA /F Valuta od. Archiv Datum /1 {0} /2 {1}", "",""));
break;
default:
Debug_Print(string.Format("SET_FIELD_DATA /F Dokument-Id /1 {0}", ARS_DocID));
//Client.Execute(string.Format("SET_FIELD_DATA /F Dokument-Id /1 {0})", ARS_DocID), 3000);
Client.ExecuteCommand(string.Format("SET_FIELD_DATA /F Dokument-Id /1 {0}", ARS_DocID));
break;
}
break;
case "Logoff":
//Client.Execute("LOGOFF",3000);
//Client.ExecuteCommand("LOGOFF");
break;
default:
break;
}
}
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:");
}
}
}