Exemplo n.º 1
0
 private void validateEmpty(object sender, RoutedEventArgs e)
 {
     try
     {
         if (sender.GetType().Name == "TextBox")
         {
             if (txtUserName.Text.Equals(""))
             {
                 HelpClass.SetValidate(p_errorUserName, "trEmptyUserNameToolTip");
             }
         }
         else if (sender.GetType().Name == "PasswordBox")
         {
             if (txtPassword.Password.Equals(""))
             {
                 HelpClass.SetValidate(p_errorPassword, "trEmptyPasswordToolTip");
             }
         }
     }
     catch (Exception ex)
     {
         HelpClass.ExceptionMessage(ex, this);
     }
 }
Exemplo n.º 2
0
        private async void btnLogIn_Click(object sender, RoutedEventArgs e)
        {//log in
            try
            {
                if (!logInProcessing)
                {
                    logInProcessing = true;

                    HelpClass.StartAwait(grid_main);

                    HelpClass.clearValidate(p_errorUserName);
                    HelpClass.clearValidate(p_errorPassword);

                    string password = Md5Encription.MD5Hash("Inc-m" + txtPassword.Password);
                    string userName = txtUserName.Text;

                    user = await userModel.Getloginuser(userName, password);

                    if (user.accountName == null)
                    {
                        //user does not exist
                        HelpClass.SetValidate(p_errorUserName, "trUserNotFound");
                    }
                    else
                    {
                        if (user.userId == 0)
                        {
                            //wrong password
                            HelpClass.SetValidate(p_errorPassword, "trWrongPassword");
                        }
                        else
                        {
                            //correct
                            //send user info to main window
                            MainWindow.userID    = user.userId;
                            MainWindow.userLogin = user;

                            #region check if menu is open
                            //try
                            //{
                            //    string m = await SectionData.getUserMenuIsOpen(user.userId);
                            //    if (!m.Equals("-1"))
                            //        MainWindow.menuIsOpen = m;
                            //    else
                            //        MainWindow.menuIsOpen = "close";
                            //    menuIsOpen = MainWindow.menuIsOpen;
                            //}
                            //catch
                            //{
                            //    MainWindow.menuIsOpen = "close";
                            //    menuIsOpen = MainWindow.menuIsOpen;
                            //}
                            #endregion

                            //make user online
                            user.isOnline = 1;

                            int s = await userModel.Save(user);

                            #region remember me
                            if (cbxRemmemberMe.IsChecked.Value)
                            {
                                Properties.Settings.Default.userName = txtUserName.Text;
                                Properties.Settings.Default.password = txtPassword.Password;
                                Properties.Settings.Default.Lang     = MainWindow.lang;
                                //Properties.Settings.Default.menuIsOpen = menuIsOpen;
                            }
                            else
                            {
                                Properties.Settings.Default.userName = "";
                                Properties.Settings.Default.password = "";
                                Properties.Settings.Default.Lang     = "";
                                //Properties.Settings.Default.menuIsOpen = "";
                            }
                            Properties.Settings.Default.Save();
                            #endregion
                            MainWindow.Region.countryId = 1;

                            MainWindow main = new MainWindow();

                            main.Show();
                            this.Close();
                        }
                    }

                    HelpClass.EndAwait(grid_main);
                    logInProcessing = false;
                }
            }
            catch (Exception ex)
            {
                HelpClass.EndAwait(grid_main);
                logInProcessing = false;
                HelpClass.ExceptionMessage(ex, this);
            }
        }
