Tải bản đầy đủ (.pdf) (18 trang)

Đáp án môn lập trình c

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (48.12 MB, 18 trang )

ĐÁP ÁN CÂU 10 ĐIỂM
Câu
1

Ý

Nội dung
Xây dựng chương trình soạn thảo văn bản
Thiết kế giao diện:
Mở Microsoft Visual Studio, tạo và đặt tên ứng dụng.
Tạo form, đặt tên form, tên tiêu đề form.
Tạo mainMenu.
Tạo menuItem File và submenuItem New, Open, Save, Exit trên
mainMenu.
Tạo menuItem Edit và submenuItem Cut, Copy, Paste trên
mainMenu.
Tạo menuItem Format và submenuItem Font trên mainMenu.
Tạo menuItem Help và submenuItem About trên mainMenu.
Sử dụng TextBox làm vùng soạn thảo.
Thuộc tính

Giá trị

name

txtnoidung

font

Time New Roman


readonly

False

Multiline

true

Xây dựng các phương thức xử lý:
- Chức năng tạo file mới (File\New).
private void mnew_Click(object sender, System.EventArgs e)
{
checkdirty();
}
private void checkdirty()
{
if (dirty)
{
DialogResult click = MessageBox.Show(this,"Do You
wish to save this
Document?","Save",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Qu
estion,MessageBoxDefaultButton.Button1);
if (click == DialogResult.Yes)
{
savedata();
txt.Text="";
fname = "";
dirty = false;



}
if (click == DialogResult.No)
{
txt.Text="";
fname = "";
dirty = false;
}
}
else
{
txt.Text = "";
fname = "";
}
}

- Chức năng mở file trên đĩa (File\Open).
Từ Toolbox kéo công cụ OpenFileDialog vào form, đặt tên đối tượng
này là ofd.
private void mopen_Click(object sender, System.EventArgs e)
{
ofd.Multiselect = false;
ofd.Filter = "Text Files|*.txt";
ofd.ShowDialog();
if (File.Exists(ofd.FileName))
{
fname = ofd.FileName;
StreamReader sr = new StreamReader(fname);
txt.Text=sr.ReadToEnd();
dirty = false;
sr.Close();

}
}

- Chức năng lưu file lên đĩa (File\Save).
Từ Toolbox kéo công cụ SaveFileDialog vào form, đặt tên đối tượng
này là sfd.
private void msave_Click(object sender, System.EventArgs e)
{
savedata();
}
private void savedata()
{
if (fname == "")
{
sfd.Filter = "Text Files|*.txt";
DialogResult res = sfd.ShowDialog();


if (res == DialogResult.Cancel)
{
return;
}
fname = sfd.FileName;
MessageBox.Show(fname);
}
StreamWriter sw = new StreamWriter(fname);
sw.WriteLine(txt.Text);
sw.Flush();
sw.Close();
dirty = false;

}

- Chức năng thoát ứng dụng (File\Exit).
private void mexit_Click(object sender, System.EventArgs e)
{
checkdirty();
this.Dispose();
}

- Chức năng Cut (Edit\Cut).
private void mcut_Click(object sender, System.EventArgs e)
{
txt.Cut();
dirty = true;
}

- Chức năng Copy (Edit\Copy).
private void mcopy_Click(object sender, System.EventArgs e)
{
Clipboard.SetDataObject(txt.SelectedText, true);
}

- Chức năng Paste (Edit\Paste).
private void mpaste_Click(object sender, System.EventArgs e)
{
IDataObject iData = Clipboard.GetDataObject();
if (iData.GetDataPresent(DataFormats.Text))
{
txt.SelectedText =
iData.GetData(DataFormats.Text).ToString();

}
}

- Chức năng định dạng văn bản (Format\Font).
Từ Toolbox kéo công cụ FontDialog vào form, đặt tên đối tượng này là
fd.
private void mfont_Click(object sender, System.EventArgs e)
{
fd.ShowColor = true;
fd.ShowDialog();


txt.Font = fd.Font;
txt.ForeColor=fd.Color;
}

