HO CHI MINH UNIVERSITY OF INDUSTRY Faculty of Information Technology LAB REPORT Software Development Topics Student:Vũ Văn Thức ID:09017172 Class:CDTH11K I.Part 1: Custom Component 3 1) Exercise 1: 3 2) Exercise 2: 4 3) Exercise 3: 5 4) Exercise 4: 6 5) Exercise 5: 7 6) Exercise 6: 7 7) Exercise 7: 8 8) Exercise 8: 9 9) Exercise 9: 9 10) Exercise 10: 10 11) Exercise 11: 10 12) Exercise 12: 11 13) Exercise 13: 11 14) Exercise 14: 12 15) Exercise 15: 12 16) Exercise 16 13 17) Exercise 17: 13 18) Exercise 18: 14 II.Part 2: LinQ 14 1) Exercise 1: 14 2) Exercise 2: 15 3) Exercise 3: 15 4) Exercise 4: 16 5) Exercise 5: 16 III.Part 3: WPF 17 1) Exercise 1: 17 2) Exercise 2: 19 3) Exercise 3: 19 4) Exercise 4: 20 5) Exercise 5: 20 IV.Part 4: Net Remoting 23 1) Exercise 1: 23 Part 1: Custom Component 1) Exercise1: Creating Metro Forms Cách làm: Tạo project như bình thường. Project Add Window Form. Chọn Metro Form hoặc Metro App Form. Kết Quả : 2) Exercise2: Office 2007 Ribbon Control Cách làm: Tạo project như bình thường. Click chuột phải vào Form chính chọn View Code. Đổi phần thừa kế của Form thành Office2007RibbonControl Trong thanh Toolbox kéo thả RibbonControl vào Form
Trang 1HO CHI MINH UNIVERSITY OF INDUSTRY
Faculty of Information Technology
LAB REPORT
Software Development Topics
Student:Vũ Văn Thức ID:09017172
Class:CDTH11K
Trang 2I.Part 1: Custom Component 3
1) Exercise 1: 3
2) Exercise 2: 4
3) Exercise 3: 5
4) Exercise 4: 6
5) Exercise 5: 7
6) Exercise 6: 7
7) Exercise 7: 8
8) Exercise 8: 9
9) Exercise 9: 9
10) Exercise 10: 10
11) Exercise 11: 10
12) Exercise 12: 11
13) Exercise 13: 11
14) Exercise 14: 12
15) Exercise 15: 12
16) Exercise 16 13
17) Exercise 17: 13
18) Exercise 18: 14
II.Part 2: LinQ 14
1) Exercise 1: 14
2) Exercise 2: 15
3) Exercise 3: 15
4) Exercise 4: 16
5) Exercise 5: 16
III.Part 3: WPF 17
1) Exercise 1: 17
2) Exercise 2: 19
3) Exercise 3: 19
4) Exercise 4: 20
5) Exercise 5: 20
IV.Part 4: Net Remoting 23
1) Exercise 1: 23
Trang 3Part 1: Custom Component
1) Exercise1: Creating Metro Forms
Cách làm:
-Tạo project như bình thường
- Project/ Add Window Form
-Chọn Metro Form hoặc Metro App Form
Trang 4Kết Quả :
2) Exercise2: Office 2007 Ribbon Control
Cách làm:
-Tạo project như bình thường
- Click chuột phải vào Form chính chọn View Code
-Đổi phần thừa kế của Form thành Office2007RibbonControl
-Trong thanh Toolbox kéo thả RibbonControl vào Form
Trang 5Kết Quả:
3) Exercise3: Ribbon MDI Merging
Cách Làm:
-Tạo project như bình thường
-Kéo thả Ribbon Control vào form chính
-Trong form chính chọn thuộc tính isMdiContainer=true.-Tạo button để mở form con ta được:
Trang 6-Tạo Form con và kéo thả RibbonBarMergerContainer vào form và tạo vài control vào ta được:
Trang 7Kết Quả:
4) Exercise4: Ribbon Contextual Tab GroupsCách Làm
-Tạo Office2007RibbonControl
-Chọn RibbonTab sửa thuôc tính Group
-Muốn cho cùng nhóm thì cho cùng tên Groub
Trang 96) Exercise6: Grouping Popup Gallery Items
Trang 10Kết Quả:
8) Exercise8: Creating Menus and Toolbars with DotNetBar Cách Làm:
-Trong form kéo thả DotNetBarMannager vào
-Click phải chọn Add Menu Bar
-Click phải chọn Add ToolBar và Add các Button menu vàoKết Quả:
Trang 119) Exercise9: Creating Dockable Window
Cách Làm:
-Trong form kéo thả DotNetBarMannager vào
-Click phải vào DotNetBarMannager chọn Crete Dock Bar left ,right,button,top
-Hiệu chỉnh theo ý muốn
Trang 12Kết Quả:
10) Exercise10:Creating Context Menus
Cách Làm:
-Trong Toolbox kéo thả ContextMenuBar vào form
-Chỉnh menu theo ý muốn
-Control nào muốn sử dụng thì chọn thuộc tính ContextMenu On : là tên của ContextMenuBar vừa tạo
Kết Quả:
11) Exercise11: Office 2010 Status bar
Cách Làm:
Trang 13-Trong Toolbox kéo thả bar vào from rồi gán thuộc tính Dock là botton.-Thêm các button vào Bar để hiển thị thông tin.
Trang 14-Chọn tab vừa tạo click phải chọn Choose items.
-Chọn tab Net Famework Component rồi tick vào các control muốn hiển thị
Trang 1514) Exercise14:Working with NavigationPane Control
Cách Làm:
-Trong thanh Toolbox kéo thả NavigationPane vào from
-Click phải vào NavigationPane tạo vài panel
-Kéo thả một vài textbox … vào
Kết Quả:
15) Exercise15: Working with New Tab Control
Cách Làm:
-Trong thanh Toolbox kéo thả Tab Control vào from
-Click phải vào panel vừa tạo chọn Create new tab để tạo thêm tab.-Điền thông tin và chỉnh một số chức năng của tab theo yêu cầu
Trang 16Kết Quả:
16) Exercise16: Working with New BubbleBar Control
Cách Làm:
-Trong thanh Toolbox kéo thả BubbleBar vào from
-Thêm một vài tab và item cho BubbleBar
Kết Quả
17) Exercise17: Working with New ExpandableSplitter Control
-Cách Làm:
-Kéo thả một panel vào form chỉnh dock là left
-Kéo thả ExpandableSplitter vào from
-Hiệu chỉnh thuộc tính của ExpandControl ExpandableSplitter chọn panel vừatạo
Trang 17-Tương tự với panel nằm bên phải.Kết Quả:
Trang 1818) Exercise18: Document Docking
-Cách Làm:
-Kéo DotNetBarManager vào from
-Chuột phải vào DotNetBarManager vừa tạo chọn Enable Document Docking
-Chuột phải vào Document Docking để tạo thêm vài tab
-Dùng chuột kéo thả các Document Docking vào vị trí thích hợp.Kết Quả:
II.Part 2: LINQ
1) Exercise 1:Example 1
Mô tả: Sử dụng câu query của LinQ:
-Code:
Trang 19
2) Exercise 2:Chuyển mảng số từ chuỗi sang mảng số
Mô tả: S =“20;10;2;0;1;0” => array of int {20,10,2,0,1,0}
Code:
string s = "20;10;2;0;1;0" ;
string [] arr = s.Split( ';' );Tạo mảng chỉ gồm số
List < int > numbersList = arr.Select(m =>m.ToNumber()).ToList(); Chuyển qua list
int [] arrInt = numbersList.ToArray();Chuyển từ list qua arrayKết Quả:
3) Exercise 3:Ví dụ về lazy loading
Mô tả:
Code:
var source = newList<string>() {"A","B","C"};
var sources = from c in source
select c;
source.Add("D");
=> Kết quả sẽ là A,B,C,D
Trang 20Kết Quả:
4) Exercise 4:LinQ Query Syntax
Mô tả:Phân biệt Query Syntax và Method syntax
Code:
//Query syntax
IEnumerable<int> query1 = from num in numbers
where num % 2 == 0 orderby num
-Add LinQ to SQL class
PetshopDataContext db = newPetshopDataContext();//Tạo xxxDatacontex để truycập csdl
Trang 21var product = from m in db.Products select m; Lấy dữ liệu bảng Product
Trang 22-Thêm một dũ liệu qua LinQ:
Product product = newProduct();Tạo một product
Nhập dữ liệu cho product
PetshopDataContext db = new PetshopDataContext();
db.Products.InsertOnSubmit(product);Thực hiện insert
db.SubmitChanges(); Lưu vào csdl
-Xóa:
PetshopDataContext db = new PetshopDataContext();
string proID = txtProID.Text;
Product b = db.Products.Single(c => c.ProductId == proID);
db.Products.DeleteOnSubmit(b); Thực hiện xóa
db.SubmitChanges();
-Sửa:
PetshopDataContext db = newPetshopDataContext();
Product prod = db.Products.Single(a => a.ProductId == id);
prod.CategoryId = txtCategoryID.Text;
prod.Name = txtName.Text;
prod.Descn = txtDescn.Text;
prod.Image = txtImage.Text;
db.SubmitChanges(); // Lưu thay đổi
III.Part 3: WPF (Windows Presentation Foundation)
1) Exercise 1:Đổi màu chữ tìm thấy
Mô tả :Cho một đoạn văn bản có sẵn Viết chương trình tìm kiếm một từ nhập vào và tô màu từ đó nếu có trong đoạn văn bản đó
Trang 23-Tạo một Brush chứa màu theo yêu cầu
Run run = newRun(); run.Background = brush; Tạo Run để thay đổi màu chữ
textBlock1.Text = ""; Gán xóa chữ của texBlock
foreach (string str in chuoi)
Trang 242) Exercise 2:Basic control
Mô tả: Tạo một vài control cơ bản trong wpf
Trang 25</Button>
Thêm thuộc tính Offset và GradientOrigin để thay đổi hiệu ứng
Kết Quả:
4) Exercise 4:Tạo Control động
Mô tả: Tạo Control động
Code:
StackPanel pn = new StackPanel (); Tạo panel
TextBox txt = new TextBox (); Tạo textbox
txt.Text = "Hello teo" ;
Button bt = new Button (); Tạo button
bt.Content = "Click me" ;
Add textbox và button vào panel
pn.Children.Add(txt);
pn.Children.Add(bt);
this Content = pn; Add panel vào form chính
5) Exercise 5: Di chuyển Button
Mô tả:Di chuyển button quanh form
Code:
Vector Position; //Vi tri
Vector Velocity; // Van toc
Vector size; // size cua button
Position = new Vector (button1.Margin.Left, button1.Margin.Top); Vị trí của button
size = new Vector (button1.Width, button1.Height); Lấy kích thước của button
Trang 26Di chuyển xung quanh form theo chiều kim đồng hồ:
if ((Velocity.X + Position.X + size.X) >= this Width) Kiểm tra xem button có di chuyển ra ngoài cùng bên phải không
Velocity = new Vector (0, Velocity.X); dừng di chuyển theo chiều ngang => di chuyển
đi xuống(velocity=(0,+a))
if ((Velocity.Y + Position.Y + size.Y + 30) >= this Height) di chuyển ra ngoài phía dưới
Velocity = new Vector (-Velocity.Y,0); chuyển theo chiều dọc => di chuyển đi ngang giản dần(velocity=(-a,0)
if ((Velocity.X + Position.X) <= 0) di chuyển ra ngoài cùng bên trái
Velocity = new Vector (0,Velocity.X); dừng di chuyển theo chiều ngang => di chuyển
đi lên(velocity=(0,-a) vì trước đó velocity.X <0)
Lại một vòng mới
if ((Velocity.Y + Position.Y) < 0) di chuyển ra ngoài phía trên
Velocity = new Vector (-Velocity.Y,0); chuyển theo chiều dọc => di chuyển đi ngang tăng dần(velocity=(+a,0) vì trước đó Velocity.Y<0)
Di chuyển button
Position += Velocity;
button1.Margin = new Thickness (Position.X + Velocity.X, Position.Y + Velocity.Y, 0, 0);
Di chuyển tự do:
Velocity có giá tri x và y là 1, chỉ cần thay đổi dấu để đổi hướng:
if ( (Velocity.X + Position.X+size.X) > this Width)
Velocity = new Vector (-Velocity.X,Velocity.Y);
if ( (Velocity.X + Position.X) < 0)
Velocity = new Vector (-Velocity.X, Velocity.Y);
if ( (Velocity.Y + Position.Y+size.Y+30) > this Height)
Velocity = new Vector (Velocity.X, -Velocity.Y);
Trang 27File Resource :
-Tạo Style cho button bằng target :
<Style TargetType ="{x Type Button }">
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property ="Width" Value ="100"/>
<Setter Property ="Height" Value ="40"/>
</Style>
-Tương tự với texbox:
<Style TargetType ="{x Type TextBox }">
<Setter Property ="Width" Value ="100"/>
<Setter Property ="Height" Value ="30"></Setter>
<Style.Triggers>
<Trigger Property ="IsMouseOver" Value ="True">
<Setter Property ="Background" Value ="red"></Setter> <Setter Property ="FontSize" Value ="14"></Setter> </Trigger>
Trang 28Kết Quả:
IV.Part 4
1) Exercise 1:Viết chương trình giải phương trình bậc 2
Mô t ả : Dùng Net Remoting viết chương trình có server và client giải phươngtrình bậc 2
private int client;
+Tạo get và set
Trang 29
string url = "http://localhost:" +
Int32 Parse(txtPort.Text) + "/GiaiPT" ;
RemotingConfiguration RegisterWellKnownClientType( typeof ( GiaiPhuongTri nhBac2 ), url);
int a = Int32 Parse(txtA.Text);
int b = Int32 Parse(txtB.Text);
int c = Int32 Parse(txtC.Text);
Trang 30httpChannel = new HttpChannel ( Int32 Parse(txtPort.Text));
ChannelServices RegisterChannel(httpChannel, false );
WellKnownObjectMode mode = WellKnownObjectMode SingleCall;
Trang 31Kết Quả: