如何通过单击计算按钮显示计算字段结果? [英] How to show calculated fields results by clicking calculate button?

查看:92
本文介绍了如何通过单击计算按钮显示计算字段结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了员工类来保存员工姓名,工作时间,PayRate,税金和NetPay。



我为每个人设置了构造函数和属性。另外,创建了一个支付毛钱的方法,如下所示。



所以想法是需要通过点击Calculate来显示每个的计算主窗体上的按钮。到目前为止,只写了课堂上的总薪酬方法。问题是,当我尝试通过clciking主窗体上的Calculate_click按钮调用grosspay方法时,它无法识别方法。



我怎么能去做?



一旦知道如何调用类中的grossPay方法,我就可以完成剩下的工作。



I created Employee Class to hold employee Name, hoursworked, PayRate,tax and NetPay.

I set the constructors and properties for each. Also, created a method for the grosspay as shown below.

So the idea is that need to display the calculations of each of them by clicking on the Calculate button on the main form. So far only wrote the method for gross pay in the class. The issue is that when I try to call the grosspay method by clciking on the Calculate_click button on the main form, it doesn't recognize the method.

How can I do that?

I can do the rest once know how to call the grossPay method that is in the Class.

 lang="C#">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Payroll
{
    class Employee
    {
        //Fields

        private string _name;
        private decimal _hoursWorked;
        private decimal _hourlyPayRate;
        private decimal _netPay;
        private decimal _tax;
        private decimal _grossPay;




        //Constructor
        public Employee(string name, decimal hWorked, decimal hPayRate, decimal netPay, decimal tax, decimal grossPay)
        {

            _name = name;
            _hoursWorked = hWorked;
            _hourlyPayRate = hPayRate;
            _netPay = netPay;
            _tax = tax;
            _grossPay = grossPay;
        }

        //Name property
        public string name
        {
            get { return _name; }
            set { _name = value; }
        }

        //Hours worked property
        public decimal hWorked
        {
            get { return _hoursWorked; }
            set { _hoursWorked = value; }
        }

        //Pay Rate property
        public decimal hPayRate
        {
            get { return _hourlyPayRate; }
            set { _hourlyPayRate = value; }

        }
        //Pay Rate property
        public decimal netPay
        {
            get { return _netPay; }
            set { _netPay = value; }

        }

        //Tax property
        public decimal tax
        {
            get { return _tax; }
            set { _tax = value; }

        }


        //gross pay property
        public decimal grossPay
        {
            get { return _grossPay; }
            set { _grossPay = value; }

        }


        public void GrossPay()
        {

            _grossPay = _hoursWorked * _hourlyPayRate;
        }







    }
}





我尝试了什么:



我把grosspay()放入Calculate_click按钮但无法识别它。



What I have tried:

I put grosspay() in Calculate_click button but doesn't recognize it.

推荐答案

在继续执行此类任务之前,您需要获得一本关于c#的书籍并学习基础知识。 />


You need to get a book on c# and learn the basics before you move on to doing tasks like this.

Payroll.Employee e = new Payroll.Employee( ... your data here ...);
e.GrossPay();


这篇关于如何通过单击计算按钮显示计算字段结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