using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using System.Reflection; using System.Xml.Linq; using System.Windows.Markup; using AppRes = Eugen.ESystem.Windows.Forms.Properties.AppResources; using System.Windows.Documents; namespace Eugen.ESystem.Windows.Forms { public partial class TruthTableControl : UserControl { #region Version und Copyright // Keys und Copyright static string dllName = Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); //Den Programmnamen auslesen static string dllVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); static object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); static string copyright = GenerateCopyright(); string icon = Application.StartupPath + "\\Info.bmp"; //Assembly Datum und Zeit static DateTime value = AssemblyDateTime(); string date = value.ToShortDateString(); string time = value.ToLongTimeString(); private static DateTime AssemblyDateTime() { var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; var buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond * 2 * version.Revision)); //Tage seit dem 1. Januar 2000 und Sekunden seit Mitternacht, (multiplizier mit 2 ergibt das Original) return buildDateTime; } private static string CurrentYear() { DateTime dtn = DateTime.Now; return dtn.Year.ToString(); } private static string StartYear() { string startYear = ""; if (((AssemblyCopyrightAttribute)attributes[0]).Copyright.Contains("Copyright © ")) { startYear = ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace("Copyright © ", ""); while (startYear.StartsWith(" ")) { startYear = startYear.Remove(0, 1); } startYear = startYear.Remove(startYear.IndexOf(" ")); return startYear; } else { DateTime dtn = DateTime.Now; return dtn.Year.ToString(); } } private static string GenerateCopyright() { string startYear = StartYear(); string currentYear = CurrentYear(); if (startYear == currentYear) { return ((AssemblyCopyrightAttribute)attributes[0]).Copyright; } else { return ((AssemblyCopyrightAttribute)attributes[0]).Copyright.Replace(startYear, String.Concat(startYear, "-", currentYear)); } } #endregion #region DLL-Info /// /// Contains the name of the dll file. /// public static string DllName { private set; get; } /// /// Contains the version of the dll file. /// public static string DllVersion { private set; get; } /// /// Contains the copyright notice. /// public static string Copyright { private set; get; } /// /// Contains the name-, version- and copyright-information of the dll file. /// public static string[] DllInfo { private set; get; } private static void SetDllInfo() { //Name, Keys und Copyright setzen DllName = dllName; DllVersion = dllVersion; Copyright = copyright; } #endregion static TruthTableControl() { SetDllInfo(); //Name, Keys und Copyright der DLL setzen } /// /// Creates a control with which the values in an XML file can be edited /// public TruthTableControl() { InitializeComponent(); InitialDirectory = @"C:\"; Topic = "Topic"; StandardValue = 0; CleanUpButton = cleanUpButton; MoveButtons = moveButtons; SetSurfaceStandardAppearance(); } #region Public values /// /// The password used for encryption. An empty value disables the Encrypt values switch /// public string Password { get { return password; } set { password = value; checkBoxEncryptValues.Enabled = !String.IsNullOrEmpty(Password); } } /// /// Defines or read the initial directory /// public string InitialDirectory { set; get; } /// /// XML file name. Must be specified mandatory /// public string XMLfileName { set; get; } /// /// XML group file name. Must be specified mandatory and defines the XML file in which the groups are stored /// public string XMLgroupFileName { set; get; } /// /// Adjusts the labeling of the values control. An empty value forces the default labeling /// public string ValueControlName { get { return groupBoxValueControl.Text; } set { groupBoxValueControl.Text = value; groupBoxValueControl.Refresh(); } } /// /// Defines the Topic. An empty value forces the default labeling /// public string Topic { set; get; } /// /// Adjusts the labeling of the group designation. An empty value forces the default labeling /// public string GroupName { get { return labelGroup.Text; } set { labelGroup.Text = value; } } /// /// Changes the name of the group attribute used in the XML file, which is displayed and must be included in groups. Required for the Load function /// public string Group { set; get; } /// /// List of group attribute names. Required for the Load function /// public string[] Groups { set; get; } ///// ///// Adjusts the name of the key attribute used in the XML file. Required by the Load function ///// //public string Key { set; get; } /// /// Adjusts the labeling of the table header designation for the key. An empty value forces the default labeling /// public string TableKeyName { get { return dataGridViewValues.Columns[0].HeaderText; } set { dataGridViewValues.Columns[0].HeaderText = value; } } /// /// Adjusts the labeling of the table header designation for the user 1. An empty value forces the default labeling /// public string User1Label { get { return labelUser1.Text; } set { labelUser1.Text = value; } } /// /// Adjusts the labeling of the table header designation for the user 2. An empty value forces the default labeling /// public string User2Label { get { return labelUser2.Text; } set { labelUser2.Text = value; } } /// /// Adjusts the labeling of the table header designation for the user 3. An empty value forces the default labeling /// public string User3Label { get { return labelUser3.Text; } set { labelUser3.Text = value; } } /// /// Adjusts the labeling of the table header designation for the user 4. An empty value forces the default labeling /// public string User4Label { get { return labelUser4.Text; } set { labelUser4.Text = value; } } /// /// Adjusts the labeling of the table header designation for the user 5. An empty value forces the default labeling /// public string User5Label { get { return labelUser5.Text; } set { labelUser5.Text = value; } } /// /// Adjusts the labeling of the table header designation for the user 6. An empty value forces the default labeling /// public string User6Label { get { return labelUser6.Text; } set { labelUser6.Text = value; } } /// /// Adjusts the labeling of the table header designation for the user 7. An empty value forces the default labeling /// public string User7Label { get { return labelUser7.Text; } set { labelUser7.Text = value; } } /// /// Adjusts the labeling of the table header designation for the user 8. An empty value forces the default labeling /// public string User8Label { get { return labelUser8.Text; } set { labelUser8.Text = value; } } /// /// Adjusts the labeling of the table header designation for the value. An empty value forces the default labeling /// public string TableValue1_1Name { get { return dataGridViewValues.Columns[1].HeaderText; } set { dataGridViewValues.Columns[1].HeaderText = value; } } /// /// Adjusts the labeling of the table header designation for the value. An empty value forces the default labeling /// public string TableValue1_2Name { get { return dataGridViewValues.Columns[2].HeaderText; } set { dataGridViewValues.Columns[2].HeaderText = value; } } /// /// Adjusts the labeling of the table header designation for the value. An empty value forces the default labeling /// public string TableValue2_1Name { get { return dataGridViewValues.Columns[3].HeaderText; } set { dataGridViewValues.Columns[3].HeaderText = value; } } /// /// Adjusts the labeling of the table header designation for the value. An empty value forces the default labeling /// public string TableValue2_2Name { get { return dataGridViewValues.Columns[4].HeaderText; } set { dataGridViewValues.Columns[4].HeaderText = value; } } /// /// Adjusts the labeling of the table header designation for the value. An empty value forces the default labeling /// public string TableValue3_1Name { get { return dataGridViewValues.Columns[5].HeaderText; } set { dataGridViewValues.Columns[5].HeaderText = value; } } /// /// Adjusts the labeling of the table header designation for the value. An empty value forces the default labeling /// public string TableValue3_2Name { get { return dataGridViewValues.Columns[6].HeaderText; } set { dataGridViewValues.Columns[6].HeaderText = value; } } /// /// Adjusts the labeling of the table header designation for the value. An empty value forces the default labeling /// public string TableValue4_1Name { get { return dataGridViewValues.Columns[7].HeaderText; } set { dataGridViewValues.Columns[7].HeaderText = value; } } /// /// Adjusts the labeling of the table header designation for the value. An empty value forces the default labeling /// public string TableValue4_2Name { get { return dataGridViewValues.Columns[8].HeaderText; } set { dataGridViewValues.Columns[8].HeaderText = value; } } /// /// Adjusts the labeling of the table header designation for the value. An empty value forces the default labeling /// public string TableValue5_1Name { get { return dataGridViewValues.Columns[9].HeaderText; } set { dataGridViewValues.Columns[9].HeaderText = value; } } /// /// Adjusts the labeling of the table header designation for the value. An empty value forces the default labeling /// public string TableValue5_2Name { get { return dataGridViewValues.Columns[10].HeaderText; } set { dataGridViewValues.Columns[10].HeaderText = value; } } /// /// Adjusts the labeling of the table header designation for the value. An empty value forces the default labeling /// public string TableValue6_1Name { get { return dataGridViewValues.Columns[11].HeaderText; } set { dataGridViewValues.Columns[11].HeaderText = value; } } /// /// Adjusts the labeling of the table header designation for the value. An empty value forces the default labeling /// public string TableValue6_2Name { get { return dataGridViewValues.Columns[12].HeaderText; } set { dataGridViewValues.Columns[12].HeaderText = value; } } /// /// Adjusts the labeling of the table header designation for the value. An empty value forces the default labeling /// public string TableValue7_1Name { get { return dataGridViewValues.Columns[13].HeaderText; } set { dataGridViewValues.Columns[13].HeaderText = value; } } /// /// Adjusts the labeling of the table header designation for the value. An empty value forces the default labeling /// public string TableValue7_2Name { get { return dataGridViewValues.Columns[14].HeaderText; } set { dataGridViewValues.Columns[14].HeaderText = value; } } /// /// Adjusts the labeling of the table header designation for the value. An empty value forces the default labeling /// public string TableValue8_1Name { get { return dataGridViewValues.Columns[15].HeaderText; } set { dataGridViewValues.Columns[15].HeaderText = value; } } /// /// Adjusts the labeling of the table header designation for the value. An empty value forces the default labeling /// public string TableValue8_2Name { get { return dataGridViewValues.Columns[16].HeaderText; } set { dataGridViewValues.Columns[16].HeaderText = value; } } /// /// Sets the content of the truth table for the 'InterfaceNxPortal' area /// public List InterfaceNxPortal { set; get; } /// /// Sets the content of the truth table for the Menu 'Action' area /// public List MenuAction { set; get; } /// /// Sets the content of the truth table for the Menu 'Tools' area /// public List MenuTools { set; get; } /// /// Sets the content of the truth table for the Menu 'Information' area /// public List MenuInformations { set; get; } /// /// Sets the content of the truth table for the Menu 'Preferences' area /// public List MenuPreferences { set; get; } /// /// Sets the content of the truth table for the Menu 'Help' area /// public List MenuHelp { set; get; } /// /// Controls whether the CleanUp button is enabled. An empty value forces the default value (true) /// public bool CleanUpButton { get { return cleanUpButton; } set { cleanUpButton = value; buttonUp.Enabled = !cleanUpButton; buttonDown.Enabled = !cleanUpButton; } } /// /// Controls whether the Move buttons are enabled. An empty value forces the default value (true) /// public bool MoveButtons { get { return moveButtons; } set { moveButtons = value; buttonUp.Enabled = !moveButtons; buttonDown.Enabled = !moveButtons; } } /// /// Adjusts the labeling of the encrypt value checkBox. An empty value forces the default labeling /// public string CheckBoxEncryptValueText { get { return checkBoxEncryptValues.Text; } set { checkBoxEncryptValues.Text = value; checkBoxEncryptValues.Enabled = !String.IsNullOrEmpty(Password); } } /// /// Controls whether values are always encrypted. An empty value forces the default value (false) /// public bool AlwaysEncrypted { get { return alwaysEncrypted; } set { alwaysEncrypted = value; checkBoxEncryptValues.Enabled = !alwaysEncrypted; checkBoxEncryptValues.Checked = alwaysEncrypted; } } #endregion #region Private values private string password; private bool cleanUpButton = true; private bool moveButtons = true; private bool alwaysEncrypted = false; private bool standardValueSet = false; private int selectedRow = 0; private int rowIndexColored = 0; private int StandardValue { get; set; } private string XmlFileName { get; set; } private string OldXMLfileName { get; set; } private List OldNameData { get; set; } private List OldValueData { get; set; } private List NewNameData { get; set; } private List NewValueData { get; set; } private bool OldEcryptStatus { get; set; } private bool NewEcryptStatus { get; set; } #endregion private void comboBoxGroup_SelectedIndexChanged(object sender, EventArgs e) { Group = comboBoxGroup.SelectedItem.ToString(); XmlFileName = String.Concat(XMLfileName.Replace(".xml", ""), "_", Group, ".xml"); OldXMLfileName = XmlFileName; //XMLfileName = String.Concat(InitialDirectory, "\\", Group, ".xml"); buttonSave.Enabled = (!String.IsNullOrEmpty(comboBoxGroup.Text)); checkBoxEncryptValues.Checked = AlwaysEncrypted; //OldNameData und OldValueDate schreiben SetData("new"); if (File.Exists(XmlFileName)) { if (dataGridViewValues.Rows.Count > 1) { //Wurden in der Datagridview Werte geändert, dann speichern if (HasAnyDataChanged()) { DialogResult result = MessageBox.Show(AppRes.msgBoxTxt003, AppRes.msgBoxCapt003, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { //Datagridview speichern SaveXML(OldXMLfileName); } } } //Datagridview leeren und XML Laden dataGridViewValues.Rows.Clear(); LoadXML(); } else { if (dataGridViewValues.Rows.Count > 1) { //Wurden in der Datagridview Werte geändert, dann speichern if (HasAnyDataChanged()) { DialogResult result = MessageBox.Show(AppRes.msgBoxTxt003, AppRes.msgBoxCapt003, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { //Datagridview speichern SaveXML(OldXMLfileName); } } } dataGridViewValues.Rows.Clear(); MessageBox.Show(AppRes.msgBoxTxt002, AppRes.msgBoxCapt002, MessageBoxButtons.OK, MessageBoxIcon.Warning); SetTableContent(); //Die Übergebenen werte laden } //OldNameData und OldValueDate schreiben SetData("old"); } private void comboBoxGroup_TextChanged(object sender, EventArgs e) { buttonSave.Enabled = (!String.IsNullOrEmpty(comboBoxGroup.Text)); } private void buttonUp_Click(object sender, EventArgs e) { if (dataGridViewValues.SelectedCells.Count > 0) { int index = dataGridViewValues.SelectedCells[0].OwningRow.Index; if (index > 0) { int col = dataGridViewValues.SelectedCells[0].OwningColumn.Index; DataGridViewRowCollection rows = dataGridViewValues.Rows; DataGridViewRow row = rows[index]; rows.Remove(row); rows.Insert(index - 1, row); dataGridViewValues.ClearSelection(); dataGridViewValues.Rows[index - 1].Cells[col].Selected = true; } } } private void buttonDown_Click(object sender, EventArgs e) { if (dataGridViewValues.SelectedCells.Count > 0) { int index = dataGridViewValues.SelectedCells[0].OwningRow.Index; if (index < dataGridViewValues.Rows.Count - 2) { int col = dataGridViewValues.SelectedCells[0].OwningColumn.Index; DataGridViewRowCollection rows = dataGridViewValues.Rows; DataGridViewRow row = rows[index]; rows.Remove(row); rows.Insert(index + 1, row); dataGridViewValues.ClearSelection(); dataGridViewValues.Rows[index + 1].Cells[col].Selected = true; } } } private void buttonLoad_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(XmlFileName)) { openFileDialog.Title = AppRes.dlgOpenTitle; openFileDialog.InitialDirectory = InitialDirectory; openFileDialog.FileName = ""; openFileDialog.Filter = AppRes.dlgFilter; //"xml files (*.xml)|*.xml|All files (*.*)|*.*" openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { XmlFileName = openFileDialog.FileName; LoadXML(); } } else { if (File.Exists(XmlFileName)) { LoadXML(); } else { MessageBox.Show(AppRes.msgBoxTxt001, AppRes.msgBoxCapt001, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } private void buttonSave_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(XmlFileName)) { saveFileDialog.Title = AppRes.dlgSaveTitle; saveFileDialog.InitialDirectory = InitialDirectory; saveFileDialog.Filter = AppRes.dlgFilter; //"xml files (*.xml)|*.xml|All files (*.*)|*.*" saveFileDialog.FilterIndex = 1; saveFileDialog.RestoreDirectory = true; if (saveFileDialog.ShowDialog() == DialogResult.OK) { SaveXML(XmlFileName); } } else { SaveXML(XmlFileName); } } private void buttonCleanup_Click(object sender, EventArgs e) { //Alle der ComboBox Einträge auslesen string[] xmlItems = LoadGroup(); //Alle XML-Dateien auslesen die mit 'NXenvironment' beginnen string path = Path.GetDirectoryName(XMLfileName); string[] origXmlFiles = Directory.GetFiles(path); List xmlFiles = new List(); string temp = ""; bool exist = false; for (int i = 0; i < origXmlFiles.Length; i++) { origXmlFiles[i] = Path.GetFileName(origXmlFiles[i]); if (origXmlFiles[i].StartsWith(Path.GetFileNameWithoutExtension(XMLfileName))) { xmlFiles.Add(origXmlFiles[i]); } } //Dateien die in den ComboBox Einträgen nicht vorkommen, löschen for (int i = 0; i < xmlFiles.Count; i++) { for (int j = 0; j < xmlItems.Length; j++) { //Vergleichen und 'exist' setzen temp = xmlFiles[i].Replace(Path.GetFileNameWithoutExtension(XMLfileName) + "_", ""); if (temp.Remove(temp.LastIndexOf(".")) == xmlItems[j]) { exist = true; } } if (!exist) { //Datei löschen try { File.Delete(String.Concat(path, "\\", xmlFiles[i])); MessageBox.Show(AppRes.msgBoxTxt005, AppRes.msgBoxCapt004, MessageBoxButtons.OK); } catch (Exception) { MessageBox.Show(AppRes.msgBoxTxt004, AppRes.msgBoxCapt002, MessageBoxButtons.OK); } } exist = false; } } private void dataGridViewValues_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete) { selectedRow = dataGridViewValues.SelectedCells[0].RowIndex + 1; //Wenn die Zeile gelöscht wird, dann die Zeilennummer merken } } private void dataGridViewValues_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e) { //Wenn die gelöschte Zeile den Standardwert enthielt, dann die WErte zurücksetzten, weil es keinen Standardwert mehr gibt if (selectedRow == rowIndexColored) { StandardValue = 0; //Es gibt keine ausgewählte Standardzeile standardValueSet = false; //es gibt keinen Standardwert rowIndexColored = 0; //Es gibt keine umgefärbte Zeile } } private void SetSurfaceStandardAppearance() { SetBasicValues(); labelUser1.Text = AppRes.user001; labelUser2.Text = AppRes.user002; labelUser3.Text = AppRes.user003; labelUser4.Text = AppRes.user004; labelUser5.Text = AppRes.user005; labelUser6.Text = AppRes.user006; labelUser7.Text = AppRes.user007; labelUser8.Text = AppRes.user008; dataGridViewValues.Columns[1].HeaderText = AppRes.function001; dataGridViewValues.Columns[1].HeaderText = AppRes.status001; dataGridViewValues.Columns[2].HeaderText = AppRes.status002; dataGridViewValues.Columns[3].HeaderText = AppRes.status001; dataGridViewValues.Columns[4].HeaderText = AppRes.status002; dataGridViewValues.Columns[5].HeaderText = AppRes.status001; dataGridViewValues.Columns[6].HeaderText = AppRes.status002; dataGridViewValues.Columns[7].HeaderText = AppRes.status001; dataGridViewValues.Columns[8].HeaderText = AppRes.status002; dataGridViewValues.Columns[9].HeaderText = AppRes.status001; dataGridViewValues.Columns[10].HeaderText = AppRes.status002; dataGridViewValues.Columns[11].HeaderText = AppRes.status001; dataGridViewValues.Columns[12].HeaderText = AppRes.status002; dataGridViewValues.Columns[13].HeaderText = AppRes.status001; dataGridViewValues.Columns[14].HeaderText = AppRes.status002; dataGridViewValues.Columns[15].HeaderText = AppRes.status001; dataGridViewValues.Columns[16].HeaderText = AppRes.status002; } public void SetTableContent() { switch (Group) { case "InterfaceNxPortal": SetStandardValues(InterfaceNxPortal); break; case "MenuAction": SetStandardValues(MenuAction); break; case "MenuTools": SetStandardValues(MenuTools); break; case "MenuInformations": SetStandardValues(MenuInformations); break; case "MenuPreferences": SetStandardValues(MenuPreferences); break; case "MenuHelp": SetStandardValues(MenuHelp); break; default: break; } } private void SetStandardValues(List values) { foreach (TableRow tableRow in values) { AddTableRow(tableRow); } } public void SetBasicValues() { string[] temp = Groups; Groups = ReadGroups(); if (Groups != null) { comboBoxGroup.Items.Clear(); for (int i = 0; i < Groups.Length; i++) { comboBoxGroup.Items.Add(Groups[i]); } comboBoxGroup.SelectedIndex = 0; } else { Groups = temp; if (Groups != null) { comboBoxGroup.Items.Clear(); for (int i = 0; i < Groups.Length; i++) { comboBoxGroup.Items.Add(Groups[i]); } comboBoxGroup.SelectedIndex = 0; } } buttonCleanup.Enabled = CleanUpButton; buttonCleanup.Visible = CleanUpButton; buttonUp.Enabled = MoveButtons; buttonUp.Visible = MoveButtons; buttonDown.Enabled = MoveButtons; buttonDown.Visible = MoveButtons; } private void LoadXML() { checkBoxEncryptValues.Checked = false; var loadXML = new LoadXML(); loadXML.FileName = String.Concat(XMLfileName.Replace(".xml", ""), "_", Group, ".xml"); loadXML.Load(); string[] values = new string[loadXML.Values.Length]; values = loadXML.Values; string[] trueTableValues = new string[16]; if (!String.IsNullOrEmpty(Group)) { loadXML.Group = Group; } dataGridViewValues.Rows.Clear(); for (int i = 0; i < values.Length; i++) { if (values[i].StartsWith("$$$$")) { values[i] = Decrypt(values[i], Password); checkBoxEncryptValues.Checked = true; //Wenn ein verschlüsseltes Element gefunden wurde, dann setzen } //dataGridViewValues.Rows.Add(loadXML.Keys[i], values[i]); trueTableValues = values[i].Split(','); dataGridViewValues.Rows.Add(loadXML.Keys[i], Convert.ToBoolean(trueTableValues[0]), Convert.ToBoolean(trueTableValues[1]), Convert.ToBoolean(trueTableValues[2]), Convert.ToBoolean(trueTableValues[3]), Convert.ToBoolean(trueTableValues[4]), Convert.ToBoolean(trueTableValues[5]), Convert.ToBoolean(trueTableValues[6]), Convert.ToBoolean(trueTableValues[7]), Convert.ToBoolean(trueTableValues[8]), Convert.ToBoolean(trueTableValues[9]), Convert.ToBoolean(trueTableValues[10]), Convert.ToBoolean(trueTableValues[11]), Convert.ToBoolean(trueTableValues[12]), Convert.ToBoolean(trueTableValues[13]), Convert.ToBoolean(trueTableValues[14]), Convert.ToBoolean(trueTableValues[15])); } dataGridViewValues.Refresh(); comboBoxGroup.Text = loadXML.Group; //Gruppe setzen SetData("old"); //Die geladenen Daten setzten } private string[] LoadGroup() { string[] values = new string[comboBoxGroup.Items.Count]; for (int i = 0; i < comboBoxGroup.Items.Count; i++) { values[i] = comboBoxGroup.Items[i].ToString(); } for (int i = 0; i < values.Length; i++) { if (values[i].StartsWith("$$$$")) { values[i] = Decrypt(values[i], Password); } } return values; } private void SaveXML(string xmlFileName) { xmlFileName = String.Concat(XMLfileName.Replace(".xml", ""), "_", Group, ".xml"); XMLgroupFileName = xmlFileName; if (!Directory.Exists(Path.GetDirectoryName(xmlFileName))) { Directory.CreateDirectory(Path.GetDirectoryName(xmlFileName)); //Wenn das Verzeichnis nicht existiert, dann erzeugen } int dgvLength = dataGridViewValues.RowCount; string[] keys = new string[dgvLength]; string value = ""; string[] values = new string[dgvLength]; for (int i = 0; i < dgvLength; i++) { if (checkBoxEncryptValues.Checked) { //value = Encrypt(dataGridViewValues[1, i].Value.ToString(), Password); //Verschlüsselt value = Encrypt(dataGridViewValues[1, i].Value.ToString() + "," + dataGridViewValues[2, i].Value.ToString() + "," + dataGridViewValues[3, i].Value.ToString() + "," + dataGridViewValues[4, i].Value.ToString() + "," + dataGridViewValues[5, i].Value.ToString() + "," + dataGridViewValues[6, i].Value.ToString() + "," + dataGridViewValues[7, i].Value.ToString() + "," + dataGridViewValues[8, i].Value.ToString() + "," + dataGridViewValues[9, i].Value.ToString() + "," + dataGridViewValues[10, i].Value.ToString() + "," + dataGridViewValues[11, i].Value.ToString() + "," + dataGridViewValues[12, i].Value.ToString() + "," + dataGridViewValues[13, i].Value.ToString() + "," + dataGridViewValues[14, i].Value.ToString() + "," + dataGridViewValues[15, i].Value.ToString() + "," + dataGridViewValues[16, i].Value.ToString(), Password); //Verschlüsselt } else { //value = dataGridViewValues[1, i].Value.ToString(); //Unverschlüsselt value = dataGridViewValues[1, i].Value.ToString() + "," + dataGridViewValues[2, i].Value.ToString() + "," + dataGridViewValues[3, i].Value.ToString() + "," + dataGridViewValues[4, i].Value.ToString() + "," + dataGridViewValues[5, i].Value.ToString() + "," + dataGridViewValues[6, i].Value.ToString() + "," + dataGridViewValues[7, i].Value.ToString() + "," + dataGridViewValues[8, i].Value.ToString() + "," + dataGridViewValues[9, i].Value.ToString() + "," + dataGridViewValues[10, i].Value.ToString() + "," + dataGridViewValues[11, i].Value.ToString() + "," + dataGridViewValues[12, i].Value.ToString() + "," + dataGridViewValues[13, i].Value.ToString() + "," + dataGridViewValues[14, i].Value.ToString() + "," + dataGridViewValues[15, i].Value.ToString() + "," + dataGridViewValues[16, i].Value.ToString(); //Unverschlüsselt } keys[i] = dataGridViewValues[0, i].Value.ToString(); values[i] = value; } //Speichern var saveXML = new SaveXML(); saveXML.FileName = xmlFileName; saveXML.Topic = Topic; //z.B. "NX-Portal" saveXML.Group = comboBoxGroup.Text; //z.B. "NX 1953" saveXML.Keys = keys; //z.B. "UGII_ENV" saveXML.Values = values; //z.B. "M:\ug\NX1953_NXTC\global\00_DEFAULTS\UGII\ugii_env.dat" saveXML.Save(); //OldNameData und OldValueDate schreiben SetData("old"); } private string Encrypt(string clearText, string password) { var crypt = new Cryption(); return String.Concat("$$$$", crypt.EncryptString(clearText, password)); } private string Decrypt(string encryptedText, string password) { var crypt = new Cryption(); return crypt.DecryptString(encryptedText.Replace("$$$$", ""), password); } private void SetData(string stage) { int dgvLength = dataGridViewValues.RowCount - 1; if (stage == "old") { //Old Data List oldNameData = new List(); List oldValueData = new List(); for (int i = 0; i < dgvLength; i++) { oldNameData.Add(dataGridViewValues[0, i].Value.ToString()); oldValueData.Add(dataGridViewValues[1, i].Value.ToString()); } OldNameData = oldNameData; OldValueData = oldValueData; OldEcryptStatus = checkBoxEncryptValues.Checked; } else { //New Data List newNameData = new List(); List newValueData = new List(); for (int i = 0; i < dgvLength; i++) { newNameData.Add(dataGridViewValues[0, i].Value.ToString()); newValueData.Add(dataGridViewValues[1, i].Value.ToString()); } NewNameData = newNameData; NewValueData = newValueData; NewEcryptStatus = checkBoxEncryptValues.Checked; } } private bool HasAnyDataChanged() { int dgvLength = dataGridViewValues.RowCount - 1; bool hasChanged = false; if (OldNameData.Count != NewNameData.Count) { hasChanged = true; } else { for (int i = 0; i < dgvLength; i++) { if (OldNameData[i] != NewNameData[i]) { hasChanged = true; } if (OldValueData[i] != NewValueData[i]) { hasChanged = true; } if (OldEcryptStatus != NewEcryptStatus) { hasChanged = true; } } } return hasChanged; } /// /// Reads the groups from a XML file /// private string[] ReadGroups() { if (File.Exists(XMLgroupFileName)) { var sivco = new SingleValueControl(); sivco.XMLfileName = XMLgroupFileName; sivco.Password = Password; return sivco.GetValues(); } else { return null; } } /// /// Sets a customer width of the user control /// /// The width. Min=316, Max=800 public void SetDialogWidth(int width) { if (width >= this.MinimumSize.Width && width <= this.MaximumSize.Width) { this.Width = width; int dif = width - this.MinimumSize.Width; if (dif >= 0) { dataGridViewValues.Columns[0].Width = width - 954; } } } /// /// Adds a line to the 'datagridview' /// /// The truth table of a position public void AddTableRow(TableRow tableRow) { dataGridViewValues.Rows.Add(tableRow.Column0, tableRow.Column1_1, tableRow.Column1_2, tableRow.Column2_1, tableRow.Column2_2, tableRow.Column3_1, tableRow.Column3_2, tableRow.Column4_1, tableRow.Column4_2, tableRow.Column5_1, tableRow.Column5_2, tableRow.Column6_1, tableRow.Column6_2, tableRow.Column7_1, tableRow.Column7_2, tableRow.Column8_1, tableRow.Column8_2); } } public class TableRow { public string Column0 { get; } public bool Column1_1 { get; } public bool Column1_2 { get; } public bool Column2_1 { get; } public bool Column2_2 { get; } public bool Column3_1 { get; } public bool Column3_2 { get; } public bool Column4_1 { get; } public bool Column4_2 { get; } public bool Column5_1 { get; } public bool Column5_2 { get; } public bool Column6_1 { get; } public bool Column6_2 { get; } public bool Column7_1 { get; } public bool Column7_2 { get; } public bool Column8_1 { get; } public bool Column8_2 { get; } public TableRow(string column0, bool column1_1, bool column1_2, bool column2_1, bool column2_2, bool column3_1, bool column3_2, bool column4_1, bool column4_2, bool column5_1, bool column5_2, bool column6_1, bool column6_2, bool column7_1, bool column7_2, bool column8_1, bool column8_2) => (Column0, Column1_1, Column1_2, Column2_1, Column2_2, Column3_1, Column3_2, Column4_1, Column4_2, Column5_1, Column5_2, Column6_1, Column6_2, Column7_1, Column7_2, Column8_1, Column8_2) = (column0, column1_1, column1_2, column2_1, column2_2, column3_1, column3_2, column4_1, column4_2, column5_1, column5_2, column6_1, column6_2, column7_1, column7_2, column8_1, column8_2); } }