Beispiel #1
0
        private void Btn_DeleteUser_Click(object sender, RoutedEventArgs e)
        {
            var resultMsg = MessageBox.Show("Selected user will delete.\n\nAre you sure?", "Delete User", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (resultMsg == MessageBoxResult.Yes)
            {
                var result = db.DeleteUser((long)cb_users.SelectedValue);
                switch (result)
                {
                case 1:
                    notifyCall = new NotificationPanelCall("Delete User", "Successfully deleted", StatusColor.Success, 3);
                    UnloadAllFields();
                    cb_users.SelectedIndex = -1;
                    LoadUsers();
                    cb_users.IsEnabled     = true;
                    wp_editPanel.IsEnabled = false;
                    break;

                case 0:
                    notifyCall = new NotificationPanelCall("Error", "User not found", StatusColor.Error, 3);
                    CustomAnimations.ShakeAnimation(this);
                    break;

                case -1:
                    notifyCall = new NotificationPanelCall("Error", "Something went wrong", StatusColor.Error, 3);
                    CustomAnimations.ShakeAnimation(this);
                    break;

                default:
                    break;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Set view as connection status
        /// </summary>
        /// <param name="connected">is connected</param>
        private void ConnectionStatus(bool connected)
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                if (connected)
                {
                    img_ConnectionStatus.Source        = new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/Scada.wpf;component/" + "Assets/img/icons/b-Link-50.png", UriKind.Absolute));
                    Lbl_PlcStatus.Content        = "Connected";
                    img_ReConnectToPLC.IsEnabled = false;
                    notifyCall = new NotificationPanelCall("Connection", "Connected the device", StatusColor.Success, 3);
                }
                else
                {
                    img_ConnectionStatus.Source        = new BitmapImage(new Uri(@"pack://*****:*****@"pack://application:,,,/Scada.wpf;component/" + "Assets/img/icons/b-Broken Link-64.png", UriKind.Absolute));
                    Lbl_PlcStatus.Content        = "No Connection";
                    img_ReConnectToPLC.IsEnabled = true;
                }

                img_ConnectionStatus2.Source = img_ConnectionStatus.Source;
                img_ConnectionStatus3.Source = img_ConnectionStatus.Source;
                Lbl_PlcAddress.Content       = SetPLC.Default.Profinet_IP;
                Lbl_PlcName.Content          = SetPLC.Default.Profinet_DeviceName;
                Lbl_PlcName2.Content         = Lbl_PlcName.Content;
                Lbl_PlcStatus2.Content       = Lbl_PlcStatus.Content;
                Lbl_PlcAddress2.Content      = Lbl_PlcAddress.Content;
            });
        }
Beispiel #3
0
 /// <summary>
 /// Thread Method
 /// </summary>
 private void ReadTest()
 {
     try
     {
         bool threadRun = true;
         while (threadRun)
         {
             try
             {
                 Lbl_TestResult.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate()
                 {
                     notifyCall = new NotificationPanelCall("Test", "Unable to read data from [" + StrAddress + "]", StatusColor.Error, 3);
                     threadRun  = false;
                     TestStop();
                 });
                 Thread.Sleep(200);
             }
             catch (ThreadAbortException)
             {
                 threadRun = false;
             }
         }
     }
     finally
     {
     }
 }
Beispiel #4
0
        /// <summary>
        /// Test Start Method
        /// </summary>
        private void TestStart()
        {
            readTestThread = new Thread(new ThreadStart(ReadTest));
            readTestThread.IsBackground = true;
            //if (readTestThread != null && !readTestThread.IsAlive)

            btn_TestStart.Content = "Read Stop";
            notifyCall            = new NotificationPanelCall("Test", "Test started. Address : [" + StrAddress + "]", StatusColor.Success, 3);
            readTestThread.Start();
        }
Beispiel #5
0
        private void SetInterfaceSettings()
        {
            SetInterface.Default.AlwaysOnTop            = (bool)Cb_AlwaysOnTop.IsChecked;
            SetInterface.Default.PreventWindowMinimized = (bool)Cb_PreventMinimized.IsChecked;
            SetInterface.Default.PreventWindowResize    = (bool)Cb_PreventResize.IsChecked;
            SetInterface.Default.PreventClose           = (bool)Cb_PreventClose.IsChecked;
            SetInterface.Default.HideIconOnTaskbar      = (bool)Cb_HideIconOnTaskbar.IsChecked;
            SetInterface.Default.Save();

            OnChangedInterfaceSettings?.Invoke(); // Event Trigger
            notifyCall = new NotificationPanelCall("Save Settings", "Successfully saved", StatusColor.Success, 3);
        }
Beispiel #6
0
        private void SetGeneralSettings()
        {
            SetGeneral.Default.AppStartWithWindows    = (bool)Cb_StartWithWindows.IsChecked;
            SetGeneral.Default.AutoReconnectToPLC     = (bool)Cb_AutoConnect.IsChecked;
            SetGeneral.Default.AutoReconnectPeriod    = TypeControls.CheckStrToInt(Txt_AutoConnectPeriod.Text, 10);
            SetGeneral.Default.AutoRecordWhenAppStart = (bool)Cb_AutoDBRecord.IsChecked;
            SetGeneral.Default.AutoRecordPeriod       = TypeControls.CheckStrToInt(Txt_AutoDBRecord.Text, 600);
            SetGeneral.Default.Save();

            OnChangedGeneralSettings?.Invoke(); // Event Trigger
            notifyCall = new NotificationPanelCall("Save Settings", "Successfully saved", StatusColor.Success, 3);
        }
Beispiel #7
0
        /// <summary>
        /// Menu Button : Logout Action
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Img_LogoutBtn_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (dataContextMainWindow.UserInfo.Authorization > 0)
            {
                dataContextMainWindow.UserInfo = UserInfo.InvalidUser;

                notifyCall = new NotificationPanelCall("Logout", "Successful", StatusColor.Success, 3);
            }

            cv_ContentUC.Children.Clear();
            createUserUC = null;

            InitializeStatus();
        }
Beispiel #8
0
        private void Btn_signIn(object sender, RoutedEventArgs e)
        {
            userRecord = new User();
            db         = new core.DB();

            #region user data transfer to MainWindow

            mainWindow = (IUserInfoTransfer)Application.Current.MainWindow;
            if (txt_uName.Text != "" && txt_uPass.Password != "")
            {
                if (db.SignIn(txt_uName.Text, txt_uPass.Password, out userRecord))
                {
                    mainWindow.Transfer(userRecord);
                    notifyCall = new NotificationPanelCall("Login", "Successfully logged in", StatusColor.Success, 3);
                    RemoveThis();
                }
                else
                {
                    lbl_WarningMessage.Visibility = Visibility.Hidden;

                    CustomAnimations.ShakeAnimation(this);
                    if (MainWindow.dataContextMainWindow.UserInfo.Authorization != 0)
                    {
                        mainWindow.Transfer(new User()
                        {
                            User_ID = 0, UserName = "******", Authorization = 0, SuperUser = false
                        });                                                                                                   // Default Data Transfer
                        notifyCall = new NotificationPanelCall("Invalid User", "Username or password is wrong. (+) Current session closed", StatusColor.Warning, 3);
                    }
                    else
                    {
                        notifyCall = new NotificationPanelCall("Invalid User", "Username or password is wrong", StatusColor.Error, 3);
                    }

                    txt_uPass.Password = "";
                    txt_uPass.Focus();
                }
            }
            else
            {
                lbl_WarningMessage.Content    = "fields should not be null";
                lbl_WarningMessage.Visibility = Visibility.Visible;
            }
            #endregion
        }
Beispiel #9
0
 /// <summary>
 /// from CommInterface
 /// </summary>
 private void PlcCommunication_OnDisconnected()
 {
     ConnectionStatus(false);
     notifyCall = new NotificationPanelCall("Connection Failed", "Device is disconnected", StatusColor.Error, 3);
 }
Beispiel #10
0
 /// <summary>
 /// from CommInterface
 /// </summary>
 private void PlcCommunication_OnCouldNotConnect()
 {
     ConnectionStatus(false);
     notifyCall = new NotificationPanelCall("Connection Failed", "Could not connect the device", StatusColor.Error, 3);
 }
        private void Btn_SaveMyProfil_Click(object sender, RoutedEventArgs e)
        {
            lbl_WarningMessage.Content    = "fields should not be empty";
            lbl_WarningMessage.Visibility = CheckEmpty() ? Visibility.Visible : Visibility.Hidden;

            if (!CheckEmpty())
            {
                var currentPass = txt_CurrentUPass_new.Password;
                if (CurrentUser.UserPassword != currentPass)
                {
                    lbl_WarningMessage.Content    = "current password is faulty";
                    lbl_WarningMessage.Visibility = Visibility.Visible;
                    txt_CurrentUPass_new.Password = "";
                    txt_CurrentUPass_new.Focus();
                }
                else
                {
                    if (PassDontMatch())
                    {
                        lbl_WarningMessage.Content    = "passwords do not match";
                        lbl_WarningMessage.Visibility = txt_uPass_new.Password != txt_RuPass_new.Password ? Visibility.Visible : Visibility.Hidden;
                        CustomAnimations.ShakeAnimation(this);
                        txt_RuPass_new.Password = "";
                        txt_RuPass_new.Focus();
                    }
                    else
                    {
                        User user = new User
                        {
                            User_ID       = CurrentUser.User_ID,
                            UserName      = txt_uName_new.Text,
                            UserPassword  = (txt_uPass_new.Password != "") ? txt_uPass_new.Password : CurrentUser.UserPassword,
                            SuperUser     = false,
                            Enable        = true,
                            Authorization = CurrentUser.Authorization,
                            Email         = txt_eMail_new.Text,
                            Name          = txt_name_new.Text,
                            SecondName    = txt_secondName_new.Text,
                            Surname       = txt_surname_new.Text,
                            Title         = txt_title_new.Text,
                            Position      = txt_position_new.Text,
                            PhotoAddress  = "",
                            CardID        = txt_cardID_new.Text,
                            DateTime      = CurrentUser.DateTime
                        };

                        using (db = new DB("UsersDB", ""))
                        {
                            var result = db.UpdateUser(ref user, CurrentUser.User_ID);
                            switch (result)
                            {
                            case 1:
                                notifyCall = new NotificationPanelCall("Update User", "Successfully updated", StatusColor.Success, 3);
                                RemoveThis();
                                txt_CurrentUPass_new.Password = "";
                                // UnloadAllFields();
                                break;

                            case 0:
                                notifyCall = new NotificationPanelCall("Error", "Something went wrong", StatusColor.Error, 3);
                                CustomAnimations.ShakeAnimation(this);
                                break;

                            case -1:
                                notifyCall = new NotificationPanelCall("Error", "User is not found", StatusColor.Error, 3);
                                CustomAnimations.ShakeAnimation(this);
                                txt_uName_new.Text = "";
                                txt_uName_new.Focus();
                                break;

                            case -2:
                                notifyCall = new NotificationPanelCall("Error", "Same User already exist", StatusColor.Error, 3);
                                CustomAnimations.ShakeAnimation(this);
                                txt_uName_new.Text = "";
                                txt_uName_new.Focus();
                                break;

                            default:
                                CustomAnimations.ShakeAnimation(this);
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                CustomAnimations.ShakeAnimation(this);
                txt_CurrentUPass_new.Focus();
            }
        }
Beispiel #12
0
        private void Btn_SaveUser_Click(object sender, RoutedEventArgs e)
        {
            lbl_WarningMessage.Content    = "fields should not be empty";
            lbl_WarningMessage.Visibility = CheckEmpty() ? Visibility.Visible : Visibility.Hidden;

            if (!CheckEmpty())
            {
                var currentPass = core.CryptorEngine.Encrypt(txt_CurrentUPass_new.Password, true);
                if (CurrentUser.UserPassword != currentPass)
                {
                    lbl_WarningMessage.Content    = "your password is faulty";
                    lbl_WarningMessage.Visibility = Visibility.Visible;
                    txt_CurrentUPass_new.Password = "";
                    txt_CurrentUPass_new.Focus();
                }
                else
                {
                    if (PassDontMatch())
                    {
                        lbl_WarningMessage.Content    = "passwords do not match";
                        lbl_WarningMessage.Visibility = txt_uPass_new.Password != txt_RuPass_new.Password ? Visibility.Visible : Visibility.Hidden;
                        CustomAnimations.ShakeAnimation(this);
                        txt_RuPass_new.Password = "";
                        txt_RuPass_new.Focus();
                    }
                    else
                    {
                        User user = new User
                        {
                            User_ID       = SelectedUser.User_ID,
                            UserName      = txt_uName_new.Text,
                            UserPassword  = txt_uPass_new.Password,
                            SuperUser     = false,
                            Enable        = true,
                            Authorization = (short)cb_auth_new.SelectedValue,
                            Email         = txt_eMail_new.Text,
                            Name          = txt_name_new.Text,
                            SecondName    = txt_secondName_new.Text,
                            Surname       = txt_surname_new.Text,
                            Title         = txt_title_new.Text,
                            Position      = txt_position_new.Text,
                            PhotoAddress  = "",
                            CardID        = txt_cardID_new.Text,
                            DateTime      = DateTime.Now
                        };

                        using (db = new core.DB())
                        {
                            var result = (int)db.UpdateUser(user);
                            switch (result)
                            {
                            case 1:
                                notifyCall = new NotificationPanelCall("Update User", "Successfully updated", StatusColor.Success, 3);
                                RemoveThis();
                                txt_CurrentUPass_new.Password = "";
                                Btn_CancelUpdate_Click(sender, e);
                                LoadUsers();
                                break;

                            case 0:
                                notifyCall = new NotificationPanelCall("Error", "Something went wrong", StatusColor.Error, 3);
                                CustomAnimations.ShakeAnimation(this);
                                break;

                            case -1:
                                notifyCall = new NotificationPanelCall("Error", "User is not found", StatusColor.Error, 3);
                                CustomAnimations.ShakeAnimation(this);
                                txt_uName_new.Text = "";
                                txt_uName_new.Focus();
                                break;

                            case -2:
                                notifyCall = new NotificationPanelCall("Error", "Same User already exist", StatusColor.Error, 3);
                                CustomAnimations.ShakeAnimation(this);
                                txt_uName_new.Text = "";
                                txt_uName_new.Focus();
                                break;

                            default:
                                CustomAnimations.ShakeAnimation(this);
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                CustomAnimations.ShakeAnimation(this);
            }
        }
        private void Btn_CreateUser_Click(object sender, RoutedEventArgs e)
        {
            lbl_WarningMessage.Content    = "fields should not be empty";
            lbl_WarningMessage.Visibility = CheckEmpty() ? Visibility.Visible : Visibility.Hidden;

            if (!CheckEmpty())
            {
                if (txt_uPass_new.Password != txt_RuPass_new.Password)
                {
                    lbl_WarningMessage.Content    = "passwords do not match";
                    lbl_WarningMessage.Visibility = txt_uPass_new.Password != txt_RuPass_new.Password ? Visibility.Visible : Visibility.Hidden;
                    CustomAnimations.ShakeAnimation(this);
                }
                else
                {
                    User user = new User
                    {
                        UserName      = txt_uName_new.Text,
                        UserPassword  = txt_uPass_new.Password,
                        SuperUser     = false,
                        Enable        = true,
                        Authorization = (short)cb_auth_new.SelectedValue,
                        Email         = txt_eMail_new.Text,
                        Name          = txt_name_new.Text,
                        SecondName    = txt_secondName_new.Text,
                        Surname       = txt_surname_new.Text,
                        Title         = txt_title_new.Text,
                        Position      = txt_position_new.Text,
                        PhotoAddress  = "",
                        CardID        = txt_cardID_new.Text,
                        DateTime      = DateTime.Now
                    };

                    using (db = new core.DB())
                    {
                        var result = db.AddUser(user);
                        switch (result)
                        {
                        case 1:
                            notifyCall = new NotificationPanelCall("Create User", "Successfully created", StatusColor.Success, 3);
                            RemoveThis();
                            UnloadAllFields();
                            break;

                        case 0:
                            notifyCall = new NotificationPanelCall("Error", "Something went wrong", StatusColor.Error, 3);
                            CustomAnimations.ShakeAnimation(this);
                            break;

                        case -1:
                            notifyCall = new NotificationPanelCall("Error", "Same User already exist", StatusColor.Error, 3);
                            CustomAnimations.ShakeAnimation(this);
                            txt_uName_new.Text = "";
                            txt_uName_new.Focus();
                            break;

                        default:
                            CustomAnimations.ShakeAnimation(this);
                            break;
                        }
                    }
                }
            }
            else
            {
                CustomAnimations.ShakeAnimation(this);
            }
        }
Beispiel #14
0
 private void NotificationShow(string Title, string Message, core.StatusColor Status, int Second)
 {
     notifyCall = new NotificationPanelCall(Title, Message, Status, Second);
 }