|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml.Serialization;
using BusinessEntities;
namespace WinClient
{
public partial class frmProduct : Form
{
public frmProduct()
{
InitializeComponent();
}
private void buttonClear_Click(object sender, EventArgs e)
{
ClearControls();
}
private void buttonDeserialize_Click(object sender, EventArgs e)
{
StringReader reader = new StringReader(textBoxResult.Text);
XmlSerializer serializer = new XmlSerializer(typeof(Product));
Product product = (Product)serializer.Deserialize(reader);
ShowData(product);
}
private void buttonSerialize_Click(object sender, EventArgs e)
{
Product product = new Product();
product.Id = textBoxId.Text;
product.Name = textBoxName.Text;
product.Rate = decimal.Parse(textBoxRate.Text);
product.Quantity = int.Parse(textBoxQty.Text);
XmlSerializer serializer = new XmlSerializer(typeof(Product));
StringWriter writer = new StringWriter();
serializer.Serialize(writer, product);
textBoxResult.Text = writer.ToString();
}
private void frmProduct_Load(object sender, EventArgs e)
{
ClearControls();
}
private void ClearControls()
{
textBoxId.Text = string.Empty;
textBoxName.Text = string.Empty;
textBoxQty.Text = "0";
textBoxRate.Text = "0";
}
private void ShowData(Product product)
{
textBoxId.Text = product.Id;
textBoxName.Text = product.Name;
textBoxRate.Text = product.Rate.ToString();
textBoxQty.Text = product.Quantity.ToString();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.