private void detach_HSMuons(HSMuon entity) { this.SendPropertyChanging(); entity.KhachHang = null; }
private void attach_HSMuons(HSMuon entity) { this.SendPropertyChanging(); entity.KhachHang = this; }
partial void DeleteHSMuon(HSMuon instance);
partial void UpdateHSMuon(HSMuon instance);
partial void InsertHSMuon(HSMuon instance);
private void btnLuu_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtMaKH.Text)) { MessageBox.Show("Mã Khách Hàng không thể để trống!"); return; } if (listViewDaThemBD.Items.Count <= 0) { MessageBox.Show("Chưa có Băng Đĩa nào!"); return; } HSMuon hsmuon = new HSMuon { //MaHSMuon = txtMaHSMuon.Text, NgayMuon = dateNgMuon.Value, NgayDuKien = dateNgDuKienTra.Value, MaKH = Int32.Parse(txtMaKH.Text), DaTra = false // chua tra }; db.HSMuons.InsertOnSubmit(hsmuon); db.SubmitChanges(); for (int i = 0; i < listViewDaThemBD.Items.Count; i++) { if (listViewDaThemBD.Columns[0].Text == "Mã Băng") { var hsm = from temp in db.HSMuons select new { temp.MaHSMuon }; foreach (var s in hsm) { var mabang = Int32.Parse(listViewDaThemBD.Items[i].SubItems[0].Text); int soluong = int.Parse(listViewDaThemBD.Items[i].SubItems[5].Text); int slBangDia = Int32.Parse(listViewBangDia.Items[i].SubItems[5].Text); int tongSoLuong = slBangDia - soluong; String statement = "insert into HSMuon_BangDia values('" + s.MaHSMuon + "','" + mabang + "','" + soluong + "')"; db.ExecuteQuery <HSMuon_BangDia>(statement); var kq = from temp in db.BangDias where temp.MaBang == mabang select temp; foreach (var sl in kq) { sl.SoLuong = tongSoLuong; } db.SubmitChanges(); //string statementCN = "update BangDia set SoLuong=" + tongSoLuong + " where MaBang = '" + mabang + "'";//cap nhat lai so luong bang dia //db.ExecuteQuery<BangDia>(statementCN); } } } MessageBox.Show("Lưu Thành Công!!"); }