You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.5 KiB
C#

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 ICSharpCode.Core;
using Mesnac.Core;
using Mesnac.Basic;
using Mesnac.Gui.Run.Global;
namespace Mesnac.Gui.Run.Dialog
{
public partial class FrmSelectMessage : Form
{
public FrmSelectMessage()
{
InitializeComponent();
this.InitUIMethod();
this.refreshListData();
}
#region 属性定义
/// <summary>
/// 当前选择的资源ID
/// </summary>
public string CurrMsgId
{
get
{
if (this.lstMessages.SelectedIndex != -1)
{
return this.lstMessages.SelectedItem as string;
}
else
{
return String.Empty;
}
}
}
#endregion
#region 初始化界面元素
/// <summary>
/// 初始化界面元素
/// </summary>
private void InitUIMethod()
{
this.Text = StringParser.Parse(ResourceService.GetString("Dialog_FrmSelectMessage_Text")); //筛选资源;
this.groupBox1.Text = StringParser.Parse(ResourceService.GetString("Dialog_FrmSelectMessage_groupBox1_Text")); //资源项信息
this.groupBox2.Text = StringParser.Parse(ResourceService.GetString("Dialog_FrmSelectMessage_groupBox2_Text")); //区域信息
this.btnOK.Text = StringParser.Parse(ResourceService.GetString("Dialog_Button_OK")); //确定
this.btnCancel.Text = StringParser.Parse(ResourceService.GetString("Dialog_Button_Cancel")); //取消
}
#endregion
#region 刷新列表数据
/// <summary>
/// 刷新列表框数据
/// </summary>
private void refreshListData()
{
this.lstMessages.Items.Clear();
if (String.IsNullOrEmpty(this.txtMessageId.Text))
{
foreach (string msgId in AppConfigHandler.Instance.SysMessages.Messages.Keys)
{
this.lstMessages.Items.Add(msgId);
}
}
else
{
foreach (string msgId in AppConfigHandler.Instance.SysMessages.Messages.Keys.Where<string>(p => p.StartsWith(this.txtMessageId.Text, StringComparison.OrdinalIgnoreCase)))
{
this.lstMessages.Items.Add(msgId);
}
}
}
#endregion
#region 文本框筛选处理
private void txtMessageId_TextChanged(object sender, EventArgs e)
{
refreshListData();
}
#endregion
#region 选择资源项处理
private void lstMessages_SelectedIndexChanged(object sender, EventArgs e)
{
DataTable localeTable = new DataTable();
localeTable.Columns.Add("code");
localeTable.Columns.Add("country");
localeTable.Columns.Add("language");
localeTable.Columns.Add("value");
if (!String.IsNullOrEmpty(this.CurrMsgId))
{
foreach (LocaleItem item in AppConfigHandler.Instance.SysMessages.Messages[this.CurrMsgId].Values)
{
DataRow row = localeTable.NewRow();
row["code"] = item.Code;
row["country"] = item.Country;
row["language"] = item.Language;
row["value"] = item.Value;
localeTable.Rows.Add(row);
}
}
this.dgvLocales.Columns["colCode"].DataPropertyName = "code";
this.dgvLocales.Columns["colCountry"].DataPropertyName = "country";
this.dgvLocales.Columns["colLanguage"].DataPropertyName = "language";
this.dgvLocales.Columns["colValue"].DataPropertyName = "value";
this.dgvLocales.DataSource = localeTable;
}
#endregion
#region 确定
private void btnOK_Click(object sender, EventArgs e)
{
this.DialogResult = System.Windows.Forms.DialogResult.OK;
}
#endregion
#region 取消
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
}
#endregion
}
}