Chapter One hierarchical development of software systems
Case
Student Management
Build Class Library Dal
Add Class
Build a form to bind data to Datagrivel
Because under a different project
So to quote
Data Access Layer
Data Access Layer (DAL)
usingSystem;usingSystem.Collections.Generic;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespacemyschool.dal{//CRUD Create Read Update Delete Public classStudentdal {//Four Methods Public voidaddstudent () {}//Read all the students PublicDataTable selectstudent () {stringsql ="Select *from Student"; stringStr="Data source=.; Initial catalog=myschool; Uid=sa"; SqlConnection Con=NewSqlConnection (str); SqlDataAdapter da=NewSqlDataAdapter (Sql,con); DataSet DS=NewDataSet (); Da. Fill (DS,"Stuinfo"); returnDs. tables["Stuinfo"]; } Public voidupdatestudent () {} Public voiddeletestudent () {} }}
usingMyschool.dal;usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespacemyschool.ui{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Private voidForm1_Load (Objectsender, EventArgs e) { //Add ReferenceStudentdal dal=NewStudentdal (); DataTable DT=dal. Selectstudent (); Datagridview1.datasource=DT; } }}
Problems
1. The Class Library project cannot be started
2. A class name under the project, inconsistent with the real class keyword name
Three-layer Code drop diagram
1. Under one solution, hang on two items:. A class library. Form
2. Create a class named Studentdal at the DAL layer, which has the following structure: and a common glow method is implanted in the class selectstudent () will be called by the UI layer (a collection in memory)
Microsoft provides a folder app,congig XML file for the link command to store the database
GAC (Global Assembly Cache) global Assembly cache
=============================================================================================================== ======
Chapter II Entities
1. Classification of exceptions: Exception runtime exceptions at compile time
2. Exception capture Log
3. Do not interrupt execution in case of abnormal program
Divedbyzeroexception----arthimaticexception----sysyemexception
Masage: A description of the exception information
StackTrace: precise positioning to the trigger point of the exception, exactly to the number of rows
Innerexception:sql in case of error
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceconsoleapplication1{classProgram {Static voidMain (string[] args) { #regionReadyonly const (must test)//const can be used in classes and methods, but ReadOnly can not be in a method in a class//compile. When the source file is transformed into an intermediate file, the intermediate file MSIL in C # is actually an EXE file//in a static method, only static members can be accessed directly//If you want to be non-static, first new is accessed through the object name, variable name//Const-Decorated class members are added by default to the static keyword//ReadOnly is assigned while running and const is at compile time the system has given the value to solid//const can only modify value types and special reference types, and string readonly can decorate all data types #endregion } } }
========================================================================================
Chapter three begins with data access
The Using keyword can introduce namespaces
Freeing a resource: the type of the release resource is an unmanaged resource that is not JIT-managed by the CLR (Common language Runtime)-supervised resource
usingSystem;usingSystem.Collections.Generic;usingSystem.Data.SqlClient;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespacecase{classProgram {Static voidMain (string[] args) { //Using a using- release linked object stringstr ="Data source=.; Initial Catalog=blog; Uid=sa"; SqlConnection Con=NewSqlConnection (str); Con. Open (); Con. Dispose (); Con. Open (); Console.WriteLine ("OK"); Console.readkey (); //1. Import Namespaces//Releasing unmanaged Resources//2. Why {}, resources can be released automatically//because the system automatically calls the Dispose method of the object when the {} is out, Dispose (), internally calls Close (); //the difference between 3/dispose () and close//Dispose () destroys the con with DB//Close () does not destroy the channel and can be opened again//4 using (object) {}//whether all objects can be released by using the//No, the object is not allowed to have the close () method to use the using//the freed object must implement the IDisposable interface } }}
==============================================================================
The fourth chapter of business expansion three-tier framework
1.BLL
2.MD5 encryption
3. Ability to open transactions in C #
Shortcut keys alter+shift+ Primary key
Three-layer architecture diagram
Three Layer Schema Diagram
Characteristics of a transaction
Atomic Consistency Isolation Persistent
Begin Transaction
Commit Trabsaction
Rollback Transaction
Locking mechanism of a transaction
Concurrency Access Policy for transactions
Bypass transaction without locking in SQL
Select *from grade with (NOLOCK)
If there is physical involvement in the ADO, the real impact on the data sheet record is no longer
After you have finished playing the Excecute series method, but after the transaction commits or and I roll out
Enables multiple execution process data to be accurate to ensure the integrity of data across multiple execution units
The formation of a transaction should be formed after the linked object is opened open
String Str= ""; /Memory consumption
String str=string. empty;//consumes memory. Performance is higher than ""
String str=null;//does not account for memory
entity classes corresponding to Mobel and underlying tables
DAL and data table-related operations
BLL Isolation Dal and UI
UI is responsible for echoing the page
Common GM has
DataView Data expansion
Dv. Rowfilter= "Studentname=xxx";
Dv. soet= "Studentno desc";
====================================================================
Fifth. Advanced applications in entity class Windows programs
1 Layered dal The data Access layer is responsible for interacting with the database Mobel entity layer passes objects in three tiers the BLL business logic layer refers to the DAL responsible for business logic processing common tool classes have2, the reference relationship between the tiers BLL---->Mobel and Daldal--->Mobelui---->Mobel and Bllyijicommon3. Multiple-Path exception captureTry{}cath (Subclass exception) {}cath (Parent-class exception) {}4. Exception schema Diagram Sqlexceptionargumentnullexceptionfilenotfoundexceptionioexceptionapplicationexception5. Common Properties Message: StackTrace: Stack message more precise line number Innerexception:sql Statement App. Config is written at the UI layer but the developed node can be read at the DAL Layer 2, Because all dependent files after compilation are put down in the same directory under the Debug folder and Xxx.exe<connectionStrings> <add name="Constr"connectionstring=""/> <connectionStrings>you need to first introduce the System.Configuration assembly in the Dal to add a using reference using SYSXXX to write the SqlHelper file configurationmanager.connectionstring[ "Constr"]. ConnectionString6. Const and ReadOnly1the. Const-Modified data type can only be a value type and a string2. Const defines the location of the const class and the method are all rows readonly can only be in the class3. Const assignment Timing: Cheap is assignment, readonly runtime assignmentusingkeyword using can introduce namespaces using or release resourcesusing(IDisposible object) {released unmanaged resource}close and Dispose () Distinguish Connection object is destroyed7. Parametric query Universal landing Hair'or 1=1--Sqlconnectionsqlcommndsqldatreadersqldataadaptercmd.commandttype=commandtype.storedproceduresqlparameter[] P={ NewSqlParameter ("@gender", gender),NewSqlParameter ("@count", SqlDbType.Int) outputNewSqlParameter ("@name", SqlDbType.Int)return}p[1]. direction=parameterdirection.output;p[2]. direction=ParameterDirection.ReturnValue; Add to the Cmd object Cmd.parameters.AddRange (P); cmd.xxxxx ();p [1]. valuep[2]. Value8. Encryption Md5cryptoprovider m=NewMd5cryptoprovider (); String Str="xxxxx";byte[] b1=Encoding.Default.GetByTes (str);byte[] b2=M.computhash (bytes); String b=String.Empty;foreach(byteIteminchB2) {b+=item. ToString ("X2")}9. Turn on transaction transcation TX=con. Begintracrtion (); CND. Transaction=tx;tx.commit ();TenSelectGradeid asNumber, Gradename age name fromGrade
Depth. The layered development of software system in the net Platform