private void btnTaoLK_Click(object sender, EventArgs e) { KhuyenMaiBLL bll = new KhuyenMaiBLL(); MatHangBLL mhb = new MatHangBLL(); String str; foreach (var item in lisMHLK.SelectedItems) { str = lisMHLK.GetItemText(item); KMInfo kmi = new KMInfo(); kmi.idKM = int.Parse(cboKhuyenMaiLK.SelectedValue.ToString()); kmi.idMH = mhb.getIdByName(str); try { bll.addKM(kmi); MessageBox.Show(kmi.idKM + "-" + kmi.idMH.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message); } } MessageBox.Show("Tạo liên kết thành công"); }
public bool addKM(KMInfo O) { try { return(dal.addKM(O)); } catch (Exception ex) { throw ex; } }
public KMInfo getKMInfo(int idMH) { string query = string.Format("SELECT * FROM dbo.KMInfo WHERE idMH = {0}", idMH); DataTable data = ExcuteQuery(query); foreach (DataRow item in data.Rows) { KMInfo km = new KMInfo(item); return(km); } return(null); }
public bool addKM(KMInfo O) { string query = string.Format("INSERT INTO dbo.KMInfo(idKM, idMH) VALUES({0},{1})", O.idKM, O.idMH); try { ExcuteNonQuery(query); return(true); } catch (Exception ex) { throw ex; } }
private void Details_Load(object sender, EventArgs e) { SuKien(); tbcUpdate.Controls.Clear(); // Mặt hàng if (Fn == Function.MAT_HANG) { tbcUpdate.Controls.Add(tpMH); MatHangBLL bll = new MatHangBLL(); MatHang mh = bll.getDetailsById(id); DanhMucBLL bll1 = new DanhMucBLL(); KhuyenMaiBLL kmb = new KhuyenMaiBLL(); KMInfo km = kmb.getKMInfo(mh.id); if (km == null) { btnXoaLK.Enabled = false; } txtIdM.Text = mh.id.ToString(); txtIdDMM.Text = bll1.getNameById(mh.idDM); txtNameM.Text = mh.name; txtSoLuongM.Text = mh.soluong.ToString(); txtGiaBanM.Text = mh.giaban.ToString(); txtGiaNhapM.Text = mh.gianhap.ToString(); txtGiaNhapM.ReadOnly = txtGiaBanM.ReadOnly = txtSoLuongM.ReadOnly = txtIdM.ReadOnly = txtIdDMM.ReadOnly = txtNameM.ReadOnly = true; Width = 609; Height = 421; } // Danh mục else if (Fn == Function.DANH_MUC) { tbcUpdate.Controls.Add(tpDM); DanhMucBLL bll = new DanhMucBLL(); DanhMuc dm = bll.getDetailsById(id); txtIdDM.Text = dm.id.ToString(); txtNameDM.Text = dm.name; txtContentDM.Text = dm.content; txtIdDM.ReadOnly = txtNameDM.ReadOnly = txtContentDM.ReadOnly = true; Width = 426; Height = 419; } // Nhân viên else if (Fn == Function.NHAN_VIEN) { tbcUpdate.Controls.Add(tpNV); NhanVienBLL bll = new NhanVienBLL(); NhanVien nv = bll.getDetailsById(id); txtIdNV.Text = nv.id.ToString(); txtUsernameNV.Text = nv.username; txtPasswordNV.Text = nv.password; txtNameNV.Text = nv.name; txtChucVuNV.Text = nv.chucvu; if (nv.gioitinh == 0) { txtGioiTinhNV.Text = "Nữ"; } else { txtGioiTinhNV.Text = "Nam"; } txtDiaChiNV.Text = nv.diachi; txtSdtNV.Text = nv.sdt; txtIdNV.ReadOnly = txtUsernameNV.ReadOnly = txtPasswordNV.ReadOnly = txtNameNV.ReadOnly = txtChucVuNV.ReadOnly = txtGioiTinhNV.ReadOnly = txtDiaChiNV.ReadOnly = txtSdtNV.ReadOnly = true; Width = 631; Height = 428; } // Nhà cung cấp else if (Fn == Function.NHA_CUNG_CAP) { tbcUpdate.Controls.Add(tpNCC); NhaCungCapBLL bll = new NhaCungCapBLL(); NhaCungCap ncc = bll.getDetailsById(id); txtIdNCC.Text = ncc.id.ToString(); txtNameNCC.Text = ncc.name; txtContentNCC.Text = ncc.content; txtSdtNCC.Text = ncc.sdt; txtDiaChiNCC.Text = ncc.diachi; txtIdNCC.ReadOnly = txtNameNCC.ReadOnly = txtContentNCC.ReadOnly = txtSdtNCC.ReadOnly = txtDiaChiNCC.ReadOnly = true; Width = 480; Height = 428; } // Khuyến mãi else if (Fn == Function.KHUYEN_MAI) { tbcUpdate.Controls.Add(tpKM); KhuyenMaiBLL bll = new KhuyenMaiBLL(); KhuyenMai km = bll.getDetailsById(id); txtIdKM.Text = km.id.ToString(); txtContentKM.Text = km.content; txtGiaKM.Text = km.gia.ToString(); if (km.typegia == 0) { txtTypeGiaKM.Text = "Phần trăm"; } else { txtTypeGiaKM.Text = "Nghìn đồng"; } txtBatDauKM.Text = km.starttime.Substring(0, km.starttime.LastIndexOf(" 12:00:00 AM")); txtKetThucKM.Text = km.endtime.Substring(0, km.endtime.LastIndexOf(" 12:00:00 AM")); txtTypeGiaKM.ReadOnly = txtIdKM.ReadOnly = txtContentKM.ReadOnly = txtGiaKM.ReadOnly = txtGiaKM.ReadOnly = txtBatDauKM.ReadOnly = txtKetThucKM.ReadOnly = true; Width = 580; Height = 421; } // Nhập hàng else if (Fn == Function.NHAP) { tbcUpdate.Controls.Add(tpNH); NhapHangBLL bll = new NhapHangBLL(); NhapHang nh = bll.getDetailsById(id); txtIdNH.Text = nh.id.ToString(); txtIdMHNH.Text = nh.idMH.ToString(); txtIdNVNH.Text = nh.idNV.ToString(); txtIdNCCNH.Text = nh.idNCC.ToString(); txtSoLuongNH.Text = nh.soluong.ToString(); txtThanhTienNH.Text = nh.thanhtien.ToString(); txtIdNH.ReadOnly = txtIdMHNH.ReadOnly = txtIdNVNH.ReadOnly = txtIdNCCNH.ReadOnly = txtSoLuongNH.ReadOnly = txtThanhTienNH.ReadOnly = true; Width = 613; Height = 421; } // Xuất hàng else if (Fn == Function.XUAT) { tbcUpdate.Controls.Add(tpXH); XuatHangBLL bll = new XuatHangBLL(); XuatHang xh = bll.getDetailsById(id); txtIdXH.Text = xh.id.ToString(); txtIdNVXH.Text = xh.idNV.ToString(); txtIdMHXH.Text = xh.idMH.ToString(); txtSoLuongXH.Text = xh.soluong.ToString(); txtThanhTienXH.Text = xh.thanhtien.ToString(); txtNgayXuat.Text = xh.ngayxuat; txtIdXH.ReadOnly = txtIdNVXH.ReadOnly = txtIdMHXH.ReadOnly = txtSoLuongXH.ReadOnly = txtThanhTienXH.ReadOnly = txtNgayXuat.ReadOnly = true; Width = 613; Height = 421; } }