Exemplo n.º 3
0
        private async void Btn_update_Click(object sender, RoutedEventArgs e)
        {//update
            try
            {
                HelpClass.StartAwait(grid_main);
                if (package.packageId > 0)
                {
                    if (HelpClass.validate(requiredControlList, this))
                    {
                        bool isExist = await HelpClass.isCodeExist(tb_code.Text, "", "Packages", package.packageId);

                        if (!isExist)
                        {
                            package.packageCode = tb_code.Text.Trim();
                            package.packageName = tb_packageName.Text;
                            package.details     = tb_details.Text;
                            package.programId   = (int)cb_program.SelectedValue;
                            package.verId       = (int)cb_version.SelectedValue;

                            if (tgl_branch.IsChecked == true)
                            {
                                package.branchCount = -1;
                            }
                            else
                            {
                                if (tb_branchCount.Text.Equals("0"))
                                {
                                    package.branchCount = int.Parse("1");
                                }
                                else
                                {
                                    package.branchCount = int.Parse(tb_branchCount.Text);
                                }
                            }
                            if (tgl_store.IsChecked == true)
                            {
                                package.storeCount = -1;
                            }
                            else
                            {
                                if (tb_storeCount.Text.Equals("0"))
                                {
                                    package.storeCount = int.Parse("1");
                                }
                                else
                                {
                                    package.storeCount = int.Parse(tb_storeCount.Text);
                                }
                            }
                            if (tgl_pos.IsChecked == true)
                            {
                                package.posCount = -1;
                            }
                            else
                            {
                                if (tb_posCount.Text.Equals("0"))
                                {
                                    package.posCount = int.Parse("1");
                                }
                                else
                                {
                                    package.posCount = int.Parse(tb_posCount.Text);
                                }
                            }
                            if (tgl_user.IsChecked == true)
                            {
                                package.userCount = -1;
                            }
                            else
                            {
                                if (tb_userCount.Text.Equals("0"))
                                {
                                    package.userCount = int.Parse("1");
                                }
                                else
                                {
                                    package.userCount = int.Parse(tb_userCount.Text);
                                }
                            }
                            if (tgl_vendor.IsChecked == true)
                            {
                                package.vendorCount = -1;
                            }
                            else
                            {
                                if (tb_vendorCount.Text.Equals("0"))
                                {
                                    package.vendorCount = int.Parse("1");
                                }
                                else
                                {
                                    package.vendorCount = int.Parse(tb_vendorCount.Text);
                                }
                            }
                            if (tgl_customer.IsChecked == true)
                            {
                                package.customerCount = -1;
                            }
                            else
                            {
                                if (tb_customerCount.Text.Equals("0"))
                                {
                                    package.customerCount = int.Parse("1");
                                }
                                else
                                {
                                    package.customerCount = int.Parse(tb_customerCount.Text);
                                }
                            }
                            if (tgl_item.IsChecked == true)
                            {
                                package.itemCount = -1;
                            }
                            else
                            {
                                if (tb_itemCount.Text.Equals("0"))
                                {
                                    package.itemCount = int.Parse("1");
                                }
                                else
                                {
                                    package.itemCount = int.Parse(tb_itemCount.Text);
                                }
                            }
                            if (tgl_saleInv.IsChecked == true)
                            {
                                package.salesInvCount = -1;
                            }
                            else
                            {
                                if (tb_salesInvCount.Text.Equals("0"))
                                {
                                    package.salesInvCount = int.Parse("1");
                                }
                                else
                                {
                                    package.salesInvCount = int.Parse(tb_salesInvCount.Text);
                                }
                            }

                            package.notes        = tb_notes.Text;
                            package.isActive     = 1;
                            package.createUserId = MainWindow.userLogin.userId;
                            package.updateUserId = MainWindow.userLogin.userId;

                            int s = await package.Save(package);

                            if (s <= 0)
                            {
                                Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopError"), animation: ToasterAnimation.FadeIn);
                            }
                            else
                            {
                                Toaster.ShowSuccess(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trPopUpdate"), animation: ToasterAnimation.FadeIn);
                                resetRequiredControlList();
                                await RefreshPackagesList();
                                await Search();
                            }
                        }
                        else
                        {
                            HelpClass.SetValidate(p_error_code, "trDuplicateCodeToolTip");
                        }
                    }
                }
                else
                {
                    Toaster.ShowWarning(Window.GetWindow(this), message: MainWindow.resourcemanager.GetString("trSelectItemFirst"), animation: ToasterAnimation.FadeIn);
                }

                HelpClass.EndAwait(grid_main);
            }
            catch (Exception ex)
            {
                HelpClass.EndAwait(grid_main);
                HelpClass.ExceptionMessage(ex, this);
            }
        }