public void updateGrid()
        {
            string    iscredit              = "";
            DataSet   transactionsDataSet   = new DataSet();
            DataTable transactionsDataTable = new DataTable("Transactions");

            transactionsDataTable.Columns.Add("AccountTitle");
            transactionsDataTable.Columns.Add("TransactionType");
            transactionsDataTable.Columns.Add("Description");
            transactionsDataTable.Columns.Add("Date");
            transactionsDataTable.Columns.Add("Time");
            transactionsDataTable.Columns.Add("Amount");
            transactionsDataTable.Columns.Add("Balance");

            foreach (var item in currentTransactions)
            {
                if (item.iscredit == 1)
                {
                    iscredit = "Credit";
                }
                else
                {
                    iscredit = "Debit";
                }
                //transactionsDataTable.Rows.Add(item.AccountName, iscredit, item.transactionDescription, item.transactionDate.Date.ToShortDateString(), item.transactionTime.ToShortTimeString(), item.transactionAmount, item.balance);
                //working code when deleting the rows.
                transactionsDataTable.Rows.Add(item.AccountName, iscredit, item.transactionDescription, item.transactionDate.Date.ToShortDateString(), item.transactionTime.TimeOfDay.ToString(), item.transactionAmount, item.balance);
            }

            transactionsDataSet.Tables.Add(transactionsDataTable);
            LedgerGridView.DataSource = transactionsDataSet;
            LedgerGridView.DataMember = "Transactions";
            LedgerGridView.Refresh();
            reColorGrid();
        }
        private void SaveTransactionsButton_Click(object sender, EventArgs e)
        {
            if (isBalanced() == false)
            {
                return;
            }

            Model.transaction trans;
            try
            {
                using (var db = new POSApplication.Model.posdbEntities())
                {
                    foreach (var item in currentTransactions)
                    {
                        trans           = new Model.transaction();
                        trans.accountid = GetAccountID(item.AccountName);
                        if (item.iscredit == 0)
                        {
                            trans.Debit = Decimal.Parse(item.transactionAmount.ToString());
                        }
                        else
                        {
                            trans.Credit = Decimal.Parse(item.transactionAmount.ToString());
                        }
                        trans.entrydate   = item.transactionDate;
                        trans.entrytime   = item.transactionTime.TimeOfDay;
                        trans.description = item.transactionDescription;
                        db.transactions.Add(trans);
                        db.SaveChanges();
                    }
                    MessageBox.Show("Transactions saved successfully.");
                }

                LedgerGridView.DataSource = null;
                LedgerGridView.DataMember = null;
                LedgerGridView.Refresh();

                CreditAccountID.Text              = "";
                CreditAmountField.Text            = "";
                CreditTransactionDescription.Text = "";

                DebitAccountID.Text              = "";
                DebitAmountField.Text            = "";
                DebitTransactionDescription.Text = "";
            }
            catch (Exception e1)
            {
                MessageBox.Show("Transactions could not be saved.");
            }
        }
Exemplo n.º 3
0
        private void ShowLedgerButton_Click(object sender, EventArgs e)
        {
            if (selectedAccount.Length == 0)
            {
                if (AccountNameCombo.Text.Length > 0)
                {
                    selectedAccount = AccountNameCombo.GetItemText(AccountNameCombo.Text);
                }
            }

            //if (selectedAccount.Length > 0)
            searchRecords(selectedAccount, dateTimePicker1.Value.ToString(), dateTimePicker2.Value.ToString());
            selectedAccount = "";
            string    iscredit              = "";
            DataSet   transactionsDataSet   = new DataSet();
            DataTable transactionsDataTable = new DataTable("Transactions");

            transactionsDataTable.Columns.Add("AccountTitle");
            transactionsDataTable.Columns.Add("TransactionType");
            transactionsDataTable.Columns.Add("Description");
            transactionsDataTable.Columns.Add("Date");
            transactionsDataTable.Columns.Add("Time");
            transactionsDataTable.Columns.Add("Amount");
            transactionsDataTable.Columns.Add("Balance");

            foreach (var item in currentTransactions)
            {
                if (item.iscredit == 1)
                {
                    iscredit = "Credit";
                }
                else
                {
                    iscredit = "Debit";
                }
                //working code when deleting the rows.
                transactionsDataTable.Rows.Add(item.AccountName, iscredit, item.transactionDescription, item.transactionDate.Date.ToShortDateString(), item.transactionTimeString, item.transactionAmount, item.balance);
            }

            transactionsDataSet.Tables.Add(transactionsDataTable);
            LedgerGridView.DataSource = transactionsDataSet;
            LedgerGridView.DataMember = "Transactions";
            LedgerGridView.Refresh();
            reColorGrid();
        }