0

一旦员工输入他们的信息和时间,我编写了一个程序来计算工资数据。我在将数据从一种形式的变量读取到另一种形式时遇到问题。我试图做的是从另一个名为 Payroll_Submission 的表单中读取一个名为 TimeSheet 的表单。这是我到目前为止的代码,我真的需要从其他表单中获取数据来进行计算。如果您需要我的 TimeSheet 代码,请告诉我,它很长,所以我这次没有附上。

Public Class Payroll_Submission

Private Sub Payroll_Submission_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    Dim counter As Integer
    counter = 0

    lblEmployee.Text = TimeSheet.EmpName
    lblSuperName.Text = TimeSheet.Supervisor
    lblReport.Text = TimeSheet.Period

    If Not TimeSheet.flag Then
        lblHoursWorked.Text = TimeSheet.txtMon1 + TimeSheet.txtTues1 + TimeSheet.txtWed1 + TimeSheet.txtThurs1 + TimeSheet.txtFri1 + TimeSheet.txtSat1 + TimeSheet.txtSun1
        If lblOvertimeHours.Text > 40 Then
            lblRegHours.Text = 40
            lblRegHours.Text = lblHoursWorked.Text - 40
        Else
            lblRegHours.Text = lblHoursWorked.Text
            lblOvertimeHours.Text = 0
        End If
        lblOvertimeHours.Text = "$15"
        lblRateOver.Text = "$22.50"

        HourlyPay.Text = Convert.ToInt32(lblRegHours.Text) * 15
        lblOvertimeHours.Text = Convert.ToInt32(lblOvertimeHours.Text) * 22.5
        lblGrossPay.Text = Convert.ToInt32(HourlyPay.Text) + Convert.ToInt32(lblOvertimeHours.Text)

        If TimeSheet.chk1.Checked Then
            counter = counter + 1
        End If

        If TimeSheet.chk2.Checked Then
            counter = counter + 1
        End If

        If TimeSheet.chk3.Checked Then
            counter = counter + 1
        End If

        If TimeSheet.chk4.Checked Then
            counter = counter + 1
        End If

        If TimeSheet.chk5.Checked Then
            counter = counter + 1
        End If

        If TimeSheet.chk6.Checked Then
            counter = counter + 1
        End If

        If TimeSheet.chk7.Checked Then
            counter = counter + 1
        End If

        lblPTOHours.Text = counter

    End If

    HourlyPay.Text = Convert.ToInt32(lblRegHours.Text) * 15
    lblOvertimeHours.Text = Convert.ToInt32(lblOvertimeHours.Text) * 22.5
    lblGrossPay.Text = Convert.ToInt32(lblRegHours.Text) + Convert.ToInt32(lblOvertimeHours.Text)
End Sub

结束类

4

3 回答 3

1

如果我理解您想要正确做的事情,那实际上非常简单。在您的时间表表格中,您是否像这样称呼您的工资单?

dim payroll as new Payroll_Submission
payroll.showdialog()

如果您这样做,您应该能够通过以下方式访问工资单上的所有控件:

payroll.lblEmployee.Text = Me.EmpName

等等等等

然后,这会将工资单表单上的每个标签和其他控件设置为您在时间表表单中拥有的变量。在执行 .showdialog 之前,您需要确保在工资单表单上设置控件。

它应该看起来像这样:

    dim payroll as new Payroll_Submission
    payroll.lblEmployee.Text = Me.EmpName
    payroll.lblSuperName.Text = Me.Supervisor
    payroll.showdialog()
于 2012-10-09T08:38:03.310 回答
0

Assuming that you create the Payroll_Submission form from your Timesheet form I would look at adding a second constructor to your Payroll_Submission form:

Private _ts As Form

Public Sub New(ts As Form)
    Me.New()
    _ts = ts
End Sub

When you create the form pass a reference to your form through the constructor

    Dim ps As New Payroll_Submission(Me)

Then, once you change references to TimeSheet to be _ts, your code should work fine.

Just looking at your code, you could also do this to shrink it down a bit for the calculation of counter:

Dim cbs As New List(Of CheckBox) From _
{ _
    _ts.chk1, _ts.chk2, _ts.chk3, _
    _ts.chk4, _ts.chk5, _ts.chk6, _
    _ts.chk7 _
}
Dim counter = cbs.Where(Function (cb) cb.Checked).Count()
于 2012-10-09T01:54:48.857 回答
0

将 Timesheet 表单中的变量声明为 Friend。例如

Public Class Timesheet
  Friend EmpName As String
  Friend Supervisor As String
于 2012-10-09T04:16:42.660 回答