using Ini;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Windows.Forms;

namespace hKursu
{
    public partial class frmAna : Form
    {

        private hLabel wrappingLabel;
        public String Resim, Toplanti, Onceki, FontName;
        public int Boyut,Mon,Golge, Baslangic, Hizalama, Efekt;
        public uint MonID = 0;
        public String Katilimci01, Katilimci02, Katilimci03, Katilimci04, Katilimci05, Katilimci06, Katilimci07, Katilimci08, Katilimci09, Katilimci10, Katilimci11, Katilimci12, Katilimci13, Katilimci14, Katilimci15;

        public frmAna()
        {
            InitializeComponent();
            Oku();
            Ciz();
        }

        private void frmAna_Load(object sender, EventArgs e)
        {
            //Oku();
        }

        private void frmAna_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 27) { Application.Exit();};
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Oku();
            Ciz();
        }

        private void frmAna_Paint(object sender, PaintEventArgs e)
        {
            //RenderDropshadowText(e.Graphics,label1.Text, label1.Font, Color.DarkSlateBlue, Color.DarkGray, 90, new PointF(125, 125));

        }

        private void hLabel1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 27) { Application.Exit(); }
         
        }

        private void Ciz()
        {
            //label1.TextAlign = ContentAlignment.
            label1.Font = new Font(FontName , Boyut, FontStyle.Bold);
            //label1.Font = new Font("Microsoft PhagsPa", Boyut, FontStyle.Bold);
            label2.Font = label1.Font;

            label1.Text = Toplanti + Katilimci01 + Katilimci02 + Katilimci03 + Katilimci04 + Katilimci05 + Katilimci06 + Katilimci07 + Katilimci08 + Katilimci09 + Katilimci10;
            label2.Text = label1.Text;
            hLabel1.Text = label1.Text;
            hLabel1.Font = label1.Font;
            //hLabel1.Dock = DockStyle.Fill;

            hLabel1.ShadowOffset = 0;
            //hLabel1.DrawOutline = true;
            //hLabel1.OutlineColor = Color.White;
            //hLabel1.OutlineWidth = 2;//3.0f;

            //hLabel.Effect = hLabel.TextEffect.Bevel;

            hLabel1.ForeColor = Color.Black;
            hLabel1.Effect = hLabel.TextEffect.None;

            switch (Efekt)
            {
                case 1:
                    hLabel1.Effect = hLabel.TextEffect.None;
                    hLabel1.DrawOutline = false;
                    hLabel1.ShadowOffset = Golge;
                    hLabel1.ShadowColor = Color.Gray;
                    break;
                case 2:
                    hLabel1.Effect = hLabel.TextEffect.Emboss;
                    hLabel1.DrawOutline = false;
                    hLabel1.ShadowOffset = Golge;
                    hLabel1.ShadowColor = Color.Gray;
                    break;
                case 3:
                    hLabel1.Effect = hLabel.TextEffect.Bevel;
                    hLabel1.DrawOutline = false;
                    hLabel1.ShadowOffset = Golge;
                    hLabel1.ShadowColor = Color.Gray;
                    hLabel1.BevelHighlight = Color.White;
                    hLabel1.BevelShadow = Color.DarkGray;
                    hLabel1.BevelDepth = Golge;
                    hLabel1.Effect = hLabel.TextEffect.Bevel;
                    break;
                case 4:
                    hLabel1.Effect = hLabel.TextEffect.Engrave;
                    hLabel1.DrawOutline = false;
                    hLabel1.ShadowOffset = 0;
                    hLabel1.ShadowColor = Color.Gray;
                    break;
                case 5:
                    hLabel1.Effect = hLabel.TextEffect.None;
                    hLabel1.DrawOutline = true;
                    hLabel1.OutlineColor = Color.White;
                    hLabel1.OutlineWidth = Golge; //4.0f;
                    hLabel1.ShadowOffset = 0;
                    hLabel1.ShadowColor = Color.Gray;
                    break;
            }


            switch (Hizalama)
            {
                case 1:
                    hLabel1.TextAlign = ContentAlignment.TopLeft;
                    break;
                case 2:
                    hLabel1.TextAlign = ContentAlignment.TopCenter;
                    break;
                case 3:
                    hLabel1.TextAlign = ContentAlignment.TopRight;
                    break;
                case 4:
                    hLabel1.TextAlign = ContentAlignment.MiddleLeft;
                    break;
                case 5:
                    hLabel1.TextAlign = ContentAlignment.MiddleCenter;
                    break;
                case 6:
                    hLabel1.TextAlign = ContentAlignment.MiddleRight;
                    break;
                case 7:
                    hLabel1.TextAlign = ContentAlignment.BottomLeft;
                    break;
                case 8:
                    hLabel1.TextAlign = ContentAlignment.BottomCenter;
                    break;
                case 9:
                    hLabel1.TextAlign = ContentAlignment.BottomRight;
                    break;
                default:
                    hLabel1.TextAlign = ContentAlignment.TopLeft;
                    break;
            }
            //hLabel1.TextAlign = Hizalama;

            hLabel1.AutoSize = false;
            hLabel1.MaxWidth = this.Width;
            hLabel1.MaximumSize = new Size(this.Width, this.Height);
            hLabel1.Height = this.Height - Baslangic;
            hLabel1.Width = this.Width;
            hLabel1.Location = new Point(0, Baslangic);

            //hLabel1.AutoSize = true;
            //hLabel1.Top = Baslangic;
            //hLabel1.Padding = new Padding(10, Baslangic, 10, 10);
            //hLabel1.Margin = new Padding(10, Baslangic, 10, 10);

            if (Resim != Onceki)
            {
                Image bgimage = new Bitmap(@Resim);
                this.BackgroundImage = bgimage;
                Onceki = Resim;
            }
        }

        private void Oku() {

            string curFile = @Application.StartupPath + "\\ayarlar.ini";
            //if (File.Exists(curFile) { }

            IniFile ini = new IniFile( Application.StartupPath + "\\ayarlar.ini");
            
           
            if (Resim is null) { Resim = ini.IniReadValue("Ayarlar", "Resim"); }

            Resim = Kontrol(ini.IniReadValue("Ayarlar", "Resim"));
            Hizalama = Convert.ToInt16(Kontrol(ini.IniReadValue("Ayarlar","Hizalama")));
            FontName = Kontrol(ini.IniReadValue("Ayarlar", "Font"));
            Boyut = Convert.ToInt16(Kontrol(ini.IniReadValue("Ayarlar", "Boyut")));
            //MonID = Convert.ToUInt16(ini.IniReadValue("Ayarlar", "Monitor"));
            //Monitor.SetAsPrimaryMonitor(MonID);
            Efekt = Convert.ToInt16(Kontrol(ini.IniReadValue("Ayarlar", "Efekt")));
            Mon = Convert.ToInt16(Kontrol(ini.IniReadValue("Ayarlar", "Monitor")));
            Baslangic = Convert.ToInt16(Kontrol(ini.IniReadValue("Ayarlar", "Baslangic")));
            Golge = Convert.ToInt16(Kontrol(ini.IniReadValue("Ayarlar", "Golge")));

            var secondScreen = Screen.AllScreens[Mon];
            this.StartPosition = FormStartPosition.Manual;
            this.Location = secondScreen.Bounds.Location;
            this.Size = secondScreen.Bounds.Size;
            this.FormBorderStyle = FormBorderStyle.None;
            this.WindowState = FormWindowState.Maximized;


            Toplanti = Kontrol(ini.IniReadValue("Toplanti","ToplantiAdi"));

            Katilimci01 = Kontrol(ini.IniReadValue("Toplanti", "Katilimci01"));
            Katilimci02 = Kontrol(ini.IniReadValue("Toplanti", "Katilimci02"));
            Katilimci03 = Kontrol(ini.IniReadValue("Toplanti", "Katilimci03"));
            Katilimci04 = Kontrol(ini.IniReadValue("Toplanti", "Katilimci04"));
            Katilimci05 = Kontrol(ini.IniReadValue("Toplanti", "Katilimci05"));
            Katilimci06 = Kontrol(ini.IniReadValue("Toplanti", "Katilimci06"));
            Katilimci07 = Kontrol(ini.IniReadValue("Toplanti", "Katilimci07"));
            Katilimci08 = Kontrol(ini.IniReadValue("Toplanti", "Katilimci08"));
            Katilimci09 = Kontrol(ini.IniReadValue("Toplanti", "Katilimci09"));
            Katilimci10 = Kontrol(ini.IniReadValue("Toplanti", "Katilimci10"));

            if (Katilimci01 != "") { Katilimci01 = "\r\n" + Katilimci01; }
            if (Katilimci02 != "") { Katilimci02 = "\r\n" + Katilimci02; }
            if (Katilimci03 != "") { Katilimci03 = "\r\n" + Katilimci03; }
            if (Katilimci04 != "") { Katilimci04 = "\r\n" + Katilimci04; }
            if (Katilimci05 != "") { Katilimci05 = "\r\n" + Katilimci05; }
            if (Katilimci06 != "") { Katilimci06 = "\r\n" + Katilimci06; }
            if (Katilimci07 != "") { Katilimci07 = "\r\n" + Katilimci07; }
            if (Katilimci08 != "") { Katilimci08 = "\r\n" + Katilimci08; }
            if (Katilimci09 != "") { Katilimci09 = "\r\n" + Katilimci09; }
            if (Katilimci10 != "") { Katilimci10 = "\r\n" + Katilimci10; }

        }

        private string Kontrol(string gelen)
        {
            int k = gelen.IndexOf(";");
            if (k>0) gelen = gelen.Substring(0, k-1);

            if (gelen == null) { gelen = ""; }
            gelen = gelen.Replace("\\n", Environment.NewLine);
            gelen = gelen.Replace("\\N", Environment.NewLine);
            gelen = gelen.Replace("\t", "");
            //gelen = gelen.Replace("\\r", Environment. );
            return gelen;
        }   

        private void frmAna_DoubleClick(object sender, EventArgs e)
        {
            Application.Exit();
        }

    }
}
