本文整理汇总了C#中Select.SaveAll方法的典型用法代码示例。如果您正苦于以下问题:C# Select.SaveAll方法的具体用法?C# Select.SaveAll怎么用?C# Select.SaveAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Select
的用法示例。
在下文中一共展示了Select.SaveAll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: change_vessel
//end package type
#endregion
#region move container and orders
/// <summary>
/// move container to a different vessel
/// 1. update Order table set VesselID = 'new vessel id', VesselLastUpdated = current date where containerid = N .Equivalent to access "ContainerVesselUpdateVesselQuery"
/// 2. update Order table set ETS = VoyageETSSubTable.ETS, ETA=VoyageETSSubTable.ETA where containerid = N .Equivalent to access "ContainerVesselUpdateDatesQuery"
/// 3. update Container table set VoyageID = 'new voyage id' where containerid = N .Equivalent to access ""ContainerVesselUpdateContainerQuery"
/// </summary>
/// <param name="containerid"></param>
protected bool change_vessel(int containerid, int vesselid)
{
bool _changed = false;
DateTime _currentdate = DateTime.Now;
//for testing
//containerid = 2332;
using (SharedDbConnectionScope _sc = new SharedDbConnectionScope())
{
using (System.Transactions.TransactionScope _ts = new System.Transactions.TransactionScope())
{
try
{
//for testing q1
//string _q1 = "SELECT o.OrderID, VesselId, VesselLastUpdated FROM OrderTable as o INNER JOIN " +
//"ContainerTable AS c INNER JOIN " +
//"ContainerSubTable AS s ON c.ContainerID = s.ContainerID ON o.OrderNumber = s.OrderNumber WHERE (c.ContainerID = 2332);";
//object[] _p1 = { containerid };
//int _result = new SubSonic.CodingHorror().ExecuteScalar<int>(_q1, _p1);
OrderTableCollection _q2 = new Select().From(DAL.Logistics.Tables.OrderTable)
.InnerJoin(DAL.Logistics.ContainerSubTable.OrderNumberColumn, DAL.Logistics.OrderTable.OrderNumberColumn)
.InnerJoin(DAL.Logistics.ContainerTable.ContainerIDColumn, DAL.Logistics.ContainerSubTable.ContainerIDColumn)
.Where(DAL.Logistics.ContainerTable.ContainerIDColumn).IsEqualTo(containerid).ExecuteAsCollection<OrderTableCollection>();
for (int _ix = 0; _ix < _q2.Count; _ix++)
{
_q2[_ix].VesselID = vesselid;
_q2[_ix].VesselLastUpdated = _currentdate;
}
_q2.SaveAll();
//does not work because the triggers on the ordertable cause errors
//Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression
//1st statement paramatised and using subsonic.codinghorror, table aliases prevent 'multi-part identifier can't be bound' tsql error
//string _q1 = "UPDATE OrderTable " +
// "SET VesselID = @vesselid, VesselLastUpdated = @lastupdated " +
// "FROM OrderTable INNER JOIN " +
// "ContainerTable AS c INNER JOIN " +
// "ContainerSubTable AS s ON c.ContainerID = s.ContainerID ON OrderTable.OrderNumber = s.OrderNumber " +
// "WHERE (c.ContainerID = @containerid);";
//
//object[] _p1 = { vesselid, _currentdate, containerid };
//int _result = new SubSonic.CodingHorror().ExecuteScalar<int>(_q1, _p1);
//for testing q2
//SELECT c.ContainerID, ets.ets, eta.eta, OrderTable.OrderID FROM ContainerTable AS c INNER JOIN
//ContainerSubTable AS s ON c.ContainerID = s.ContainerID INNER JOIN
//VoyageTable AS v INNER JOIN VoyageETASubTable AS eta ON v.VoyageID = eta.VoyageID
//INNER JOIN VoyageETSSubTable AS ets ON v.VoyageID = ets.VoyageID INNER JOIN
//OrderTable ON v.VoyageID = OrderTable.VesselID ON s.OrderNumber = OrderTable.OrderNumber
//WHERE (c.ContainerID = @containerid);
//object[] _p2 = { containerid };
//_result = new SubSonic.CodingHorror().ExecuteScalar<int>(_q2, _p2);
//q2
string[] _cols2 = { "OrderTable.OrderID", "VoyageETSSubTable.ETS", "VoyageETASubTable.ETA" };
DataTable _dt = new Select(_cols2).From(DAL.Logistics.Tables.OrderTable)
.InnerJoin(DAL.Logistics.ContainerSubTable.OrderIDColumn, DAL.Logistics.OrderTable.OrderIDColumn)
.InnerJoin(DAL.Logistics.ContainerTable.ContainerIDColumn, DAL.Logistics.ContainerSubTable.ContainerIDColumn)
.InnerJoin(DAL.Logistics.VoyageTable.VoyageIDColumn, DAL.Logistics.OrderTable.VesselIDColumn)
.InnerJoin(DAL.Logistics.VoyageETSSubTable.VoyageIDColumn, DAL.Logistics.VoyageTable.VoyageIDColumn)
.InnerJoin(DAL.Logistics.VoyageETASubTable.VoyageIDColumn, DAL.Logistics.VoyageTable.VoyageIDColumn)
.Where(DAL.Logistics.ContainerTable.ContainerIDColumn).IsEqualTo(containerid).ExecuteDataSet().Tables[0];
if (_dt.Rows.Count > 0)
{
OrderTableCollection _ot = new OrderTableCollection();
for (int _ix = 0; _ix < _dt.Rows.Count; _ix++)
{
int _id = wwi_func.vint(_dt.Rows[_ix]["OrderID"].ToString());
DateTime _ets = wwi_func.vdatetime(_dt.Rows[_ix]["Ets"].ToString());
DateTime _eta = wwi_func.vdatetime(_dt.Rows[_ix]["Eta"].ToString());
//update
OrderTable _tb = new OrderTable(_id);
_tb.Ets = _ets;
_tb.Eta = _eta;
_ot.Add(_tb);
}
_ot.SaveAll();
}
//does not work because the triggers on the ordertable cause errors
//2nd statement paramatised and using subsonic.codinghorror, table aliases prevent 'multi-part identifier can't be bound' tsql error
//string _q2 = "UPDATE OrderTable " +
// "SET ETS = ets.ETS, ETA = eta.ETA " +
// "FROM ContainerTable AS c INNER JOIN " +
// "ContainerSubTable AS s ON c.ContainerID = s.ContainerID INNER JOIN " +
// "VoyageTable AS v INNER JOIN " +
// "VoyageETASubTable AS eta ON v.VoyageID = eta.VoyageID INNER JOIN " +
// "VoyageETSSubTable AS ets ON v.VoyageID = ets.VoyageID INNER JOIN " +
//.........这里部分代码省略.........
示例2: mark_loaded_on_board
//end package type
#endregion
#region mark loaded
/// <summary>
/// mark container as loaded on board
/// can't paramatise and use subsonic.codinghorror with table aliases prevent 'multi-part identifier can't be bound' tsql error and
/// can't use an update query if multiple records are to be updated as it crashes the triggers on OrderTable:
/// Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression
/// 1. update container table set loadedonboard = -1, updated = current date where containerid = N .Equivalent to access "UpdateContainerLoadedQuery"
/// 2. update all in order table set loadedonboard = -1 where containerid = N .Equivalent to access "UpdateOrderLoadedOnBoardQuery"
/// 3. update deliverysubtable table set currentstatusid=1 where currentstatusid=12, statusdate = current date, currentstatusdate = [VoyageETSSubTable.ETS]
/// where containerid = N .Equivalent to access "UpdateDeliveryStatusOnBoardQuery"
/// </summary>
/// <param name="containerid">int</param>
protected bool mark_loaded_on_board(int containerid)
{
//method using subsonic.codinghorror for update statements 2 and 3 as subsonic does not handle aliasing well
//and we need to get around the multi-part identifier can't be bound problem
//int _onboard = 0;
bool _onboard = true;
DateTime _currentdate = DateTime.Now;
int _result = 0;
int _newstatusid = 1;
int _currentstatusid = 12;
//containerid = 125;
//containerid 7 or 115 or 16316 or 125 was good for testing
using (SharedDbConnectionScope _sc = new SharedDbConnectionScope())
{
using (System.Transactions.TransactionScope _ts = new System.Transactions.TransactionScope())
{
using (SqlConnection _cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["PublishipSQLConnectionString"].ToString()))
{
try
{
//1. update container table
Update _q1 = new Update(DAL.Logistics.Tables.ContainerTable);
_q1.Set(DAL.Logistics.ContainerTable.LoadedOnBoardColumn).EqualTo(_onboard);
_q1.Set(DAL.Logistics.ContainerTable.UpdatedColumn).EqualTo(_currentdate);
_q1.Where(DAL.Logistics.ContainerTable.ContainerIDColumn).IsEqualTo(containerid);
//string _test = _q1.ToString();
_result = _q1.Execute();
//end
//2. update ordertable
OrderTableCollection _q2 = new Select().From(DAL.Logistics.Tables.OrderTable)
.InnerJoin(DAL.Logistics.ContainerSubTable.OrderIDColumn, DAL.Logistics.OrderTable.OrderIDColumn)
.InnerJoin(DAL.Logistics.ContainerTable.ContainerIDColumn, DAL.Logistics.ContainerSubTable.ContainerIDColumn)
.Where(DAL.Logistics.ContainerTable.ContainerIDColumn).IsEqualTo(containerid).ExecuteAsCollection<OrderTableCollection>();
for (int _ix = 0; _ix < _q2.Count; _ix++)
{
_q2[_ix].ShippedOnBoard = _onboard;
}
_q2.SaveAll();
//end
//3. get data we need ets from VoyageEtsSubtable
//used containerid 125 for testing
//return a datatable, can't use a reader here as you would get an error when you try and process the deliverysubtable
DeliverySubTableCollection _q3 = new DeliverySubTableCollection();
string[] _cols = { "DeliverySubTable.DeliveryID", "VoyageETSSubTable.ETS" };
DataTable _dt = new Select(_cols).From(DAL.Logistics.Tables.DeliverySubTable)
.InnerJoin(DAL.Logistics.ContainerSubTable.OrderNumberColumn, DAL.Logistics.DeliverySubTable.OrderNumberColumn)
.InnerJoin(DAL.Logistics.ContainerTable.ContainerIDColumn, DAL.Logistics.ContainerSubTable.ContainerIDColumn)
.InnerJoin(DAL.Logistics.OrderTable.OrderIDColumn, DAL.Logistics.ContainerSubTable.OrderIDColumn)
.InnerJoin(DAL.Logistics.VoyageTable.VoyageIDColumn, DAL.Logistics.ContainerTable.VoyageIDColumn)
.InnerJoin(DAL.Logistics.VoyageETSSubTable.VoyageIDColumn, DAL.Logistics.VoyageTable.VoyageIDColumn)
.Where(DAL.Logistics.ContainerTable.ContainerIDColumn).IsEqualTo(containerid)
.And(DAL.Logistics.DeliverySubTable.CurrentStatusIDColumn).IsEqualTo(_currentstatusid).ExecuteDataSet().Tables[0];
if (_dt.Rows.Count > 0)
{
for (int _ix = 0; _ix < _dt.Rows.Count; _ix++)
{
int _id = wwi_func.vint(_dt.Rows[_ix]["DeliveryID"].ToString());
DateTime _ets = wwi_func.vdatetime(_dt.Rows[_ix]["ETS"].ToString());
//update
DeliverySubTable _tb = new DeliverySubTable(_id);
_tb.CurrentStatusID = _newstatusid;
_tb.StatusDate = _currentdate;
_tb.CurrentStatusDate = _ets;
_q3.Add(_tb);
}
_q3.SaveAll();
}
//end
}
catch (Exception ex)
{
_onboard = false;
string _er = ex.Message.ToString();
this.dxlblErr.Text = _er;
this.dxpnlErr.ClientVisible = true;
}//end try/catch
}//end using SqlConnection
}//end using TransactionScope
//.........这里部分代码省略.........