private void bAccept_Click(object sender, EventArgs e) { if (validate_data()) { try { int? id = (this.accountRange == null) ? null : this.accountRange.Id; if (FormSelectCompany.selectedCompanyId == null) { this.accountRange = new AccountRangeTemplateDTO(id, tbName.Text, (int)nudCodeFrom.Value, (int)nudCodeTo.Value, (AccountTypeDTO)cbType.SelectedItem, cbCurrent.Checked, true); this.dataValidation.saveAccountRangeTemplate(this.accountRange); } else { this.accountRange = new AccountRangeDTO(id, (int)FormSelectCompany.selectedCompanyId, tbName.Text, (int)nudCodeFrom.Value, (int)nudCodeTo.Value, (AccountTypeDTO)cbType.SelectedItem, cbCurrent.Checked, (id == null) ? true : this.accountRange.Removable); this.dataValidation.saveAccountRange(this.accountRange as AccountRangeDTO); } DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void enterDataCompany(AccountRangeTemplateDTO accountRange) { tbName.Text = accountRange.Name; nudCodeFrom.Value = accountRange.CodeFrom; nudCodeTo.Value = accountRange.CodeTo; cbType.SelectedItem = accountRange.Type; cbCurrent.Checked = accountRange.CurrentAccount; }
public FormModifyAccountRangeTemplate(DataValidation dataValidation, AccountRangeTemplateDTO accountRange) : base(dataValidation) { this.accountRange = accountRange; InitializeComponent(); this.Text = "Modificar rango de cuenta"; this.bAccept.Text = "Modificar"; this.enterDataCompany(accountRange); }
public void deleteAccountRangeTemplate(AccountRangeTemplateDTO accountRange) { this.data.deleteAccountRangeTemplate(accountRange); }
public void saveAccountRangeTemplate(AccountRangeTemplateDTO accountRange) { string name = this.getNameOfAccountRangeTemplateOverlapped(accountRange); if (name != null) throw new ArgumentException(String.Format("El rango ingresado se superpone con '{0}'", name)); if (accountRange.Id == null) { accountRange.Id = this.data.addAccountRangeTemplate(accountRange); } else { this.data.modifyAccountRangeTemplate(accountRange); } }
public string getNameOfAccountRangeTemplateOverlapped(AccountRangeTemplateDTO accountRange) { return this.data.getNameOfAccountRangeTemplateOverlapped(accountRange); }
public void modifyAccountRangeTemplate(AccountRangeTemplateDTO accountRange) { StringBuilder query = new StringBuilder(); query.AppendLine("UPDATE AccountRangeTemplates"); query.AppendLine("SET CodeFrom = @codeFrom, CodeTo = @codeTo, AccountTypeId = @accountTypeId, Name = @name, CurrentAccount = @currentAccount, Removable = @removable"); query.AppendLine("WHERE Id = @id;"); SqlCommand command = new SqlCommand(query.ToString(), this.conection); command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@id", accountRange.Id); command.Parameters.AddWithValue("@codeFrom", accountRange.CodeFrom); command.Parameters.AddWithValue("@codeTo", accountRange.CodeTo); command.Parameters.AddWithValue("@accountTypeId", accountRange.Type.Id); command.Parameters.AddWithValue("@currentAccount", accountRange.CurrentAccount); command.Parameters.AddWithValue("@name", accountRange.Name); command.Parameters.AddWithValue("@removable", accountRange.Removable); try { this.conection.Open(); command.ExecuteNonQuery(); } finally { if (this.conection.State == ConnectionState.Open) this.conection.Close(); } }
public string getNameOfAccountRangeTemplateOverlapped(AccountRangeTemplateDTO accountRange) { StringBuilder query = new StringBuilder(); query.AppendLine("SELECT Name FROM AccountRangeTemplates"); query.AppendLine("WHERE Id != @id AND ((CodeFrom BETWEEN @codeFrom AND @codeTo) OR (CodeTo BETWEEN @codeFrom AND @codeTo));"); SqlCommand command = new SqlCommand(query.ToString(), this.conection); command.CommandType = System.Data.CommandType.Text; if (accountRange.Id != null) command.Parameters.AddWithValue("@id", accountRange.Id); else command.Parameters.AddWithValue("@id", SqlInt32.Null); command.Parameters.AddWithValue("@codeFrom", accountRange.CodeFrom); command.Parameters.AddWithValue("@codeTo", accountRange.CodeTo); string name; try { this.conection.Open(); object obj = command.ExecuteScalar(); name = obj == null ? null : obj.ToString(); } finally { if (this.conection.State == ConnectionState.Open) this.conection.Close(); } return name; }
public List<AccountRangeTemplateDTO> getAccountRangeTemplates() { StringBuilder query = new StringBuilder(); query.AppendLine("SELECT ART.Id, AT.Id AccountTypeId, AT.Type AccountType, BT.Id BalanceTypeId, BT.Type BalanceType, CodeFrom, CodeTo, CurrentAccount, Removable, Name FROM AccountRangeTemplates ART"); query.AppendLine("INNER JOIN AccountType AT ON ART.AccountTypeId = AT.Id"); query.AppendLine("INNER JOIN BalanceType BT ON AT.BalanceTypeId = BT.Id"); query.AppendLine("ORDER BY ART.Id;"); SqlCommand command = new SqlCommand(query.ToString(), this.conection); command.CommandType = System.Data.CommandType.Text; List<AccountRangeTemplateDTO> templates = new List<AccountRangeTemplateDTO>(); try { this.conection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { AccountRangeTemplateDTO template = new AccountRangeTemplateDTO( (int)reader["Id"], reader["Name"].ToString(), (int)reader["CodeFrom"], (int)reader["CodeTo"], new AccountTypeDTO((int)reader["AccountTypeId"], new BalanceTypeDTO((int)reader["BalanceTypeId"], reader["BalanceType"].ToString()), reader["AccountType"].ToString()), (bool)reader["CurrentAccount"], (bool)reader["Removable"]); templates.Add(template); } } } } finally { if (this.conection.State == ConnectionState.Open) this.conection.Close(); } return templates; }
public void deleteAccountRangeTemplate(AccountRangeTemplateDTO accountRange) { StringBuilder query = new StringBuilder(); query.AppendLine("DELETE FROM AccountRangeTemplates"); query.AppendLine("WHERE Id = @id;"); SqlCommand command = new SqlCommand(query.ToString(), this.conection); command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@id", accountRange.Id); try { this.conection.Open(); command.ExecuteNonQuery(); } finally { if (this.conection.State == ConnectionState.Open) this.conection.Close(); } }
public int addAccountRangeTemplate(AccountRangeTemplateDTO accountRange) { StringBuilder query = new StringBuilder(); query.AppendLine("INSERT INTO AccountRangeTemplates"); query.AppendLine("(CodeFrom, CodeTo, AccountTypeId, CurrentAccount, Name, Removable)"); query.AppendLine("VALUES (@codeFrom, @codeTo, @accountTypeId, @currentAccount, @name, @removable);"); query.AppendLine("SELECT SCOPE_IDENTITY();"); SqlCommand command = new SqlCommand(query.ToString(), this.conection); command.CommandType = CommandType.Text; command.Parameters.AddWithValue("@codeFrom", accountRange.CodeFrom); command.Parameters.AddWithValue("@codeTo", accountRange.CodeTo); command.Parameters.AddWithValue("@accountTypeId", accountRange.Type.Id); command.Parameters.AddWithValue("@currentAccount", accountRange.CurrentAccount); command.Parameters.AddWithValue("@name", accountRange.Name); command.Parameters.AddWithValue("@removable", accountRange.Removable); int id; try { this.conection.Open(); id = (int)(decimal)command.ExecuteScalar(); } finally { if (this.conection.State == ConnectionState.Open) this.conection.Close(); } return id; }