- Chức năng About (Help\About).
Trong cửa sổ Solution Explorer, bấm chuột phải vào tên ứng dụng,
chọn mục Add\Windows form, trong cửa sổ hiện ra chọn About form.
Trong cửa sổ Properties đặt tên cho đối tượng form này là NewForm
trong mục name.
private void mabout_Click(object sender, System.EventArgs e)
{
NewForm nf = new NewForm();
nf.ShowDialog();
}

Câu Ý Nội dung
2


Xây dựng chương trình soạn thảo văn bản
Thiết kế giao diện.
- Mở ứng dụng Microsoft Visual Studio, tạo một Project mới.
- Đặt tên Form là F_chinh, thay đổi tiêu đề của Form.
- Tạo menu cho Form:
+ Trong cửa sổ Toolbox, chọn mục Menu&Toolbars kéo công cụ
MenuStrip thả vào form, đặt tên cho menu này.
+ Tạo menu File và submenu Exit.
- Tạo thanh công cụ tắt:
+ Trong cửa sổ Toolbox, chọn mục Menu&Toolbars kéo công cụ
ToolStrip thả vào form, đặt tên cho thanh công cụ này.
+ Trên thanh công cụ vừa tạo, tạo các button: tạo file mới, mở file đã
có, ghi file…, các comboBox chọn font chữ, cỡ chữ.
- Tạo Form con:
+ Bấm chuột phải vào tên ứng dụng, chọn mục Add, chọn Windows
Form. Trong cửa sổ hiện ra chọn kiểu form là Windows Form, đặt tên
cho form là F_con.
+ Trên Form con kéo thả công cụ TextBox vào làm vùng soạn thảo.
Thuộc tính

Giá trị

name

Txtnoidung

font

Time New Roman


readonly

False

Multiline

true

Xây dựng các phương thức xử lý:


- Tạo file mới:
void taomoi()
{
F_con fc = new F_con();
fc.MdiParent = this;
fc.Text = "Document " + (stt++).ToString();
closeToolStripMenuItem.Enabled = true;
saveToolStripMenuItem.Enabled = true;
tsmauto.Enabled = true;
toolStripSave.Enabled = true;
fc.Show();
}
void newopen(string s)
{
F_con fc = new F_con();
fc.MdiParent = this;
fc.Text = s;
closeToolStripMenuItem.Enabled = true;
saveToolStripMenuItem.Enabled = true;

toolStripSave.Enabled = true;
fc.Show();
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
taomoi();
}

- Mở file đã có trên đĩa:
Từ Toolbox kéo công cụ OpenFileDialog vào form, đặt tên đối tượng
này là open.
void openfile()
{
OpenFileDialog open = new OpenFileDialog();
open.Filter = "Text Files (.txt)|*.txt|Ms Word Files
(.doc)|*.doc|Rich Text Files (.rtf)|*.rtf|All Files (*.*)|*.*";
open.Multiselect = true;
open.FilterIndex = 2;
if (open.ShowDialog() == DialogResult.OK)
{
newopen(open.FileName);
((F_con)this.ActiveMdiChild).txtnoidung.LoadFile(open.FileName);
}
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
openfile();
}



- Ghi file đã có soạn thảo:
Từ Toolbox kéo công cụ SaveFileDialog vào form, đặt tên đối tượng
này là savefile.
void savefile_new()
{
SaveFileDialog savefile = new SaveFileDialog();
savefile.Filter = "Text Files (.txt)|*.txt|Ms Word
Files (.doc)|*.doc|Rich Text Files (.rtf)|*.rtf|All Files
(*.*)|*.*";
savefile.FilterIndex = 2;
savefile.RestoreDirectory = true;
if (savefile.ShowDialog() == DialogResult.OK)
{
((F_con)this.ActiveMdiChild).txtnoidung.SaveFile(savefile.FileName
);
((F_con)this.ActiveMdiChild).Text =
savefile.FileName;
}
}
void SaveFileTong()
{
string s = this.ActiveMdiChild.Text;
if (s.Substring(0, 8).Equals("Document"))
{
savefile_new();
}
else
{
((F_con)this.ActiveMdiChild).txtnoidung.SaveFile(s);
}

}
private void toolStripSave_Click(object sender, EventArgs e)
{
SaveFileTong();
}

