public object GetProduct(receipt pRec)
 {
     try
     {
         var p = from d in pRec.receipt_details
                 select d;
         return p;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public bool Insert(receipt pReceipt)
 {
     try
     {
         pReceipt.created = DateTime.Now;
         db.receipts.InsertOnSubmit(pReceipt);
         db.SubmitChanges();
         return true;
     }
     catch(Exception ex)
     {
         throw ex;
     }
 }
 private void btnLuu_Click(object sender, EventArgs e)
 {
     if (dpNgayLap.EditValue == null)
     {
         CheckLoi(lbNgayLap.Text);
         dpNgayLap.Focus();
     }
     if (lkNhanVien.EditValue == null)
     {
         CheckLoi(lkNhanVien.Text);
         lkNhanVien.Focus();
     }
     if (lkNhaCungCap.EditValue == null)
     {
         CheckLoi(lkNhaCungCap.Text);
         lkNhaCungCap.Focus();
     }
     r = new receipt();
     r.id = txtMaPhieuNhap.Text;
     r.created = (DateTime)dpNgayLap.EditValue;
     staff st = (staff)lkNhanVien.GetSelectedDataRow();
     provider pr = (provider)lkNhaCungCap.GetSelectedDataRow();
     r.staff = st;
     r.provider = pr;
     if (busNhapHang.Save())
     {
         XtraMessageBox.Show("Lưu thành công", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
         btnDanhMucLamMoi.PerformClick();
     }
     else
     {
         XtraMessageBox.Show("Lưu thất bại", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
     }
     txtMaPhieuNhap.Text = null;
     dpNgayLap.EditValue = lkNhaCungCap.EditValue = lkNhanVien.EditValue = null;
     panelControl4.Enabled = false;
 }
        private void gvPhieuNhapHang_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (gvPhieuNhapHang.SelectedRowsCount != 1)
                return;
            r = (receipt)gvPhieuNhapHang.GetFocusedRow();
            dpNgayLap.EditValue = r.created;
            dpNgayLap.DateTime = r.created;
            txtMaPhieuNhap.Text = r.id;
            lkNhaCungCap.EditValue = r.provider.id;
            lkNhanVien.EditValue = r.staff.id;

            dgvChiTietNhapHang.DataSource = busNhapHang.GetProduct(r);
        }
 public bool KiemTraTonTai(receipt pnh, product sp)
 {
     try
     {
         var p = from d in pnh.receipt_details
                 where d.product_id.Equals(sp.id)
                 select d;
         return p.Count() == 1;
     }
     catch(Exception ex)
     {
         throw ex;
     }
 }
 public bool Update(receipt pReceipt)
 {
     try
     {
         pReceipt.modified = DateTime.Now;
         db.SubmitChanges();
         return true;
     }
     catch(Exception ex)
     {
         throw ex;
     }
 }
 partial void Deletereceipt(receipt instance);
 partial void Updatereceipt(receipt instance);
 partial void Insertreceipt(receipt instance);
		private void detach_receipts(receipt entity)
		{
			this.SendPropertyChanging();
			entity.staff = null;
		}
		private void attach_receipts(receipt entity)
		{
			this.SendPropertyChanging();
			entity.staff = this;
		}