749 lines
27 KiB
C#
749 lines
27 KiB
C#
using ExcelNet;
|
|
using FastExcel;
|
|
using Syncfusion.Windows.Forms.Edit;
|
|
using Syncfusion.XlsIO;
|
|
using Syncfusion.XlsIO.Implementation.Security;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Drawing.Text;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Tool_API_Dokumentgenerator
|
|
{
|
|
|
|
public partial class Form1 : Form
|
|
{
|
|
|
|
|
|
string partnernr = "";
|
|
string unterschriftlinks = "";
|
|
string unterschriftrechts = "";
|
|
public class ControlState
|
|
{
|
|
public string Name { get; set; }
|
|
public string Type { get; set; }
|
|
public string Value { get; set; }
|
|
}
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
string datapath = Properties.Settings.Default.Datapath;
|
|
string inputdata = "";
|
|
string tabelle1 = "";
|
|
string tabelle2 = "";
|
|
string tabelle3 = "";
|
|
string tabelle4 = "";
|
|
DataTable ExcelMapping = new DataTable();
|
|
private void start()
|
|
{
|
|
ExcelMapping.Columns.Clear();
|
|
ExcelMapping.Columns.Add("Tag");
|
|
ExcelMapping.Columns.Add("Excelspalte");
|
|
ExcelMapping.Columns.Add("FixText");
|
|
ExcelMapping.Columns.Add("Formatierung");
|
|
ExcelMapping.TableName = "ExcelMappoing";
|
|
}
|
|
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
Generate(false);
|
|
}
|
|
private void button5_Click(object sender, EventArgs e)
|
|
{
|
|
System.IO.File.WriteAllText(datapath + txttextinput.Text, editControl1.Text);
|
|
Generate(true);
|
|
}
|
|
private void Generate(bool demo)
|
|
{
|
|
int processed = 0;
|
|
System.Data.DataTable importdata = new System.Data.DataTable();
|
|
|
|
ExcelNet.ExcelReader reader = new ExcelNet.ExcelReader();
|
|
string selected_sheetname = "";
|
|
var sheets = new List<string>();
|
|
try
|
|
{
|
|
sheets = reader.Get_ExcelSheets(datapath + txtexcelinput.Text);
|
|
}
|
|
catch
|
|
{
|
|
MessageBox.Show("Auf die gewählte Excel-Datei kann aktuell nicht zugegriffen werden. Evtl. ist diese noch geöffnet.", "Excel-Import", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
|
|
selected_sheetname = sheets[0];
|
|
|
|
|
|
Import_sf_Excel(datapath + txtexcelinput.Text, selected_sheetname, ref importdata);
|
|
for (int i = 0; i < importdata.Rows.Count; i++)
|
|
{
|
|
DataRow dr = importdata.Rows[i];
|
|
if (dr[0].ToString() == "")
|
|
dr.Delete();
|
|
}
|
|
importdata.AcceptChanges();
|
|
DataView dv = new DataView(importdata);
|
|
dv.Sort = txtspalten.Text.Replace(";", ",");
|
|
importdata.DefaultView.Sort = txtspalten.Text.Replace(";", ",");
|
|
progressBarAdv1.Visible = true;
|
|
string oldkey = "";
|
|
int counter = 0;
|
|
progressBarAdv1.Minimum = 0;
|
|
progressBarAdv1.Maximum = dv.Count;
|
|
progressBarAdv1.Value = 0;
|
|
System.Windows.Forms.Application.DoEvents();
|
|
DataRow rowsave = null;
|
|
foreach (DataRowView rowView in dv)
|
|
{
|
|
progressBarAdv1.Value++;
|
|
DataRow row = rowView.Row;
|
|
|
|
partnernr = "";
|
|
unterschriftlinks = "";
|
|
unterschriftrechts = "";
|
|
//if (txtPartnerNr.Text != "") { try { partnernr = row[txtPartnerNr.Text].ToString().Replace(".", ""); } catch { partnernr = ""; } }
|
|
//if (txtUnterschriftRechts.Text != "") { try { unterschriftrechts = row[txtUnterschriftRechts.Text].ToString().Replace(".", ""); } catch { unterschriftrechts = ""; } }
|
|
//if (txtUnterschriftRechts.Text != "") { try { unterschriftrechts = row[txtUnterschriftRechts.Text].ToString().Replace(".", ""); } catch { unterschriftrechts = ""; } }
|
|
|
|
if (oldkey != row[txtdokumenttrenner.Text].ToString())
|
|
{
|
|
|
|
if (counter > 0)
|
|
{
|
|
|
|
processed = processed + 1;
|
|
//WriteTable(ref rowsave);
|
|
Update_Excelspalten(ref rowsave);
|
|
Abschluss_Dokument(oldkey,true);
|
|
if (demo)
|
|
{
|
|
this.editControl2.Text = inputdata;
|
|
panel1.Visible = true;
|
|
panel1.Dock = DockStyle.Bottom;
|
|
editControl1.Visible = false;
|
|
groupBox2.Visible = false;
|
|
//groupBox3.Visible = true;
|
|
//groupBox3.Dock = DockStyle.Fill;
|
|
editControl2.MoveToBeginning();
|
|
progressBarAdv1.Visible = false;
|
|
editControl2.Visible = true;
|
|
toolStrip1.Visible = true;
|
|
return;
|
|
}
|
|
}
|
|
rowsave = row;
|
|
oldkey = row[txtdokumenttrenner.Text].ToString();
|
|
inputdata = System.IO.File.ReadAllText(datapath + txttextinput.Text);
|
|
tabelle1 = ""; tabelle2 = ""; tabelle3 = ""; tabelle4 = "";
|
|
}
|
|
|
|
editControl1.Text = inputdata;
|
|
counter++;
|
|
WriteTable(ref row);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
Update_Excelspalten(ref rowsave);
|
|
Abschluss_Dokument(oldkey);
|
|
progressBarAdv1.Visible = false;
|
|
processed = processed + 1;
|
|
MessageBox.Show(processed.ToString() + " Dokumente wurden erfolgreich erstellt.", "Dokumentgenerator", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
|
|
|
|
private void Abschluss_Dokument(string oldkey, bool demo = false)
|
|
{
|
|
string headers = "";
|
|
if (tabelle1 != "")
|
|
{
|
|
headers = "";
|
|
if (txtcolheader1.ToString() != "")
|
|
{
|
|
headers = "<row><col>" + txtcolheader1.Text.Replace(";", "</col>") + "</col></row>";
|
|
}
|
|
tabelle1 = "<p><table" + txtformat1.Text + ">" + headers + tabelle1 + "</table><p>";
|
|
inputdata = inputdata.Replace(txttag1.Text, tabelle1);
|
|
if (txtueberschrift1.Text != "") { inputdata = inputdata.Replace(txttagueberschrift1.Text, txtueberschrift1.Text); }
|
|
}
|
|
if (tabelle2 != "")
|
|
{
|
|
headers = "";
|
|
if (txtcolheader2.ToString() != "")
|
|
{
|
|
headers = "<row><col>" + txtcolheader2.Text.Replace(";", "</col>") + "</col></row>";
|
|
}
|
|
tabelle2 = "<p><table" + txtformat2.Text + ">" + headers + tabelle2 + "</table><p>";
|
|
inputdata = inputdata.Replace(txttag2.Text, tabelle2);
|
|
if (txtueberschrift2.Text != "") { inputdata = inputdata.Replace(txttagueberschrift2.Text, txtueberschrift2.Text); }
|
|
}
|
|
if (tabelle3 != "")
|
|
{
|
|
headers = "";
|
|
if (txtcolheader3.ToString() != "")
|
|
{
|
|
headers = "<row><col>" + txtcolheader3.Text.Replace(";", "</col>") + "</col></row>";
|
|
}
|
|
tabelle3 = "<p><table" + txtformat3.Text + ">" + headers + tabelle3 + "</table><p>";
|
|
inputdata = inputdata.Replace(txttag3.Text, tabelle3);
|
|
if (txtueberschrift3.Text != "") { inputdata = inputdata.Replace(txttagueberschrift3.Text, txtueberschrift3.Text); }
|
|
}
|
|
if (tabelle4 != "")
|
|
{
|
|
headers = "";
|
|
if (txtcolheader4.ToString() != "")
|
|
{
|
|
headers = "<row><col>" + txtcolheader4.Text.Replace(";", "</col>") + "</col></row>";
|
|
}
|
|
tabelle4 = "<p><table" + txtformat4.Text + ">" + headers + tabelle4 + "</table><p>";
|
|
inputdata = inputdata.Replace(txttag4.Text, tabelle4);
|
|
if (txtueberschrift4.Text != "") { inputdata = inputdata.Replace(txttagueberschrift4.Text, txtueberschrift4.Text); }
|
|
}
|
|
if (tabelle1 == "" && txttag1.Text != "")
|
|
{
|
|
inputdata = inputdata.Replace(txttag1.Text, "");
|
|
inputdata = inputdata.Replace(txttagueberschrift1.Text, "");
|
|
}
|
|
if (tabelle2 == "" && txttag2.Text != "")
|
|
{
|
|
inputdata = inputdata.Replace(txttag2.Text, "");
|
|
inputdata = inputdata.Replace(txttagueberschrift2.Text, "");
|
|
}
|
|
if (tabelle3 == "" && txttag3.Text != "")
|
|
{
|
|
inputdata = inputdata.Replace(txttag3.Text, "");
|
|
inputdata = inputdata.Replace(txttagueberschrift3.Text, "");
|
|
}
|
|
if (tabelle4 == "" && txttag4.Text != "")
|
|
{
|
|
inputdata = inputdata.Replace(txttag4.Text, "");
|
|
inputdata = inputdata.Replace(txttagueberschrift4.Text, "");
|
|
}
|
|
//if (partnernr != "")
|
|
//{
|
|
// inputdata = inputdata.Replace("$$PARTNERNR$$", partnernr.Replace(".", ""));
|
|
//}
|
|
//if (unterschriftlinks != "")
|
|
//{
|
|
// inputdata = inputdata.Replace("$$UNTERSCHRIFTLINKS$$", unterschriftlinks.ToString());
|
|
//}
|
|
//if (unterschriftrechts != "")
|
|
//{
|
|
// inputdata = inputdata.Replace("$$UNTERSCHRIFTRECHTS$$", unterschriftrechts.ToString());
|
|
//}
|
|
if (!demo)
|
|
{
|
|
System.IO.File.WriteAllText(datapath + @"\output\" + this.txtname.Text + "_Data_" + oldkey + ".json", inputdata);
|
|
}
|
|
else
|
|
{
|
|
System.IO.File.WriteAllText(datapath + @"\test-json.json", inputdata);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string formatvalue(string data, string format)
|
|
{
|
|
|
|
if (format.ToUpper().Contains("REPLACE"))
|
|
{
|
|
string[] parts=format.Split('|');
|
|
return data.Replace(parts[1], parts[2]);
|
|
}
|
|
|
|
if (format.ToUpper().Contains("UPPER"))
|
|
{
|
|
return data.ToUpper();
|
|
}
|
|
if (format.ToUpper().Contains("LOWER"))
|
|
{
|
|
return data.ToLower();
|
|
|
|
}
|
|
return data;
|
|
}
|
|
private void Update_Excelspalten(ref DataRow row)
|
|
{
|
|
string value = "";
|
|
foreach (DataRow dr in ExcelMapping.Rows)
|
|
{
|
|
value = "";
|
|
if (dr["Tag"].ToString() != "") // && row[dr["Excelspalte"].ToString()] != "")
|
|
{
|
|
if (dr["Excelspalte"].ToString() != "")
|
|
{
|
|
try
|
|
{
|
|
|
|
if (row[dr["Excelspalte"].ToString()] != "") { inputdata = inputdata.Replace(dr["Tag"].ToString(), formatvalue(row[dr["Excelspalte"].ToString()].ToString(), dr["Formatierung"].ToString())); }
|
|
//if (row[dr["Excelspalte"].ToString()] != "") { inputdata = inputdata.Replace(dr["Tag"].ToString(), row[dr["Excelspalte"].ToString()].ToString()); }
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
|
|
if (dr["FixText"].ToString().Trim() != "")
|
|
{
|
|
switch (dr["FixText"].ToString())
|
|
{
|
|
case "Date()":
|
|
inputdata = inputdata.Replace(dr["Tag"].ToString(), DateTime.Now.ToString("dd.MM.yyyy"));
|
|
break;
|
|
default:
|
|
inputdata = inputdata.Replace(dr["Tag"].ToString(), dr["FixText"].ToString().ToString());
|
|
break;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private string FormatColumn(ref DataRow row, string col)
|
|
{
|
|
|
|
if (!col.Contains("{") && !col.Contains("|"))
|
|
{
|
|
return "<col>" + row[col].ToString() + "</col>";
|
|
}
|
|
|
|
|
|
string[] parts = col.Split('|');
|
|
string resultat = "";
|
|
foreach (string part in parts)
|
|
{
|
|
if (resultat != "") { resultat = resultat + " "; }
|
|
resultat = resultat + getpartvalue(ref row, part);
|
|
int i = 0;
|
|
|
|
}
|
|
return "<col>"+resultat+"</col>";
|
|
//
|
|
}
|
|
private string getpartvalue(ref DataRow row, string col)
|
|
{
|
|
string[] cols = col.Split('}');
|
|
if (cols.Length > 1) { col = cols[1]; } else { col = cols[0]; }
|
|
string value = row[col].ToString();
|
|
|
|
if (cols.Length > 1)
|
|
{
|
|
cols[0] = cols[0].Replace("}", "");
|
|
cols[0] = cols[0].Replace("{", "");
|
|
switch (cols[0].ToUpper())
|
|
{
|
|
case "CURRENCY":
|
|
decimal zahl = decimal.Parse(value);
|
|
string currency = zahl.ToString("N2");
|
|
value = currency;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
return value ;
|
|
|
|
}
|
|
|
|
private void WriteTable(ref DataRow row)
|
|
{
|
|
if (txttnr1.Text != "" && row["tabelle"].ToString() == txttnr1.Text)
|
|
{
|
|
|
|
tabelle1 += "<row>";
|
|
string[] cols = txttabellenspalten.Text.Split(';');
|
|
for (int i = 0; i < cols.Length; i++)
|
|
{
|
|
// tabelle1 = tabelle1 + "<col>" + row[cols[i]].ToString() + "</col>";
|
|
tabelle1 = tabelle1 + FormatColumn(ref row, cols[i]);
|
|
}
|
|
tabelle1 += "</row>";
|
|
}
|
|
if (txttnr2.Text != "" && row["tabelle"].ToString() == txttnr2.Text)
|
|
{
|
|
|
|
tabelle2 += "<row>";
|
|
string[] cols = txttabellenspalten.Text.Split(';');
|
|
for (int i = 0; i < cols.Length; i++)
|
|
{
|
|
//tabelle2 = tabelle2 + "<col>" + row[cols[i]].ToString() + "</col>";
|
|
tabelle2 = tabelle2 + FormatColumn(ref row, cols[i]);
|
|
}
|
|
tabelle2 += "</row>";
|
|
}
|
|
if (txttnr3.Text != "" && row["tabelle"].ToString() == txttnr3.Text)
|
|
{
|
|
|
|
|
|
tabelle3 += "<row>";
|
|
string[] cols = txttabellenspalten.Text.Split(';');
|
|
for (int i = 0; i < cols.Length; i++)
|
|
{
|
|
//tabelle3 = tabelle3 + "<col>" + row[cols[i]].ToString() + "</col>";
|
|
tabelle3 = tabelle3 + FormatColumn(ref row, cols[i]);
|
|
}
|
|
tabelle3 += "</row>";
|
|
}
|
|
if (txttnr4.Text != "" && row["tabelle"].ToString() == txttnr4.Text)
|
|
{
|
|
|
|
tabelle4 += "<row>";
|
|
string[] cols = txttabellenspalten.Text.Split(';');
|
|
for (int i = 0; i < cols.Length; i++)
|
|
{
|
|
//tabelle4 = tabelle4 + "<col>" + row[cols[i]].ToString() + "</col>";
|
|
tabelle4 = tabelle4 + FormatColumn(ref row, cols[i]);
|
|
}
|
|
tabelle4 += "</row>";
|
|
}
|
|
}
|
|
private void Import_sf_Excel(string filename, string sheetname, ref System.Data.DataTable importdata)
|
|
{
|
|
ExcelEngine excelEngine = new ExcelEngine();
|
|
IApplication application = excelEngine.Excel;
|
|
IWorkbook workbook = application.Workbooks.Open(filename);
|
|
IWorksheet sheet = workbook.Worksheets[sheetname];
|
|
importdata = sheet.ExportDataTable(sheet.UsedRange, ExcelExportDataTableOptions.ColumnNames);
|
|
sheet = null;
|
|
workbook.Close();
|
|
workbook = null;
|
|
excelEngine = null;
|
|
}
|
|
|
|
private void txtspalten_TextChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
start();
|
|
sfDataGrid1.DataSource = ExcelMapping;
|
|
sfDataGrid1.Columns[0].Width = sfDataGrid1.Width / 4 - 5;
|
|
sfDataGrid1.Columns[1].Width = sfDataGrid1.Width / 4 - 5;
|
|
sfDataGrid1.Columns[2].Width = sfDataGrid1.Width / 4 - 5;
|
|
sfDataGrid1.Columns[3].Width = sfDataGrid1.Width / 4 - 5;
|
|
groupBox2.Dock= DockStyle.Fill;
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
SaveControlsToJson(this, datapath + txtname.Text + ".json");
|
|
ExcelMapping.AcceptChanges();
|
|
ExcelMapping.WriteXml(datapath + txtname.Text + "_mapping.xml", XmlWriteMode.WriteSchema);
|
|
System.IO.File.WriteAllText(datapath + txttextinput.Text, editControl1.Text);
|
|
}
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
{
|
|
LoadControlsFromJson(this, datapath + txtname.Text + ".json");
|
|
ExcelMapping.Rows.Clear();
|
|
ExcelMapping.ReadXml(datapath + txtname.Text + "_mapping.xml");
|
|
inputdata = System.IO.File.ReadAllText(datapath + txttextinput.Text);
|
|
tabelle1 = ""; tabelle2 = ""; tabelle3 = ""; tabelle4 = "";
|
|
editControl1.Text = inputdata;
|
|
editControl1.MoveToBeginning();
|
|
}
|
|
|
|
public void SaveControlsToJson(Control parent, string filePath)
|
|
{
|
|
var list = new List<ControlState>();
|
|
|
|
foreach (Control ctrl in GetAllControls(parent))
|
|
{
|
|
var state = new ControlState
|
|
{
|
|
Name = ctrl.Name,
|
|
Type = ctrl.GetType().Name
|
|
};
|
|
|
|
switch (ctrl)
|
|
{
|
|
case TextBox tb:
|
|
state.Value = tb.Text;
|
|
break;
|
|
|
|
case CheckBox cb:
|
|
state.Value = cb.Checked.ToString();
|
|
break;
|
|
|
|
case ComboBox cmb:
|
|
state.Value = cmb.SelectedIndex.ToString();
|
|
break;
|
|
|
|
case DateTimePicker dtp:
|
|
state.Value = dtp.Value.ToString("o"); // ISO 8601
|
|
break;
|
|
}
|
|
|
|
list.Add(state);
|
|
}
|
|
|
|
var options = new System.Text.Json.JsonSerializerOptions
|
|
{
|
|
WriteIndented = true
|
|
};
|
|
|
|
string json = System.Text.Json.JsonSerializer.Serialize(list, options);
|
|
System.IO.File.WriteAllText(filePath, json);
|
|
}
|
|
|
|
public void LoadControlsFromJson(Control parent, string filePath)
|
|
{
|
|
if (!System.IO.File.Exists(filePath))
|
|
return;
|
|
|
|
string json = System.IO.File.ReadAllText(filePath);
|
|
var list = System.Text.Json.JsonSerializer.Deserialize<List<ControlState>>(json);
|
|
|
|
foreach (var state in list)
|
|
{
|
|
Control ctrl = GetAllControls(parent)
|
|
.FirstOrDefault(c => c.Name == state.Name);
|
|
|
|
if (ctrl == null)
|
|
continue;
|
|
|
|
switch (ctrl)
|
|
{
|
|
case TextBox tb:
|
|
tb.Text = state.Value;
|
|
break;
|
|
|
|
case CheckBox cb:
|
|
if (bool.TryParse(state.Value, out bool b))
|
|
cb.Checked = b;
|
|
break;
|
|
|
|
case ComboBox cmb:
|
|
if (int.TryParse(state.Value, out int i))
|
|
cmb.SelectedIndex = i;
|
|
break;
|
|
|
|
case DateTimePicker dtp:
|
|
if (DateTime.TryParse(state.Value, out DateTime d))
|
|
dtp.Value = d;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
private IEnumerable<Control> GetAllControls(Control parent)
|
|
{
|
|
foreach (Control ctrl in parent.Controls)
|
|
{
|
|
foreach (Control child in GetAllControls(ctrl))
|
|
yield return child;
|
|
|
|
yield return ctrl;
|
|
}
|
|
}
|
|
|
|
private void label1_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void txttagueberschrift1_TextChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void panel1_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void button4_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void label14_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void textBox1_TextChanged(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void toolStripButton1_Click(object sender, EventArgs e)
|
|
{
|
|
groupBox3.Visible = false;
|
|
groupBox2.Visible = true;
|
|
panel1.Visible = false;
|
|
editControl2.Visible = false;
|
|
toolStrip1.Visible = false;
|
|
editControl1.Visible = true;
|
|
}
|
|
|
|
private void button4_Click_1(object sender, EventArgs e)
|
|
{
|
|
openFileDialog1.InitialDirectory = datapath;
|
|
|
|
openFileDialog1.Filter = "JSON-Dateien (*.json)|*.json|Alle Dateien (*.*)|*.*";
|
|
openFileDialog1.ShowDialog();
|
|
if (openFileDialog1.FileName != "")
|
|
{
|
|
this.txtbasedir.Text = Path.GetDirectoryName(openFileDialog1.FileName);
|
|
this.txtname.Text=Path.GetFileNameWithoutExtension(openFileDialog1.FileName);
|
|
button3_Click(sender, e);
|
|
//if (this.txtbasedir.Text == "")
|
|
//{
|
|
|
|
//}
|
|
}
|
|
}
|
|
|
|
|
|
private void button6_Click(object sender, EventArgs e)
|
|
{
|
|
button1_Click(sender, e);
|
|
}
|
|
|
|
private void button7_Click(object sender, EventArgs e)
|
|
{
|
|
openFileDialog1.InitialDirectory = datapath;
|
|
|
|
openFileDialog1.Filter = "Excel-Dateien (*.xlsx)|*.xlsx|Alle Dateien (*.*)|*.*";
|
|
openFileDialog1.ShowDialog();
|
|
if (openFileDialog1.FileName != "")
|
|
{
|
|
this.txtexcelinput.Text = Path.GetFileName(openFileDialog1.FileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void button8_Click(object sender, EventArgs e)
|
|
{
|
|
openFileDialog1.InitialDirectory = datapath;
|
|
|
|
openFileDialog1.Filter = "Text-Dateien (*.txt)|*.txt|Alle Dateien (*.*)|*.*";
|
|
openFileDialog1.ShowDialog();
|
|
if (openFileDialog1.FileName != "")
|
|
{
|
|
this.txttextinput.Text = Path.GetFileName(openFileDialog1.FileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void button9_Click(object sender, EventArgs e)
|
|
{
|
|
using (var fbd = new FolderBrowserDialog())
|
|
{
|
|
DialogResult result = fbd.ShowDialog();
|
|
|
|
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
|
|
{
|
|
this.txtbasedir.Text = fbd.SelectedPath;
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
private void check_outputdir()
|
|
{
|
|
datapath = txtbasedir.Text;
|
|
if (!datapath.EndsWith(@"\"))
|
|
{
|
|
datapath = datapath + @"\";
|
|
}
|
|
|
|
if (!System.IO.Directory.Exists(datapath + @"\output"))
|
|
{
|
|
System.IO.Directory.CreateDirectory(datapath + @"\output");
|
|
}
|
|
}
|
|
|
|
private void txtbasedir_TextChanged(object sender, EventArgs e)
|
|
{
|
|
if (!System.IO.Directory.Exists(txtbasedir.Text))
|
|
{
|
|
MessageBox.Show("Das angegebene Verzeichnis existiert nicht. Bitte geben Sie ein gültiges Verzeichnis an.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
check_outputdir();
|
|
}
|
|
|
|
private void btnbpcheck_Click(object sender, EventArgs e)
|
|
{
|
|
}
|
|
// System.Data.DataTable importdata = new System.Data.DataTable();
|
|
|
|
// ExcelNet.ExcelReader reader = new ExcelNet.ExcelReader();
|
|
// string selected_sheetname = "";
|
|
// var sheets = new List<string>();
|
|
// try
|
|
// {
|
|
// sheets = reader.Get_ExcelSheets(datapath + txtexcelinput.Text);
|
|
// }
|
|
// catch
|
|
// {
|
|
// MessageBox.Show("Auf die gewählte Excel-Datei kann aktuell nicht zugegriffen werden. Evtl. ist diese noch geöffnet.", "Excel-Import", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
// return;
|
|
// }
|
|
|
|
// selected_sheetname = sheets[0];
|
|
|
|
// Import_sf_Excel(datapath + txtexcelinput.Text, selected_sheetname, ref importdata);
|
|
// int bperror = 0;
|
|
// string connectionstring = Properties.Settings.Default.ConnectionString;
|
|
// for (int i = 0; i < importdata.Rows.Count; i++)
|
|
// {
|
|
// DataRow dr = importdata.Rows[i];
|
|
// if (bp_exists(connectionstring, dr[txtbp.Text].ToString()))
|
|
// {
|
|
// System.IO.File.AppendAllText(datapath + @"\partnercheck.log", dr[txtbp.Text].ToString() + " NOK");
|
|
// bperror++;
|
|
// }
|
|
|
|
// }
|
|
// if (bperror > 0)
|
|
// {
|
|
// MessageBox.Show($"Es wurden {bperror} Partner nicht gefundenen.", "Partnercheck", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
// }
|
|
//}
|
|
//private bool bp_exists(string connectionString, string bpnr)
|
|
//{
|
|
// return true;
|
|
// string sql = "SELECT COUNT(*) FROM MeineTabelle WHERE Nummer = @Nummer";
|
|
|
|
// //using (SqlConnection conn = new SqlConnection(connectionString))
|
|
// //using (SqlCommand cmd = new SqlCommand(sql, conn))
|
|
// //{
|
|
// // cmd.Parameters.AddWithValue("@Nummer", bpnr);
|
|
|
|
// // conn.Open();
|
|
// // int anzahl = (int)cmd.ExecuteScalar();
|
|
|
|
// // return anzahl > 0;
|
|
// //}
|
|
//}
|
|
}
|
|
}
|