Câu
3

Ý

Nội dung
Xây dựng chương trình xử lý văn bản
Thiết kế giao diện:
- Mở Microsoft Visual Studio, tạo và đặt tên ứng dụng.
- Tạo form, đặt tên form, thay đổi tiêu đề của form.
- Tạo textBox chứa nội dung của văn bản, thay đổi một số thuộc tính
của textBox cho phù hợp.
- Tạo các label với text là Find what, Replace with.
- Tạo textBox để nhập vào từ cần tìm kiếm, đặt tên textBox.


- Tạo textBox để nhập vào từ cần thay thế, đặt tên textBox.
- Tạo button Find, đặt tên button này.
- Tạo button Find next, đặt tên button này.
- Tạo button Replace, đặt tên button này.
- Tạo button Replace all, đặt tên button này.
- Tạo button Undo, đặt tên button này.
- Tạo button Exit, đặt tên button này.
Xây dựng các phương thức xử lý:

- Xử lý khi người dùng nhấn button Find.
private void btnTim_Click(object sender, EventArgs e)
{
if (txtVanBan.Text == "") MessageBox.Show("Bạn chưa
nhập nội dung văn bản", "Thông báo");
BatDau = txtVanBan.Text.IndexOf(txtChuoiTim.Text,
StringComparison.OrdinalIgnoreCase);
if (BatDau >= 0)
{
txtVanBan.SelectionStart = BatDau;
txtVanBan.SelectionLength =
txtChuoiTim.TextLength;
txtVanBan.Focus();
VitriBD=BatDau+txtChuoiTim.TextLength;
}
else
{
MessageBox.Show("Không có chuỗi này trong văn
bản", "Tìm Kiếm");
BatDau = 0;
}
}

- Xử lý khi người dùng nhấn button Find Next.
private void btnTimtiep_Click(object sender, EventArgs e)
{
if (txtVanBan.Text == "") MessageBox.Show("Bạn chưa
nhập nội dung văn bản", "Thông báo");
int TimTiep;
if (VitriBD > txtVanBan.TextLength txtChuoiTim.TextLength)

{
MessageBox.Show("Không còn tìm thấy chuổi, đã hết
văn bản", "Tìm Tiếp");
VitriBD = 0; return;


}
TimTiep = txtVanBan.Text.IndexOf(txtChuoiTim.Text,
VitriBD, StringComparison.OrdinalIgnoreCase);
if (TimTiep >= 0)
{
txtVanBan.SelectionStart = TimTiep;
txtVanBan.SelectionLength =
txtChuoiTim.TextLength;
txtVanBan.Focus();
VitriBD = TimTiep + txtChuoiTim.TextLength;
}
else
{
if (VitriBD == 0)
{
MessageBox.Show("Không có chuỗi này trong văn
bản", "Tìm kiếm");
}
else
{
MessageBox.Show("Không còn tìm thấy chuổi, đã
hết văn bản", "Tìm Tiếp");
VitriBD = 0;
}

}
}

- Xử lý khi người dùng nhấn button Replace.
private void btnThayThe_Click(object sender, EventArgs e)
{
if (txtVanBan.Text == "") MessageBox.Show("Bạn chưa
nhập nội dung văn bản", "Thông báo");
else NoiDung = txtVanBan.Text;
if (txtChuoiTim.Text == "")
{
MessageBox.Show("Chưa có chuỗi cần tìm", "Tìm và
thay thế");
return;
}
BatDau = txtVanBan.Text.IndexOf(txtChuoiTim.Text,
VitriBD, StringComparison.OrdinalIgnoreCase);
if (BatDau >= 0)
{
txtVanBan.SelectionStart = BatDau;
txtVanBan.SelectionLength =
txtChuoiTim.TextLength;
VitriBD = BatDau + txtChuoiTim.TextLength;
txtVanBan.Focus();


txtVanBan.SelectedText =
txtVanBan.SelectedText.Replace(txtVanBan.SelectedText,
txtChuoiThay.Text);
}

else
{
if (VitriBD == 0)
{
MessageBox.Show("Không có chuỗi này trong văn
bản", "Tìm và thay thế");
}
else
{
MessageBox.Show("Không còn tìm thấy,đã hết
văn bản", "Tìm và thay thế");
BatDau = 0;
VitriBD = 0;
}
}
}


- Xử lý khi người dùng nhấn button Replace All.
private void btnThayTatCa_Click(object sender, EventArgs e)
{
if (txtVanBan.Text == "") MessageBox.Show("Bạn chưa
nhập nội dung văn bản", "Thông báo");
if (txtChuoiTim.Text == "")
{
MessageBox.Show("Chưa có chổ cần tìm", "Tìm và
thay thế");
return;
}
BatDau = txtVanBan.Text.IndexOf(txtChuoiTim.Text,

VitriBD,StringComparison.OrdinalIgnoreCase);
if (BatDau == -1)
{
MessageBox.Show("Không có chuỗi này trong văn
bản", "Tìm và thay thế");
BatDau = 0; return;
}
while (BatDau >= 0)
{
txtVanBan.SelectionStart = BatDau;
txtVanBan.SelectionLength =
txtChuoiTim.TextLength;
VitriBD = BatDau + txtChuoiTim.TextLength;
txtVanBan.Focus();
txtVanBan.SelectedText =
txtVanBan.SelectedText.Replace(txtVanBan.SelectedText,txtChuoiTha
y.Text);
BatDau = txtVanBan.Text.IndexOf(txtChuoiTim.Text,
VitriBD,StringComparison.OrdinalIgnoreCase);
}
MessageBox.Show("Đã hết văn bản", "Tìm và thay thế");
BatDau = 0;
VitriBD = 0
}

- Xử lý khi người dùng nhấn button Undo.
(noidung = txtVanban.text)
private void btnLamlai_Click(object sender, EventArgs e)
{
txtVanBan.Text = NoiDung;

txtChuoiTim.Clear();
txtChuoiThay.Clear();
txtChuoiTim.Focus();
BatDau = 0;
VitriBD = 0;
}


- Xử lý khi người dùng nhấn button Exit.
private void btnThoat_Click(object sender, EventArgs e)
{
this.Close();
}

Câu Ý
4

Nội dung
Xây dựng chương trình vẽ hình
Thiết kế giao diện:
- Mở Microsoft Visual Studio, tạo và đặt tên ứng dụng.
- Tạo form, đặt tên form, thay đổi tiêu đề của form.
- Tạo toolStrip dùng để chứa các mục chọn chức năng.
- Trên toolStrip thêm được các mục: Pen Size, PenColor, Clear,
BackGround Color, Draw Shape.
- Tạo numericUpDown dùng để chỉ giá trị của Pen Size.
- Tạo numericUpDown dùng để chỉ giá trị của Shape Size.
- Tạo Panel dùng để làm cửa sổ vẽ.
Xây dựng các phương thức xử lý:
- Xử lý xự kiện khi người dùng chọn màu vẽ (PenColor).

private void toolStripButton1_Click(object sender, EventArgs e)
{
ColorDialog cd = new ColorDialog();
if (cd.ShowDialog() == DialogResult.OK)
{
toolStripButton1.ForeColor = cd.Color;
}
}

- Xử lý xự kiện khi người dùng chọn màu nền (BachGround Color).
private void toolStripButton3_Click(object sender, EventArgs e)
{
ColorDialog cd = new ColorDialog();
if (cd.ShowDialog() == DialogResult.OK)
{
toolStripButton3.ForeColor = cd.Color;
panel1.BackColor = cd.Color;
}
}

- Xử lý sự kiện khi người dùng muốn xóa tất cả các hình trên cửa sổ vẽ
(Clear).
private void toolStripButton2_Click(object sender, EventArgs e)
{


_g.Clear(panel1.BackColor);
}

- Xử lý sự kiện khi người dùng vẽ bằng bút vẽ.

private void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (_canPaint)
{
Pen pen = new Pen(toolStripButton1.ForeColor,
float.Parse(numericUpDown1.Value.ToString()));
_g.DrawLine(pen, new Point(_preX, _preY), new
Point(e.X, e.Y));
}
_preX = e.X; _preY = e.Y;
}

- Xử lý sự kiện khi người dùng vẽ hình vuông, hình chữ nhật, hình tròn.
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
_canPaint = true;
if (_drawSquare)
{
_canPaint = false;
_drawSquare = false;
SolidBrush sb = new
SolidBrush(toolStripButton1.ForeColor);
_g.FillRectangle(sb, e.X, e.Y,
int.Parse(numericUpDown2.Value.ToString()),
int.Parse(numericUpDown2.Value.ToString()));
}
else if (_drawRectangle)
{
_canPaint = false;
_drawRectangle = false;

SolidBrush sb = new
SolidBrush(toolStripButton1.ForeColor);
_g.FillRectangle(sb, e.X, e.Y,
int.Parse(numericUpDown2.Value.ToString()) * 2,
int.Parse(numericUpDown2.Value.ToString()));
}
else if (_drawCircle)
{
_canPaint = false;
_drawCircle = false;
SolidBrush sb = new
SolidBrush(toolStripButton1.ForeColor);
_g.FillEllipse(sb, e.X, e.Y,


int.Parse(numericUpDown2.Value.ToString()),
int.Parse(numericUpDown2.Value.ToString()));
}
}

Câu
5

Ý Nội dung
Xây dựng chương trình quản lý học sinh
Thiết kế CSDL:
- Mở Microsoft SQL Server Management Studio tạo cơ sở dữ liệu
HocSinh.
- Trong cơ sở dữ liệu đã tạo tạo bảng hocsinh có cấu trúc theo yêu cầu.
- Nhập được thông tin của ít nhất 5 học sinh.

Thiết kế giao diện:`
- Mở Microsoft Visual Studio, tạo và đặt tên ứng dụng.
- Tạo form, đặt tên form, thay đổi tiêu đề của form.
- Tạo label có text là Mã học sinh, textBox chứa mã học sinh, đặt tên
textBox.
- Tạo label có text là Họ và tên, textBox chứa họ tên học sinh, đặt tên
textBox.
- Tạo label có text là Ngày sinh, textBox chứa ngày sinh, đặt tên
textBox.
- Tạo label có text Giới tính, textBox chứa giới tính, đặt tên textBox.
- Tạo label có text Quê quán, textBox chứa quê quán, đặt tên textBox.
- Tạo label có text Email, textBox chứa email, đặt tên textBox.
- Tạo và đặt tên các button điều khiển việc xem thông tin học sinh.
- Tạo button Add New, đặt tên cho button này.
- Tạo button Save, đặt tên cho button này.
- Tạo button Edit, đặt tên cho button này.
- Tạo button Delete, đặt tên cho button này.
- Tạo button Cancel, đặt tên cho button này.
Viết các phương thức xử lý:
- Tạo kết nối đến cơ sở dữ liệu:
public frmHocsinh()
{
InitializeComponent();
// Kết nối CSDL
connectionString = "Server=TUQUYEN; Database=hocsinh;
Trusted_connection=true";
sqlconHocsinh = new SqlConnection(connectionString);
sqlcomHocsinh = new SqlCommand();
}



- Xử lý sự kiện form_load.
private void frmHocsinh_Load(object sender, EventArgs e)
{
try
{
ClearControls();
//ClearControls
if (sqlconHocsinh.State == ConnectionState.Open)
{
sqlconHocsinh.Close();
}
sqlconHocsinh.Open();
sqlcomHocsinh.CommandText = "Select * from hocsinh";
sqlcomHocsinh.Connection = sqlconHocsinh;
sqldreaderHocsinh = sqlcomHocsinh.ExecuteReader();
if (sqldreaderHocsinh.HasRows)
{
sqldreaderHocsinh.Read();
DisplayResults();
if (sqldreaderHocsinh.Read())
{
btnNext.Enabled = true;
btnEnd.Enabled = true;
rowNumber = rowNumber + 1;
btnPre_Click(null, null);
}
else
{
btnNext.Enabled = false;

btnEnd.Enabled = false;
btnFirst.Enabled = false;
btnPre.Enabled = false;
}
btnEdit.Enabled = true;
btnDelete.Enabled = true;
}
else
{
DisableButtons();
}
btnCancel.Enabled = false;
btnSave.Enabled = false;
btnAdd.Enabled = true;
}


catch (SqlException sqlexchocsinh)
{
MessageBox.Show("Lỗi trong khi kết nối CSDL", "Thông báo
lỗi", MessageBoxButtons.OK, MessageBoxIcon.Information);
sqlconHocsinh.Close();
}
}
void DisplayResults()
{
txtMahs.Text = sqldreaderHocsinh.GetString(0);
txtHoten.Text = sqldreaderHocsinh.GetString(1);
txtGioitinh.Text = sqldreaderHocsinh.GetString(2);
txtQuequan.Text = sqldreaderHocsinh.GetString(3);

txtEmail.Text = sqldreaderHocsinh.GetString(4);
txtNgaysinh.Text = sqldreaderHocsinh.GetString(5);
}

- Xử lý các sự kiện khi người dùng nhấn các button điều khiển: btnNext,
btnPre, btnFirst, btnEnd.
private void btnNext_Click(object sender, EventArgs e)
{
if (sqldreaderHocsinh.Read())
{
rowNumber = rowNumber + 1;
DisplayResults();
}
else
{
MessageBox.Show("Đây là bản ghi cuối", "Thông
báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
btnNext.Enabled = false;
btnEdit.Enabled = false;
}
btnFirst.Enabled = true;
btnPre.Enabled = true;
}
private void btnEnd_Click(object sender, EventArgs e)
{
while (sqldreaderHocsinh.Read())
{
rowNumber = rowNumber + 1;
DisplayResults();
}

btnNext.Enabled = false;
btnEnd.Enabled = false;
btnPre.Enabled = true;
btnFirst.Enabled = true;
}


private void btnFirst_Click(object sender, EventArgs e)
{
if (!sqldreaderHocsinh.IsClosed)
{
sqldreaderHocsinh.Close();
}
sqldreaderHocsinh = sqlcomHocsinh.ExecuteReader();
if (rowNumber != 0)
{
sqldreaderHocsinh.Read();
DisplayResults();
rowNumber = 0;
}
else
{
MessageBox.Show("Đây là bản ghi đầu tiên", "Thông
báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
sqldreaderHocsinh.Read();
}
btnPre.Enabled = false;
btnFirst.Enabled = false;
btnNext.Enabled = true;
btnEdit.Enabled = true;

}
private void btnPre_Click(object sender, EventArgs e)
{
int currentRowNumber = 0;
if (!sqldreaderHocsinh.IsClosed)
{
sqldreaderHocsinh.Close();
}
sqldreaderHocsinh = sqlcomHocsinh.ExecuteReader();
if (rowNumber != 0)
{
while (currentRowNumber < rowNumber)
{
currentRowNumber = currentRowNumber + 1;
sqldreaderHocsinh.Read();
}
DisplayResults();
rowNumber = rowNumber - 1;
}


else
{
MessageBox.Show("Đây là bản ghi đầu tiên", "Thông
báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
sqldreaderHocsinh.Read();
}
btnNext.Enabled = true;
btnEdit.Enabled = true;
}


- Xử lý sự kiện thêm mới, sửa một bản ghi.
private void btnSave_Click(object sender, EventArgs e)
{
string addNewString = "";
int index = 0;
if (operation == "addnew")
{
addNewString = "insert into Hocsinh(mahs, hoten,
gioitinh, quequan, email, ngaysinh) values ('" + txtMahs.Text +
"','" + txtHoten.Text + "','" + txtGioitinh.Text + "'," +
txtQuequan.Text + ",'" + txtEmail.Text + "," + txtNgaysinh.Text+
")";
}
else if (operation == "edit")
{
addNewString = "update hocsinh set hoten='" +
txtHoten.Text + "', ngaysinh=" + txtNgaysinh.Text + ",gioitinh='"
+ txtGioitinh.Text + ",quequan='" + txtQuequan.Text + "',email=" +
txtEmail.Text + "Where mahs='" + txtMahs.Text + "'";
}
if (operation != "")
{
if (!sqldreaderHocsinh.IsClosed)
{
sqldreaderHocsinh.Close();
}
sqlcomHocsinh.CommandText = addNewString;
sqlcomHocsinh.Connection = sqlconHocsinh;
record = "mahs: " + txtMahs.Text + "\nhoten: " +

txtHoten.Text + "\ngioitinh: " + txtGioitinh.Text + "\nquequan: "
+ txtQuequan.Text + "\nemail: " + txtEmail.Text + "\nngaysinh: "
+ txtNgaysinh.Text;
sqlcomHocsinh.ExecuteNonQuery();
MessageBox.Show("Đã cập nhật thành công thông tin
của học sinh\n" + record,"Hoc
sinh",MessageBoxButtons.OK,MessageBoxIcon.Information);
frmHocsinh_Load(null,null);
}
}


private void btnEdit_Click(object sender, EventArgs e)
{
DisableButtons();
operation = "edit";
btnAdd.Enabled = false;
btnSave.Enabled = true;
btnCancel.Enabled = true;
}
private void btnCancel_Click(object sender, EventArgs e)
{
operation = "";
frmHocsinh_Load(null,null);
}

- Xử lý sự kiện xóa một bản ghi.
private void btnDelete_Click(object sender, EventArgs e)
{
record = "mahs: " + txtMahs.Text + "\nHo ten: " +

txtHoten.Text +"\nNgay sinh: " + txtNgaysinh.Text + "\nEmail: " +
txtEmail.Text + "\nGioi tinh: " + txtGioitinh.Text

+

"\nQue quan: " + txtQuequan.Text;
if (!sqldreaderHocsinh.IsClosed)
{
sqldreaderHocsinh.Close();
}
sqlcomHocsinh.CommandText = "Delete from hocsinh Where
mahs='" + txtMahs.Text + "'";
if (sqlconHocsinh.State == ConnectionState.Open)
{
sqlconHocsinh.Close();
}
sqlconHocsinh.Open();
sqlcomHocsinh.ExecuteNonQuery();
sqlconHocsinh.Close();
MessageBox.Show("Thông tin của học sinh đã xóa thành
công\n" + record, "Hoc sinh", MessageBoxButtons.OK,
MessageBoxIcon.Information);
frmHocsinh_Load(null, null);
}

Câu Ý
6

Nội dung
Xây dựng ứng dụng mô phỏng một máy tính bỏ túi để thực hiện các

phép toán số học (cộng, trừ, nhân, chia)
Thiết kế giao diện:
- Mở Microsoft Visual Studio, tạo và đặt tên ứng dụng.
- Tạo form, đặt tên form, thay đổi tiêu đề của form.
- Tạo label hoặc textBox dùng để chứa thông và kết quả tính toán. Nếu
là textBox thì cần đặt thuộc tính readonly = true. Đặt tên cho công cụ



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×