private void exportToolStripMenuItem_Click(object sender, EventArgs e) { try { service.Export("orders.xml"); TipForm tipForm = new TipForm("Export successful!"); tipForm.ShowDialog(); } catch { TipForm tipForm = new TipForm("Export failed!"); tipForm.ShowDialog(); } }
private void importToolStripMenuItem_Click(object sender, EventArgs e) { try { service.Import("orders.xml"); List <OrderTableView> views = service.Orders.Select(order => new OrderTableView(order)).ToList(); orderBindingSource.DataSource = views; service.OrderIDCounter = service.Orders != null && service.Orders.Count > 0 ? service.Orders[service.Orders.Count - 1].OrderID : 0; TipForm tipForm = new TipForm("Import successful!"); tipForm.ShowDialog(); } catch (Exception y) { TipForm tipForm = new TipForm(y.Message); tipForm.ShowDialog(); } }
private void btnSearch_Click(object sender, EventArgs e) { List <Order> resultOrders = null; switch (cmbSearch.SelectedIndex) { case 0: if (tbxSearch.Text == "") { resultOrders = service.FindOrder(int.MinValue, null, null); } else { int ID; try { ID = int.Parse(tbxSearch.Text); resultOrders = service.FindOrder(ID, null, null); } catch { TipForm tipForm = new TipForm("Invaild input!"); tipForm.ShowDialog(); tbxSearch.Text = ""; return; } } break; case 1: resultOrders = service.FindOrder(int.MinValue, tbxSearch.Text, null); break; case 2: resultOrders = service.FindOrder(int.MinValue, null, tbxSearch.Text); break; } List <OrderTableView> views = resultOrders.Select(order => new OrderTableView(order)).ToList(); orderBindingSource.DataSource = views; }