本人嘗試用List<T>寫了一個數據庫Demo,程序採用了分層的結構,使用了.NET REMOTING技術。由於代碼結構簡單,不想多說,下面是各層代碼:
1.實體層(dll文件名:Sales_Entity)
using
System;
using System.Collections.Generic;
using System.Text;
namespace GAO.Sales_Entity
... {
public enum DataStatus
...{
dsNew,
dsModify,
dsDelete,
dsNormal
}
}
using System.Collections.Generic;
using System.Text;
namespace GAO.Sales_Entity
... {
public enum DataStatus
...{
dsNew,
dsModify,
dsDelete,
dsNormal
}
}
using
System;
using System.Collections;
namespace GAO.Sales_Entity
... {
/**//// <summary>
/// 客戶實體類
/// </summary>
[Serializable]
public class Customer
...{
私有字段#region 私有字段
private DataStatus m_DB_Action = DataStatus.dsNormal; //操作方法 Insert:新增 Update:修改; Delete:刪除
private string m_CustomerCode;
private string m_CustomerName;
private string m_Address;
private string m_Contact;
private string m_Phone;
private string m_Email;
private int m_AutoID;
#endregion
公共屬性#region 公共屬性
public DataStatus DB_Action
...{
set
...{
this.m_DB_Action = value;
}
get
...{
return this.m_DB_Action;
}
}
public string CustomerCode
...{
set
...{
this.m_CustomerCode = value;
}
get
...{
return this.m_CustomerCode;
}
}
public string CustomerName
...{
set
...{
this.m_CustomerName = value;
}
get
...{
return this.m_CustomerName;
}
}
public string Address
...{
set
...{
this.m_Address = value;
}
get
...{
return this.m_Address;
}
}
public string Contact
...{
set
...{
this.m_Contact = value;
}
get
...{
return this.m_Contact;
}
}
public string Phone
...{
set
...{
this.m_Phone = value;
}
get
...{
return this.m_Phone;
}
}
public string Email
...{
set
...{
this.m_Email = value;
}
get
...{
return this.m_Email;
}
}
public int AutoID
...{
set ...{ this.m_AutoID = value; }
get ...{ return this.m_AutoID; }
}
#endregion
}
}
using System.Collections;
namespace GAO.Sales_Entity
... {
/**//// <summary>
/// 客戶實體類
/// </summary>
[Serializable]
public class Customer
...{
私有字段#region 私有字段
private DataStatus m_DB_Action = DataStatus.dsNormal; //操作方法 Insert:新增 Update:修改; Delete:刪除
private string m_CustomerCode;
private string m_CustomerName;
private string m_Address;
private string m_Contact;
private string m_Phone;
private string m_Email;
private int m_AutoID;
#endregion
公共屬性#region 公共屬性
public DataStatus DB_Action
...{
set
...{
this.m_DB_Action = value;
}
get
...{
return this.m_DB_Action;
}
}
public string CustomerCode
...{
set
...{
this.m_CustomerCode = value;
}
get
...{
return this.m_CustomerCode;
}
}
public string CustomerName
...{
set
...{
this.m_CustomerName = value;
}
get
...{
return this.m_CustomerName;
}
}
public string Address
...{
set
...{
this.m_Address = value;
}
get
...{
return this.m_Address;
}
}
public string Contact
...{
set
...{
this.m_Contact = value;
}
get
...{
return this.m_Contact;
}
}
public string Phone
...{
set
...{
this.m_Phone = value;
}
get
...{
return this.m_Phone;
}
}
public string Email
...{
set
...{
this.m_Email = value;
}
get
...{
return this.m_Email;
}
}
public int AutoID
...{
set ...{ this.m_AutoID = value; }
get ...{ return this.m_AutoID; }
}
#endregion
}
}
2.數據訪問層(dll文件名:Sales_DAL_MSSQL)
/**/
/*
Auto generate code
*/
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using GAO.Sales_Entity;
namespace GAO.Sales_DAL_MSSQL
... {
/**//// <summary>
/// 客戶信息訪問類
/// </summary>
public partial class CustomerInfo
...{
private static readonly string m_ERP_STUDY = ConfigurationManager.ConnectionStrings["ERP_STUDY"].ConnectionString;
private static readonly string m_SelectCustomer = "SELECT AutoID, CustomerCode, CustomerName, Address, Contact, Phone, Email FROM dbo.Customer ";
private static readonly string m_CustomerList = "SELECT CustomerCode, CustomerName FROM dbo.Customer ";
private static readonly string m_UpdateCustomer = "UPDATE dbo.Customer SET CustomerCode=@CustomerCode"
+ ",CustomerName=@CustomerName "
+ ",Address=@Address "
+ ",Contact=@Contact, Phone=@Phone, Email=@Email WHERE AutoID=@AutoID ";
private static readonly string m_DeleteCustomer = "DELETE FROM dbo.Customer WHERE AutoID=@AutoID ";
private static readonly string m_InsertCustomer = "INSERT INTO dbo.Customer(CustomerCode, CustomerName, Address, Contact, Phone, Email) "
+ "VALUES(@CustomerCode, @CustomerName, @Address, @Contact, @Phone, @Email) SELECT @p1=@@IDENTITY ";
public int Update(Customer cust)
...{
int count = 0;
try
...{
switch (cust.DB_Action)
...{
case DataStatus.dsNew :
count = this.InsertCommand(cust);
break;
case DataStatus.dsModify :
count = this.UpdateCommand(cust);
break;
case DataStatus.dsDelete :
count = this.DeleteCommand(cust);
break;
default :
break;
}
}
catch (Exception ex)
...{
throw new Exception(ex.Message);
}
return count;
}
private int InsertCommand(Customer cust)
...{
using (SqlConnection conn = new SqlConnection(m_ERP_STUDY))
...{
try
...{
SqlCommand cmd = new SqlCommand(m_InsertCustomer, conn);
cmd.Parameters.Add("@CustomerCode", SqlDbType.Char, 3, "CustomerCode").Value = cust.CustomerCode;
cmd.Parameters.Add("@CustomerName", SqlDbType.NVarChar, 50, "CustomerName").Value = cust.CustomerName;
cmd.Parameters.Add("@Address", SqlDbType.NVarChar, 50, "Address").Value = cust.Address;
cmd.Parameters.Add("@Contact", SqlDbType.NVarChar, 10, "Contact").Value = cust.Contact;
cmd.Parameters.Add("@Phone", SqlDbType.VarChar, 20, "Phone").Value = cust.Phone;
cmd.Parameters.Add("@Email", SqlDbType.VarChar, 30, "Email").Value = cust.Email;
SqlParameter para = cmd.Parameters.Add("@p1", SqlDbType.Int);
para.Direction = ParameterDirection.Output;
conn.Open();
cmd.ExecuteNonQuery();
return (int)para.Value;
}
catch (Exception ex)
...{
throw new Exception(ex.Message);
}
}
}
private int UpdateCommand(Customer cust)
...{
using (SqlConnection conn = new SqlConnection(m_ERP_STUDY))
...{
try
...{
SqlCommand cmd = new SqlCommand(m_UpdateCustomer, conn);
cmd.Parameters.Add("@CustomerCode", SqlDbType.Char, 3, "CustomerCode").Value = cust.CustomerCode;
cmd.Parameters.Add("@CustomerName", SqlDbType.NVarChar, 50, "CustomerName").Value = cust.CustomerName;
cmd.Parameters.Add("@Address", SqlDbType.NVarChar, 50, "Address").Value = cust.Address;
cmd.Parameters.Add("@Contact", SqlDbType.NVarChar, 10, "Contact").Value = cust.Contact;
cmd.Parameters.Add("@Phone", SqlDbType.VarChar, 20, "Phone").Value = cust.Phone;
cmd.Parameters.Add("@Email", SqlDbType.VarChar, 30, "Email").Value = cust.Email;
cmd.Parameters.Add("@AutoID", SqlDbType.Int, 4, "AutoID").Value = cust.AutoID;
conn.Open();
return cmd.ExecuteNonQuery();
}
catch (Exception ex)
...{
throw new Exception(ex.Message);
}
}
}
private int DeleteCommand(Customer cust)
...{
using (SqlConnection conn = new SqlConnection(m_ERP_STUDY))
...{
try
...{
SqlCommand cmd = new SqlCommand(m_DeleteCustomer, conn);
cmd.Parameters.Add("@AutoID", SqlDbType.Int, 4, "AutoID").Value = cust.AutoID;
conn.Open();
return cmd.ExecuteNonQuery();
}
catch (Exception ex)
...{
throw new Exception(ex.Message);
}
}
}
public int Update(List<Customer> custList)
...{
for (int i = 0; i < custList.Count; i++)
...{
this.Update(custList[i]);
}
return 1;
}
public Customer DBToEnitity(IDataReader dr)
...{
Customer cust = new Customer();
cust.DB_Action = DataStatus.dsNormal;
cust.CustomerCode = dr["CustomerCode"].ToString();
cust.CustomerName = dr["CustomerName"].ToString();
cust.Address = dr["Address"].ToString();
cust.Contact = dr["Contact"].ToString();
cust.Phone = dr["Phone"].ToString();
cust.Email = dr["Email"].ToString();
cust.AutoID = int.Parse(dr["AutoID"].ToString());
return cust;
}
/**//*public void Update(DataSet changeDS)
{
using (SqlConnection conn = new SqlConnection(m_ERP_STUDY))
{
try
{
SqlDataAdapter ad = new SqlDataAdapter();
System.Data.Common.DataTableMapping tbMap = new System.Data.Common.DataTableMapping();
tbMap.SourceTable = "dbo.Customer";
tbMap.DataSetTable = "dsCustomer";
tbMap.ColumnMappings.Add("AutoID", "AutoID");
tbMap.ColumnMappings.Add("CustomerCode", "CustomerCode");
tbMap.ColumnMappings.Add("CustomerName", "CustomerName");
tbMap.ColumnMappings.Add("Address", "Address");
tbMap.ColumnMappings.Add("Contact", "Contact");
tbMap.ColumnMappings.Add("Phone", "Phone");
tbMap.ColumnMappings.Add("Email", "Email");
ad.TableMappings.Add(tbMap);
ad.UpdateCommand = GetCommand(m_UpdateCustomer, conn);
ad.UpdateCommand.Parameters.Add(new SqlParameter("@CustomerCode", SqlDbType.Char, 3, ParameterDirection.Input, 0, 0, "CustomerCode", DataRowVersion.Current, false, null, "", "", ""));
ad.UpdateCommand.Parameters.Add(new SqlParameter("OldCustomerCode", SqlDbType.Char, 3, ParameterDirection.Input, 0, 0, "CustomerCode", DataRowVersion.Original, false, null, "", "", ""));
ad.UpdateCommand.Parameters.Add(new SqlParameter("@CustomerName", SqlDbType.NVarChar, 50, ParameterDirection.Input, 0, 0, "CustomerName", DataRowVersion.Current, false, null, "", "", ""));
ad.UpdateCommand.Parameters.Add(new SqlParameter("@Address", SqlDbType.NVarChar, 50, ParameterDirection.Input, 0, 0, "Address", DataRowVersion.Current, false, null, "", "", ""));
ad.UpdateCommand.Parameters.Add(new SqlParameter("@Contact", SqlDbType.NVarChar, 10, ParameterDirection.Input, 0, 0, "Contact", DataRowVersion.Current, false, null, "", "", ""));
ad.UpdateCommand.Parameters.Add(new SqlParameter("@Phone", SqlDbType.NVarChar, 20, ParameterDirection.Input, 0, 0, "Phone", DataRowVersion.Current, false, null, "", "", ""));
ad.UpdateCommand.Parameters.Add(new SqlParameter("@Email", SqlDbType.NVarChar, 30, ParameterDirection.Input, 0, 0, "Email", DataRowVersion.Current, false, null, "", "", ""));
ad.DeleteCommand = GetCommand(m_DeleteCustomer, conn);
ad.DeleteCommand.Parameters.Add(new SqlParameter("@OldCustomerCode", SqlDbType.Char, 3, ParameterDirection.Input, 0, 0, "CustomerCode", DataRowVersion.Original, false, null, "", "", ""));
ad.InsertCommand = GetCommand(m_InsertCustomer, conn);
ad.InsertCommand.Parameters.Add(new SqlParameter("@CustomerCode", SqlDbType.Char, 3, ParameterDirection.Input, 0, 0, "CustomerCode", DataRowVersion.Current, false, null, "", "", ""));
ad.InsertCommand.Parameters.Add(new SqlParameter("@CustomerName", SqlDbType.NVarChar, 50, ParameterDirection.Input, 0, 0, "CustomerName", DataRowVersion.Current, false, null, "", "", ""));
ad.InsertCommand.Parameters.Add(new SqlParameter("@Address", SqlDbType.NVarChar, 50, ParameterDirection.Input, 0, 0, "Address", DataRowVersion.Current, false, null, "", "", ""));
ad.InsertCommand.Parameters.Add(new SqlParameter("@Contact", SqlDbType.NVarChar, 10, ParameterDirection.Input, 0, 0, "Contact", DataRowVersion.Current, false, null, "", "", ""));
ad.InsertCommand.Parameters.Add(new SqlParameter("@Phone", SqlDbType.NVarChar, 20, ParameterDirection.Input, 0, 0, "Phone", DataRowVersion.Current, false, null, "", "", ""));
ad.InsertCommand.Parameters.Add(new SqlParameter("@Email", SqlDbType.NVarChar, 30, ParameterDirection.Input, 0, 0, "Email", DataRowVersion.Current, false, null, "", "", ""));
conn.Open();
// ad.AcceptChangesDuringUpdate = true;
ad.Update(changeDS, "dbo.Customer");
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
private SqlCommand GetCommand(string CommandText, SqlConnection conn)
{
return new SqlCommand(CommandText, conn);
}*/
}
}
Auto generate code
*/
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using GAO.Sales_Entity;
namespace GAO.Sales_DAL_MSSQL
... {
/**//// <summary>
/// 客戶信息訪問類
/// </summary>
public partial class CustomerInfo
...{
private static readonly string m_ERP_STUDY = ConfigurationManager.ConnectionStrings["ERP_STUDY"].ConnectionString;
private static readonly string m_SelectCustomer = "SELECT AutoID, CustomerCode, CustomerName, Address, Contact, Phone, Email FROM dbo.Customer ";
private static readonly string m_CustomerList = "SELECT CustomerCode, CustomerName FROM dbo.Customer ";
private static readonly string m_UpdateCustomer = "UPDATE dbo.Customer SET CustomerCode=@CustomerCode"
+ ",CustomerName=@CustomerName "
+ ",Address=@Address "
+ ",Contact=@Contact, Phone=@Phone, Email=@Email WHERE AutoID=@AutoID ";
private static readonly string m_DeleteCustomer = "DELETE FROM dbo.Customer WHERE AutoID=@AutoID ";
private static readonly string m_InsertCustomer = "INSERT INTO dbo.Customer(CustomerCode, CustomerName, Address, Contact, Phone, Email) "
+ "VALUES(@CustomerCode, @CustomerName, @Address, @Contact, @Phone, @Email) SELECT @p1=@@IDENTITY ";
public int Update(Customer cust)
...{
int count = 0;
try
...{
switch (cust.DB_Action)
...{
case DataStatus.dsNew :
count = this.InsertCommand(cust);
break;
case DataStatus.dsModify :
count = this.UpdateCommand(cust);
break;
case DataStatus.dsDelete :
count = this.DeleteCommand(cust);
break;
default :
break;
}
}
catch (Exception ex)
...{
throw new Exception(ex.Message);
}
return count;
}
private int InsertCommand(Customer cust)
...{
using (SqlConnection conn = new SqlConnection(m_ERP_STUDY))
...{
try
...{
SqlCommand cmd = new SqlCommand(m_InsertCustomer, conn);
cmd.Parameters.Add("@CustomerCode", SqlDbType.Char, 3, "CustomerCode").Value = cust.CustomerCode;
cmd.Parameters.Add("@CustomerName", SqlDbType.NVarChar, 50, "CustomerName").Value = cust.CustomerName;
cmd.Parameters.Add("@Address", SqlDbType.NVarChar, 50, "Address").Value = cust.Address;
cmd.Parameters.Add("@Contact", SqlDbType.NVarChar, 10, "Contact").Value = cust.Contact;
cmd.Parameters.Add("@Phone", SqlDbType.VarChar, 20, "Phone").Value = cust.Phone;
cmd.Parameters.Add("@Email", SqlDbType.VarChar, 30, "Email").Value = cust.Email;
SqlParameter para = cmd.Parameters.Add("@p1", SqlDbType.Int);
para.Direction = ParameterDirection.Output;
conn.Open();
cmd.ExecuteNonQuery();
return (int)para.Value;
}
catch (Exception ex)
...{
throw new Exception(ex.Message);
}
}
}
private int UpdateCommand(Customer cust)
...{
using (SqlConnection conn = new SqlConnection(m_ERP_STUDY))
...{
try
...{
SqlCommand cmd = new SqlCommand(m_UpdateCustomer, conn);
cmd.Parameters.Add("@CustomerCode", SqlDbType.Char, 3, "CustomerCode").Value = cust.CustomerCode;
cmd.Parameters.Add("@CustomerName", SqlDbType.NVarChar, 50, "CustomerName").Value = cust.CustomerName;
cmd.Parameters.Add("@Address", SqlDbType.NVarChar, 50, "Address").Value = cust.Address;
cmd.Parameters.Add("@Contact", SqlDbType.NVarChar, 10, "Contact").Value = cust.Contact;
cmd.Parameters.Add("@Phone", SqlDbType.VarChar, 20, "Phone").Value = cust.Phone;
cmd.Parameters.Add("@Email", SqlDbType.VarChar, 30, "Email").Value = cust.Email;
cmd.Parameters.Add("@AutoID", SqlDbType.Int, 4, "AutoID").Value = cust.AutoID;
conn.Open();
return cmd.ExecuteNonQuery();
}
catch (Exception ex)
...{
throw new Exception(ex.Message);
}
}
}
private int DeleteCommand(Customer cust)
...{
using (SqlConnection conn = new SqlConnection(m_ERP_STUDY))
...{
try
...{
SqlCommand cmd = new SqlCommand(m_DeleteCustomer, conn);
cmd.Parameters.Add("@AutoID", SqlDbType.Int, 4, "AutoID").Value = cust.AutoID;
conn.Open();
return cmd.ExecuteNonQuery();
}
catch (Exception ex)
...{
throw new Exception(ex.Message);
}
}
}
public int Update(List<Customer> custList)
...{
for (int i = 0; i < custList.Count; i++)
...{
this.Update(custList[i]);
}
return 1;
}
public Customer DBToEnitity(IDataReader dr)
...{
Customer cust = new Customer();
cust.DB_Action = DataStatus.dsNormal;
cust.CustomerCode = dr["CustomerCode"].ToString();
cust.CustomerName = dr["CustomerName"].ToString();
cust.Address = dr["Address"].ToString();
cust.Contact = dr["Contact"].ToString();
cust.Phone = dr["Phone"].ToString();
cust.Email = dr["Email"].ToString();
cust.AutoID = int.Parse(dr["AutoID"].ToString());
return cust;
}
/**//*public void Update(DataSet changeDS)
{
using (SqlConnection conn = new SqlConnection(m_ERP_STUDY))
{
try
{
SqlDataAdapter ad = new SqlDataAdapter();
System.Data.Common.DataTableMapping tbMap = new System.Data.Common.DataTableMapping();
tbMap.SourceTable = "dbo.Customer";
tbMap.DataSetTable = "dsCustomer";
tbMap.ColumnMappings.Add("AutoID", "AutoID");
tbMap.ColumnMappings.Add("CustomerCode", "CustomerCode");
tbMap.ColumnMappings.Add("CustomerName", "CustomerName");
tbMap.ColumnMappings.Add("Address", "Address");
tbMap.ColumnMappings.Add("Contact", "Contact");
tbMap.ColumnMappings.Add("Phone", "Phone");
tbMap.ColumnMappings.Add("Email", "Email");
ad.TableMappings.Add(tbMap);
ad.UpdateCommand = GetCommand(m_UpdateCustomer, conn);
ad.UpdateCommand.Parameters.Add(new SqlParameter("@CustomerCode", SqlDbType.Char, 3, ParameterDirection.Input, 0, 0, "CustomerCode", DataRowVersion.Current, false, null, "", "", ""));
ad.UpdateCommand.Parameters.Add(new SqlParameter("OldCustomerCode", SqlDbType.Char, 3, ParameterDirection.Input, 0, 0, "CustomerCode", DataRowVersion.Original, false, null, "", "", ""));
ad.UpdateCommand.Parameters.Add(new SqlParameter("@CustomerName", SqlDbType.NVarChar, 50, ParameterDirection.Input, 0, 0, "CustomerName", DataRowVersion.Current, false, null, "", "", ""));
ad.UpdateCommand.Parameters.Add(new SqlParameter("@Address", SqlDbType.NVarChar, 50, ParameterDirection.Input, 0, 0, "Address", DataRowVersion.Current, false, null, "", "", ""));
ad.UpdateCommand.Parameters.Add(new SqlParameter("@Contact", SqlDbType.NVarChar, 10, ParameterDirection.Input, 0, 0, "Contact", DataRowVersion.Current, false, null, "", "", ""));
ad.UpdateCommand.Parameters.Add(new SqlParameter("@Phone", SqlDbType.NVarChar, 20, ParameterDirection.Input, 0, 0, "Phone", DataRowVersion.Current, false, null, "", "", ""));
ad.UpdateCommand.Parameters.Add(new SqlParameter("@Email", SqlDbType.NVarChar, 30, ParameterDirection.Input, 0, 0, "Email", DataRowVersion.Current, false, null, "", "", ""));
ad.DeleteCommand = GetCommand(m_DeleteCustomer, conn);
ad.DeleteCommand.Parameters.Add(new SqlParameter("@OldCustomerCode", SqlDbType.Char, 3, ParameterDirection.Input, 0, 0, "CustomerCode", DataRowVersion.Original, false, null, "", "", ""));
ad.InsertCommand = GetCommand(m_InsertCustomer, conn);
ad.InsertCommand.Parameters.Add(new SqlParameter("@CustomerCode", SqlDbType.Char, 3, ParameterDirection.Input, 0, 0, "CustomerCode", DataRowVersion.Current, false, null, "", "", ""));
ad.InsertCommand.Parameters.Add(new SqlParameter("@CustomerName", SqlDbType.NVarChar, 50, ParameterDirection.Input, 0, 0, "CustomerName", DataRowVersion.Current, false, null, "", "", ""));
ad.InsertCommand.Parameters.Add(new SqlParameter("@Address", SqlDbType.NVarChar, 50, ParameterDirection.Input, 0, 0, "Address", DataRowVersion.Current, false, null, "", "", ""));
ad.InsertCommand.Parameters.Add(new SqlParameter("@Contact", SqlDbType.NVarChar, 10, ParameterDirection.Input, 0, 0, "Contact", DataRowVersion.Current, false, null, "", "", ""));
ad.InsertCommand.Parameters.Add(new SqlParameter("@Phone", SqlDbType.NVarChar, 20, ParameterDirection.Input, 0, 0, "Phone", DataRowVersion.Current, false, null, "", "", ""));
ad.InsertCommand.Parameters.Add(new SqlParameter("@Email", SqlDbType.NVarChar, 30, ParameterDirection.Input, 0, 0, "Email", DataRowVersion.Current, false, null, "", "", ""));
conn.Open();
// ad.AcceptChangesDuringUpdate = true;
ad.Update(changeDS, "dbo.Customer");
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
private SqlCommand GetCommand(string CommandText, SqlConnection conn)
{
return new SqlCommand(CommandText, conn);
}*/
}
}
/**/
/*
Custom code
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using GAO.Sales_Entity;
namespace GAO.Sales_DAL_MSSQL
... {
public partial class CustomerInfo
...{
public CustomerInfo()
...{
}
public List<Customer> GetCustomer()
...{
List<Customer> list = new List<Customer>();
using (SqlConnection conn = new SqlConnection(m_ERP_STUDY))
...{
SqlCommand cmd = new SqlCommand(m_SelectCustomer, conn);
conn.Open();
using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
...{
while (dr.Read())
...{
list.Add(DBToEnitity(dr));
}
dr.Close();
}
cmd.Dispose();
}
return list;
}
public List<Customer> GetCustomerList()
...{
List<Customer> list = new List<Customer>();
using (SqlConnection conn = new SqlConnection(m_ERP_STUDY))
...{
SqlCommand cmd = new SqlCommand(m_CustomerList, conn);
conn.Open();
using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
...{
while (dr.Read())
...{
Customer cust = new Customer();
cust.CustomerCode = dr[0].ToString();
cust.CustomerName = dr[1].ToString();
list.Add(cust);
}
dr.Close();
}
cmd.Dispose();
}
return list;
}
}
}
Custom code
*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using GAO.Sales_Entity;
namespace GAO.Sales_DAL_MSSQL
... {
public partial class CustomerInfo
...{
public CustomerInfo()
...{
}
public List<Customer> GetCustomer()
...{
List<Customer> list = new List<Customer>();
using (SqlConnection conn = new SqlConnection(m_ERP_STUDY))
...{
SqlCommand cmd = new SqlCommand(m_SelectCustomer, conn);
conn.Open();
using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
...{
while (dr.Read())
...{
list.Add(DBToEnitity(dr));
}
dr.Close();
}
cmd.Dispose();
}
return list;
}
public List<Customer> GetCustomerList()
...{
List<Customer> list = new List<Customer>();
using (SqlConnection conn = new SqlConnection(m_ERP_STUDY))
...{
SqlCommand cmd = new SqlCommand(m_CustomerList, conn);
conn.Open();
using (SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
...{
while (dr.Read())
...{
Customer cust = new Customer();
cust.CustomerCode = dr[0].ToString();
cust.CustomerName = dr[1].ToString();
list.Add(cust);
}
dr.Close();
}
cmd.Dispose();
}
return list;
}
}
}
3 業務層(dll文件:Sales_Business)
using
System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using GAO.ISales_Service;
using GAO.Sales_DAL_MSSQL;
using GAO.Sales_Entity;
namespace GAO.Sales_Business
... {
public class CustomerFacade : MarshalByRefObject,ICustomerService
...{
public List<Customer> GetALLCustomer()
...{
CustomerInfo cinfo = new CustomerInfo();
return cinfo.GetCustomer();
}
public int Update(Customer changeData)
...{
CustomerInfo cinfo = new CustomerInfo();
return cinfo.Update(changeData);
}
public List<Customer> GetCustomerList()
...{
CustomerInfo cinfo = new CustomerInfo();
return cinfo.GetCustomerList();
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Data;
using GAO.ISales_Service;
using GAO.Sales_DAL_MSSQL;
using GAO.Sales_Entity;
namespace GAO.Sales_Business
... {
public class CustomerFacade : MarshalByRefObject,ICustomerService
...{
public List<Customer> GetALLCustomer()
...{
CustomerInfo cinfo = new CustomerInfo();
return cinfo.GetCustomer();
}
public int Update(Customer changeData)
...{
CustomerInfo cinfo = new CustomerInfo();
return cinfo.Update(changeData);
}
public List<Customer> GetCustomerList()
...{
CustomerInfo cinfo = new CustomerInfo();
return cinfo.GetCustomerList();
}
}
}
4.服務接口(DLL文件ISales_Service)
using
System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Data;
using GAO.Sales_Entity;
namespace GAO.ISales_Service
... {
public interface ICustomerService
...{
List<Customer> GetALLCustomer();
int Update(Customer changeData);
List<Customer> GetCustomerList();
}
}
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Data;
using GAO.Sales_Entity;
namespace GAO.ISales_Service
... {
public interface ICustomerService
...{
List<Customer> GetALLCustomer();
int Update(Customer changeData);
List<Customer> GetCustomerList();
}
}
5界面
using
System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting;
using GAO.ISales_Service;
using GAO.Sales_Entity;
namespace TelBookClient
... {
public partial class MainForm : Form
...{
private ICustomerService m_CustomerService;
private List<Customer> custList;
public List<Customer> CustomerList
...{
get ...{ return custList; }
}
private ICustomerService GetCustomerService()
...{
RemotingConfiguration.Configure("SalesClient.exe.config", true);
ICustomerService CustomerService = (ICustomerService)RemotingServices.Connect(typeof(ICustomerService), ConfigurationManager.AppSettings["Sales_BusinessURI"]);
return CustomerService;
}
public MainForm()
...{
InitializeComponent();
m_CustomerService = GetCustomerService();
custList = m_CustomerService.GetALLCustomer();
bindingSource1.DataSource = custList;
}
private void btnAddNew_Click(object sender, EventArgs e)
...{
bindingSource1.AddNew();
ShowEditForm(DataStatus.dsNew);
}
private static bool IsChangeData(Customer cust)
...{
if ((cust != null) && ((cust.DB_Action == DataStatus.dsNew)||(cust.DB_Action == DataStatus.dsModify)
|| (cust.DB_Action == DataStatus.dsDelete) ))
...{
return true;
}
else
...{
return false;
}
}
private void btnUpdate_Click(object sender, EventArgs e)
...{
SaveData();
}
public void SaveData()
...{
Customer newData = custList.Find(IsChangeData);
if (newData != null)
...{
if (newData.DB_Action == DataStatus.dsNew)
newData.AutoID = m_CustomerService.Update(newData);
else
m_CustomerService.Update(newData);
newData.DB_Action = DataStatus.dsNormal;
bindingSource1.DataSource = CustomerList;
this.dataGridView1.Refresh();
}
/**//*bindingSource1.EndEdit();
if (changeDS != null)
{
changeDS = m_CustomerService.UpdateAndGetNewID(changeDS);
(bindingSource1.DataSource as DataSet).Merge(changeDS, false);
(bindingSource1.DataSource as DataSet).AcceptChanges();
}*/
}
private void btnDelete_Click(object sender, EventArgs e)
...{
(bindingSource1.Current as Customer).DB_Action = DataStatus.dsDelete;
SaveData();
bindingSource1.RemoveCurrent();
}
private void btnGetAll_Click(object sender, EventArgs e)
...{
bindingSource1.DataSource = m_CustomerService.GetALLCustomer();
//bindingSource1.DataMember = "dsCustomer";
}
private void btnExit_Click(object sender, EventArgs e)
...{
Application.Exit();
}
private void ShowEditForm(DataStatus dts)
...{
frmEdtCustomer frm = new frmEdtCustomer(this, dts);
frm.BindingContext = this.BindingContext;
frm.ShowDialog();
}
private void btnModify_Click(object sender, EventArgs e)
...{
ShowEditForm(DataStatus.dsModify);
}
/**//*public static void FillLookupEdit(LookUpEdit lookUpEdit, List<Customer> list, bool ShowCaption, string[] FieldList, string[] CaptionList, string DisplayMember, string ValueMember)
{
if ((FieldList == null) || (FieldList.Length == 0))
throw new Exception("必須指定LookUpEdit字段顯示列表");
if ((CaptionList == null) || (CaptionList.Length == 0))
throw new Exception("必須指定LookUpEdit字段標題列表");
if (FieldList.Length != CaptionList.Length)
{
throw new Exception("The FieldList's Length Must be equals the CaptionList's Length");
}
lookUpEdit.Properties.BeginUpdate();
lookUpEdit.Properties.Columns.Clear();
lookUpEdit.Properties.DataSource = list;
int index = 0;
foreach (string str in FieldList)
{
LookUpColumnInfo info = new LookUpColumnInfo();
info.FieldName = str;
if (ShowCaption)
{
info.Caption = CaptionList[index];
}
index++;
lookUpEdit.Properties.Columns.Add(info);
}
lookUpEdit.Properties.DisplayMember = DisplayMember;
lookUpEdit.Properties.ValueMember = ValueMember;
lookUpEdit.Properties.EndUpdate();
}
*/
}
}
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GAO.Sales_Entity;
namespace TelBookClient
... {
public partial class frmEdtCustomer : Form
...{
private MainForm m_FormOwner;
private DataStatus m_dts;
private StringCollection m_FocusControlType = new StringCollection();
public StringCollection FocusControlTypes
...{
get ...{ return m_FocusControlType; }
set ...{ m_FocusControlType = value; }
}
public frmEdtCustomer(MainForm ParentForm, DataStatus dts)
...{
InitializeComponent();
FocusControlTypes.Add("System.Windows.Forms.TextBox");
this.m_FormOwner = ParentForm;
this.m_dts = dts;
DataBind();
}
public MainForm FormOwner
...{
get ...{ return this.m_FormOwner; }
set ...{ this.m_FormOwner = (MainForm)value; }
}
private void DataBind()
...{
txtCustomerCode.DataBindings.Add("Text", this.FormOwner.bindingSource1, "CustomerCode");
txtCustomerName.DataBindings.Add("Text", this.FormOwner.bindingSource1, "CustomerName");
txtAddress.DataBindings.Add("Text", this.FormOwner.bindingSource1, "Address");
txtContact.DataBindings.Add("Text", this.FormOwner.bindingSource1, "Contact");
txtPhone.DataBindings.Add("Text", this.FormOwner.bindingSource1, "Phone");
txtEmail.DataBindings.Add("Text", this.FormOwner.bindingSource1, "Email");
}
private bool CheckData()
...{
if (string.IsNullOrEmpty(txtCustomerCode.Text) || string.IsNullOrEmpty(txtCustomerName.Text)
|| string.IsNullOrEmpty(txtAddress.Text) || string.IsNullOrEmpty(txtContact.Text)
|| string.IsNullOrEmpty(txtPhone.Text) || string.IsNullOrEmpty(txtEmail.Text))
...{
return false;
}
return true;
}
private void btnOk_Click(object sender, EventArgs e)
...{
if (!CheckData())
...{
MessageBox.Show("數據不能為空!!!");
return;
}
Customer d = this.FormOwner.bindingSource1.Current as Customer;
d.DB_Action = this.m_dts;
this.FormOwner.SaveData();
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
...{
this.FormOwner.bindingSource1.CancelEdit();
this.Close();
}
private void btnContinue_Click(object sender, EventArgs e)
...{
if (!CheckData())
...{
MessageBox.Show("數據不能為空!!!");
return;
}
Customer d = this.FormOwner.bindingSource1.Current as Customer;
d.DB_Action = this.m_dts;
this.FormOwner.SaveData();
this.FormOwner.bindingSource1.AddNew();
this.m_dts = DataStatus.dsNew;
txtCustomerCode.Focus();
}
protected void txt_Enter(object sender, System.EventArgs e)
...{
(sender as Control).BackColor = Color.BlanchedAlmond;
}
protected void txt_Leave(object sender, System.EventArgs e)
...{
(sender as Control).BackColor = Color.FromKnownColor(KnownColor.Window);
}
protected void txt_KeyDown(object sender, KeyEventArgs e)
...{
switch (e.KeyCode)
...{
case Keys.Enter:
e.Handled = true;
SendKeys.Send("{TAB}");
break;
case Keys.Up:
(sender as Control).Parent.SelectNextControl(this.ActiveControl, false, false, false, false);
break;
case Keys.Down:
(sender as Control).Parent.SelectNextControl(this.ActiveControl, true, false, false, false);
break;
}
}
protected void AddEventHandler(Control pnl)
...{
foreach (Control ctrl in pnl.Controls)
...{
if ( FocusControlTypes.Contains(ctrl.GetType().ToString()) )
...{
ctrl.Enter += new EventHandler(this.txt_Enter);
ctrl.Leave += new EventHandler(this.txt_Leave);
ctrl.KeyDown += new KeyEventHandler(this.txt_KeyDown);
}
if (ctrl.HasChildren)
...{
AddEventHandler(ctrl);
}
}
}
private void frmEdtCustomer_Load(object sender, EventArgs e)
...{
AddEventHandler(this);
}
}
}
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting;
using GAO.ISales_Service;
using GAO.Sales_Entity;
namespace TelBookClient
... {
public partial class MainForm : Form
...{
private ICustomerService m_CustomerService;
private List<Customer> custList;
public List<Customer> CustomerList
...{
get ...{ return custList; }
}
private ICustomerService GetCustomerService()
...{
RemotingConfiguration.Configure("SalesClient.exe.config", true);
ICustomerService CustomerService = (ICustomerService)RemotingServices.Connect(typeof(ICustomerService), ConfigurationManager.AppSettings["Sales_BusinessURI"]);
return CustomerService;
}
public MainForm()
...{
InitializeComponent();
m_CustomerService = GetCustomerService();
custList = m_CustomerService.GetALLCustomer();
bindingSource1.DataSource = custList;
}
private void btnAddNew_Click(object sender, EventArgs e)
...{
bindingSource1.AddNew();
ShowEditForm(DataStatus.dsNew);
}
private static bool IsChangeData(Customer cust)
...{
if ((cust != null) && ((cust.DB_Action == DataStatus.dsNew)||(cust.DB_Action == DataStatus.dsModify)
|| (cust.DB_Action == DataStatus.dsDelete) ))
...{
return true;
}
else
...{
return false;
}
}
private void btnUpdate_Click(object sender, EventArgs e)
...{
SaveData();
}
public void SaveData()
...{
Customer newData = custList.Find(IsChangeData);
if (newData != null)
...{
if (newData.DB_Action == DataStatus.dsNew)
newData.AutoID = m_CustomerService.Update(newData);
else
m_CustomerService.Update(newData);
newData.DB_Action = DataStatus.dsNormal;
bindingSource1.DataSource = CustomerList;
this.dataGridView1.Refresh();
}
/**//*bindingSource1.EndEdit();
if (changeDS != null)
{
changeDS = m_CustomerService.UpdateAndGetNewID(changeDS);
(bindingSource1.DataSource as DataSet).Merge(changeDS, false);
(bindingSource1.DataSource as DataSet).AcceptChanges();
}*/
}
private void btnDelete_Click(object sender, EventArgs e)
...{
(bindingSource1.Current as Customer).DB_Action = DataStatus.dsDelete;
SaveData();
bindingSource1.RemoveCurrent();
}
private void btnGetAll_Click(object sender, EventArgs e)
...{
bindingSource1.DataSource = m_CustomerService.GetALLCustomer();
//bindingSource1.DataMember = "dsCustomer";
}
private void btnExit_Click(object sender, EventArgs e)
...{
Application.Exit();
}
private void ShowEditForm(DataStatus dts)
...{
frmEdtCustomer frm = new frmEdtCustomer(this, dts);
frm.BindingContext = this.BindingContext;
frm.ShowDialog();
}
private void btnModify_Click(object sender, EventArgs e)
...{
ShowEditForm(DataStatus.dsModify);
}
/**//*public static void FillLookupEdit(LookUpEdit lookUpEdit, List<Customer> list, bool ShowCaption, string[] FieldList, string[] CaptionList, string DisplayMember, string ValueMember)
{
if ((FieldList == null) || (FieldList.Length == 0))
throw new Exception("必須指定LookUpEdit字段顯示列表");
if ((CaptionList == null) || (CaptionList.Length == 0))
throw new Exception("必須指定LookUpEdit字段標題列表");
if (FieldList.Length != CaptionList.Length)
{
throw new Exception("The FieldList's Length Must be equals the CaptionList's Length");
}
lookUpEdit.Properties.BeginUpdate();
lookUpEdit.Properties.Columns.Clear();
lookUpEdit.Properties.DataSource = list;
int index = 0;
foreach (string str in FieldList)
{
LookUpColumnInfo info = new LookUpColumnInfo();
info.FieldName = str;
if (ShowCaption)
{
info.Caption = CaptionList[index];
}
index++;
lookUpEdit.Properties.Columns.Add(info);
}
lookUpEdit.Properties.DisplayMember = DisplayMember;
lookUpEdit.Properties.ValueMember = ValueMember;
lookUpEdit.Properties.EndUpdate();
}
*/
}
}
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using GAO.Sales_Entity;
namespace TelBookClient
... {
public partial class frmEdtCustomer : Form
...{
private MainForm m_FormOwner;
private DataStatus m_dts;
private StringCollection m_FocusControlType = new StringCollection();
public StringCollection FocusControlTypes
...{
get ...{ return m_FocusControlType; }
set ...{ m_FocusControlType = value; }
}
public frmEdtCustomer(MainForm ParentForm, DataStatus dts)
...{
InitializeComponent();
FocusControlTypes.Add("System.Windows.Forms.TextBox");
this.m_FormOwner = ParentForm;
this.m_dts = dts;
DataBind();
}
public MainForm FormOwner
...{
get ...{ return this.m_FormOwner; }
set ...{ this.m_FormOwner = (MainForm)value; }
}
private void DataBind()
...{
txtCustomerCode.DataBindings.Add("Text", this.FormOwner.bindingSource1, "CustomerCode");
txtCustomerName.DataBindings.Add("Text", this.FormOwner.bindingSource1, "CustomerName");
txtAddress.DataBindings.Add("Text", this.FormOwner.bindingSource1, "Address");
txtContact.DataBindings.Add("Text", this.FormOwner.bindingSource1, "Contact");
txtPhone.DataBindings.Add("Text", this.FormOwner.bindingSource1, "Phone");
txtEmail.DataBindings.Add("Text", this.FormOwner.bindingSource1, "Email");
}
private bool CheckData()
...{
if (string.IsNullOrEmpty(txtCustomerCode.Text) || string.IsNullOrEmpty(txtCustomerName.Text)
|| string.IsNullOrEmpty(txtAddress.Text) || string.IsNullOrEmpty(txtContact.Text)
|| string.IsNullOrEmpty(txtPhone.Text) || string.IsNullOrEmpty(txtEmail.Text))
...{
return false;
}
return true;
}
private void btnOk_Click(object sender, EventArgs e)
...{
if (!CheckData())
...{
MessageBox.Show("數據不能為空!!!");
return;
}
Customer d = this.FormOwner.bindingSource1.Current as Customer;
d.DB_Action = this.m_dts;
this.FormOwner.SaveData();
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
...{
this.FormOwner.bindingSource1.CancelEdit();
this.Close();
}
private void btnContinue_Click(object sender, EventArgs e)
...{
if (!CheckData())
...{
MessageBox.Show("數據不能為空!!!");
return;
}
Customer d = this.FormOwner.bindingSource1.Current as Customer;
d.DB_Action = this.m_dts;
this.FormOwner.SaveData();
this.FormOwner.bindingSource1.AddNew();
this.m_dts = DataStatus.dsNew;
txtCustomerCode.Focus();
}
protected void txt_Enter(object sender, System.EventArgs e)
...{
(sender as Control).BackColor = Color.BlanchedAlmond;
}
protected void txt_Leave(object sender, System.EventArgs e)
...{
(sender as Control).BackColor = Color.FromKnownColor(KnownColor.Window);
}
protected void txt_KeyDown(object sender, KeyEventArgs e)
...{
switch (e.KeyCode)
...{
case Keys.Enter:
e.Handled = true;
SendKeys.Send("{TAB}");
break;
case Keys.Up:
(sender as Control).Parent.SelectNextControl(this.ActiveControl, false, false, false, false);
break;
case Keys.Down:
(sender as Control).Parent.SelectNextControl(this.ActiveControl, true, false, false, false);
break;
}
}
protected void AddEventHandler(Control pnl)
...{
foreach (Control ctrl in pnl.Controls)
...{
if ( FocusControlTypes.Contains(ctrl.GetType().ToString()) )
...{
ctrl.Enter += new EventHandler(this.txt_Enter);
ctrl.Leave += new EventHandler(this.txt_Leave);
ctrl.KeyDown += new KeyEventHandler(this.txt_KeyDown);
}
if (ctrl.HasChildren)
...{
AddEventHandler(ctrl);
}
}
}
private void frmEdtCustomer_Load(object sender, EventArgs e)
...{
AddEventHandler(this);
}
}
}
客戶端app.config文件
<?
xml version="1.0" encoding="utf-8"
?>
< configuration >
< appSettings >
< add key ="Sales_BusinessURI" value ="tcp://192.168.168.9:808/Sales_BusinessURI" />
</ appSettings >
< system .runtime.remoting >
< application name ="SalesClient" >
< channels >
< channel ref ="tcp" port ="0" >
< clientProviders >
< formatter ref ="binary" />
</ clientProviders >
</ channel >
</ channels >
</ application >
</ system.runtime.remoting >
</ configuration >
< configuration >
< appSettings >
< add key ="Sales_BusinessURI" value ="tcp://192.168.168.9:808/Sales_BusinessURI" />
</ appSettings >
< system .runtime.remoting >
< application name ="SalesClient" >
< channels >
< channel ref ="tcp" port ="0" >
< clientProviders >
< formatter ref ="binary" />
</ clientProviders >
</ channel >
</ channels >
</ application >
</ system.runtime.remoting >
</ configuration >
服務器app.config文件
<?
xml version="1.0" encoding="utf-8"
?>
< configuration >
< connectionStrings >
< add name ="ERP_STUDY" connectionString ="Data Source=KM-IT-P09;Initial Catalog=ERP_STUDY; Integrated security=SSPI"
providerName ="System.Data.SqlClient" />
</ connectionStrings >
< system .runtime.remoting >
< application name ="SalesServer" >
< service >
< wellknown mode ="Singleton" type ="GAO.Sales_Business.CustomerFacade,Sales_Business" objectUri ="Sales_BusinessURI" />
</ service >
< channels >
< channel ref ="tcp" port ="808" >
< serverProviders >
< formatter ref ="binary" typeFilterLevel ='Full'/>
</serverProviders >
</ channel >
</ channels >
</ application >
</ system.runtime.remoting >
</ configuration >
< configuration >
< connectionStrings >
< add name ="ERP_STUDY" connectionString ="Data Source=KM-IT-P09;Initial Catalog=ERP_STUDY; Integrated security=SSPI"
providerName ="System.Data.SqlClient" />
</ connectionStrings >
< system .runtime.remoting >
< application name ="SalesServer" >
< service >
< wellknown mode ="Singleton" type ="GAO.Sales_Business.CustomerFacade,Sales_Business" objectUri ="Sales_BusinessURI" />
</ service >
< channels >
< channel ref ="tcp" port ="808" >
< serverProviders >
< formatter ref ="binary" typeFilterLevel ='Full'/>
</serverProviders >
</ channel >
</ channels >
</ application >
</ system.runtime.remoting >
</ configuration >
服務器代碼
using
System;
using System.Runtime.Remoting;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace TBookServer
... {
class Program
...{
public static void ShowActivatedServiceTypes()
...{
ActivatedServiceTypeEntry[] entries = RemotingConfiguration.GetRegisteredActivatedServiceTypes();
foreach (ActivatedServiceTypeEntry entry in entries)
...{
Console.WriteLine("Assembly:{0}", entry.AssemblyName);
Console.WriteLine("Type:{0}", entry.TypeName);
}
}
public static void ShowWellKnownServiceTypes()
...{
WellKnownServiceTypeEntry[] entries = RemotingConfiguration.GetRegisteredWellKnownServiceTypes();
foreach (WellKnownServiceTypeEntry entry in entries)
...{
Console.WriteLine("Assembly:{0}", entry.AssemblyName);
Console.WriteLine("Mode:{0}", entry.Mode);
Console.WriteLine("URL:{0}", entry.ObjectUri);
Console.WriteLine("Type:{0}", entry.TypeName);
}
}
static void Main(string[] args)
...{
string path = Application.StartupPath;
string[] files = System.IO.Directory.GetFiles(path, "*.dll");
RemotingConfiguration.Configure("SalesServer.exe.config", true);
Console.WriteLine("Application:{0}", RemotingConfiguration.ApplicationName);
ShowActivatedServiceTypes();
ShowWellKnownServiceTypes();
Console.WriteLine("Host started. Press ENTER to exit.");
Console.ReadLine();
}
}
}
using System.Runtime.Remoting;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace TBookServer
... {
class Program
...{
public static void ShowActivatedServiceTypes()
...{
ActivatedServiceTypeEntry[] entries = RemotingConfiguration.GetRegisteredActivatedServiceTypes();
foreach (ActivatedServiceTypeEntry entry in entries)
...{
Console.WriteLine("Assembly:{0}", entry.AssemblyName);
Console.WriteLine("Type:{0}", entry.TypeName);
}
}
public static void ShowWellKnownServiceTypes()
...{
WellKnownServiceTypeEntry[] entries = RemotingConfiguration.GetRegisteredWellKnownServiceTypes();
foreach (WellKnownServiceTypeEntry entry in entries)
...{
Console.WriteLine("Assembly:{0}", entry.AssemblyName);
Console.WriteLine("Mode:{0}", entry.Mode);
Console.WriteLine("URL:{0}", entry.ObjectUri);
Console.WriteLine("Type:{0}", entry.TypeName);
}
}
static void Main(string[] args)
...{
string path = Application.StartupPath;
string[] files = System.IO.Directory.GetFiles(path, "*.dll");
RemotingConfiguration.Configure("SalesServer.exe.config", true);
Console.WriteLine("Application:{0}", RemotingConfiguration.ApplicationName);
ShowActivatedServiceTypes();
ShowWellKnownServiceTypes();
Console.WriteLine("Host started. Press ENTER to exit.");
Console.ReadLine();
}
}
}
數據庫腳本
USE
[
master
]
GO
/**/ /****** 物件: Database [ERP_STUDY] 指令碼日期: 05/24/2008 15:42:17 ******/
CREATE DATABASE [ ERP_STUDY ] ON PRIMARY
( NAME = N ' ERP_STUDY ' , FILENAME = N ' C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLDATAERP_STUDY.mdf ' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N ' ERP_STUDY_log ' , FILENAME = N ' C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLDATAERP_STUDY_log.ldf ' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10 % )
GO
EXEC dbo.sp_dbcmptlevel @dbname = N ' ERP_STUDY ' , @new_cmptlevel = 90
GO
IF ( 1 = FULLTEXTSERVICEPROPERTY ( ' IsFullTextInstalled ' ))
begin
EXEC [ ERP_STUDY ] . [ dbo ] . [ sp_fulltext_database ] @action = ' disable '
end
GO
ALTER DATABASE [ ERP_STUDY ] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET ANSI_NULLS OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET ANSI_PADDING OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET ARITHABORT OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [ ERP_STUDY ] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [ ERP_STUDY ] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET CURSOR_DEFAULT GLOBAL
GO
ALTER DATABASE [ ERP_STUDY ] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET ENABLE_BROKER
GO
ALTER DATABASE [ ERP_STUDY ] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [ ERP_STUDY ] SET READ_WRITE
GO
ALTER DATABASE [ ERP_STUDY ] SET RECOVERY FULL
GO
ALTER DATABASE [ ERP_STUDY ] SET MULTI_USER
GO
ALTER DATABASE [ ERP_STUDY ] SET PAGE_VERIFY CHECKSUM
GO
ALTER DATABASE [ ERP_STUDY ] SET DB_CHAINING OFF
GO
USE [ ERP_STUDY ]
GO
/**/ /****** 物件: Table [dbo].[Customer] 指令碼日期: 05/24/2008 15:43:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [ dbo ] . [ Customer ] (
[ AutoID ] [ int ] IDENTITY ( 1 , 1 ) NOT NULL ,
[ CustomerCode ] [ char ] ( 3 ) NOT NULL ,
[ CustomerName ] [ nvarchar ] ( 50 ) NULL ,
[ Address ] [ nvarchar ] ( 50 ) NULL ,
[ Contact ] [ nvarchar ] ( 10 ) NULL ,
[ Phone ] [ nvarchar ] ( 20 ) NULL ,
[ Email ] [ nvarchar ] ( 30 ) NULL ,
CONSTRAINT [ PK_Customer ] PRIMARY KEY CLUSTERED
(
[ CustomerCode ] ASC
) WITH (PAD_INDEX = OFF , STATISTICS_NORECOMPUTE = OFF , IGNORE_DUP_KEY = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON ) ON [ PRIMARY ]
) ON [ PRIMARY ]
GO
SET ANSI_PADDING OFF
GO
/**/ /****** 物件: Database [ERP_STUDY] 指令碼日期: 05/24/2008 15:42:17 ******/
CREATE DATABASE [ ERP_STUDY ] ON PRIMARY
( NAME = N ' ERP_STUDY ' , FILENAME = N ' C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLDATAERP_STUDY.mdf ' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N ' ERP_STUDY_log ' , FILENAME = N ' C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLDATAERP_STUDY_log.ldf ' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10 % )
GO
EXEC dbo.sp_dbcmptlevel @dbname = N ' ERP_STUDY ' , @new_cmptlevel = 90
GO
IF ( 1 = FULLTEXTSERVICEPROPERTY ( ' IsFullTextInstalled ' ))
begin
EXEC [ ERP_STUDY ] . [ dbo ] . [ sp_fulltext_database ] @action = ' disable '
end
GO
ALTER DATABASE [ ERP_STUDY ] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET ANSI_NULLS OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET ANSI_PADDING OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET ARITHABORT OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [ ERP_STUDY ] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [ ERP_STUDY ] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET CURSOR_DEFAULT GLOBAL
GO
ALTER DATABASE [ ERP_STUDY ] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET ENABLE_BROKER
GO
ALTER DATABASE [ ERP_STUDY ] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [ ERP_STUDY ] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [ ERP_STUDY ] SET READ_WRITE
GO
ALTER DATABASE [ ERP_STUDY ] SET RECOVERY FULL
GO
ALTER DATABASE [ ERP_STUDY ] SET MULTI_USER
GO
ALTER DATABASE [ ERP_STUDY ] SET PAGE_VERIFY CHECKSUM
GO
ALTER DATABASE [ ERP_STUDY ] SET DB_CHAINING OFF
GO
USE [ ERP_STUDY ]
GO
/**/ /****** 物件: Table [dbo].[Customer] 指令碼日期: 05/24/2008 15:43:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [ dbo ] . [ Customer ] (
[ AutoID ] [ int ] IDENTITY ( 1 , 1 ) NOT NULL ,
[ CustomerCode ] [ char ] ( 3 ) NOT NULL ,
[ CustomerName ] [ nvarchar ] ( 50 ) NULL ,
[ Address ] [ nvarchar ] ( 50 ) NULL ,
[ Contact ] [ nvarchar ] ( 10 ) NULL ,
[ Phone ] [ nvarchar ] ( 20 ) NULL ,
[ Email ] [ nvarchar ] ( 30 ) NULL ,
CONSTRAINT [ PK_Customer ] PRIMARY KEY CLUSTERED
(
[ CustomerCode ] ASC
) WITH (PAD_INDEX = OFF , STATISTICS_NORECOMPUTE = OFF , IGNORE_DUP_KEY = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON ) ON [ PRIMARY ]
) ON [ PRIMARY ]
GO
SET ANSI_PADDING OFF
由於本人水平有限,肯定有很多缺點,請多指正。