我不完全確定標題對此很有幫助。我被困在學校的任務上,假設是一個視頻來展示如何做到這一點,但對於我的生活,我無法弄清楚如何從皮爾森網站下載學生文件。以下是我正在處理的問題。員工和生產工人班,從班級獲取信息
員工和ProductionWorker類
創建一個具有以下數據性質的Employee類:
- 員工姓名
- 員工人數
接下來,創建一個名爲ProductionWorker類這是從Employee類派生的。該ProudctionWorker類應該具有的屬性來保存以下數據:
- 移位號(一個整數,例如1,2或3)
- 小時工資率
在工作日被分成兩班倒:白天和晚上。 Shift屬性將保存一個表示員工工作班次的整數值。白班是變速1和夜班是移位2.
創建創建ProductionWorker類的一個對象,並允許用戶對每個對象的屬性的輸入數據的應用程序。檢索對象的屬性並顯示它們的值。
這裏是我正在爲它的代碼:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace classes
{
public partial class frmMainClasses : Form
{
string EmpShift = "";
string EmployeeName = "";
int EmployeeNumber = 0;
float HourlyPayRate = 0;
public class Employee
{
public string EmployeeName { get; set; }
public int EmployeeNumber { get; set; }
}
public class ProductionWorker : Employee
{
public float HourlyPayRate { get; set; }
public Shift Shift { get; set; }
}
public enum Shift
{
Day = 1,
Night = 2
}
public frmMainClasses()
{
InitializeComponent();
}
private void btxExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnGetInfo_Click(object sender, EventArgs e)
{
string EmpShift = "";
ProductionWorker productionWorker = new ProductionWorker();
productionWorker.EmployeeName = txtName.ToString();
EmployeeName = productionWorker.EmployeeName; //Added mostly because I couldn't get EmployeeName to show anything in the messagebox
productionWorker.EmployeeNumber = Convert.ToInt32(txtIdNumb.text);
productionWorker.HourlyPayRate = Convert.ToInt32(txtPay.text);
EmpShift = Convert.ToString(txtShift.text);
txtName.Text = "";
txtIdNumb.Text = "";
txtPay.Text = "";
txtShift.Text = "";
}
private void btnShow_Click(object sender, EventArgs e)
{
MessageBox.Show("Name " + EmployeeName + "IDNumber " + EmployeeNumber + "Hourly rate " + txtPay + "Shift " + txtShift);
}
}
}
代碼本身沒有顯示任何錯誤,但是當我嘗試運行它,我得到:
字符串EmpShift的是在那裏,因爲我無法弄清楚如何使用移位代碼或多或少地使用它作爲佔位符,直到我指出它。我不知道如何解決這個問題,希望它有一個小小的錯誤。
多虧了我能解決的第一個問題我有,現在我在與末尾的消息框出現問題的commets幫助。我輸入的信息是,名稱爲Glitter,ID號碼爲12,輪班號碼爲1,付費號碼爲12。下面是它的表現:
名稱System.Windows.Forms.TextBox,文本:GlitterIDNumber 0Hourly率 System.Windows.Forms.TextBox,文字:按住Shift鍵SystemWindowsForm.TextBox,文本:
它應該是'Convert.ToInt32(txtIdNumb.Text)'。你想轉換文本屬性,而不是文本框本身。 –
啊,謝謝羅恩。 – Lyght
我的留言箱無法正常工作/顯示正確,現在正試圖解決此問題。 – Lyght