Ejemplo n.º 1
0
        public void CapNhat( )
        {
            NhanVienBUS.XoaMoiNhanVien( );

            foreach (var nhanVien in ListNhanVien)
            {
                NhanVienDTO tmp = new NhanVienDTO
                {
                    MaNhanVien  = nhanVien.MaNhanVien,
                    TenNhanVien = nhanVien.TenNhanVien
                };

                try
                {
                    NhanVienBUS.ThemNhanVien(tmp);
                }
                catch (Exception e)
                {
                    var error = IoC.Get <ErrorViewModel>();
                    error.ErrorName   = e.Message;
                    error.DisplayName = "Lỗi";
                    _windowManager.ShowDialog(error);
                }
            }

            ListNhanVien.Clear(  );
            NhanVienBUS.SelectNhanVienAll().ForEach(x => ListNhanVien.Add(new NhanVien(x)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Hàm lấy danh sách nhân viên
        /// </summary>
        /// <returns></returns>
        public ObservableCollection <NhanVien> GetListNhanVien()
        {
            NhanVienDaoImpl impl = new NhanVienDaoImpl();

            if (ListNhanVien == null)
            {
                ListNhanVien = new ObservableCollection <NhanVien>();
            }
            else
            {
                ListNhanVien.Clear();
            }
            impl.GetListNhanVien().ForEach(p => ListNhanVien.Add(p));
            return(ListNhanVien);
        }
Ejemplo n.º 3
0
 public void ThemNhanVien( )
 {
     ListNhanVien.Add(new NhanVien());
 }
        public void Command()
        {
            ExitCommand = new RelayCommand <object>((p) => true, (p) =>
            {
                (p as Window).Close();
            });
            AddCommand = new RelayCommand <Grid>((p) => true, (p) =>
            {
                string tennv  = "";
                string loainv = "";

                foreach (var item in p.Children)
                {
                    if (item is TextBox)
                    {
                        TextBox tb = item as TextBox;
                        switch (tb.Name)
                        {
                        case "txbTenNV":
                            {
                                tennv = tb.Text;
                            }
                            break;
                        }
                    }
                    if (item is ComboBox)
                    {
                        ComboBox cb = item as ComboBox;
                        switch (cb.Name)
                        {
                        case "cbLoaiNV":
                            {
                                loainv = cb.Text;
                            }
                            break;
                        }
                    }
                }
                if (string.IsNullOrEmpty(tennv) || string.IsNullOrEmpty(loainv))
                {
                    MessageBox.Show("Nhâp đầy đủ thông tin nhân viên");
                    return;
                }
                int MaloaiNV      = DataProvider.Instance.DB.LOAINHANVIENs.Where(x => x.TENLOAINV == loainv).SingleOrDefault().MALOAINV;
                NHANVIEN nhanvien = new NHANVIEN()
                {
                    TENNHANVIEN = tennv,
                    MANHANVIEN  = manv,
                    MALOAINV    = MaloaiNV
                };
                ListNhanVien.Add(nhanvien);
                Insert.Instance.ThemThongTinNhanVien(nhanvien);
                MessageBox.Show("Thêm thành công");
            });
            DeleteCommand = new RelayCommand <ListView>((p) => true, (p) =>
            {
                try
                {
                    int selectedindex = (p as ListView).SelectedIndex;
                    if (selectedindex >= 0)
                    {
                        string manv = ListNhanVien[selectedindex].MANHANVIEN;
                        if (DataProvider.Instance.DB.HOADONBHs.Where(x => x.MANHANVIEN == manv).ToList().Count == 0)
                        {
                            if (Delete.Instance.XoaThongTinNhanVien(ListNhanVien[selectedindex]) == true)
                            {
                                ListNhanVien.RemoveAt(selectedindex);
                                MessageBox.Show("Xóa nhân viên thành công");
                            }
                            else
                            {
                                MessageBox.Show("Xóa tài khoản trước khi xóa nhân viên");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Không thể xóa nhân viên", "CẢNH BÁO");
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Vui lòng chọn nhân viên cần xóa;");
                        return;
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show("NHÂN VIÊN ĐÃ CÓ TÀI KHOẢN " + "\n" + "XÓA TÀI KHOẢN TRƯỚC KHI XÓA NHÂN VIÊN", "CẢNH BÁO");
                }
            });

            RefreshCommand = new RelayCommand <Grid>((p) => true, (p) =>
            {
                manv = PrimaryKey.Instance.CreatePrimaryKey("NHANVIEN", "NV", 1);
                foreach (var item in p.Children)
                {
                    if (item is TextBox)
                    {
                        TextBox tb = item as TextBox;
                        switch (tb.Name)
                        {
                        case "txbMaNV":
                            {
                                tb.Text = manv;
                            }
                            break;

                        case "txbTenNV":
                            {
                                tb.Text = "";
                            }
                            break;
                        }
                    }
                    if (item is ComboBox)
                    {
                        ComboBox cb = item as ComboBox;
                        switch (cb.Name)
                        {
                        case "cbLoaiNV":
                            {
                                cb.Text = "";
                            }
                            break;
                        }
                    }
                }
            });
        }