private void btnSaveEdit_Click(object sender, RoutedEventArgs e)
        {
            /////////////////////////   VALIDATION OF THE USER INPUT   //////////////////
            if (!Validity.StringOK(txtName.Text))
            {
                GuiMsgs.Warning("Please Enter User Name");
            }
            else if (!Validity.StringOK(txtPassword.Text))
            {
                GuiMsgs.Warning("Please Enter Password");
            }
            else if (cmbType.SelectedIndex < 0)
            {
                GuiMsgs.Warning("Please select the User Type");
            }
            /////////////////////////   VALIDATION OF THE USER INPUT   //////////////////
            else //if all fields are OK
            {
                switch (EditMode)
                {
                case true:     //updating existing user
                    UserToAddOrEdit.Name     = txtName.Text;
                    UserToAddOrEdit.Password = txtPassword.Text;
                    UserToAddOrEdit.Type     = (User.eUserType)cmbType.SelectedItem;
                    this.Close();
                    break;

                case false:     //adding new user
                    UserToAddOrEdit = new User(txtName.Text, txtPassword.Text, (User.eUserType)cmbType.SelectedItem);
                    MainWindow.mainLibrary.LibraryUsers.Users.Add(UserToAddOrEdit);
                    this.Close();
                    break;
                }
            }
        }
        //Ctor of Login Dialog
        public LoginWindow()
        {
            InitializeComponent();
            //Try open the Data File and read the Info from it.
            try
            {
                //if there's file at all
                if (File.Exists(DBData.FilePath))
                {
                    MainWindow.mainLibrary = MainWindow.mainLibrary.GetBLData();
                }
                //if it's the first initiation of the program - because there's no data file
                else
                {
                    GuiMsgs.FirstLogin();
                }
            }
            //catching the possible Exception and showing to the user with warning sign
            catch (Exception ex)
            {
                GuiMsgs.Warning(ex.Message);
            }

            //Disable the login button until the user enters some characters
            //in both fields
            GuiChanges.Disable(btnLogin);

            txtUserName.HorizontalContentAlignment     =
                pswPassword.HorizontalContentAlignment = HorizontalAlignment.Center;

            pswPassword.PasswordChar = '*';

            //Focusing the keyboard into username field
            txtUserName.Focus();
        }
Exemple #3
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            /////////////////////////   VALIDATION OF THE USER INPUT   //////////////////
            if (CurrentItem == ItemType.Default)
            {
                GuiMsgs.Warning
                    ("Please Choose the Item Type:" +
                    "\nBook or Journal!");
            }
            //if Base category is choosen
            else if (cmbBaseCat.SelectedIndex < 0)
            {
                GuiMsgs.Warning("Please choose the Base Category!");
            }
            else if (!Validity.StringOK(txtName.Text))
            {
                GuiMsgs.Warning("Please Enter The Name of The Item!");
            }
            else if (dtPick.SelectedDate == null)
            {
                GuiMsgs.Warning("Please Select a Publishing Date!");
            }
            else
            {
                switch (CurrentItem)
                {
                case ItemType.Book:
                    if (!Validity.StringOK(txtAuthor.Text))
                    {
                        GuiMsgs.Warning("Please Enter The Author Name!");
                    }
                    else
                    {
                        CreateItem();
                        this.Close();
                    }
                    break;

                case ItemType.Journal:
                    if (!Validity.StringOK(txtIssue.Text))
                    {
                        GuiMsgs.Warning("Please Enter The Issue Number!");
                    }
                    else if (!Validity.PositiveInteger(txtIssue.Text))
                    {
                        GuiMsgs.Warning("Please Enter the valid Issue Number!");
                    }
                    else     //If All the fields are OK - create new Item and add him into the Library
                    {
                        CreateItem();
                        this.Close();
                    }
                    break;
                }
            }
            /////////////////////////   VALIDATION OF THE USER INPUT   //////////////////
        }
Exemple #4
0
        /// <summary>
        /// Validation method that checks if all the fields are valid
        /// before Update the Current Item
        /// </summary>
        /// <returns>true if the fields are OK and false if opposite</returns>
        private bool FieldsValidForUpdate()
        {
            if (!Validity.StringOK(txtName.Text))
            {
                GuiMsgs.Warning("Please enter the Item Name!");

                return(false);
            }
            else if (dtPick.SelectedDate == null)
            {
                GuiMsgs.Warning("Please Select the Publishing Date!");

                return(false);
            }
            else
            {
                switch (CurrentItem.ItemType)
                {
                case "Book":
                    if (!Validity.StringOK(txtAuthor.Text))
                    {
                        GuiMsgs.Warning("Please Enter the Author Name!");

                        return(false);
                    }
                    break;

                case "Journal":
                    if (!Validity.StringOK(txtIssue.Text))
                    {
                        GuiMsgs.Warning("Please Enter The Issue Number!");

                        return(false);
                    }
                    else if (!Validity.PositiveInteger(txtIssue.Text))
                    {
                        GuiMsgs.Warning("Please Enter the valid Issue Number!");

                        return(false);
                    }
                    break;
                }
            }
            return(true);
        }