Esempio n. 1
0
        public ExpenseBo Get(int id)
        {
            using (SqlConnection conn = CreateConnection())
            {
                using (SqlCommand cmd = CreateSpCommand("spExpenseGet", conn))
                {
                    cmd.Parameters.AddWithValue("@Id", id);
                    cmd.AddIntOutParam("@Category");
                    cmd.AddVarCharOutParam("@Description", 200);
                    cmd.AddDecimalOutParam("@Amount", 16, 2);
                    cmd.AddDateTimeOutParam("@Date");
                    cmd.AddIntOutParam("@Receipt");

                    conn.Open();
                    cmd.ExecuteNonQuery();
                    conn.Close();

                    var expenseBo = new ExpenseBo();
                    expenseBo.Id = id;
                    expenseBo.Category = cmd.GetParamValue<int?>("@Category");
                    expenseBo.Description = cmd.GetParamValue<string>("@Description");
                    expenseBo.Amount = cmd.GetParamValue<decimal>("@Amount");
                    expenseBo.Date = cmd.GetParamValue<DateTime>("@Date");
                    expenseBo.Receipt = cmd.GetParamValue<int?>("@Receipt");
                    return expenseBo;
                }
            }
        }
Esempio n. 2
0
 public void Save(ExpenseBo bo, bool createReceipt)
 {
     if (bo.IsNewRecord)
     {
         Insert(bo, createReceipt);
     }
     else
     {
         Update(bo, createReceipt);
     }
 }
Esempio n. 3
0
 private void Insert(ExpenseBo expense, bool createReceipt)
 {
     using (SqlConnection conn = CreateConnection())
     {
         using (SqlCommand cmd = CreateSpCommand("spExpenseIns", conn))
         {
             cmd.AddIntOutParam("@Id");
             cmd.Parameters.AddWithNullableValue("@Category", expense.Category);
             cmd.Parameters.AddWithNullableValue("@Description", expense.Description);
             cmd.Parameters.AddWithValue("@Amount", expense.Amount);
             cmd.Parameters.AddWithValue("@Date", expense.Date);
             cmd.Parameters.AddWithValue("@CreateReceipt", createReceipt);
             cmd.AddIntOutParam("@Receipt");
             conn.Open();
             cmd.ExecuteNonQuery();
             conn.Close();
             expense.Id = cmd.GetParamValue<int>("@Id");
             expense.Receipt = cmd.GetParamValue<int?>("@Receipt");
         }
     }
 }
Esempio n. 4
0
 public void SetCurrentId(int currentId)
 {
     _currentExpense = _expenseRepository.Get(currentId);
 }
Esempio n. 5
0
 private void SaveExpense()
 {
     if (_currentExpense == null)
     {
         _currentExpense = new ExpenseBo();
     }
     _currentExpense.Category = GetCurrentCategory();
     _currentExpense.Description = txtDescription.Text;
     _currentExpense.Amount = clcValue.Value;
     _currentExpense.Date = dateEditDate.DateTime;
     _expenseRepository.Save(_currentExpense, chkBonFiscal.Checked);
 }