Esempio n. 1
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            try
            {
                bool flag = true;
                nv.MaNV     = biz.BIZ_TaoMaNV();
                nv.HoTen    = txtHoTen.Text.Trim();
                nv.MaNgach  = cbNgach.SelectedValue.ToString();
                nv.DanToc   = txtDanToc.Text.Trim();
                nv.DiaChi   = txtDiaChi.Text.Trim();
                nv.NgaySinh = Convert.ToDateTime(dateNgaySinh.Text.Trim());
                nv.HinhAnh  = System.IO.Path.GetFileName(ofd.FileName);
                nv.CMND     = txtCMND.Text.Trim();
                nv.NgayHuu  = biz.BIZ_TinhNgayHuu(dateNgaySinh.Value, cbGioiTinh.SelectedItem.ToString());
                nv.MaHeSo   = cbHeSo.SelectedValue.ToString();
                if (nv.HoTen == "" || nv.DanToc == "" || nv.DiaChi == "" || ofd.CheckFileExists == false || cbGioiTinh.SelectedIndex == -1 || nv.CMND == "")
                {
                    flag          = false;
                    lbErr.Visible = true;
                    lbErr.Text    = "Nhập đầy đủ và chọn hình ảnh đại diện";
                }
                if (flag)
                {
                    nv.GioiTinh = cbGioiTinh.SelectedItem.ToString();
                    if (!Directory.Exists(@"../../../Webform/Images"))
                    {
                        Directory.CreateDirectory(@"../../../Webform/Images");
                        if (!File.Exists(@"../../../Webform/Images/" + ofd.SafeFileName))
                        {
                            File.Copy(ofd.FileName, @"../../../Webform/Images/" + ofd.SafeFileName);
                        }
                        else
                        {
                            File.Copy(ofd.FileName, @"../../../Webform/Images/" + ofd.SafeFileName + RandomString(4) + ".jpg");
                        }
                    }
                    else
                    {
                        if (!File.Exists(@"../../../Webform/Images/" + ofd.SafeFileName))
                        {
                            File.Copy(ofd.FileName, @"../../../Webform/Images/" + ofd.SafeFileName);
                        }
                        else
                        {
                            File.Copy(ofd.FileName, @"../../../Webform/Images/" + ofd.SafeFileName + RandomString(4) + ".jpg");
                        }
                    }
                    if (biz.Create(nv) == true)
                    {
                        _3Layer.LichSuChuyenBac _lichsuchuyenbac = new _3Layer.LichSuChuyenBac();
                        _lichsuchuyenbac.MaNV       = nv.MaNV;
                        _lichsuchuyenbac.Mangach    = nv.MaNV;
                        _lichsuchuyenbac.MaHeSo     = nv.MaHeSo;
                        _lichsuchuyenbac.NgayChuyen = DateTime.Now;
                        BIZ_LichSuChuyenBac _bizlichsucb = new BIZ_LichSuChuyenBac();
                        _bizlichsucb.ThemLichSu(_lichsuchuyenbac);

                        MessageBox.Show("Đã thêm!");
                        txtHoTen.Text  = "";
                        txtDanToc.Text = "";
                        txtDiaChi.Text = "";
                        txtCMND.Text   = "";
                        picNV.Image    = null;
                    }
                    else
                    {
                        MessageBox.Show("Thêm thất bại!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi hệ thống!");
            }
        }
        private void btnThem_Click(object sender, EventArgs e)
        {
            try
            {
                bool flag = true;
                nv.MaNV = biz.BIZ_TaoMaNV();
                nv.HoTen = txtHoTen.Text.Trim();
                nv.MaNgach = cbNgach.SelectedValue.ToString();
                nv.DanToc = txtDanToc.Text.Trim();
                nv.DiaChi = txtDiaChi.Text.Trim();
                nv.NgaySinh = Convert.ToDateTime(dateNgaySinh.Text.Trim());
                nv.HinhAnh = System.IO.Path.GetFileName(ofd.FileName);
                nv.CMND = txtCMND.Text.Trim();
                nv.NgayHuu = biz.BIZ_TinhNgayHuu(dateNgaySinh.Value, cbGioiTinh.SelectedItem.ToString());
                nv.MaHeSo = cbHeSo.SelectedValue.ToString();
                if (nv.HoTen == "" || nv.DanToc == "" || nv.DiaChi == "" || ofd.CheckFileExists == false || cbGioiTinh.SelectedIndex == -1 || nv.CMND == "")
                {
                    flag = false;
                    lbErr.Visible = true;
                    lbErr.Text = "Nhập đầy đủ và chọn hình ảnh đại diện";
                }
                if (flag)
                {
                    nv.GioiTinh = cbGioiTinh.SelectedItem.ToString();
                    if (!Directory.Exists(@"../../../Webform/Images"))
                    {
                        Directory.CreateDirectory(@"../../../Webform/Images");
                        if (!File.Exists(@"../../../Webform/Images/" + ofd.SafeFileName))
                        {
                            File.Copy(ofd.FileName, @"../../../Webform/Images/" + ofd.SafeFileName);
                        }
                        else
                        {
                            File.Copy(ofd.FileName, @"../../../Webform/Images/" + ofd.SafeFileName + RandomString(4) + ".jpg");
                        }
                    }
                    else
                    {
                        if (!File.Exists(@"../../../Webform/Images/" + ofd.SafeFileName))
                        {
                            File.Copy(ofd.FileName, @"../../../Webform/Images/" + ofd.SafeFileName);
                        }
                        else
                        {
                            File.Copy(ofd.FileName, @"../../../Webform/Images/" + ofd.SafeFileName + RandomString(4) + ".jpg");
                        }
                    }
                    if (biz.Create(nv) == true)
                    {
                        _3Layer.LichSuChuyenBac _lichsuchuyenbac = new _3Layer.LichSuChuyenBac();
                        _lichsuchuyenbac.MaNV = nv.MaNV;
                        _lichsuchuyenbac.Mangach = nv.MaNV;
                        _lichsuchuyenbac.MaHeSo = nv.MaHeSo;
                        _lichsuchuyenbac.NgayChuyen = DateTime.Now;
                        BIZ_LichSuChuyenBac _bizlichsucb = new BIZ_LichSuChuyenBac();
                        _bizlichsucb.ThemLichSu(_lichsuchuyenbac);

                        MessageBox.Show("Đã thêm!");
                        txtHoTen.Text = "";
                        txtDanToc.Text = "";
                        txtDiaChi.Text = "";
                        txtCMND.Text = "";
                        picNV.Image = null;
                    }
                    else
                    {
                        MessageBox.Show("Thêm thất bại!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi hệ thống!");
            }
        }