Ejemplo n.º 1
0
        public async void SendGetAccount()
        {
            if (MyClub != null)
            {
                if (MyClub.Numbers != null && MyClub.Numbers.Count > 0)
                {
                    foreach (var item in MyClub.Numbers)
                    {
                        var acc = await Helper.Instance().CheckExistAccount(item);

                        if (acc.Number_Id > 0)
                        {
                            var accJoinClub = new Accountlocal();
                            accJoinClub.Avatar_Uri = acc.Avatar_Uri;
                            accJoinClub.fullname   = acc.fullname;
                            accJoinClub.Number_Id  = acc.Number_Id;
                            accJoinClub.Level      = "Hạng C";
                            accJoinClub.AccepLevel = "Đã Duyệt";
                            accJoinClub.Facebat    = "Mặt A - Hãng A";
                            accJoinClub.Blade      = "Cốt A - Hãng A";
                            if (!ChallengeAction.ListAccRecive.ContainsKey(acc.Number_Id))
                            {
                                accJoinClub.Challenge = "pingpong.png";
                            }
                            else
                            {
                                accJoinClub.Challenge = "pingpong_invi.png";
                            }
                            accJoinClub.AddFriend = Helper.Instance().IsFriendImg(acc.Number_Id);
                            ListAccount.Add(accJoinClub);
                            if (!Helper.Instance().ListAcclocal.ContainsKey(acc.Number_Id))
                            {
                                Helper.Instance().ListAcclocal.Add(acc.Number_Id, accJoinClub);
                            }
                        }
                    }
                }
            }
        }
        public AccountMngVM()
        {
            AddAccountCmd = new RelayCommand <Button>((p) => { return(true); }, (p) =>
            {
                IsAdding = true;
                IsEnabledUserNameTextBox = true;
                IsEnabledTextBox         = true;
            });
            EditCommand = new RelayCommand <Button>((p) => { return(SelectedAccount == null ? false : true); }, (p) =>
            {
                IsAdding = false;
                IsEnabledUserNameTextBox = false;
                IsEnabledTextBox         = true;
            });
            SaveCommand = new RelayCommand <Button>((p) =>
            {
                if (IsEnabledTextBox && ((Password != null && Password2 != null && IsAdding) || !IsAdding))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }, (p) =>
            {
                IsEnabledTextBox         = false;
                IsEnabledUserNameTextBox = false;
                if (!IsAdding)
                {
                    var account = DataProvider.Ins.DB.TAIKHOANs.Where(x => x.TENTK == SelectedAccount.TENTK).SingleOrDefault();
                    if (account == null)
                    {
                        MessageBoxWindow mess2 = new MessageBoxWindow();
                        mess2.Tag = "Không tìm thấy tài khoản này";
                        mess2.ShowDialog();

                        // MessageBox.Show("Không tìm thấy tài khoản này", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                    if (Img != null)
                    {
                        Image           = ByteToImageConverter.Ins.ImageToByte(Img);
                        account.HINHANH = Image;
                    }
                    else
                    {
                        account.HINHANH = null;
                    }
                    account.TENTK      = AccountName;
                    account.TENHIENTHI = DisplayName;
                    account.LOAITK     = TypeAccount.IDType;

                    if (Password != null)
                    {
                        if (Password != Password2)
                        {
                            MessageBoxWindow mess2 = new MessageBoxWindow();
                            mess2.Tag = "Nhập lại mật khẩu không khớp với mật khẩu đã nhập!";
                            mess2.ShowDialog();

                            // MessageBox.Show("Nhập lại mật khẩu không khớp với mật khẩu đã nhập!", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            account.MATKHAU = Password;
                        }
                    }
                    else
                    {
                        account.MATKHAU = DataProvider.Ins.DB.TAIKHOANs.Where(x => x.TENTK == SelectedAccount.TENTK).SingleOrDefault().MATKHAU;
                    }
                    DataProvider.Ins.DB.SaveChanges();
                    Password2 = Password = null;
                    IsAdding  = true;
                }
                else
                {
                    if (Img != null)
                    {
                        Image = ByteToImageConverter.Ins.ImageToByte(Img);
                    }
                    else
                    {
                        Image = null;
                    }
                    var account = new TAIKHOAN()
                    {
                        TENTK = AccountName, TENHIENTHI = DisplayName, HINHANH = Image, LOAITK = TypeAccount.IDType, MATKHAU = Password
                    };
                    if (DataProvider.Ins.DB.TAIKHOANs.Where(x => x.TENTK == account.TENTK).Count() > 0)
                    {
                        MessageBoxWindow mess2 = new MessageBoxWindow();
                        mess2.Tag = "Tài khoản đã tồn tại!";
                        mess2.ShowDialog();

                        //MessageBox.Show("Tài khoản đã tồn tại!", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        if (Password != Password2)
                        {
                            MessageBoxWindow mess2 = new MessageBoxWindow();
                            mess2.Tag = "Nhập lại mật khẩu không khớp với mật khẩu đã nhập!";
                            mess2.ShowDialog();

                            //MessageBox.Show("Nhập lại mật khẩu không khớp với mật khẩu đã nhập!", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                        else
                        {
                            DataProvider.Ins.DB.TAIKHOANs.Add(account);
                            DataProvider.Ins.DB.SaveChanges();
                            ListAccount.Add(account);
                        }
                    }
                }
            });
            DeleteCommand = new RelayCommand <Button>((p) => { return(true); }, (p) =>
            {
                var account = DataProvider.Ins.DB.TAIKHOANs.Where(x => x.TENTK == SelectedAccount.TENTK).SingleOrDefault();
                DataProvider.Ins.DB.TAIKHOANs.Remove(account);
                DataProvider.Ins.DB.SaveChanges();

                ListAccount.Remove(SelectedAccount);
            });
            SearchCmd = new RelayCommand <TextBox>((p) => { return(true); }, (p) =>
            {
                if (p.Text != "")
                {
                    var newList = new ObservableCollection <TAIKHOAN>(DataProvider.Ins.DB.Database.SqlQuery <TAIKHOAN>("USP_TIMTKTHEOTEN @TEN", new SqlParameter("TEN", p.Text)));
                    ListAccount = newList;
                }
                else
                {
                    var newList = new ObservableCollection <TAIKHOAN>(DataProvider.Ins.DB.TAIKHOANs);
                    ListAccount = newList;
                }
            });
            PasswordChangedCommand  = new RelayCommand <PasswordBox>((p) => { return(true); }, (p) => { Password = p.Password; });
            Password2ChangedCommand = new RelayCommand <PasswordBox>((p) => { return(true); }, (p) => { Password2 = p.Password; });
            ListAccount             = new ObservableCollection <TAIKHOAN>(DataProvider.Ins.DB.TAIKHOANs);
            ListTypeAccount         = new ObservableCollection <TypeAccount>()
            {
                new TypeAccount(0), new TypeAccount(1)
            };
        }
Ejemplo n.º 3
0
        private async void Submit(string obj)
        {
            try
            {
                var newemp = new Account()
                {
                    Address   = Address,
                    Avatar    = ImgEmp.ConvertToByte(),
                    UserName  = UserName,
                    NameLogin = NameLogin,
                    Phone     = Phone,
                    DOB       = Convert.ToDateTime(DOB),
                };


                if (IsB)
                {
                    newemp.Sex = true;
                }
                if (IsG)
                {
                    newemp.Sex = false;
                }

                if (IsE == true)
                {
                    newemp.Role = 1;
                }

                if (string.IsNullOrEmpty(obj))
                {
                    //Create new customer

                    var objresult = await employee_Repo.Add(newemp);

                    if (objresult != null)
                    {
                        dc = new DialogContent()
                        {
                            Content = "Thêm Thành Công", Tilte = "Thông Báo"
                        };
                        dialog = new DialogOk()
                        {
                            DataContext = dc
                        };
                        DialogHost.CloseDialogCommand.Execute(null, null);
                        await DialogHost.Show(dialog, DialogHostId);

                        ListAccount.Add(objresult);
                    }
                    else
                    {
                        dc = new DialogContent()
                        {
                            Content = "Thêm Thất Bại", Tilte = "Thông Báo"
                        };
                        dialog = new DialogOk()
                        {
                            DataContext = dc
                        };
                        DialogHost.CloseDialogCommand.Execute(null, null);
                        await DialogHost.Show(dialog, DialogHostId);
                    }
                }
                else
                {
                    //update customer

                    newemp.EmpID = Convert.ToInt32(obj);

                    if (await employee_Repo.Update(newemp))
                    {
                        dc = new DialogContent()
                        {
                            Content = "Cập Nhật Thành Công", Tilte = "Thông Báo"
                        };
                        dialog = new DialogOk()
                        {
                            DataContext = dc
                        };
                        DialogHost.CloseDialogCommand.Execute(null, null);
                        await DialogHost.Show(dialog, DialogHostId);

                        ListAccount = new ObservableCollection <Account>(await employee_Repo.GetAllAsync());
                    }
                    else
                    {
                        dc = new DialogContent()
                        {
                            Content = "Cập Nhật Thất Bại", Tilte = "Thông Báo"
                        };
                        dialog = new DialogOk()
                        {
                            DataContext = dc
                        };
                        DialogHost.CloseDialogCommand.Execute(null, null);
                        await DialogHost.Show(dialog, DialogHostId);
                    }
                }
            }
            catch
            {
                dc.Content = "Có Lỗi";
                dc.Tilte   = "Thông Báo";
                dialog     = new DialogOk()
                {
                    DataContext = dc
                };
                DialogHost.CloseDialogCommand.Execute(null, null);
                await DialogHost.Show(dialog, DialogHostId);
            }
        }