FrmAboutAny.cs 6.42 KB
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;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Management;
using GeneralLib;
using System.Reflection;
using System.IO;

namespace SunVoteARSPPT
{
    public partial class FrmAboutAny : Form
    {
        public FrmAboutAny()
        {
            InitializeComponent();

            string bitInfo = "_32bit";//默认32位
            string proInfo = Assembly.GetExecutingAssembly().GetName().ProcessorArchitecture.ToString();
            if (proInfo.IndexOf("64") >= 0)
            {
                bitInfo = "_64bit";
            }
            else if (proInfo == "MSIL")
            {
                if (GetOSBit() == 64)
                {
                    bool retVal = false;
                    IsWow64Process(Process.GetCurrentProcess().Handle, out retVal);
                    if (!retVal)
                        bitInfo = "_64bit";
                }
            }

            //加载OEM信息
            AppInfo info = new AppInfo();
            if (!Directory.Exists(GlobalInfo.OEMInfoDir))
                Directory.CreateDirectory(GlobalInfo.OEMInfoDir);
            string path = GlobalInfo.OEMInfoFile;
            if (File.Exists(path))
            {
                info = MyXmlSerializer.DisSerializerFromFile<AppInfo>(path);
            }
            //自动创建   
            if (info == null)
            {
                info = new AppInfo();
            }
            if ((info.ListInfoItem == null) || (info.ListInfoItem.Count < 1))
            {
                info.ListInfoItem = new List<InfoItem>();
                info.ListInfoItem.Add(new InfoItem() { Name = "Support Tel:", Value = "+86-18908457700" });
                info.ListInfoItem.Add(new InfoItem() { Name = "Website:", Value = "http://www.psunsky.com.cn/", Type = 1 });
                info.ListInfoItem.Add(new InfoItem() { Name = "Mailbox:", Value = "support@sunvote.com.cn", Type = 2 });

            }
            MyXmlSerializer.SerializerToFile(info, path);

            //加载Logo图标
            string pathLogo = GlobalInfo.OEMInfoDir + info.AppLogo;
            if (File.Exists(pathLogo))
                picLogo.Image = Image.FromFile(pathLogo);
            //显示App Name软件名称
            lblSysSoftName.Text = info.AppName;
            //版本信息+自定义行数
            pnlParam.RowCount = 1 + info.ListInfoItem.Count;
            pnlParam.Height = pnlParam.RowCount * 25;
            this.Height = pnlParam.Bottom + 60;
            for (int i = 0; i < pnlParam.RowStyles.Count; i++)
                pnlParam.RowStyles[i] = new RowStyle(SizeType.Percent, 100);
            for (int i = pnlParam.RowStyles.Count; i < pnlParam.RowCount; i++)
                pnlParam.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
            //版本信息
            lblVer.Text = "Version:";
            ////bitInfo += GlobalInfo.VerInfo;//Alpha/Beta
            lblVerNoInfo.Text = "V " + Assembly.GetExecutingAssembly().GetName().Version.ToString() + bitInfo;
            //其他信息
            for (int i = 0; i < info.ListInfoItem.Count; i++)
            {
                int row = i + 1; 

                 Label lab = new Label();
                pnlParam.Controls.Add(lab, 0, row);
                lab.Margin = new Padding(3, 3, 3, 3);
                lab.AutoSize = true;
                lab.Dock = DockStyle.Fill;
                lab.TextAlign = ContentAlignment.MiddleRight;
                lab.Text = info.ListInfoItem[i].Name;//属性名称
                lab.Visible = true;

                Label lab2 = new Label();
                pnlParam.Controls.Add(lab2, 1, row);
                lab2.Margin = new Padding(3, 3, 3, 3);
                lab2.AutoSize = true;
                lab2.Dock = DockStyle.Fill;
                lab2.TextAlign = ContentAlignment.MiddleLeft;
                lab2.Text = info.ListInfoItem[i].Value;//属性内容
                lab2.Tag = info.ListInfoItem[i].Type;//属性类型
                if (info.ListInfoItem[i].Type > 0)
                    lab2.ForeColor = Color.Blue;
                lab2.Visible = true;
                lab2.Click += Lab2_Click;
            }
        }

        private void FrmAboutAny_Load(object sender, EventArgs e)
        {

        }

        private void Lab2_Click(object sender, EventArgs e)
        {
            Label lab = sender as Label;
            int proType = ConvertOper.Convert(lab.Tag + "").ToInt;
            if (proType > 0)
                OpenLink(lab.Text, proType == 2);
        }

        public static int GetOSBit()
        {
            try
            {
                //杨斌 2015-03-17
                int bit = 32;
                if (Environment.Is64BitOperatingSystem)
                    bit = 64;
                return bit;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return 32;
            }
        }

        [DllImport("kernel32.dll")]
        public static extern bool IsWow64Process([In] IntPtr hProcess, [Out] out bool lpSystemInfo);

        private void FrmAboutUs_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)//杨斌 2012-03-13
                this.Close();
        }

        void OpenLink(string link, bool isMail = false)
        {
            if (isMail)
                Process.Start("mailto:" + link);
            else
                Process.Start(link);
        }

    }

    public class AppInfo
    {
        public string AppName = "ARS PPT";
        public string AppLogo = "Logo.png";
        public List<InfoItem> ListInfoItem = new List<InfoItem>();
    }

    /// <summary>
    /// OEM信息,包括:编译工程名称(System.ini的SoftInfo),关于xml指定,关于Logo图片xml指定
    /// 帮助关联文件夹
    /// ARS和ToolKit名称,ARS和ToolKit快捷方式图标,默认中性图标
    /// 特殊定制键盘型号名称和图片
    /// </summary>
    public class InfoItem
    {
        /// <summary>
        /// 类型:0=普通文本,1=链接,2=邮箱
        /// </summary>
        public int Type = 0;
        /// <summary>
        /// 属性名称
        /// </summary>
        public string Name = "";
        /// <summary>
        /// 属性值
        /// </summary>
        public string Value = "";
    }
}