public MonthlyIncomeBo Get(int id) { using (SqlConnection conn = CreateConnection()) { using (SqlCommand cmd = CreateSpCommand("spMonthlyIncomeGet", conn)) { cmd.Parameters.AddWithValue("@Id", id); cmd.AddVarCharOutParam("@Description", 200); cmd.AddDecimalOutParam("@Amount", 16, 2); cmd.AddDateTimeOutParam("@StartDate"); cmd.AddDateTimeOutParam("@EndDate"); cmd.AddTinyIntOutParam("@IncomeDay"); cmd.AddDateTimeOutParam("@CreationDate"); cmd.AddDateTimeOutParam("@ChangeDate"); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); var bo = new MonthlyIncomeBo(); bo.Id = id; bo.Description = cmd.GetParamValue<string>("@Description"); bo.Amount = cmd.GetParamValue<decimal>("@Amount"); bo.StartDate = cmd.GetParamValue<DateTime?>("@StartDate"); bo.EndDate = cmd.GetParamValue<DateTime?>("@EndDate"); bo.IncomeDay = cmd.GetParamValue<byte?>("@IncomeDay"); bo.CreationDate = cmd.GetParamValue<DateTime>("@CreationDate"); bo.ChangeDate = cmd.GetParamValue<DateTime>("@ChangeDate"); return bo; } } }
private void SaveIncome() { if (_currentMonthlyIncome == null) { _currentMonthlyIncome = new MonthlyIncomeBo(); } _currentMonthlyIncome.Description = txtName.Text; _currentMonthlyIncome.Amount = clcValue.Value; if (clcIncomeDay.EditValue != null) _currentMonthlyIncome.IncomeDay = (byte) clcIncomeDay.Value; else _currentMonthlyIncome.IncomeDay = null; if(dateEditStartDate.EditValue != null) _currentMonthlyIncome.StartDate = dateEditStartDate.DateTime; else _currentMonthlyIncome.StartDate = null; if (dateEditEndDate.EditValue != null) _currentMonthlyIncome.EndDate = dateEditEndDate.DateTime; else _currentMonthlyIncome.EndDate = null; _monthlyIncomeRepository.Save(_currentMonthlyIncome); }
public void Save(MonthlyIncomeBo monthlyIncome) { if (monthlyIncome.IsNewRecord) { Insert(monthlyIncome); } else { Update(monthlyIncome); } }
private void Insert(MonthlyIncomeBo bo) { using (SqlConnection conn = CreateConnection()) { using (SqlCommand cmd = CreateSpCommand("spMonthlyIncomeIns", conn)) { cmd.AddIntOutParam("@Id"); cmd.Parameters.AddWithValue("@Description", bo.Description); cmd.Parameters.AddWithValue("@Amount", bo.Amount); cmd.Parameters.AddWithNullableValue("@StartDate", bo.StartDate); cmd.Parameters.AddWithNullableValue("@EndDate", bo.EndDate); cmd.Parameters.AddWithValue("@IncomeDay", bo.IncomeDay); cmd.AddDateTimeOutParam("@CreationDate"); cmd.AddDateTimeOutParam("@ChangeDate"); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); bo.Id = cmd.GetParamValue<int>("@Id"); bo.CreationDate = cmd.GetParamValue<DateTime>("@CreationDate"); bo.ChangeDate = cmd.GetParamValue<DateTime>("@ChangeDate"); } } }
private void Update(MonthlyIncomeBo monthlyIncome) { using (SqlConnection conn = CreateConnection()) { using (SqlCommand cmd = CreateSpCommand("spMonthlyIncomeUpd", conn)) { cmd.Parameters.AddWithValue("@Id", monthlyIncome.Id); cmd.Parameters.AddWithValue("@Description", monthlyIncome.Description); cmd.Parameters.AddWithValue("@Amount", monthlyIncome.Amount); cmd.Parameters.AddWithNullableValue("@StartDate", monthlyIncome.StartDate); cmd.Parameters.AddWithNullableValue("@EndDate", monthlyIncome.EndDate); cmd.Parameters.AddWithNullableValue("@IncomeDay", monthlyIncome.IncomeDay); cmd.AddDateTimeOutParam("@ChangeDate"); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); monthlyIncome.ChangeDate = cmd.GetParamValue<DateTime>("@ChangeDate"); } } }
public void SetCurrentId(int currentId) { _currentMonthlyIncome = _monthlyIncomeRepository.Get(currentId); }