コード例 #1
0
 private void addChuyenDi(ChuyenDi m)
 {
     try
     {
         bool kq = chuyenDiDB.add(m);
         if (kq)
         {
             loadData();
             ClearInput();
         }
         else
         {
             MessageBox.Show("Them ko thanh cong");
         }
     }
     catch (Exception e)
     {
         if (e.Message.Contains("UNIQUE"))
         {
             MessageBox.Show("Email trung lap");
         }
         else
         {
             MessageBox.Show("Khong the thuc hien duoc: " + e.Message);
         }
     }
 }
コード例 #2
0
        public List <ChuyenDi> selectChuyenDiTheoThoiGian(string maTuyenDi, string thoiGianDau, string thoiGianCuoi)
        {
            String       sql = "select * from ChuyenDi where maTuyenDi = @maTuyenDi and ngayGio >= @thoiGianDau and ngayGio <= @thoiGianCuoi";
            SqlParameter p1  = new SqlParameter("@maTuyenDi", maTuyenDi);
            SqlParameter p2  = new SqlParameter("@thoiGianDau", thoiGianDau);
            SqlParameter p3  = new SqlParameter("@thoiGianCuoi", thoiGianCuoi);

            SqlParameter[] param = { p1, p2, p3 };

            DataTable table = manager.executeQuery(sql, param);

            List <ChuyenDi> list = new List <ChuyenDi>();

            for (int i = 0; i < table.Rows.Count; i++)
            {
                DataRow row = table.Rows[i];

                string   maChuyenDi = (string)row["maChuyenDi"];
                DateTime ngayGio    = (DateTime)row["ngayGio"];
                int      thoiGianDi = (int)row["thoiGianDi"];
                int      soLuongGhe = (int)row["soLuongGhe"];

                ChuyenDi c = new ChuyenDi(maChuyenDi, maTuyenDi, ngayGio, thoiGianDi, soLuongGhe);

                list.Add(c);
            }

            return(list);
        }
コード例 #3
0
        private void Display(ChuyenDi c)
        {
            txtMaChuyenDi.Text = c.MaChuyenDi;
            txtMaTuyenDi.Text  = c.MaTuyenDi;
            dtpNgayGio.Value   = c.NgayGio;
            txtThoiGianDi.Text = c.ThoiGianDi.ToString();
            txtSoLuongGhe.Text = c.SoLuongGhe.ToString();

            setEditMode(true);
        }
コード例 #4
0
        private void gridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int row = e.RowIndex;

            if (row < 0 || row >= list.Count)
            {
                return;
            }

            ChuyenDi c = list[row];

            Display(c);
        }
コード例 #5
0
        public bool update(ChuyenDi c)
        {
            String sql = "update ChuyenDi set maTuyenDi = @maTuyenDi, ngayGio = @ngayGio, thoiGianDi = @thoiGianDi, soLuongGhe = @soLuongGhe where maChuyenDi = @maChuyenDi";

            SqlParameter p1 = new SqlParameter("@maChuyenDi", c.MaChuyenDi);
            SqlParameter p2 = new SqlParameter("@maTuyenDi", c.MaTuyenDi);
            SqlParameter p3 = new SqlParameter("@ngayGio", c.NgayGio);
            SqlParameter p4 = new SqlParameter("@thoiGianDi", c.ThoiGianDi);
            SqlParameter p5 = new SqlParameter("@soLuongGhe", c.SoLuongGhe);

            SqlParameter[] param = { p1, p2, p3, p4, p5 };

            return(manager.executeUpdate(sql, param));
        }
コード例 #6
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string   maChuyenDi = txtMaChuyenDi.Text.Trim();
            string   maTuyenDi  = txtMaTuyenDi.Text.Trim();
            DateTime ngayGio    = dtpNgayGio.Value;
            int      thoiGianDi = Convert.ToInt32(txtThoiGianDi.Text.Trim());
            int      soLuongGhe = Convert.ToInt32(txtSoLuongGhe.Text.Trim());

            ChuyenDi m = new ChuyenDi(maChuyenDi, maTuyenDi, ngayGio, thoiGianDi, soLuongGhe);

            list.Add(m);
            gridView.DataSource = null;
            gridView.DataSource = list;
            addChuyenDi(m);
        }
コード例 #7
0
        public bool add(ChuyenDi c)
        {
            try
            {
                String sql = "insert into ChuyenDi values(@maChuyenDi, @maTuyenDi, @ngayGio, @thoiGianDi, @soLuongGhe)";

                SqlParameter p1 = new SqlParameter("@maChuyenDi", c.MaChuyenDi);
                SqlParameter p2 = new SqlParameter("@maTuyenDi", c.MaTuyenDi);
                SqlParameter p3 = new SqlParameter("@ngayGio", c.NgayGio);
                SqlParameter p4 = new SqlParameter("@thoiGianDi", c.ThoiGianDi);
                SqlParameter p5 = new SqlParameter("@soLuongGhe", c.SoLuongGhe);

                SqlParameter[] param = { p1, p2, p3, p4, p5 };

                return(manager.executeUpdate(sql, param));
            }
            catch (Exception e)
            {
                return(false);
            }
        }
コード例 #8
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (!isInputValid())
            {
                return;
            }

            string   maChuyenDi = txtMaChuyenDi.Text.Trim();
            string   maTuyenDi  = txtMaTuyenDi.Text.Trim();
            DateTime ngayGio    = dtpNgayGio.Value;
            int      thoiGianDi = Convert.ToInt32(txtThoiGianDi.Text.Trim());
            int      soLuongGhe = Convert.ToInt32(txtSoLuongGhe.Text.Trim());

            DialogResult result = MessageBox.Show("Ban co muon cap nhat " + maChuyenDi, "Cap nhat thong tin ", MessageBoxButtons.YesNo);

            if (result != DialogResult.Yes)
            {
                return;
            }

            ChuyenDi m      = new ChuyenDi(maChuyenDi, maTuyenDi, ngayGio, thoiGianDi, soLuongGhe);
            bool     ketQua = chuyenDiDB.update(m);

            // thong bao
            if (ketQua)
            {
                MessageBox.Show("Cap nhat thanh cong");
            }
            else
            {
                MessageBox.Show("Cap nhat ko thanh cong");
            }

            list = chuyenDiDB.getAll();
            gridView.DataSource = null;
            gridView.DataSource = list;
        }
コード例 #9
0
        public List <ChuyenDi> getAll()
        {
            String    sql   = "select * from ChuyenDi";
            DataTable table = manager.executeQuery(sql);

            List <ChuyenDi> list = new List <ChuyenDi>();

            for (int i = 0; i < table.Rows.Count; i++)
            {
                DataRow row = table.Rows[i];

                string   maChuyenDi = (string)row["maChuyenDi"];
                string   maTuyenDi  = (string)row["maTuyenDi"];
                DateTime ngayGio    = (DateTime)row["ngayGio"];
                int      thoiGianDi = (int)row["thoiGianDi"];
                int      soLuongGhe = (int)row["soLuongGhe"];

                ChuyenDi c = new ChuyenDi(maChuyenDi, maTuyenDi, ngayGio, thoiGianDi, soLuongGhe);

                list.Add(c);
            }

            return(list);
        }