Blame view

SunVoteARSPPT/Forms/FrmSetDB.cs 2.7 KB
20c0108c   wutaian   xx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
  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);
          }
      }
  }