Ejemplo n.º 1
0
        /// <summary>
        /// hàm thục hiện Login
        /// </summary>
        /// <param name="parameter"></param>
        private void OnLogin(object parameter)
        {
            var    value = (object[])parameter;
            var    childWindow = (Window)value[0];
            var    wrap = (WrapPanel)value[1];
            string email = "", pass = "";

            try
            {
                foreach (var child in wrap.Children)
                {
                    string name = null;
                    if (child is FrameworkElement)
                    {
                        name = (child as FrameworkElement).Name;
                        switch (name)
                        {
                        case "txtEmail":
                            email = (child as TextBox).Text;
                            break;

                        case "txtPassword":
                            pass = (child as PasswordBox).Password.ToString();
                            break;
                        }
                    }
                }
                NhanVienDaoImpl impl     = new NhanVienDaoImpl();
                var             nhanvien = impl.checklogin(email, pass);
                if (nhanvien != null)
                {
                    MessageBox.Show("Xin chào" + nhanvien.TenNhanVien);
                    MainWindow mainwindow = new MainWindow()
                    {
                        DataContext = new MainViewModel(nhanvien)
                    };
                    mainwindow.Show();
                    childWindow.Close();
                }
                else
                {
                    MessageBox.Show("Login không thành công!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
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
 /// <summary>
 /// hàm xóa nhan viên
 /// </summary>
 /// <param name="parameter"></param>
 private void OnDelete(object parameter)
 {
     try
     {
         NhanVienDaoImpl impl     = new NhanVienDaoImpl();
         NhanVien        NhanVien = parameter as NhanVien;
         //delete in database
         impl.DeleteNhanVien(NhanVien.MaNhanVien);
         //delete in datagrid
         GetListNhanVien();
         MessageBox.Show("Delete Sussess!");
     }
     catch
     {
         MessageBox.Show("Delete fail!");
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// hàm lưu thông tin nhân viên
        /// </summary>
        /// <param name="parameter"></param>
        private void onSave(object parameter)
        {
            var             value       = (object[])parameter;
            var             childWindow = (Window)value[0];
            var             stack       = (StackPanel)value[1];
            NhanVienDaoImpl impl        = new NhanVienDaoImpl();
            NhanVien        newNhanVien = new NhanVien();

            try
            {
                foreach (object child in stack.Children)
                {
                    string childname = null;
                    if (child is FrameworkElement)
                    {
                        childname = (child as FrameworkElement).Name;
                        switch (childname)
                        {
                        case "txtMaNhanVien":
                            newNhanVien.MaNhanVien = (child as TextBox).Text;
                            break;

                        case "txtTenNhanVien":
                            newNhanVien.TenNhanVien = (child as TextBox).Text;
                            break;

                        case "txtDiaChi":
                            newNhanVien.DiaChi = (child as TextBox).Text;
                            break;

                        case "txtSdt":
                            newNhanVien.Sdt = (child as TextBox).Text;
                            break;

                        case "txtEmail":
                            newNhanVien.Email = (child as TextBox).Text;
                            break;

                        case "cbxMaChucVu":
                            newNhanVien.MaChucVu = ((child as ComboBox).SelectedItem as ChucVu).MaChucVu;
                            break;

                        case "cbxMaLop":
                            newNhanVien.MaLop = ((child as ComboBox).SelectedItem as Lop).MaLop;
                            break;

                        case "txtPassword":
                            newNhanVien.Password = (child as TextBox).Text;
                            break;
                        }
                    }
                }
                if (string.IsNullOrEmpty(newNhanVien.MaNhanVien))
                {
                    impl.AddNhanVien(newNhanVien);
                }
                else
                {
                    impl.EditNhanVien(newNhanVien);
                }
                MessageBox.Show("Susscess!");
                childWindow.Close();
                foreach (Window win in Application.Current.Windows)
                {
                    if (win.Name == "NhanVienWindowName")
                    {
                        win.DataContext = new NhanVienViewModel();
                    }
                }
            }
            catch
            {
                MessageBox.Show("Fail!");
            }
        }