Click here to Skip to main content
15,902,445 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to create and implement triggers in C#.NET Pin
Paul Conrad8-Dec-07 5:36
professionalPaul Conrad8-Dec-07 5:36 
Questionthread question Pin
poqeqw29-Nov-07 18:24
poqeqw29-Nov-07 18:24 
AnswerRe: thread question Pin
Luc Pattyn30-Nov-07 1:02
sitebuilderLuc Pattyn30-Nov-07 1:02 
QuestionHow to create a login form Pin
Nitin Raj29-Nov-07 17:57
Nitin Raj29-Nov-07 17:57 
AnswerRe: How to create a login form Pin
Paul Conrad29-Nov-07 18:12
professionalPaul Conrad29-Nov-07 18:12 
Questionwriting to a text file Pin
Kyle Maldonado29-Nov-07 17:36
Kyle Maldonado29-Nov-07 17:36 
AnswerRe: writing to a text file Pin
PIEBALDconsult29-Nov-07 17:46
mvePIEBALDconsult29-Nov-07 17:46 
GeneralRe: writing to a text file Pin
Kyle Maldonado29-Nov-07 17:51
Kyle Maldonado29-Nov-07 17:51 
this is the code


clsContact myData = new clsContact();
string Filename = "Employee.dat";
int flag;

string State = cboState.Text;
string Country = cboCountry.Text;
string Birthday = txtBdayMonth.Text + '/' + txtBdayDay.Text + '/' + txtBdayYear.Text;
string Anniversary = txtAnnMonth.Text + '/' + txtAnnDay.Text + '/' + txtAnnYear.Text;
string HomePhone = txtHAreaCode.Text + '-' + txtHPrefix.Text + '-' + txtHLast.Text;
string CellPhone = txtCAreaCode.Text + '-' + txtCPrefix.Text + '-' + txtCLast.Text;
string EmployeePictureFile = txtLName.Text + txtFName.Text + ".jpg";

myData.FirstName = txtFName.Text;
myData.LastName = txtLName.Text;
myData.MI = txtMI.Text;
myData.SSN = txtSSN.Text;
myData.AddressLine1 = txtAddressLine1.Text;
myData.AddressLine2 = txtAddressLine2.Text;
myData.Zip = txtZip.Text;
myData.OfficeExtension = txtOfficeExt.Text;
myData.Email = txtEmail.Text;
myData.Spouse = txtSpouse.Text;
myData.Department = cboDepartment.Text;
myData.State = cboState.Text;
myData.Country = cboCountry.Text;
myData.City = txtCity.Text;
myData.Birthday = Birthday;
myData.Anniversary = Anniversary;
myData.HomePhoneNumber = HomePhone;
myData.CellPhoneNumber = CellPhone;
myData.EmployeePictureFile = EmployeePictureFile;

BinaryWriter bw = null;
if (!validation())
{
return;
}

myData.FileName = Filename;
flag = myData.Create(Filename);
if (flag == 0) //An error
{
return;
}
{
{
try
{
int recs = (int)myData.getRecordCount();
//getInputValues();
myData.WriteOneRecord(recs);
}
catch (Exception ex)
{
MessageBox.Show("Error saving contact" + contact.FileName + ex.Message);
}
finally
{
if (bw != null)
{
bw.Close();
}
}
lstContacts.Items.Add(myData.LastName + "\t" + myData.FirstName);
contact = null;
}
}
}



and its calling these methods from a class


public long getRecordCount()
{
long records = 0;
long remainder;

try
{
if (myFile != null)
{
// Position the file pointer
records = myFile.Seek(0, SeekOrigin.End);
}
}
catch (IOException ex)
{
errorMessage = ex.Message;
return 0;
}
// See if there is a partial record
remainder = records % RECORDSIZE;
// Calculate the records
records = records / RECORDSIZE;
// If there was a partial record...
if (remainder > 0)
// ...up the counter to account for it.
records++;

return records;
}



and



public int WriteOneRecord(int num)
{
int errorFlag = 1;

try
{

if (myFile != null && bw != null)
{
//Postions the file pointer
myFile.Seek(num * RECORDSIZE, SeekOrigin.Begin);
bw.Write(LastName);
bw.Write(FirstName);
bw.Write(MI);
bw.Write(SSN);
bw.Write(AddressLine1);
bw.Write(AddressLine2);
bw.Write(City);
bw.Write(State);
bw.Write(Country);
bw.Write(Zip);
bw.Write(HomePhoneNumber);
bw.Write(CellPhoneNumber);
bw.Write(OfficeExtension);
bw.Write(Department);
bw.Write(Email);
bw.Write(Spouse);
bw.Write(Birthday);
bw.Write(Anniversary);
bw.Write(EmployeePictureFile);
}
}
catch (IOException ex)
{
errorMessage = ex.Message; //In case they want to view it
errorFlag = 0;
}
return errorFlag;
}

Thanks for the help in advance

Kyle Maldonado

GeneralRe: writing to a text file Pin
Kyle Maldonado29-Nov-07 18:24
Kyle Maldonado29-Nov-07 18:24 
GeneralRe: writing to a text file Pin
gericooper29-Nov-07 20:19
gericooper29-Nov-07 20:19 
GeneralRe: writing to a text file Pin
Kyle Maldonado29-Nov-07 20:21
Kyle Maldonado29-Nov-07 20:21 
GeneralRe: writing to a text file Pin
gericooper29-Nov-07 20:32
gericooper29-Nov-07 20:32 
GeneralRe: writing to a text file Pin
Kyle Maldonado29-Nov-07 20:35
Kyle Maldonado29-Nov-07 20:35 
GeneralRe: writing to a text file Pin
PIEBALDconsult30-Nov-07 3:35
mvePIEBALDconsult30-Nov-07 3:35 
GeneralRe: writing to a text file Pin
Luc Pattyn30-Nov-07 1:08
sitebuilderLuc Pattyn30-Nov-07 1:08 
QuestionHow to have program respond to code created button Pin
Jordanwb29-Nov-07 15:13
Jordanwb29-Nov-07 15:13 
AnswerRe: How to have program respond to code created button Pin
MickCurley29-Nov-07 15:27
MickCurley29-Nov-07 15:27 
GeneralRe: How to have program respond to code created button Pin
Jordanwb29-Nov-07 15:29
Jordanwb29-Nov-07 15:29 
GeneralRe: How to have program respond to code created button Pin
MickCurley29-Nov-07 15:42
MickCurley29-Nov-07 15:42 
GeneralRe: How to have program respond to code created button Pin
Jordanwb29-Nov-07 15:51
Jordanwb29-Nov-07 15:51 
GeneralRe: How to have program respond to code created button Pin
gericooper29-Nov-07 20:24
gericooper29-Nov-07 20:24 
AnswerRe: How to have program respond to code created button Pin
Luc Pattyn29-Nov-07 15:51
sitebuilderLuc Pattyn29-Nov-07 15:51 
GeneralRe: How to have program respond to code created button Pin
Jordanwb30-Nov-07 2:49
Jordanwb30-Nov-07 2:49 
GeneralRe: How to have program respond to code created button Pin
Luc Pattyn30-Nov-07 2:59
sitebuilderLuc Pattyn30-Nov-07 2:59 
QuestionQuestion about the number of Controls in a Form Pin
chinajuanbob29-Nov-07 14:34
chinajuanbob29-Nov-07 14:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.