Help need with Calculation

Hi guys.

I am using VS 2005 and I'm tryng my hand at C#. I have created an app with two forms/Tabs, one with employee details an the other with attendance details. My basic problem here is to get a few things calculated and sent to the DB. I'm using JET db (Access DB with two tables). On the attendance form I have the days that the guys worked which is populated by the user with 1 or 0. On the form I also have fields called Total days worked, Gross amount, Net amount. I basicaly need to calculate the total days worked and store that in the DB. I am totaly not sure how to do this. Below is the code I have writen. I need to calculate the days from the various days fields, send that to the DB and display that in the txtTotalDays field. I'm not sure which portions of the code to place here so I'm placing all of it. Any help would be greatly appreciated.

[code]
public partial class fclsMumble : Form
{
OleDbConnection m_cnADONetConnection = new OleDbConnection();
OleDbDataAdapter m_daDataAdapter;
OleDbDataAdapter m_ddDataAdapter;
DataTable m_dtEmployee = new DataTable();
DataTable m_dtDays = new DataTable();
int m_rowPosition = 0;
public fclsMumble()
{
InitializeComponent();
}

private void timer1_Tick(object sender, EventArgs e)
{
DateTime dtCurrentTime = DateTime.Now;
tlsStatus1.Text = dtCurrentTime.ToLongTimeString();
}

private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}




private void fclsMumble_Load(object sender, EventArgs e)
{
m_cnADONetConnection.ConnectionString =
@Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:Documents and SettingsmumblebDesktopC-SharpBernard MumbleEmployee.mdb;
m_cnADONetConnection.Open();
m_daDataAdapter =
new OleDbDataAdapter("Select * From [Employee]", m_cnADONetConnection);
OleDbCommandBuilder m_cbCommandBuilder =
new OleDbCommandBuilder(m_daDataAdapter);
m_ddDataAdapter =
new OleDbDataAdapter("Select * From Days", m_cnADONetConnection);
OleDbCommandBuilder m_cdCommandbuilder =
new OleDbCommandBuilder(m_ddDataAdapter);
m_daDataAdapter.Fill(m_dtEmployee);
m_ddDataAdapter.Fill(m_dtDays);
this.ShowCurrentRecord();
}
private void fclsMumble_FormClosing(object sender, FormClosingEventArgs e)
{
m_cnADONetConnection.Close();
m_cnADONetConnection.Dispose();
}
private void ShowCurrentRecord()
{
if (m_dtEmployee.Rows.Count == 0)
{
txtEmployeeName.Text = "";
txtEmployeeNumber.Text = "";
txtAddress1.Text = "";
txtArea.Text = "";
txtCity.Text = "";
txtHomePhone.Text = "";
txtMobile.Text = "";
txtPayRate.Text = "";
txtPostCode.Text = "";
txtEmpID.Text = "";
return;
}
txtEmployeeName.Text =
m_dtEmployee.Rows[m_rowPosition]["EmployeeName"].ToString();
txtEmployeeNumber.Text =
m_dtEmployee.Rows[m_rowPosition]["EmployeeNumber"].ToString();
txtAddress1.Text =
m_dtEmployee.Rows[m_rowPosition]["Address1"].ToString();
txtArea.Text =
m_dtEmployee.Rows[m_rowPosition]["Area"].ToString();
txtCity.Text =
m_dtEmployee.Rows[m_rowPosition]["City"].ToString();
txtHomePhone.Text =
m_dtEmployee.Rows[m_rowPosition]["HomePhone"].ToString();
txtMobile.Text =
m_dtEmployee.Rows[m_rowPosition]["Mobile"].ToString();
txtPayRate.Text =
m_dtEmployee.Rows[m_rowPosition]["PayRate"].ToString();
txtPostCode.Text =
m_dtEmployee.Rows[m_rowPosition]["PostCode"].ToString();
txtEmpID.Text =
m_dtEmployee.Rows[m_rowPosition]["EmpID"].ToString();
}
private void ShowRecord()
{
if (m_dtDays.Rows.Count == 0)
{
txtThurs1.Text = "";
txtThursday2.Text = "";
txtFriday1.Text = "";
txtFriday2.Text = "";
txtMonday1.Text = "";
txtMonday2.Text = "";
txtTuesday1.Text = "";
txtTuesday2.Text = "";
txtWednesday1.Text = "";
txtWednesday2.Text = "";
txtEmpName.Text = "";
txtEmpNumber.Text = "";
txtLoan.Text = "";
txtGrossAmount.Text = "";
txtNetAmount.Text = "";
txtTotalDays.Text = "";
return;
}
txtThurs1.Text =
m_dtDays.Rows[m_rowPosition]["Thurs1"].ToString();
txtThursday2.Text =
m_dtDays.Rows[m_rowPosition]["Thursday2"].ToString();
txtFriday1.Text =
m_dtDays.Rows[m_rowPosition]["Friday1"].ToString();
txtFriday2.Text =
m_dtDays.Rows[m_rowPosition]["Friday2"].ToString();
txtMonday1.Text =
m_dtDays.Rows[m_rowPosition]["Monday1"].ToString();
txtMonday2.Text =
m_dtDays.Rows[m_rowPosition]["Monday2"].ToString();
txtTuesday1.Text =
m_dtDays.Rows[m_rowPosition]["Tuesday1"].ToString();
txtTuesday2.Text =
m_dtDays.Rows[m_rowPosition]["Tuesday2"].ToString();
txtWednesday1.Text =
m_dtDays.Rows[m_rowPosition]["Wednesday1"].ToString();
txtWednesday2.Text =
m_dtDays.Rows[m_rowPosition]["Wednesday2"].ToString();
txtEmpName.Text =
m_dtDays.Rows[m_rowPosition]["EmpName"].ToString();
txtEmpNumber.Text =
m_dtDays.Rows[m_rowPosition]["EmpNumber"].ToString();
dateTimePicker1.Text =
m_dtDays.Rows[m_rowPosition]["DateWorked"].ToString();
txtLoan.Text =
m_dtDays.Rows[m_rowPosition]["Loan"].ToString();
txtNetAmount.Text =
m_dtDays.Rows[m_rowPosition]["NetAmount"].ToString();
txtGrossAmount.Text =
m_dtDays.Rows[m_rowPosition]["GrossAmount"].ToString();
txtTotalDays.Text =
m_dtDays.Rows[m_rowPosition]["TotalDays"].ToString();
}
private void btnMoveFirst_Click(object sender, EventArgs e)
{
//Move to the first row and show the data.
m_rowPosition = 0;
this.ShowCurrentRecord();
}

