private void button1_Click(object sender, EventArgs e) { if(txAmount.Text.Equals("") || txDescription.Text.Equals("")) MessageBox.Show(this, "Please fill in the Description and Amount", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); else if(cmbCategory.SelectedIndex < 1) MessageBox.Show(this, "Please select one Category", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); else if (!checkNumeric(txAmount.Text)) MessageBox.Show(this, "Amount must be numeric", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); else { Expense ex = new Expense(); ex.Amount = Decimal.Parse(txAmount.Text); ex.Category = cmbCategory.SelectedItem.ToString(); ex.Description = txDescription.Text; ex.PurchaseDate = DateTime.Now; db.Expenses.InsertOnSubmit(ex); db.SubmitChanges(); refreshTable(); MessageBox.Show(this, "New Expense submitted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
partial void DeleteExpense(Expense instance);
partial void InsertExpense(Expense instance);
partial void UpdateExpense(Expense instance);
private void expenseToolStripMenuItem1_Click(object sender, EventArgs e) { openFileDialog1.InitialDirectory = Utility.mySettings.DefaultFileLocation; DialogResult dr = openFileDialog1.ShowDialog(); if (dr == DialogResult.OK) { string filePath = openFileDialog1.FileName; long rows = Utility.CountLinesInFile(filePath); if (rows > 0) { toolStripProgressBar1.Visible = true; toolStripProgressBar1.Maximum = (int)rows; toolStripProgressBar1.Value = 0; } StreamReader sr = new StreamReader(filePath); int x = 0; while (!sr.EndOfStream) { string[] Line = sr.ReadLine().Split(','); try { Expense o = new Expense(); o.Description = Line[1].Trim(); o.Amount = Decimal.Parse(Line[2].Trim()); o.PurchaseDate = DateTime.ParseExact(Line[3].Trim(), Utility.myDateTimeFormat, null); o.Category = convertCategory(Line[4].Trim()); db.Expenses.InsertOnSubmit(o); db.SubmitChanges(); if (rows > 0) toolStripProgressBar1.Value++; x++; } catch (Exception ex) { } } sr.Close(); MessageBox.Show(this, x + " rows of Expense imported", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); toolStripProgressBar1.Visible = false; } }