FrmSetDB.cs 2.7 KB
using GeneralLib;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

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

        private void FrmSetDB_Load(object sender, EventArgs e)
        {
            LoadSet();
        }

        private void LoadSet()
        {
            string name = GlobalInfo.DBName;
            int i = name.IndexOf('[');
            if (i >= 0)
                name = name.Substring(0, i);
            if (name.Length > 4)
                if (name.ToLower().Substring(name.Length - 4) == ".mdb")
                    name = name.Substring(0, name.Length - 4);
            this.txtDBName.Text = name;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtDBName.TextLength < 1)
            {
                this.Close();
                return;
            }
            try
            {
                Microsoft.Office.Interop.PowerPoint.Presentation pres = Globals.SunVoteARSAddIn.Application.ActivePresentation;

                if (pres == null)
                {
                    this.Close();
                    return;
                }

                GlobalInfo.DBOperation.CloseConn();
                string file = GlobalInfo.DB_PATH + GlobalInfo.DBName;
                FileInfo f = new FileInfo(file);
                string fNew = GlobalInfo.GetNewDBName(pres, txtDBName.Text);
                file = GlobalInfo.DB_PATH + fNew;
                f.MoveTo(file);

                TagSet tagSet = new TagSet(pres.Tags);
                tagSet.SetValue(TagKey.PPT_DBName, fNew);

                GlobalInfo.DBName = fNew;

                //杨斌 2018-06-28
                GlobalInfo.DBOperation.InitConnStrAccess(GlobalInfo.DB_PATH + GlobalInfo.DBName, "");
                GlobalInfo.DBOperation.OpenConn();

                this.Close();
            }
            catch (Exception ex)
            {
                SystemLog.WriterLog(ex);
            }
        }

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

        private void txtDBName_KeyPress(object sender, KeyPressEventArgs e)
        {
            switch (e.KeyChar)
            {
                case '[':
                case ']':
                    e.Handled = true;
                    break;
            }
        }

        private void txtDBName_TextChanged(object sender, EventArgs e)
        {
            btnOK.Enabled = (txtDBName.TextLength > 0);
        }
    }
}