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

namespace RegistrationAPI_Tester
{
    
    public partial class ChangeRegServerModalForm : Form
    {
        private static string s_url = "services.ndchealthvar.com";

        public ChangeRegServerModalForm()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(textHost.Text) ||
                String.IsNullOrEmpty(textPort.Text))
            {
                MessageBox.Show("Host and Port can not be empty");
                return;
            }
            
            uint nPort = 0;
            if (!uint.TryParse(textPort.Text, out nPort) && nPort > 0)
            {
                MessageBox.Show("Port is invalid");
                return;
            }

            s_url = textHost.Text;
            RegistrationAPI.API.SetNetworkSettings(textHost.Text, nPort);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void ChangeRegServerModalForm_Load(object sender, EventArgs e)
        {
            textHost.Text = s_url;
        }
    }
}
