Ejemplo n.º 1
0
 private void processPurchaseTransactionItemChild(PurchaseTransactionItemUC purchaseTransactionItemUc)
 {
     if (purchaseTransactionItemUc != null && purchaseTransactionItemUc.SelectedItem != null)
     {
         this.SelectedItem = purchaseTransactionItemUc.SelectedItem;
         CurrentState = RentMeUserControlPrimaryStates.Deleting;
     }
 }
Ejemplo n.º 2
0
        private void selectItemButton_Click(object sender, EventArgs e)
        {
            if (DataGrid.SelectedRows.Count == 0)
            {
                ErrorHandler.DisplayErrorBox("No Item Selected", "Please select an item to return.");
            }else if (this.quantityTextBox.Text == "")
            {
                ErrorHandler.DisplayErrorBox("Quantity Not Specified", "Please set the quantity of the item you would like to return.");
            }
            else
            {
                this.SelectedItem = DataGrid.SelectedRows[0].DataBoundItem as PurchaseTransaction_Item;

                try
                {
                    int quantity = int.Parse(this.quantityTextBox.Text);
                    if (quantity > this.SelectedItem.ReturnableQuantity || quantity <= 0)
                        throw new ArgumentException();
                    this.SelectedItem.Quantity = quantity;
                }
                catch (ArgumentException)
                {
                    if (this.SelectedItem.ReturnableQuantity == 0)
                    {
                        ErrorHandler.DisplayErrorBox("Quantity Error", "Those items have already been returned.");
                    }
                    else
                    {
                        ErrorHandler.DisplayErrorBox("Quantity Error", "You must select a non-zero value less than or equal to " + this.SelectedItem.ReturnableQuantity + ".");
                    }
                    return;
                }
                catch
                {
                    ErrorHandler.DisplayErrorBox("Invalid Quantity","Please enter a valid quantity.");
                    return;
                }
                CurrentState = RentMeUserControlPrimaryStates.Deleting;
            }
        }
Ejemplo n.º 3
0
 private void cancelButton_Click(object sender, EventArgs e)
 {
     this.SelectedItem = null;
     CurrentState = RentMeUserControlPrimaryStates.Deleting;
 }
 /// <summary>
 /// Adds one item to the database.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns></returns>
 /// <exception cref="NotImplementedException"></exception>
 public string AddOne(PurchaseTransaction_Item item)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Gets all items by purchase transaction.
        /// </summary>
        /// <param name="transaction">The transaction.</param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public IList<PurchaseTransaction_Item> GetAllItemsByPurchaseTransaction(PurchaseTransaction transaction)
        {
            if (transaction == null)
            {
                throw new ArgumentNullException();
            }

            var items = new List<PurchaseTransaction_Item>();

            var query = "SELECT PurchaseTransaction_Item.*, Furniture.name AS FurnitureName, ReturnTransaction_Item.ReturnTransaction_id, SUM(ReturnTransaction_Item.quantity) AS ReturnedQuantity " +
                        "FROM PurchaseTransaction_Item " +
                        "INNER JOIN Furniture " +
                        "ON PurchaseTransaction_Item.Furniture_id=Furniture.id " +
                        "LEFT JOIN ReturnTransaction_Item " +
                        "ON PurchaseTransaction_Item.PurchaseTransaction_id=ReturnTransaction_Item.PurchaseTransaction_Item_PurchaseTransaction_id AND PurchaseTransaction_Item.Furniture_id = ReturnTransaction_Item.PurchaseTransaction_Item_Furniture_id " +
                        "WHERE PurchaseTransaction_id=@Id " +
                        "GROUP BY PurchaseTransaction_Item.Furniture_id, PurchaseTransaction_Item.PurchaseTransaction_id";

            var connection = new MySqlConnection(this.CONNECTION_STRING);

            using (var command = new MySqlCommand(query))
            {
                command.Parameters.AddWithValue("@Id", transaction.Id);

                command.Connection = connection;

                try
                {
                    command.Connection.Open();

                    var reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        var item = new PurchaseTransaction_Item
                        {
                            PurchaseTransactionId = transaction.Id,
                            FurnitureId =
                                reader["Furniture_id"] == DBNull.Value ? "NULL" : reader["Furniture_id"].ToString(),
                            Quantity = reader["quantity"] == DBNull.Value ? 0 : (int) reader["quantity"],
                            LeaseTime = reader["leaseTime"] == DBNull.Value ? 0 : (int) reader["leaseTime"],
                            FurnitureName = reader["FurnitureName"] == DBNull.Value ? "NULL" : reader["FurnitureName"].ToString()
                        };

                        var returnedQuantity = reader["ReturnedQuantity"] == DBNull.Value ? 0: Int32.Parse(reader["ReturnedQuantity"].ToString());


                        if (reader["ReturnTransaction_id"] != DBNull.Value)
                        {
                            item.ReturnableQuantity = item.Quantity - returnedQuantity;
                        }
                        else
                        {
                            item.ReturnableQuantity = item.Quantity;
                        }

                        items.Add(item);
                    }

                }
                finally
                {
                    command.Connection.Close();
                }
            }

            return items;
        }
 /// <summary>
 /// Updates the item by identifier.
 /// </summary>
 /// <param name="item">The item.</param>
 public void UpdateById(PurchaseTransaction_Item item)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Deletes the specified item from the database.
        /// </summary>
        /// <param name="item">The item.</param>
        public void Delete(PurchaseTransaction_Item item)
        {
            var sqlStatement = "DELETE FROM PurchaseTransaction_Item WHERE Furniture_id = @id AND leaseTime = @lease AND quantity = @quantity AND PurchaseTransaction_id = @pid";

            var connection = new MySqlConnection(this.CONNECTION_STRING);

            var command = new MySqlCommand(sqlStatement);

            command.Parameters.AddWithValue("@id", item.FurnitureId);
            command.Parameters.AddWithValue("@lease", item.LeaseTime);
            command.Parameters.AddWithValue("@quantity", item.Quantity);
            command.Parameters.AddWithValue("@pid", item.PurchaseTransactionId);

            command.Connection = connection;

            try
            {
                command.Connection.Open();

                command.ExecuteNonQuery();
            }
            finally
            {
                command.Connection.Close();
            }
        }
