Advertisement
khaiwen1111

Untitled

Jul 29th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.07 KB | None | 0 0
  1.   private void Button1_Click(object sender, EventArgs e)
  2.         {
  3.             update1();
  4.         }
  5.         private void update1()
  6.         {
  7.             string text = text = UpdatedArray();
  8.            
  9.             File.WriteAllText("account1.txt", text);
  10.         }
  11.      
  12.        public string UpdatedArray()
  13.         {
  14.             filelist = new string[LineNo];
  15.             row = GetRowNumber();
  16.            
  17.             int newbal; string strbal;
  18.             newbal = Convert.ToInt32(label3.Text) + Convert.ToInt32(textBox1.Text);
  19.             strbal = Convert.ToString(newbal);
  20.             string username = login.accountname;
  21.             TextReader sr = new StreamReader("account.txt");
  22.             string line = "";
  23.             bool found = false;
  24.             string text = File.ReadAllText("account.txt");
  25.             while ((line = sr.ReadLine()) != null)
  26.             {
  27.                 string[] components = line.Split(" ".ToCharArray());
  28.                 if (components.Contains(username))
  29.                 {
  30.                     found = true;
  31.                 }
  32.                 if(found == true)
  33.                 {
  34.                     string str, str1, str2;
  35.                     str = components[5];
  36.                     str1 = line.Replace(str, strbal);
  37.                     str2 = string.Join(" ", str1);
  38.                     text = text.Replace(filelist[row], str2);
  39.                 }
  40.             }
  41.             sr.Close();
  42.             return text;
  43.         }
  44.      
  45.         public int GetRowNumber()
  46.         {
  47.             string username = login.accountname;
  48.             TextReader sr = new StreamReader("account.txt");
  49.             bool found = false;
  50.             int i = 0;
  51.             while (i < LineNo && !found)
  52.             {
  53.                 filelist[i] = sr.ReadLine();
  54.                 if (filelist[i].Contains(username))
  55.                     found = true;
  56.                 else i++;
  57.             }
  58.             if (found == true)
  59.             {
  60.                 row = i;
  61.  
  62.                 sr.Close();
  63.             }
  64.  
  65.             return row;
  66.  
  67.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement