예제 #1
0
        private void search_labourer_btn_Click(object sender, EventArgs e)
        {
            labourerTable.Refresh();

            DbConnector dbcon = new DbConnector();

            dbcon.connect();

            LabourerHandler labourerHandler = new LabourerHandler();
            List <Labourer> labourersList   = labourerHandler.getLabourers(dbcon.getConn());

            if (labourersList != null)
            {
                foreach (Labourer labourer in labourersList)
                {
                    labourerTable.RowCount++;
                    labourerTable.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                    int currentRow = labourerTable.RowCount;

                    Label idLabel = new Label();
                    idLabel.Text      = labourer.Id.ToString();
                    idLabel.Dock      = DockStyle.Fill;
                    idLabel.TextAlign = ContentAlignment.MiddleCenter;

                    Label nameLabel = new Label();
                    nameLabel.Text      = labourer.Name;
                    nameLabel.Dock      = DockStyle.Fill;
                    nameLabel.TextAlign = ContentAlignment.MiddleCenter;

                    Label ageLabel = new Label();
                    ageLabel.Text      = labourer.Age.ToString();
                    ageLabel.Dock      = DockStyle.Fill;
                    ageLabel.TextAlign = ContentAlignment.MiddleCenter;

                    Label genderLabel = new Label();
                    genderLabel.Text      = labourer.Gender;
                    genderLabel.Dock      = DockStyle.Fill;
                    genderLabel.TextAlign = ContentAlignment.MiddleCenter;

                    labourerTable.Controls.Add(idLabel, 0, currentRow - 1);
                    labourerTable.Controls.Add(nameLabel, 1, currentRow - 1);
                    labourerTable.Controls.Add(ageLabel, 2, currentRow - 1);
                    labourerTable.Controls.Add(genderLabel, 3, currentRow - 1);
                }
            }
            else
            {
                labourerTable.RowCount++;
                labourerTable.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                labourerTable.SetColumnSpan(new Label()
                {
                    Text = "No Result Found"
                }, 4);
            }
        }
예제 #2
0
        private void submit_labourer_btn_Click(object sender, EventArgs e)
        {
            DbConnector dbcon = new DbConnector();

            dbcon.connect();

            string   labourName   = nameTextBox.Text;
            DateTime labourDob    = dob_datePicker.Value;
            int      labourAge    = DateTime.Now.Year - labourDob.Year;
            string   labourGender = (male_radioBtn.Checked ? "MALE" : "FEMALE");

            Labourer labourer = new Labourer();

            labourer.Name   = labourName;
            labourer.Age    = labourAge;
            labourer.Gender = labourGender;

            LabourerHandler labourerHandler = new LabourerHandler();
            int             recCount        = labourerHandler.addNewLabourer(dbcon.getConn(), labourer);

            MessageBox.Show(recCount + " record(s) has been inserted !");

            addLabour_panel.Visible = false;
        }