Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10.  
  11. namespace Kadai03
  12. {
  13. public partial class FrmLogin : Form
  14. {
  15. private const string ADDRESFILE = @"Z:\WinPro\Lesson04\User.txt";
  16. public int flg = -1;
  17.  
  18. public FrmLogin()
  19. {
  20. InitializeComponent();
  21. }
  22.  
  23. private void btnLogin_Click(object sender, EventArgs e)
  24. {
  25. StreamReader sr = new StreamReader(ADDRESFILE);
  26. string line;
  27. if(txtUserID.Text != "" && txtPassWord.Text != "")
  28. {
  29. while ((line = sr.ReadLine()) != null)
  30. {
  31. string[] fields = line.Split(',');
  32.  
  33. if (txtUserID.Text == fields[0] && txtPassWord.Text == fields[1] && flg == -1)
  34. {
  35. if (txtUserID.Text == fields[0] && txtPassWord.Text == fields[1])
  36. {
  37. flg = 0;
  38. }
  39. }
  40. else if (txtUserID.Text != fields[0] && txtPassWord.Text != fields[1] && flg == -1)
  41. {
  42. flg = 1;
  43. }
  44. }
  45. if (flg == 0)
  46. {
  47. DialogResult = DialogResult.OK;
  48. }
  49. if (flg == 1)
  50. {
  51. MessageBox.Show("IDまたはパスワードが違います", "パスエラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
  52. }
  53. sr.Close();
  54. }
  55. else
  56. {
  57. MessageBox.Show("入力してください", "入力エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64. }
  65.  
  66. private void btnCancel_Click(object sender, EventArgs e)
  67. {
  68. DialogResult = DialogResult.Cancel;
  69. }
  70.  
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement