hi all,
i am currently writing a program as my school homework. it used to work and when i changed the column name in my database, it won't save data to the database. i am currently using sql server 2005 and visual studio 2008 and c# language.
here is my code, is there anything wrong with my 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;
using System.Net;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Data.SqlClient;
using System.Threading;
using System.Net.NetworkInformation;
using System.IO;
namespace WinFrm_FitnessCentral_Ver1._0
{
public partial class Frm_UserRegistration : Form
{
public string Username, Password, FirstName, LastName, DOB, Address, Country, Email;
private int pingsSent;
AutoResetEvent resetEvent = new AutoResetEvent(false);
public Frm_UserRegistration()
{
InitializeComponent();
}
DateTime currentTime = DateTime.Now;
//private void button1_Click(object sender, EventArgs e)
//{
//DialogResult result = openFileDialog1.ShowDialog();
//if (result == DialogResult.OK)
//PhotoBox.ImageLocation = openFileDialog1.FileName;
//}
private void MetricCheckBox_CheckedChanged(object sender, EventArgs e)
{
if (MetricCheckBox.Checked == true)
{
CmLabel.Visible = true;
KgLabel.Visible = true;
PoundsLabel.Visible = false;
InchesLabel.Visible = false;
}
else
{
CmLabel.Visible = false;
KgLabel.Visible = false;
PoundsLabel.Visible = true;
InchesLabel.Visible = true;
}
}
private void Frm_UserRegistration_Load(object sender, EventArgs e)
{
ReadOnlyCollection<TimeZoneInfo> tzCollection;
tzCollection = TimeZoneInfo.GetSystemTimeZones();
this.TimeZoneCombo.DataSource = tzCollection;
TimeZoneInfo country = TimeZoneInfo.Local;
TimeZone localZone = TimeZone.CurrentTimeZone;
int currentYear = currentTime.Year;
DateTime currentUTC = localZone.ToUniversalTime(currentTime);
TimeSpan currentOffset = localZone.GetUtcOffset(currentTime);
if (TimeZoneCombo.SelectedItem.ToString() != country.ToString())
{
TimeZoneCombo.Text = country.ToString();
}
}
private void UsernameTextBox_TextChanged(object sender, EventArgs e)
{
this.Username = this.UsernameTextBox.Text.ToString();
}
private void PasswordTextBox_TextChanged(object sender, EventArgs e)
{
this.Password = this.PasswordTextBox.Text.ToString();
}
private void FirstNameTextBox_TextChanged(object sender, EventArgs e)
{
this.FirstName = this.FirstNameTextBox.Text.ToString();
}
private void LastNameTextBox_TextChanged(object sender, EventArgs e)
{
this.LastName = this.LastNameTextBox.Text.ToString();
}
private void DOBTextBox_TextChanged(object sender, EventArgs e)
{
this.DOB = this.DOBTextBox.Text.ToString();
}
private void HouseAddressTextBox_TextChanged(object sender, EventArgs e)
{
this.Address = this.HouseAddressTextBox.Text.ToString();
}
private void CountryTextBox_TextChanged(object sender, EventArgs e)
{
this.Country = this.CountryTextBox.Text.ToString();
}
private void EmailTextBox_TextChanged(object sender, EventArgs e)
{
this.Email = this.EmailTextBox.Text.ToString();
}
private void RegisterButton_Click(object sender, EventArgs e)
{
TimeZoneInfo selectedTimeZone = (TimeZoneInfo)this.TimeZoneCombo.SelectedItem;
pingsSent = 0;
Ping();
}
private void EraseButton_Click(object sender, EventArgs e)
{
UsernameTextBox.Text = "";
PasswordTextBox.Text = "";
FirstNameTextBox.Text = "";
LastNameTextBox.Text = "";
DOBTextBox.Text = "";
HouseAddressTextBox.Text = "";
CountryTextBox.Text = "";
EmailTextBox.Text = "";
}
private void Ping()
{
System.Net.NetworkInformation.Ping pingSender = new System.Net.NetworkInformation.Ping();
pingSender.PingCompleted += new PingCompletedEventHandler(pingSender_Complete);
byte[] packetData = Encoding.ASCII.GetBytes("--------------------------------");
PingOptions packetOptions = new PingOptions(50, true);
pingSender.SendAsync("175.16.227.57", 5000, packetData, packetOptions, resetEvent);
}
private void pingSender_Complete(object sender, PingCompletedEventArgs e)
{
if (e.Cancelled)
{
((AutoResetEvent)e.UserState).Set();
}
else if (e.Error != null)
{
((AutoResetEvent)e.UserState).Set();
}
else
{
PingReply pingResponse = e.Reply;
ShowPingResults(pingResponse);
}
}
public void ShowPingResults(PingReply pingResponse)
{
if (pingResponse == null)
{
MessageBox.Show("Network Connection is Down.");
}
else if (pingResponse.Status == IPStatus.Success)
{
SqlConnection Connection = new SqlConnection(Properties.Settings.Default.FitnessCentralDatabaseConnectionString);
Connection.Open();
SqlCommand InsertCommand = new SqlCommand
("INSERT INTO Customers (User_Name, Password, First_Name, Last_Name, Date_Of_Birth, Address, Country, Email_Address, LastUpdatedDate, CreationDate) VALUES ('" + this.Username + "','" + this.Password + "','" + this.FirstName + "','" + this.LastName + "','" + this.DOB + "','" + this.Address + "','" + this.Country + "','" + this.Email + "','" + DateTime.Now + "','" + DateTime.Now + "')",
Connection);
InsertCommand.ExecuteNonQuery();
Connection.Close();
MessageBox.Show("New Record Inserted. Please Check Table Data.");
}
else
{
StreamWriter Writer = new StreamWriter
("D:\\\\15122009\\\\WinFrm_FitnessCentral_Ver1.0CorrectedNetwork\\\\USBDeviceData.txt");
Writer.WriteLine(UsernameTextBox.Text);
Writer.WriteLine(PasswordTextBox.Text);
Writer.WriteLine(FirstNameTextBox.Text);
Writer.WriteLine(LastNameTextBox.Text);
Writer.WriteLine(DOBTextBox.Text);
Writer.WriteLine(HouseAddressTextBox.Text);
Writer.WriteLine(CountryTextBox.Text);
Writer.WriteLine(EmailTextBox.Text);
Writer.Close();
MessageBox.Show("Network Connection Timed Out.");
}
pingsSent++;
if (pingsSent < 1)
{
Ping();
}
}
}
}