using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Resources;
using System.Text;
using System.Windows.Forms;
using System.Collections;namespace Jayn.BaseParent
{
    public class Parent:Form
    {
        /// <summary>
        /// 系统名称
        /// </summary>
        private static string  title="资产管理系统";
        /// <summary>
        /// 窗口宽度
        /// </summary>
        private int _width=0;
        /// <summary>
        /// 窗口高度
        /// </summary>
        private int _height=0;
        /// <summary>
        /// 存放窗口控件
        /// </summary>
        private ArrayList alFormControl = new ArrayList(8);
        /// <summary>
        /// 临时存放窗口控件值
        /// </summary>
        private Bitmap _map;
        /// <summary>
        /// 添加一个控件
        /// </summary>
        /// <param name="FormControlName">控件名称</param>
        /// <param name="FormControlVaue">控件值</param>
        public void addControl(string FormControlName, object FormControlVaue)
        {
            for (int i = 0; i < this.alFormControl.Count; i++)
            {
                if (((FormControl)this.alFormControl[i]).FormControlName == FormControlName)
                {
                    return;
                }
            }
            this.alFormControl.Add(new FormControl(FormControlName, FormControlVaue));
        }        /// <summary>
        /// 获取窗口控件的值
        /// </summary>
        /// <param name="FormControlName">控件名称</param>
        /// <returns>Bitmap</returns>
        public Bitmap getControl(string FormControlName)
        {
            for (int i = 0; i < this.alFormControl.Count; i++)
            {
                if (((FormControl)this.alFormControl[i]).FormControlName == FormControlName)
                {
                    return ((Bitmap)((FormControl)this.alFormControl[i]).FormControlVaue);
                }
            }
            return null;
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        public Parent()
        {
            this._width = Width;
            this._height = Height;
            try
            {
                
                CreateResource cr = new CreateResource();
                cr.Create(); //创建资源文件,如果存在就不创建了
                ResourceReader rr = new ResourceReader(cr.ResourcesName);//获取资源文件名称并读取
                foreach (DictionaryEntry d in rr)
                {
                    addControl(d.Key.ToString(), d.Value);
                }
                rr.Close();               
            }
            catch { }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
           
            DrawTopMiddel(g);
            DrawTopLeft(g);
            DrawTopRight(g);
        }
        /// <summary>
        /// 画左上样式
        /// </summary>
        /// <param name="g"></param>
        private void DrawTopLeft(Graphics g)
        {
            _map = getControl("Top_Left");
            if (_map == null)
            {
                throw new ArgumentException("加载窗口样式失败。");
            }            Brush brush = new TextureBrush(_map, new Rectangle(0, 0, _map.Width, _map.Height));
            g.FillRectangle(brush, 0, 0, _map.Width, _map.Height);        }
        private void DrawTopMiddel(Graphics g)
        {
            _map = getControl("Top_Middle");
            if (_map == null)
            {
                throw new ArgumentException("加载窗口样式失败。");
            }            Brush brush = new TextureBrush(_map, new Rectangle(0, 0, _map.Width, _map.Height));
            g.FillRectangle(brush, 4, 0, Width, _map.Height);        }        private void DrawTopRight(Graphics g)
        {
            _map = getControl("Top_Right");
            if (_map == null)
            {
                throw new ArgumentException("加载窗口样式失败。");
            }            Brush brush = new TextureBrush(_map, new Rectangle(0, 0, _map.Width, _map.Height));
            g.FillRectangle(brush, Width - _map.Width, 0, _map.Width, _map.Height);
            //MessageBox.Show(Width.ToString() + "," + _map.Width);        }        
    }    /// <summary>
    /// 用于保存窗口控件
    /// </summary>
    public class FormControl
    {
        /// <summary>
        /// 控件名称
        /// </summary>
        public string FormControlName;
        /// <summary>
        /// 控件值
        /// </summary>
        public object FormControlVaue;        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="FormControlName">控件名称</param>
        /// <param name="FormControlVaue">控件值</param>
        public FormControl(string FormControlName, object FormControlVaue)
        {
            this.FormControlName = FormControlName;
            this.FormControlVaue = FormControlVaue;
        }
    }
}