Вы находитесь на странице: 1из 61

1 Windows Software Development in C#

C# OOP
C# Tutorial C#.Net
W n ows So tw r

Create Project
1
FILE >> N w >> Proj ct…

2
Visual C# >> Windows Forms Application Select
2 Windows Software Development in C#

3
Name : CoffeeShop
Location: project File
Solution name :

OK

Project

႔ Project ႔

႔ variable , array, list ႔


run ႔
program run stop >>
3 Windows Software Development in C#

File system ႔ Fl Input out ႔


႔ varia l rr y l st ႔
.txt ႔ /
႔ ႔

႔ database
႔ project database ႔ ႔ database ႔
Project

Program.cs

႔ Project run run class

Application.Run(new Form1());

Form Form1
4 Windows Software Development in C#

၁ Form
CoffeeShop Right Click
A >> W n ows Form …

၂ Form2.cs MainForm ႔ Space ႔ Add


5 Windows Software Development in C#

Run Form1
MainForm
Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CoffeeShoop
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}

Application.Run(new Form1()); Form MainForm


run
6 Windows Software Development in C#

Form1 ႔ ႔

MainForm Menu Bar


7 Windows Software Development in C#

Products ႔ Form

Label
Textbox
utton
8 Windows Software Development in C#

Textbox Product Name txtProductName Price txtPrice


Button btnSave , btnUpdate, btnDelete, btnSelect ႔
Properties Name

DataGridView

က္ေတား ဆျဲထာ့တဲံအတုိငး့ ညီေအာငး


ဆျဲေပ့ပါ။

အေပၚေဘ့ေတျမြာ
ေလ့ေထာငးံအကျကးေတျ ေပၚေနတဲံ
ေနရာမြာ ်မြာ့ေလ့တငးၿပီ့ေတာံ ဆျဲလုိ႔
ရပါတယး။
9 Windows Software Development in C#

Create Database and Table

D t s >> N w D t s ….

CoffeeShop ႔ OK
10 Windows Software Development in C#

Database Table

T l s >> N w >> T l …

က္ေတား
ေရ့်ပထာ့တဲံအတုိငး့
column name,
data type,
llow nulls ေတျကုိ
ေသခ္ာ ်ဖညးံေပ့ပါ။
ၿပီ့ရငး Save
11 Windows Software Development in C#

Ctrl+S Choose Name table ႔


OK

(၂)
Id Primary Key
(၁)
productid right click >> Set Primary Key
12 Windows Software Development in C#

product
user product

product
id id
႔ pro r mm r ႕

productid Primary Key

(၂)
productid user ႔ program auto

product productid ၁
product productid ၂ ႔၁ ၁

productid s l ct
13 Windows Software Development in C#

(Is Identity) double click (Yes ႔ )

Identity Increment = 1 id ၁
Identity Seed =1 ႔ ၁ id ၁
14 Windows Software Development in C#

Database ႔
႔ C# UI
Mssql server Database ႔ Table
႔ ႕ ႔ Database ႔

1. Co Shop >>(R ht Cl ck) A >> N w It m…

V su l C It ms >> D t >> D t S t ( Add ႔ )


15 Windows Software Development in C#

Name : MyDataSet ႔ Add

Database ႔ ႔ DataSet.xsd Class


Database ႔

Software version
1. Standalone Version
2. Server Version/ Network Version
Standalone Version Database
install
install
႔ ႔

Server Version/ Network Version


႔ Database
႔ oceans supermarket
Server

Database
Server ႔ S rv r V rs on N twork V rs on
16 Windows Software Development in C#

Developer ႔
Basic ႔

? Developer
Developer ?
Project database ႔ database

Database Management System (DBMS) Normalization

Project OOP ႔ Class


Library ႔
D v lop r ႔ ႔

႔ ႔

Error
Developer ႔ Error ႔

Error Program.cs ႔
App.config ႔ Button Form Double click
Error
Error
Error Provider SaYarChit
Error ႕
17 Windows Software Development in C#

