예제 #1
0
파일: banhang.cs 프로젝트: ducanh6699/QLBH
        private void dgvMatHang_HoaDon_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0 && e.RowIndex != -1) // bấm nút xóa trên dgv
            {
                if (ThuvienWin.confirm())
                {
                    DataTable dt = ThuvienWin.XemQuery("select * from hoadon where ID = " + MaChonHD);
                    ThuvienWin.ThemSuaXoaQuery(String.Format("update hoadon set Tongtien = '{0}' where ID = {1}", int.Parse(dt.Rows[0]["Tongtien"].ToString()) - int.Parse(dgvMatHang_HoaDon.Rows[e.RowIndex].Cells[9].Value.ToString()), MaChonHD));
                    dt = ThuvienWin.XemQuery("select * from mathang where ID = " + dgvMatHang_HoaDon.Rows[e.RowIndex].Cells[3].Value.ToString());
                    ThuvienWin.ThemSuaXoaQuery(String.Format("update mathang set Conlai = '{0}' where ID = {1}", int.Parse(dt.Rows[0]["Conlai"].ToString()) + int.Parse(dgvMatHang_HoaDon.Rows[e.RowIndex].Cells[5].Value.ToString()), dgvMatHang_HoaDon.Rows[e.RowIndex].Cells[3].Value.ToString()));
                    ThuvienWin.ThemSuaXoaQuery("delete from mathang_hoadon where ID = " + dgvMatHang_HoaDon.Rows[e.RowIndex].Cells[2].Value.ToString());
                    MessageBox.Show("Đã xóa thành công!", "Thông báo");
                    dgvMatHang_HoaDon.DataSource = ThuvienWin.XemQuery(String.Format(@"SELECT mathang_hoadon.ID, mathang_hoadon.Mamathang, mathang_hoadon.Mahoadon, mathang_hoadon.Soluongmathang, mathang.Mavach, mathang.Tenhang, mathang.Gia, mathang_hoadon.Thanhtien
                                            FROM mathang INNER JOIN mathang_hoadon ON mathang.ID = mathang_hoadon.Mamathang
                                            WHERE (((mathang_hoadon.Mahoadon)={0}));", MaChonHD));
                    cbThemMH_SelectedIndexChanged(sender, e);
                    cbSuaMH_SelectedIndexChanged(sender, e);
                    LayHoaDon();
                    TaoMaHD_MH();
                    tabControl1.SelectedTab = tabPage1;
                }
            }
            else if (e.ColumnIndex == 1 && e.RowIndex != -1) // bấm nút sửa trên dgv
            {
                MaSuaMH_HD            = dgvMatHang_HoaDon.Rows[e.RowIndex].Cells[2].Value.ToString();
                cbSuaMH.SelectedValue = dgvMatHang_HoaDon.Rows[e.RowIndex].Cells[3].Value.ToString();
                cbSuaMH_SelectedIndexChanged(sender, e);
                txtSuaSL.Text = dgvMatHang_HoaDon.Rows[e.RowIndex].Cells[5].Value.ToString();
//                dgvMatHang_HoaDon.DataSource = ThuvienWin.XemQuery(String.Format(@"SELECT mathang_hoadon.ID, mathang_hoadon.Mamathang, mathang_hoadon.Mahoadon, mathang_hoadon.soluongmathang, mathang.mavach, mathang.tenmathang, mathang.dongia
//                                            FROM mathang INNER JOIN mathang_hoadon ON mathang.ID = mathang_hoadon.Mamathang
//                                            WHERE (((mathang_hoadon.Mahoadon)={0}));", MaChonHD));
                tabControl1.SelectedTab = tabPage2;
            }
        }
예제 #2
0
 private void btnSua_Click(object sender, EventArgs e)
 {
     if (ThuvienWin.confirm())
     {
         String sql = String.Format("update mathang set Mavach = '{0}', Tenhang = '{1}', Gia = {2}, Conlai = '{3}' where Id = {4}", txtSuaMV.Text, txtSuaTMH.Text, txtSuaGMH.Text, txtSuaSL.Text, MaSuaMH);
         ThuvienWin.ThemSuaXoaQuery(sql);
         MessageBox.Show("Sửa thành công!", "Thông Báo");
         LayMatHang();
     }
 }
예제 #3
0
 private void btnThem_Click(object sender, EventArgs e)
 {
     if (ThuvienWin.confirm())
     {
         String sql = String.Format("insert into mathang (ID,Mavach,Tenhang,Gia,Conlai) values({0},'{1}','{2}',{3},'{4}')", MaMH, txtThemMV.Text, txtThemTMH.Text, txtThemGMH.Text, txtThemSL.Text);
         ThuvienWin.ThemSuaXoaQuery(sql);
         MessageBox.Show("Đã thêm thành công!", "Thông báo");
         TaoMaMatHang();
         LayMatHang();
     }
 }
예제 #4
0
파일: banhang.cs 프로젝트: ducanh6699/QLBH
 private void dgvHoaDon_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 0 && e.RowIndex != -1) // bấm nút xóa trên dgv
     {
         if (ThuvienWin.confirm())
         {
             ThuvienWin.ThemSuaXoaQuery("delete from hoadon where ID = " + dgvHoaDon.Rows[e.RowIndex].Cells[2].Value.ToString());
             MessageBox.Show("Đã xóa thành công!", "Thông báo");
             dgvMatHang_HoaDon.DataSource = ThuvienWin.XemQuery(String.Format(@"SELECT mathang_hoadon.ID, mathang_hoadon.Mamathang, mathang_hoadon.Mahoadon, mathang_hoadon.Soluongmathang, mathang.Mavach, mathang.Tenhang, mathang.Gia, mathang_hoadon.Thanhtien
                                     FROM mathang INNER JOIN mathang_hoadon ON mathang.ID = mathang_hoadon.Mamathang
                                     WHERE (((mathang_hoadon.Mahoadon)={0}));", dgvHoaDon.Rows[e.RowIndex].Cells[2].Value.ToString()));
             LayHoaDon();
             TaoMaHoaDon();
         }
     }
     else if (e.ColumnIndex == 1 && e.RowIndex != -1) // bấm nút hiển thị trên dgv
     {
         MaChonHD = dgvHoaDon.Rows[e.RowIndex].Cells[2].Value.ToString();
         dgvMatHang_HoaDon.DataSource = ThuvienWin.XemQuery(String.Format(@"SELECT mathang_hoadon.ID, mathang_hoadon.Mamathang, mathang_hoadon.Mahoadon, mathang_hoadon.Soluongmathang, mathang.Mavach, mathang.Tenhang, mathang.Gia, mathang_hoadon.Thanhtien
                                     FROM mathang INNER JOIN mathang_hoadon ON mathang.ID = mathang_hoadon.Mamathang
                                     WHERE (((mathang_hoadon.Mahoadon)={0}));", MaChonHD));
     }
 }
예제 #5
0
 private void dgvMatHang_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == 1 && e.RowIndex != -1) // bấm nút sửa trên dgv
     {
         MaSuaMH                 = dgvMatHang.Rows[e.RowIndex].Cells[2].Value.ToString();
         txtSuaMV.Text           = dgvMatHang.Rows[e.RowIndex].Cells[3].Value.ToString();
         txtSuaTMH.Text          = dgvMatHang.Rows[e.RowIndex].Cells[4].Value.ToString();
         txtSuaGMH.Text          = dgvMatHang.Rows[e.RowIndex].Cells[6].Value.ToString();
         txtSuaSL.Text           = dgvMatHang.Rows[e.RowIndex].Cells[5].Value.ToString();
         tabControl1.SelectedTab = tabPage2;
     }
     else if (e.ColumnIndex == 0 && e.RowIndex != -1) // bấm nút xóa trên dgv
     {
         if (ThuvienWin.confirm())
         {
             String sql = String.Format("delete from mathang where ID = {0}", dgvMatHang.Rows[e.RowIndex].Cells[2].Value.ToString());
             ThuvienWin.ThemSuaXoaQuery(sql);
             MessageBox.Show("Xóa Thành Công!", "Thông Báo");
             TaoMaMatHang();
             LayMatHang();
             tabControl1.SelectedTab = tabPage1;
         }
     }
 }