//Вставка строки private void InsertRecord() { fmIncTaxEdit fmEdit = new fmIncTaxEdit(EnumFormMode.Insert, "Створення корегування прибуткового податку"); IncTax setIncTax = new IncTax(); int month = SalaryHelper.GetMonthByIndex(cmbCalendar.SelectedIndex, true); if (month == 0) { setIncTax.IncTax_Date = DateTime.MinValue.AddYears(DateTime.Today.Year - 1).AddMonths(DateTime.Today.Month - 1); } else { int year = SalaryHelper.GetYearByIndex(DateTime.Today.Year - SetupProgram.YearSalary, cmbCalendar.SelectedIndex, true); setIncTax.IncTax_Date = DateTime.MinValue.AddYears(year - 1).AddMonths(month - 1); } fmEdit.SetData(setIncTax); if (fmEdit.ShowDialog() == DialogResult.OK) { string error; IncTax getIncTax = fmEdit.GetData(); int id = _repoIncTax.AddIncTax(getIncTax, out error); if (id == 0) { MessageBox.Show("Помилка додавання рядка.\nТехнічна інформація: " + error, "Помилка"); return; } RefreshTables(); dgvIncTax.SetPositionRow <v_IncTax>("IncTax_Id", id.ToString()); } }
//Обновление строки private void UpdateRecord() { if (dgvIncTax.CurrentRow == null) { return; } v_IncTax vIncTax = dgvIncTax.CurrentRow.DataBoundItem as v_IncTax; if (vIncTax == null) { MessageBox.Show("Не знайдений рядок для оновлення", "Помилка"); return; } fmIncTaxEdit fmEdit = new fmIncTaxEdit(EnumFormMode.Edit, "Зміна корегування прибуткового податку"); fmEdit.SetData(vIncTax); if (fmEdit.ShowDialog() == DialogResult.OK) { IncTax IncTax = fmEdit.GetData(); string error; if (!_repoIncTax.ModifyIncTax(IncTax, out error)) { MessageBox.Show("Помилка оновлення рядка.\nТехнічна інформація: " + error, "Помилка"); return; } RefreshTables(); } }
//Изменить сумму подоходного налога public bool ModifyIncTax(IncTax incTax, out string error) { error = string.Empty; if (conn == null) { error = "conn == null"; return(false); } if (incTax == null) { error = "incTax == null"; return(false); } SqlCommand command = new SqlCommand(spIncTaxUpdate, conn); command.CommandType = System.Data.CommandType.StoredProcedure; command.Connection = conn; command.Parameters.AddWithValue("@inIncTax_Id", incTax.IncTax_Id); command.Parameters.AddWithValue("@inIncTax_PersCard_Id", incTax.IncTax_PersCard_Id == 0 ? Convert.DBNull : incTax.IncTax_PersCard_Id); command.Parameters.AddWithValue("@inIncTax_Date", incTax.IncTax_Date == DateTime.MinValue ? Convert.DBNull : incTax.IncTax_Date); command.Parameters.AddWithValue("@inIncTax_Sm", incTax.IncTax_Sm); try { command.ExecuteNonQuery(); } catch (Exception ex) { error = ex.Message; return(false); } return(true); }
//Получить суммы подоходного налога по параметрам public List <IncTax> GetIncTaxByParams(int incTax_id, DateTime incTax_dateBeg, DateTime incTax_dateEnd, out string error) { error = string.Empty; if (conn == null) { error = "conn == null"; return(null); } if (incTax_id == 0 && incTax_dateBeg == DateTime.MinValue && incTax_dateEnd == DateTime.MinValue) { error = "Не задані вхідні параметри"; return(null); } if (incTax_dateBeg == DateTime.MinValue || incTax_dateEnd == DateTime.MinValue) { error = "Не заданий період"; return(null); } List <IncTax> incTaxs = new List <IncTax>(); SqlCommand command = new SqlCommand(spIncTaxSelect, conn); command.CommandType = System.Data.CommandType.StoredProcedure; command.Connection = conn; command.Parameters.AddWithValue("@inIncTax_Id", incTax_id); command.Parameters.AddWithValue("@inIncTax_DateBeg", (incTax_dateBeg == DateTime.MinValue) ? Convert.DBNull : incTax_dateBeg); command.Parameters.AddWithValue("@inIncTax_DateEnd", (incTax_dateEnd == DateTime.MinValue) ? Convert.DBNull : incTax_dateEnd); SqlDataReader reader = null; try { reader = command.ExecuteReader(); while (reader.Read()) { IncTax incTax = new IncTax(); FillDataRec(reader, incTax); incTaxs.Add(incTax); } } catch (Exception ex) { error = ex.Message; incTaxs = null; } finally { if (reader != null) { reader.Close(); } } return(incTaxs); }
public void SetData(IncTax incTax) { _id = incTax.IncTax_Id; cmbCalendar.SelectedIndex = SalaryHelper.GetIndexByDate( DateTime.Today.Year - SetupProgram.YearSalary, incTax.IncTax_Date, false); cmbCard.ReadCombobox(incTax.IncTax_PersCard_Id); tbSm.Text = incTax.IncTax_Sm.ToString("0.00"); }
public IncTax GetData() { IncTax incTax = new IncTax(); incTax.IncTax_Id = _id; incTax.IncTax_PersCard_Id = _cmbCardParams.PersCard_Id; incTax.IncTax_Date = SalaryHelper.GetDateByIndex(cmbCalendar.SelectedIndex, DateTime.Today.Year - SetupProgram.YearSalary, false); decimal resDec = 0; //Сумма if (decimal.TryParse(tbSm.Text, out resDec)) { incTax.IncTax_Sm = resDec; } return(incTax); }
//Добавить сумму подоходного налога public int AddIncTax(IncTax incTax, out string error) { error = string.Empty; if (incTax == null) { error = "incTax == null"; return(0); } if (conn == null) { error = "conn == null"; return(0); } SqlCommand command = new SqlCommand(spIncTaxInsert, conn); command.CommandType = System.Data.CommandType.StoredProcedure; command.Connection = conn; command.Parameters.AddWithValue("@inIncTax_PersCard_Id", incTax.IncTax_PersCard_Id == 0 ? Convert.DBNull : incTax.IncTax_PersCard_Id); command.Parameters.AddWithValue("@inIncTax_Date", incTax.IncTax_Date == DateTime.MinValue ? Convert.DBNull : incTax.IncTax_Date); command.Parameters.AddWithValue("@inIncTax_Sm", incTax.IncTax_Sm); // определяем выходной параметр SqlParameter outId = new SqlParameter { ParameterName = "outId", Direction = ParameterDirection.Output, SqlDbType = SqlDbType.Int }; command.Parameters.Add(outId); try { command.ExecuteNonQuery(); } catch (Exception ex) { error = ex.Message; return(0); } int id = 0; int.TryParse(command.Parameters["outId"].Value.ToString(), out id); return(id); }
//Получить список сумм подоходного налога public List <IncTax> GetAllIncTaxs(out string error) { error = string.Empty; List <IncTax> incTaxs = new List <IncTax>(); if (conn == null) { error = "conn == null"; return(incTaxs); } SqlCommand command = new SqlCommand(spIncTaxSelect, conn); command.CommandType = System.Data.CommandType.StoredProcedure; SqlDataReader reader = null; try { reader = command.ExecuteReader(); while (reader.Read()) { IncTax incTax = new IncTax(); FillDataRec(reader, incTax); incTaxs.Add(incTax); } } catch (Exception exc) { error = exc.Message; } finally { if (reader != null) { reader.Close(); } } return(incTaxs); }
private void FillDataRec(SqlDataReader reader, IncTax incTax) { int resInt = 0; DateTime resDate = DateTime.MinValue; decimal resDec = 0; if (int.TryParse(reader["IncTax_Id"].ToString(), out resInt)) { incTax.IncTax_Id = resInt; } if (int.TryParse(reader["IncTax_PersCard_Id"].ToString(), out resInt)) { incTax.IncTax_PersCard_Id = resInt; } if (DateTime.TryParse(reader["IncTax_Date"].ToString(), out resDate)) { incTax.IncTax_Date = resDate; } if (decimal.TryParse(reader["IncTax_Sm"].ToString(), out resDec)) { incTax.IncTax_Sm = resDec; } }