Database ႔
Xsd
Xs Right Click
A >> T l A pt r…

႔ ႔
N w Conn ct on…
18 Windows Software Development in C#

Server Name မြာ ထညးံရမယးံ Server


Name

Microsoft SQL Server ကုိ ဖျငးံ

ေအာကးကပုဵမြာ ်ပထာ့တဲံ Server


Name ကုိ ထညးံေပ့ရမြာ ်ဖစးပါတယး။
19 Windows Software Development in C#

Server Name ႔


Database
20 Windows Software Development in C#

database name

r Test Connection
21 Windows Software Development in C#

Database ႔ ( )

Ok Ok
22 Windows Software Development in C#


S rv r n m D t s n m

Connection String ႔

Next
23 Windows Software Development in C#

႔ Next

Next
(Sql st t m nt ႔ )
24 Windows Software Development in C#

Qu ry u l r…

Query Builder ( database


T l tblProducts ႔
)
25 Windows Software Development in C#

Add ( )

All Column Ok
26 Windows Software Development in C#

OK ႔ Finish

Database ႔
27 Windows Software Development in C#

Database ႔

<?xml version="1.0" encoding="utf-8" ?>


<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="CoffeeShoop.Properties.Settings.CoffeeShopConnectionString"
connectionString="Data Source=HANNI-PC;Initial
Catalog=CoffeeShop;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

App.config File ႔
Database ႔ ?
28 Windows Software Development in C#

<connectionStrings>
<add name="CoffeeShoop.Properties.Settings.CoffeeShopConnectionString"
connectionString="Data Source=HANNI-PC;Initial
Catalog=CoffeeShop;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>

Database ႔

add name="CoffeeShoop.Properties.Settings.CoffeeShopConnectionString"
connectionString="Data Source=HANNI-PC;Initial Catalog=CoffeeShop;Integrated
Security=True"
connectionString="Data Source=HANNI-PC;Initial Catalog=CoffeeShop;Integrated
Security=True"
Database ႔

D t Sourc =”HANNI-PC”
Initial Catalog=CoffeeShop
Int r t S cur ty=Tru ”

D t Sourc =”HANNI-PC” D t s S rv r N m
Initial Catalog=CoffeeShop Server D t s N m
Int r t S cur ty=Tru ” Database Server User Name, Password ႔
Tru

add name="CoffeeShoop.Properties.Settings.CoffeeShopConnectionString"
Database ႔
႔ “” ႔
add name="dbConnection" ႔ Error
29 Windows Software Development in C#

add name="CoffeeShoop.Properties.Settings.CoffeeShopConnectionString"

CoffeeShopConnectionString Settings
Settings Properties
Properties CoffeeShoop

CoffeeShoop Porperties Settings CoffeeShopConnectionString

CoffeeShoop.Properties.Settings.CoffeeShopConnectionString ႔ . (dot) ႔

႔ Database ႔ ႔ ႔ Visual Studio


Auto

Table C# ႔
30 Windows Software Development in C#

C# Database table

Product Name textbox database Products table productname


column
Price textbox Products table price

Save button double click


31 Windows Software Development in C#


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CoffeeShoop
{
public partial class Products : Form
{
public Products()
{
InitializeComponent();
}
private void btnSave_Click(object sender, EventArgs e)
{
}
}
}

ဒီထမ
ဲ ြာ

Database ထဲက table


ထဲကုိ တနးဖုိ့ထညးံတံဲ
ကုဒးေရ့မယး။
32 Windows Software Development in C#

Database table ႔

၁ using System.Data.SqlClient;
System.Data.SqlClient; using

၂ SqlConnection o j ct

SqlConnection o j ct

SqlConnection() ႕ ()

SqlConnection(string connectionString)
33 Windows Software Development in C#

? ႕ connectionString

connectionString App.config

