OrderLineData.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:2k
- using System;
- using System.EnterpriseServices;
- using System.Data;
- using System.Data.SqlClient;
- namespace Wrox.ProCSharp.EnterpriseServices
- {
- public interface IOrderLineUpdate
- {
- void Insert(int orderId, OrderLine orderDetail);
- void Update(OrderLine orderDetail);
- }
- [Transaction(TransactionOption.Required)]
- [EventTrackingEnabled(true)]
- [ConstructionEnabled(true, Default="server=localhost;database=northwind;trusted_connection=true")]
- public class OrderLineData : ServicedComponent, IOrderLineUpdate
- {
- public OrderLineData()
- {
- }
- private string connectionString = null;
- #region IOrderDetailUpdate Members
- public void Insert(int orderId, OrderLine orderDetail)
- {
- SqlConnection connection = new SqlConnection(connectionString);
- try
- {
- SqlCommand command = connection.CreateCommand();
- command.CommandText = "INSERT INTO [Order Details] (OrderId, ProductId, UnitPrice, Quantity)" +
- "VALUES(@OrderId, @ProductId, @UnitPrice, @Quantity)";
- command.Parameters.Add("@OrderId", orderId);
- command.Parameters.Add("@ProductId", orderDetail.ProductId);
- command.Parameters.Add("@UnitPrice", orderDetail.UnitPrice);
- command.Parameters.Add("@Quantity", orderDetail.Quantity);
- connection.Open();
- int rows = command.ExecuteNonQuery();
- if (rows != 1)
- throw new Exception("error");
- }
- catch (Exception ex)
- {
- System.Windows.Forms.MessageBox.Show(ex.Message);
- ContextUtil.SetAbort();
- throw;
- }
- finally
- {
- connection.Close();
- }
- ContextUtil.SetComplete();
- }
- protected override void Construct(string s)
- {
- connectionString = s;
- }
- public void Update(OrderLine orderDetail)
- {
- // TODO: Add UpdateOrderDetail.Update implementation
- }
- #endregion
- }
- }