private void btnMovePrevious_Click(object sender, EventArgs e)
{
// If not at the first row, go back one row and show the record.
if (m_rowPosition != 0)
{
m_rowPosition = m_rowPosition - 1;
this.ShowCurrentRecord();
}

}

private void btnMoveNext_Click(object sender, EventArgs e)
{
//If not on the last row, advance one row and show record.
if (m_rowPosition < m_dtEmployee.Rows.Count - 1)
{
m_rowPosition = m_rowPosition + 1;
this.ShowCurrentRecord();
}
}

private void btnMoveLast_Click(object sender, EventArgs e)
{
//If there are any rows in the data table, move to the last and show the record
if (m_dtEmployee.Rows.Count != 0)
{
m_rowPosition = m_dtEmployee.Rows.Count - 1;
this.ShowCurrentRecord();
}

}

private void btnSave_Click(object sender, EventArgs e)
{
//If there is existing data, update it.
if (m_dtEmployee.Rows.Count != 0)
{
m_dtEmployee.Rows[m_rowPosition]["EmployeeName"] = txtEmployeeName.Text;
m_dtEmployee.Rows[m_rowPosition]["EmployeeNumber"] = txtEmployeeNumber.Text;
m_dtEmployee.Rows[m_rowPosition]["Address1"] = txtAddress1.Text;
m_dtEmployee.Rows[m_rowPosition]["Area"] = txtArea.Text;
m_dtEmployee.Rows[m_rowPosition]["City"] = txtCity.Text;
m_dtEmployee.Rows[m_rowPosition]["HomePhone"] = txtHomePhone.Text;
m_dtEmployee.Rows[m_rowPosition]["Mobile"] = txtMobile.Text;
m_dtEmployee.Rows[m_rowPosition]["PayRate"] = txtPayRate.Text;
m_dtEmployee.Rows[m_rowPosition]["PostCode"] = txtPostCode.Text;
m_dtEmployee.Rows[m_rowPosition]["EmpID"] = txtEmpID.Text;
m_daDataAdapter.Update(m_dtEmployee);

}
}

private void btnAddNew_Click(object sender, EventArgs e)
{
DataRow drNewRow = m_dtEmployee.NewRow();
drNewRow["EmployeeName"] = txtEmployeeName.Text;
drNewRow["EmployeeNumber"] = txtEmployeeNumber.Text;
drNewRow["Address1"] = txtAddress1.Text;
drNewRow["Area"] = txtArea.Text;
drNewRow["City"] = txtCity.Text;
drNewRow["HomePhone"] = txtHomePhone.Text;
drNewRow["Mobile"] = txtMobile.Text;
drNewRow["PayRate"] = txtPayRate.Text;
drNewRow["PostCode"] = txtPostCode.Text;
drNewRow["EmpID"] = txtEmpID.Text;
m_dtEmployee.Rows.Add(drNewRow);
m_daDataAdapter.Update(m_dtEmployee);
m_rowPosition = m_dtEmployee.Rows.Count - 1;
this.ShowCurrentRecord();
}

