/// <summary> /// TODO use PartID and DTO to hydrate the control /// </summary> /// <param name="part"></param> /// <param name="ctx"></param> public PartView(Part part, BadgerDataModel ctx) { InitializeComponent(); _context = ctx; ISuppliersService var = new SuppliersService(_context); inventoryService = new InventoryService(_context); partsService = new PartsService(_context); this.dataGridView1.AutoGenerateColumns = false; this.dgvTransactions.AutoGenerateColumns = false; if (part.PartID > 0) { _part = partsService.Find(part.PartID); } else { _part = partsService.New(); _part.AddedBy = Globals.CurrentUserName; _part.DateAdded = DateTime.Today; } cboSuppliers.DisplayMember = "SupplierName"; cboSuppliers.ValueMember = "SupplierID"; cboSuppliers.SelectedItem = _part.SupplierId; cboSuppliers.DataSource = var.GetAll(); cboUnits.DisplayMember = "UOM"; cboUnits.ValueMember = "UID"; cboUnits.SelectedItem = _part.UID; cboUnits.DataSource = partsService.Units(); cboManus.DisplayMember = "Manufacturer"; cboManus.ValueMember = "ManuID"; cboManus.SelectedItem = _part.ManuId; cboManus.DataSource = partsService.Manufacturers(); bsPart.DataSource = _part; // This triggers the Save Button On changed-- bsPart.CurrentItemChanged += BsPart_CurrentItemChanged; this.btnSave.Enabled = _isDirty; this.txtSupplierDesc.Enabled = false; _documents = _context.Document.Where(r => r.PartID == _part.PartID).ToList(); // _documents = _part.Document.ToList(); bsDocuments.DataSource = _documents; this.dataGridView1.DataSource = bsDocuments; LoadTransaction(); this.rbRecieved.Checked = true; }