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.

173 lines
6.5 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 Update : DatabaseAction, IAction
{
public void Run(RuntimeParameter runtime)
{
if (MessageBox.Show(Language(5), Language(1), MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
base.RunIni(runtime); //必须调用
#region 控件数据合法性验证
bool isValidFlag = true;
foreach (DbMCControl control in GetAllDbMCControls())
{
if (control.BaseControl.IsValid == false)
{
isValidFlag = false;
break;
}
}
if (isValidFlag == false)
{
ShowMsg(Language(31));
return;
}
#endregion
ShowMsg(Language(0));
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();
DbMCControlDesignKeyConfig config = new DbMCControlDesignKeyConfig();
List<DbMCControl> controls = GetDbMCControlByKey(config.ToString(new string[] { source, table, "ObjID" }));
foreach (DbMCControl control in controls)
{
if ((control.BaseControl.DbOptionType != DbOptionTypes.Modify
&& control.BaseControl.DbOptionType != DbOptionTypes.QueryAndModify) ||
control.BaseControl.MCValue == null ||
string.IsNullOrWhiteSpace(control.BaseControl.MCValue.ToString()))
{
continue;
}
string objid = control.BaseControl.MCValue.ToString();
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
StringBuilder sqlsb = new StringBuilder();
if (dbHelper.DbSession.ProviderFactory.GetType().FullName.Contains("OracleClientFactory"))
{
sqlsb.Append("UPDATE ").Append(table).Append(" SET ");
}
else
{
sqlsb.Append("UPDATE [").Append(table).Append("] SET ");
}
int iPara = 0;
foreach (DbMCControl update_control in lstDbMCControl)
{
if (update_control.DbMCSource == null ||
update_control.DbMCSource.DbMCKey != dbsource.DbMCKey ||
string.IsNullOrWhiteSpace(update_control.DataField) ||
update_control.DataField.Equals("ObjID", StringComparison.CurrentCultureIgnoreCase))
{
continue;
}
if ((base.DbOptionTypesIsModify(control.BaseControl)))
{
iPara++;
string parkey = "@" + update_control.DataField + "_Para" + iPara.ToString();
if (dbHelper.DbSession.ProviderFactory.GetType().FullName.Contains("OracleClientFactory"))
{
parkey = ":" + update_control.DataField + "_Para" + iPara.ToString();
}
sqlsb.Append(update_control.DataField).Append("=").Append(parkey).Append(",");
dbHelper.AddParameter(parkey, update_control.BaseControl.MCValue);
}
}
sqlsb.Remove(sqlsb.Length - 1, 1);
sqlsb.Append(" WHERE ObjID=").Append(objid);
if (iPara == 0)
{
continue;
}
dbHelper.CommandText = sqlsb.ToString();
dbHelper.ExecuteNonQuery();
}
new LastActionRow(runtime, dbsource);
}
ShowMsg(Language(6));
}
}
public class LastActionRow : DatabaseAction
{
public LastActionRow(RuntimeParameter runtime, DbMCSource dbsource)
{
base.RunIni(runtime);
List<DbMCControl> lstDbMCControl = GetAllDbMCControls();
foreach (DbMCControl dbgrid in lstDbMCControl)
{
if (dbgrid.DbMCSource == null ||
dbgrid.DbMCSource.DbMCKey != dbsource.DbMCKey ||
(dbgrid.BaseControl as DataGridView) == null)
{
continue;
}
DataGridView grid = dbgrid.BaseControl as DataGridView;
if (grid.SelectedRows.Count > 0)
{
this.Index = grid.SelectedRows[0].Index;
}
else
{
this.Index = grid.SelectedRows[0].Index;
}
}
}
public LastActionRow(RuntimeParameter runtime)
{
base.RunIni(runtime);
}
public int Index
{
get
{
int iResult = 0;
IBaseControl control = this.GetMCControlByKey("SelectRowIndexControl").FirstOrDefault();
if (control != null)
{
int.TryParse(control.MCValue.ToString(), out iResult);
}
return iResult;
}
private set
{
IBaseControl control = this.GetMCControlByKey("SelectRowIndexControl").FirstOrDefault();
if (control != null)
{
control.MCValue = value.ToString();
}
}
}
}
}