private void btnDelete_Click(object sender, EventArgs e)
{
//If there is data, delete the current row.
if (m_dtEmployee.Rows.Count != 0)
{
m_dtEmployee.Rows[m_rowPosition].Delete();
m_daDataAdapter.Update(m_dtEmployee);
m_rowPosition = 0;
this.ShowCurrentRecord();
}
}

private void btnMovFirst_Click(object sender, EventArgs e)
{
//Move to the first row and show the data.
m_rowPosition = 0;
this.ShowRecord();
}

private void btnMovPrevious_Click(object sender, EventArgs e)
{
// If not at the first row, go back one row and show the record.
if (m_rowPosition != 0)
{
m_rowPosition = m_rowPosition - 1;
this.ShowRecord();

}
}

private void btnMovNext_Click(object sender, EventArgs e)
{
//If not on the last row, advance one row and show record.
if (m_rowPosition < m_dtDays.Rows.Count - 1)
{
m_rowPosition = m_rowPosition + 1;
this.ShowRecord();
}

}

private void btnMovLast_Click(object sender, EventArgs e)
{
//If there are any rows in the data table, move to the last and show the record
if (m_dtDays.Rows.Count != 0)
{
m_rowPosition = m_dtDays.Rows.Count - 1;
this.ShowRecord();
}

}

private void btnDelete1_Click(object sender, EventArgs e)
{
//If there is data, delete the current row.
if (m_dtDays.Rows.Count != 0)
{
m_dtDays.Rows[m_rowPosition].Delete();
//m_ddDataAdapter.Update(m_dtDays);
m_ddDataAdapter.Update(m_dtDays);
m_rowPosition = 0;
this.ShowRecord();
}
}

private void btnSave1_Click(object sender, EventArgs e)
{
//If there is existing data, update it.
if (m_dtDays.Rows.Count != 0)
{
m_dtDays.Rows[m_rowPosition]["EmpName"] = txtEmpName.Text;
m_dtDays.Rows[m_rowPosition]["EmpNumber"] = txtEmpNumber.Text;
m_dtDays.Rows[m_rowPosition]["Thurs1"] = txtThurs1.Text;
m_dtDays.Rows[m_rowPosition]["Friday1"] = txtFriday1.Text;
m_dtDays.Rows[m_rowPosition]["Monday1"] = txtMonday1.Text;
m_dtDays.Rows[m_rowPosition]["Tuesday1"] = txtTuesday1.Text;
m_dtDays.Rows[m_rowPosition]["Wednesday1"] = txtWednesday1.Text;
m_dtDays.Rows[m_rowPosition]["Thursday2"] = txtThursday2.Text;
m_dtDays.Rows[m_rowPosition]["Friday2"] = txtFriday2.Text;
m_dtDays.Rows[m_rowPosition]["Monday2"] = txtMonday2.Text;
m_dtDays.Rows[m_rowPosition]["Tuesday2"] = txtTuesday2.Text;
m_dtDays.Rows[m_rowPosition]["Wednesday2"] = txtWednesday2.Text;
m_dtDays.Rows[m_rowPosition]["DateWorked"] = dateTimePicker1.Text;
m_dtDays.Rows[m_rowPosition]["Loan"] = txtLoan.Text;
m_dtDays.Rows[m_rowPosition]["TotalDays"] = txtTotalDays.Text;
//m_ddDataAdapter.Update(m_dtDays);
m_ddDataAdapter.Update(m_dtDays);
}

}

private void btnAdd1_Click(object sender, EventArgs e)
{
DataRow drNewDRow = m_dtDays.NewRow();
drNewDRow["EmpName"] = txtEmpName.Text;
drNewDRow["EmpNumber"] = txtEmpNumber.Text;
drNewDRow["Thurs1"] = txtThurs1.Text;
drNewDRow["Friday1"] = txtFriday1.Text;
drNewDRow["Monday1"] = txtMonday1.Text;
drNewDRow["Tuesday1"] = txtTuesday1.Text;
drNewDRow["Wednesday1"] = txtWednesday1.Text;
drNewDRow["Thursday2"] = txtThursday2.Text;
drNewDRow["Friday2"] = txtFriday2.Text;
drNewDRow["Monday2"] = txtMonday2.Text;
drNewDRow["Tuesday2"] = txtTuesday2.Text;
drNewDRow["Wednesday2"] = txtWednesday2.Text;
drNewDRow["DateWorked"] = dateTimePicker1.Text;
drNewDRow["Loan"] = txtLoan.Text;
drNewDRow["TotalDays"] = txtTotalDays.Text;
m_dtDays.Rows.Add(drNewDRow);
m_ddDataAdapter.Update(m_dtDays);
m_rowPosition = m_dtDays.Rows.Count - 1;
this.ShowRecord();

}

}
[/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories