Click here to Skip to main content
15,881,693 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to Import database.mdf file in Visual Studio 2010 Project Pin
OriginalGriff12-Nov-19 0:46
mveOriginalGriff12-Nov-19 0:46 
GeneralRe: How to Import database.mdf file in Visual Studio 2010 Project Pin
Member 1464246912-Nov-19 18:28
Member 1464246912-Nov-19 18:28 
GeneralRe: How to Import database.mdf file in Visual Studio 2010 Project Pin
OriginalGriff12-Nov-19 20:44
mveOriginalGriff12-Nov-19 20:44 
Questionc++ DLL import in c# Pin
Member 1465244911-Nov-19 19:49
Member 1465244911-Nov-19 19:49 
AnswerRe: c++ DLL import in c# Pin
Richard MacCutchan11-Nov-19 21:12
mveRichard MacCutchan11-Nov-19 21:12 
GeneralRe: c++ DLL import in c# Pin
Member 1465244912-Nov-19 19:44
Member 1465244912-Nov-19 19:44 
GeneralRe: c++ DLL import in c# Pin
Richard MacCutchan12-Nov-19 22:09
mveRichard MacCutchan12-Nov-19 22:09 
QuestionCode not splitting for login form. C# Pin
Member 1465157011-Nov-19 1:10
Member 1465157011-Nov-19 1:10 
Hiya all, I'm trying to get my code to allow me to login with details from a .csv file. The code is not splitting correctly and therefore says the user and pass is incorrect. I'm wanting it to open a second form.
Any suggestions? Here's the code..

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace --------
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Label1_Click(object sender, EventArgs e)
        {

        }

        private void BtnLogin_Click(object sender, EventArgs e)
        {
            string Username = txtUsername.Text;
            string Password = txtPassword.Text;
            bool Found = false;

            string FilePath = "Login.csv";
            StreamReader fileReader = new StreamReader(FilePath);
            String[] details = File.ReadAllLines(FilePath);

            String[] splitted;
            foreach (string line in details)
            {
                splitted = line.Split(',');
                if (details[0] == Username && details[1] == Password)
                {
                    Found = true;
                }
            }
            if (Found == true)
            {
                Form2 Form2 = new Form2();
                Form2.Show();
                this.Hide();
            }
            else
            {
                AutoClosingMessageBox.Show("Incorrect Login Details Entered", "Error:", 5000);
            }
        }
    }
}
public class AutoClosingMessageBox
{
    System.Threading.Timer _timeoutTimer;
    string _caption;
    AutoClosingMessageBox(string text, string caption, int timeout)
    {
        _caption = caption;
        _timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
            null, timeout, System.Threading.Timeout.Infinite);
        using (_timeoutTimer)
            MessageBox.Show(text, caption);
    }
    public static void Show(string text, string caption, int timeout)
    {
        new AutoClosingMessageBox(text, caption, timeout);
    }
    void OnTimerElapsed(object state)
    {
        IntPtr mbWnd = FindWindow("#32770", _caption);
        if (mbWnd != IntPtr.Zero)
            SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
        _timeoutTimer.Dispose();
    }
    const int WM_CLOSE = 0x0010;
    [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
    static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
}

AnswerRe: Code not splitting for login form. C# Pin
phil.o11-Nov-19 1:19
professionalphil.o11-Nov-19 1:19 
AnswerRe: Code not splitting for login form. C# Pin
Richard MacCutchan11-Nov-19 1:32
mveRichard MacCutchan11-Nov-19 1:32 
GeneralRe: Code not splitting for login form. C# Pin
OriginalGriff11-Nov-19 1:32
mveOriginalGriff11-Nov-19 1:32 
GeneralRe: Code not splitting for login form. C# Pin
Richard MacCutchan11-Nov-19 1:50
mveRichard MacCutchan11-Nov-19 1:50 
AnswerRe: Code not splitting for login form. C# Pin
OriginalGriff11-Nov-19 1:32
mveOriginalGriff11-Nov-19 1:32 
NewsRe: Code not splitting for login form. C# Pin
Eddy Vluggen11-Nov-19 3:20
professionalEddy Vluggen11-Nov-19 3:20 
QuestionQuestion Pin
Member 1450924010-Nov-19 1:39
Member 1450924010-Nov-19 1:39 
QuestionRe: Question Pin
Richard MacCutchan10-Nov-19 1:44
mveRichard MacCutchan10-Nov-19 1:44 
AnswerRe: Question Pin
OriginalGriff10-Nov-19 1:48
mveOriginalGriff10-Nov-19 1:48 
AnswerRe: Question Pin
Eddy Vluggen10-Nov-19 1:51
professionalEddy Vluggen10-Nov-19 1:51 
QuestionHow to disable other buttons based on user role login Pin
Member 146022408-Nov-19 22:05
Member 146022408-Nov-19 22:05 
AnswerRe: How to disable other buttons based on user role login Pin
OriginalGriff8-Nov-19 22:30
mveOriginalGriff8-Nov-19 22:30 
AnswerRe: How to disable other buttons based on user role login Pin
Richard MacCutchan8-Nov-19 22:53
mveRichard MacCutchan8-Nov-19 22:53 
GeneralRe: How to disable other buttons based on user role login Pin
Mycroft Holmes9-Nov-19 10:21
professionalMycroft Holmes9-Nov-19 10:21 
GeneralRe: How to disable other buttons based on user role login Pin
OriginalGriff9-Nov-19 10:35
mveOriginalGriff9-Nov-19 10:35 
GeneralRe: How to disable other buttons based on user role login Pin
Richard MacCutchan9-Nov-19 20:53
mveRichard MacCutchan9-Nov-19 20:53 
GeneralRe: How to disable other buttons based on user role login Pin
Mycroft Holmes10-Nov-19 10:08
professionalMycroft Holmes10-Nov-19 10:08 

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.