Exemplo n.º 1
0
        public bool LoadLedgerEntry(int businessId)
        {
            SaveRecord();

            m_businessId = businessId;

            UpdateBalances();

            textDate.Text = "";
            comboType.SelectedIndex = -1;
            comboAccount.Text = "";
            comboAccount.SelectedIndex = -1;
            comboAccount.Items.Clear();
            comboDescription.Text = "";
            comboDescription.SelectedIndex = -1;
            comboDescription.Items.Clear();
            textAmount.Text = "";
            textComments.Text = "";

            string sql = string.Format("select account from ledger_accounts where business_id = {0}", businessId);

            OleDbCommand selectCmd = new OleDbCommand(sql, m_dbConnection);
            OleDbDataReader dataReader = selectCmd.ExecuteReader();

            while(dataReader.Read())
            {
                comboAccount.Items.Add(dataReader[0].ToString());
            }

            dataReader.Close();

            //@ need a query for this
            sql = string.Format("select distinct description from ledger where business_id = {0}", businessId);

            selectCmd = new OleDbCommand(sql, m_dbConnection);
            dataReader = selectCmd.ExecuteReader();

            while (dataReader.Read())
            {
                comboDescription.Items.Add(dataReader[0].ToString());
            }

            dataReader.Close();

            listEntries.Items.Clear();

            sql = string.Format("select * from ledger where business_id = {0} order by entry_date", businessId);

            selectCmd = new OleDbCommand(sql, m_dbConnection);
            dataReader = selectCmd.ExecuteReader();

            ListViewItem item = null;

            while(dataReader.Read())
            {
                Ledger rec = new Ledger();
                rec.Load(dataReader);

                item = new ListViewItem(rec.EntryDateString);
                item.Tag = rec;
                rec.Tag = item;

                item.SubItems.Add(rec.Description);
                item.SubItems.Add(rec.EntryAccount);

                if(rec.EntryType == "C")
                {
                    item.SubItems.Add(rec.EntryAmount.ToString("C"));
                }
                else
                {
                    item.SubItems.Add(string.Format("<{0:C}>", rec.EntryAmount));
                }

                listEntries.Items.Add(item);
            }

            dataReader.Close();

            if(null != item)
            {
                item.Selected = true;
            }

            return true;
        }
Exemplo n.º 2
0
        private void btnNew_Click(object sender, System.EventArgs e)
        {
            ListViewItem item = new ListViewItem("");
            item.SubItems.Add("");
            item.SubItems.Add("");
            item.SubItems.Add("");

            Ledger rec = new Ledger();
            rec.BusinessId = m_businessId;

            item.Tag = rec;
            rec.Tag = item;

            listEntries.Items.Add(item);
            item.Selected = true;

            textDate.Focus();
        }