using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace JsonSerialization
{
    public partial class frm2JsonSerialization : Form
    {
        public frm2JsonSerialization()
        {
            InitializeComponent();
        }

        private void frm2JsonSerialization_Load(object sender, EventArgs e)
        {
            // Make an object to serialize.
            Customer cust = new Customer()
            {
                Name = "Rod Stephens",
                Street = "1337 Leet St",
                City = "Bugsville",
                State = "CA",
                Zip = "98765",
                PhoneNumbers = new Dictionary<string, string>()
                {
                    {"Home", "111-222-3333"},
                    {"Cell", "222-333-4444"},
                    {"Work", "333-444-5555"},
                },
                EmailAddresses = new List<string>()
                {
                    "somewhere@someplace.com",
                    "nowhere@noplace.com",
                    "root@everywhere.org",
                },
            };
            cust.Orders = new Order[3];
            cust.Orders[0] = new Order()
            {
                Description = "Pencils, dozen",
                Quantity = 10,
                Price = 1.13m
            };
            cust.Orders[1] = new Order()
            {
                Description = "Notepad",
                Quantity = 3,
                Price = 0.99m
            };
            cust.Orders[2] = new Order()
            {
                Description = "Cookies",
                Quantity = 1,
                Price = 3.75m
            };

            // Serialize.
            string serialization = cust.ToJson();
            jsonTextBox.Text = serialization;
            jsonTextBox.Select(0, 0);

            // Deserialize.
            Customer new_cust = Customer.FromJson(serialization);
            propertiesTextBox.Text = new_cust.ToString();
            propertiesTextBox.Select(0, 0);
        }


        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
            this.propertiesTextBox = new System.Windows.Forms.TextBox();
            this.jsonTextBox = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.tableLayoutPanel1.SuspendLayout();
            this.SuspendLayout();
            // 
            // tableLayoutPanel1
            // 
            this.tableLayoutPanel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
            | System.Windows.Forms.AnchorStyles.Left) 
            | System.Windows.Forms.AnchorStyles.Right)));
            this.tableLayoutPanel1.ColumnCount = 2;
            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tableLayoutPanel1.Controls.Add(this.propertiesTextBox, 1, 1);
            this.tableLayoutPanel1.Controls.Add(this.jsonTextBox, 0, 1);
            this.tableLayoutPanel1.Controls.Add(this.label1, 0, 0);
            this.tableLayoutPanel1.Controls.Add(this.label2, 1, 0);
            this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 12);
            this.tableLayoutPanel1.Name = "tableLayoutPanel1";
            this.tableLayoutPanel1.RowCount = 2;
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
            this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tableLayoutPanel1.Size = new System.Drawing.Size(460, 267);
            this.tableLayoutPanel1.TabIndex = 5;
            // 
            // propertiesTextBox
            // 
            this.propertiesTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
            this.propertiesTextBox.Location = new System.Drawing.Point(233, 23);
            this.propertiesTextBox.Multiline = true;
            this.propertiesTextBox.Name = "propertiesTextBox";
            this.propertiesTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.propertiesTextBox.Size = new System.Drawing.Size(224, 241);
            this.propertiesTextBox.TabIndex = 4;
            // 
            // jsonTextBox
            // 
            this.jsonTextBox.Dock = System.Windows.Forms.DockStyle.Fill;
            this.jsonTextBox.Location = new System.Drawing.Point(3, 23);
            this.jsonTextBox.Multiline = true;
            this.jsonTextBox.Name = "jsonTextBox";
            this.jsonTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.jsonTextBox.Size = new System.Drawing.Size(224, 241);
            this.jsonTextBox.TabIndex = 1;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(3, 0);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(38, 13);
            this.label1.TabIndex = 0;
            this.label1.Text = "JSON:";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(233, 0);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(57, 13);
            this.label2.TabIndex = 2;
            this.label2.Text = "Properties:";
            // 
            // frm2JsonSerialization
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(484, 291);
            this.Controls.Add(this.tableLayoutPanel1);
            this.Name = "frm2JsonSerialization";
            this.Text = "JsonSerialization";
            this.Load += new System.EventHandler(this.frm2JsonSerialization_Load);
            this.tableLayoutPanel1.ResumeLayout(false);
            this.tableLayoutPanel1.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
        private System.Windows.Forms.TextBox propertiesTextBox;
        private System.Windows.Forms.TextBox jsonTextBox;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
    }
}