FormTour.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;

using TourDuLich.DAL;

namespace TourDuLich

{

    public partial class FormTour : Form

    {

        BizTour tour;

        public FormTour()

        {

            InitializeComponent();

        }

        public FormTour(BizTour _tour):this()

        {

            tour = _tour;

        }

        private void btnDong_Click(object sender, EventArgs e)

        {

            this.Close();

        }

        private void button1_Click(object sender, EventArgs e)

        {

            FormDanhMucDiaDiem frmDd = new FormDanhMucDiaDiem();

            frmDd.ShowDialog();

            LoadTabDiaDiem();

        }

        private void LoadTabDiaDiem()

        {

            List<BizDiaDiem> allDiaDiems = DalDiaDiem.getAllDiaDiem();

            int i = 0;

            while (i < allDiaDiems.Count)

            {

                BizDiaDiem dd = allDiaDiems[i];

                if (tour.DiaDiems.Contains(dd, new BizDiaDiemComparer()))

                    allDiaDiems.Remove(dd);

                else

                    i++;

            }

            listDiaDiem.DataSource = allDiaDiems;

            listDiaDiem.DisplayMember = "TenDD";

            listDDTour.DataSource = tour.DiaDiems;

            listDDTour.DisplayMember = "TenDD";

        }

        private void FormTour_Load(object sender, EventArgs e)

        {

            // cbo loại tour

            cbLoaiTour.DataSource = DalTour.GetAllLoaiTour();

            cbLoaiTour.DisplayMember = "TenLoai";

            cbLoaiTour.ValueMember = "Id";

            // Thông tin chung của tour

            txtMaTour.Text = tour.MaTour;

            txtTenTour.Text = tour.TenTour;

            cbLoaiTour.Text = tour.TenLoaiTour;

            ckTourTrongNuoc.Checked = tour.LaTourTrongNuoc;

            // giá

            gvGia.AutoGenerateColumns = false;

            gvGia.DataSource = tour.Gias;

            // địa điểm

            LoadTabDiaDiem();           

        }

        private void gvGia_CellClick(object sender, DataGridViewCellEventArgs e)

        {

            BizGiaTour gia = tour.Gias[e.RowIndex];

            txtGiaTour.Text = gia.GiaTri.ToString();

            ckApDung.Checked = gia.DangApDung;

            dtTgbd.Value = gia.ThoiGianBatDau;

            dtTgkt.Value = gia.ThoiGianKetThuc;

        }

        private void btnThem_Click(object sender, EventArgs e)

        {

            float gt = 0;

            if (!float.TryParse(txtGiaTour.Text, out gt))

            {

                MessageBox.Show("Giá tour không hợp lệ");

                txtGiaTour.SelectAll();

                txtGiaTour.Focus();

            }

            else

            {

                BizGiaTour gia = new BizGiaTour(-1, gt,

                    dtTgbd.Value, dtTgkt.Value, ckApDung.Checked, tour);

                tour.Gias.Add(gia);

                gvGia.DataSource = null;

                gvGia.DataSource = tour.Gias;

            }

           

        }

        private void btnSua_Click(object sender, EventArgs e)

        {

            if (gvGia.SelectedRows.Count > 0)

            {

                BizGiaTour gia = (BizGiaTour)gvGia.SelectedRows[0].DataBoundItem;

                float gt = 0;

                if (!float.TryParse(txtGiaTour.Text, out gt))

                {

                    MessageBox.Show("Giá tour không hợp lệ");

                    txtGiaTour.SelectAll();

                    txtGiaTour.Focus();

                }

                else

                {

                    gia.GiaTri = gt;

                    gia.ThoiGianBatDau = dtTgbd.Value;

                    gia.ThoiGianKetThuc = dtTgkt.Value;

                    gia.DangApDung = ckApDung.Checked;

                    if (gia.DangApDung)

                    {

                        tour.CapNhatGiaDangApDung(gia);

                    }

                    gvGia.DataSource = null;

                    gvGia.DataSource = tour.Gias;

                }               

            }

        }

        private void btnXoa_Click(object sender, EventArgs e)

        {

            foreach (DataGridViewRow row in gvGia.SelectedRows)

            {

                BizGiaTour gia = (BizGiaTour)row.DataBoundItem;

                tour.Gias.Remove(gia);

            }

            gvGia.DataSource = null;

            gvGia.DataSource = tour.Gias;

        }

        private void btnLuu_Click(object sender, EventArgs e)

        {

            tour.MaTour = txtMaTour.Text;

            tour.TenTour = txtTenTour.Text;

            tour.LaTourTrongNuoc = ckTourTrongNuoc.Checked;

            tour.LoaiTour = (BizLoaiTour)cbLoaiTour.SelectedItem;

            try

            {

                if (tour.Id == -1)

                {

                    tour.Add();

                }

                tour.Save();

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }           

        }

        private void btnPhai_Click(object sender, EventArgs e)

        {

            List<BizDiaDiem> allDiaDiems = (List<BizDiaDiem>)listDiaDiem.DataSource;

            tour.DiaDiems.Add(allDiaDiems[listDiaDiem.SelectedIndex]);

            allDiaDiems.RemoveAt(listDiaDiem.SelectedIndex);

            listDiaDiem.DataSource = null;

            listDiaDiem.DataSource = allDiaDiems;

            listDiaDiem.DisplayMember = "TenDD";

            listDDTour.DataSource = null;

            listDDTour.DataSource = tour.DiaDiems;

            listDDTour.DisplayMember = "TenDD";                          

        }

        private void btnTrai_Click(object sender, EventArgs e)

        {

            List<BizDiaDiem> allDiaDiems = (List<BizDiaDiem>)listDiaDiem.DataSource;

            allDiaDiems.Add(tour.DiaDiems[listDDTour.SelectedIndex]);

            tour.DiaDiems.RemoveAt(listDDTour.SelectedIndex);

            listDiaDiem.DataSource = null;

            listDiaDiem.DataSource = allDiaDiems;

            listDiaDiem.DisplayMember = "TenDD";

            listDDTour.DataSource = null;

            listDDTour.DataSource = tour.DiaDiems;

            listDDTour.DisplayMember = "TenDD";                          

        }

        private void button5_Click(object sender, EventArgs e)

        {

            if (listDDTour.SelectedIndex > 0)

            {

                BizDiaDiem tmp = tour.DiaDiems[listDDTour.SelectedIndex];

                tour.DiaDiems[listDDTour.SelectedIndex] = tour.DiaDiems[listDDTour.SelectedIndex - 1];

                tour.DiaDiems[listDDTour.SelectedIndex - 1] = tmp;

                listDDTour.DataSource = null;

                listDDTour.DataSource = tour.DiaDiems;

                listDDTour.DisplayMember = "TenDD";                          

            }           

        }

        private void button6_Click(object sender, EventArgs e)

        {

            if (listDDTour.SelectedIndex < tour.DiaDiems.Count - 1)

            {

                BizDiaDiem tmp = tour.DiaDiems[listDDTour.SelectedIndex];

                tour.DiaDiems[listDDTour.SelectedIndex] = tour.DiaDiems[listDDTour.SelectedIndex + 1];

                tour.DiaDiems[listDDTour.SelectedIndex + 1] = tmp;

                listDDTour.DataSource = null;

                listDDTour.DataSource = tour.DiaDiems;

                listDDTour.DisplayMember = "TenDD";

            }

        }

    }

}

Bạn đang đọc truyện trên: truyentop.pro

Tags: