void dataGridView1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete) { if (this.dgvListForm.SelectedRows.Count == 1) { if (MessageBox.Show("Do you want delete this?") == System.Windows.Forms.DialogResult.OK) { XeView selected = (XeView)this.dgvListForm.SelectedRows[0].DataBoundItem; var db = new WorkerFileEntities(); Xe deleted = db.Xes.Find(selected.License_Plates); db.Xes.Remove(deleted); db.SaveChanges(); string bienSoXe = selected.License_Plates; string tenXe = selected.Name; int hangXe = business.ReManufacure(selected.Manufacture); DateTime time = DateTime.Parse(selected.Time_Parking); business.AddBikes(bienSoXe, tenXe, hangXe, time); MessageBox.Show("Successfully deleted"); this.OnLoad(null); } } } }
public void AddBike(string bienSo, string tenXe, int hangXe, DateTime guiXe) { WorkerFileEntities db = new WorkerFileEntities(); Xe xe = new Xe(); xe.License_Plates = bienSo; xe.Name = tenXe; xe.Manufacture = hangXe; xe.Time_Parking = guiXe; db.Xes.Add(xe); db.SaveChanges(); db.Dispose(); }
void UpdateListForm_Load(object sender, EventArgs e) { //MessageBox.Show("OK"); this.cboHang.DataSource = business.GetManufactures(); this.cboHang.DisplayMember = "Name"; this.cboHang.ValueMember = "ID"; Xe xe = business.GetBike(this.bienSo); this.txtbienSo.Text = xe.License_Plates; this.txtTenxe.Text = xe.Name; this.cboHang.SelectedValue = xe.Manufacture; this.dtpGui.Value = xe.Time_Parking; }