private void Entry_DataChanged(object sender, VehicleUpdateEventArgs e, DataEventType Action) { ListViewItem lvItem; switch (Action) { case DataEventType.INSERT_EVENT: lvItem = new ListViewItem(); lvItem.Name = Convert.ToString(e.DBID); lvItem.Text = e.VehicleNo; lvItem.SubItems.Add(e.PUCExpiry.ToShortDateString()); lvwVehicles.Items.Add(lvItem); lvwVehicles.EnsureVisible(lvItem.Index); break; case DataEventType.UPDATE_EVENT: lvItem = lvwVehicles.Items[lvwVehicles.SelectedItems[0].Index]; lvItem.Text = e.VehicleNo; lvItem.SubItems[1].Text = e.PUCExpiry.ToShortDateString(); lvwVehicles.EnsureVisible(lvwVehicles.SelectedItems[0].Index); break; } }
private void btnSave_Click(object sender, EventArgs e) { try { bool flgApplyEdit; flgApplyEdit = VehicleManager.Save(objVehicle, objUser); if (flgApplyEdit) { // instance the event args and pass it value VehicleUpdateEventArgs args = new VehicleUpdateEventArgs(objVehicle.Dbid, objVehicle.VehicleNo, objVehicle.VLicencseNo, objVehicle.PUCExpiry); // raise event wtth updated if (Entry_DataChanged != null) { if (this.IsNew) { Entry_DataChanged(this, args, DataEventType.INSERT_EVENT); } else { Entry_DataChanged(this, args, DataEventType.UPDATE_EVENT); } } this.Close(); } else { MessageBox.Show("Record Not Saved."); } } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }