C# Employee Form Application Assignment Description:
The objective for this assignment is to create a program that manages employee data stored in an employee list. The user interface design should efficiently and robustly implement the required functionality as exemplified in class. The fields are: FirstName, LastName, EmpType, Salary.
The basic requirements for the program are as follows: Create a Windows Forms application (written in C#) named Employees, with:
o Menu, toolbar and status bar elements
o Support File: Open, Save, Save As, Help: About, and Edit: Add,Delete,Properties
o Include an About box, customized to your liking
Add a listbox to the main form, docked so that it takes up the entire screen area
Use a common dialog box to get the name of the file to be opened
Define a public Employee object (class), with:
o A public constructor
o Private data members and public properties for each of the four fields
o A public ToString method (overridden from the base class) that returns the last name, a comma, a space, and the first name.
Open the file using a StreamReader object and read the lines as records into instances of your class, by doing the following:
o Split the line of text read from the file
o Create a new instance of the Employee object
o Set each property of the Employee object accordingly, e.g., emp.FirstName = strSplit[0]; emp.LastName = strSplit[1]; etc.
Add each new Employee object to the list box occupying the main client area of the form
o Verify that as the employees are displayed, the ToString method was called by the listbox to display the object’s textual representation
Support a toolbar button, menu item and double-clicking an item to get properties on it.
Create a second “dialog box” style form to display employee properties, with:
o OK, Cancel buttons o Labels and TextBox controls for each field
o A public property Employee in the form that is used to pass data back and forth between the main form and the properties form using the technique from the previous Windows Forms application
Support a Save (to the same filename) and Save As (allow them to pick a new filename)
o Use the Rename, Create, Delete process to save the new contents of the file
When reading lines from the file and processing them, if any errors are encountered (such as failing to convert a string to an integer, let the user know the line number of the bad record in the file via MessageBox.
Support Add and Delete of records as well.
Okay so my first form takes in the employees name first before you can do anything. The moment the name is entered, it is populated in
Form2: (My GUI's should look identical to the windows I have created below, with the addition of the toolstrip buttons that I need added in).
After the new employees name populates, they proceed to fill out the remaining areas:
After the new employee hits Submit, it should redirect them to form1 where they will now see there name populated in the bottom listbox showing (Employees: lastName, firstName( is how it should populate)).
If they double-click or hit edit, they will be redirected to Form2 to make changes. After everything looks good, they will save it using regular save or save as.
Open will open a file saved(everything is to be stored, saved and written using a StreamReader. My Employee class should be stored as such:
Public Employee(string firstName, string lastName, string empType, double salary)
Private variables and public properties(get/set) for each type
Override the public ToString
Example: Public override string ToString() { Return lastName + “, ” + firstName;
Private variables and public properties(get/set) for each type
Override the public ToString
Example: Public override string ToString() { Return lastName + “, ” + firstName;
Open the file using a StreamReader object and read the lines as records into instances of your class, by doing the following:
o Split the line of text read from the file
o Create a new instance of the Employee object o Set each property of the Employee object accordingly, e.g., emp.FirstName = strSplit[0]; emp.LastName = strSplit[1]; etc. .
Please let me know if you have any questions!
Expert Answer
- Employee.cs
using System;
using System.Collecetions.Generics;
using System.ComponentModel;
using System.Data
using System.Text
using System.Windows.Forms;namespace employee
{
public partial class Employee : EmpTable
{
public SaveFileDialog saveFile; // save file to save files
public OpenFileDialog openFile; //open file to open files
public int indices;#region"Constructor"
public Employee() //initialize the constructor
{
InitializeComponent();
saveFile = new SaveFileDialog();
openFile = new OpenFileDialog();
this.text = "Untitled-Digital Diary";
richTextBox1.TabIndex = 5;
}private void toolStripButton1_Click(object sender, EventArgs e)
{
//call savefile()SaveFile();
}private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
saveFile.Title = "Save As";
saveFile.Filter = "Text Document|*.txt";
saveFile.DefaultExt = "txt";
saveFile.ShowDialog();richTextBox1.saveFile(saveFile.FileName, RichTextBoxStreamType.PlainText);
this.Text = saveFile.FileName;
}private void cutToolStripMenuItem_Click(object sender, EventArgs e){
//cutting
richTextBox1.Cut();
}private void pasteToolStripMenuItem_CLick(object sender, EventArgs e){
//pasting
richTextBox1.Paste();
}private void copyToolStripMenuItem_Click(Object sender, EventArgs e)
{
//copying
richTextBox1.copy();
}private void selectAllToolStripMenuItem_Click(object sender, EventArgs e){
//perform and check for undo
if(richTextBox1.canUndo)
{
richTextBox1.Undo();
}
}private void redoToolStripMenuItem_Click(object sender, EventArgs e){
//check for redostatusStrip1.Text = "Redo to last changed";
if(richTextBox1.canRedo)
{
richTextBox1.Redo();
}
}private void timeDateToolStripMenuItem_Click(object sender, EventArgs e){
//inserting current date and time
richTextBox1.Text += Convert.ToString(DateTime.Now);
}private void findToolStripMenuItem_Click(object sender, EventArgs e){
//calling for searching
findform findob = new findform(this);
finddob.Show();
}private void fontToolStripMenuItem_Click(object sender, EventArgs e)
{
//setting richtextbox text font and colorFontDialog fd = new FontDialog();
fd.Font = richTextBox1.SelectionFont;
fd.Color = richTextBox1.SelectionColor;if(fd.ShowDialog() == DialogResult.OK)
{
richTextBox1.SelectionFont = fd.Font;
richTextBox1.SelectionColor = fd.Color;
}
}private void wordWrapToolStripMenuItem_Click(object sender, EventArgs e)
{
//perform word wrapif(wordWrapToolStripMenuItem.Checked == false)
{
wordWrapToolStripMenuItem.Checked = true;
}
else
{
wordWrapToolStripMenuItem.Checked == false;
richTextBox1.WordWrap = false;
}
}private void toolStripTextBox1_Click(object sender, EventArgs e)
{GotoForm gob = new Gotoform(this);
gob.Show();}private void statusBarToolStripMenuItem_Click(object sender, EventArsd e)
{
//statuslabel1.Text = "Columns" + richTextBox1.Text.Length
}private void findNextToolStripMenuItem_Click(object sender,EventArgs e)
{
findform f = new findform(this);
f.Show();
}
private void replaceToolStripMenuItem_Click(object sender, EventArgs e)
{
undoToolStripMenuItem.Enabled = false;
rechTextBox1.Focus();
}
#endregion#region "Menu Item"
private void newToolStripMenuItem_Click(object sender,EventArgs e)
{
saveFile.Title = "Save";DialogResult dr = MessageBox.Show("Are you sure you want to save the file", "save", MessageBoxButtons. YesNo,messageBoxIcon.Question);
replaceform ob = new replaceForm(this);
ob.show();
}private void addBulletToolStripMenuItem_Click(object sender, EventArgs e){
//inserting bullets
try
{
richTextBox1.BulletIndent = 10;
richTextBox1.SelectionBullet = true;
}
catch(Exception exc)
{
MessageBox.Show(exc.Message.ToString(), "Error");
}
}
private void removeBulletToolStripMenuItem_Click(object sender, EventArgs e)
{
//removing bullets
try
{
richTextBox1.SelectionBullet = false;
}
catch(Exception exc)
{
MessageBox.Show(exc.Message.ToString(), "Error");
}
}
private void leftIndentationToolStripMenuItem_Click(Object sender, EventArgs e)
{
//set the alignment
try
{
richTextBox1.SelectionAlignment = HorizontalAlignment.Left;
}
catch(Exception exc1)
{
MessageBox.Show(exc1.Message.ToString());
}
}
private void centerIntendationToolStripMenuItem_Click(Object sender, EventArgs e)
{
try
{
richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
}
catch(Exception exc1)
{
MessageBox.Show(exc1.Message.ToString());
}
}
private void rightIntendationToolStripMenuItem_Click(Object sender, EventArgs e)
{
try
{
richTextBox1.SelectionAlignment = HorizontalAlignment.Right;
}
catch(Exception exc1)
{
MessageBox.Show(exc1.Message.ToString());
}
}private void backGroundColorToolStripMenuItem_CLick(Object sender, EventArgs e)
{
//set background colorColorDialog color = new ColorDialog();
if(color.Show.Dialog() == DialogResult.OK)
{
richTextBox1.BackColor = color.Color;
}
}private void toolStripTextBox2_Click(Object sender, EventArgs e)
{
richTextBox1.SelectedText = "";
}
private void aboutToolStripMenuItem_Click(Object sender, EventArgs e)
{
AboutBox1 about = new AboutBox1();
about.ShowDialog();
}
#endregion#region "Function To Save File"private void SaveFile()
{
saveFile.Title = "Save As";
saveFile.Filter = "Text Document|*.txt"; //applied filter
saveFile.DefaultExt = "txt"; //appplied default extension
}
#endregion
#region "User Defined Function to Open File"private void OpenFile()
{
//putting title of openfileDialog to Open Document
opneFile.title = "Open Document";
//openFile.DefaultExt = "txt";
openFile.Filter = "Text Files|*.txt" //Apply Filter
openFile.FileName = string.Empty; //set Filename
if(openFile.ShowDialog() == DialogResult.OK)
{
if(openFile.FileName == String.Empty)
{
return
}
else
{
//reading or loading selected file into richtextboxstring options = opneFile.FileName;
richTextBox1.LoadFile(options, RichTextBoxStreamType.PlainText);
this.Text = OpenFile.FileName;
}
if(dr.Equals(DialogResult.Yes)) //execution when clicked Yes
{
SaveFile(); //call SaveFile()
richTextBox1.Clear();
this.Text = "Employee ";
}
else if (dr.Equals(DialogResult.No)) //execution when clicked No{
richTextBox1.Clear();
this.Text = "Employee Data";
}}
}
#endregionprivate void richTextBox1_TextChanged(Object sender, EventArgs e)
{
undoToolStripMenuItem.Enabled = true;
statusLabel1.Text = "Line: " +
(richTextBox1.GetLineFromCharIndex(Int32.MaxValue) +1)"
Cols: " + richTextBox1.Text.Length;
}#region "Printing"private void printPreviewToolStripMenuItem_Click(Object sender, EventArgs e)
{
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.Show.Dialog();
}
private void toolStripMenuItem1_Click(Object sender, EventArgs e)
{printDialog1.Document = printDocument1;if (printDialog1.ShowDialog () == DialogResult.OK)
{
printDocument1.print();
}
}
private void pageSetUPToolStripMenuItem_Click(Object sender, EventArgs e)
{
pageSetupDialog1.Document = printDocument1;
pageSetupDialog1.ShowDialog();
}
private void printDocument1_PrintPAge(Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawString(rich.TextBox1.Text, richTextBox1.Font, Brushes.Black, 100, 100);
}
#endregion#region "Function For GoTo"
public void GoTo(int horizontal) //Goto horizontal function to navigate user to horizontal number{
indices = richTextBox1.GetFirstCharIndexFromLine(horizontal-1);
richTextBox1.Select(indices,0);
richTextBox1.Focus();
}
#endregion
#region "Function For FindNext"
public void FindNext(String options) //find open
{try
{
//int res = richTextBox1.Find(options, indices, options.Length, RichTextBoxFinds.WholeWord);if(indices == -1)
{
MessageBox.Show("Word Search Complete");
}
else
{
int starting = richTextBox1.Text.IndexOf(options, indices)
richTextBox1.Select(starting, options.Length);
richTextBox1.Focus();
indices = starting+ options.Length;
}
}
catch(SystemException s)
{
MessageBox.Show(s.Message.ToString(), "Error Message")
}
}
#endregion
#region"Standard ToolBar Event"
private void toolStripButton6_Click(object sender, EventArgs e)
{
newToolStripMenuItem_CLick(this,e)
}
private void toolStripButton5_Click(object sender, EventArgs e)
{
openToolStripMenuItem_CLick(this, e);
}
private void printPreviewToolStripMenuItem1_Click(object sender, EventArgs e)
{
printPreviewToolStripMenuItem_Click(this, e);
}
private void pageSetUPToolStripMenuItem1_Click(object sender, EventArgs e)
{
pageSetUPToolStripMenuItem_Click(this, e)
}
private void toolStripButton4_Click(object sender, EventArgs e)
{
exitToolStripMenuItem_Click(this e);
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
backGroundcolorToolStripMenuItem_Click(this e)'
}
private void toolStripButton3_Click(object sender, EventArgs e)
{
fontToolStripMenuItem_Click(this e);
}
private void toolStripButton7_Click(object sender, EventArgs e)
{
addBulletToolStripMenuItem_Click(this e);
}
private void toolStripButton8_Click(object sender, EventArgs e)
{
cutToolStripMenuItem_Click(this e);
}
private void toolStripButton9_click(object sender, EventArgs e)
{
copyToolStripMenuitem_Click(this e);
}
private void toolButton10_Click(object sender, EventArgs e)
}private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFile(); //calling saveFile()
}private void opentoolStripMenuItem_Click(object sender, EventArgs e)
{
if(richTextBox1.Mofdified == true) // Checking for entered value
{
{
pasteToolStripMenuItem_Click(this, e);
}
#endregionprivate void Form1_Load(object sender, EventArgs e){
}
{
}DialogResult dr = MesageBox.Show("Save Changes" , "unsaved document", MessageBoxButtons.YesNo, MessageBoxIcon.Question);if(dr == DialogResult.No)
{
richTextBox1.Modified = false;
OpenFile(); // call OpenFile()
}
else
{
if(this.Text == "Employee Data")
{
//call SaveFile() and Openfile()
SaveFile();
OpenFile();
}
else
{
DialogREsult dr1 = MessageBox.Show("There are changes in the file.Save the changes","Open", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if(dr1 == DialogResult.Yes)
{
richTextBox1.SaveFile(this.Text);
OpenFile();
}
else
{
OpenFile();
}
}
}
}
else
{
OpenFile();
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{if(richTextBox1.Modified == true)
{
DialogResult dr = MessageBox.Show("Save file before exiting", "unsaved file", MessageBoxButtons.YesNo,MessageBoxIcon.Question);if (dr == DialogResult.Yes)
{
SaveFile();
richTextBox1.Modified = false;
Application.Exit();
}
else
}
richTextBox1.Modified = false;
Application.Exit();
}
}
ليست هناك تعليقات:
إرسال تعليق