public TransactionMappingForm(Guid guid)
        {
            InitializeComponent();

            initializeView();

            operation = new BalanceOperation(guid);
            operation.getNotConsumedBuying(table);

            remainValue.Text = operation.getTransaction().amount.ToString();
        }
        private void chooseButton_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow item in gridView.SelectedRows)
            {
                DataRow row = table.Rows[item.Index];
                Debug.WriteLine(String.Format("Selected amount: {0} {1}", row["數量"], row["編號"]));

                Guid    selectedId     = Guid.Parse(row["編號"].ToString());
                decimal selectedAmount = Decimal.Parse(row["數量"].ToString());
                decimal remainAmount   = Decimal.Parse(remainValue.Text);

                // Calculate the remaining amount after assigning the record.
                if (remainAmount > selectedAmount)
                {
                    operation.updateRemainingAmountToRecord(selectedId, 0);
                    remainAmount -= selectedAmount;
                }
                else
                {
                    operation.updateRemainingAmountToRecord(selectedId, selectedAmount - remainAmount);
                    remainAmount = 0;
                }

                // Write balance record.
                operation.addBalanceRecord(selectedId);

                // Set the new amount back to the label.
                remainValue.Text = remainAmount.ToString();

                if (remainAmount == 0)
                {
                    MessageBox.Show("沖帳紀錄已完成。");
                    this.Close();
                }
                else
                {
                    // Refresh the form.
                    operation.getNotConsumedBuying(table);
                }
            }
        }