|
Yes, I thought in that way but .... I want to know when they are disconnected ... my question really here.... How do I know when one client is disconneted.
Thank you man.
|
|
|
|
|
here, when i Click a button then connect to Database server and program run properly
|
|
|
|
|
In button click event, write connection string. this will lead to connect to your database. which database you are using?
|
|
|
|
|
Rahad
Will you PLEASE go and buy a book on C# and database programming, work through it and come back when you can ask an intelligent question.
|
|
|
|
|
Dont you go round encouraging him now!
var question = (_2b || !(_2b));
|
|
|
|
|
I did check his history before I became 'encouraging', there seems to be a rash of teach me programming, build my database type post today.
|
|
|
|
|
Hi, I've written the WorkbookEvents_SheetCalculateEventHandler event to trigger for recalculation in Excel.
public event Excel.WorkbookEvents_SheetCalculateEventHandler SheetCalculate;
SheetCalculate = new Excel.WorkbookEvents_SheetCalculateEventHandler( ThisWorkbook_SheetCalculate);
The function Workbook_SheetCalculate(object Sh) triggers when there is a formula change in the excel sheet.
My aim is to read the function result from the Sh object.
for example, if A1=15, A2=17 and A3=SUM(A1,A2)
Workbook_SheetCalculate fires as soon as there is change in A1 or A2. I need to read the function result,32. Please guide me to get the value.
Thanks in advance.
|
|
|
|
|
Hello
In my application i am having a datagridview with a combobox column
and the data in the combobox is binded with a company table in database.
and the display member field is binded with column "Company Name" and
the Value field is binded with column "Company Id".
When i click on the save button i like to save the selected display
member and also the value field.
Plz tell me how i can do this...
Thanks in advance...
|
|
|
|
|
Hi I've few Java code and want to convert exact C# code can anybody help me out?
public static String calculateRFC2104HMAC(String data, String key, String signatureMethod)
throws SignatureException
{
String result = "";
try
{
SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), signatureMethod);
Mac mac = Mac.getInstance(signatureMethod);
mac.init(signingKey);
byte rawHmac[] = mac.doFinal(data.getBytes());
result = Base64.encodeBytes(rawHmac);
}
catch(Exception e)
{
throw new SignatureException("Failed to generate HMAC : " + e.getMessage());
}
return result;
}
|
|
|
|
|
|
Hi,
What I am trying to achieve is that in the winforms application I am creating (a journal one), it allows multiple users to register/login and add/edit/delete their entries, my questions are:
1. How do I create the application that allows different users to login?
2. Once logged in, how will the application know which user is which and to update the logged in user's particular entries?
Like in PHP you can use sessions do this easily, but how to do it in C#?
I have created a simple register and login form right now, but the difference of user is my problem, I am using the SqlceDataReader but I can only login with the last user that exists in the DB and if a change that user's password, every user's password in the db is changed to that particular password. Is it better to use datasets?
Here are the relevant bits from my code for both winforms:
Main form:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlServerCe;
[STAThread]
static void Main()
{
MainForm frmLogin = new MainForm();
frmLogin.ShowDialog();
}
private void btnLogin_Click(object sender, System.EventArgs e)
{
if (txtuser.Text.Equals(""))
{
MessageBox.Show("Please Enter User Name", "Organiser", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (txtpwd.Text.Equals(""))
{
MessageBox.Show("Please Enter Password", "Organiser", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
int count = 0;
con = new SqlCeConnection();
con.ConnectionString = "Data Source=Database.sdf";
com = new SqlCeCommand("select * from [User]", con);
con.Open();
if (con.State == ConnectionState.Open)
{
SqlCeDataReader dtr = com.ExecuteReader();
while (dtr.Read())
{
us = dtr["username"].ToString();
ps = dtr["password"].ToString();
if (us == txtuser.Text && ps == txtpwd.Text)
{
count = 1;
}
else count = 2;
}
}
if (count == 1)
{
MessageBox.Show("Login successful " + us, "Login", MessageBoxButtons.OK, MessageBoxIcon.Information);
ChangePassword pass = new ChangePassword();
pass.ShowDialog();
}
else if (count == 2)
{
MessageBox.Show("WRONG USER NAME OR PASSWORD ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnRegister_Click(object sender, System.EventArgs e)
{
this.Close();
this.Dispose();
RegisterUser reg = new RegisterUser();
reg.ShowDialog();
}
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
this.Dispose();
Application.Exit();
}
private void MainForm_Load(object sender, EventArgs e)
{
}
private void MainForm_Load_1(object sender, EventArgs e)
{
}
}
}
For changing password:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlServerCe;
private void btnCancel_Click(object sender, System.EventArgs e)
{
this.Close();
this.Dispose();
}
private void btnSave_Click(object sender, System.EventArgs e)
{
MainForm mf = new MainForm();
int count = 0;
string connectionString = "Data Source=..\\..\\Database.sdf";
SqlCeConnection conn = new SqlCeConnection(connectionString);
conn.Open();
if (conn.State == ConnectionState.Open)
{
SqlCeCommand com;
com = new SqlCeCommand("select * from [User]", conn);
SqlCeDataReader dtr = com.ExecuteReader();
while (dtr.Read())
{
string pass = dtr["password"].ToString();
username = dtr["username"].ToString();
password = txtNew.Text;
if (pass == txtOld.Text)
{
count = 1;
string query = "UPDATE [User] SET password = '" + password + "' WHERE username = '" + username + "'";
try
{
SqlCeCommand myCommand1 = new SqlCeCommand();
myCommand1.CommandText = query;
myCommand1.Connection = conn;
myCommand1.ExecuteNonQuery();
MessageBox.Show(username +"'s password changed to " + password, "Password change", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Problem.");
}
} else count = 2;
if (count == 2)
{
MessageBox.Show("WRONG USER NAME OR PASSWORD ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
conn.Close();
}
}
}
Thanks
|
|
|
|
|
Hi,
first of all a question: Do you want to build a Windows Forms Application or an ASP.NET application (because PHP is web-based as ASP.NET is). When you use ASP.NET you got a session object, just like in PHP.
Second: The way you validate username and password is not really the safest one. I suggest using a query within a prepared-statement, passing the username and passwords as statements.
Regards
Sebastian
|
|
|
|
|
SeMartens wrote:
Second: The way you validate username and password is not really the safest one.
Safest? It's flawed badly!
Of course you can only log in as the last user in the db, because that's when your while loop ends.
Even when and if your username and password is correct for some other user, and you set the count variable to 1, the next time the loop.. .erm... loops it will change it back to 2. Unless it's the last record.
To the author:
But yeah, the way you do it is really ugly, though. Imagine you had 500k users. Would you put all the records in the memory then, and iterate through them?
Ever heard of the "WHERE" clause for T-Sql? ;>
var question = (_2b || !(_2b));
|
|
|
|
|
Haha, its only in the early stages of development lads, just like I am a novice at this.
Could you guys provide me with examples as to how I can do it better.
PS. I am creating a winforms application only, no ASP.NET or nothing. Its a standalone app.
Thanks
|
|
|
|
|
An Enigma wrote: 2. Once logged in, how will the application know which user is which and to update the logged in user's particular entries?
Well this part sort of says: "I can't tell the difference between a winform and a webform", with all due respect.
Each instance of your "application" will have to be installed on each computer you will ever want to use it on, right? Then when you log in, just keep your user id, name, or shoe-size in a global variable than you can access later.
Bah, go crazy, make it a static!
And use it in your PARAMETERIZED queries in the WHERE clause ;>
What's your ChangePassword class supposed to do, again?
var question = (_2b || !(_2b));
|
|
|
|
|
Woah, this is too much unknown info for me there mate.
The change password class changes the password for the user logged in.
Are there any examples I can look at for what you are saying?
|
|
|
|
|
|
First up split the database connection and authentication of the application out from the authentication of the users.
Create a SQL standard login for you app. Now you application has na identity that it can use to connect to the database regardless of the user.
Create your own user table where you store all the data to authenticate you users (userid, password - encrypted, expiry date and any groups he user may belong to in your app, email, names, address, phones, etc etc)
You login form can now talk to your database (using it's own ID) and query the user table to check the userid and password, if the login is valid then pass the user to the main form.
I think there is an example login project here on CP if you search for it.
|
|
|
|
|
Thanks for the reply Mycroft.
The way you described it in your post sounds like what I am looking for, would you know the name of the project?
Thanks
|
|
|
|
|
Heres a little light reading[^] for you.
It is after all a fairly large and critical area of developing. try wandering through some of these articles and pick the ones most relevant to you.
|
|
|
|
|
Hi all
i have a c# application on minimizing i place it into the system tray.now when the application is in the system tray and the user shutdown the system a log file should be written into a temp folder in c:\ i tried using onshutdown() it is not working, it would be better to say i dont know how to use it in my application plz help me
|
|
|
|
|
Handle the form's closing event. FormClosingEventArgs has a CloseReason property. If it is CloseReason.WindowsShutDown , write log file.
|
|
|
|
|
thanks a lot. it works fine
|
|
|
|
|
Hey, im working on a project and i have to get the name(header text) of selected column in my listbox or textbox from datagridview, when i select any column it shows the name of that column in textbox or listbox.. i'll be very thankful to if you guys kindly help me out in this matter..
im trying to use the code on DataGridViewHeaderClickEvent
"textBox1.Text=dataGridView1.SelectedColumns.ToString();"
|
|
|
|
|
Try this
private void dgData_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
string s = (sender as DataGridView).Columns[e.ColumnIndex].HeaderText;
}
|
|
|
|