FrmErrorMsg.cs 3.63 KB
/// ----------------------------------------------------------------
/// 文 件 名:FrmErrorMsg.cs
/// 功能描述:系统错误日志类
/// 
/// 创建:杨斌 2011-11-29
/// 修改:杨斌 2013-09-02
/// ----------------------------------------------------------------
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 GeneralLib;
using System.Diagnostics;
using System.IO;
using SunVoteARSPPT;

namespace GeneralLib
{
    public partial class FrmErrorMsg : Form
    {
        public FrmErrorMsg(Exception ex, string logPath, string msg = "")
        {
            try
            {
                InitializeComponent();

                string title = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name
                        + " " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

                string logInfo = DateTime.Now.ToString() + "\r\n" + title + "\r\n" + ex.ToString();
                if (!string.IsNullOrEmpty(msg))
                    logInfo += msg;

                this.Text = title;
                txtDetail.Text = logInfo;
                LogPath = logPath;

                btnShowLog.Visible = File.Exists(LogPath);

                strBtnShowDetal0 = GlobalInfo.SysLanguage.LPT.ReadString("FrmErrorMsg", "btnShowDetail", "点击此处查看详细信息↓");
                strBtnShowDetal1 = GlobalInfo.SysLanguage.LPT.ReadString("FrmErrorMsg", "btnShowDetail_1", "收起详细信息↑");

                GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
            }
            catch (Exception exx)
            {
                MessageBox.Show(exx.ToString());
            }
        }

        private string strBtnShowDetal0 = "";
        private string strBtnShowDetal1 = "";

        public string LogPath = "";

        private void FrmErrorMsg_Load(object sender, EventArgs e)
        {
            ShowDetail = false;
            ShowDetail = true;//杨斌 2019-06-13。默认展开。之前他们评审默认隐藏,结果每次报错截图有个屁用,真™坑

            //杨斌 2014-06-16
            this.Text += "  " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + "  " + FrmAboutPowerVote.GetVersionInfo();
        }

        private void btnShowDetail_Click(object sender, EventArgs e)
        {
            ShowDetail = !ShowDetail;
        }

        private bool mShowDetail = false;
        private bool ShowDetail
        {
            get { return mShowDetail; }
            set
            {
                mShowDetail = value;
                if (value)
                {
                    this.Height = pnlDetail.Bottom + (int)(btnShowDetail.Height*1.5f);//杨斌 2016-03-01
                    pnlDetail.Visible = true;
                    btnShowDetail.Text = strBtnShowDetal1;
                }
                else
                {
                    this.Height = pnlDetail.Top + (int)(btnShowDetail.Height * 1.5f);//杨斌 2016-03-01
                    pnlDetail.Visible = false;
                    btnShowDetail.Text = strBtnShowDetal0;
                }
            }
        }

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

        private void btnShowLog_Click(object sender, EventArgs e)
        {
            if (!File.Exists(LogPath)) return;
            Process open = new Process();
            open.StartInfo.FileName = "explorer";
            open.StartInfo.Arguments = @"/select," + LogPath;
            open.Start();

        }
    }
}