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 OnDoc.Klassen; using Model; using Syncfusion.Windows.Forms.Tools; using Syncfusion.WinForms.Controls; using Syncfusion.WinForms.DataGrid; using Syncfusion.WinForms.DataGrid.Interactivity; using Database; using OnDoc.UIControls; using BroadcastListener.Classes; using BroadcastListener.Interfaces; using static BroadcastListener.Classes.Factory; using OnDoc.Helper; using DOCGEN; using System.Globalization; using System.Threading; using Syncfusion.Windows.Forms; using Syncfusion.Grouping; namespace OnDoc.DocMgmt { public partial class Dokumenterstellung : SfForm, IMessageListener1 { public int partnernr { get; set; } = 0; public int profilnr { get; set; } = 0; public int dokumenttypnr { get; set; } = 0; public string interaktion { get; set; } = ""; public string showdoc { get; set; } = ""; public int DocFunction = 0; public bool interop { get; set; } = false; public bool runmacros { get; set; } = false; public string dokumentid { get; set; } = ""; public string filename { get; set; } = ""; public bool editdoc { get; set; } = false; public Dokumenterstellung() { InitializeComponent(); Broadcaster().AddListener(this); Closing += Form_Closing; } public Dokumenterstellung(int Partnernr, int Dokumenttpynr, int Profilnr) { InitializeComponent(); partnernr = Partnernr; dokumenttypnr = Dokumenttpynr; profilnr = Profilnr; Broadcaster().AddListener(this); Closing += Form_Closing; } public Dokumenterstellung(int Partnernr, int Dokumenttypnr, int Profilnr, string Interaktion, string Showdoc) { InitializeComponent(); partnernr = Partnernr; dokumenttypnr = Dokumenttypnr; profilnr = Profilnr; interaktion= Interaktion; showdoc = Showdoc; Broadcaster().AddListener(this); Closing += Form_Closing; } public Dokumenterstellung(string dokumentid) { InitializeComponent(); Broadcaster().AddListener(this); Closing += Form_Closing; this.dokumentid=dokumentid; this.editdoc = true; btnDokumenterstellen.Text = "Dokument bearbeiten"; } private void Form_Closing(object sender, CancelEventArgs e) { Broadcaster().RemoveListener(this); } public void OnListen(string message, SenderInfo sender) { if (message == "BtnErstellung") { if (ucAllgemeineDokumentParam1.uniqid == sender.Details) { if (sender.Function == "Disable") { btnDokumenterstellen.Enabled = false; } else { btnDokumenterstellen.Enabled = true; } } } if (message == "AdminDokErstellung") { Dokument_Erstellen("",false); } } private void Dokumenterstellung_Load(object sender, EventArgs e) { this.Style.TitleBar.BackColor = Theaming.Titelbar(); this.Style.TitleBar.ForeColor = Theaming.TitelFontColor(); this.Style.ShadowOpacity = Theaming.ShadowOpacity; this.Style.InactiveShadowOpacity = Theaming.InactivShadowOpacity; if (dokumentid != "") { ucAllgemeineDokumentParam1.dokumentid = dokumentid; ucAllgemeineDokumentParam1.load_doc(); } else { ucAllgemeineDokumentParam1.dokumenttypnr = dokumenttypnr; ucAllgemeineDokumentParam1.partnernr = partnernr; ucAllgemeineDokumentParam1.profilnr = profilnr; ucAllgemeineDokumentParam1.Refresh_Details(); } //if (ucAllgemeineDokumentParam1.check_bp_person() == false) //{ // btnDokumenterstellen.Enabled = false; //} Security security = new Security(); security.set_security_general(this); security = null; } private void sfButton2_Click(object sender, EventArgs e) { Cursor = Cursors.WaitCursor; Dokument_Erstellen(this.dokumentid,this.editdoc); Cursor = Cursors.Default; } public void Dokument_Erstellen(string dokumentid, bool editdoc) { this.filename = ""; if (ucAllgemeineDokumentParam1.check_fields()==false) { MessageBox.Show(ucAllgemeineDokumentParam1.check_error,"Feldwerte",MessageBoxButtons.OK,MessageBoxIcon.Error); return; }; ucAllgemeineDokumentParam1.Update_DocGenData(); clsDocData dokdata = new clsDocData(); ucAllgemeineDokumentParam1.update_dokdata(ref dokdata); DOCGEN.DocGen docgen = new DOCGEN.DocGen(AppParams.connectionstring); dokumentid = docgen.GenDocID(dokdata, editdoc, dokumentid); dokdata.Dokumentid = dokumentid; ucAllgemeineDokumentParam1.genertated_dokumentid = dokumentid; this.dokumentid=dokdata.Dokumentid; if (dokdata.barcode_type == "1") { DB dB = new DB(AppParams.connectionstring); dB.clear_parameter(); dB.add_parameter("@dokumentid", dokumentid); dB.add_parameter("@DokumentidBR", ""); dB.add_parameter("@BARCODEFONTNAME", ""); dB.add_parameter("@BARCODEFONTSIZE",""); dB.add_parameter("@BarcodeKantenlaenge", ""); dB.Get_Tabledata("sp_get_OnDoc_barcodetype_and_value", true, false); dokdata.barcode_content = dB.dsdaten.Tables[0].Rows[0][1].ToString(); dokdata.barcode_formatn = dB.dsdaten.Tables[0].Rows[0][3].ToString(); dokdata.barcode_text = dB.dsdaten.Tables[0].Rows[0][4].ToString(); dokdata.barcode_kantenlaenge = dB.dsdaten.Tables[0].Rows[0][5].ToString(); dokdata.Zusatz_Font = dB.dsdaten.Tables[0].Rows[0][6].ToString(); dokdata.Zusatz_FontSize = Convert.ToInt32(dB.dsdaten.Tables[0].Rows[0][7]); dokdata.barcode_width = Convert.ToInt32(dB.dsdaten.Tables[0].Rows[0][8]); dokdata.barcode_height = Convert.ToInt32(dB.dsdaten.Tables[0].Rows[0][9]); //dokdata.barcode_type= dB.dsdaten.Tables[0].Rows[0][3].ToString(); string sql = ""; sql = "select bcpt, bcpl, bcw, bch, bchorizontal from OnDocBarcodeMpping "; sql = sql + "where orig_bcpt = " + dokdata.barcode_top.ToString() + " and orig_bcpl=" + dokdata.barcode_left.ToString() + " "; sql = sql + "and orig_bcw=" + dokdata.barcode_width.ToString() + " and orig_bch=" + dokdata.barcode_height.ToString(); dB.Get_Tabledata(sql, false, true); if (dB.dsdaten.Tables[0].Rows.Count > 0) { Logging.Logging.Debug("Barcode-Übersteuerung" + dokdata.DokumenttypNr.ToString(), "Dokumenterstellung", ""); dokdata.barcode_left = Convert.ToInt32(dB.dsdaten.Tables[0].Rows[0]["bcpl"]); dokdata.barcode_top = Convert.ToInt32(dB.dsdaten.Tables[0].Rows[0]["bcpt"]); dokdata.barcode_width = Convert.ToInt32(dB.dsdaten.Tables[0].Rows[0]["bcw"]); dokdata.barcode_height = Convert.ToInt32(dB.dsdaten.Tables[0].Rows[0]["bch"]); } dB = null; } Logging.DocLog.Info("Dokumenterstellung", "frmDokumenterstellung", dokumentid, ucAllgemeineDokumentParam1.partnernr.ToString(), "Dokumenterstellung"); if (dokumentid != "") { DOCGEN.Generator.DocGenerator_from_EDOKA Generator = new DOCGEN.Generator.DocGenerator_from_EDOKA(AppParams.connectionstring, AppParams.tempdir, AppParams.RESTURI, AppParams.apikey,AppParams.Office_Fill_DocIO); clsdok dok = new clsdok("", "", "", ""); Logging.Logging.Debug("Generate_Doc_EDOKA", "Dokumenterstellung", dokumentid); dok = Generator.Generate_Doc_EDOKA(dokumentid, ref dokdata, ucAllgemeineDokumentParam1.ErstellungInOffice,AppParams.OfficeSpleep1, AppParams.vbvorlagenmanagement=="Yes",this.editdoc); Logging.Logging.Debug("Generate_Doc_EDOKA - Ende", "Dokumenterstellung", dokumentid); if (dok.extension == "QDF") { this.Close(); DocFunction = 99; return; } interop = ucAllgemeineDokumentParam1.interop; //Erstellung Office if (ucAllgemeineDokumentParam1.docgendata.erstellungsart == Erstellungsart.ErstellungInOffice) { Logging.Logging.Debug("Dokumentbearbeitung Erstellungsart.ErstellungInOffice", "OnDocClient", ""); string filename = AppParams.tempdir + dokumentid + "_Erstellt_." + dok.extension; filename = AppParams.tempdir + dok.dokumentname + "_erstellt"; System.IO.File.WriteAllBytes(filename, Convert.FromBase64String(dok.dokument)); DB db = new DB(AppParams.connectionstring); db.Save_To_DB(dokdata.Dokumentid, filename); db = null; Logging.Logging.Debug("Dokumentbearbeitung Saved", "OnDocClient", ""); System.IO.File.Delete(filename); Logging.Logging.Debug("Dokumentbearbeitung Deleted", "OnDocClient", ""); filename = AppParams.tempdir + dokumentid +"." + dok.extension; filename = AppParams.tempdir+dok.dokumentname; this.filename = filename; DocFunction = 6; this.Close(); return; } //Bearbeiten if (ucAllgemeineDokumentParam1.docgendata.erstellungsart == Erstellungsart.DokumentBearbeiten) { Logging.Logging.Debug("Dokumentbearbeitung Erstellungsart.DokumentBearbeiten", "OnDocClient", ""); //string filename = AppParams.tempdir + dokumentid + "." + dok.extension; string filename = AppParams.tempdir + dokumentid + "_Erstellt_." + dok.extension; System.IO.File.WriteAllBytes(filename, Convert.FromBase64String(dok.dokument)); DB db = new DB(AppParams.connectionstring); db.Save_To_DB(dokdata.Dokumentid, filename); db.Get_Tabledata("Select count(*) from idvmakro_office_vorlage where office_vorlagenr=" + ucAllgemeineDokumentParam1.vorlagenr.ToString(), false, true); if (Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][0]) > 0) { interop = true; runmacros = true; } db = null; Logging.Logging.Debug("Dokumentbearbeitung DocFunction1", "OnDocClient", ""); DocFunction = 1; System.IO.File.Delete(filename); filename = AppParams.tempdir + dokumentid + "." + dok.extension; this.filename = filename; this.Close(); return; } if (ucAllgemeineDokumentParam1.docgendata.erstellungsart == Erstellungsart.DokumentPreview) { Logging.Logging.Debug("Dokumentbearbeitung Erstellungsart.DokumentBearbeiten", "DokumentPreview", ""); string filename = AppParams.tempdir + dokumentid + "." + dok.extension; System.IO.File.WriteAllBytes(filename, Convert.FromBase64String(dok.dokument)); DB db = new DB(AppParams.connectionstring); db.Save_To_DB(dokdata.Dokumentid, filename); db = null; } if (ucAllgemeineDokumentParam1.docgendata.erstellungsart == Erstellungsart.DokumentAlsPDF) { Logging.Logging.Debug("Dokumentbearbeitung Erstellungsart.DokumentAlsPDF", "DokumentPreview", ""); //Generator.DocToPDF(dokumentid, ref dok); dok.extension = "pdf"; string filename = AppParams.tempdir + dokumentid + "." + dok.extension; System.IO.File.WriteAllBytes(filename, Convert.FromBase64String(dok.dokument)); DB db = new DB(AppParams.connectionstring); db.Save_To_DB(dokdata.Dokumentid, filename); } if (ucAllgemeineDokumentParam1.docgendata.erstellungsart == Erstellungsart.DokumentSpäterBearbeiten) { Logging.Logging.Debug("Dokumentbearbietung Erstellungsart.DokumentSpäterBearbeiten", "DokumentPreview", ""); string filename = AppParams.tempdir + dokumentid + "." + dok.extension; System.IO.File.WriteAllBytes(filename, Convert.FromBase64String(dok.dokument)); DB db = new DB(AppParams.connectionstring); db.Save_To_DB(dokdata.Dokumentid, filename); db = null; } if (ucAllgemeineDokumentParam1.docgendata.versandstrasse_moeglich == true) { ribbonButtonVersandstrasse.Enabled = true; } else { ribbonButtonVersandstrasse.Enabled = false; } PnlPreview.Visible = true; PnlPreview.Dock = DockStyle.Fill; Database.DB db1 = new Database.DB(AppParams.connectionstring); db1.Get_Tabledata("Select coldstatus from dokument where dokumentid='"+dokumentid+"'",false,true); if (Convert.ToInt32(db1.dsdaten.Tables[0].Rows[0][0]) == 1) { ribbonButtonArchiv.Enabled = false; ribbonButtonVersandstrasse.Enabled = false; } else { ribbonButtonArchiv.Enabled = true; ribbonButtonVersandstrasse.Enabled = true; } if (ucAllgemeineDokumentParam1.docgendata.versandstrasse_moeglich == false) { ribbonButtonVersandstrasse.Enabled = false; } docPreview1.Show_Doc(dokumentid); DB dB = new DB(AppParams.connectionstring); dB.Get_Tabledata("Select * from dokument where dokumentid='"+dokumentid+"'",false,true); if (Convert.ToBoolean(dB.dsdaten.Tables[0].Rows[0]["ToApprove"])==true && Convert.ToBoolean(dB.dsdaten.Tables[0].Rows[0]["approved"]) == false) { ribbonButtonArchiv.Enabled = false; } if (Convert.ToBoolean(dB.dsdaten.Tables[0].Rows[0]["bearbeitung_zwingend"]) == true) { ribbonButtonArchiv.Enabled = false; } dB = null; docPreview1.Hide_Editbuttons(); } } private void sfButton3_Click(object sender, EventArgs e) { DialogResult = DialogResult.Abort; this.Close(); } private void button1_Click(object sender, EventArgs e) { DocFunction = 1; this.Close(); } private void button2_Click(object sender, EventArgs e) { DocFunction = 2; this.Close(); } private void button3_Click(object sender, EventArgs e) { DocFunction = 3; PnlPreview.Visible = false; } private void button4_Click(object sender, EventArgs e) { DocFunction = 4; this.Close(); } private void button5_Click(object sender, EventArgs e) { DocFunction = 5; this.Close(); } private void GrpFnkt_Enter(object sender, EventArgs e) { } private void btnOfficePrint_Click(object sender, EventArgs e) { clsdok dok = new clsdok("", "", "", ""); DocGet gd = new DocGet(AppParams.connectionstring); { dok = gd.GetDoc(dokumentid); } if (dok.doktype == "D") { OfficePrinter.OnDocOffice op = new OfficePrinter.OnDocOffice(); Helper.FileHelper fh = new Helper.FileHelper(); string Filename = AppParams.tempdir + dokumentid + "." + dok.extension; fh.SaveBase64ToFile(dok.dokument, Filename); op.PrintInWord(Filename, AppParams.wordprintmacro, AppParams.OfficeSpleep1); op = null; } if (dok.doktype == "P") { docPreview1.printpdf(); } if (dok.doktype == "X") { Helper.FileHelper fh = new Helper.FileHelper(); string Filename = AppParams.tempdir + dokumentid + "." + dok.extension; fh.SaveBase64ToFile(dok.dokument, Filename); System.Diagnostics.Process.Start("winword.exe", "/w " + Filename); } } private void label8_Click(object sender, EventArgs e) { } } }