Click here to Skip to main content
15,887,477 members
Home / Discussions / C#
   

C#

 
QuestionSmall Dialogs - How Small Can I Go ?? Pin
iltallman6-Feb-11 9:12
iltallman6-Feb-11 9:12 
AnswerRe: Small Dialogs - How Small Can I Go ?? Pin
dan!sh 6-Feb-11 10:03
professional dan!sh 6-Feb-11 10:03 
AnswerRe: Small Dialogs - How Small Can I Go ?? [modified] Pin
RobCroll7-Feb-11 1:52
RobCroll7-Feb-11 1:52 
GeneralRe: Small Dialogs - How Small Can I Go ?? Pin
iltallman7-Feb-11 12:31
iltallman7-Feb-11 12:31 
AnswerRe: Small Dialogs - How Small Can I Go ?? Pin
#realJSOP7-Feb-11 2:33
mve#realJSOP7-Feb-11 2:33 
QuestionC# Object reference not set to an instance of an object Pin
LAPEC6-Feb-11 8:45
LAPEC6-Feb-11 8:45 
AnswerRe: C# Object reference not set to an instance of an object Pin
fjdiewornncalwe6-Feb-11 8:56
professionalfjdiewornncalwe6-Feb-11 8:56 
GeneralRe: C# Object reference not set to an instance of an object Pin
LAPEC6-Feb-11 10:31
LAPEC6-Feb-11 10:31 
Hi Marcus

Here is the full code of login button click event...

public partial class ClientLogin : Window
{
    public Client client = new Client();

    OleDbConnection conn = new OleDbConnection();
    OleDbDataAdapter dtAdapter = new OleDbDataAdapter();
    OleDbCommand command = new OleDbCommand();
    OleDbDataReader dataReader;// = new OleDbDataReader();

    //public TextBox txtIPaddress = new System.Windows.Controls.TextBox();
    //public TextBox txtPortNumber = new System.Windows.Controls.TextBox();

    public ClientLogin()
    {
        InitializeComponent();
        conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\AP_AE\Desktop\DTPOS_ClientServer\DataBase\DtposMenu.accdb";
        //command.CommandText.ToString();
    }

    public void infoChecker(Client formOne)
    {
        this.client = formOne;
        this.Show();
    }

    // IsNumeric Function
    static bool IsNumeric(object Expression)
    {
        // Variable to collect the Return value of the TryParse method.
        bool isNum;

        // Define variable to collect out parameter of the TryParse method. If the conversion fails, the out parameter is zero.
        double retNum;

        // The TryParse method converts a string in a specified style and culture-specific format to its double-precision floating point number equivalent.
        // The TryParse method does not generate an exception if the conversion fails. If the conversion passes, True is returned. If it does not, False is returned.
        isNum = Double.TryParse(Convert.ToString(Expression), System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out retNum);
        return isNum;
    }

