#region
|
|
using System;
|
using System.ComponentModel;
|
using System.Data;
|
using CSFrameworkV5.Business;
|
using CSFrameworkV5.Common;
|
using CSFrameworkV5.Core;
|
using CSFrameworkV5.Library.CommonClass;
|
using CSFrameworkV5.Models;
|
|
#endregion
|
|
namespace CSFrameworkV5.Library
|
{
|
public partial class frmLogFieldConfig : frmBase
|
{
|
public frmLogFieldConfig()
|
{
|
InitializeComponent();
|
}
|
|
private void AddOtherDB(DataTable dtDB)
|
{
|
var R = dtDB.NewRow();
|
R["DBName"] = "OtherDB"; //例子:其他服务器的数据库(与账套数据库不在同一个服务器)
|
dtDB.Rows.InsertAt(R, 0);
|
dtDB.AcceptChanges();
|
}
|
|
private void btnAdd_Click(object sender, EventArgs e)
|
{
|
if (gcFields.DataSource == null)
|
{
|
Msg.Warning("请查询数据!");
|
return;
|
}
|
|
if (txtDBName.Text.Trim() == "" || txtTableName.Text.Trim() == "" ||
|
txtFieldName.Text.Trim() == "")
|
{
|
Msg.Warning("数据库、表名、字段名不能为空!");
|
txtFieldName.Focus();
|
return;
|
}
|
|
var R = (gcFields.DataSource as DataTable).Rows.Add();
|
R[sys_LogFields.RowID] = Guid.NewGuid().ToStringEx();
|
R[sys_LogFields.DBName] = txtDBName.Text;
|
R[sys_LogFields.TableName] = txtTableName.Text;
|
R[sys_LogFields.FieldName] = txtFieldName.Text;
|
R[sys_LogFields.FlagLog] = "Y";
|
|
//保存数据
|
if (DoSave()) txtFieldName.Text = "";
|
}
|
|
private void btnDel_Click(object sender, EventArgs e)
|
{
|
if (gvFields.FocusedRowHandle >= 0)
|
if (Msg.AskQuestion(
|
$"确定要删除{gvFields.GetFocusedRowCellDisplayText(colFieldCaption)}字段吗?"))
|
{
|
gvFields.GetFocusedDataRow().Delete();
|
|
//保存数据
|
DoSave();
|
}
|
}
|
|
private void btnRefresh_Click(object sender, EventArgs e)
|
{
|
if (txt_DBs.Text == "")
|
{
|
txt_DBs.Focus();
|
txt_DBs.ShowPopup();
|
return;
|
}
|
|
if (txtTableList.Text == "")
|
{
|
txtTableList.Focus();
|
txtTableList.ShowPopup();
|
return;
|
}
|
|
if (txtTableList.Text != "")
|
try
|
{
|
frmWaitingEx.ShowMe(this);
|
var tableName = txtTableList.Text;
|
var dt = new bllFieldNameDefs().GetTableFields(
|
Loginer.CurrentUser.DBName,
|
txt_DBs.EditValue.ToStringEx(), tableName);
|
gcFields.DataSource = dt;
|
gcFields.RefreshDataSource();
|
if (gvFields.RowCount == 0)
|
Msg.Warning(
|
$"资料表{txtTableList.Text}没有字段数据,请使用【字段名管理】工具导入字段!");
|
}
|
finally
|
{
|
frmWaitingEx.HideMe(this);
|
}
|
}
|
|
private void btnSave_Click(object sender, EventArgs e)
|
{
|
DoSave();
|
}
|
|
private bool DoSave()
|
{
|
try
|
{
|
frmWaitingEx.ShowMe(this);
|
|
var dt = (gcFields.DataSource as DataTable).GetChanges();
|
|
if (dt != null)
|
{
|
if (LogEditHistory.SaveFieldDef(dt))
|
{
|
(gcFields.DataSource as DataTable).AcceptChanges();
|
Msg.ShowInformation("保存成功!");
|
}
|
else
|
{
|
Msg.Warning("保存失败!");
|
}
|
}
|
else
|
{
|
Msg.Warning("你没有修改数据!");
|
}
|
|
return true;
|
}
|
catch
|
{
|
return false;
|
}
|
finally
|
{
|
frmWaitingEx.HideMe(this);
|
}
|
}
|
|
private void frmLogFieldConfig_Load(object sender, EventArgs e)
|
{
|
DataBinderTools.BoundCheckEdit(repCheck);
|
|
//加载数据库清单
|
var dtDB = new bllFieldNameDefs().GetDataBaseList();
|
AddOtherDB(dtDB);
|
DataBinder.BindingComboEditDataSource(txt_DBs, dtDB, "DBName");
|
}
|
|
private void LoadTable(string DBName)
|
{
|
if (ConvertEx.ToString(txtTableList.Tag) != DBName)
|
{
|
//加载数据表
|
var dtTB = new bllFieldNameDefs().GetTableNames(DBName);
|
DataBinder.BindingComboEditDataSource(txtTableList, dtTB,
|
"TableName");
|
txtTableList.Tag = DBName; //标记
|
}
|
}
|
|
private void txt_DBs_EditValueChanged(object sender, EventArgs e)
|
{
|
txtTableList.Properties.Items.Clear();
|
txtTableList.EditValue = null;
|
}
|
|
private void txtTableList_QueryPopUp(object sender, CancelEventArgs e)
|
{
|
if (txt_DBs.Text != "")
|
LoadTable(txt_DBs.Text);
|
else
|
txt_DBs.Focus();
|
}
|
}
|
}
|