コード例 #1
0
 private void addDonGia(DonGia m)
 {
     try
     {
         bool kq = DonGiaDB.add(m);
         if (kq)
         {
             loadData();
             ClearInput();
         }
         else
         {
             MessageBox.Show("Them ko thanh cong");
         }
     }
     catch (Exception e)
     {
         if (e.Message.Contains("UNIQUE"))
         {
             MessageBox.Show("Mã tuyến đi đã tồn tại.");
         }
         else
         {
             MessageBox.Show("Khong the thuc hien duoc: " + e.Message);
         }
     }
 }
コード例 #2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (!isInputValid())
            {
                return;
            }

            string  maDonGia  = txtMaDonGia.Text.Trim();
            string  maTuyenDi = txtMaTuyenDi.Text.Trim();
            Decimal gia       = Convert.ToDecimal(txtGia.Text.Trim());

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

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

            DonGia m      = new DonGia(maDonGia, maTuyenDi, gia);
            bool   ketQua = DonGiaDB.update(m);

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

            list = DonGiaDB.getAll();
            gridView.DataSource = null;
            gridView.DataSource = list;
        }
コード例 #3
0
        private void Display(DonGia c)
        {
            txtMaDonGia.Text  = c.MaDonGia;
            txtMaTuyenDi.Text = c.MaTuyenDi;
            txtGia.Text       = c.Gia.ToString();

            setEditMode(true);
        }
コード例 #4
0
        public bool update(DonGia c)
        {
            String       sql = "update DonGia set maTuyenDi = @maTuyenDi, gia = @gia where maDonGia = @maDonGia";
            SqlParameter p1  = new SqlParameter("@maDonGia", c.MaDonGia);
            SqlParameter p2  = new SqlParameter("@maTuyenDi", c.MaTuyenDi);
            SqlParameter p3  = new SqlParameter("@gia", c.Gia);

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

            return(manager.executeUpdate(sql, param));
        }
コード例 #5
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string  maDonGia  = txtMaDonGia.Text.Trim();
            string  maTuyenDi = txtMaTuyenDi.Text.Trim();
            Decimal gia       = Convert.ToDecimal(txtGia.Text.Trim());

            DonGia m = new DonGia(maDonGia, maTuyenDi, gia);

            list.Add(m);
            gridView.DataSource = null;
            gridView.DataSource = list;
            addDonGia(m);
        }
コード例 #6
0
        private void gridView_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int row = e.RowIndex;

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

            DonGia c = list[row];

            Display(c);
        }
コード例 #7
0
        public bool add(DonGia c)
        {
            try
            {
                String sql = "insert into DonGia values(@maDonGia, @maTuyenDi, @gia)";

                SqlParameter p1 = new SqlParameter("@maDonGia", c.MaDonGia);
                SqlParameter p2 = new SqlParameter("@maTuyenDi", c.MaTuyenDi);
                SqlParameter p3 = new SqlParameter("@gia", c.Gia);

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

                return(manager.executeUpdate(sql, param));
            }
            catch (Exception e)
            {
                return(false);
            }
        }
コード例 #8
0
        public List <DonGia> getAll()
        {
            String    sql   = "select * from DonGia";
            DataTable table = manager.executeQuery(sql);

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

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

                string  maDonGia  = (string)row["maDonGia"];
                string  maTuyenDi = (string)row["maTuyenDi"];
                Decimal gia       = Convert.ToDecimal(row["gia"]);

                DonGia c = new DonGia(maDonGia, maTuyenDi, gia);

                list.Add(c);
            }

            return(list);
        }