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.
111 lines
4.1 KiB
C#
111 lines
4.1 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 Insert : DatabaseAction, IAction
|
|
{
|
|
public void Run(RuntimeParameter runtime)
|
|
{
|
|
///确定要添加吗?
|
|
if (MessageBox.Show(Language(3), Language(1), MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
|
{
|
|
runtime.IsReturn = true;
|
|
return;
|
|
}
|
|
base.RunIni(runtime); //必须调用
|
|
|
|
#region 控件数据合法性验证
|
|
|
|
bool isValidFlag = true;
|
|
foreach (DbMCControl control in GetAllDbMCControls())
|
|
{
|
|
if (control.BaseControl.IsValid == false)
|
|
{
|
|
//MessageBox.Show(Language(31), Language(1), MessageBoxButtons.OK);
|
|
isValidFlag = false;
|
|
break;
|
|
}
|
|
}
|
|
if (isValidFlag == false)
|
|
{
|
|
ShowMsg(Language(31));
|
|
runtime.IsReturn = true;
|
|
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;
|
|
}
|
|
dbHelper.ClearParameter();
|
|
dbHelper.CommandType = CommandType.Text;
|
|
List<DbMCControl> lstDbMCControl = GetAllDbMCControls();
|
|
StringBuilder sqlsb_A = new StringBuilder();
|
|
StringBuilder sqlsb_B = new StringBuilder();
|
|
if (dbHelper.DbSession.ProviderFactory.GetType().FullName.Contains("OracleClientFactory"))
|
|
{
|
|
sqlsb_A.Append("INSERT INTO ").Append(table).Append(" (");
|
|
}
|
|
else
|
|
{
|
|
sqlsb_A.Append("INSERT INTO [").Append(table).Append("] (");
|
|
}
|
|
sqlsb_B.Append(") values (");
|
|
int iPara = 0;
|
|
foreach (DbMCControl control in lstDbMCControl)
|
|
{
|
|
if (control.DbMCSource == null ||
|
|
control.DbMCSource.DbMCKey != dbsource.DbMCKey ||
|
|
string.IsNullOrWhiteSpace(control.DataField) ||
|
|
control.DataField.Equals("ObjID", StringComparison.CurrentCultureIgnoreCase))
|
|
{
|
|
continue;
|
|
}
|
|
if ((base.DbOptionTypesIsModify(control.BaseControl)))
|
|
{
|
|
iPara++;
|
|
string parkey = "@" + control.DataField + "_Para" + iPara.ToString();
|
|
if (dbHelper.DbSession.ProviderFactory.GetType().FullName.Contains("OracleClientFactory"))
|
|
{
|
|
parkey = ":" + control.DataField + "_Para" + iPara.ToString();
|
|
}
|
|
sqlsb_A.Append(control.DataField).Append(",");
|
|
sqlsb_B.Append(parkey).Append(",");
|
|
dbHelper.AddParameter(parkey, control.BaseControl.MCValue);
|
|
}
|
|
}
|
|
sqlsb_A.Remove(sqlsb_A.Length - 1, 1);
|
|
sqlsb_B.Remove(sqlsb_B.Length - 1, 1).Append(")");
|
|
if (iPara == 0)
|
|
{
|
|
continue;
|
|
}
|
|
dbHelper.CommandText = sqlsb_A.ToString() + sqlsb_B.ToString();
|
|
dbHelper.ExecuteNonQuery();
|
|
}
|
|
ShowMsg(Language(4));
|
|
}
|
|
}
|
|
}
|