Blame view

SunVoteARSPPT/Controls/UcResponsePara.cs 12.6 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
  using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Drawing;
  using System.Data;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using Microsoft.Office.Interop.PowerPoint;
  using GeneralLib;
  using System.IO;
  
  namespace SunVoteARSPPT
  {
      public partial class UcResponsePara : UserControl, IPanel
      {
          public TagSet TagSet { get; set; }
          /// <summary>
          /// 防止设置语言时触发SelectedIndexChanged事件
          /// </summary>
          public bool readOnly = false;
          public UcResponsePara()
          {
              InitializeComponent();
              try
              {
                  FrmSystemSet.LanguageSetEvent += new FrmSystemSet.LanguageSetEventHander(FrmSystemSet_LanguageSetEvent);
                  FrmSystemSet.GlobalSetChangeEvent += new FrmSystemSet.GlobalSetChangeEventHander(FrmSystemSet_GlobalSetChangeEvent);
                  gbxNameAuthorize.Resize += gbxNameAuthorize_Resize;
                  //设置控件大小
                  this.Height = gbxNameAuthorize.Bottom;
                  LoadComboBox();
                  //GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
              }
              catch (Exception ex)
              {
                  SystemLog.WriterLog(ex);
              }
          }
  
          void gbxNameAuthorize_Resize(object sender, EventArgs e)
          {
              int pos = gbxNameAuthorize.ClientSize.Width / 2;
              int w = pos - 3;
              rbtNameModeOff.Left = pos;
              rbtNameModeOff.Width = w;
  
              cboCanVote.Left = pos;
              cboCanVote.Width = w;
  
              cboBackMusic.Left = pos;
              cboBackMusic.Width = w;
  
              cboFieldVoteRate.Left = pos;
              cboFieldVoteRate.Width = w;
          }
  
          void FrmSystemSet_GlobalSetChangeEvent()
          {
              try
              {
                  if (gbxNameAuthorize.Enabled)
                  {
                      rbtNameModeOn.Checked = Convert.ToInt32(TagSet.GetValue(TagKey.ResponsePara_NameMode).Value) == 1;
                      rbtNameModeOff.Checked = Convert.ToInt32(TagSet.GetValue(TagKey.ResponsePara_NameMode).Value) == 0;
                  }
              }
              catch { }
          }
          /// <summary>
          /// 语言设置
          /// </summary>
          void FrmSystemSet_LanguageSetEvent()
          {
              readOnly = true;
              GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
              LoadMusicSet();//杨斌 2015-04-10
              int index = ComboBoxOper.GetIndexByValue(cboCanVote, TagSet.GetValue(TagKey.ResponsePara_CanVote).Value);
              cboCanVote.SelectedIndex = index;
              readOnly = false;
          }
  
          private void UcResponsePara_Load(object sender, EventArgs e)
          {
              if (GlobalInfo.SysLanguage == null) return;
              GlobalInfo.SysLanguage.SetLanguage(this.Name, this);
              LoadMusicSet();//杨斌 2015-04-10
              //设置默认值
              if (cboCanVote.Items.Count > 0)
                  cboCanVote.SelectedIndex = 0;
          }
  
          /// <summary>
          /// 补充从现有词条加载新功能语言。杨斌 2015-05-07
          /// </summary>
          private void LoadMusicSet()
          {
              lblBackMusic.Text = GlobalInfo.SysLanguage.LPT.ReadString("FrmSystemSet", "lvwSound_Item_0", "背景音效");
  
              List<string> lstItem = new List<string>();
              lstItem.Add(GlobalInfo.SysLanguage.LPT.ReadString("FrmSystemSet", "FrmSystemSet", "系统设置"));
  
              string musicFile = "";
              string musicFilePre = "";
              if (TagSet != null)//杨斌 2016-06-07
              {
                  musicFile = TagSet.GetValue(TagKey.ResponsePara_SlideBackMusic).Value;
                  if (string.IsNullOrEmpty(musicFile))
                      musicFilePre = TagSet.GetValue(TagKey.ResponsePara_SlideBackMusicPre).Value;
                  else
                  {
                      if (musicFilePre != musicFile)
                      {
                          musicFilePre = musicFile;
                          TagSet.SetValue(TagKey.ResponsePara_SlideBackMusicPre, musicFilePre);
                      }
                  }
                  if (!string.IsNullOrEmpty(musicFilePre))
                      lstItem.Add(musicFilePre);
              }
  
              lstItem.Add(GlobalInfo.SysLanguage.LPT.ReadString("FrmSystemSet", "btnSoundBrowse", "浏览..."));
  
              cboBackMusic.Enabled = false;
              cboBackMusic.Items.Clear();
  
              foreach (var v in lstItem)
              {
                  cboBackMusic.Items.Add(v);
              }
              if (string.IsNullOrEmpty(musicFile))
                  cboBackMusic.SelectedIndex = 0;
              else
                  cboBackMusic.SelectedIndex = 1;
  
              cboBackMusic.Enabled = true;
  
          }
  
          /// <summary>
          /// 加载参数面板数据
          /// </summary>
          public void LoadData()
          {
              if (TagSet == null) return;
  
              var iniSet = INIControl.GetInstances(GlobalInfo.SYSTEM_CONFIG_PATH);//杨斌 2019-06-12
              int defNameMode = iniSet.ReadInt("VoteSet", "NameMode", 0);//杨斌 2019-06-12
  
              //杨斌 2014-10-27
              cboFieldVoteRate.Items.Clear();
              cboFieldVoteRate.Items.Add("");
              RosterList rost = new RosterList();
              if (rost.RosterEnabled)
              {
                  rost.LoadCloumn(GlobalInfo.DBOperation);
                  for (int i = 1; i < rost.Columns.Count; i++)
                  {
                      cboFieldVoteRate.Items.Add(rost.Columns[i].ColumnName);
                  }
              }
              ComboBoxOper.SetComboText(cboFieldVoteRate, TagSet.GetValue(TagKey.ResponsePara_VoteRateField).Value);
  
              //if (TagSet.LoadValue(TagKey.ResponsePara_NameMode, rbtNameModeOn.Checked ? 1 : 0).ToInt == 1)
              if (TagSet.LoadValue(TagKey.ResponsePara_NameMode, 1 - defNameMode).ToInt == 1)//杨斌 2019-06-12
                  rbtNameModeOn.Checked = true;
              else
                  rbtNameModeOff.Checked = true;
              int index = ComboBoxOper.GetIndexByValue(cboCanVote, TagSet.LoadValue(TagKey.ResponsePara_CanVote, "cvAll").Value);
              cboCanVote.SelectedIndex = index;
              //cboCanVote.SelectedIndex = TagSet.LoadValue(TagKey.ResponsePara_CanVote, 0).ToInt;
  
              //杨斌 2015-04-10
              cboBackMusic.Enabled = false;
              string musicFile = TagSet.GetValue(TagKey.ResponsePara_SlideBackMusic).Value;
              if (!string.IsNullOrEmpty(musicFile))
              {
                  if (cboBackMusic.Items.Count >= 2)
                      cboBackMusic.Items[1] = musicFile;
                  else
                  {
                      if (cboBackMusic.Items.Count < 1)
                          cboBackMusic.Items.Add("");
                      cboBackMusic.Items.Add(musicFile);
                  }
                  cboBackMusic.SelectedIndex = 1;
              }
              else
                  cboBackMusic.SelectedIndex = 0;
              cboBackMusic.Enabled = true;
  
              SetVoteRateEnabled();//杨斌 2014-10-27
          }
  
          /// <summary>
          /// 隐藏投票权重
          /// 杨斌 2014-11-06
          /// </summary>
          //public void HideVoteRate()
          //{
          //    lblFieldVoteRate.Visible = false;
          //    cboFieldVoteRate.Visible = false;
          //    gbxNameAuthorize.Height = cboBackMusic.Bottom + 12;//杨斌 2015-04-10
          //    this.Height = gbxNameAuthorize.Bottom;
          //}
  
          /// <summary>
          /// 显示或隐藏参数。杨斌 2015-04-10
          /// </summary>
          /// <param name="showOther"></param>
          /// <param name="showRate"></param>
          public void ShowSet(bool showOther = true, bool showRate = true)
          {
              rbtNameModeOn.Visible = rbtNameModeOff.Visible = showOther;
              lblAuthorize.Visible = cboCanVote.Visible = showOther;
              lblFieldVoteRate.Visible = cboFieldVoteRate.Visible = showRate;
              if (showOther)
              {
                  cboCanVote.Top = rbtNameModeOff.Bottom + 5;//杨斌 2016-02-03
                  lblAuthorize.Top = cboCanVote.Top + 3;
  
                  cboBackMusic.Top = cboCanVote.Bottom + 5;
                  lblBackMusic.Top = cboBackMusic.Top + 3;
              }
              else
              {
                  cboBackMusic.Top = rbtNameModeOff.Top;
                  lblBackMusic.Top = cboBackMusic.Top + 3;
              }
              if (showRate)
              {
                  cboFieldVoteRate.Top = cboBackMusic.Bottom + 5;
                  lblFieldVoteRate.Top = cboFieldVoteRate.Top + 3;
  
                  gbxNameAuthorize.Height = cboFieldVoteRate.Bottom + 12;
              }
              else
              {
                  gbxNameAuthorize.Height = cboBackMusic.Bottom + 12;
              }
              this.Height = gbxNameAuthorize.Bottom;
          }
  
          /// <summary>
          /// 设置签到码签到是否启用
          /// 杨斌 2014-10-27
          /// </summary>
          private void SetVoteRateEnabled()
          {
              lblFieldVoteRate.Enabled = cboFieldVoteRate.Enabled = GlobalInfo.response.CanVoteRate();//杨斌 2014-10-27
          }
  
          private void rbtNameMode_CheckedChanged(object sender, EventArgs e)
          {
              if (TagSet == null) return;
              TagSet.SetValue(TagKey.ResponsePara_NameMode, rbtNameModeOn.Checked ? 1 : 0);
          }
  
          private void cboCanVote_SelectedIndexChanged(object sender, EventArgs e)
          {
              try
              {
                  if (TagSet == null) return;
                  if (TagSet.ReadOnlyPPT) return;
                  string cboValue = ((ComboItem)cboCanVote.Items[cboCanVote.SelectedIndex]).EnumValue;
                  if (!readOnly)
                      Globals.SunVoteARSAddIn.ShowCanVoteSet(cboValue);
                  //防止返回上次设置时反复调用ShowCanVoteSet方法
                  readOnly = true;
                  int index = ComboBoxOper.GetIndexByValue(cboCanVote, TagSet.LoadValue(TagKey.ResponsePara_CanVote, "cvAll").Value);
                  cboCanVote.SelectedIndex = index;
                  readOnly = false;
                  //cboCanVote.SelectedIndex = TagSet.LoadValue(TagKey.ResponsePara_CanVote, 0).ToInt;
                  //FrmVoteBar.ActivateSlideShowWindow();
              }
              catch (Exception ex)
              {
              }
          }
  
          /// <summary>
          /// 加载下拉框的值
          /// </summary>
          private void LoadComboBox()
          {
              cboCanVote.Items.Clear();
              cboCanVote.Items.Add(new ComboItem(0, "所有人", "cvAll"));
              cboCanVote.Items.Add(new ComboItem(1, "指定名单", "cvPerson"));
              cboCanVote.Items.Add(new ComboItem(2, "指定题目选项", "cvTopic"));
              cboCanVote.DisplayMember = "Name";
              cboCanVote.ValueMember = "EnumValue";
          }
  
          /// <summary>
          /// 权重字段。杨斌 2014-10-27
          /// </summary>
          /// <param name="sender"></param>
          /// <param name="e"></param>
          private void cboFieldVoteRate_SelectedIndexChanged(object sender, EventArgs e)
          {
              //杨斌 2015-04-30
              if (TagSet == null) return;
              if (TagSet.ReadOnlyPPT) return;
              TagSet.SetValue(TagKey.ResponsePara_VoteRateField, cboFieldVoteRate.Text);
          }
  
          private void cboBackMusic_SelectedIndexChanged(object sender, EventArgs e)
          {
              if (!cboBackMusic.Enabled) return;
              if (readOnly) return;//杨斌 2015-04-13
              try
              {
                  int max = cboBackMusic.Items.Count - 1;
                  if (cboBackMusic.SelectedIndex == max)
                  {
                      string path = FrmSystemSet.OpenSoundFile();
                      if (path.Length > 0)
                      {
                          FileInfo fi = new FileInfo(path);
                          if (!fi.Exists) return;
                          string file = fi.Name;
  
                          //若工程目录下没有则复制,总是取相对路径
                          string pathSound = GlobalInfo.SOUND_DIR + file;
                          if (!(new FileInfo(pathSound).Exists)) fi.CopyTo(pathSound, true);
  
                          TagSet.SetValue(TagKey.ResponsePara_SlideBackMusic, file);
                      }
                  }
                  else if (cboBackMusic.SelectedIndex == 0)
                  {
                      TagSet.SetValue(TagKey.ResponsePara_SlideBackMusic, "");
                  }
                  else
                  {
                      TagSet.SetValue(TagKey.ResponsePara_SlideBackMusic, cboBackMusic.Items[1].ToString());
                  }
                  LoadMusicSet();
  
              }
              catch (Exception ex)
              {
  
              }
          }
  
      }
  }