|
You do that through the database.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
is there a way to call thread.join to thread from the threadpool?
|
|
|
|
|
If you want to synchronize one of your threads with a queued worker item, I would suggest
you use an AutoResetEvent or ManualResetEvent object; the worker item could call its Set()
method, the interested thread could use its WaitOne().
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi,
I have created a window application. I have to provide security to it. I have to provide a login form with username and password. The username and password are present in the database. When i click the login button it should compare the username and password entered in the form with that in database and give access to the Window application that i first created. How to do it.
Please help
Nitin Raj Bidkikar
Nitin Raj Bidkikar
|
|
|
|
|
You just take the username and password from the windows form, have them be in the where clause of your query, if the query returns 1 row, then you let them log in. Simple enough.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I am writing a program that stores date, as fixed width data. The record is supposed to be 532 characters wrong. When I do the getRecordLength method it says that the record is 548 characters wrong. I looked at the file and its adding a strange character ( [], (, #, $, etc...) to each thing im writing. Why is it adding this and how do i get rid of this.
Thanks.
Kyle
Kyle Maldonado
|
|
|
|
|
Because your name is Kyle.
Could you post a small section of the code that is performing the write?
|
|
|
|
|
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
|
|
|
|
|
Anyone see anything wrong?
Kyle Maldonado
|
|
|
|
|
I guess from the code, your thing would be much easier to handle as a SQL (or simply a Database) task. Still, I have question: Why is it important the size you stated in your 1st post?
to avoid strange chars:
you can use streamwriter instead of binarywriter with proper encoding (eg.: Encoding.UTF-16 - as a parameter-) if you expect other than eng. characters.
cheers, geri
|
|
|
|
|
Its for a school project, we have to use a text file, using a fixed witdth. And we have to use binary.
Kyle Maldonado
|
|
|
|
|
still don't understand why to use a fixed size (do you mean fixed size, when you write fixed width?):
an idea to your code: it 's always useful to close your writer in a finally block like:
binarywriter.close();
|
|
|
|
|
When I say fixed size i mean that
NAMESIZE = 30
if (txtName.length < NAMESIZE)
{
txtName.PadRight(NAMESIZE).Substring(0,NAMESIZE);
}
so then all the records are the same size so its easier to pull data out.
(The above code was just written fast, may not be correct)
Kyle Maldonado
|
|
|
|
|
|
Hi,
from MSDN on BinaryWriter.Write Method (String):
"Writes a length-prefixed string to this stream in the current encoding of the BinaryWriter,
and advances the current position of the stream in accordance with the encoding used and the
specific characters being written to the stream"
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
In the code I have it create a form, then a button. The button is added to the newly created form. When the user clicks on the button I want it to run a function that includes closing the form. Can this be done?
|
|
|
|
|
Jordanwb wrote: Can this be done?
Of course it can be done...just a shot in the dark here...
maybe form.close();
A craft is an enemy if not well learned.
|
|
|
|
|
I know how to do that, but what I want to know is how to have the program catch the button being pressed.
|
|
|
|
|
Place the code to close the form between the curly braces.....
private void button1_Click(object sender, EventArgs e)
{
formwhatever.close();
}
This is fairly basic you know.
Maybe you need a beginners book ???
A craft is an enemy if not well learned.
|
|
|
|
|
Actually I found what I was looking for:
<br />
this.add_button.Click += new System.EventHandler(this.save_content);<br />
|
|
|
|
|
at least 3-4 articles popped up in "C# event handling" on Codeproject
It is worth the time reading through. 1-2 hour & you'll be fine....
|
|
|
|
|
You also need to wire your handler to the event, as in:
button.Click+=new EventHandler(button1_Clicked);
Make sure this line executes only once (you can do it where you create the Button).
In fact you can and often should program exactly the way Visual Designer does it for you
when you add a Control graphically; just have a look in the code generated by Visual itself!
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
That's actually how I found the needed code (looked at Visual's generated code)
|
|
|
|
|
There are alternatives, such as
- reading the documentation (MSDN, Google),
- reading some articles, maybe from CodeProject
- working your way through a book on either a programming language or Visual Studio.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I want to put a lot of Controls like Button or UserControl in one Form, and let it scrollable.
My question is if the number of Controls is 1000 or more, can it be tolerant when refresh the Form on a normal PC? or is there any tip on scrollable Form, like dealing with visible Controls only, i don't know~
anyway, thx for your reply!
http://chinajuanbob.spaces.live.com/
|
|
|
|