示例#1
0
        static void insert_data()
        {
            try
            {
                //Console.WriteLine(id + "\t" + name + "\t" + DOB + "\t" + location + "\t\t\t" + designation + "\t\t\t" + joining);
                var data = File.ReadAllLines(@"..\..\..\records.csv").ToList();

                var records = from record in data.Skip(1)
                              let rec = record.Split(',')
                                        select new
                {
                    ID          = rec[0],
                    Name        = rec[1] + rec[2] + " " + rec[3] + " " + rec[4],
                    DOB         = rec[10],
                    Location    = rec[30],
                    Designation = rec[34],
                    Joining     = rec[14]
                };

                foreach (var record in records)
                {
                    DateTime.TryParseExact(record.DOB, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out DateTime date);

                    using (Employee_DetailsEntities context = new Employee_DetailsEntities())
                    {
                        employee_details emp = new employee_details
                        {
                            emp_id          = int.Parse(record.ID),
                            name            = record.Name,
                            DOB             = record.DOB,
                            age             = DateTime.Now.Year - date.Year,
                            location        = record.Location,
                            date_of_joining = record.Joining
                        };
                        context.employee_details.Add(emp);

                        context.SaveChanges();
                    }
                }
            }
            catch (DbUpdateException)
            {
                Console.WriteLine("Data already exists");
            }
        }
示例#2
0
        static void Filter_date(DateTime date)
        {
            try
            {
                IEnumerable <employee_details> filtered_data;
                DateTime doj;
                Employee_DetailsEntities context = new Employee_DetailsEntities();

                filtered_data = from emp in context.employee_details where DateTime.ParseExact(emp.date_of_joining, "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None) >= date select emp;
                foreach (var item in filtered_data)
                {
                    Console.WriteLine(item.emp_id + "\t" + item.name + "\t" + item.DOB + "\t" + item.location + "\t\t\t" + item.date_of_joining);
                }
                Console.Read();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e);
            }
        }
示例#3
0
        static void Filter_location(string loc)
        {
            try
            {
                IEnumerable <employee_details> filtered_data;
                Employee_DetailsEntities       context = new Employee_DetailsEntities();

                filtered_data = from emp in context.employee_details where emp.location.ToLower().Contains(loc.ToLower()) select emp;

                foreach (var item in filtered_data)
                {
                    Console.WriteLine(item.emp_id + "\t" + item.name + "\t" + item.DOB + "\t" + item.location + "\t\t\t" + item.date_of_joining);
                }
                Console.Read();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e);
            }
        }