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.

101 lines
3.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Mesnac.Action.Base;
using Mesnac.Controls.Base;
using System.Windows.Forms;
using Mesnac.Codd.Session;
namespace Mesnac.Action.Default.SynchroData
{
public class IniForm : DatabaseAction, IAction
{
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须调用
base.SynchroTable();
base.SynchroField();
foreach (DbMCSource dbsource in GetAllDbMCSources())
{
if (string.IsNullOrWhiteSpace(dbsource.DesignSource) ||
string.IsNullOrWhiteSpace(dbsource.DataTable.ToString()))
{
continue;
}
string source = dbsource.DesignSource;
string table = dbsource.DataTable;
DbHelper dbHelper = NewDbHelper(source);
if (dbHelper==null)
{
continue;
}
//1、先初始化DataGridView以外的控件数据
foreach (DbMCControl control in GetAllDbMCControls())
{
if (control.DbMCSource == null ||
control.DbMCSource.DbMCKey != dbsource.DbMCKey ||
string.IsNullOrWhiteSpace(control.BaseControl.InitDataSource))
{
continue;
}
if (control.BaseControl is DataGridView)
{
continue;
}
string sqlstr = control.BaseControl.InitDataSource;
if (!sqlstr.ToLower().Trim().StartsWith("select"))
{
if (dbHelper.DbSession.ProviderFactory.GetType().FullName.Contains("OracleClientFactory"))
{
sqlstr = "SELECT * FROM " + sqlstr;
}
else
{
sqlstr = "SELECT * FROM [" + sqlstr + "]";
}
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
DataTable dt = dbHelper.ToDataTable();
control.BaseControl.BindDataSource = dt;
}
//2、再初始化DataGridView控件数据
foreach (DbMCControl control in GetAllDbMCControls())
{
if (control.DbMCSource == null ||
control.DbMCSource.DbMCKey != dbsource.DbMCKey ||
string.IsNullOrWhiteSpace(control.BaseControl.InitDataSource))
{
continue;
}
if (control.BaseControl is DataGridView)
{
string sqlstr = control.BaseControl.InitDataSource;
if (!sqlstr.ToLower().Trim().StartsWith("select"))
{
if (dbHelper.DbSession.ProviderFactory.GetType().FullName.Contains("OracleClientFactory"))
{
sqlstr = "SELECT * FROM " + sqlstr;
}
else
{
sqlstr = "SELECT * FROM [" + sqlstr + "]";
}
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
dbHelper.CommandText = sqlstr;
DataTable dt = dbHelper.ToDataTable();
control.BaseControl.BindDataSource = dt;
}
}
}
}
}
}