المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : 1st Post and Code snip so far



C# Programming
04-02-2009, 07:12 PM
Hi I'm Tim and this is my first post. I just started coding in C# a few days ago. I'm developing a piece of software to manage some things at work. If anyone here has a few minutes, can you go over my code so far and let me know if it looks solid and please please let me know if I'm doing anything that throws up "warning flags" as far as coding style etc? Thanks in advance!

2 Forms so far.

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.Collections;

namespace WindowsFormsApplication1
{



public partial class Form1 : Form
{
ArrayList vins = new ArrayList();

public Form1()
{
InitializeComponent();
}

public void CreateDataTable()
{
string s1 = "Date";
string s2 = "System.String";
DataTable dt = new DataTable();
dt.TableName = textBox1.Text;

while (s1!= "Stop")
{
DataColumn dc = new DataColumn();
dc.ColumnName = s1;
dc.Caption = dc.ColumnName;
dc.DataType = System.Type.GetType(s2);
dc.DefaultValue = null;
dt.Columns.Add(dc);

switch (s1)
{
case "Date":
s1 = "Member#";
s2 = "System.Int32";
break;
case "Member#":
s1 = "VIN#";
s2 = "System.Int32";
break;
case "VIN#":
s1 = "******** Name";
s2 = "System.String";
break;
case "******** Name":
s1 = "Address";
s2 = "System.String";
break;
case "Address":
s1 = "City";
s2 = "System.String";
break;
case "City":
s1 = "State";
s2 = "System.String";
break;
case "State":
s1 = "Zip";
s2 = "System.Int32";
break;
case "Zip":
s1 = "Phone";
s2 = "System.String";
break;
case "Phone":
s1 = "Fax";
s2 = "System.String";
break;
case "Fax":
s1 = "Email";
s2 = "System.String";
break;
case "Email":
s1 = "Stop";
break;
}
}
DataRow dr;
dr = CreateTableRow(dt);
}

public DataRow CreateTableRow(DataTable dtPass)
{
// Check VIN against DataTable
DataRow myRow;
myRow = dtPass.NewRow();
DateTime today = DateTime.Now;
string date;
int year = today.Year;
int month = today.Month;
int day = today.Day;
date = month + "\\" + day + "\\" + year;
// From Form1
myRow[0] = date;
myRow[1] = int.Parse(textBox1.Text);
myRow[2] = int.Parse(textBox2.Text); // Change to a while statement to add all vins in ArrayList and also call the VIN checking function

// From Form2
//dr[3] =
return myRow;
}

private void label1_Click(object sender, EventArgs e)
{

}

private void AddTruck()
{
try
{
if (textBox2.Text != null)
{
long vinNumber = long.Parse(textBox2.Text);
vins.Add(vinNumber);
textBox2.Text = "";
label3.Text = label3.Text + vinNumber + Environment.NewLine;
}
}
catch (FormatException)
{
textBox2.Text = "";
}
}

private void button1_Click(object sender, EventArgs e)
{
Form2 f = new Form2(this);
//f.Show(); // This shows Form2

AddTruck();
// CheckforDuplicateVin();

/*
* Check DB for Member#
* Check DB for duplicate VIN#
*
* If Member#.!Exist && !duplicateVin
* {
* Create DataTable for new member
* Open a form to fill in the ******** information
* Open the new DataTable
* Save the DataTable to the DataSheet/Database
* }
* Elseif Member#.Exist && !duplicateVin
* {
* Open DataTabel for current member
* Add new VIN to the DataSheet/Database
* }
* Else
* {
* Output duplicate VIN error message
* }
*/
}

private void OpenContactInfo()
{
//Open form 2
}
private void button2_Click(object sender, EventArgs e)
{
/* Check DB for an existing member
* If No, open Form2
* If Yes, Pull data from Data Table
* Do not open Form2
* Possibly open a Form for confirmation
*/

// Check ArrayList vin vs DB for a duplicate

// Edit the line below so that it only runs if the member is new

// If !ExistingMember
//{A
try // Edit this so that it catches non numerical character entry
{
if (textBox1.Text != null)
{

CreateDataTable();
// Call OpenContactInfo
}
}
catch (FormatException)
{
textBox1.Text = "";
}
//}A


}
}
}


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 WindowsFormsApplication1
{
public partial class Form2 : Form
{
Form1 f;

public Form2()
{
InitializeComponent();
}

public Form2(Form1 fr1)
{
InitializeComponent();
f = new Form1();
f = fr1;

}

private void Form2_Load(object sender, EventArgs e)
{

}
}
}