    private void btnLogin_Click(object sender, RoutedEventArgs e)
    {
        // Using Try-Catch-Finally block structure
        try
        {
            if (IsNumeric(txtUserId.Text) & IsNumeric(txtPassword.Text))
            {
                // Open database connection
                conn.Open();
                // Set SQL select command to check User_ID and User_Password
                dtAdapter.SelectCommand.CommandText = "SELECT * FROM Users WHERE ID = '" + txtUserId.Text + "' AND Password = '" + txtPassword.Text + "'";
                dataReader = dtAdapter.SelectCommand.ExecuteReader();
                dataReader.Read();

                MessageBox.Show(" - You Have Loged In As: - " + dataReader["Access Level"].ToString() + "\n" + "\n" + " - Welcome " + dataReader["Name"].ToString() + "\n" + "\n" + " - To DTPOS - Point Of Sale System ", "Login Successful", MessageBoxButton.OK, MessageBoxImage.Information);
                UserLoginModule.UserAccessLevel = dataReader["Access Level"].ToString();
                UserLoginModule.UserFullName = dataReader["Name"].ToString();

                //ToDo: Error processing original source shown below
                //--^--- Unexpected pre-processor directive
                this.client.startServer(txtIpAddress.Text.ToString().Trim(), Convert.ToInt32(txtPortNumber.Text.ToString().Trim()), Convert.ToInt32(txtUserId.Text.ToString().Trim()), Convert.ToInt32(txtPassword.Text.ToString().Trim()));
                // Always call Close when done reading.
                if ((dataReader != null))
                {
                    dataReader.Close();
                }
                this.Close();

            }
            else
            {
                MessageBox.Show("You must enter data in order to proceed further. Please try again...", "Error: Non Data Entry", MessageBoxButton.OK, MessageBoxImage.Information);
                txtUserId.Focus();
            }
            // Display error if unable to open database
        }
        catch (System.Data.OleDb.OleDbException exception)
        {
            MessageBox.Show(exception.StackTrace);
            MessageBox.Show(exception.ToString(), "Unable to open database!");
            // Display message box when invalid operation
        }
        catch (InvalidOperationException invalidOperationException)
        {
            MessageBox.Show(invalidOperationException.Message, "An Invalid Operation Exception");
        }
        finally
        {
            // Close database connection when done with it
            if ((conn.State == ConnectionState.Open))
            {
                conn.Close();
            }
        }
        this.Close();
    }


kind regards

lapeci
GeneralRe: C# Object reference not set to an instance of an object Pin
RobCroll7-Feb-11 2:12
RobCroll7-Feb-11 2:12 
GeneralRe: C# Object reference not set to an instance of an object Pin
Rob Philpott7-Feb-11 3:51
Rob Philpott7-Feb-11 3:51 
AnswerRe: C# Object reference not set to an instance of an object Pin
Luc Pattyn6-Feb-11 9:15
sitebuilderLuc Pattyn6-Feb-11 9:15 
AnswerRe: C# Object reference not set to an instance of an object Pin
dan!sh 6-Feb-11 10:07
professional dan!sh 6-Feb-11 10:07 
QuestionObtain the path and save the file. Pin
sososm6-Feb-11 2:45
sososm6-Feb-11 2:45 
AnswerRe: Obtain the path and save the file. Pin
OriginalGriff6-Feb-11 2:52
mveOriginalGriff6-Feb-11 2:52 
GeneralRe: Obtain the path and save the file. Pin
sososm6-Feb-11 5:39
sososm6-Feb-11 5:39 
AnswerRe: Obtain the path and save the file. Pin
Abhinav S6-Feb-11 6:10
Abhinav S6-Feb-11 6:10 
QuestionError: "Could not use"file name"; file already in use." [SOLVED] Pin
Marat Beiner5-Feb-11 22:26
Marat Beiner5-Feb-11 22:26 
AnswerRe: Error: "Could not use"file name"; file already in use." Pin
Elham M5-Feb-11 23:06
Elham M5-Feb-11 23:06 
AnswerRe: Error: "Could not use"file name"; file already in use." Pin
OriginalGriff5-Feb-11 23:10
mveOriginalGriff5-Feb-11 23:10 
GeneralRe: Error: "Could not use"file name"; file already in use." Pin
Marat Beiner5-Feb-11 23:18
Marat Beiner5-Feb-11 23:18 
GeneralRe: Error: "Could not use"file name"; file already in use." Pin
OriginalGriff5-Feb-11 23:24
mveOriginalGriff5-Feb-11 23:24 
GeneralRe: Error: "Could not use"file name"; file already in use." Pin
Marat Beiner5-Feb-11 23:30
Marat Beiner5-Feb-11 23:30 
GeneralRe: Error: "Could not use"file name"; file already in use." Pin
OriginalGriff5-Feb-11 23:32
mveOriginalGriff5-Feb-11 23:32 
GeneralRe: Error: "Could not use"file name"; file already in use." Pin
Marat Beiner5-Feb-11 23:37
Marat Beiner5-Feb-11 23:37 
GeneralRe: Error: "Could not use"file name"; file already in use." Pin
OriginalGriff5-Feb-11 23:42
mveOriginalGriff5-Feb-11 23:42 

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.