Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- namespace Kadai03
- {
- public partial class FrmLogin : Form
- {
- private const string ADDRESFILE = @"Z:\WinPro\Lesson04\User.txt";
- public int flg = -1;
- public FrmLogin()
- {
- InitializeComponent();
- }
- private void btnLogin_Click(object sender, EventArgs e)
- {
- StreamReader sr = new StreamReader(ADDRESFILE);
- string line;
- if(txtUserID.Text != "" && txtPassWord.Text != "")
- {
- while ((line = sr.ReadLine()) != null)
- {
- string[] fields = line.Split(',');
- if (txtUserID.Text == fields[0] && txtPassWord.Text == fields[1] && flg == -1)
- {
- if (txtUserID.Text == fields[0] && txtPassWord.Text == fields[1])
- {
- flg = 0;
- }
- }
- else if (txtUserID.Text != fields[0] && txtPassWord.Text != fields[1] && flg == -1)
- {
- flg = 1;
- }
- }
- if (flg == 0)
- {
- DialogResult = DialogResult.OK;
- }
- if (flg == 1)
- {
- MessageBox.Show("IDまたはパスワードが違います", "パスエラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- sr.Close();
- }
- else
- {
- MessageBox.Show("入力してください", "入力エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void btnCancel_Click(object sender, EventArgs e)
- {
- DialogResult = DialogResult.Cancel;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement