public void ReturnItems(IList<PurchaseTransaction_Item> theItems, LoginSession theSession)
        {
            IList<ReturnTransactionItem> newItems = this.convertItemsToReturnItems(theItems);

            ReturnTransaction theTransaction = new ReturnTransaction
            {
                Employee_id = theSession.Id.ToString(),
                returnTime = DateTime.Now
            };

            var id = this.returnRepo.AddOne(theTransaction);

            foreach (var returnTransactionItem in newItems)
            {
                returnTransactionItem.ReturnTransactionId = id;
            }

            try
            {
                this.returnItemRepo.AddList(newItems);
            }
            catch (Exception)
            {
                this.DeleteTransaction(newItems, id);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AdminUC"/> class.
 /// </summary>
 /// <param name="theGrid">The grid.</param>
 /// <param name="theSession">The session.</param>
 public AdminUC(DataGridView theGrid, LoginSession theSession)
 {
     if (theSession.IsAdmin && theSession.IsAuthenticated)
     {
         DataGrid = theGrid;
         this.InitializeComponent();
         UserControlType = UserControls.Admin;
         this.theSession = theSession;
         this.theController = new GenericSqlController();
     }
 }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TransactionUC"/> class.
 /// </summary>
 /// <param name="theGrid">The grid.</param>
 /// <param name="session">The session.</param>
 public TransactionUC(DataGridView theGrid, LoginSession session)
 {
     this.DataGrid = theGrid;
     this.InitializeComponent();
     this.itemsToPurchase = new BindingList<PurchaseTransaction_Item>();
     this.session = session;
     this.DataGrid.RowsAdded += this.DataGridOnRowsChanged;
     this.DataGrid.RowsRemoved += this.DataGridOnRowsChanged;
     this.dateTimePicker1.MinDate = DateTime.Now;
     UserControlType = UserControls.Transaction;
 }
Beispiel #4
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            var theController = new EmployeeController();
            var id = 0;

            int.TryParse(this.usernameTextBox.Text, out id);

            DialogResult = DialogResult.None;

            if (id != 0)
            {
                var theUser = new LoginSession();
                try
                {
                    theUser = theController.ValidateUserOnNetwork(id, this.passwordTextBox.Text);
                }
                catch (Exception exception)
                {
                    ErrorHandler.DisplayErrorMessageToUserAndLog("Network Error",
                        "Unable to connect to SQL Database. Please try again.", exception);
                }

                if (theUser.IsAuthenticated)
                {
                    Tag = theUser;
                    DialogResult = DialogResult.OK;
                    Close();
                }
                else
                {
                    ErrorHandler.DisplayErrorBox("Login Error", "Invalid login information. Please try again.");
                }
            }
            else
            {
                ErrorHandler.DisplayErrorBox("Login Error", "Invalid login information. Please try again.");
            }
        }
Beispiel #5
0
        private void loginUser()
        {
            var loginWindow = new LoginForm();
            var loginResult = loginWindow.ShowDialog(this);

            if (loginResult == DialogResult.OK)
            {
                Enabled = true;
                Opacity = 100;
                this.loginSession = loginWindow.Tag as LoginSession;
                this.verifyAdminRights();
            }
            else
            {
                Close();
            }
        }
Beispiel #6
0
 private void proccessAdminParent(AdminUC adminUc)
 {
     if (adminUc != null && adminUc.theSession.IsAdmin && adminUc.theSession.IsAuthenticated)
     {
         this.theSession = adminUc.theSession;
         this.verifyAdminButtonsMainState();
     }
 }
Beispiel #7
0
        /// <summary>
        ///     Logs in the employee to database.
        /// </summary>
        /// <param name="theSession">The session.</param>
        /// <returns></returns>
        public LoginSession LoginEmployeeToDatabase(LoginSession theSession)
        {
            var sqlStatement = "SELECT id, IsAdmin FROM Employee WHERE id = @Username AND password = @Password";

            var connection = new MySqlConnection(this.CONNECTION_STRING);

            var command = new MySqlCommand(sqlStatement);

            command.Parameters.AddWithValue("@Username", theSession.Id);
            command.Parameters.AddWithValue("@Password", theSession.Password);

            command.Connection = connection;

            try
            {
                command.Connection.Open();

                var reader = command.ExecuteReader();

                theSession.IsAuthenticated = false;
                theSession.IsAdmin = false;

                if (reader.HasRows)
                {
                    reader.Read();

                    if (theSession.Id == (int) reader["id"])
                    {
                        theSession.IsAuthenticated = true;

                        if ((bool) reader["IsAdmin"])
                        {
                            theSession.IsAdmin = true;
                        }
                    }
                }
            }
            finally
            {
                command.Connection.Close();
            }

            return theSession;
        }
Beispiel #8
0
        /// <summary>
        ///     Adds the one.
        /// </summary>
        /// <param name="employee">The employee.</param>
        /// <param name="loginSession">The login session.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public void AddOne(Employee employee, LoginSession loginSession)
        {
            if (employee == null || loginSession == null || loginSession.Password == null)
            {
                throw new ArgumentNullException();
            }

            const string statement = "INSERT INTO Employee (fname, lname, phone, Address_id, IsAdmin, ssn, password)" +
                                     " VALUES (@Fname, @Lname, @Phone, @Address, @Admin, @Ssn, @Password)";

            var connection = new MySqlConnection(this.CONNECTION_STRING);

            using (var command = new MySqlCommand(statement))
            {
                command.Parameters.AddWithValue("@Fname", employee.FirstName);
                command.Parameters.AddWithValue("@Lname", employee.LastName);
                command.Parameters.AddWithValue("@Phone", employee.PhoneNumber);
                command.Parameters.AddWithValue("@Address", employee.EmployeeAddress.Id);
                command.Parameters.AddWithValue("@Admin", employee.IsAdmin);
                command.Parameters.AddWithValue("@Ssn", employee.SSN);
                command.Parameters.AddWithValue("@Password", loginSession.Password);

                command.Connection = connection;

                try
                {
                    command.Connection.Open();
                    command.ExecuteNonQuery();
                }
                finally
                {
                    command.Connection.Close();
                }
            }
        }
 /// <summary>
 /// Processes the parent intention.
 /// </summary>
 public override void processParentIntention()
 {
     this.theSession = (ParentParameter as TransactionUC)?.session;
 }