public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: Diese Codezeile lädt Daten in die Tabelle "dsCountries.CustomersCountry". Sie können sie bei Bedarf verschieben oder entfernen
this.customersCountryTableAdapter.Fill(this.dsCountries.CustomersCountry);
this.customersBindingSource.Sort = "CompanyName";
if(cboCountry.Items.Count > 1)
{
cboCountry.SelectedIndex = 1;
cboCountry.SelectedIndex = 0;
}
// TODO: Diese Codezeile lädt Daten in die Tabelle "northwindCustomerDataSet.Customers". Sie können sie bei Bedarf verschieben oder entfernen.
//this.customersTableAdapter.ClearBeforeFill = true;
//this.customersTableAdapter.Fill(this.northwindCustomerDataSet.Customers);
}
private void cboCountry_SelectedIndexChanged(object sender, EventArgs e)
{
this.customersTableAdapter.Fill(this.northwindCustomerDataSet.Customers, (String) cboCountry.SelectedValue);
}
private void btnDeleteData_Click(object sender, EventArgs e)
{
//Save to db
/*
*
* customersBindingSource.EndEdit();
* customersTableAdapter.Update(northwindCustomerDataSet.Customers);
*/
var confirmResult = MessageBox.Show("Are you sure to delete all selected items??\nYou can only restore this date with an export-file!",
"Confirm Delete!!",
MessageBoxButtons.YesNo);
if (confirmResult == DialogResult.Yes)
{
this.northwindCustomerDataSet.Clear();
}
}
private void btnExport_Click(object sender, EventArgs e)
{
try
{
SaveFileDialog saveDialog = new SaveFileDialog
{
Title = "Select XML File",
CheckPathExists = true,
DefaultExt = "xml",
Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*",
RestoreDirectory = true,
};
if (saveDialog.ShowDialog() == DialogResult.OK)
{
northwindCustomerDataSet.WriteXml(saveDialog.FileName, XmlWriteMode.WriteSchema);
}
} catch(Exception ex) {
MessageBox.Show("Es ist ein Fehler aufgetreten: " + ex.Message + "\n\n" + ex.StackTrace, "Error exporting",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnImport_Click(object sender, EventArgs e)
{
try
{
foreach (DataTable dataTable in northwindCustomerDataSet.Tables)
dataTable.BeginLoadData();
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
northwindCustomerDataSet.ReadXml(openFileDialog.FileName);
}
}
foreach (DataTable dataTable in northwindCustomerDataSet.Tables)
dataTable.EndLoadData();
northwindCustomerDataSet.AcceptChanges();
}
catch (Exception ex)
{
MessageBox.Show("Es ist ein Fehler aufgetreten: " + ex.Message + "\n\n" + ex.StackTrace, "Error exporting",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void openDLL_Click(object sender, EventArgs e)
{
OpenFileDialog dllDialog = new OpenFileDialog();
dllDialog.Title = "Öffne Assembly-DLL";
dllDialog.Filter = "Assembly-DLL|*.dll|Assembly-EXE|*.exe";
if(dllDialog.ShowDialog() == DialogResult.OK)
{
try {
typeTree.BeginUpdate();
Assembly assembly = Assembly.LoadFile(dllDialog.FileName);
assemblyName.Text = "Assembly-Name: " + assembly.GetName().Name;
typeTree.Nodes.Clear();
foreach (Type type in assembly.GetTypes())
{
Console.WriteLine(type.ToString());
//Add Type to tree
TreeNode node = new TreeNode(type.Name);
//Check if theire are any methods
if (type.GetMethods().Length != 0)
{
//Add all Methods
TreeNode methodsNode = new TreeNode("Methods: ");
foreach (MethodInfo method in type.GetMethods())
{
TreeNode methodNode = new TreeNode(method.Name);
if (method.GetParameters().Length != 0)
{
TreeNode paramNode = new TreeNode("Parameters: ");
foreach (ParameterInfo paramInfo in method.GetParameters())
{
if (!paramInfo.IsOut)
{
paramNode.Nodes.Add(paramInfo.ParameterType.Name + " " + paramInfo.Name);
}
}
methodNode.Nodes.Add(paramNode);
}
methodNode.Nodes.Add(new TreeNode("Returns: " + method.ReturnType.Name));
methodsNode.Nodes.Add(methodNode);
}
node.Nodes.Add(methodsNode);
}
//Check if theire are any properties
if(type.GetProperties().Length != 0)
{
TreeNode memberNode = new TreeNode("Properties: ");
foreach (PropertyInfo prop in type.GetProperties())
{
memberNode.Nodes.Add(prop.PropertyType.Name + " " + prop.Name);
}
node.Nodes.Add(memberNode);
typeTree.Nodes.Add(node);
}
}
typeTree.EndUpdate();
}
catch (BadImageFormatException)
{
MessageBox.Show("Konnte diese Datei nicht laden, da diese ein ungültiges Format hat!", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}