private async void DeleteCustomer(int?obj)
        {
            try
            {
                dc = new DialogContent()
                {
                    Content = "Bạn muốn xóa customer này ?", Tilte = "Thông Báo"
                };
                var dialogYS = new DialogYesNo()
                {
                    DataContext = dc
                };
                var result = (bool)await DialogHost.Show(dialogYS, DialogHostId);

                if (result)
                {
                    if (obj != null)
                    {
                        if (await customer_repo.Remove((int)obj))
                        {
                            ListCustomer.Remove(ListCustomer.SingleOrDefault(t => t.CusID == (int)obj));
                            dc = new DialogContent()
                            {
                                Content = "Xóa Thành Công", Tilte = "Thông Báo"
                            };
                            dialog = new DialogOk()
                            {
                                DataContext = dc
                            };
                            await DialogHost.Show(dialog, DialogHostId);
                        }
                        else
                        {
                            dc = new DialogContent()
                            {
                                Content = "Xóa Thất Bại", Tilte = "Thông Báo"
                            };
                            dialog = new DialogOk()
                            {
                                DataContext = dc
                            };
                            await DialogHost.Show(dialog, DialogHostId);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        static void Main(string[] args)
        {
            ListCustomer list  = new ListCustomer();
            var          test  = list.CreateNewDataBase("test", "password");
            var          test2 = list.LoadDataBase("test", "password");

            Customer cu1 = new Customer("Fristname", "Lastname", "email", 0, new DateTime());
            Customer cu2 = new Customer("Tobi", "Ww", "Email", 0, new DateTime());
            Customer cu3 = new Customer("Clemens", "Lasdetname", "email", 0, new DateTime());
            Customer cu4 = new Customer("Grunt", "Gg", "email", 0, new DateTime());

            list.AddCustomer(cu1);
            list.AddCustomer(cu2);
            list.AddCustomer(cu3);
            list.AddCustomer(cu4);

            list.UpdateDatabase();
        }
        private async void ShowInfoCus(int?obj)
        {
            if (obj != null)
            {
                var index = (int)obj;

                var cus = ListCustomer.SingleOrDefault(t => t.CusID == index);
                if (cus != null)
                {
                    Name   = cus.Name;
                    CusID  = cus.CusID.ToString();
                    ImgCus = cus.Avatar.LoadImage();
                    Phone  = cus.Phone;
                    if (cus.Sex == true)
                    {
                        IsB = true;
                    }
                    if (cus.Sex == false)
                    {
                        IsG = true;
                    }
                    Address = cus.Address;
                    Email   = cus.Email;
                    if (cus.Kind != null)
                    {
                        int indexcus = (int)cus.Kind;
                        Kind = ListKinds.ElementAt(indexcus);
                    }
                    else
                    {
                        Kind = null;
                    }
                }

                await DialogHost.Show(new CustomerProfile(), DialogHostId);
            }
        }
示例#4
0
 /// <summary>
 /// For clearing user information from controls
 /// </summary>
 public void ClearUserInfo()
 {
     try
     {
         CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgStart, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
         UserID       = null;
         UserName     = null;
         Password     = null;
         Email        = null;
         IsActive     = null;
         FirstName    = null;
         LastName     = null;
         LastLogin    = null;
         Phone        = null;
         ListCustomer = ListCustomer.Select(x => new UserCustomerList {
             CustomerName = x.CustomerName, CustomerID = x.CustomerID, IsSelected = false
         }).ToList();
         ListModule = ListModule.Select(x => new ModuleList {
             ModuleID = x.ModuleID, ModuleName = x.ModuleName, IsSelected = false, ModuleCode = x.ModuleCode
         }).ToList();
         ListRole = ListRole.Select(x => new RoleList {
             RoleID = x.RoleID, RoleName = x.RoleName, Description = x.Description, IsSelected = false
         }).ToList();
         ListGroup = ListGroup.Select(x => new GroupList {
             GroupID = x.GroupID, GroupName = x.GroupName, Description = x.Description, IsSelected = false
         }).ToList();
     }
     catch (Exception ex)
     {
         CommonSettings.logger.LogError(this.GetType(), ex);
     }
     finally
     {
         CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgEnd, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
     }
 }
示例#5
0
        public CustomerMngViewVM()
        {
            IsEnabledListView = true;
            IsAdding          = true;
            AddCommand        = new RelayCommand <Button>((p) => { return(true); }, (p) =>
            {
                IsEnabledListView  = false;
                IsEnabledTextBox   = true;
                IsEnabledIDTextBox = true;

                ID = DataProvider.Ins.DB.Database.SqlQuery <string>("MAKHTIEPTHEO").First();
            });
            SaveCommand = new RelayCommand <Button>((p) =>
            {
                if (!IsEnabledListView)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }, (p) =>
            {
                IsEnabledListView  = true;
                IsEnabledTextBox   = false;
                IsEnabledIDTextBox = false;
                if (!IsAdding)
                {
                    var customer = DataProvider.Ins.DB.KHACHHANGs.Where(x => x.MAKH == SelectedItem.MAKH).SingleOrDefault();
                    if (customer == null)
                    {
                        MessageBox.Show("Không tìm thấy khách hàng này", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                    customer.TENKH       = NameOfCustomer;
                    customer.DIACHI      = Address;
                    customer.SODIENTHOAI = PhoneNumber;
                    customer.EMAIL       = Mail;
                    customer.TIENNO      = Debt;
                    try
                    {
                        DataProvider.Ins.DB.SaveChanges();
                        ListCustomer = new ObservableCollection <KHACHHANG>(DataProvider.Ins.DB.Database.SqlQuery <KHACHHANG>("GET_KH").OrderByDescending(x => x.MAKH == ID));
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Trường giá trị vượt quá giới hạn cho phép", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                    }

                    IsAdding = true;
                }
                else
                {
                    var customer = new KHACHHANG()
                    {
                        MAKH = ID, TENKH = NameOfCustomer, DIACHI = Address, EMAIL = Mail, SODIENTHOAI = PhoneNumber, TIENNO = Debt
                    };
                    if (DataProvider.Ins.DB.KHACHHANGs.Where(x => x.MAKH == customer.MAKH).Count() > 0)
                    {
                        MessageBox.Show("Mã Khách hàng đã tồn tại!", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    else
                    {
                        DataProvider.Ins.DB.KHACHHANGs.Add(customer);

                        try
                        {
                            DataProvider.Ins.DB.SaveChanges();
                            ListCustomer.Add(customer);
                            ListCustomer = new ObservableCollection <KHACHHANG>(DataProvider.Ins.DB.Database.SqlQuery <KHACHHANG>("GET_KH").OrderByDescending(x => x.MAKH == ID));
                        }
                        catch (Exception)
                        {
                            MessageBox.Show("Trường giá trị vượt quá giới hạn cho phép", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                }
            });
            EditCommand = new RelayCommand <Button>((p) => { return(true); }, (p) =>
            {
                IsAdding           = false;
                IsEnabledListView  = false;
                IsEnabledTextBox   = true;
                IsEnabledIDTextBox = false;
            });
            DeleteCommand = new RelayCommand <Button>((p) => { return(true); }, (p) =>
            {
                var customer = DataProvider.Ins.DB.KHACHHANGs.Where(x => x.MAKH == SelectedItem.MAKH).SingleOrDefault();
                DataProvider.Ins.DB.KHACHHANGs.Remove(customer);
                try
                {
                    DataProvider.Ins.DB.SaveChanges();

                    ListCustomer.Remove(SelectedItem);
                }
                catch (Exception)
                {
                    MessageBox.Show("Không thể xóa khách hàng này", "Lỗi", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            });
            SearchCmd = new RelayCommand <TextBox>((p) => { return(true); }, (p) =>
            {
                if (p.Text != "")
                {
                    var newList  = new ObservableCollection <KHACHHANG>(DataProvider.Ins.DB.Database.SqlQuery <KHACHHANG>("USP_TIMKHTHEOTEN @TEN", new SqlParameter("TEN", p.Text)));
                    ListCustomer = newList;
                }
                else
                {
                    var newList  = new ObservableCollection <KHACHHANG>(DataProvider.Ins.DB.KHACHHANGs);
                    ListCustomer = newList;
                }
            });
            ListCustomer = new ObservableCollection <KHACHHANG>(DataProvider.Ins.DB.KHACHHANGs);
        }
        private async void Submit(string obj)
        {
            try
            {
                var newcus = new Customer()
                {
                    Email   = Email,
                    Address = Address,
                    Avatar  = ImgCus.ConvertToByte(),
                    Name    = Name,
                    Phone   = Phone,
                };


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

                if (Kind != null)
                {
                    newcus.Kind = ListKinds.IndexOf(Kind);
                }

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

                    var objresult = await customer_repo.Add(newcus);

                    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);

                        ListCustomer.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

                    newcus.CusID = Convert.ToInt32(obj);

                    if (await customer_repo.Update(newcus))
                    {
                        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);

                        ListCustomer = new ObservableCollection <Customer>(await customer_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);
            }
        }
示例#7
0
        private void CustomerList_Click(object sender, RoutedEventArgs e)
        {
            ListCustomer customerListPage = new ListCustomer();

            MainFrame.Navigate(customerListPage);
        }
示例#8
0
        /// <summary>
        /// Function to Save/Update a particular user.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>NA</returns>
        /// <createdBy></createdBy>
        /// <createdOn>May-27,2016</createdOn>
        public void Save_Click(object obj)
        {
            try
            {
                CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgStart, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));

                WebPortalUserList objUserProp = new WebPortalUserList();

                if (UserID != null && UserID > 0)
                {
                    objUserProp.userID = (int)UserID;
                }

                objUserProp.username    = UserName;
                objUserProp.password    = Password;
                objUserProp.firstname   = FirstName;
                objUserProp.lastname    = LastName;
                objUserProp.email       = Email;
                objUserProp.phone       = Phone;
                objUserProp.isActive    = IsActive;
                objUserProp.isSuperUser = 0;
                objUserProp.lastLogin   = DateTime.Now;
                if (IsAction == Resources.ActionSave)
                {
                    objUserProp.whoCreated  = Application.Current.Properties["LoggedInUserName"].ToString();
                    objUserProp.dateCreated = DateTime.Now;
                }
                else if (IsAction == Resources.ActionUpdate)
                {
                    objUserProp.whoModified  = Application.Current.Properties["LoggedInUserName"].ToString();
                    objUserProp.dateModified = DateTime.Now;
                }

                if (!string.IsNullOrEmpty(UserName))
                {
                    if (!string.IsNullOrEmpty(Password))
                    {
                        if (!string.IsNullOrEmpty(Email))
                        {
                            ValidateEmail emailValidation = new ValidateEmail();
                            bool          isValid         = emailValidation.IsValidEmail(Email);
                            if (isValid)
                            {
                                bool checkDuplicateUserName = _serviceInstance.CheckDuplicateEmail(Email);
                                bool checkDuplicateEmailID  = _serviceInstance.CheckDuplicatePortalUserName(UserName);
                                bool isSuccessfull          = false;
                                if (IsAction == Resources.ActionSave)
                                {
                                    if (!checkDuplicateUserName)
                                    {
                                        if (!checkDuplicateEmailID)
                                        {
                                            isSuccessfull = _serviceInstance.InsertUpdateUser(objUserProp, ListCustomer.ToArray(), ListModule.ToArray(), ListRole.ToArray(), ListGroup.ToArray());
                                        }
                                        else
                                        {
                                            MessageBox.Show(Resources.MsgDuplicateUserName);
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show(Resources.MsgDuplicateEmailID);
                                    }
                                }
                                else if (IsAction == Resources.ActionUpdate)
                                {
                                    isSuccessfull = _serviceInstance.InsertUpdateUser(objUserProp, ListCustomer.ToArray(), ListModule.ToArray(), ListRole.ToArray(), ListGroup.ToArray());
                                }

                                if (isSuccessfull)
                                {
                                    if (IsAction == Resources.ActionUpdate)
                                    {
                                        MessageBox.Show(Resources.msgUpdatedSuccessfully);
                                    }
                                    else if (IsAction == Resources.ActionSave)
                                    {
                                        MessageBox.Show(Resources.msgInsertedSuccessfully);
                                    }
                                    ClearUserInfo();
                                    CurrentView   = new WebPortalUsersView();
                                    IsVisibleInfo = Resources.MsgHidden;
                                    IsModify      = true;
                                    IsButtonPanel = Resources.MsgHidden;
                                    IsAction      = Resources.ActionSave;
                                    LoadUsers(null);
                                    View_Click(null);
                                    AcceptChanges();
                                }
                            }
                            else
                            {
                                MessageBox.Show(Resources.ErrorEmail);
                            }
                        }
                        else
                        {
                            MessageBox.Show(Resources.ReqEmail);
                        }
                    }
                    else
                    {
                        MessageBox.Show(Resources.ReqPassword);
                    }
                }
                else
                {
                    MessageBox.Show(Resources.ReqrUserName);
                }
            }
            catch (Exception ex)
            {
                CommonSettings.logger.LogError(this.GetType(), ex);
            }
            finally
            {
                CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgEnd, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
            }
        }