Ejemplo n.º 1
0
        private void buttonSua_Click(object sender, EventArgs e)
        {
            NguoiLaoDong nguoilaodong = new NguoiLaoDong();

            if (radioButton1.Checked == true)
            {
                string   ma;
                string   hoten          = txtTen.Text;
                DateTime ngaysinh       = dateTimeNgaysinh.Value;
                string   dienthoai      = txtSDT.Text;
                string   diachi         = txtDCtamtru.Text;
                string   chucvu         = ComboBoxChucVu.Text;
                string   donvitructhuoc = ComboBoxDVTT.Text;
                string   trinhdo        = ComboBoxTrinhDo.Text;
                string   chuyenmon      = ComboBoxChuyenMon.Text;
                string   gioitinh       = "Nam";
                if (radioButtonFemale.Checked)
                {
                    gioitinh = "Nữ";
                }
                MemoryStream hinhanh   = new MemoryStream();
                int          born_year = dateTimeNgaysinh.Value.Year;
                int          this_year = DateTime.Now.Year;
                if (((this_year - born_year) < 18) || ((this_year - born_year) > 100))
                {
                    MessageBox.Show("The KySu Age Must Be Between 18 and 100 year", "Invalid Birth Date", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (verif())
                {
                    try
                    {
                        ma = Convert.ToString(txtMa.Text);
                        pictureBoxImage.Image.Save(hinhanh, pictureBoxImage.Image.RawFormat);
                        if (nguoilaodong.UpdateNguoiLaoDong(ma, hoten, ngaysinh, gioitinh, diachi, dienthoai, trinhdo, chucvu, chuyenmon, donvitructhuoc, hinhanh))
                        {
                            MessageBox.Show("KySu Information Update", "Edit Kỹ Sư", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Error", "Edit Kỹ Sư", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Edit Kỹ Sư", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Empty Fields", "Edit Kỹ Sư", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                getdata();
                labelNguoiLaoDong.Text = ("Tổng Người Lao Động trong danh sách: " + DataGridView1.RowCount);
            }
            if (radioButton2.Checked == true)
            {
                string   ma;
                string   hoten          = txtTen.Text;
                DateTime ngaysinh       = dateTimeNgaysinh.Value;
                string   dienthoai      = txtSDT.Text;
                string   diachi         = txtDCtamtru.Text;
                string   chucvu         = ComboBoxChucVu.Text;
                string   donvitructhuoc = ComboBoxDVTT.Text;
                string   trinhdo        = ComboBoxTrinhDo.Text;
                string   chuyenmon      = ComboBoxChuyenMon.Text;
                string   gioitinh       = "Nam";
                if (radioButtonFemale.Checked)
                {
                    gioitinh = "Nữ";
                }
                MemoryStream hinhanh   = new MemoryStream();
                int          born_year = dateTimeNgaysinh.Value.Year;
                int          this_year = DateTime.Now.Year;
                if (((this_year - born_year) < 18) || ((this_year - born_year) > 100))
                {
                    MessageBox.Show("The CongNhan Age Must Be Between 18 and 100 year", "Invalid Birth Date", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (verif())
                {
                    try
                    {
                        ma = Convert.ToString(txtMa.Text);
                        pictureBoxImage.Image.Save(hinhanh, pictureBoxImage.Image.RawFormat);
                        if (nguoilaodong.UpdateNguoiLaoDong(ma, hoten, ngaysinh, gioitinh, diachi, dienthoai, trinhdo, chucvu, chuyenmon, donvitructhuoc, hinhanh))
                        {
                            MessageBox.Show("NhanVien Information Update", "Edit Nhân Viên", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Error", "Edit Nhân Viên", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Edit Nhân Viên", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Empty Fields", "Edit Nhân Viên", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                getdata();
                labelNguoiLaoDong.Text = ("Tổng Người Lao Động trong danh sách: " + DataGridView1.RowCount);
            }
            if (radioButton3.Checked == true)
            {
                string   ma;
                string   hoten          = txtTen.Text;
                DateTime ngaysinh       = dateTimeNgaysinh.Value;
                string   dienthoai      = txtSDT.Text;
                string   diachi         = txtDCtamtru.Text;
                string   chucvu         = ComboBoxChucVu.Text;
                string   donvitructhuoc = ComboBoxDVTT.Text;
                string   trinhdo        = ComboBoxTrinhDo.Text;
                string   chuyenmon      = ComboBoxChuyenMon.Text;
                string   gioitinh       = "Nam";
                if (radioButtonFemale.Checked)
                {
                    gioitinh = "Nữ";
                }
                MemoryStream hinhanh   = new MemoryStream();
                int          born_year = dateTimeNgaysinh.Value.Year;
                int          this_year = DateTime.Now.Year;
                if (((this_year - born_year) < 18) || ((this_year - born_year) > 100))
                {
                    MessageBox.Show("The CongNhan Age Must Be Between 18 and 100 year", "Invalid Birth Date", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (verif())
                {
                    try
                    {
                        ma = Convert.ToString(txtMa.Text);
                        pictureBoxImage.Image.Save(hinhanh, pictureBoxImage.Image.RawFormat);
                        if (nguoilaodong.UpdateNguoiLaoDong(ma, hoten, ngaysinh, gioitinh, diachi, dienthoai, trinhdo, chucvu, chuyenmon, donvitructhuoc, hinhanh))
                        {
                            MessageBox.Show("CongNhan Information Update", "Edit Công Nhân", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            MessageBox.Show("Error", "Edit Công Nhân", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Edit Công Nhân", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Empty Fields", "Edit Công Nhân", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

                getdata();
                labelNguoiLaoDong.Text = ("Tổng Người Lao Động trong danh sách: " + DataGridView1.RowCount);
            }
        }