Write a C program to read the specified Data from a database

Write a C# program to read the specified Data from a database and display it on the screen and format it to CSV and write it to an output file your firstname_lastname_output.csv

You are required to do your own research to do this project. Questions will be asked based on the work you submit.

You can use Visual Studio if you use Windows.

If you are using Linux, you can use mono develop (linux solution preferred, but not mandatory).

1: Setup a mysql community server on your local resources (local machine or Virtual Machine on Local network etc)

2: Load the database with the employees-db-1.0.6 from (https://launchpad.net/test-db/employees-db-1/1.0.6)

Write the C# program to display the following information of all employees who are females and last name is Peac:

emp_no,

first_name,

last_name,

gender,

dept_name, from_date, to_date (employee\'s from date and to date in that department)

title, from_date, to_date (employee\'s Title\'s from date and to date, how long the employee held the title)

Salary, from_date, to_date (employee\'s Salary\'s from date and to date, how long the employee had that salary)

I need help with this. I have to download a sample database on visual studio and write a c# program to read a data from a database. How would i wanna do that?

2: Load the database with the employees-db-1.0.6 from (https://launchpad.net/test-db/employees-db-1/1.0.6)

Solution

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

namespace Help

{
class Employee
{
private string firstName;
private string lastName;
private char gender;
private int dependents;
private double annualSalary;
private double pay;
public static int numEmployees = 0; // created static variable

public const string DEFAULT_FIRST = \" not given\";
public const string DEFAULT_LAST = \" not given\";
public const char DEFAULT_GENDER = \'U\';
public const int DEFAULT_DEPENDENTS = 0;
private const double DEFAULT_ANNUALSALARY = 20000;


public Employee()
{
FirstName = DEFAULT_FIRST;
LastName = DEFAULT_LAST;
Gender = DEFAULT_GENDER;
Dependents = DEFAULT_DEPENDENTS;
AnnualSalary = DEFAULT_ANNUALSALARY;
numEmployees++; // incremented numEmployees

}

public Employee(string first, string last, char gen, int dep, double salary)
{

DisplayEmployeeInformation(first, last, gen, dep, salary);
numEmployees++; //incremented numEmployees

}

~Employee()
{
Console.WriteLine(\"Cancel the employee!!\");
}

public string FirstName
{
get
{ return firstName; }
set
{firstName = value;}
}
public string LastName
{
get
{ return lastName; }
set
{lastName = value;}
}
public char Gender
{
get
{ return gender; }
set
{gender = value;}

}
public int Dependents
{
get
{ return dependents; }
set
{ dependents = value;}
}

public double AnnualSalary
{
get { return annualSalary; }
set
{
if(value > 19999)
annualSalary = value;
else
annualSalary = DEFAULT_ANNUALSALARY;
}
}
public static int GetNumEmployees() //
{
return numEmployees;
}
public double CalculatePay()
{
return (annualSalary / 52);

}
public override string ToString()
{
string str;

str = \"Employee AnnualSalary: $\" + AnnualSalary.ToString(\"N2\") + \"\ \";
return str;
}
public void DisplayEmployeeInformation(string first, string last, char gen, int dep, double salary)
{

Console.WriteLine(\"First Name: \" + first);
Console.WriteLine(\"Last Name: \" + last);
Console.WriteLine(\"Gender: \" + gen);
Console.WriteLine(\"Dependents: \" + dep);
Console.WriteLine(\"Annual Salary:$ \" + salary.ToString(\"N2\"));
annualSalary = salary;
pay = CalculatePay();
Console.WriteLine(\"Employee Weekly Pay:$ \" + pay.ToString(\"N2\"));
Console.WriteLine(\"Total Employees:\" + numEmployees);
}

}

}

***** start of Program.cs *****

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

namespace Help
{
public class Program
{
static void Main(string[] args)
{

DisplayApplicationInformation();
DisplayDivider(\"Start Program\");

//Employee.DisplayEmployeeInformation();
DisplayDivider(\"Employee Information\");

DisplayDivider(\"Creating and testing employee1\");
Employee employee1 = new Employee();
Employee.GetNumEmployees(); // is this where we access the
employee1.FirstName = GetInput(\"First Name\");
employee1.LastName = GetInput(\"Last Name\");
employee1.Gender = char.Parse(GetInput(\"Gender\"));
employee1.Dependents = int.Parse(GetInput(\"Dependents\"));
employee1.AnnualSalary = double.Parse(GetInput(\"Salary\"));



DisplayDivider(\"Creating and testing employee2\");
Employee employee2 = new Employee();
Employee.GetNumEmployees();
employee2.FirstName = GetInput(\"First Name\");
employee2.LastName = GetInput(\"Last Name\");
employee2.Gender = char.Parse(GetInput(\"Gender\"));
employee2.Dependents = int.Parse(GetInput(\"Dependents\"));
employee2.AnnualSalary = double.Parse(GetInput(\"Salary\"));


Console.Clear();
Employee employee1write = new Employee(employee1.FirstName, employee1.LastName, employee1.Gender, employee1.Dependents, employee1.AnnualSalary);
Console.WriteLine();
Employee employee2write = new Employee(employee2.FirstName, employee2.LastName, employee2.Gender, employee2.Dependents, employee2.AnnualSalary);


TerminateApplication();

}
private static void DisplayApplicationInformation()
{
Console.WriteLine(\"Welcome to Employee Class Program\");
Console.WriteLine(\"CIS247, Week 3 Lab\");
Console.WriteLine(\"Name: Chuck\");
Console.WriteLine(\"This program will increment the employee class to count the employees\");
Console.WriteLine();
}

private static void DisplayDivider(string outputTitle)
{
Console.WriteLine(\"***************\" + outputTitle + \" \" + \"***************\");
}

private static string GetInput(string inputType)
{
string strInput = String.Empty;
Console.Write(\" Please enter \" + inputType + \" : \");
strInput = Console.ReadLine();

return strInput;
}

private static void TerminateApplication()
{
DisplayDivider(\"Program Termination\");
Console.Write(\"Thank You! Please press any key to terminate the program\");
Console.ReadKey();
}
}
}

Write a C# program to read the specified Data from a database and display it on the screen and format it to CSV and write it to an output file your firstname_la
Write a C# program to read the specified Data from a database and display it on the screen and format it to CSV and write it to an output file your firstname_la
Write a C# program to read the specified Data from a database and display it on the screen and format it to CSV and write it to an output file your firstname_la
Write a C# program to read the specified Data from a database and display it on the screen and format it to CSV and write it to an output file your firstname_la

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site