private void btnAgregarIngreso_Click(object sender, EventArgs e) { string error = ""; MontoEntities montoEntity = new MontoEntities(TipoMonto.Ingreso); Utiles.AccionEnum.TipoAccion tipoAccion = Utiles.AccionEnum.TipoAccion.Add; montoEntity.Descripcion = Utiles.FirstToUpper.ToUpper(txtDescripcionIngreso.Text); montoEntity.Monto = txtIngreso.Text; montoEntity.Tipo = ddlTipo.SelectedItem.ToString(); montoEntity.ID_Cliente = ddlClientes.SelectedValue.ToString(); error = Utiles.Validaciones.ValidarCampos(montoEntity.Descripcion, montoEntity.Monto); if (this.ddlTipo.SelectedItem.ToString() == "Agregar nuevo...") { error += "Seleccione otro Tipo"; } if (error == "") { IngLogic.Save(montoEntity, tipoAccion); txtDescripcionIngreso.Clear(); txtIngreso.Clear(); ListarIngresos(DateTime.Now.Month); } else { MessageBox.Show(error, "Campos incompletos", MessageBoxButtons.OK); } }
public void Save(MontoEntities montoEntity, Utiles.AccionEnum.TipoAccion tipoAccion) { string filePath = ""; string subPath = ""; switch (montoEntity.TipoMonto) { case TipoMonto.Ingreso: filePath = "connectionIngresos"; subPath = "registros/ingreso"; break; case TipoMonto.Gasto: filePath = "connectionGastos"; subPath = "registros/gasto"; break; } switch (tipoAccion) { case Utiles.AccionEnum.TipoAccion.Add: this.AddRowIngresos(montoEntity, filePath); break; case Utiles.AccionEnum.TipoAccion.Modify: this.ModifyRow(montoEntity, filePath, subPath); break; case Utiles.AccionEnum.TipoAccion.Delete: this.DeleteRow(montoEntity.ID, filePath, subPath); break; } }
private void btnAgregarGasto_Click(object sender, EventArgs e) { string error = ""; MontoEntities montoEntity = new MontoEntities(TipoMonto.Gasto); Utiles.AccionEnum.TipoAccion tipoAccion = Utiles.AccionEnum.TipoAccion.Add; montoEntity.Descripcion = txtDescripcionGasto.Text; montoEntity.Monto = txtGasto.Text; montoEntity.Tipo = ddlTipo.SelectedItem.ToString(); montoEntity.ID_Cliente = ddlClientes.SelectedValue.ToString(); error = Utiles.Validaciones.ValidarCampos(montoEntity.Descripcion, montoEntity.Monto); if (error == "") { IngLogic.Save(montoEntity, tipoAccion); txtDescripcionGasto.Clear(); txtGasto.Clear(); ListarGastos(Mes_Actual); } else { MessageBox.Show(error, "Campos incompletos", MessageBoxButtons.OK); } }
public void AdNuedRowIngresos(MontoEntities montoEntity, string filePath) { string appSettings = ConfigurationManager.AppSettings[filePath]; string subPath = ""; string subPath2 = ""; switch (montoEntity.TipoMonto) { case TipoMonto.Ingreso: subPath = "ingreso"; subPath2 = "Ingresos.xml"; break; case TipoMonto.Gasto: subPath = "gasto"; subPath2 = "Gastos.xml"; break; } montoEntity.ID = GetLastID(subPath2); montoEntity.Fecha = DateTime.Now; XmlDocument doc = new XmlDocument(); doc.Load(appSettings); XmlNode Ingreso = doc.CreateElement(subPath); //<ingreso>...nodos internos...</ingreso> //son los nodos internos de <ingreso></ingreso> XmlNode ID = doc.CreateElement("ID"); XmlNode descripcion = doc.CreateElement("Descripcion"); XmlNode monto = doc.CreateElement("Monto"); XmlNode fecha = doc.CreateElement("Fecha"); XmlNode tipo = doc.CreateElement("Tipo"); XmlNode id_cliente = doc.CreateElement("ID_Cliente"); //se asignan los valores dentro de las etiquetas //por ejemplo, <ID>***</ID> --> toma el valor ***montoEntity.ID.ToString(); ID.InnerText = montoEntity.ID.ToString(); descripcion.InnerText = montoEntity.Descripcion; monto.InnerText = montoEntity.Monto; fecha.InnerText = montoEntity.Fecha.ToString(); tipo.InnerText = montoEntity.Tipo; id_cliente.InnerText = montoEntity.ID_Cliente; //se anidan los nodos dentro de ingreso Ingreso.AppendChild(ID); Ingreso.AppendChild(descripcion); Ingreso.AppendChild(monto); Ingreso.AppendChild(fecha); Ingreso.AppendChild(tipo); Ingreso.AppendChild(id_cliente); //se anida el nodo <ingreso></ingreso> dentro del documento doc.DocumentElement.AppendChild(Ingreso); doc.Save(appSettings); }
private void btnEditarIngreso_Click(object sender, EventArgs e) { MontoEntities montoEntity = new MontoEntities(TipoMonto.Ingreso); if (dgvIngresos.SelectedRows.Count > 0) { montoEntity.ID = int.Parse(dgvIngresos.SelectedCells[0].Value.ToString()); montoEntity.Descripcion = dgvIngresos.SelectedCells[1].Value.ToString(); montoEntity.Tipo = dgvIngresos.SelectedCells[4].Value.ToString(); montoEntity.Monto = dgvIngresos.SelectedCells[2].Value.ToString(); CambiarDatos cambiarDatos = new CambiarDatos(montoEntity); cambiarDatos.ShowDialog(); this.ListarIngresos(DateTime.Now.Month); } }
public CambiarDatos(MontoEntities montoEntity) : this() { MontoEntities = montoEntity; switch (montoEntity.TipoMonto) { case TipoMonto.Ingreso: this.lblTitleChange.Text = "Editar Ingreso"; break; case TipoMonto.Gasto: this.lblTitleChange.Text = "Editar Gasto"; break; } this.txtChangeDescripcion.Text = montoEntity.Descripcion; this.txtChangeMonto.Text = montoEntity.Monto; this.ddlTipo.DataSource = IngLogic.GetTipos(false); /* * it's necessary because it may happen a "tipo" item be deleted.. * then if you want to edit some register which has that "tipo" * it will cause an error because it'll try to select its "tipo" in the combobox */ foreach (var s in ddlTipo.Items) { if (s.ToString() == montoEntity.Tipo) { this.ddlTipo.SelectedItem = montoEntity.Tipo; break; } /*it's not necessary an "else" statement because ddlTipo.DataSource = ... * already completes the combobox's list and will select the first item in * the list */ } }
private void btnBorrarIngreso_Click(object sender, EventArgs e) { MontoEntities montoEntity = new MontoEntities(TipoMonto.Ingreso); if (dgvIngresos.SelectedRows.Count > 0) { montoEntity.ID = int.Parse(dgvIngresos.SelectedCells[0].Value.ToString()); } DialogResult dr = MessageBox.Show("¿Estás seguro de borrar este registro? No podrá deshacerlo luego", "¿Estás seguro?", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); switch (dr) { case DialogResult.Yes: IngLogic.Save(montoEntity, Utiles.AccionEnum.TipoAccion.Delete); ListarIngresos(DateTime.Now.Month); break; case DialogResult.Cancel: break; } }
public void ModifyRow(MontoEntities montoEntity, string filePath, string subPath) { string appSettings = ConfigurationManager.AppSettings[filePath]; XmlDocument doc = new XmlDocument(); doc.Load(appSettings); foreach (XmlNode xNode in doc.SelectNodes(subPath)) { if (xNode.SelectSingleNode("ID").InnerText == montoEntity.ID.ToString()) { xNode.SelectSingleNode("Descripcion").InnerText = montoEntity.Descripcion; xNode.SelectSingleNode("Monto").InnerText = montoEntity.Monto; //xNode.SelectSingleNode("Fecha").InnerText = DateTime.Now.ToString(); xNode.SelectSingleNode("Tipo").InnerText = montoEntity.Tipo; doc.Save(appSettings); break; } } }
public void ModifyRow(MontoEntities montoEntity, string filePath, string subPath) { RecordManejador.ModifyRow(montoEntity, filePath, subPath); }
public void AddRowIngresos(MontoEntities montoEntity, string filePath) { RecordManejador.AdNuedRowIngresos(montoEntity, filePath); }