/**//* 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 ...{ publicpartialclass 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 ...{ publicclass CustomerFacade : MarshalByRefObject,ICustomerService ...{ public List<Customer> GetALLCustomer() ...{ CustomerInfo cinfo =new CustomerInfo(); return cinfo.GetCustomer(); } publicint 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 ...{ publicinterface 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 ...{ publicpartialclass 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; } privatevoid btnAddNew_Click(object sender, EventArgs e) ...{ bindingSource1.AddNew(); ShowEditForm(DataStatus.dsNew); } privatestaticbool IsChangeData(Customer cust) ...{ if ((cust !=null) && ((cust.DB_Action == DataStatus.dsNew)||(cust.DB_Action == DataStatus.dsModify) || (cust.DB_Action == DataStatus.dsDelete) )) ...{ returntrue; } else ...{ returnfalse; } } privatevoid btnUpdate_Click(object sender, EventArgs e) ...{ SaveData(); } publicvoid 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(); }*/ } privatevoid btnDelete_Click(object sender, EventArgs e) ...{ (bindingSource1.Current as Customer).DB_Action = DataStatus.dsDelete; SaveData(); bindingSource1.RemoveCurrent(); } privatevoid btnGetAll_Click(object sender, EventArgs e) ...{ bindingSource1.DataSource = m_CustomerService.GetALLCustomer(); //bindingSource1.DataMember = "dsCustomer"; } privatevoid btnExit_Click(object sender, EventArgs e) ...{ Application.Exit(); } privatevoid ShowEditForm(DataStatus dts) ...{ frmEdtCustomer frm =new frmEdtCustomer(this, dts); frm.BindingContext =this.BindingContext; frm.ShowDialog(); } privatevoid 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 ...{ publicpartialclass 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...{ returnthis.m_FormOwner; } set...{ this.m_FormOwner = (MainForm)value; } } privatevoid 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"); } privatebool 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)) ...{ returnfalse; } returntrue; } privatevoid 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(); } privatevoid btnCancel_Click(object sender, EventArgs e) ...{ this.FormOwner.bindingSource1.CancelEdit(); this.Close(); } privatevoid 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(); } protectedvoid txt_Enter(object sender, System.EventArgs e) ...{ (sender as Control).BackColor = Color.BlanchedAlmond; } protectedvoid txt_Leave(object sender, System.EventArgs e) ...{ (sender as Control).BackColor = Color.FromKnownColor(KnownColor.Window); } protectedvoid 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; } } protectedvoid 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); } } } privatevoid frmEdtCustomer_Load(object sender, EventArgs e) ...{ AddEventHandler(this); } } }
using System; using System.Runtime.Remoting; using System.Runtime.CompilerServices; using System.Windows.Forms; namespace TBookServer ...{ class Program ...{ publicstaticvoid ShowActivatedServiceTypes() ...{ ActivatedServiceTypeEntry[] entries = RemotingConfiguration.GetRegisteredActivatedServiceTypes(); foreach (ActivatedServiceTypeEntry entry in entries) ...{ Console.WriteLine("Assembly:{0}", entry.AssemblyName); Console.WriteLine("Type:{0}", entry.TypeName); } } publicstaticvoid 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); } } staticvoid 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 ******/ CREATEDATABASE[ERP_STUDY]ONPRIMARY ( NAME = N'ERP_STUDY', FILENAME = N'C:Program FilesMicrosoft SQL ServerMSSQL.1MSSQLDATAERP_STUDY.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) LOGON ( 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 ALTERDATABASE[ERP_STUDY]SET ANSI_NULL_DEFAULT OFF GO ALTERDATABASE[ERP_STUDY]SET ANSI_NULLS OFF GO ALTERDATABASE[ERP_STUDY]SET ANSI_PADDING OFF GO ALTERDATABASE[ERP_STUDY]SET ANSI_WARNINGS OFF GO ALTERDATABASE[ERP_STUDY]SET ARITHABORT OFF GO ALTERDATABASE[ERP_STUDY]SET AUTO_CLOSE OFF GO ALTERDATABASE[ERP_STUDY]SET AUTO_CREATE_STATISTICS ON GO ALTERDATABASE[ERP_STUDY]SET AUTO_SHRINK OFF GO ALTERDATABASE[ERP_STUDY]SET AUTO_UPDATE_STATISTICS ON GO ALTERDATABASE[ERP_STUDY]SET CURSOR_CLOSE_ON_COMMIT OFF GO ALTERDATABASE[ERP_STUDY]SET CURSOR_DEFAULT GLOBAL GO ALTERDATABASE[ERP_STUDY]SET CONCAT_NULL_YIELDS_NULL OFF GO ALTERDATABASE[ERP_STUDY]SET NUMERIC_ROUNDABORT OFF GO ALTERDATABASE[ERP_STUDY]SET QUOTED_IDENTIFIER OFF GO ALTERDATABASE[ERP_STUDY]SET RECURSIVE_TRIGGERS OFF GO ALTERDATABASE[ERP_STUDY]SET ENABLE_BROKER GO ALTERDATABASE[ERP_STUDY]SET AUTO_UPDATE_STATISTICS_ASYNC OFF GO ALTERDATABASE[ERP_STUDY]SET DATE_CORRELATION_OPTIMIZATION OFF GO ALTERDATABASE[ERP_STUDY]SET TRUSTWORTHY OFF GO ALTERDATABASE[ERP_STUDY]SET ALLOW_SNAPSHOT_ISOLATION OFF GO ALTERDATABASE[ERP_STUDY]SET PARAMETERIZATION SIMPLE GO ALTERDATABASE[ERP_STUDY]SET READ_WRITE GO ALTERDATABASE[ERP_STUDY]SET RECOVERY FULL GO ALTERDATABASE[ERP_STUDY]SET MULTI_USER GO ALTERDATABASE[ERP_STUDY]SET PAGE_VERIFY CHECKSUM GO ALTERDATABASE[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 CREATETABLE[dbo].[Customer]( [AutoID][int]IDENTITY(1,1) NOTNULL, [CustomerCode][char](3) NOTNULL, [CustomerName][nvarchar](50) NULL, [Address][nvarchar](50) NULL, [Contact][nvarchar](10) NULL, [Phone][nvarchar](20) NULL, [Email][nvarchar](30) NULL, CONSTRAINT[PK_Customer]PRIMARYKEYCLUSTERED ( [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