Разработка приложений на платформе Microsoft .Net: Методическое пособие

  • Published on
    08-Dec-2016

  • View
    218

  • Download
    5

Embed Size (px)

Transcript

  • Microsoft.Net 1

    & SoftLine Academy, 2006 . ..

    Microsoft .Net

    18 . Microsoft .Net

    Windows-, Web-. , Microsoft .Net Microsoft Visual Studio . 2005 .Net v2.0 Visual Studio 2005 .

    Microsoft .Net. : - C#, Windows-, . . ASP.NET 2 Web Services.

  • Microsoft.Net 2

    & SoftLine Academy, 2006 . ..

    Microsoft

    .Net ................................................................................................................................................1 ........................................................................................................................2 Microsoft .Net .................................................................................................3 #. .....................................................................................3 ...................................................................................................3 ......................................................................3 ................................................................................................4 .............................................................................................................5 .............................................................................................................5 ...................................................................................................................5

    ....................................................................................................................6 ..............................................................6 .............................................................................................7

    ...............................................................................................8 ........................................................................................................8 ...........................................................................................................8

    ..........................................................................................................................9 ..................................................................9 ...........................................................................................................................10 ..........................................................................................................................11 ...............................................................................................................11 .......................................................................................................................11

    1 ................................................................................................12 Windows Forms............................................................................................12 Form, MessageBox ....................................................................13 Form ...............................................................................................................13 MessageBox ..................................................................................................14 ToolBox ..............................................................................14

    ...............................................................................16 .............................................................................................................................17

    2 ................................................................................................17 ADO.NET..........................................................................................................................17 ADO.NET...............................................................................................18 .................................................................................19

    .................................................................................................19 ..................................19 ..............................................................................................19

    3 ................................................................................................21 ...................................................................................................22 .................................................................................................22 .................................................................22 ..................................22 ....................................................................................................................22

  • Microsoft.Net 3

    & SoftLine Academy, 2006 . ..

    Microsoft .Net Microsoft .Net

    . 5 . , , . , . , , [1]. Microsoft .NET -. .Net Microsoft .Net Framework , .

    .NET (CLR, common language runtime). Java Runtime Environment, . , (managed code) , .NET runtime. Microsoft Intermediate Language (MSIL, IL). , , .. .

    . , (versioning).

    #. .Net ,

    . C#, , . C# ++ Java, , , .

    Hello, world!. class Hello {

    public static void Main(string[] args) {

    System.Console.WriteLine("Hello, world!"); }

    } 1. Hello,world C# - .

    - Main. . , DLL. . 1.

    , .Net . ,

    .Net Framework , - Framework Class Library (FCL). .

  • Microsoft.Net 4

    & SoftLine Academy, 2006 . ..

    /\. , (ADO.NET), (ASP.NET), windows (Windows Forms), XML (DOM, XSD, XSLT, /, ADO.NET), (System.Net), (remoting), COM+ (Enterprise Services, Serviced components), (System.Security.Cryptography).

    , . System.

    System.Console.WriteLine("Hello, world!"); "Hello, world!"

    WriteLine Console, System. , . , . . .

    using System; class Hello { public static void Main(string[] args) { Console.WriteLine("Hello, world!"); } } 2. Hello,world using System using,

    , . , , , using , .

    C# csc.exe (C Sharp

    Compiler). , Windows XP .Net Framework v2.0, c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727. .Net Framewrok 2 net. %net%\csc.exe. . .

    /t:exe /t:winexe /t:library /t:module

    Windows

    /t:exe . , , %net%\csc hello.cs, hello.exe.

  • Microsoft.Net 5

    & SoftLine Academy, 2006 . ..

    1. , Main . , , .

    C# .

    : sbyte, byte, char, short, ushort, int, uint,

    long, ulong, float, double, decimal.

    - -, .

    . enum [: ] { 0 = 0,,N = N } 1.

    , : enum DayOfWeek {Monday=1, Tuesday, Wednesday, Thursday, Friday, Saturday Sunday};

    . ,

    . , :

    ; ; .

    , , , .

    struct Point { public int x,y; public Point(int p1, int p2) { x=p1; y=p2; }

    - (value-types)

    (reference types)

    (int, float,) (enum) (struct)

    (class) (delegate) (interface) (System.String) System.Object (System.Array)

  • Microsoft.Net 6

    & SoftLine Academy, 2006 . ..

    } struct Circle { public Point Centre; public int Radius; public Circle(int p1,int p2,int p3) { Centre=new Point(p1,p2); Radius=p3; } } 3. , . .

    C# Visual Basic . C#

    7 : , , , , , .

    ,

    static. . , . . .

    class Variables { static int N1; int N2; public Variables(int p1, int p2) { N1=p1; N2=p2; } public static void Main(string[] args) { Variables var1 = new Variables(10,20); System.Console.WriteLine(" .: "+Variables.N1.ToString()); Variables var2 = new Variables(100,200); System.Console.WriteLine(" .: "+Variables.N1.ToString()); System.Console.WriteLine(" .: "+var1.N2.ToString()+" "+var2.N2.ToString()); } } 4. var2 N1 , ..

    .

  • Microsoft.Net 7

    & SoftLine Academy, 2006 . ..

    , .

    . , . class Variables { public static void Main(string[] args) { int a; { int b; } { int a; // , int b; // , .. } } } 5. ( )

    class Variables { public static void Main(string[] args) { // int a; { int b; } { int a; int b; } } } 6. ( )

    , .

  • Microsoft.Net 8

    & SoftLine Academy, 2006 . ..

    System.Console. Console.WriteLine(Hello, World!); Console.Write(Hello, World!); .

    . Console.WriteLine({0}, {1}{2},Hello,World,!); . {N,M:F}, : N ( ); M ; F ; R . : - ; D - ; E - 1e+3; F - 123.456; G - ; N - 123,456,789.5; X - .

    C# ,

    . int i = Console.Read(); string str = Console.ReadLine(); . string str = Console.ReadLine(); int i = Int32.Parse(str); float f = Float.Parse(str); double d = Double.Parse(str);

  • Microsoft.Net 9

    & SoftLine Academy, 2006 . ..

    System.Array. CLR

    : ; ; (jagged) .

    . class Arrays { static void Main(string[] args) { int[] a = new int[3]; int[] b = { 1,2,3 }; int[] d; // d = null d = b; // d c ! a = (int[])b.Clone(); // int[,] e = new int[2, 3] { { 1, 2, 3 }, { 4, 5, 6 } }; // int[][] f = new int[2][]; // f[0] = new int[3] { 0, 1, 2 }; f[1] = new int[2] { 3, 4 }; // } } 7. : Length ; Rank ; GetLength(int i) i- .

    C# : if, switch; :

    for, while, do, foreach. goto .

    if (a>b) { Console.WriteLine(a>b); } else { Console.WriteLine(a

  • Microsoft.Net 10

    & SoftLine Academy, 2006 . ..

    int a=10; switch (a) { case 0: ; break; case 1: ; break; default: ; break; } 9. SWITCH , default, ,

    . int[] a ={ 10, 20, 30, 40 }; for (int i=0;i1) { a /= 10; } 11. WHILE int a=5678; do { a /= 10; } while (a>1); 12. DO int[] a ={ 10, 20, 30, 40 }; foreach (int i in a) { System.Console.WriteLine(i); }; 13. FOREACH foreach

    for.

    C# , ++ Java.

    : - class - { } .

    : public ; internal (). internal. :

  • Microsoft.Net 11

    & SoftLine Academy, 2006 . ..

    (field) ( ) ( ) (property) ( ) (event)

    :

    private () public protected internal - protected internal.

    : - -o - -(-) { - }

    : public, private, protected - C++ internal -

    : static ( ++) virtual, override, new

    ,

    . Variables var = new Variables(); new , Variables() . .

    . , .

    . , .

    . . protected.

    . .

    . set()

    , get() .

  • Microsoft.Net 12

    & SoftLine Academy, 2006 . ..

    , .

    , . .

    1 C#,

    . .

    : ...; ; ; .

    , . . : , , , , , .

    . . .

    Windows Forms .Net

    , Microsoft Visual Studio 2005.

    WindowsForms FCL . WindowsForms System.Windows.Forms.

    Windows- Microsoft Visual Studio 2005 .

  • Microsoft.Net 13

    & SoftLine Academy, 2006 . ..

    Visual Studio 2005 , Delphi. Visual Studio 2005 MDI, SDI-.

    Form, MessageBox

    Form Form. .Net 2

    . VS2005 . .cs. . - < >.Designer.cs. , Visual Studio. .

    partial class PartCl { int a; int b; } partial class PartCl { public PartCl(int p1, int p2) { a=p1; b=p2; } } 14. . Properties.

  • Microsoft.Net 14

    & SoftLine Academy, 2006 . ..

    Solution Explorer

    ( ), , Add->Windows Form. , OK. Solution Explorer , View->Solution Explorer.

    : Load; GotFocus; Activated; Closing; Closed; Deactivate; LostFocus; Dispose.

    . Form: Show ShowModal. Show , ShowModal .

    MessageBox - Show

    MessageBox System.Windows.Forms. MessageBox.Show(This is a test, Title, MessageBoxButtons.OK); ,

    . if(MessageBox.Show(Press Yes or No?, Title, MessageBoxButtons.YesNo) == DialogResult.Yes) {};

    ToolBox Windows-

    . , .

  • Microsoft.Net 15

    & SoftLine Academy, 2006 . ..

    ToolBox

    Choose ToolBox Items. Choose Items ToolBox.

  • Microsoft.Net 16

    & SoftLine Academy, 2006 . ..

    Toolbox

    .

    - ,

    . . , Properties, private void InitializeComponent().

    . : , .

    private void button1_Click(object sender, EventArgs e) EventArgs .

    Format.

    Splitter.

    partial class Form1 { private System.ComponentModel.IContainer components = null; private System.Windows.Forms.Button button1; }

  • Microsoft.Net 17

    & SoftLine Academy, 2006 . ..

    MenuStrip. . -.

    private void

    InitializeComponent(). private System.Windows.Forms.MenuStrip menuStrip1; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem2; private System.Windows.Forms.ToolStripSeparator toolStripMenuItem3; private System.Windows.Forms.ToolStripComboBox toolStripComboBox1;

    . private void toolStripMenuItem2_Click(object sender, EventArgs e)

    2 , 1.

    .

    ADO.NET ADO.NET . ADO.NET

    : .

    . . , .

    . . .

    ADO.NET , .

  • Microsoft.Net 18

    & SoftLine Academy, 2006 . ..

    ADO.NET :

    . , . DataSet. :

    1. ; 2. ; 3. . DataSet : DataTable

    DataRelation.

    DataTable . DataTable

    : DataColums ; Constraints ; DataRows , . DataRelation . . .NET Framework

    .: SQL Server .NET Data Provider c Microsft

    Sql Server 7.0 ; OleDB .NET Data Provider c .

    : Connection, Command, DataReader, DataAdapter.

  • Microsoft.Net 19

    & SoftLine Academy, 2006 . ..

    SqlConnetcion OleDbConnection . SqlCommand OleDbCommand

    SQL. SqlDataReader OleDbDataReader

    Select. .

    SqlDataAdapter OleDbDataAdapter DataSet DataSet.

    Visual Studio2005 .

    . , Microsoft Sql Server 2005.

    , ,

    DataGridView.

    Add Project Data Source .

    Data Source Configuration Wizard. . , .

  • Microsoft.Net 20

    & SoftLine Academy, 2006 . ..

    Choose Data Source Data Source Microsoft Sql

    Server ....

Recommended

View more >