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.
lj_plc/Actions/Default/Mesnac.Action.Default/SynchroData/SelectRow.cs

106 lines
3.4 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 SelectRow : DatabaseAction, IAction
{
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须调用
bool isSender = false;
List<DbMCControl> lstDbMCControl = GetAllDbMCControls();
foreach (DbMCControl control in lstDbMCControl)
{
DataGridView grid = runtime.Sender as DataGridView;
DbMCControl dbgrid = null;
if (grid != null)
{
isSender = true;
}
if (!isSender)
{
if (control.BaseControl is DataGridView)
{
dbgrid = control;
grid = control.BaseControl as DataGridView;
}
}
if (grid == null)
{
continue;
}
if (isSender)
{
foreach (DbMCControl _dbgrid in lstDbMCControl)
{
if (_dbgrid.BaseControl == grid)
{
dbgrid = _dbgrid;
break;
}
}
}
if (grid.SelectedRows.Count == 0)
{
continue;
}
if (dbgrid == null)
{
continue;
}
if (grid == null)
{
continue;
}
DataGridViewRow row = grid.SelectedRows[0];
foreach (DataGridViewCell cell in row.Cells)
{
if (cell.Displayed)
{
grid.CurrentCell = cell;
break;
}
}
foreach (DbMCControl set_control in GetAllDbMCControls())
{
if ((set_control.DbMCSource != null) &&
(set_control.DbMCSource.DbMCKey == dbgrid.DbMCKey) &&
(set_control != control) &&
(base.DbOptionTypesIsModify(set_control.BaseControl)))
{
if (!string.IsNullOrWhiteSpace(set_control.DataField))
{
try
{
foreach (DataGridViewColumn dc in grid.Columns)
{
if (dc.DataPropertyName == set_control.DataField)
{
set_control.BaseControl.MCValue = row.Cells[dc.Index].Value;
break;
}
}
}
catch { }
}
}
}
if (runtime.Sender is DataGridView)
{
return;
}
}
}
}
}