SlideShare a Scribd company logo
1 of 3
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace ql_tour
{
public partial class Form1 : Form
{
public DataTable dt = new DataTable();
public SqlDataAdapter da;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//hiển thị thông tin tour hiện hành trên
Textbox,combobox,DateTimePicker,PictureBox,DataGridView
//Duyệt bản ghi, kích chọn hàng DataGridView hàng tương ứng hiển thị lên
các control
try
{
SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source=FCVU1209AJESQLEXPRESS;Initial
Catalog=ql_tour;Integrated Security=True";
con.Open();
SqlCommand cmd = new SqlCommand("select * from tour", con);
da = new SqlDataAdapter(cmd);
da.Fill(dt);
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = dt;
grid_tour.DataSource = bindingSource;
bindingNavigator1.BindingSource = bindingSource;
this.txtma.DataBindings.Add("Text", bindingSource, "matour");
this.txtten.DataBindings.Add("Text", bindingSource, "tentour");
this.dtpngay.DataBindings.Add("Value", bindingSource,
"ngaykhoihanh");
this.txthinh.DataBindings.Add("Text", bindingSource, "hinh");
this.cmbloai.DataBindings.Add("Text", bindingSource, "maloai");
this.loadImage();
this.dtpngay.Format = DateTimePickerFormat.Custom;
this.dtpngay.CustomFormat = "dd/MM/yyyy";
}
catch (SqlException ex) { MessageBox.Show(ex.Message); }
}
private void loadImage()
{
try { pic1.Image = Image.FromFile("image" + txthinh.Text); }
catch (System.IO.FileNotFoundException) { pic1.Image = null; }
catch (System.ArgumentException) { pic1.Image = null; }
}
private void btnthem_Click(object sender, EventArgs e)
{
//Thêm thông tin tour
string ma = this.txtma.Text;
string ten = this.txtten.Text;
string ngaykhoihanh = this.dtpngay.Value.ToString();
string hinh = this.txthinh.Text;
string maloai = this.cmbloai.Text;
try
{
SqlConnection con = new SqlConnection(@"Data
Source=FCVU1209AJESQLEXPRESS;Initial Catalog=ql_tour;Integrated Security=True");
con.Open();
string sql = "insert into tour(matour, tentour, ngaykhoihanh,
hinh,maloai) values ('" + ma + "',N'" + ten + "','" + ngaykhoihanh + "','" + hinh +
"','" + maloai + "')";
SqlCommand command = new SqlCommand(sql, con);
int n = command.ExecuteNonQuery();
con.Close();
dt.Clear();
da.Fill(dt);
}
catch (SqlException ex) { MessageBox.Show(ex.Message); }
}
private void btnsua_Click(object sender, EventArgs e)
{
//sửa thông tin tour
string ma= this.txtma.Text;
string ten = this.txtten.Text;
string ngaykhoihanh = this.dtpngay.Value.ToString();
string hinh = this.txthinh.Text;
string maloai = this.cmbloai.SelectedValue.ToString();
try
{
SqlConnection con = new SqlConnection(@"Data
Source=FCVU1209AJESQLEXPRESS;Initial Catalog=ql_tour;Integrated Security=True");
con.Open();
string sql = "update tour set tenhang = N'" + ten + "', ngaykhoihanh
= '" + ngaykhoihanh + "', hinh = '" + hinh + "', maloai = '" + maloai +"' where
matour = '" + ma+ "'";
SqlCommand command = new SqlCommand(sql, con);
int n = command.ExecuteNonQuery();
con.Close();
dt.Clear();
da.Fill(dt);
}
catch (SqlException ex)
{ MessageBox.Show(ex.Message); }
}
private void btnxoa_Click(object sender, EventArgs e)
{
//xóa thông tin tour
DialogResult d = MessageBox.Show("Bạn có muốn xóa không", "Xóa",
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (d == DialogResult.Yes)
{
string ma = this.txtma.Text;
try
{
SqlConnection con = new SqlConnection(@"Data
Source=FCVU1209AJESQLEXPRESS;Initial Catalog=ql_tour;Integrated Security=True");
con.Open();
string sql = "delete from tour where matour = '" + ma + "'";
SqlCommand command = new SqlCommand(sql, con);
int n = command.ExecuteNonQuery();
con.Close();
dt.Clear();
da.Fill(dt);
}
catch (SqlException ex) { MessageBox.Show(ex.Message); }
}
}
}
}

More Related Content

Similar to bai giai de LTWINForm.docx

33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
Tomek Kaczanowski
 
[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9
Shih-Hsiang Lin
 
You are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdfYou are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdf
JUSTSTYLISH3B2MOHALI
 
help me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdfhelp me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdf
arihantmum
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
mary772
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
mccormicknadine86
 

Similar to bai giai de LTWINForm.docx (20)

Quanlycanbo
QuanlycanboQuanlycanbo
Quanlycanbo
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴
 
[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9[C++ gui programming with qt4] chap9
[C++ gui programming with qt4] chap9
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012
 
The Ring programming language version 1.5.1 book - Part 63 of 180
The Ring programming language version 1.5.1 book - Part 63 of 180The Ring programming language version 1.5.1 book - Part 63 of 180
The Ring programming language version 1.5.1 book - Part 63 of 180
 
You are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdfYou are to simulate a dispatcher using a priority queue system in C+.pdf
You are to simulate a dispatcher using a priority queue system in C+.pdf
 
The Ring programming language version 1.6 book - Part 69 of 189
The Ring programming language version 1.6 book - Part 69 of 189The Ring programming language version 1.6 book - Part 69 of 189
The Ring programming language version 1.6 book - Part 69 of 189
 
help me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdfhelp me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdf
 
Ss
SsSs
Ss
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
 
662305 11
662305 11662305 11
662305 11
 
The Ring programming language version 1.7 book - Part 71 of 196
The Ring programming language version 1.7 book - Part 71 of 196The Ring programming language version 1.7 book - Part 71 of 196
The Ring programming language version 1.7 book - Part 71 of 196
 
The Ring programming language version 1.9 book - Part 78 of 210
The Ring programming language version 1.9 book - Part 78 of 210The Ring programming language version 1.9 book - Part 78 of 210
The Ring programming language version 1.9 book - Part 78 of 210
 
Deep Dumpster Diving
Deep Dumpster DivingDeep Dumpster Diving
Deep Dumpster Diving
 
16 18
16 1816 18
16 18
 
Spring data access
Spring data accessSpring data access
Spring data access
 
Kode vb.net
Kode vb.netKode vb.net
Kode vb.net
 
Kode vb.net
Kode vb.netKode vb.net
Kode vb.net
 

Recently uploaded

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 

Recently uploaded (20)

WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of TransformationWSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
WSO2CON 2024 - Designing Event-Driven Enterprises: Stories of Transformation
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & InnovationWSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 

bai giai de LTWINForm.docx

  • 1. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace ql_tour { public partial class Form1 : Form { public DataTable dt = new DataTable(); public SqlDataAdapter da; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //hiển thị thông tin tour hiện hành trên Textbox,combobox,DateTimePicker,PictureBox,DataGridView //Duyệt bản ghi, kích chọn hàng DataGridView hàng tương ứng hiển thị lên các control try { SqlConnection con = new SqlConnection(); con.ConnectionString = @"Data Source=FCVU1209AJESQLEXPRESS;Initial Catalog=ql_tour;Integrated Security=True"; con.Open(); SqlCommand cmd = new SqlCommand("select * from tour", con); da = new SqlDataAdapter(cmd); da.Fill(dt); BindingSource bindingSource = new BindingSource(); bindingSource.DataSource = dt; grid_tour.DataSource = bindingSource; bindingNavigator1.BindingSource = bindingSource; this.txtma.DataBindings.Add("Text", bindingSource, "matour"); this.txtten.DataBindings.Add("Text", bindingSource, "tentour"); this.dtpngay.DataBindings.Add("Value", bindingSource, "ngaykhoihanh"); this.txthinh.DataBindings.Add("Text", bindingSource, "hinh"); this.cmbloai.DataBindings.Add("Text", bindingSource, "maloai"); this.loadImage(); this.dtpngay.Format = DateTimePickerFormat.Custom; this.dtpngay.CustomFormat = "dd/MM/yyyy"; } catch (SqlException ex) { MessageBox.Show(ex.Message); } } private void loadImage() { try { pic1.Image = Image.FromFile("image" + txthinh.Text); } catch (System.IO.FileNotFoundException) { pic1.Image = null; } catch (System.ArgumentException) { pic1.Image = null; }
  • 2. } private void btnthem_Click(object sender, EventArgs e) { //Thêm thông tin tour string ma = this.txtma.Text; string ten = this.txtten.Text; string ngaykhoihanh = this.dtpngay.Value.ToString(); string hinh = this.txthinh.Text; string maloai = this.cmbloai.Text; try { SqlConnection con = new SqlConnection(@"Data Source=FCVU1209AJESQLEXPRESS;Initial Catalog=ql_tour;Integrated Security=True"); con.Open(); string sql = "insert into tour(matour, tentour, ngaykhoihanh, hinh,maloai) values ('" + ma + "',N'" + ten + "','" + ngaykhoihanh + "','" + hinh + "','" + maloai + "')"; SqlCommand command = new SqlCommand(sql, con); int n = command.ExecuteNonQuery(); con.Close(); dt.Clear(); da.Fill(dt); } catch (SqlException ex) { MessageBox.Show(ex.Message); } } private void btnsua_Click(object sender, EventArgs e) { //sửa thông tin tour string ma= this.txtma.Text; string ten = this.txtten.Text; string ngaykhoihanh = this.dtpngay.Value.ToString(); string hinh = this.txthinh.Text; string maloai = this.cmbloai.SelectedValue.ToString(); try { SqlConnection con = new SqlConnection(@"Data Source=FCVU1209AJESQLEXPRESS;Initial Catalog=ql_tour;Integrated Security=True"); con.Open(); string sql = "update tour set tenhang = N'" + ten + "', ngaykhoihanh = '" + ngaykhoihanh + "', hinh = '" + hinh + "', maloai = '" + maloai +"' where matour = '" + ma+ "'"; SqlCommand command = new SqlCommand(sql, con); int n = command.ExecuteNonQuery(); con.Close(); dt.Clear(); da.Fill(dt); } catch (SqlException ex) { MessageBox.Show(ex.Message); } } private void btnxoa_Click(object sender, EventArgs e)
  • 3. { //xóa thông tin tour DialogResult d = MessageBox.Show("Bạn có muốn xóa không", "Xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (d == DialogResult.Yes) { string ma = this.txtma.Text; try { SqlConnection con = new SqlConnection(@"Data Source=FCVU1209AJESQLEXPRESS;Initial Catalog=ql_tour;Integrated Security=True"); con.Open(); string sql = "delete from tour where matour = '" + ma + "'"; SqlCommand command = new SqlCommand(sql, con); int n = command.ExecuteNonQuery(); con.Close(); dt.Clear(); da.Fill(dt); } catch (SqlException ex) { MessageBox.Show(ex.Message); } } } } }