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;

namespace Engineer.Forms
{
    public partial class TipsDisplay : Form
    {
        private const string tipFile = "Tips.txt";
        private List<string> tips;
        private int currentTip;

        public TipsDisplay()
        {
            InitializeComponent();

            FileInfo fi = new FileInfo(Application.StartupPath + "\\" + tipFile);
            if (fi.Exists == false)
            {
                lblTip.Text = "Error: no tip file was found";
                return;
            }

            StreamReader sr = new StreamReader(fi.OpenRead());

            string tip = null;
            tips = new List<string>();

            while ((tip = sr.ReadLine()) != null)
            {
                tips.Add(tip);
            }


            sr.Close();
 
            currentTip = 0;
            ShowNextTip();
        }

        private void ShowNextTip()
        {
            Random RND = new Random();

            currentTip = RND.Next(tips.Count);

            lblTip.Text = tips[currentTip];
        }

        private void btnNextTip_Click(object sender, EventArgs e)
        {
            ShowNextTip();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            AppSettings.Settings.ShowTipsAtStartup = !AppSettings.Settings.ShowTipsAtStartup;
            AppSettings.SaveSettings();
        }
    }
}
