using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;
namespace OutlookExpress_V1._._
{
    public partial class AddContact : Form
    {
        private DataSet ds;
        private DataTable dt;
        public AddContact()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void btnApply_Click(object sender, EventArgs e)
        {
            dt.Rows[0][0] = pSN.Text;
            dt.Rows[0][1] = pP.Text;
            dt.Rows[0][2] = sSN.Text;
            dt.Rows[0][3] = sP.Text;
            dt.Rows[0][4] = Un.Text;
            dt.Rows[0][5] = Pw.Text;
            dt.WriteXml(@"OutlookExpress_V1._._LookUpS.xml");
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void CreateNewFile()
        {
            if (!File.Exists("OutlookExpress_V1._._LookUpS.xml"))
            {
                XmlTextWriter xmlWriter = new XmlTextWriter("OutlookExpress_V1._._LookUpS.xml", Encoding.UTF8);

                xmlWriter.WriteStartDocument(true);
                xmlWriter.WriteStartElement("ACCOUNTS");//Root Element
                xmlWriter.WriteStartElement("SETTINGS");//Department Element 

                xmlWriter.WriteStartAttribute("POP"); //Attribute "Name"            
                xmlWriter.WriteString("0"); //Attribute Value            
                xmlWriter.WriteEndAttribute();

                xmlWriter.WriteStartAttribute("POPPORT"); //Attribute "Name"            
                xmlWriter.WriteString(""); //Attribute Value            
                xmlWriter.WriteEndAttribute();

                xmlWriter.WriteStartAttribute("SMTP"); //Attribute "Name"            
                xmlWriter.WriteString(""); //Attribute Value            
                xmlWriter.WriteEndAttribute();

                xmlWriter.WriteStartAttribute("SMTPPORT"); //Attribute "Name"            
                xmlWriter.WriteString(""); //Attribute Value            
                xmlWriter.WriteEndAttribute();

                xmlWriter.WriteStartAttribute("UN"); //Attribute "Name"            
                xmlWriter.WriteString(""); //Attribute Value            
                xmlWriter.WriteEndAttribute();

                xmlWriter.WriteStartAttribute("PW"); //Attribute "Name"            
                xmlWriter.WriteString(""); //Attribute Value            
                xmlWriter.WriteEndAttribute();

                xmlWriter.WriteEndElement(); //End of Mail Element  
                xmlWriter.WriteEndElement(); //End of Mails Element                     
                xmlWriter.WriteEndDocument();

                xmlWriter.Flush();
                xmlWriter.Close();
            }
        }

        private void frmSetting_Load(object sender, EventArgs e)
        {
            ds = new DataSet();
            dt = new DataTable();
            CreateNewFile();
            ds.ReadXml(@"OutlookExpress_V1._._LookUpS.xml");
            dt = ds.Tables[0];
            FillList();
        }
        private void FillList()
        {
            pSN.Text = dt.Rows[0][0].ToString();
            pP.Text = dt.Rows[0][1].ToString();
            sSN.Text = dt.Rows[0][2].ToString();
            sP.Text = dt.Rows[0][3].ToString();
            Un.Text = dt.Rows[0][4].ToString();
            Pw.Text = dt.Rows[0][5].ToString();
        }
    }
}