Ejemplo n.º 8
0
        private void addItemConfirmButton_Click(object sender, EventArgs e)
        {
            FurnitureController theController = new FurnitureController();
            try
            {
                var id = int.Parse(this.itemToAddTextBox.Text);
                var result = theController.GetItemById(id);
                var quantity = int.Parse(this.qtyTextBox.Text);
                var days = (this.dateTimePicker1.Value - DateTime.Now).Days + 1;

                if (quantity <= 0)
                {
                    ErrorHandler.DisplayErrorBox("Error", "Please enter a valid quantity. ");
                    return;
                }

                if (result == null)
                {
                    ErrorHandler.DisplayErrorBox("Error", "Item not found. Please try again.");
                    return;
                }

                if (result.Quantity < quantity)
                {
                    ErrorHandler.DisplayErrorBox("Quantity Error",
                        "There are not enough items in stock. You can only rent " + result.Quantity + " items or less.");
                    return;
                }

                if (days <= 0)
                {
                    ErrorHandler.DisplayErrorBox("Lease Time Error", "You must rent for at least one day.");
                    return;
                }

                PurchaseTransaction_Item theItem = new PurchaseTransaction_Item();
                theItem.FurnitureId = result.Id;
                theItem.Quantity = quantity;
                theItem.LeaseTime = days;
                theItem.FurnitureName = result.Name;


                foreach (var purchaseTransactionItem in this.itemsToPurchase)
                {
                    if (purchaseTransactionItem.FurnitureId == theItem.FurnitureId)
                    {
                        ErrorHandler.DisplayErrorBox("Duplicate Error", "Cannot add duplicate item to transaction");
                        return;
                    }
                }

                this.itemsToPurchase.Add(theItem);

                if (this.DataGrid.DataSource == null)
                {
                    this.DataGrid.DataSource = this.itemsToPurchase;
                    this.DataGrid.Columns["ReturnableQuantity"].Visible = false;
                }
            }
            catch (MySqlException error)
            {
                ErrorHandler.DisplayErrorMessageToUserAndLog("Network Error", "There was a problem adding this item to the transaciton. Please try again.", error);
                return;
            }
            catch (Exception)
            {
                ErrorHandler.DisplayErrorBox("Error", "Please enter a numerical value.");
                return;
            }

            this.InternalState = TransactionStates.Main;
        }