using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ExWeb
{
    public partial class Mod : System.Web.UI.UserControl
    {
        public static string RelPathToMod = "/Mod/";
        public static string RelPathToMod_Test = "/Mod_Test/";
        public static string Help_Description = "Für alle Module verwendbare Attribute";
        public static string[][] Help_Attributes = new string[][]
        {
            // Attribut, Wert, DefaultWert, Optional, Hilfe
            new string[] {"ID","string","","opt","Eindeutige Kennzeichnung des Moduls","Id=\"Mod_Image_1\""},
            new string[] {"Visible","true false","true","opt","Modul kann versteckt werden, ohne den Kode zu löschen","Visible=\"false\""},
            new string[] {"Cap","string","","opt","Titel des Objekts","Caption=\"MeinTitel\""},
            new string[] {"ToolTip","string","","opt","Erklärender Text bei Maubewegung","ToolTip=\"Erklärender Text\""},
            new string[] {"Target","_top _self _blank","_self","opt","Zielframe bei Links","Target=\"_top\""},
            new string[] {"Width","int","","opt","Breite des Objekts","Width=\"600\""},
            new string[] {"Height","int","","opt","Höhe des Objekts","Height=\"400\""},
            new string[] {"BackColor","color","transparent","opt","Hintergrundfarbe","BackColor=\"green\""},
            new string[] {"BorderColor","color","transparent","opt","Rahmenfarbe","BorderColor=\"yellow\""},
            new string[] {"ForeColor","color","transparent","opt","Vordergrundfarbe","ForeColor=\"lightblue\""},
            new string[] {"BorderStyle","dashed dotted double groove inset none notset outset ridge solid","none","opt","Rahmenart","BorderStyle=\"solid\""},
            new string[] {"HorizontalAlignMod","center justify left notset right","","opt","Ausrichtung horizontal","HorizontalAlignMod=\"right\""},
            new string[] {"ScrollBars","auto both horizontal none vertical","","opt","Laufleisten","ScrollBars=\"both\""},
            new string[] {"Wrap","0 1","0","opt","Textumbruch erzwingen","Wrap=\"1\""},
            new string[] {"FontName","font","","opt","Schriftart","FontName=\"Verdana\""},
            new string[] {"FontSize","int","","opt","Schriftgröße","FontSize=\"14\""},
            new string[] {"FontBold","0 1","0","opt","Fett","FontBold=\"1\""},
            new string[] {"FontItalic","0 1","0","opt","Schräg","FontItalic=\"1\""},
            new string[] {"FontOverline","0 1","0","opt","Übertreichen","FontOverline=\"1\""},
            new string[] {"FontUnterline","0 1","0","opt","Unterstreichen","FontUnterline=\"1\""},
            new string[] {"FontStrikeout","0 1","0","opt","Durchstreichen","FontStrikeout=\"1\""},
            new string[] {"Overflow","auto hidden inherit initial no-content no-display scroll visible","auto","opt","Laufleisten","Overflow=\"scroll\""},
            new string[] {"Authorize","0 1","0","opt","Passwortschutz aktivieren","Authorize=\"1\""},
            new string[] {"Password","string","","opt","Passwort","Password=\"MyPassword\""},
        };
        protected string _ID = "";
        public string ID
        {
            set
            {
                _ID = value;
            }
            get
            {
                return _ID;
            }
        }
        protected string _Cap = "";
        public string Cap
        {
            set
            {
                _Cap = value;
            }
        }
        protected string _ToolTip = "";
        public string ToolTip
        {
            set
            {
                _ToolTip = value;
            }
        }
        protected string _Target = "_self";
        public string Target
        {
            set
            {
                _Target = value.ToLower(); ;
            }
            get
            {
                return _Target;
            }
        }
        protected int _Width = -1;
        public string Width
        {
            set
            {
                int.TryParse(value, out _Width);
            }
            get
            {
                return _Width.ToString();
            }
        }
        protected int _Height = -1;
        public string Height
        {
            set
            {
                int.TryParse(value, out _Height);
            }
            get
            {
                return _Height.ToString();
            }
        }
        protected System.Drawing.Color _BackColor = System.Drawing.Color.Transparent;
        public string BackColor
        {
            set
            {
                _BackColor = System.Drawing.Color.FromName(value);
            }
        }
        protected System.Drawing.Color _BorderColor = System.Drawing.Color.Transparent;
        public string BorderColor
        {
            set
            {
                _BorderColor = System.Drawing.Color.FromName(value);
            }
        }
        protected System.Drawing.Color _ForeColor = System.Drawing.Color.Transparent;
        public string ForeColor
        {
            set
            {
                _ForeColor = System.Drawing.Color.FromName(value);
            }
        }
        protected System.Web.UI.WebControls.BorderStyle _BorderStyle = System.Web.UI.WebControls.BorderStyle.None;
        public string BorderStyle
        {
            set
            {
                switch (value.ToLower())
                {
                    default:
                    case "":
                        break;
                    case "dashed":
                        _BorderStyle = System.Web.UI.WebControls.BorderStyle.Dashed;
                        break;
                    case "dotted":
                        _BorderStyle = System.Web.UI.WebControls.BorderStyle.Dotted;
                        break;
                    case "double":
                        _BorderStyle = System.Web.UI.WebControls.BorderStyle.Double;
                        break;
                    case "groove":
                        _BorderStyle = System.Web.UI.WebControls.BorderStyle.Groove;
                        break;
                    case "inset":
                        _BorderStyle = System.Web.UI.WebControls.BorderStyle.Inset;
                        break;
                    case "none":
                        _BorderStyle = System.Web.UI.WebControls.BorderStyle.None;
                        break;
                    case "notset":
                        _BorderStyle = System.Web.UI.WebControls.BorderStyle.NotSet;
                        break;
                    case "outset":
                        _BorderStyle = System.Web.UI.WebControls.BorderStyle.Outset;
                        break;
                    case "ridge":
                        _BorderStyle = System.Web.UI.WebControls.BorderStyle.Ridge;
                        break;
                    case "solid":
                        _BorderStyle = System.Web.UI.WebControls.BorderStyle.Solid;
                        break;
                }
            }
        }
        protected int _BorderWidth = -1;
        public string BorderWidth
        {
            set
            {
                int.TryParse(value, out _BorderWidth);
            }
        }
        protected HorizontalAlign _HorizontalAlign = 0;
        public string HorizontalAlign
        {
            set
            {
                switch (value.ToLower())
                {
                    default:
                    case "":
                        break;
                    case "center":
                        _HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                        break;
                    case "justify":
                        _HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Justify;
                        break;
                    case "left":
                        _HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
                        break;
                    case "notset":
                        _HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.NotSet;
                        break;
                    case "right":
                        _HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Right;
                        break;
                }
            }
        }
        protected ScrollBars _ScrollBars = 0;
        public string ScrollBars
        {
            set
            {
                switch (value.ToLower())
                {
                    default:
                    case "":
                        break;
                    case "auto":
                        _ScrollBars = System.Web.UI.WebControls.ScrollBars.Auto;
                        break;
                    case "both":
                        _ScrollBars = System.Web.UI.WebControls.ScrollBars.Both;
                        break;
                    case "horizontal":
                        _ScrollBars = System.Web.UI.WebControls.ScrollBars.Horizontal;
                        break;
                    case "none":
                        _ScrollBars = System.Web.UI.WebControls.ScrollBars.None;
                        break;
                    case "vertical":
                        _ScrollBars = System.Web.UI.WebControls.ScrollBars.Vertical;
                        break;
                }
            }
        }
        protected bool _Wrap = false;
        public string Wrap
        {
            set
            {
                _Wrap = (value == "1");
            }
        }
        protected string _FontName = "";
        public string FontName
        {
            set
            {
                _FontName = value;
            }
        }
        protected int _FontSize = -1;
        public string FontSize
        {
            set
            {
                int.TryParse(value, out _FontSize);
            }
        }
        protected bool _FontBold = false;
        public string FontBold
        {
            set
            {
                _FontBold = (value == "1");
            }
        }
        protected bool _FontItalic = false;
        public string FontItalic
        {
            set
            {
                _FontItalic = (value == "1");
            }
        }
        protected bool _FontStrikeout = false;
        public string FontStrikeout
        {
            set
            {
                _FontStrikeout = (value == "1");
            }
        }
        protected bool _FontOverline = false;
        public string FontOverline
        {
            set
            {
                _FontOverline = (value == "1");
            }
        }
        protected bool _FontUnderline = false;
        public string FontUnderline
        {
            set
            {
                _FontUnderline = (value == "1");
            }
        }
        protected string _Overflow = "auto";
        public string Overflow
        {
            set
            {
                switch (value.ToLower())
                {
                    default:
                        break;
                    case "auto":
                    case "hidden":
                    case "inherit":
                    case "initial":
                    case "no-content":
                    case "no-display":
                    case "scroll":
                    case "visible":
                        _Overflow = value;
                        break;
                }
            }
        }
        protected bool _Authorize = false;
        public string Authorize
        {
            set
            {
                _Authorize = (value == "1");
            }
        }
        private string _Password = "";
        public string Password
        {
            set
            {
                _Password = value;
            }
            get
            {
                return _Password;
            }
        }
        // true: Panel can be used as usual
        // false: Panel is Password protected and is invisible
        protected bool SetPanelLayout(ControlCollection controls)
        {
            Mod_Password pass = null;
            Panel p = null;
            for (int i = 0; i < controls.Count; i++)
            {
                Control c = controls[i];
                string ControlName = c.GetType().ToString().ToLower();
                if (ControlName.Contains("panel"))
                    p = (Panel)c;
                if (ControlName.Contains("mod_password"))
                    pass = (Mod_Password)c;
                if ((p != null) && (pass != null))
                    break;
            }
            if (p == null) 
            {
//                Response.Write("Panel not found");
                return false;
            }
            if (pass == null)
            {
//                Response.Write("Mod_Pass not found");
                return false;
            }
            if (_Cap != "") p.GroupingText = _Cap;
            if (_ToolTip != "") p.ToolTip = _ToolTip;
            if (_Width > -1) p.Width = _Width;
            if (_Height > -1) p.Height = _Height;
            if (_BackColor != System.Drawing.Color.Transparent) p.BackColor = _BackColor;
            if (_ForeColor != System.Drawing.Color.Transparent) p.ForeColor = _ForeColor;
            if (_BorderColor != System.Drawing.Color.Transparent) p.BorderColor = _BorderColor;
            if (_BorderStyle != System.Web.UI.WebControls.BorderStyle.None) p.BorderStyle = _BorderStyle;
            if (_BorderWidth > -1) p.BorderWidth = _BorderWidth;
            if (_HorizontalAlign != 0) p.HorizontalAlign = _HorizontalAlign;
            if (_ScrollBars != 0) p.ScrollBars = _ScrollBars;
            p.Wrap = _Wrap;
            if (_FontName != "") p.Font.Name = _FontName;
            if (_FontSize > -1) p.Font.Size = _FontSize;
            p.Font.Bold = _FontBold;
            p.Font.Italic = _FontItalic;
            p.Font.Overline = _FontOverline;
            p.Font.Strikeout = _FontStrikeout;
            p.Font.Underline = _FontUnderline;
            p.Style.Add("overflow", _Overflow);
            if (_Authorize)
            {
                if (pass.Authorized)
                {
                    pass.Visible = false;
                    p.Visible = true;
                    return true;
                }
                else
                {
                    pass.Visible = true;
                    p.Visible = false;
                    return false;
                }
            }
            else
            {
                pass.Visible = false;
                p.Visible = true;
                return true;
            }
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            Width = Mod.GetQs_String("width", _Width.ToString(), this.Page);
            Height = Mod.GetQs_String("height", _Height.ToString(), this.Page);
            Cap = Mod.GetQs_String("cap", _Cap, this.Page);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
        }
    }
}