I want to make a small app using c# that will help me control my cash flow.
I would input to the program each time the amount of money I spent (after each day I will enter this day's expenses and it will be added to the program database).
I know this program should include the following factors:
A calendar that will show me each day's expenses.
Some integers, not too difficult to grasp.
A database that will hold each day's expenses (how should I do that?).
A save function (no idea how to do that one).
Any recommendations on how to make it?
I know it shouldn't be THAT hard and that this is kind of a Low-level usage of the language, so the inexperienced c# newbie should grasp this project maybe not too easily, but he should.
Speak, my friends :)
Cashflow\\ Any suggestions?
Started by Demodex, Jan 08 2010 06:12 AM
13 replies to this topic
#1
Posted 08 January 2010 - 06:12 AM
Demodex is one of the parasitic face mites that occur on people
These parasites are found in the hair, normally found in greater numbers around the cheeks and foreheadWatch out !!!;)
These parasites are found in the hair, normally found in greater numbers around the cheeks and foreheadWatch out !!!;)
|
|
|
#2
Posted 08 January 2010 - 07:35 AM
If this isn't an assignment, just do this in a spreadsheet.
If it is, take a look at using SQLite to handle your database functions. (Love it & use it at my job for configuration files / calibration files )
If it is, take a look at using SQLite to handle your database functions. (Love it & use it at my job for configuration files / calibration files )
#3
Posted 09 January 2010 - 07:57 AM
Not an assignment.
Just want to implement what I have learned so far in C#, while getting recommendations from you guys.
Just want to implement what I have learned so far in C#, while getting recommendations from you guys.
Demodex is one of the parasitic face mites that occur on people
These parasites are found in the hair, normally found in greater numbers around the cheeks and foreheadWatch out !!!;)
These parasites are found in the hair, normally found in greater numbers around the cheeks and foreheadWatch out !!!;)
#4
Posted 09 January 2010 - 08:23 AM
Ok, not a prob then.
It seems like we're getting lots of homework help questions recently.
OK, What have you got so far ?
Do you have a Database Format (Are you going to use a full blown Database or something like SQLIte ?)
It seems like we're getting lots of homework help questions recently.
OK, What have you got so far ?
Do you have a Database Format (Are you going to use a full blown Database or something like SQLIte ?)
#5
Posted 09 January 2010 - 12:00 PM
Well I think the biggest thing I recognize as a problem is the database.
I never worked with databases before in C#.
Is creating an SQL database will be the smartest thing to do?
This is, above all my biggest challenge.
**
By the way, for the record - I finished school long ago :)
I never worked with databases before in C#.
Is creating an SQL database will be the smartest thing to do?
This is, above all my biggest challenge.
**
By the way, for the record - I finished school long ago :)
Demodex is one of the parasitic face mites that occur on people
These parasites are found in the hair, normally found in greater numbers around the cheeks and foreheadWatch out !!!;)
These parasites are found in the hair, normally found in greater numbers around the cheeks and foreheadWatch out !!!;)
#6
Posted 09 January 2010 - 05:38 PM
You can use a database like SQL or mySQL which there are a lot of tutorials for. If you want to keep it simple you can just use a simple text file for your database and use StreamWriter to "save" the data to it.
#7
Posted 10 January 2010 - 09:12 AM
Demodex said:
Well I think the biggest thing I recognize as a problem is the database.
I never worked with databases before in C#.
Is creating an SQL database will be the smartest thing to do?
This is, above all my biggest challenge.
**
By the way, for the record - I finished school long ago :)
I never worked with databases before in C#.
Is creating an SQL database will be the smartest thing to do?
This is, above all my biggest challenge.
**
By the way, for the record - I finished school long ago :)
A Database works well if you're going to be accessing the data from multiple locations, and you want them to all access the same data.
A File works best if you only want the program to access the one copy of data. So if you install the program on a second site, then that copy will have its own version of the data.
If it's the second (One copy of data) I'd go with either SQLite or a custom XML Document.
Both are quite easy to use in C#
Example Code (Not including the Includes :) )
public static bool LoadData(string LoadFile)
{
bool ValidConfigurationLoaded = false;
try
{
SQLConnect = new SQLiteConnection();
SQLConnect.ConnectionString = "Data Source = " + LoadFile;
SQLConnect.Open();
SQL_Command = SQLConnect.CreateCommand();
#region Get Settings
SQL_Command.CommandText = "SELECT * FROM 'settings'";
SQLReader = SQL_Command.ExecuteReader();
while (SQLReader.Read())
{
switch (SQLReader.GetInt32(0))
{
case 1:
Global.Data1 = SQLReader.GetInt32(2);
break;
case 2:
Global.Data2 = SQLReader.GetInt32(2);
break;
case 3:
Global.Data3 = SQLReader.GetInt32(2);
break;
}
}
SQLReader.Close();
#endregion
#region Get Magnet Calibraion Data
SQL_Command.CommandText = "SELECT * FROM 'buffers'";
SQLReader = SQL_Command.ExecuteReader();
int BufferIndex = 0;
while (SQLReader.Read())
{
MagCalIndex = SQLReader.GetInt32(0);
Global.Buffers[1, 1, BufferIndex] = Convert.ToDouble(SQLReader.GetValue(2));
Global.Buffers[1, 2, BufferIndex] = Convert.ToDouble(SQLReader.GetValue(3));
Global.Buffers[1, 3, BufferIndex] = Convert.ToDouble(SQLReader.GetValue(4));
Global.Buffers[2, 1, BufferIndex] = Convert.ToDouble(SQLReader.GetValue(5));
Global.Buffers[2, 2, BufferIndex] = Convert.ToDouble(SQLReader.GetValue(6));
Global.Buffers[2, 3, BufferIndex] = Convert.ToDouble(SQLReader.GetValue(7));
}
SQLReader.Close();
#endregion
ValidConfigurationLoaded = true;
}
catch (Exception e)
{
// Database read had An Error
MessageBox.Show(e.Message);
ValidConfigurationLoaded = false;
}
return ValidConfigurationLoaded;
}
This Loads a SQLite File into the predefined arrays (Defined in Globals.cs)This is only a sniplet of code, and won't work by itself, but is taken from a working program I'm using that loads a few thousand data points.
#8
Posted 25 January 2010 - 11:38 AM
OK here is what I have so far...
Would appreciate any help :)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Cashflow
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
System.Data.SqlClient.SqlConnection con;
DataSet ds1;
System.Data.SqlClient.SqlDataAdapter da;
int MaxRows = 0;
int inc = 0;
private void Form1_Load(object sender, EventArgs e)
{
con = new System.Data.SqlClient.SqlConnection();
ds1 = new DataSet();
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\DB.mdf;Integrated Security=True;User Instance=True";
string sql = "SELECT* From DB";
da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
}
private void NavigateRecords()
{
DataRow dRow = ds1.Tables["Deals"].Rows[inc];
purchaselbl.Text = dRow.ItemArray.GetValue(1).ToString();
costlbl.Text = dRow.ItemArray.GetValue(2).ToString();
methodlbl.Text = dRow.ItemArray.GetValue(3).ToString();
}
private void dbconnectbtn_Click(object sender, EventArgs e)
{
if (con.State == ConnectionState.Closed)
{
con.Open();
MessageBox.Show("Connected to Database");
da.Fill(ds1, "Deals");
connectstatuslbl.Text = "Connected";
dbconnectbtn.Text = "Disconnect from Database";
connectstatuslbl.ForeColor = Color.Green;
NavigateRecords();
MaxRows = ds1.Tables["Deals"].Rows.Count;
}
else
{
con.Close();
MessageBox.Show("Disconnected from Database");
connectstatuslbl.Text = ("Disconnected");
dbconnectbtn.Text = "Connect to Database";
connectstatuslbl.ForeColor = Color.Red;
}
}
private void nextrecordbtn_Click(object sender, EventArgs e)
{
if (inc != MaxRows -1)
{
inc++;
NavigateRecords();
}
else
{
MessageBox.Show("No more records");
}
}
private void prevrecordbtn_Click(object sender, EventArgs e)
{
if (inc > 0)
{
inc--;
NavigateRecords();
}
else
{
MessageBox.Show("No more records");
}
}
private void lastrecordbtn_Click(object sender, EventArgs e)
{
if (inc != MaxRows - 1)
{
inc = MaxRows - 1;
NavigateRecords();
}
else
{
MessageBox.Show("This is the last record");
}
}
private void firstrecordbtn_Click_1(object sender, EventArgs e)
{
inc = 0;
NavigateRecords();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
DataRow dRow = ds1.Tables["Deals"].NewRow();
dRow[1] = newpurchasetb.Text;
dRow[2] = newsumtb.Text;
if (newcashrb.Checked)
{
dRow[3] = newcashrb.Text;
}
else if (newcreditrb.Checked)
{
dRow[3] = newcreditrb.Text;
}
else
{
MessageBox.Show("You must select a payment method", "Error");
}
ds1.Tables["Deals"].Rows.Add(dRow);
MaxRows = MaxRows + 1;
inc = MaxRows - 1;
}
catch
{
MessageBox.Show("You must fill the expense details", "Error");
}
}
}
}
Would appreciate any help :)
Demodex is one of the parasitic face mites that occur on people
These parasites are found in the hair, normally found in greater numbers around the cheeks and foreheadWatch out !!!;)
These parasites are found in the hair, normally found in greater numbers around the cheeks and foreheadWatch out !!!;)
#9
Posted 28 January 2010 - 08:28 AM
Guys It is extremely important for me to continue with this but I am now stuck...
I Added "Insurance" to the "Add & Update Records" buttons, from evil users point of view (evil inputs, integers instead of string and opposite, and blank text boxes. This is the reason for the two huge "if" parts. They are commented to help navigate through the code.
I have a new problem now though.
After I add a record, and then try to update it I get the following exception:
Concurrency violation:the UpdateCommand affected 0 of the expected 1 records.
Here is the code:
I Added "Insurance" to the "Add & Update Records" buttons, from evil users point of view (evil inputs, integers instead of string and opposite, and blank text boxes. This is the reason for the two huge "if" parts. They are commented to help navigate through the code.
I have a new problem now though.
After I add a record, and then try to update it I get the following exception:
Concurrency violation:the UpdateCommand affected 0 of the expected 1 records.
Here is the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Cashflow
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
System.Data.SqlClient.SqlConnection con;
DataSet ds1;
System.Data.SqlClient.SqlDataAdapter da;
int MaxRows = 0;
int inc = 0;
private void Form1_Load(object sender, EventArgs e)
{
con = new System.Data.SqlClient.SqlConnection();
ds1 = new DataSet();
con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\DB.mdf;Integrated Security=True;User Instance=True";
string sql = "SELECT* From DB";
da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
}
private void NavigateRecords()
{
DataRow dRow = ds1.Tables["Deals"].Rows[inc];
purchaselbl.Text = dRow.ItemArray.GetValue(1).ToString();
costlbl.Text = dRow.ItemArray.GetValue(2).ToString();
methodlbl.Text = dRow.ItemArray.GetValue(3).ToString();
}
private void dbconnectbtn_Click(object sender, EventArgs e)
{
if (con.State == ConnectionState.Closed)
{
con.Open();
MessageBox.Show("Connected to Database");
da.Fill(ds1, "Deals");
connectstatuslbl.Text = "Connected";
dbconnectbtn.Text = "Disconnect from Database";
connectstatuslbl.ForeColor = Color.Green;
NavigateRecords();
MaxRows = ds1.Tables["Deals"].Rows.Count;
}
else
{
con.Close();
MessageBox.Show("Disconnected from Database");
connectstatuslbl.Text = ("Disconnected");
dbconnectbtn.Text = "Connect to Database";
connectstatuslbl.ForeColor = Color.Red;
}
}
private void nextrecordbtn_Click(object sender, EventArgs e)
{
if (inc != MaxRows - 1)
{
inc++;
NavigateRecords();
}
else
{
MessageBox.Show("No more records");
}
}
private void prevrecordbtn_Click(object sender, EventArgs e)
{
if (inc > 0)
{
inc--;
NavigateRecords();
}
else
{
MessageBox.Show("No more records");
}
}
private void lastrecordbtn_Click(object sender, EventArgs e)
{
if (inc != MaxRows - 1)
{
inc = MaxRows - 1;
NavigateRecords();
}
else
{
MessageBox.Show("This is the last record");
}
}
private void firstrecordbtn_Click_1(object sender, EventArgs e)
{
inc = 0;
NavigateRecords();
}
private void createbtn_Click(object sender, EventArgs e)
{
System.Data.SqlClient.SqlCommandBuilder cb;
cb = new System.Data.SqlClient.SqlCommandBuilder(da);
DataRow dRow = ds1.Tables["Deals"].NewRow();
//1.this "if" is for all fields blank -> Error //
if (newpurchasetb.Text.Length == 0 && newsumtb.Text.Length == 0 && newcashrb.Checked == false && newcreditrb.Checked == false)
{
MessageBox.Show("Please enter purchase and sum fields, and select a payment method", "Error");
}
//2.this "if" is for all fields blank but "Credit" is checked -> Error //
else if (newpurchasetb.Text.Length == 0 && newsumtb.Text.Length == 0 && newcreditrb.Checked)
{
MessageBox.Show("Please enter purchase and sum details", "Error");
}
//3.this "if" is for all fields blank but "Cash" is checked -> Error //
else if (newpurchasetb.Text.Length == 0 && newsumtb.Text.Length == 0 && newcashrb.Checked)
{
MessageBox.Show("Please enter purchase and sum details", "Error");
}
//4.this "if" is for "Purchase" field not empty, but rest of fields are empty -> Error //
else if (newpurchasetb.Text.Length > 0 && newsumtb.Text.Length == 0 && newcashrb.Checked == false && newcreditrb.Checked == false)
{
MessageBox.Show("Please enter sum details and select a payment method", "Error");
}
//5.this "if" is for "Sum" field not empty, but rest of fields are empty -> Error //
else if (newpurchasetb.Text.Length == 0 && newsumtb.Text.Length > 0 && newcashrb.Checked == false && newcreditrb.Checked == false)
{
MessageBox.Show("Please enter purchase details and select a payment method", "Error");
}
//6.this "if" is for "Sum" field not empty and "Cash" is checked, but "Purchase" is empty -> Error //
else if (newpurchasetb.Text.Length == 0 && newsumtb.Text.Length > 0 && newcashrb.Checked)
{
MessageBox.Show("Please enter purchase details", "Error");
}
//7.this "if" is for "Sum" field not empty and "Credit" is checked, but "Purchase" is empty -> Error //
else if (newpurchasetb.Text.Length == 0 && newsumtb.Text.Length > 0 && newcreditrb.Checked)
{
MessageBox.Show("Please enter purchase details", "Error");
}
//8.this "if" is for "Purchase" field not empty and "Credit" is checked, but "Sum" is empty -> Error //
else if (newpurchasetb.Text.Length > 0 && newsumtb.Text.Length == 0 && newcreditrb.Checked)
{
MessageBox.Show("Please enter sum details", "Error");
}
//9.this "if" is for "Purchase" field not empty and "Cash" is checked, but "Sum" is empty -> Error //
else if (newpurchasetb.Text.Length > 0 && newsumtb.Text.Length == 0 && newcashrb.Checked)
{
MessageBox.Show("Please enter sum details", "Error");
}
//10.this "if" is for "Purchase" and "Sum" fiels not empty, but no payment method is checked -> Error//
else if (newpurchasetb.Text.Length > 0 && newsumtb.Text.Length > 0 && newcashrb.Checked == false && newcreditrb.Checked == false)
{
MessageBox.Show("Please select a payment method", "Error");
}
//11.this "if" is for "Purchase" and "Sum" fiels not empty, and "Cash" is selected -> Success//
else if (newpurchasetb.Text.Length > 0 && newsumtb.Text.Length > 0 && newcashrb.Checked)
{
dRow[1] = newpurchasetb.Text;
dRow[2] = newsumtb.Text;
dRow[3] = newcashrb.Text;
ds1.Tables["Deals"].Rows.Add(dRow);
MaxRows = MaxRows + 1;
inc = MaxRows - 1;
da.Update(ds1, "Deals");
MessageBox.Show("The data you enterred has been successfully added to the database", "Data added");
}
//12.this "if" is for "Purchase" and "Sum" fiels not empty, and "Credit" is selected -> Success//
else if (newpurchasetb.Text.Length > 0 && newsumtb.Text.Length > 0 && newcreditrb.Checked)
{
dRow[1] = newpurchasetb.Text;
dRow[2] = newsumtb.Text;
dRow[3] = newcreditrb.Text;
ds1.Tables["Deals"].Rows.Add(dRow);
MaxRows = MaxRows + 1;
inc = MaxRows - 1;
da.Update(ds1, "Deals");
MessageBox.Show("The data you enterred has been successfully added to the database", "Data added");
}
}
private void updatebtn_Click(object sender, EventArgs e)
{
System.Data.SqlClient.SqlCommandBuilder cb;
cb = new System.Data.SqlClient.SqlCommandBuilder(da);
System.Data.DataRow dRow2 = ds1.Tables["Deals"].Rows[inc];
//1.this "if" is for all fields blank -> Error //
if (newpurchasetb.Text.Length == 0 && newsumtb.Text.Length == 0 && newcashrb.Checked == false && newcreditrb.Checked == false)
{
MessageBox.Show("Please enter purchase and sum fields, and select a payment method", "Error");
}
//2.this "if" is for all fields blank but "Credit" is checked -> Error //
else if (newpurchasetb.Text.Length == 0 && newsumtb.Text.Length == 0 && newcreditrb.Checked)
{
MessageBox.Show("Please enter purchase and sum details", "Error");
}
//3.this "if" is for all fields blank but "Cash" is checked -> Error //
else if (newpurchasetb.Text.Length == 0 && newsumtb.Text.Length == 0 && newcashrb.Checked)
{
MessageBox.Show("Please enter purchase and sum details", "Error");
}
//4.this "if" is for "Purchase" field not empty, but rest of fields are empty -> Error //
else if (newpurchasetb.Text.Length > 0 && newsumtb.Text.Length == 0 && newcashrb.Checked == false && newcreditrb.Checked == false)
{
MessageBox.Show("Please enter sum details and select a payment method", "Error");
}
//5.this "if" is for "Sum" field not empty, but rest of fields are empty -> Error //
else if (newpurchasetb.Text.Length == 0 && newsumtb.Text.Length > 0 && newcashrb.Checked == false && newcreditrb.Checked == false)
{
MessageBox.Show("Please enter purchase details and select a payment method", "Error");
}
//6.this "if" is for "Sum" field not empty and "Cash" is checked, but "Purchase" is empty -> Error //
else if (newpurchasetb.Text.Length == 0 && newsumtb.Text.Length > 0 && newcashrb.Checked)
{
MessageBox.Show("Please enter purchase details", "Error");
}
//7.this "if" is for "Sum" field not empty and "Credit" is checked, but "Purchase" is empty -> Error //
else if (newpurchasetb.Text.Length == 0 && newsumtb.Text.Length > 0 && newcreditrb.Checked)
{
MessageBox.Show("Please enter purchase details", "Error");
}
//8.this "if" is for "Purchase" field not empty and "Credit" is checked, but "Sum" is empty -> Error //
else if (newpurchasetb.Text.Length > 0 && newsumtb.Text.Length == 0 && newcreditrb.Checked)
{
MessageBox.Show("Please enter sum details", "Error");
}
//9.this "if" is for "Purchase" field not empty and "Cash" is checked, but "Sum" is empty -> Error //
else if (newpurchasetb.Text.Length > 0 && newsumtb.Text.Length == 0 && newcashrb.Checked)
{
MessageBox.Show("Please enter sum details", "Error");
}
//10.this "if" is for "Purchase" and "Sum" fiels not empty, but no payment method is checked -> Error//
else if (newpurchasetb.Text.Length > 0 && newsumtb.Text.Length > 0 && newcashrb.Checked == false && newcreditrb.Checked == false)
{
MessageBox.Show("Please select a payment method", "Error");
}
//11.this "if" is for "Purchase" and "Sum" fiels not empty, and "Cash" is selected -> Success//
else if (newpurchasetb.Text.Length > 0 && newsumtb.Text.Length > 0 && newcashrb.Checked)
{
dRow2[1] = newpurchasetb.Text;
dRow2[2] = newsumtb.Text;
dRow2[3] = newcashrb.Text;
da.Update(ds1, "Deals");
MessageBox.Show("The data you edited has been successfully updated in the database", "Data updated");
}
//12.this "if" is for "Purchase" and "Sum" fiels not empty, and "Credit" is selected -> Success//
else if (newpurchasetb.Text.Length > 0 && newsumtb.Text.Length > 0 && newcreditrb.Checked)
{
dRow2[1] = newpurchasetb.Text;
dRow2[2] = newsumtb.Text;
dRow2[3] = newcreditrb.Text;
da.Update(ds1, "Deals");
MessageBox.Show("The data you edited has been successfully updated in the database", "Data updated");
}
}
private void newsumtb_KeyPress(object sender, KeyPressEventArgs e)
{
if (!System.Text.RegularExpressions.Regex.IsMatch(e.KeyChar.ToString(), "\\d+"))
e.Handled = true;
}
}
}
Demodex is one of the parasitic face mites that occur on people
These parasites are found in the hair, normally found in greater numbers around the cheeks and foreheadWatch out !!!;)
These parasites are found in the hair, normally found in greater numbers around the cheeks and foreheadWatch out !!!;)
#10
Posted 28 January 2010 - 08:28 AM
deleted
Edited by Demodex, 28 January 2010 - 08:34 AM.
browser bug, pls delete this
Demodex is one of the parasitic face mites that occur on people
These parasites are found in the hair, normally found in greater numbers around the cheeks and foreheadWatch out !!!;)
These parasites are found in the hair, normally found in greater numbers around the cheeks and foreheadWatch out !!!;)
#11
Posted 28 January 2010 - 01:25 PM
Can you post the project itself zipped?
I'm still learning C# myself, but I'll try to see if I can point you in any direction.
I'm still learning C# myself, but I'll try to see if I can point you in any direction.
#12
Posted 28 January 2010 - 01:58 PM
Thanks :)
Here is my project.
I'd be happy to hear any other remarks beside the specific problem described.
Here is my project.
I'd be happy to hear any other remarks beside the specific problem described.
Attached Files
Demodex is one of the parasitic face mites that occur on people
These parasites are found in the hair, normally found in greater numbers around the cheeks and foreheadWatch out !!!;)
These parasites are found in the hair, normally found in greater numbers around the cheeks and foreheadWatch out !!!;)


Sign In
Create Account


Back to top










