運用List代替DataSet實現的數據庫程序

本文介绍了一个简单的数据库应用程序,该程序利用.NET REMOTING技术进行远程调用,并采用分层架构来实现客户数据管理。文章展示了实体层、业务逻辑层和UI层的代码实现,并解释了如何通过枚举、属性设置以及远程服务调用来操作客户数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本人嘗試用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;
using System.Collections;

namespace GAO.Sales_Entity
{

  
/// <summary>
  
/// 客戶實體類
  
/// </summary>

    [Serializable]
    
public class Customer
    
{
        
私有字段 

        
公共屬性 
    }



}

 

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);
        }
*/



    }

}

 

 

/*
 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();
        }

    }

}

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();
    }

}

        

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, falsefalsefalsefalse);
                    
break;
                
case Keys.Down:
                    (sender 
as Control).Parent.SelectNextControl(this.ActiveControl, truefalsefalsefalse);
                    
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>

服務器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>

服務器代碼

 

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();
        }

    }

}

數據庫腳本

 

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,1NOT NULL,
    
[CustomerCode] [char](3NOT NULL,
    
[CustomerName] [nvarchar](50NULL,
    
[Address] [nvarchar](50NULL,
    
[Contact] [nvarchar](10NULL,
    
[Phone] [nvarchar](20NULL,
    
[Email] [nvarchar](30NULL,
 
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  = ONON [PRIMARY]
ON [PRIMARY]

GO
SET ANSI_PADDING OFF

由於本人水平有限,肯定有很多缺點,請多指正。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值