private void cargarTabla() { dgvServicios.DataSource = CrudServicios.Consulta(); dgvEquiposD.DataSource = CrudServicios.TraerEquipoD(); dgvServicios.AutoResizeColumns(); dgvEquiposD.AutoResizeColumns(); }
private void btnGuardarServicio_Click(object sender, EventArgs e) { try { DialogResult dr = MessageBox.Show("¿Desea ingresar este comprobante?", "INFO", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk); if (dr.Equals(DialogResult.Yes)) { if (txtMonto.Text != null && txtFi.Text != null && DateTime.Parse(txtFi.Text) <= DateTime.Parse(txtFf.Text) && txtFf.Text != null && (radioBnoActivo.Checked != false || radioBsiActivo.Checked != false) && (radioBnoPagado.Checked != false || radioBsiPagado.Checked != false)) { if (id.Equals(Guid.Empty)) { if (CrudServicios.verificarComprobante(Guid.Parse(txtClientes.SelectedValue.ToString()), Convert.ToDateTime(txtFi.Text), Convert.ToDateTime(txtFf.Text)).Equals(false)) { int c1 = DateTime.Compare(DateTime.Parse(txtFi.Text), DateTime.Parse(DateTime.Today.ToShortDateString())); int c2 = DateTime.Compare(DateTime.Parse(txtFf.Text), DateTime.Parse(DateTime.Today.ToShortDateString())); if (c1 >= 0 && c2 >= 0) { id = Guid.NewGuid(); idS = Guid.NewGuid(); idU = Conexion.usuario.idUsuario; idC = Guid.Parse(txtClientes.SelectedValue.ToString()); foreach (DataGridViewRow item in dgvEquiposD.Rows) { if (item.Cells[0].Value.Equals(true)) { CrudServicios.AltaServicio(new Servicio { idServicio = idS, idEquipo = Guid.Parse(item.Cells[1].Value.ToString()) }, activo); } } Comprobantes newRecibo = new Comprobantes { idComprobante = id, idCliente = idC, idUsuario = idU, idServicio = idS, fechaInicio = Convert.ToDateTime(txtFi.Text), fechaFinal = Convert.ToDateTime(txtFf.Text), pagado = activoPago, activo = activo, monto = Convert.ToDecimal(txtMonto.Text) }; CrudServicios.AltaComprobante(newRecibo); clearInterface(); cargarTabla(); } else { MessageBox.Show("La fecha no es la correcta", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("El comprobante ya ha sido creado, búscalo en la tabla debajo", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { foreach (DataGridViewRow item in dgvEquiposA.Rows) { if (!item.Cells[0].Value.Equals(true)) { CrudServicios.BajaServicio(Guid.Parse(item.Cells[1].Value.ToString()), idS); } } foreach (DataGridViewRow item in dgvEquiposD.Rows) { if (item.Cells[0].Value.Equals(true)) { CrudServicios.AltaServicio(new Servicio { idServicio = idS, idEquipo = Guid.Parse(item.Cells[1].Value.ToString()) }, activo); } } Comprobantes recibo = new Comprobantes { idComprobante = id, idCliente = idC, idUsuario = idU, idServicio = idS, fechaInicio = Convert.ToDateTime(txtFi.Text), fechaFinal = Convert.ToDateTime(txtFf.Text), pagado = activoPago, activo = activo, monto = Convert.ToDecimal(txtMonto.Text) }; CrudServicios.ModificarComprobante(recibo); clearInterface(); cargarTabla(); } } else { MessageBox.Show("Ingrese o corrija los campos", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void dgvServicios_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { var senderGrid = (DataGridView)sender; if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) { var i = Guid.Parse(dgvServicios.CurrentRow.Cells[1].Value.ToString()); var doc = Conexion.getInstance().Documentos.Where(w => w.idComprobante == i).FirstOrDefault(); string path = AppDomain.CurrentDomain.BaseDirectory; string folder = path + "temp/"; string fullFilePath = folder + doc.nombre; Directory.CreateDirectory(folder); File.WriteAllBytes(fullFilePath, doc.pdf); Process.Start(fullFilePath); return; } if (id.Equals(Guid.Empty)) { id = Guid.Parse(dgvServicios.CurrentRow.Cells[1].Value.ToString()); idC = Guid.Parse(dgvServicios.CurrentRow.Cells[2].Value.ToString()); idS = Guid.Parse(dgvServicios.CurrentRow.Cells[8].Value.ToString()); idU = Guid.Parse(dgvServicios.CurrentRow.Cells[3].Value.ToString()); txtClientes.SelectedValue = idC; txtFi.Text = dgvServicios.CurrentRow.Cells[9].Value.ToString(); txtFf.Text = dgvServicios.CurrentRow.Cells[10].Value.ToString(); //activo if (Convert.ToBoolean(dgvServicios.CurrentRow.Cells[12].Value)) { radioBsiActivo.Checked = true; radioBnoActivo.Checked = false; } else { radioBsiActivo.Checked = false; radioBnoActivo.Checked = true; } // pagado if (Convert.ToBoolean(dgvServicios.CurrentRow.Cells[13].Value)) { radioBsiPagado.Checked = true; radioBnoPagado.Checked = false; } else { radioBsiPagado.Checked = false; radioBnoPagado.Checked = true; } dgvEquiposA.DataSource = CrudServicios.TraerEquipoA(idS); foreach (DataGridViewRow item in dgvEquiposA.Rows) { item.Cells[0].Value = true; suma += Convert.ToInt32(item.Cells[5].Value); } foreach (DataGridViewRow item in dgvEquiposD.Rows) { item.Cells[0].Value = false; } dgvEquiposA.AutoResizeColumns(); txtMonto.Text = suma.ToString(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }