// WINDOW CONTROL BUTTON ** WINDOW CONTROL BUTTON ** WINDOW CONTROL BUTTON ** WINDOW CONTROL BUTTON ** WINDOW CONTROL BUTTON private void buttonSave_Click(object sender, EventArgs e) { try { // Create the new Model, case don't exists if (item == null) { item = new Models.Expense(); } item.Description = tbDescription.Text; item.Price = Double.Parse(tbPrice.Text); item.Count = Double.Parse(tbCount.Text); item.Date = dpDate.Value.Date; // Case if a new item if (item.Id == -1) { db.Insert(item); } // Case is a existent item else { db.Update(item); } // Close the edit form this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Confira os dados inseridos", MessageBoxButtons.OK, MessageBoxIcon.Error); // Destroy the temp item if (item.Id == -1) { item = null; } } finally { } }
// BUTTON EVENTS private void buttonImport_Click(object sender, EventArgs e) { if (tabs.SelectedIndex == 0) { try { String[] lines = textboxContent.Text.Split('\n'); // Clear old listview content listviewExpenses.Items.Clear(); foreach (String l in lines) { // Separate the row item String [] la = l.Split('\t'); // Check row length if (la.Length < 3) { continue; } // Create items Expense item = new Expense(); item.Description = la[0].Trim(); item.Date = DateTime.Parse(la[1].Trim()); item.Price = Double.Parse(la[2].Trim().Substring(2)); item.Count = 1; expenses.Add(item); // Put data on listview ListViewItem row = new ListViewItem(item.Description); row.SubItems.Add(item.Description.ToString()); row.SubItems.Add(item.Date.ToString().Split(' ')[0]); row.SubItems.Add(String.Format("{0:0.000}", item.Count)); row.SubItems.Add(String.Format("R$ {0:N}", item.Price)); row.SubItems.Add(String.Format("R$ {0:N}", item.TotalPrice)); listviewExpenses.Items.Add(row); } tabs.SelectedIndex = 1; } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro no processamento", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (tabs.SelectedIndex == 1) { try { if (expenses.Count == 0) { throw new Exception("Nenhum item processado"); } else { foreach (Expense item in expenses) { MessageBox.Show(item.ToString(), "Item inserido"); db.Insert(item); } MessageBox.Show("Totos os itens listados foram inseridos com sucesso.", "Importados com êxito", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro na importação", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }