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.
141 lines
5.8 KiB
C#
141 lines
5.8 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 Select : DatabaseAction, IAction
|
|
{
|
|
|
|
public void Run(RuntimeParameter runtime)
|
|
{
|
|
base.RunIni(runtime); //必须调用
|
|
|
|
ShowMsg(Language(0));
|
|
int iSubCount = 0;
|
|
if (!string.IsNullOrWhiteSpace(runtime.Parameters))
|
|
{
|
|
int.TryParse(runtime.Parameters, out iSubCount);
|
|
}
|
|
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;
|
|
}
|
|
List<DbMCControl> lstDbMCControl = GetAllDbMCControls();
|
|
foreach (DbMCControl control in lstDbMCControl)
|
|
{
|
|
if (control.DbMCSource == null ||
|
|
control.DbMCSource.DbMCKey != dbsource.DbMCKey ||
|
|
string.IsNullOrWhiteSpace(control.BaseControl.ActionDataSource))
|
|
{
|
|
continue;
|
|
}
|
|
string ss = control.BaseControl.ActionDataSource;
|
|
if (!ss.ToLower().Trim().StartsWith("select "))
|
|
{
|
|
if (dbHelper.DbSession.ProviderFactory.GetType().FullName.Contains("OracleClientFactory"))
|
|
{
|
|
ss = "SELECT * FROM " + ss + " WHERE 1=1 {0} ";
|
|
}
|
|
else
|
|
{
|
|
ss = "SELECT * FROM [" + ss + "] WHERE 1=1 {0} ";
|
|
}
|
|
}
|
|
|
|
StringBuilder sqlsb = new StringBuilder();
|
|
sqlsb.Append(" ");
|
|
dbHelper.ClearParameter();
|
|
dbHelper.CommandType = CommandType.Text;
|
|
int iPara = 0;
|
|
foreach (DbMCControl select_control in lstDbMCControl)
|
|
{
|
|
if (select_control.DbMCSource == null ||
|
|
select_control.DbMCSource.DbMCKey != dbsource.DbMCKey ||
|
|
string.IsNullOrWhiteSpace(select_control.DataField) ||
|
|
select_control.BaseControl.MCValue == null ||
|
|
string.IsNullOrWhiteSpace(select_control.BaseControl.MCValue.ToString()))
|
|
{
|
|
continue;
|
|
}
|
|
if ((base.DbOptionTypesIsQuery(select_control.BaseControl)))
|
|
{
|
|
iPara++;
|
|
string parkey = "@" + select_control.DataField + "_Para" + iPara.ToString();
|
|
string field = "[" + select_control.DataTable + "].[" + select_control.DataField + "]";
|
|
if (dbHelper.DbSession.ProviderFactory.GetType().FullName.Contains("OracleClientFactory"))
|
|
{
|
|
parkey = ":" + select_control.DataField + "_Para" + iPara.ToString();
|
|
field = select_control.DataTable + "." + select_control.DataField;
|
|
}
|
|
sqlsb.Append(" AND ").Append(field).Append("=").Append(parkey);
|
|
dbHelper.AddParameter(parkey, select_control.BaseControl.MCValue);
|
|
}
|
|
}
|
|
if (iPara > 0 && ss.ToLower().Trim().IndexOf(" where ") < 0)
|
|
{
|
|
ss = ss + " WHERE 1=1";
|
|
}
|
|
string sqlstr = string.Format(ss, sqlsb.ToString());
|
|
if (sqlstr.Length == ss.Length)
|
|
{
|
|
sqlstr = ss + sqlsb.ToString();
|
|
}
|
|
dbHelper.CommandText = sqlstr;
|
|
DataTable dt = dbHelper.ToDataTable();
|
|
|
|
#region 选中行处理1
|
|
|
|
int index = 0;
|
|
DataGridView grid = control.BaseControl as DataGridView;
|
|
if (grid != null)
|
|
{
|
|
foreach (DataGridViewRow row in grid.SelectedRows)
|
|
{
|
|
row.Selected = false;
|
|
index = row.Index;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
control.BaseControl.BindDataSource = dt;
|
|
|
|
#region 选中行处理2
|
|
|
|
if (grid != null)
|
|
{
|
|
if (grid.Rows.Count > 0 && index < grid.Rows.Count)
|
|
{
|
|
grid.Rows[index].Selected = true;
|
|
}
|
|
else if (grid.Rows.Count > 0)
|
|
{
|
|
grid.Rows[grid.Rows.Count - 1].Selected = true;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
//ShowMsg(string.Format(Language(2), dt.Rows.Count - iSubCount));
|
|
ICSharpCode.Core.LoggingService.Info(string.Format(Language(2), dt.Rows.Count - iSubCount));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|