Example #1
0
 private void TBCode_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (!Char.IsNumber(e.KeyChar) && !Char.IsControl(e.KeyChar))
     {
         e.Handled = true;
     }
     if (e.KeyChar == (Char)Keys.Enter) // hoặc e.KeyChar == (Char)13 == Convert.ToInt32(e.KeyChar)
     {
         string t;
         if (TBCode.Text == "1806")
         {
             string     path = "E:\\.Net\\BaiTap.Net\\102190037.txt";
             FileStream fs   = new FileStream(path, FileMode.Open, FileAccess.Write);
             fs.Position = fs.Length;
             StreamWriter sw = new StreamWriter(fs);
             t = " ❉  " + DateTime.Now.ToString() + "                    " + "Access Granted";
             sw.WriteLine(" ❉  " + DateTime.Now.ToString() + "                    " + "Access Granted");
             sw.Flush();
             sw.Close();
             fs.Close();
         }
         else if (TBCode.Text.Length == 1)
         {
             string     path = "E:\\.Net\\BaiTap.Net\\102190037.txt";
             FileStream fs   = new FileStream(path, FileMode.Open, FileAccess.Write);
             fs.Position = fs.Length;
             StreamWriter sw = new StreamWriter(fs);
             t = " ✥  " + DateTime.Now.ToString() + "                    " + "Restricted Access";
             sw.WriteLine(" ✥  " + DateTime.Now.ToString() + "                    " + "Restricted Access");
             sw.Flush();
             sw.Close();
             fs.Close();
         }
         else
         {
             string     path = "E:\\.Net\\BaiTap.Net\\102190037.txt";
             FileStream fs   = new FileStream(path, FileMode.Open, FileAccess.Write);
             fs.Position = fs.Length;
             StreamWriter sw = new StreamWriter(fs);
             t = " ✤  " + DateTime.Now.ToString() + "                    " + "Access Denied";
             sw.WriteLine(" ✤  " + DateTime.Now.ToString() + "                    " + "Access Denied");
             sw.Flush();
             sw.Close();
             fs.Close();
         }
         LB1.Items.Add(t);
         TBCode.Clear();
     }
 }
Example #2
0
        private void BTEnter_Click(object sender, EventArgs e)
        {
            string t;

            if (TBCode.Text == "1806")
            {
                string     path = "E:\\.Net\\BaiTap.Net\\102190037.txt";
                FileStream fs   = new FileStream(path, FileMode.Open, FileAccess.Write);
                fs.Position = fs.Length;
                StreamWriter sw = new StreamWriter(fs);
                t = " ❉  " + DateTime.Now.ToString() + "                    " + "Access Granted";
                sw.WriteLine(" ❉  " + DateTime.Now.ToString() + "                    " + "Access Granted");
                sw.Flush();
                sw.Close();
                fs.Close();
            }
            else if (TBCode.Text.Length == 1)
            {
                string     path = "E:\\.Net\\BaiTap.Net\\102190037.txt";
                FileStream fs   = new FileStream(path, FileMode.Open, FileAccess.Write);
                fs.Position = fs.Length;
                StreamWriter sw = new StreamWriter(fs);
                t = " ✥  " + DateTime.Now.ToString() + "                    " + "Restricted Access";
                sw.WriteLine(" ✥  " + DateTime.Now.ToString() + "                    " + "Restricted Access");
                sw.Flush();
                sw.Close();
                fs.Close();
            }
            else
            {
                string     path = "E:\\.Net\\BaiTap.Net\\102190037.txt";
                FileStream fs   = new FileStream(path, FileMode.Open, FileAccess.Write);
                fs.Position = fs.Length;
                StreamWriter sw = new StreamWriter(fs);
                t = " ✤  " + DateTime.Now.ToString() + "                    " + "Access Denied";
                sw.WriteLine(" ✤  " + DateTime.Now.ToString() + "                    " + "Access Denied");
                sw.Flush();
                sw.Close();
                fs.Close();
            }
            LB1.Items.Add(t);
            TBCode.Clear();
        }