public DTOOfertas GetOferta(string id) { DTOOfertas oferta = null; SqlCeConnection conn = new SqlCeConnection(@"Data Source=|DataDirectory|\DB\DB_local.sdf"); conn.Open(); //commands represent a query or a stored procedure SqlCeCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT * FROM ofertas WHERE id='" + id + "';"; SqlCeDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { oferta = new DTOOfertas( reader["id"].ToString(), int.Parse(reader["cantidad"].ToString()), float.Parse(reader["precio"].ToString()), reader["descripcion"].ToString(), reader["codigo"].ToString() ); } return(oferta); }
public DTOSolucoes ConsultarTurmaPorSolucaoEducacional(int idSolucaoEducacional, int idOferta, string cpfUsuario) { DTOSolucoes retorno = new DTOSolucoes(); var usuario = new BMUsuario().ObterPorCPF(cpfUsuario); List <int> permissoesOfertas = new BMOferta().ObterListaDePermissoes(usuario.ID).Select(f => f.IdOferta).Distinct().ToList(); var solucaoEducacional = new ManterSolucaoEducacional().ObterSolucaoEducacionalPorId(idSolucaoEducacional); IList <Oferta> ofertas = RecuperarOfertasValidas(solucaoEducacional, permissoesOfertas); if (idOferta > 0) { ofertas = ofertas.Where(f => f.ID == idOferta).ToList(); } var se = new DTOCurso(); se.IDSolucaoEducacional = solucaoEducacional.ID; foreach (var oferta in ofertas) { var o = new DTOOfertas { IDOferta = oferta.ID, PermiteAlterarStatusPeloGestor = (oferta.AlteraPeloGestorUC.HasValue ? oferta.AlteraPeloGestorUC.Value : true) }; var turmas = oferta.ListaTurma.Where( f => (f.DataFinal == null || f.DataFinal.Value.Date > DateTime.Today) && f.InAberta).ToList(); foreach (var turma in turmas) { o.ListaTurma.Add(new DTOOfertaTurma { IdTurma = turma.ID, Nome = turma.Nome }); } se.Ofertas.Add(o); } if (se.Ofertas.Count() > 0) { retorno.Cursos.Add(se); } return(retorno); }
public void ModifyOferta(DTOOfertas oferta) { SqlCeConnection conn = null; try { conn = new SqlCeConnection(@"Data Source=|DataDirectory|\DB\DB_local.sdf"); conn.Open(); SqlCeCommand cmd = conn.CreateCommand(); cmd.CommandText = "UPDATE ofertas SET cantidad='" + oferta.cantidad + "',precio='" + oferta.precio + "',codigo='" + oferta.codigo + "',descripcion='" + oferta.descripcion + "' WHERE id='" + oferta.id + "';"; cmd.ExecuteNonQuery(); } finally { conn.Close(); } }
public void InsertOferta(DTOOfertas oferta) { SqlCeConnection conn = null; try { conn = new SqlCeConnection(@"Data Source=|DataDirectory|\DB\DB_local.sdf"); conn.Open(); SqlCeCommand cmd = conn.CreateCommand(); cmd.CommandText = "INSERT INTO ofertas ([id],[cantidad],[precio],[codigo],[descripcion]) Values('" + oferta.id + "','" + oferta.cantidad + "','" + oferta.precio + "','" + oferta.codigo + "','" + oferta.descripcion + "')"; cmd.ExecuteNonQuery(); } finally { conn.Close(); } }
private void bttnAdd_Click(object sender, EventArgs e) { int cantidad = 0; float num = 0; if (textBox1.Text.Equals("") || textBox2.Text.Equals("") || textBox3.Text.Equals("") || textBox4.Text.Equals("") || textBox5.Text.Equals("") || textBox1.Text.Equals(" ") || textBox2.Text.Equals(" ") || textBox3.Text.Equals(" ") || textBox4.Text.Equals(" ") || textBox5.Text.Equals(" ")) { new Mensajes().DebeLlenarTodosLosCampos(); textBox1.Focus(); textBox1.SelectionStart = 0; textBox1.SelectionLength = textBox1.Text.Length; } else if (!float.TryParse(textBox4.Text, out num) || !int.TryParse(textBox3.Text, out cantidad)) { MessageBox.Show("Cantidad y precio no deben contener caracteres.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox3.Focus(); textBox3.SelectionStart = 0; textBox3.SelectionLength = textBox3.Text.Length; } else { if (new DAOProductos().GetProducts(textBox5.Text) != null) { if (this.bttnModify.Enabled) { DTOOfertas oferta = new DTOOfertas(); oferta.cantidad = int.Parse(this.textBox3.Text); oferta.precio = float.Parse(this.textBox4.Text); oferta.descripcion = this.textBox2.Text; oferta.codigo = this.textBox5.Text; oferta.id = this.textBox1.Text; new DAOOfertas().ModifyOferta(oferta); } else { DTOOfertas oferta = new DTOOfertas(); oferta.cantidad = int.Parse(this.textBox3.Text); oferta.precio = float.Parse(this.textBox4.Text); oferta.descripcion = this.textBox2.Text; oferta.codigo = this.textBox5.Text; oferta.id = this.textBox1.Text; new DAOOfertas().InsertOferta(oferta); } ofertas = new DAOOfertas().GetOfertas(); this.dataGridView1.DataSource = ofertas.ToArray(); this.bttnAdd.Enabled = false; this.bttnModify.Enabled = false; this.btttnDel.Enabled = false; this.bttnNueva.Enabled = true; this.textBox5.Text = null; this.textBox1.Text = null; this.textBox2.Text = null; this.textBox3.Text = null; this.textBox4.Text = null; this.textBox1.Enabled = false; this.textBox2.Enabled = false; this.textBox3.Enabled = false; this.textBox4.Enabled = false; this.textBox5.Enabled = false; this.panel1.Enabled = false; } else { MessageBox.Show("El producto no exite.", "Producto no existente", MessageBoxButtons.OK, MessageBoxIcon.Error); textBox5.Focus(); textBox5.SelectionStart = 0; textBox5.SelectionLength = textBox5.Text.Length; } } }