"Data Source=HANNI-PC;Initial Catalog=CoffeeShop;Integrated Security=True"

copy
SqlConnection() ႕ ()

SqlConnection("Data Source=HANNI-PC;Initial Catalog=CoffeeShop;Integrated Security=True")

၃ Database ႔
o j ct SqlConnection
SqlCommand object Column
Execute
SqlConnection
34 Windows Software Development in C#

SqlConnection ႔ SqlCommand o j ct ( )

SqlCommand()

string cmdText, SqlConnection connection

cmdText insert statement database code string ႔


႔ ႕ string ႔
string ႔ “” ႔ ႔

SqlConnection connection SqlConnection o j ct connection

SqlCommand command = new SqlCommand("insert into tblProducts (productname,


price)values(@productname,@price)", connection);

column textbox
command.Parameters.AddWithValue("@productname", txtProductName.Text);
command.Parameters.AddWithValue("@price", double.Parse(txtPrice.Text));
command Execute
command.ExecuteNonQuery();
connection
connection.Close();

database C#
35 Windows Software Development in C#

႔ program run

Run Program

run Products Form run

႕ Run Form ႔
Program.cs
36 Windows Software Development in C#

Porgram.cs file

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}

Application.Run(new MainForm());
statement Form

Products Form ႔
႔ Products

Application.Run(new Products());

Run
37 Windows Software Development in C#

Data

Run Textbox
Save
႔ Mssql server
tblProducts >> (Right click) Edit Top 200 Rows
38 Windows Software Development in C#

Database ႔ Pro ucts Form

Ins rt Up t D l t S l ct Insert Update , Delete


Select

Select
Database Select ႔ Retrieve
႔ ႔ ႔ CRUD
Project
CRUD Insert, Update , Delete, Select
Create, Retrieve, Update, Delete ႔ Select
>>

D t Gr V w Right click
Properties
39 Windows Software Development in C#

႔ Name ႕ dataGridView1 dgvProducts ႔


dgv dataGridView ႕

Select Gr v w

C#.Net Gr V w ႔

Co
Code ၂

႔ database ႔
႔ ႔ ႔
40 Windows Software Development in C#

Select ႔
Database

41 Windows Software Development in C#

၁ nu Icon DataGridView Tasks


၂ Choose Data Source ႕ Combo box

Other Data Sources ႕ ႔


42 Windows Software Development in C#

tblProducts

Database tblProducts table column GridView




43 Windows Software Development in C#

႔ Pro ucts Form Richt Click


View Code (Form )

႔ Program Run

private void Products_Load(object sender, EventArgs e)


{
this.tblProductsTableAdapter.Fill(this.myDataSet.tblProducts);
}
44 Windows Software Development in C#

Result ႔

private void Products_Load(object sender, EventArgs e)


{
this.tblProductsTableAdapter.Fill(this.myDataSet.tblProducts);
}

Program Gr V w

this.tblProductsTableAdapter.Fill(this.myDataSet.tblProducts);

// ႔ program Run
45 Windows Software Development in C#

Update
Database Form

Save textbox

private void btnSave_Click(object sender, EventArgs e)


