示例#1
0
        // display expenses record when selected gridview row is double-clicked
        private void dgvExpenses_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                if (dgvExpenses.CurrentRow.Index != -1)
                {
                    model.ExpenseID = Convert.ToInt32(dgvExpenses.CurrentRow.Cells["ExpenseID"].Value);

                    //select receipt record from receipt table
                    using (CashbookEntities db = new CashbookEntities())
                    {
                        model = db.Expenses.Where(x => x.ExpenseID == model.ExpenseID).FirstOrDefault();
                        txtDescription.Text = model.Description;
                        txtVoucherNum.Text  = model.VoucherNumber;
                        txtReference.Text   = model.Reference;
                        txtAmount.Text      = model.Amount.ToString();
                    }
                    panel1.Visible = true;
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Search"); //excep.GetType().ToString()
            }
        }
示例#2
0
        // update cash expenses record
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                model.Description   = txtDescription.Text.Trim();
                model.VoucherNumber = txtVoucherNum.Text.Trim();
                model.Reference     = txtReference.Text.Trim();
                model.Amount        = Convert.ToDecimal(txtAmount.Text.Trim());

                using (CashbookEntities db = new CashbookEntities())
                {
                    //update selected/existing customer record
                    db.Entry(model).State = EntityState.Modified;
                    db.SaveChanges();
                }
                Clear();
                PopulateData();
                MessageBox.Show("Record Updated Successfully");
                panel1.Visible = false;
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Search"); //excep.GetType().ToString()
            }
        }
示例#3
0
        // save new expense
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                model.Date = dtDate.Value.Date;

                //model.Date = Convert.ToDateTime(dtDate.Text.Trim());
                model.Description   = txtDescription.Text.Trim();
                model.VoucherNumber = txtVoucherNum.Text.Trim();
                model.Reference     = txtReference.Text.Trim();
                model.Amount        = Convert.ToDecimal(txtAmount.Text.Trim());

                using (CashbookEntities db = new CashbookEntities())
                {
                    //add new expense record
                    db.Expenses.Add(model);
                    db.SaveChanges();
                }
                Clear();
                MessageBox.Show("New Cash Expense Saved Successfully");
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Search"); //excep.GetType().ToString()
            }
        }
示例#4
0
        //bind datagridview to database content
        void PopulateData()
        {
            try {
                //dgvReceipts.AutoGenerateColumns = false; //prevent auto-generated columns in datagridview
                using (CashbookEntities db = new CashbookEntities())
                {
                    dgvReceipts.DataSource    = db.Receipts.ToList <Receipt>();
                    dgvReceipts.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Search"); //excep.GetType().ToString()
            }
        }
示例#5
0
        // search Receipts record using data in search box
        void Search()
        {
            try
            {
                int num             = Convert.ToInt32(txtSearch.Text);
                CashbookEntities dc = new CashbookEntities();
                var exp             = from expense in dc.Expenses
                                      where expense.ExpenseID == num
                                      select expense;
                dgvExpenses.DataSource = exp.ToList();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Search"); //excep.GetType().ToString()
            }
        }
示例#6
0
        // search Receipts record using data in search box
        void Search()
        {
            try {
                int num             = Convert.ToInt32(txtSearch.Text);
                CashbookEntities dc = new CashbookEntities();
                var rec             = from receipt in dc.Receipts
                                      //where receipt.ReceiptID == 2
                                      where receipt.ReceiptID == num
                                      select receipt;
                dgvReceipts.DataSource = rec.ToList();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Search");  //excep.GetType().ToString()
            }
        }