#region
|
|
using System;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Windows.Forms;
|
using CSFrameworkV5.Business;
|
using CSFrameworkV5.Common;
|
using CSFrameworkV5.Core;
|
using CSFrameworkV5.Core.Common;
|
using CSFrameworkV5.Library;
|
using CSFrameworkV5.Library.CommonClass;
|
using CSFrameworkV5.Models;
|
|
#endregion
|
|
namespace CSFrameworkV5.SystemModule
|
{
|
/// <summary>
|
/// 字段名对应的中文名称管理
|
/// </summary>
|
public partial class frmFieldNameMgr : frmBase
|
{
|
private bllFieldNameDefs _BLLInstance;
|
private string _DBID = "";
|
private string _TableName = "";
|
|
public frmFieldNameMgr()
|
{
|
InitializeComponent();
|
}
|
|
private void btnDel_Click(object sender, EventArgs e)
|
{
|
if (gvSummary.FocusedRowHandle >= 0)
|
{
|
if (Msg.AskQuestion("确定要删除当前记录吗?"))
|
try
|
{
|
frmWaitingEx.ShowMe(this);
|
|
var row = gvSummary.GetFocusedDataRow();
|
var key =
|
ConvertEx.ToString(
|
row[sys_FieldNameDefs.__KeyName]);
|
if (_BLLInstance.Delete(key)) //从物理表删除
|
{
|
gvSummary.DeleteRow(gvSummary
|
.FocusedRowHandle); //删除表格中缓存的记录
|
(gcSummary.DataSource as DataTable).AcceptChanges();
|
}
|
}
|
finally
|
{
|
frmWaitingEx.HideMe(this);
|
}
|
}
|
else
|
{
|
Msg.Warning("没有选择记录!");
|
}
|
}
|
|
private void btnEmpty_Click(object sender, EventArgs e)
|
{
|
txt_DisplayName.Text = "";
|
txt_FieldName.Text = "";
|
txt_TableName.Text = "";
|
txt_TableName.Focus();
|
}
|
|
private void btnFillCaption_Click(object sender, EventArgs e)
|
{
|
var dt = gcSummary.DataSource as DataTable;
|
|
foreach (DataRow R in dt.Rows)
|
{
|
var caption = R[sys_FieldNameDefs.DisplayName].ToStringEx();
|
var field = R[sys_FieldNameDefs.FieldName].ToStringEx();
|
var db = R[sys_FieldNameDefs.DBName].ToStringEx();
|
|
if (string.IsNullOrEmpty(caption) ||
|
caption.ToLower() == field.ToLower())
|
//获取字段标题
|
R[sys_FieldNameDefs.DisplayName] =
|
_BLLInstance.GetCaption(db, field);
|
}
|
}
|
|
private void btnQuery_Click(object sender, EventArgs e)
|
{
|
try
|
{
|
frmWaitingEx.ShowMe(this);
|
//搜索数据
|
var dt = _BLLInstance.Search(txt_TableName.Text,
|
txt_FieldName.Text, txt_DisplayName.Text);
|
gcSummary.DataSource = dt;
|
}
|
finally
|
{
|
frmWaitingEx.HideMe(this);
|
}
|
|
if (gvSummary.RowCount == 0 && txt_FieldName.Text == "" &&
|
txt_DisplayName.Text == "")
|
{
|
Msg.Warning("当前表没有字段资料,请确认表名是否输入正确,或者同步表结构!");
|
btnSync.Focus();
|
}
|
}
|
|
private void btnSave_Click(object sender, EventArgs e)
|
{
|
try
|
{
|
frmWaitingEx.ShowMe(this);
|
|
var data = (gcSummary.DataSource as DataTable).GetChanges();
|
if (data != null)
|
{
|
_BLLInstance.Update(data);
|
(gcSummary.DataSource as DataTable).AcceptChanges();
|
gcSummary.RefreshDataSource();
|
Msg.ShowInformation("保存成功!");
|
}
|
else
|
{
|
Msg.Warning("您没有修改数据!");
|
}
|
}
|
finally
|
{
|
frmWaitingEx.HideMe(this);
|
}
|
}
|
|
private void btnSync_Click(object sender, EventArgs e)
|
{
|
Assertion.AssertEditorEmpty(txt_DBs, "请选择数据库!", true);
|
Assertion.AssertEditorEmpty(txt_TableNameSync, "请输入表名!", true);
|
|
var msg = "确定要同步表结构数据吗? 注:保留中文字段描述";
|
|
if (Msg.AskQuestion(msg))
|
try
|
{
|
frmWaitingEx.ShowMe(this);
|
|
//同步表名
|
var dt = _BLLInstance.SyncTable(txt_DBs.Text,
|
txt_TableNameSync.Text);
|
|
if (dt.Rows.Count > 0)
|
{
|
gcSummary.DataSource = dt;
|
Msg.ShowInformation("同步完成,共生成" +
|
dt.Rows.Count.ToStringEx() +
|
"条记录!");
|
}
|
else
|
{
|
Msg.Warning("资料表不存在!");
|
}
|
}
|
catch (Exception ex)
|
{
|
Msg.ShowError(ex.Message);
|
}
|
finally
|
{
|
frmWaitingEx.HideMe(this);
|
}
|
}
|
|
/// <summary>
|
/// 由外部程序调用打开窗体
|
/// </summary>
|
/// <param name="ownerForm">父级窗体</param>
|
/// <param name="dataSetID">当前数据库</param>
|
/// <param name="dataSetDBName">当前数据库</param>
|
/// <param name="tableName">表名</param>
|
/// <param name="loginAccount">登录账号</param>
|
/// <param name="loginPwd">登录密码(明文密码)</param>
|
/// <param name="isExternalCall">是否外部调用</param>
|
public static void Exceute(
|
Form ownerForm,
|
string dataSetID,
|
string dataSetDBName,
|
string tableName,
|
string loginAccount,
|
string loginPwd,
|
bool isExternalCall)
|
{
|
//外部调用传入登录信息
|
if (isExternalCall)
|
{
|
KeyProvider.Default =
|
new KeyProviderRijndael("%SaFz$^p", "3aW%^&Fd");
|
|
var user = new Loginer();
|
user.Account = loginAccount;
|
user.Password = KeyProvider.Default.Encrypt(loginPwd); //test
|
user.AccountName = loginAccount;
|
user.DBID = dataSetID;
|
user.DBName = dataSetDBName;
|
user.LoginAuthType = LoginAuthType.LocalSystemAuth;
|
user.LoginTime = DateTime.Now;
|
|
Loginer.CurrentUser = user;
|
|
//外部调用,要初始化连接以及加载账套!
|
if (BridgeFactory.InitializeBridge())
|
{
|
Loginer.CurrentUser = user;
|
|
//未登陆:加载系统参数配置
|
var dtConfig = CommonData.GetSystemSettings4Program("", "");
|
SystemSettings.Current.Load(dtConfig);
|
}
|
else
|
{
|
throw new CustomException("初始化后连接连接策略失败!");
|
}
|
}
|
|
var form = new frmFieldNameMgr();
|
form.Owner = ownerForm;
|
form.ShowInTaskbar = true;
|
form.Init(dataSetDBName, tableName);
|
frmWaitingEx.HideMe(form);
|
form.ShowDialog();
|
}
|
|
private void frmFieldNameMgr_Load(object sender, EventArgs e)
|
{
|
CCursor.ShowDefaultCursor();
|
|
frmGridCustomize.RegisterGrid(gvSummary);
|
}
|
|
private void gcSummary_Click(object sender, EventArgs e)
|
{
|
}
|
|
/// <summary>
|
/// 外部调用初始化窗体
|
/// </summary>
|
/// <param name="DBName"></param>
|
/// <param name="tableName"></param>
|
private void Init(string DBName, string tableName)
|
{
|
_BLLInstance = new bllFieldNameDefs();
|
|
_DBID = DBName;
|
_TableName = tableName;
|
|
//加载数据库
|
LoadDB();
|
|
if (!string.IsNullOrEmpty(_DBID)) txt_DBs.EditValue = _DBID;
|
|
//加载数据表
|
if (!string.IsNullOrEmpty(DBName)) LoadTable(DBName);
|
|
if (!string.IsNullOrEmpty(_TableName))
|
{
|
txt_TableName.EditValue = _TableName;
|
txt_TableNameSync.EditValue = _TableName;
|
}
|
}
|
|
/// <summary>
|
/// 加载系统数据库所在服务器的全部数据库清单
|
/// </summary>
|
/// <param name="defaultDB"></param>
|
private void LoadDB()
|
{
|
txt_DBs.Properties.DisplayMember = "DBName";
|
txt_DBs.Properties.ValueMember = "DBName";
|
txt_DBs.Properties.DataSource = _BLLInstance.GetDataBaseList();
|
}
|
|
private void LoadTable(string DBName)
|
{
|
if (ConvertEx.ToString(txt_TableNameSync.Tag) != DBName)
|
{
|
txt_TableNameSync.Properties.DisplayMember = "TableName";
|
txt_TableNameSync.Properties.ValueMember = "TableName";
|
txt_TableNameSync.Properties.DataSource =
|
_BLLInstance.GetTableNames(DBName);
|
txt_TableNameSync.Tag = DBName; //标记
|
}
|
}
|
|
private void txt_DBs_EditValueChanged(object sender, EventArgs e)
|
{
|
txt_TableNameSync.Properties.DataSource = null;
|
txt_TableNameSync.EditValue = null;
|
}
|
|
private void txt_TableNameSync_EditValueChanged(object sender,
|
EventArgs e)
|
{
|
//清空记录
|
if (gcSummary.DataSource != null &&
|
gcSummary.DataSource is DataTable)
|
{
|
var dt = gcSummary.DataSource as DataTable;
|
dt.Rows.Clear();
|
dt.AcceptChanges();
|
gcSummary.RefreshDataSource();
|
}
|
}
|
|
private void txt_TableNameSync_QueryPopUp(object sender,
|
CancelEventArgs e)
|
{
|
if (txt_DBs.Text != "")
|
LoadTable(txt_DBs.Text);
|
else
|
txt_DBs.Focus();
|
}
|
}
|
}
|