本文整理汇总了C#中AppointmentSystem.Data.TransactionManager类的典型用法代码示例。如果您正苦于以下问题:C# TransactionManager类的具体用法?C# TransactionManager怎么用?C# TransactionManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TransactionManager类属于AppointmentSystem.Data命名空间,在下文中一共展示了TransactionManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
/// <summary>
/// Update an existing row in the datasource.
/// </summary>
/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
/// <param name="entity">AppointmentSystem.Entities.Patient object to update.</param>
/// <remarks>
/// After updating the datasource, the AppointmentSystem.Entities.Patient object will be updated
/// to refelect any changes made by the datasource. (ie: identity or computed columns)
/// </remarks>
/// <returns>Returns true if operation is successful.</returns>
/// <exception cref="System.Exception">The command could not be executed.</exception>
/// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
/// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
public override bool Update(TransactionManager transactionManager, AppointmentSystem.Entities.Patient entity)
{
SqlDatabase database = new SqlDatabase(this._connectionString);
DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Patient_Update", _useStoredProcedure);
database.AddInParameter(commandWrapper, "@PatientCode", DbType.StringFixedLength, entity.PatientCode );
database.AddInParameter(commandWrapper, "@OriginalPatientCode", DbType.StringFixedLength, entity.OriginalPatientCode);
database.AddInParameter(commandWrapper, "@FirstName", DbType.String, entity.FirstName );
database.AddInParameter(commandWrapper, "@LastName", DbType.String, entity.LastName );
database.AddInParameter(commandWrapper, "@MemberType", DbType.String, entity.MemberType );
database.AddInParameter(commandWrapper, "@HomePhone", DbType.String, entity.HomePhone );
database.AddInParameter(commandWrapper, "@WorkPhone", DbType.String, entity.WorkPhone );
database.AddInParameter(commandWrapper, "@CellPhone", DbType.String, entity.CellPhone );
database.AddInParameter(commandWrapper, "@Avatar", DbType.String, entity.Avatar );
database.AddInParameter(commandWrapper, "@CompanyCode", DbType.String, entity.CompanyCode );
database.AddInParameter(commandWrapper, "@Birthdate", DbType.DateTime, (entity.Birthdate.HasValue ? (object) entity.Birthdate : System.DBNull.Value) );
database.AddInParameter(commandWrapper, "@IsFemale", DbType.Boolean, entity.IsFemale );
database.AddInParameter(commandWrapper, "@Title", DbType.String, entity.Title );
database.AddInParameter(commandWrapper, "@Note", DbType.String, entity.Note );
database.AddInParameter(commandWrapper, "@IsDisabled", DbType.Boolean, entity.IsDisabled );
database.AddInParameter(commandWrapper, "@CreateUser", DbType.String, entity.CreateUser );
database.AddInParameter(commandWrapper, "@CreateDate", DbType.DateTime, entity.CreateDate );
database.AddInParameter(commandWrapper, "@UpdateUser", DbType.String, entity.UpdateUser );
database.AddInParameter(commandWrapper, "@UpdateDate", DbType.DateTime, entity.UpdateDate );
int results = 0;
//Provider Data Requesting Command Event
OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity));
if (transactionManager != null)
{
results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
}
else
{
results = Utility.ExecuteNonQuery(database,commandWrapper);
}
//Stop Tracking Now that it has been updated and persisted.
if (DataRepository.Provider.EnableEntityTracking)
EntityManager.StopTracking(entity.EntityTrackingKey);
entity.OriginalPatientCode = entity.PatientCode;
entity.AcceptChanges();
//Provider Data Requested Command Event
OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity));
return Convert.ToBoolean(results);
}
示例2: GetPaged
}//end getall
#endregion
#region GetPaged Methods
/// <summary>
/// Gets a page of rows from the DataSource.
/// </summary>
/// <param name="start">Row number at which to start reading.</param>
/// <param name="pageLength">Number of rows to return.</param>
/// <param name="count">Number of rows in the DataSource.</param>
/// <param name="whereClause">Specifies the condition for the rows returned by a query (Name='John Doe', Name='John Doe' AND Id='1', Name='John Doe' OR Id='1').</param>
/// <param name="orderBy">Specifies the sort criteria for the rows in the DataSource (Name ASC; BirthDay DESC, Name ASC);</param>
/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
/// <remarks></remarks>
/// <returns>Returns a typed collection of AppointmentSystem.Entities.Screen objects.</returns>
public override TList<Screen> GetPaged(TransactionManager transactionManager, string whereClause, string orderBy, int start, int pageLength, out int count)
{
SqlDatabase database = new SqlDatabase(this._connectionString);
DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Screen_GetPaged", _useStoredProcedure);
if (commandWrapper.CommandType == CommandType.Text
&& commandWrapper.CommandText != null)
{
commandWrapper.CommandText = commandWrapper.CommandText.Replace(SqlUtil.PAGE_INDEX, string.Concat(SqlUtil.PAGE_INDEX, Guid.NewGuid().ToString("N").Substring(0, 8)));
}
database.AddInParameter(commandWrapper, "@WhereClause", DbType.String, whereClause);
database.AddInParameter(commandWrapper, "@OrderBy", DbType.String, orderBy);
database.AddInParameter(commandWrapper, "@PageIndex", DbType.Int32, start);
database.AddInParameter(commandWrapper, "@PageSize", DbType.Int32, pageLength);
IDataReader reader = null;
//Create Collection
TList<Screen> rows = new TList<Screen>();
try
{
//Provider Data Requesting Command Event
OnDataRequesting(new CommandEventArgs(commandWrapper, "GetPaged", rows));
if (transactionManager != null)
{
reader = Utility.ExecuteReader(transactionManager, commandWrapper);
}
else
{
reader = Utility.ExecuteReader(database, commandWrapper);
}
Fill(reader, rows, 0, int.MaxValue);
count = rows.Count;
if(reader.NextResult())
{
if(reader.Read())
{
count = reader.GetInt32(0);
}
}
//Provider Data Requested Command Event
OnDataRequested(new CommandEventArgs(commandWrapper, "GetPaged", rows));
}
catch(Exception)
{
throw;
}
finally
{
if (reader != null)
reader.Close();
commandWrapper = null;
}
return rows;
}
示例3: BulkInsert
/// <summary>
/// Lets you efficiently bulk insert many entities to the database.
/// </summary>
/// <param name="transactionManager">The transaction manager.</param>
/// <param name="entities">The entities.</param>
/// <remarks>
/// After inserting into the datasource, the AppointmentSystem.Entities.Screen object will be updated
/// to refelect any changes made by the datasource. (ie: identity or computed columns)
/// </remarks>
public override void BulkInsert(TransactionManager transactionManager, TList<AppointmentSystem.Entities.Screen> entities)
{
//System.Data.SqlClient.SqlBulkCopy bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);
System.Data.SqlClient.SqlBulkCopy bulkCopy = null;
if (transactionManager != null && transactionManager.IsOpen)
{
System.Data.SqlClient.SqlConnection cnx = transactionManager.TransactionObject.Connection as System.Data.SqlClient.SqlConnection;
System.Data.SqlClient.SqlTransaction transaction = transactionManager.TransactionObject as System.Data.SqlClient.SqlTransaction;
bulkCopy = new System.Data.SqlClient.SqlBulkCopy(cnx, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints, transaction); //, null);
}
else
{
bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);
}
bulkCopy.BulkCopyTimeout = 360;
bulkCopy.DestinationTableName = "Screen";
DataTable dataTable = new DataTable();
DataColumn col0 = dataTable.Columns.Add("ScreenCode", typeof(System.String));
col0.AllowDBNull = false;
DataColumn col1 = dataTable.Columns.Add("ScreenName", typeof(System.String));
col1.AllowDBNull = true;
DataColumn col2 = dataTable.Columns.Add("PriorityIndex", typeof(System.Int32));
col2.AllowDBNull = false;
DataColumn col3 = dataTable.Columns.Add("IsDisabled", typeof(System.Boolean));
col3.AllowDBNull = false;
DataColumn col4 = dataTable.Columns.Add("CreateUser", typeof(System.String));
col4.AllowDBNull = true;
DataColumn col5 = dataTable.Columns.Add("CreateDate", typeof(System.DateTime));
col5.AllowDBNull = false;
DataColumn col6 = dataTable.Columns.Add("UpdateUser", typeof(System.String));
col6.AllowDBNull = true;
DataColumn col7 = dataTable.Columns.Add("UpdateDate", typeof(System.DateTime));
col7.AllowDBNull = false;
bulkCopy.ColumnMappings.Add("ScreenCode", "ScreenCode");
bulkCopy.ColumnMappings.Add("ScreenName", "ScreenName");
bulkCopy.ColumnMappings.Add("PriorityIndex", "PriorityIndex");
bulkCopy.ColumnMappings.Add("IsDisabled", "IsDisabled");
bulkCopy.ColumnMappings.Add("CreateUser", "CreateUser");
bulkCopy.ColumnMappings.Add("CreateDate", "CreateDate");
bulkCopy.ColumnMappings.Add("UpdateUser", "UpdateUser");
bulkCopy.ColumnMappings.Add("UpdateDate", "UpdateDate");
foreach(AppointmentSystem.Entities.Screen entity in entities)
{
if (entity.EntityState != EntityState.Added)
continue;
DataRow row = dataTable.NewRow();
row["ScreenCode"] = entity.ScreenCode;
row["ScreenName"] = entity.ScreenName;
row["PriorityIndex"] = entity.PriorityIndex;
row["IsDisabled"] = entity.IsDisabled;
row["CreateUser"] = entity.CreateUser;
row["CreateDate"] = entity.CreateDate;
row["UpdateUser"] = entity.UpdateUser;
row["UpdateDate"] = entity.UpdateDate;
dataTable.Rows.Add(row);
}
// send the data to the server
bulkCopy.WriteToServer(dataTable);
// update back the state
foreach(AppointmentSystem.Entities.Screen entity in entities)
{
if (entity.EntityState != EntityState.Added)
continue;
entity.AcceptChanges();
//.........这里部分代码省略.........
示例4: Delete
/// <summary>
/// Deletes a row from the DataSource.
/// </summary>
/// <param name="_screenCode">Link name of screen.
/// /// Ex: Status, Appointment.... Primary Key.</param>
/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
/// <remarks>Deletes based on primary key(s).</remarks>
/// <returns>Returns true if operation suceeded.</returns>
/// <exception cref="System.Exception">The command could not be executed.</exception>
/// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
/// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
public override bool Delete(TransactionManager transactionManager, System.String _screenCode)
{
SqlDatabase database = new SqlDatabase(this._connectionString);
DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Screen_Delete", _useStoredProcedure);
database.AddInParameter(commandWrapper, "@ScreenCode", DbType.AnsiString, _screenCode);
//Provider Data Requesting Command Event
OnDataRequesting(new CommandEventArgs(commandWrapper, "Delete"));
int results = 0;
if (transactionManager != null)
{
results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
}
else
{
results = Utility.ExecuteNonQuery(database,commandWrapper);
}
//Stop Tracking Now that it has been updated and persisted.
if (DataRepository.Provider.EnableEntityTracking)
{
string entityKey = EntityLocator.ConstructKeyFromPkItems(typeof(Screen)
,_screenCode);
EntityManager.StopTracking(entityKey);
}
//Provider Data Requested Command Event
OnDataRequested(new CommandEventArgs(commandWrapper, "Delete"));
commandWrapper = null;
return Convert.ToBoolean(results);
}//end Delete
示例5: Find
/// <summary>
/// Returns rows from the DataSource that meet the parameter conditions.
/// </summary>
/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
/// <param name="parameters">A collection of <see cref="SqlFilterParameter"/> objects.</param>
/// <param name="orderBy">Specifies the sort criteria for the rows in the DataSource (Name ASC; BirthDay DESC, Name ASC);</param>
/// <param name="start">Row number at which to start reading.</param>
/// <param name="pageLength">Number of rows to return.</param>
/// <param name="count">out. The number of rows that match this query.</param>
/// <returns>Returns a typed collection of AppointmentSystem.Entities.Screen objects.</returns>
public override TList<Screen> Find(TransactionManager transactionManager, IFilterParameterCollection parameters, string orderBy, int start, int pageLength, out int count)
{
SqlFilterParameterCollection filter = null;
if (parameters == null)
filter = new SqlFilterParameterCollection();
else
filter = parameters.GetParameters();
SqlDatabase database = new SqlDatabase(this._connectionString);
DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Screen_Find_Dynamic", typeof(ScreenColumn), filter, orderBy, start, pageLength);
SqlFilterParameter param;
for ( int i = 0; i < filter.Count; i++ )
{
param = filter[i];
database.AddInParameter(commandWrapper, param.Name, param.DbType, param.GetValue());
}
TList<Screen> rows = new TList<Screen>();
IDataReader reader = null;
try
{
//Provider Data Requesting Command Event
OnDataRequesting(new CommandEventArgs(commandWrapper, "Find", rows));
if ( transactionManager != null )
{
reader = Utility.ExecuteReader(transactionManager, commandWrapper);
}
else
{
reader = Utility.ExecuteReader(database, commandWrapper);
}
Fill(reader, rows, 0, int.MaxValue);
count = rows.Count;
if ( reader.NextResult() )
{
if ( reader.Read() )
{
count = reader.GetInt32(0);
}
}
//Provider Data Requested Command Event
OnDataRequested(new CommandEventArgs(commandWrapper, "Find", rows));
}
finally
{
if ( reader != null )
reader.Close();
commandWrapper = null;
}
return rows;
}
示例6: Insert
/// <summary>
/// Inserts a AppointmentSystem.Entities.Status object into the datasource using a transaction.
/// </summary>
/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
/// <param name="entity">AppointmentSystem.Entities.Status object to insert.</param>
/// <remarks>
/// After inserting into the datasource, the AppointmentSystem.Entities.Status object will be updated
/// to refelect any changes made by the datasource. (ie: identity or computed columns)
/// </remarks>
/// <returns>Returns true if operation is successful.</returns>
/// <exception cref="System.Exception">The command could not be executed.</exception>
/// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
/// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
public override bool Insert(TransactionManager transactionManager, AppointmentSystem.Entities.Status entity)
{
SqlDatabase database = new SqlDatabase(this._connectionString);
DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Status_Insert", _useStoredProcedure);
database.AddInParameter(commandWrapper, "@Id", DbType.AnsiString, entity.Id );
database.AddInParameter(commandWrapper, "@Title", DbType.String, entity.Title );
database.AddInParameter(commandWrapper, "@ColorCode", DbType.AnsiString, entity.ColorCode );
database.AddInParameter(commandWrapper, "@PriorityIndex", DbType.Int32, entity.PriorityIndex );
database.AddInParameter(commandWrapper, "@CreateUser", DbType.String, entity.CreateUser );
database.AddInParameter(commandWrapper, "@CreateDate", DbType.DateTime, entity.CreateDate );
database.AddInParameter(commandWrapper, "@UpdateUser", DbType.String, entity.UpdateUser );
database.AddInParameter(commandWrapper, "@UpdateDate", DbType.DateTime, entity.UpdateDate );
int results = 0;
//Provider Data Requesting Command Event
OnDataRequesting(new CommandEventArgs(commandWrapper, "Insert", entity));
if (transactionManager != null)
{
results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
}
else
{
results = Utility.ExecuteNonQuery(database,commandWrapper);
}
entity.OriginalId = entity.Id;
entity.AcceptChanges();
//Provider Data Requested Command Event
OnDataRequested(new CommandEventArgs(commandWrapper, "Insert", entity));
return Convert.ToBoolean(results);
}
示例7: Update
/// <summary>
/// Update an existing row in the datasource.
/// </summary>
/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
/// <param name="entity">AppointmentSystem.Entities.GroupRole object to update.</param>
/// <remarks>
/// After updating the datasource, the AppointmentSystem.Entities.GroupRole object will be updated
/// to refelect any changes made by the datasource. (ie: identity or computed columns)
/// </remarks>
/// <returns>Returns true if operation is successful.</returns>
/// <exception cref="System.Exception">The command could not be executed.</exception>
/// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
/// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
public override bool Update(TransactionManager transactionManager, AppointmentSystem.Entities.GroupRole entity)
{
SqlDatabase database = new SqlDatabase(this._connectionString);
DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.GroupRole_Update", _useStoredProcedure);
database.AddInParameter(commandWrapper, "@Id", DbType.Int64, entity.Id );
database.AddInParameter(commandWrapper, "@GroupId", DbType.String, entity.GroupId );
database.AddInParameter(commandWrapper, "@RoleId", DbType.Int32, (entity.RoleId.HasValue ? (object) entity.RoleId : System.DBNull.Value) );
database.AddInParameter(commandWrapper, "@IsDisabled", DbType.Boolean, entity.IsDisabled );
database.AddInParameter(commandWrapper, "@CreateUser", DbType.String, entity.CreateUser );
database.AddInParameter(commandWrapper, "@CreateDate", DbType.DateTime, entity.CreateDate );
database.AddInParameter(commandWrapper, "@UpdateUser", DbType.String, entity.UpdateUser );
database.AddInParameter(commandWrapper, "@UpdateDate", DbType.DateTime, entity.UpdateDate );
int results = 0;
//Provider Data Requesting Command Event
OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity));
if (transactionManager != null)
{
results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
}
else
{
results = Utility.ExecuteNonQuery(database,commandWrapper);
}
//Stop Tracking Now that it has been updated and persisted.
if (DataRepository.Provider.EnableEntityTracking)
EntityManager.StopTracking(entity.EntityTrackingKey);
entity.AcceptChanges();
//Provider Data Requested Command Event
OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity));
return Convert.ToBoolean(results);
}
示例8: UpdateStatus
/// <summary>
/// This method wraps the '_Appointment_UpdateStatus' stored procedure.
/// </summary>
/// <param name="oldId"> A <c>System.String</c> instance.</param>
/// <param name="patientCode"> A <c>System.String</c> instance.</param>
/// <param name="statusId"> A <c>System.String</c> instance.</param>
/// <param name="updateUser"> A <c>System.String</c> instance.</param>
/// <param name="result"> A <c>System.Int32?</c> instance.</param>
/// <param name="id"> A <c>System.String</c> instance.</param>
/// <param name="note"> A <c>System.String</c> instance.</param>
/// <param name="start">Row number at which to start reading.</param>
/// <param name="pageLength">Number of rows to return.</param>
/// <param name="transactionManager"><see cref="TransactionManager"/> object.</param>
/// <remark>This method is generated from a stored procedure.</remark>
public override void UpdateStatus(TransactionManager transactionManager, int start, int pageLength , System.String oldId, System.String patientCode, System.String statusId, System.String updateUser, ref System.Int32? result, ref System.String id, ref System.String note)
{
SqlDatabase database = new SqlDatabase(this._connectionString);
DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo._Appointment_UpdateStatus", true);
database.AddInParameter(commandWrapper, "@OldId", DbType.String, oldId );
database.AddInParameter(commandWrapper, "@PatientCode", DbType.StringFixedLength, patientCode );
database.AddInParameter(commandWrapper, "@StatusId", DbType.String, statusId );
database.AddInParameter(commandWrapper, "@UpdateUser", DbType.String, updateUser );
database.AddParameter(commandWrapper, "@Result", DbType.Int32, 4, ParameterDirection.InputOutput, true, 10, 0, string.Empty, DataRowVersion.Current, result);
database.AddParameter(commandWrapper, "@Id", DbType.String, 20, ParameterDirection.InputOutput, true, 0, 0, string.Empty, DataRowVersion.Current, id);
database.AddParameter(commandWrapper, "@Note", DbType.String, 500, ParameterDirection.InputOutput, true, 0, 0, string.Empty, DataRowVersion.Current, note);
//Provider Data Requesting Command Event
OnDataRequesting(new CommandEventArgs(commandWrapper, "UpdateStatus", (IEntity)null));
if (transactionManager != null)
{
Utility.ExecuteNonQuery(transactionManager, commandWrapper );
}
else
{
Utility.ExecuteNonQuery(database, commandWrapper);
}
//Provider Data Requested Command Event
OnDataRequested(new CommandEventArgs(commandWrapper, "UpdateStatus", (IEntity)null));
result = Utility.GetParameterValue<System.Int32?>(commandWrapper.Parameters["@Result"]);
id = Utility.GetParameterValue<System.String>(commandWrapper.Parameters["@Id"]);
note = Utility.GetParameterValue<System.String>(commandWrapper.Parameters["@Note"]);
return;
}
示例9: BulkInsert
/// <summary>
/// Lets you efficiently bulk insert many entities to the database.
/// </summary>
/// <param name="transactionManager">The transaction manager.</param>
/// <param name="entities">The entities.</param>
/// <remarks>
/// After inserting into the datasource, the AppointmentSystem.Entities.SmsReceiver object will be updated
/// to refelect any changes made by the datasource. (ie: identity or computed columns)
/// </remarks>
public override void BulkInsert(TransactionManager transactionManager, TList<AppointmentSystem.Entities.SmsReceiver> entities)
{
//System.Data.SqlClient.SqlBulkCopy bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);
System.Data.SqlClient.SqlBulkCopy bulkCopy = null;
if (transactionManager != null && transactionManager.IsOpen)
{
System.Data.SqlClient.SqlConnection cnx = transactionManager.TransactionObject.Connection as System.Data.SqlClient.SqlConnection;
System.Data.SqlClient.SqlTransaction transaction = transactionManager.TransactionObject as System.Data.SqlClient.SqlTransaction;
bulkCopy = new System.Data.SqlClient.SqlBulkCopy(cnx, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints, transaction); //, null);
}
else
{
bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);
}
bulkCopy.BulkCopyTimeout = 360;
bulkCopy.DestinationTableName = "SmsReceiver";
DataTable dataTable = new DataTable();
DataColumn col0 = dataTable.Columns.Add("Id", typeof(System.Int64));
col0.AllowDBNull = false;
DataColumn col1 = dataTable.Columns.Add("Mobile", typeof(System.String));
col1.AllowDBNull = false;
DataColumn col2 = dataTable.Columns.Add("FirstName", typeof(System.String));
col2.AllowDBNull = true;
DataColumn col3 = dataTable.Columns.Add("LastName", typeof(System.String));
col3.AllowDBNull = true;
DataColumn col4 = dataTable.Columns.Add("UserType", typeof(System.Byte));
col4.AllowDBNull = false;
DataColumn col5 = dataTable.Columns.Add("SmsId", typeof(System.Int64));
col5.AllowDBNull = false;
DataColumn col6 = dataTable.Columns.Add("IsSent", typeof(System.Boolean));
col6.AllowDBNull = false;
DataColumn col7 = dataTable.Columns.Add("SendingTimes", typeof(System.Int32));
col7.AllowDBNull = false;
DataColumn col8 = dataTable.Columns.Add("Note", typeof(System.String));
col8.AllowDBNull = true;
DataColumn col9 = dataTable.Columns.Add("IsDisabled", typeof(System.Boolean));
col9.AllowDBNull = false;
DataColumn col10 = dataTable.Columns.Add("CreateUser", typeof(System.String));
col10.AllowDBNull = true;
DataColumn col11 = dataTable.Columns.Add("CreateDate", typeof(System.DateTime));
col11.AllowDBNull = false;
DataColumn col12 = dataTable.Columns.Add("UpdateUser", typeof(System.String));
col12.AllowDBNull = true;
DataColumn col13 = dataTable.Columns.Add("UpdateDate", typeof(System.DateTime));
col13.AllowDBNull = false;
bulkCopy.ColumnMappings.Add("Id", "Id");
bulkCopy.ColumnMappings.Add("Mobile", "Mobile");
bulkCopy.ColumnMappings.Add("FirstName", "FirstName");
bulkCopy.ColumnMappings.Add("LastName", "LastName");
bulkCopy.ColumnMappings.Add("UserType", "UserType");
bulkCopy.ColumnMappings.Add("SmsId", "SmsId");
bulkCopy.ColumnMappings.Add("IsSent", "IsSent");
bulkCopy.ColumnMappings.Add("SendingTimes", "SendingTimes");
bulkCopy.ColumnMappings.Add("Note", "Note");
bulkCopy.ColumnMappings.Add("IsDisabled", "IsDisabled");
bulkCopy.ColumnMappings.Add("CreateUser", "CreateUser");
bulkCopy.ColumnMappings.Add("CreateDate", "CreateDate");
bulkCopy.ColumnMappings.Add("UpdateUser", "UpdateUser");
bulkCopy.ColumnMappings.Add("UpdateDate", "UpdateDate");
foreach(AppointmentSystem.Entities.SmsReceiver entity in entities)
{
if (entity.EntityState != EntityState.Added)
continue;
DataRow row = dataTable.NewRow();
row["Id"] = entity.Id;
row["Mobile"] = entity.Mobile;
row["FirstName"] = entity.FirstName;
row["LastName"] = entity.LastName;
row["UserType"] = entity.UserType;
row["SmsId"] = entity.SmsId;
row["IsSent"] = entity.IsSent;
//.........这里部分代码省略.........
示例10: BulkInsert
/// <summary>
/// Lets you efficiently bulk insert many entities to the database.
/// </summary>
/// <param name="transactionManager">The transaction manager.</param>
/// <param name="entities">The entities.</param>
/// <remarks>
/// After inserting into the datasource, the AppointmentSystem.Entities.Appointment object will be updated
/// to refelect any changes made by the datasource. (ie: identity or computed columns)
/// </remarks>
public override void BulkInsert(TransactionManager transactionManager, TList<AppointmentSystem.Entities.Appointment> entities)
{
//System.Data.SqlClient.SqlBulkCopy bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);
System.Data.SqlClient.SqlBulkCopy bulkCopy = null;
if (transactionManager != null && transactionManager.IsOpen)
{
System.Data.SqlClient.SqlConnection cnx = transactionManager.TransactionObject.Connection as System.Data.SqlClient.SqlConnection;
System.Data.SqlClient.SqlTransaction transaction = transactionManager.TransactionObject as System.Data.SqlClient.SqlTransaction;
bulkCopy = new System.Data.SqlClient.SqlBulkCopy(cnx, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints, transaction); //, null);
}
else
{
bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);
}
bulkCopy.BulkCopyTimeout = 360;
bulkCopy.DestinationTableName = "Appointment";
DataTable dataTable = new DataTable();
DataColumn col0 = dataTable.Columns.Add("Id", typeof(System.String));
col0.AllowDBNull = false;
DataColumn col1 = dataTable.Columns.Add("PatientCode", typeof(System.String));
col1.AllowDBNull = false;
DataColumn col2 = dataTable.Columns.Add("Username", typeof(System.String));
col2.AllowDBNull = false;
DataColumn col3 = dataTable.Columns.Add("RoomId", typeof(System.Int32));
col3.AllowDBNull = true;
DataColumn col4 = dataTable.Columns.Add("ServicesId", typeof(System.Int32));
col4.AllowDBNull = true;
DataColumn col5 = dataTable.Columns.Add("StatusId", typeof(System.String));
col5.AllowDBNull = true;
DataColumn col6 = dataTable.Columns.Add("AppointmentGroupId", typeof(System.Int32));
col6.AllowDBNull = true;
DataColumn col7 = dataTable.Columns.Add("Note", typeof(System.String));
col7.AllowDBNull = true;
DataColumn col8 = dataTable.Columns.Add("StartTime", typeof(System.DateTime));
col8.AllowDBNull = true;
DataColumn col9 = dataTable.Columns.Add("EndTime", typeof(System.DateTime));
col9.AllowDBNull = true;
DataColumn col10 = dataTable.Columns.Add("RosterId", typeof(System.String));
col10.AllowDBNull = true;
DataColumn col11 = dataTable.Columns.Add("IsComplete", typeof(System.Boolean));
col11.AllowDBNull = false;
DataColumn col12 = dataTable.Columns.Add("IsDisabled", typeof(System.Boolean));
col12.AllowDBNull = false;
DataColumn col13 = dataTable.Columns.Add("CreateUser", typeof(System.String));
col13.AllowDBNull = true;
DataColumn col14 = dataTable.Columns.Add("CreateDate", typeof(System.DateTime));
col14.AllowDBNull = false;
DataColumn col15 = dataTable.Columns.Add("UpdateUser", typeof(System.String));
col15.AllowDBNull = true;
DataColumn col16 = dataTable.Columns.Add("UpdateDate", typeof(System.DateTime));
col16.AllowDBNull = false;
bulkCopy.ColumnMappings.Add("Id", "Id");
bulkCopy.ColumnMappings.Add("PatientCode", "PatientCode");
bulkCopy.ColumnMappings.Add("Username", "Username");
bulkCopy.ColumnMappings.Add("RoomId", "RoomId");
bulkCopy.ColumnMappings.Add("ServicesId", "ServicesId");
bulkCopy.ColumnMappings.Add("StatusId", "StatusId");
bulkCopy.ColumnMappings.Add("AppointmentGroupId", "AppointmentGroupId");
bulkCopy.ColumnMappings.Add("Note", "Note");
bulkCopy.ColumnMappings.Add("StartTime", "StartTime");
bulkCopy.ColumnMappings.Add("EndTime", "EndTime");
bulkCopy.ColumnMappings.Add("RosterId", "RosterId");
bulkCopy.ColumnMappings.Add("IsComplete", "IsComplete");
bulkCopy.ColumnMappings.Add("IsDisabled", "IsDisabled");
bulkCopy.ColumnMappings.Add("CreateUser", "CreateUser");
bulkCopy.ColumnMappings.Add("CreateDate", "CreateDate");
bulkCopy.ColumnMappings.Add("UpdateUser", "UpdateUser");
bulkCopy.ColumnMappings.Add("UpdateDate", "UpdateDate");
foreach(AppointmentSystem.Entities.Appointment entity in entities)
{
if (entity.EntityState != EntityState.Added)
continue;
DataRow row = dataTable.NewRow();
row["Id"] = entity.Id;
row["PatientCode"] = entity.PatientCode;
row["Username"] = entity.Username;
row["RoomId"] = entity.RoomId.HasValue ? (object) entity.RoomId : System.DBNull.Value;
//.........这里部分代码省略.........
示例11: Insert
/// <summary>
/// Inserts a AppointmentSystem.Entities.Appointment object into the datasource using a transaction.
/// </summary>
/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
/// <param name="entity">AppointmentSystem.Entities.Appointment object to insert.</param>
/// <remarks>
/// After inserting into the datasource, the AppointmentSystem.Entities.Appointment object will be updated
/// to refelect any changes made by the datasource. (ie: identity or computed columns)
/// </remarks>
/// <returns>Returns true if operation is successful.</returns>
/// <exception cref="System.Exception">The command could not be executed.</exception>
/// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
/// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
public override bool Insert(TransactionManager transactionManager, AppointmentSystem.Entities.Appointment entity)
{
SqlDatabase database = new SqlDatabase(this._connectionString);
DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.Appointment_Insert", _useStoredProcedure);
database.AddInParameter(commandWrapper, "@Id", DbType.String, entity.Id );
database.AddInParameter(commandWrapper, "@PatientCode", DbType.StringFixedLength, entity.PatientCode );
database.AddInParameter(commandWrapper, "@Username", DbType.String, entity.Username );
database.AddInParameter(commandWrapper, "@RoomId", DbType.Int32, (entity.RoomId.HasValue ? (object) entity.RoomId : System.DBNull.Value));
database.AddInParameter(commandWrapper, "@ServicesId", DbType.Int32, (entity.ServicesId.HasValue ? (object) entity.ServicesId : System.DBNull.Value));
database.AddInParameter(commandWrapper, "@StatusId", DbType.AnsiString, entity.StatusId );
database.AddInParameter(commandWrapper, "@AppointmentGroupId", DbType.Int32, (entity.AppointmentGroupId.HasValue ? (object) entity.AppointmentGroupId : System.DBNull.Value));
database.AddInParameter(commandWrapper, "@Note", DbType.String, entity.Note );
database.AddInParameter(commandWrapper, "@StartTime", DbType.DateTime, (entity.StartTime.HasValue ? (object) entity.StartTime : System.DBNull.Value));
database.AddInParameter(commandWrapper, "@EndTime", DbType.DateTime, (entity.EndTime.HasValue ? (object) entity.EndTime : System.DBNull.Value));
database.AddInParameter(commandWrapper, "@RosterId", DbType.String, entity.RosterId );
database.AddInParameter(commandWrapper, "@IsComplete", DbType.Boolean, entity.IsComplete );
database.AddInParameter(commandWrapper, "@IsDisabled", DbType.Boolean, entity.IsDisabled );
database.AddInParameter(commandWrapper, "@CreateUser", DbType.String, entity.CreateUser );
database.AddInParameter(commandWrapper, "@CreateDate", DbType.DateTime, entity.CreateDate );
database.AddInParameter(commandWrapper, "@UpdateUser", DbType.String, entity.UpdateUser );
database.AddInParameter(commandWrapper, "@UpdateDate", DbType.DateTime, entity.UpdateDate );
int results = 0;
//Provider Data Requesting Command Event
OnDataRequesting(new CommandEventArgs(commandWrapper, "Insert", entity));
if (transactionManager != null)
{
results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
}
else
{
results = Utility.ExecuteNonQuery(database,commandWrapper);
}
entity.OriginalId = entity.Id;
entity.AcceptChanges();
//Provider Data Requested Command Event
OnDataRequested(new CommandEventArgs(commandWrapper, "Insert", entity));
return Convert.ToBoolean(results);
}
示例12: Insert
/// <summary>
/// Inserts a AppointmentSystem.Entities.AppointmentHistory object into the datasource using a transaction.
/// </summary>
/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
/// <param name="entity">AppointmentSystem.Entities.AppointmentHistory object to insert.</param>
/// <remarks>
/// After inserting into the datasource, the AppointmentSystem.Entities.AppointmentHistory object will be updated
/// to refelect any changes made by the datasource. (ie: identity or computed columns)
/// </remarks>
/// <returns>Returns true if operation is successful.</returns>
/// <exception cref="System.Exception">The command could not be executed.</exception>
/// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
/// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
public override bool Insert(TransactionManager transactionManager, AppointmentSystem.Entities.AppointmentHistory entity)
{
SqlDatabase database = new SqlDatabase(this._connectionString);
DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.AppointmentHistory_Insert", _useStoredProcedure);
database.AddInParameter(commandWrapper, "@Guid", DbType.Guid, entity.Guid );
database.AddInParameter(commandWrapper, "@AppointmentId", DbType.String, entity.AppointmentId );
database.AddInParameter(commandWrapper, "@Note", DbType.String, entity.Note );
database.AddInParameter(commandWrapper, "@CreateUser", DbType.String, entity.CreateUser );
database.AddInParameter(commandWrapper, "@CreateDate", DbType.DateTime, entity.CreateDate );
int results = 0;
//Provider Data Requesting Command Event
OnDataRequesting(new CommandEventArgs(commandWrapper, "Insert", entity));
if (transactionManager != null)
{
results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
}
else
{
results = Utility.ExecuteNonQuery(database,commandWrapper);
}
entity.OriginalGuid = entity.Guid;
entity.AcceptChanges();
//Provider Data Requested Command Event
OnDataRequested(new CommandEventArgs(commandWrapper, "Insert", entity));
return Convert.ToBoolean(results);
}
示例13: BulkInsert
/// <summary>
/// Lets you efficiently bulk insert many entities to the database.
/// </summary>
/// <param name="transactionManager">The transaction manager.</param>
/// <param name="entities">The entities.</param>
/// <remarks>
/// After inserting into the datasource, the AppointmentSystem.Entities.AppointmentHistory object will be updated
/// to refelect any changes made by the datasource. (ie: identity or computed columns)
/// </remarks>
public override void BulkInsert(TransactionManager transactionManager, TList<AppointmentSystem.Entities.AppointmentHistory> entities)
{
//System.Data.SqlClient.SqlBulkCopy bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);
System.Data.SqlClient.SqlBulkCopy bulkCopy = null;
if (transactionManager != null && transactionManager.IsOpen)
{
System.Data.SqlClient.SqlConnection cnx = transactionManager.TransactionObject.Connection as System.Data.SqlClient.SqlConnection;
System.Data.SqlClient.SqlTransaction transaction = transactionManager.TransactionObject as System.Data.SqlClient.SqlTransaction;
bulkCopy = new System.Data.SqlClient.SqlBulkCopy(cnx, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints, transaction); //, null);
}
else
{
bulkCopy = new System.Data.SqlClient.SqlBulkCopy(this._connectionString, System.Data.SqlClient.SqlBulkCopyOptions.CheckConstraints); //, null);
}
bulkCopy.BulkCopyTimeout = 360;
bulkCopy.DestinationTableName = "AppointmentHistory";
DataTable dataTable = new DataTable();
DataColumn col0 = dataTable.Columns.Add("Guid", typeof(System.Guid));
col0.AllowDBNull = false;
DataColumn col1 = dataTable.Columns.Add("AppointmentId", typeof(System.String));
col1.AllowDBNull = false;
DataColumn col2 = dataTable.Columns.Add("Note", typeof(System.String));
col2.AllowDBNull = true;
DataColumn col3 = dataTable.Columns.Add("CreateUser", typeof(System.String));
col3.AllowDBNull = true;
DataColumn col4 = dataTable.Columns.Add("CreateDate", typeof(System.DateTime));
col4.AllowDBNull = false;
bulkCopy.ColumnMappings.Add("Guid", "Guid");
bulkCopy.ColumnMappings.Add("AppointmentId", "AppointmentId");
bulkCopy.ColumnMappings.Add("Note", "Note");
bulkCopy.ColumnMappings.Add("CreateUser", "CreateUser");
bulkCopy.ColumnMappings.Add("CreateDate", "CreateDate");
foreach(AppointmentSystem.Entities.AppointmentHistory entity in entities)
{
if (entity.EntityState != EntityState.Added)
continue;
DataRow row = dataTable.NewRow();
row["Guid"] = entity.Guid;
row["AppointmentId"] = entity.AppointmentId;
row["Note"] = entity.Note;
row["CreateUser"] = entity.CreateUser;
row["CreateDate"] = entity.CreateDate;
dataTable.Rows.Add(row);
}
// send the data to the server
bulkCopy.WriteToServer(dataTable);
// update back the state
foreach(AppointmentSystem.Entities.AppointmentHistory entity in entities)
{
if (entity.EntityState != EntityState.Added)
continue;
entity.AcceptChanges();
}
}
示例14: Insert
/// <summary>
/// Inserts a AppointmentSystem.Entities.SmsLog object into the datasource using a transaction.
/// </summary>
/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
/// <param name="entity">AppointmentSystem.Entities.SmsLog object to insert.</param>
/// <remarks>
/// After inserting into the datasource, the AppointmentSystem.Entities.SmsLog object will be updated
/// to refelect any changes made by the datasource. (ie: identity or computed columns)
/// </remarks>
/// <returns>Returns true if operation is successful.</returns>
/// <exception cref="System.Exception">The command could not be executed.</exception>
/// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
/// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
public override bool Insert(TransactionManager transactionManager, AppointmentSystem.Entities.SmsLog entity)
{
SqlDatabase database = new SqlDatabase(this._connectionString);
DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.SmsLog_Insert", _useStoredProcedure);
database.AddInParameter(commandWrapper, "@Id", DbType.Guid, entity.Id );
database.AddInParameter(commandWrapper, "@SmsId", DbType.Int64, entity.SmsId );
database.AddInParameter(commandWrapper, "@Message", DbType.String, entity.Message );
database.AddInParameter(commandWrapper, "@Mobile", DbType.AnsiString, entity.Mobile );
database.AddInParameter(commandWrapper, "@Title", DbType.String, entity.Title );
database.AddInParameter(commandWrapper, "@SendTime", DbType.DateTime, entity.SendTime );
database.AddInParameter(commandWrapper, "@RealSendTime", DbType.DateTime, (entity.RealSendTime.HasValue ? (object) entity.RealSendTime : System.DBNull.Value));
database.AddInParameter(commandWrapper, "@IsSent", DbType.Boolean, entity.IsSent );
database.AddInParameter(commandWrapper, "@IsDisabled", DbType.Boolean, entity.IsDisabled );
database.AddInParameter(commandWrapper, "@CreateUser", DbType.String, entity.CreateUser );
database.AddInParameter(commandWrapper, "@CreateDate", DbType.DateTime, entity.CreateDate );
database.AddInParameter(commandWrapper, "@UpdateUser", DbType.String, entity.UpdateUser );
database.AddInParameter(commandWrapper, "@UpdateDate", DbType.DateTime, entity.UpdateDate );
int results = 0;
//Provider Data Requesting Command Event
OnDataRequesting(new CommandEventArgs(commandWrapper, "Insert", entity));
if (transactionManager != null)
{
results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
}
else
{
results = Utility.ExecuteNonQuery(database,commandWrapper);
}
entity.OriginalId = entity.Id;
entity.AcceptChanges();
//Provider Data Requested Command Event
OnDataRequested(new CommandEventArgs(commandWrapper, "Insert", entity));
return Convert.ToBoolean(results);
}
示例15: ExecuteScalar
/// <summary>
/// Executes the scalar.
/// </summary>
/// <param name="transactionManager">The transaction manager.</param>
/// <param name="commandWrapper">The command wrapper.</param>
/// <returns></returns>
public override object ExecuteScalar(TransactionManager transactionManager, DbCommand commandWrapper)
{
Database database = transactionManager.Database;
return database.ExecuteScalar(commandWrapper, transactionManager.TransactionObject);
}