private void button5_Click(object sender, EventArgs e) { var xmlSerializer = new XmlSerializer(typeof(List <Product>), typesname.Values.ToArray()); using (var fileStream = new FileStream("XmlSerialize.txt", FileMode.Open)) { var streamReader = new StreamReader(fileStream); string key = streamReader.ReadLine(); Type converterType; if (typesname.TryGetValue(key, out converterType)) { string text = streamReader.ReadToEnd(); ConstructorInfo ci = converterType.GetConstructor(new Type[] { }); IConverter converter = (IConverter)ci.Invoke(new object[] { }); var stringReader = new StringReader(converter.Read(text)); productList.Clear(); productList = (List <Product>)xmlSerializer.Deserialize(stringReader); treeView1.Nodes.Clear(); treeView1.Nodes.Add(TreeBuilder.GetTree(productList)); } else { MessageBox.Show("Converter not found."); } } }
private void button7_Click(object sender, EventArgs e) { var textSerializer = new Serializer(typesname); using (var fileStream = new FileStream("TextSerialize.Txt", FileMode.Open)) { var stream = new StreamReader(fileStream); productList = (List <Product>)textSerializer.Deserialize(stream); treeView1.Nodes.Clear(); treeView1.Nodes.Add(TreeBuilder.GetTree(productList)); } }
private void button3_Click(object sender, EventArgs e) { var binaryFormatter = new BinaryFormatter(); using (var fileStream = new FileStream("BinSerialize.txt", FileMode.Open)) { productList.Clear(); productList = (List <Product>)binaryFormatter.Deserialize(fileStream); treeView1.Nodes.Clear(); treeView1.Nodes.Add(TreeBuilder.GetTree(productList)); } }
private void MenuClick(object sender, EventArgs e) { Type type = typesname[sender.ToString()]; ConstructorInfo ci = type.GetConstructor(new Type[] { }); if (ci != null) { Product product = (Product)ci.Invoke(new object[] { }); productList.Add(product); treeView1.Nodes.Clear(); treeView1.Nodes.Add(TreeBuilder.GetTree(productList)); } }
private void treeView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { if (e.KeyCode == Keys.Delete) { if (selectedNode != null && selectedNode.NodeType.IsSubclassOf(typeof(Product))) { if (MessageBox.Show("You really want to delete this object?", "Delete object", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { productList.Remove((Product)selectedNode.Value); treeView1.Nodes.Clear(); treeView1.Nodes.Add(TreeBuilder.GetTree(productList)); } } } }
private void button5_Click(object sender, EventArgs e) { List <Type> typeList = new List <Type>(); foreach (var item in typesname) { typeList.Add(item.Value); } Type[] typeArray = typeList.ToArray(); var xmlSerializer = new XmlSerializer(typeof(List <Product>), typeArray); using (var fileStream = new FileStream("XmlSerialize.txt", FileMode.Open)) { productList.Clear(); productList = (List <Product>)xmlSerializer.Deserialize(fileStream); treeView1.Nodes.Clear(); treeView1.Nodes.Add(TreeBuilder.GetTree(productList)); } }
private void button1_Click(object sender, EventArgs e) { if (choseNode != null) { TreeNodeTag nodeTag = (TreeNodeTag)choseNode.Tag; TreeNodeTag parentTag = (TreeNodeTag)choseNode.Parent.Tag; choseNode.Name = nodeTag.PropertiesInfo.Name + " = "; if (nodeTag.PropertiesInfo.CanWrite) { if (nodeTag.Value is int) { int value; if (int.TryParse(textBox1.Text, out value)) { choseNode.Name += textBox1.Text; nodeTag.PropertiesInfo.SetValue(parentTag.Value, value); nodeTag.Value = value; } else { MessageBox.Show("Incorrect input."); } } else { if (nodeTag.Value is String) { choseNode.Name += textBox1.Text; nodeTag.PropertiesInfo.SetValue(parentTag.Value, textBox1.Text); nodeTag.Value = textBox1.Text; } else { if (nodeTag.Value is double) { double value; if (double.TryParse(textBox1.Text, out value)) { choseNode.Name += textBox1.Text; nodeTag.PropertiesInfo.SetValue(parentTag.Value, value); nodeTag.Value = value; } else { MessageBox.Show("Incorrect input"); } } else { if (nodeTag.Value is bool) { bool value; if (bool.TryParse(textBox1.Text, out value)) { choseNode.Name += textBox1.Text; nodeTag.PropertiesInfo.SetValue(parentTag.Value, value); nodeTag.Value = value; } } else { MessageBox.Show("Incorrect input"); } } } } } } textBox1.Visible = false; button1.Visible = false; treeView1.Nodes.Clear(); treeView1.Nodes.Add(TreeBuilder.GetTree(productList)); }
private void RefreshTree() { treeView1.Nodes.Clear(); treeView1.Nodes.Add(TreeBuilder.GetTree(list)); }
private void button6_Click(object sender, EventArgs e) { treeView1.Nodes.Add(TreeBuilder.GetTree(list)); }