Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
OrderData.cs
Package: CSharpprogramming.rar [view]
Upload User: lxycoco
Upload Date: 2022-07-21
Package Size: 38457k
Code Size: 2k
Category:
CSharp
Development Platform:
Others
- using System;
- using System.EnterpriseServices;
- using System.Data;
- using System.Data.SqlClient;
- namespace Wrox.ProCSharp.EnterpriseServices
- {
- public interface IOrderUpdate
- {
- void Insert(Order order);
- void Update(Order order);
- }
- [Transaction(TransactionOption.Required)]
- [EventTrackingEnabled(true)]
- [ConstructionEnabled(true, Default="server=localhost;database=northwind;trusted_connection=true")]
- public class OrderData : ServicedComponent, IOrderUpdate
- {
- private string connectionString = null;
- public OrderData()
- {
- }
- #region IUpdateOrder Members
- [AutoComplete()]
- public void Insert(Order order)
- {
- SqlConnection connection = new SqlConnection(connectionString);
- try
- {
- SqlCommand command = connection.CreateCommand();
- command.CommandText = "INSERT INTO Orders (CustomerId, OrderDate, ShipAddress, ShipCity, ShipCountry)" +
- "VALUES(@CustomerId, @OrderDate, @ShipAddress, @ShipCity, @ShipCountry)";
- command.Parameters.Add("@CustomerId", order.CustomerId);
- command.Parameters.Add("@OrderDate", order.OrderDate);
- command.Parameters.Add("@ShipAddress", order.ShipAddress);
- command.Parameters.Add("@ShipCity", order.ShipCity);
- command.Parameters.Add("@ShipCountry", order.ShipCountry);
- connection.Open();
- int rows = command.ExecuteNonQuery();
- if (rows != 1)
- throw new Exception("error");
- command.CommandText = "SELECT @@IDENTITY AS 'Identity'";
- object identity = command.ExecuteScalar();
- order.SetOrderId(Convert.ToInt32(identity));
- OrderLineData updateOrderLine = new OrderLineData();
- foreach (OrderLine orderLine in order.OrderLines)
- {
- updateOrderLine.Insert(order.OrderId, orderLine);
- }
- }
- catch (Exception ex)
- {
- System.Windows.Forms.MessageBox.Show(ex.Message);
- throw;
- }
- finally
- {
- connection.Close();
- }
- }
- public void Update(Order order)
- {
- }
- #endregion
- protected override void Construct(string s)
- {
- connectionString = s;
- }
- }
- }