Java Programming
Would you like to react to this message? Create an account in a few clicks or log in to continue.


here you can ask help for your java related problems
 
HomeLatest imagesSearchRegisterLog in

 

 read file from notepad using c#

Go down 
AuthorMessage
Ak
Java Freak
Java Freak
Ak


Posts : 23
Join date : 2009-02-07

read file from notepad using c# Empty
PostSubject: read file from notepad using c#   read file from notepad using c# EmptyThu Feb 16, 2012 4:58 am

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;

namespace FileHandling
{
    class Sample
    {
        public static void Main(String[] args)
        {
           
            string day = null, line ,empname = null, empid = null, emplvl = null , getid;
            StreamReader file = new StreamReader("employee.txt");
            string[] login;
            string[] logout;
            bool idnotfound = true;
            double loginmin, loginhour, logoutmin, logouthour, tmin = 0.00, thour = 0.00, week = 0.00;
            int level;
            double gross = 0.00 , rate = 0.00;
            Console.BackgroundColor = ConsoleColor.DarkGreen;
            if (File.Exists("employee.txt"))
            {           
                Console.Write("Enter Employee ID: ");
                getid = Console.ReadLine();
             
                while ((line = file.ReadLine()) != null)
                {
                    String[] strline = Regex.Split(line , ",");
                    empname = strline[0];
                    empid = strline[1];
                    emplvl = strline[2];
                    if (empid.Equals(getid))
                    {
                        idnotfound = false;
                        break;
                    }
                }
                if (idnotfound == true)
                    Console.WriteLine("ID not found!");
            }
            else
            {
                Console.WriteLine("File not found");
            }
            if (idnotfound == false)
            {
                Console.WriteLine("Employee Name: " + empname);
                Console.WriteLine("Employee id: " + empid);
                Console.WriteLine("Employee lvl: " + emplvl);

                level = Convert.ToInt32(emplvl);
                if (level == 1)
                {
                    rate = 380.00;
                }
                else if (level == 2)
                {
                    rate = 450.00;
                }
                else if (level == 3)
                {
                    rate = 550.00;
                }

                int count = 0;

                while (count != 5)
                {
                    count++;
                    if (count == 1) day = "Monday";
                    if (count == 2) day = "Tuesday";
                    if (count == 3) day = "Wednesday";
                    if (count == 4) day = "Thursday";
                    if (count == 5) day = "Friday";

                    Console.Write("Enter login for " + day + ": ");
                    login = Console.ReadLine().Split(':');
                    Console.Write("Enter logout for " + day + ": ");
                    logout = Console.ReadLine().Split(':');



                    loginhour = Double.Parse(login[0]);
                    loginmin = Double.Parse(login[1]);

                    logouthour = Double.Parse(logout[0]);
                    logoutmin = Double.Parse(logout[1]);

                    tmin = (logoutmin - loginmin) / 60;
                    thour = ((logouthour - loginhour) + tmin ) - 1;
                    week = week + thour;
                }
                Console.Write("Enter Coverage Date: ");
                string cover = Console.ReadLine();
                gross = (week / 8) * rate;

                Console.WriteLine("*****************************");
                Console.WriteLine("Employee Name: " + empname);
                Console.WriteLine("Employee id: " + empid);
                Console.WriteLine("Employee lvl: " + emplvl);
                Console.WriteLine("*****************************");
                Console.WriteLine("Coverage Date: " + cover);
                Console.WriteLine("Total Weekly hours work: " + week);
                Console.WriteLine("Regular Income: " + gross);
                Console.WriteLine("*****************************");
            }
            Console.WriteLine("Enter");
            string newcontent = Console.ReadLine();
           
        }
    }
}

Back to top Go down
https://javafreak.board-directory.net
 
read file from notepad using c#
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Java Programming-
Jump to: