FormDanhMucDiaDiem.cs
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 TourDuLich.BIZ;
namespace TourDuLich
{
public partial class FormDanhMucDiaDiem : Form
{
List<BizDiaDiem> diaDiems = new List<BizDiaDiem>();
List<BizDiaDiem> diaDiemsToDelete = new List<BizDiaDiem>();
public FormDanhMucDiaDiem()
{
InitializeComponent();
}
private void btnDong_Click(object sender, EventArgs e)
{
this.Close();
}
private void FormDanhMucDiaDiem_Load(object sender, EventArgs e)
{
diaDiems = BizDiaDiem.getAllDiaDiem();
gvDiaDiem.Columns["maDiaDiem"].DataPropertyName = "MaDD";
gvDiaDiem.Columns["tenDiaDiem"].DataPropertyName = "TenDD";
gvDiaDiem.AutoGenerateColumns = false;
gvDiaDiem.DataSource = diaDiems;
}
private void btnThem_Click(object sender, EventArgs e)
{
BizDiaDiem dd = new BizDiaDiem(-1, txtMaDD.Text, txtTenDD.Text);
diaDiems.Add(dd);
gvDiaDiem.DataSource = null;
gvDiaDiem.Columns["maDiaDiem"].DataPropertyName = "MaDD";
gvDiaDiem.Columns["tenDiaDiem"].DataPropertyName = "TenDD";
gvDiaDiem.DataSource = diaDiems;
//gvDiaDiem.Update();
//gvDiaDiem.Refresh();
//this.Refresh();
}
private void btnLuu_Click(object sender, EventArgs e)
{
try
{
foreach (BizDiaDiem dd in diaDiems)
{
if (dd.Id == -1)
dd.Add();
if (dd.updated)
dd.Update();
}
foreach (BizDiaDiem dd in diaDiemsToDelete)
{
dd.Delete();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnXoa_Click(object sender, EventArgs e)
{
foreach(DataGridViewRow row in gvDiaDiem.SelectedRows)
{
BizDiaDiem dd = (BizDiaDiem)row.DataBoundItem;
diaDiemsToDelete.Add(dd);
diaDiems.Remove(dd);
gvDiaDiem.DataSource = null;
//gvDiaDiem.Columns["maDiaDiem"].DataPropertyName = "MaDD";
//gvDiaDiem.Columns["tenDiaDiem"].DataPropertyName = "TenDD";
gvDiaDiem.DataSource = diaDiems;
}
}
private void gvDiaDiem_SelectionChanged(object sender, EventArgs e)
{
if (gvDiaDiem.SelectedRows.Count > 0)
{
BizDiaDiem dd = (BizDiaDiem)gvDiaDiem.SelectedRows[0].DataBoundItem;
txtMaDD.Text = dd.MaDD;
txtTenDD.Text = dd.TenDD;
}
}
private void btnSua_Click(object sender, EventArgs e)
{
if (gvDiaDiem.SelectedRows.Count > 0)
{
BizDiaDiem dd = (BizDiaDiem)gvDiaDiem.SelectedRows[0].DataBoundItem;
dd.MaDD = txtMaDD.Text;
dd.TenDD = txtTenDD.Text;
dd.updated = true;
gvDiaDiem.DataSource = null;
gvDiaDiem.DataSource = diaDiems;
}
}
}
}
Bạn đang đọc truyện trên: AzTruyen.Top