{
SqlConnection connection = new SqlConnection("Data Source=HANNI-
PC;Initial Catalog=CoffeeShop;Integrated Security=True");
connection.Open();

SqlCommand command = new SqlCommand("insert into tblProducts


(productname, price)values(@productname,@price)", connection);

command.Parameters.AddWithValue("@productname", txtProductName.Text);
command.Parameters.AddWithValue("@price", double.Parse(txtPrice.Text));

command.ExecuteNonQuery();
connection.Close();

TextClear();
ေအာကးက TextClear() Method ကုိ ေခၚလုိကးတာပါ။
}
private void TextClear()
Textbox ထဲက စာသာ့ေတျကုိ ရြငး့ေပ့တဲံ
{
ကုဒးကုိ Method တစးခု ဖနးတီ့ၿပီ့
txtProductName.Text = "";
ေရ့ထာ့တာပါ။
txtPrice.Text = "";
}
46 Windows Software Development in C#

DataGridView (Row) Double Click


႔ Textbox

Gr V w (Right Click) >> Properties

အ်ဖဴေရာငးနဲ႔ ွုိငး့်ပထာ့တဲံေနရာကုိ ၾကညးံပါ။

မုိ့ႀကဳိ့ပုဵစဵေလ့နဲ႔ ်ပထာ့တာက Event အတျကးပါ။

Mouse ကုိ တငးၾကညးံလုိကးရငး စာေပၚလာလိမးံမယး။

Class တစးခုဟာ Properties နဲ႔ Ev nt ေတျ


ပုိငးဆုိငးတယးဆုိတာကုိ ်ပနးသတိရပါ။

Event ကုိ ႏြိပးလုိကးပါ။


47 Windows Software Development in C#

Events GridView ႕
GridView ႕ Row Double Click
Row Textbox

႔ H ht L ht CellDoubleClick Double Click


48 Windows Software Development in C#

private int productid;


private void dgvProducts_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
productid = Convert.ToInt16(dgvProducts.Rows[e.RowIndex].Cells[0].Value.ToString());
txtProductName.Text = dgvProducts.Rows[e.RowIndex].Cells[1].Value.ToString();
txtPrice.Text = dgvProducts.Rows[e.RowIndex].Cells[2].Value.ToString();
}


dataGridView ႕ Cell Double Click ႔ productid productid
cell
txtProductName productname ႕ cell

Cell, Row, Column ႔

Row Cell[0], Cell[1], Cell[2] ႔

btnUpdate Double Click ႔

private void btnUpdate_Click(object sender, EventArgs e)


{
}
49 Windows Software Development in C#

private void btnUpdate_Click(object sender, EventArgs e)


{
SqlConnection connection = new SqlConnection("Data Source=HANNI-PC;Initial Catalog=
CoffeeShop;Integrated Security=True");
try
{
if (productid==null)
{
MessageBox.Show("Please Double click Row To Update");
}
else
{
SqlCommand command = new SqlCommand("Update tblProducts SET productname=
@productname, price=@price where productid=@productid", connection);
connection.Open();

command.Parameters.AddWithValue("@productid", productid);
command.Parameters.AddWithValue("@productname",txtProductName.Text);
command.Parameters.AddWithValue("@price", double.Parse(txtPrice.Text));
command.ExecuteNonQuery();
TextClear();
MessageBox.Show("Data Updated");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
}
}
႔ if statement
program s ႔ productid update User
႔ try catch finally
50 Windows Software Development in C#

Delete
Update Delete ႔

private void btnDelete_Click(object sender, EventArgs e)


{
SqlConnection connection = new SqlConnection("Data Source=HANNI-PC;Initial
Catalog=CoffeeShop;Integrated Security=True");
if (productid != 0)
{
SqlCommand command = new SqlCommand("delete tblProducts where
productid=@productid", connection);

connection.Open();
command.Parameters.AddWithValue("@productid", productid);
command.ExecuteNonQuery();
connection.Close();

this.tblProductsTableAdapter.Fill(this.myDataSet.tblProducts);
TextClear();

MessageBox.Show("Record Deleted Successfully!");


}
else
{
MessageBox.Show("Please Select Row to Delete");
}
}

Error

51 Windows Software Development in C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace CoffeeShoop
{
public partial class Products : Form
{
SqlConnection connection; SqlConnection, SqlCommand ကုိ class level နဲ႔
SqlCommand command; declare လုပးလုိကးပါတယး။

public Products()
{
InitializeComponent();
}
Database connection အတျကး Method တစးခု
private void dbConnection()
တညးေဆာကးလုိကးပါတယး။
{
SqlConnection connection = new SqlConnection("Data Source=HANNI-PC;Initial
Catalog=CoffeeShop;Integrated Security=True");
}
private void btnSave_Click(object sender, EventArgs e)
{
dbConnection(); Database connection method ကုိ ေခၚလုိကးတာပါ။
connection.Open();

command = new SqlCommand("insert into tblProducts (productname,


price)values(@productname,@price)", connection);
52 Windows Software Development in C#

command.Parameters.AddWithValue("@productname", txtProductName.Text);
command.Parameters.AddWithValue("@price", double.Parse(txtPrice.Text));

command.ExecuteNonQuery();
connection.Close();

TextClear();
}
private void TextClear()
{
txtProductName.Text = "";
txtPrice.Text = "";
}
private void Products_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'myDataSet.tblProducts' table. You can
move, or remove it, as needed.
this.tblProductsTableAdapter.Fill(this.myDataSet.tblProducts);
}
private int productid;
private void dgvProducts_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
productid =
Convert.ToInt16(dgvProducts.Rows[e.RowIndex].Cells[0].Value.ToString());
txtProductName.Text = dgvProducts.Rows[e.RowIndex].Cells[1].Value.ToString();
txtPrice.Text = dgvProducts.Rows[e.RowIndex].Cells[2].Value.ToString();
}

private void btnUpdate_Click(object sender, EventArgs e)


{
dbConnection();
try
{
if (productid==null)
{
53 Windows Software Development in C#

MessageBox.Show("Please Double click Row To Update");


}
else
{
command = new SqlCommand("Update tblProducts SET productname=
@productname, price=@price where productid=@productid", connection);
connection.Open();

command.Parameters.AddWithValue("@productid", productid);
command.Parameters.AddWithValue("@productname",txtProductName.Text);
command.Parameters.AddWithValue("@price", double.Parse(txtPrice.Text));

command.ExecuteNonQuery();
TextClear();
MessageBox.Show("Data Updated");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
connection.Close();
}
}

private void btnDelete_Click(object sender, EventArgs e)


{
dbConnection();
if (productid != 0)
{
command = new SqlCommand("delete tblProducts where productid=@productid",
connection);
54 Windows Software Development in C#

connection.Open();
command.Parameters.AddWithValue("@productid", productid);
command.ExecuteNonQuery();
connection.Close();

this.tblProductsTableAdapter.Fill(this.myDataSet.tblProducts);
TextClear();

MessageBox.Show("Record Deleted Successfully!");


}
else
{
MessageBox.Show("Please Select Row to Delete");
}
}
}
}

Error Provider SaYarChit = Error တကးတံဲ ေနရာမြာဆရာႀကီ့

Phone = 09 791 820 886, 09 692 872 129


55 Windows Software Development in C#

SDLC ( Integrity Training Center )

႔ ppl c t on ..
- Programming Language ..
- Database ..
- UI/UX Design ..
.. ႔ ..
႕ ...
..
..
Program Establish
***************
႔ Industry
.. ႔
႔ .. .. ??? ႔
.. ..
႔ SDLC ႔ ..

What is SDLC?
************
SDLC (Software Development Life Cycle ) ႔ ႕
..
- H h Qu l ty Appl c t on ႔
- Us r xp ct t on ႔
- ႔
..

SDLC h h qu l ty
Process .. ႔ software development
process ႔ .. ႔ ႕ International Standard ISO/IEC 12207
..
56 Windows Software Development in C#

SDLC Software

Plan ..

SDLC Stage ႔6 ..
- Planning
- Defining
- Designing
- Building
- Testing
- Development
..

1- Planning and Requirement Analysis


******************************
Software ႔ .. ႔ ..
႕ real world Domain Knowledge ႔
Requirement ..
r qu r m nt ႔ .. Requirement
.. requirement
... ႔.. ႕ ႔
႔ ..
- ႕ s n or m m r ..
- customer ႔
- sale department . ႔
..
- m rk t surv ys
R qu r m nt Planning Quality
Assurance ႔ Risk
.. Planning Stage .. ႔ Technical
႔ Planning ႔ Risk
႔ Technical Feasbilty Define
57 Windows Software Development in C#

..
R qu r m nt
႔ ႔
႔ ..
2- Defining Requrements
********************
Define ... ...
.. Define Clearly Define
.. R qu r m nt ႔ Docum nt ..
customer market analyst ႔ Approve .. ႔
.. .. .. .. ႔
.. .. SRS(Software Requirement Specification)
႔ ႔ ..

3- Designing the Product Architecture


******************************
SRS ႔ Software Architect .. SRS Product
Design Architect ႔ ocum nt ..
DDS(Design Document Specification) ႔ .. DDS
so tw r ႔ .. DDS
R sk .. ..
.. .. ..
DDS
.. .. approve ..

4- Building or Developing the Product


******************************
Stage .. ႔ ..
Pro r mm r D v lop r ႕ ..
DDS D v lop r Pro r mm r .. Pro r mm n
Tools .. Platform ႔ ... OOP
Structure .. ..
58 Windows Software Development in C#

5- Testing the Product


******************
.. ႔ Program ..
... DDS
.. ... SRS
႕ Report .. Fix .. ႔
T st .. ႕ ... DDS
SRS cov r St ႔ ..

6- Deployment in the Market and Maintenance


**************************************
Publish
.. ၄ Publish
.. Beta Version ..
႕ F ck
.. ..
.. .. .. ႔ ..

UAT(User Acceptance Testing) .. ႔


.. ( .. ႔
႔ ႊ႕ ႊ႕ ...)

*******
SDLC ႕ .. ႔ DEL
.. ႔ .. SDLC
..
.. ႔ ..
SAD(System Analysis & Design) ႔ ..
SAD
59 Windows Software Development in C#

.. ႔
႔ ...

What is SDLC ? (Software Development Life Cycle)

Stage 1: Planning of Project:

This includes making reasonable estimates of the cost and size of


the software product as compared to the resources at hand.

Stage 2: Analysis & Requirement Gathering

This step includes collecting maximum information from the client


about the desired product. All details and specifications of the
product must be discussed with the customer. The development
team analyses the requirements keeping in view the design and
coding of the software. The requirements so gathered are then
analyzed for their validity and possibility of incorporating them
into the software system. The aim of requirement analysis is to
capture the detail of each requirement so that everyone
understands how each requirement is to be worked.
60 Windows Software Development in C#

Stage 3: Design

In this phase, program developer analyses whether software can


be prepared to fulfill all the requirements of the end user. Also,
he checks that the project is financial, practically and
technologically feasible for the customer. After that best design
approach is selected for the product. The developer selects the
programming language like Java, Oracle etc. which will be best
suited for the software. It is also like the engineering
representation of the product to be built.

Stage 4: Development or Implementation

It means translating the design into a computer-readable


language. The development team does the actual coding based
on designed software and writes unit tests for each component to
test the new codes written by them. The developer may show the
work done to the business analysts and the modification or
enhancements may be required. This is the longest phase
of SDLC.

Stage 5: Testing

This is the last phase of SDLC before the software is delivered to


the customer. The job of the test team is to test the system
against the requirements. The aim of the tester is to find out the
61 Windows Software Development in C#

gaps or defects within the system and also to verify that the
software works as expected according to the requirements. It
includes Unit testing, Integration testing, and System testing.

Stage 6: Deployment

Once the Product is tested and ready to deploy, it is released to


consumers to use. The size of the project will determine the
complexity of the deployment if required. The users can be
trained on, or aided with the documentation on how to operate
the software. A small round of testing is also performed on
production to make sure of any environmental issues and any
impact of the new release.

Stage 7: Maintenance

When the customers start using the developed system, the actual
problems comes up and needs to be solved from time to time.
This process where the care is taken for the developed product is
known as Maintenance. The software is maintained timely by
updating the code according to the changes taking place in user
end environment or technology.

Вам также может понравиться