public bool EliminarRelTalonario(int cant, String ini, String fin) { int cont = 0; bool fl = false; string codrlTal = ""; Conexion.Open(); cmd = new SqlCommand("SELECT id_relTalonario FROM RelTalonario WHERE inicio='" + ini + "' AND fin='" + fin + "'", Conexion.sqlConexion); reader = cmd.ExecuteReader(); if (reader.Read()) { codrlTal = "" + (reader.GetInt64(0)); for (int i = 0; i < cant; i++) { BDPapeleta pap = new BDPapeleta(); String num = (int.Parse(ini) + i).ToString(); if (pap.eliminarAsignacionPapeleta(num)) { cont++; } } } if (cont == cant) { Conexion.Open(); cmd = new SqlCommand("DELETE FROM RelTalonario WHERE id_relTalonario=" + codrlTal, Conexion.sqlConexion); fl = (cmd.ExecuteNonQuery() > 0) ? true : false; Conexion.Close(); } Conexion.Close(); return(fl); }
private void txtNroPapeleta_TextChanged(object sender, TextChangedEventArgs e) { if (Validacion.IsValidCodPapeleta(txtNroPapeleta.Text) || (txtNroPapeleta.Text) == "") { lblErrNroPap.Content = "El Codigo de Papeleta no es Valido"; } else { lblErrNroPap.Content = ""; pap = new BDPapeleta(); if (pap.isExistPap(txtNroPapeleta.Text)) { if (pap.isEstado(txtNroPapeleta.Text)) { DataTable dt = pap.getById(txtNroPapeleta.Text); if (dt != null) { DataRow row = dt.Rows[0]; txtComisaria.Text = row["nombre_comisaria"].ToString(); } } else { MessageBox.Show("La papeleta ya ha sido ingresada o aun no ha sido Asignada a un efectivo"); } } else { lblErrNroPap.Content = "NO EXISTE"; } } }
public bool entregarPapeletas(String ini, String fin, String fec, String cip, String com, String tal, String cusu, int cant) { int cont = 0; String codrlTal = ""; bool fl = InsertRelTalonario(ini, fin, fec, cip, com, tal, cusu, cant); if (fl) { Conexion.Open(); cmd = new SqlCommand("SELECT id_relTalonario FROM RelTalonario WHERE inicio='" + ini + "' AND fin='" + fin + "' ORDER BY id_RelTalonario DESC", Conexion.sqlConexion); reader = cmd.ExecuteReader(); if (reader.Read()) { codrlTal = "" + (reader.GetInt64(0)); } for (int i = 0; i < cant; i++) { BDPapeleta pap = new BDPapeleta(); String num = (int.Parse(ini) + i).ToString(); if (pap.asignarPapeleta(num, codrlTal)) { cont++; } } } Conexion.Close(); return((fl && cont == cant)?true: false); }
public bool IngresarTal(String ini, String fin, String fec, String cod, String nofi, int cant) { int cont = 0; Conexion.Open(); cmd = new SqlCommand("INSERT INTO Talonario(inicio,fin,fecha_ingreso,id_usuario,numero_oficio)" + " VALUES('" + ini + "','" + fin + "','" + fec + "','" + cod + "','" + nofi + "')", Conexion.sqlConexion); bool fl = (cmd.ExecuteNonQuery() > 0) ? true : false; if (fl) { for (int i = 0; i < cant; i++) { BDPapeleta pap = new BDPapeleta(); String num = (int.Parse(ini) + i).ToString(); if (pap.ingresarPapeletas("(" + num + "," + 0 + "," + 1 + ",'" + nofi + "','A')")) { cont++; } } } Conexion.Close(); return((cont == cant && fl) ? true : false); }
private void btnGrabar_Click(object sender, RoutedEventArgs e) { try { int cant = Convert.ToInt32(lblCantidad.Content); if (cant > 0) { int lgNroOfi = ((lblErrNroOfi.Content) as String).Length; int lgTitOfi = ((lblErrTitOfi.Content) as String).Length; BDPapeleta pap = new BDPapeleta(); int numPapIng = pap.isIngresado(txtRangoDel.Text, txtRangoAl.Text); if (numPapIng == 0) { if (lgNroOfi == 0 && lgTitOfi == 0) { BDOficio ofi = new BDOficio(); if (ofi.IngresarOficio(txtNroOficio.Text, "M", txtTituloOficio.Text, txtDescripcion.Text)) { DateTime dt = dpFechaIngreso.SelectedDate.Value; String fecha = dt.Year + "/" + dt.Month + "/" + dt.Day; BDTal tal = new BDTal(); if (tal.IngresarTal(txtRangoDel.Text, txtRangoAl.Text, fecha, codUsuario, txtNroOficio.Text, Convert.ToInt32(lblCantidad.Content))) { MessageBox.Show("Se Grabo el Talonario y Oficio exitosamente"); } else { MessageBox.Show("Error: No se Guardo el Talonario"); } } else { MessageBox.Show("Error: No se grabo el oficio"); } } } else { MessageBox.Show(numPapIng + " papeletas dentro del rango ya han sido ingresadas en otro talonario"); } } else { MessageBox.Show("Error: La cantidad negativa"); } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } }
private void btnGrabar_Click(object sender, RoutedEventArgs e) { try { int cant = Convert.ToInt32(lblCantidad.Content); if (cant > 0) { if (codComi != "" && txtCodCIP.Text != "") { DateTime dt = dpFechaIngreso.SelectedDate.Value; String fecha = dt.Year + "/" + dt.Month + "/" + dt.Day; BDPapeleta pap = new BDPapeleta(); int numPapAsig = pap.isReAsignado(txtRangoDel.Text, txtRangoAl.Text); if (numPapAsig == cant) { BDTal tal = new BDTal(); if (tal.ReasignarTalonario(cant, txtRangoDel.Text, txtRangoAl.Text, fecha, txtCodCIP.Text, codComi, usuario)) { DataTable dat = tal.obtenerDatos(txtRangoDel.Text, txtRangoAl.Text); Reportes rep = new Reportes(); rep.TalonariosAsignados(dat); CargarTabPap(); MessageBox.Show("Se actualizacion los datos exitosamente"); } else { MessageBox.Show("no se guardaron los datos..."); } } else { MessageBox.Show("Error: no todas las papeletas se encuentran en el estado de reasignar"); } } else { MessageBox.Show("No se selecciono comisaria o no se ingreso CIP"); } } else { MessageBox.Show("Error: Rango de Papeletas "); } } catch (Exception ex) { MessageBox.Show("Error: " + ex.ToString()); } }
private void btnGrabar_Click(object sender, RoutedEventArgs e) { try { pap = new BDPapeleta(); if (lblErrNroPap.Content.ToString() == "") { if (pap.isEstado(txtNroPapeleta.Text)) { switch (cmbFisico.SelectedValue.ToString()) { case "C": int cont = 0; if (cmbInfraccion.SelectedIndex >= 0) { if (cont == 0) { if (lblErrDNI.Content.ToString() == str && lblErrBrevete.Content.ToString() == str) { con = new BDCon(); if (con.ingresarCon(txtIdConductor.Text, txtBrevete.Text, txtNombres.Text, txtApePat.Text, txtApeMat.Text)) { cont++; lblErrDNI.Foreground = Brushes.Red; lblErrDNI.Content = ""; lblErrBrevete.Foreground = Brushes.Red; lblErrBrevete.Content = ""; } else { MessageBox.Show("Error: No guardaron los datos del conductor"); } } else { if (lblErrDNI.Content.ToString() == "" && lblErrBrevete.Content.ToString() == "" && cont == 0) { cont++; } else { MessageBox.Show("Ingrese datos del conductor"); } } } if (cont == 1) { if (lblErrPlaca.Content.ToString() == str) { veh = new BDVeh(); if (veh.ingresarVeh(txtPlaca.Text, txtClase.Text, txtSerie.Text)) { lblErrPlaca.Foreground = Brushes.Red; lblErrPlaca.Content = ""; cont++; } else { MessageBox.Show("Error No se guadaron los datos del vehiculo"); } } else { if (lblErrPlaca.Content.ToString() == "" && cont == 1) { cont++; } else { MessageBox.Show("Ingrese datos del placa"); } } } if (cont == 2) { pap = new BDPapeleta(); DateTime dt = dpFechaImposicion.SelectedDate.Value; String fecha = dt.Year + "/" + dt.Month + "/" + dt.Day; dt = DateTime.Today; String tod = dt.Year + "/" + dt.Month + "/" + dt.Day; if (pap.DevolucionPapeleta(txtNroPapeleta.Text, cmbFisico.SelectedValue.ToString(), cmbInfraccion.SelectedValue.ToString(), fecha, tod, txtIdConductor.Text, txtPlaca.Text)) { MessageBox.Show("Se guardaron los datos exitosamente!"); txtNroPapeleta.Clear(); txtIdConductor.Clear(); txtNombres.Clear(); txtApePat.Clear(); txtApeMat.Clear(); txtPlaca.Clear(); txtClase.Clear(); txtSerie.Clear(); } else { MessageBox.Show("Error: No se guadaron los datos de papeleta intente de nuevo"); } } } else { MessageBox.Show("No se ingreso infraccion"); } break; case "R": case "X": DateTime f = DateTime.Today; String fec = f.Year + "/" + f.Month + "/" + f.Day; pap = new BDPapeleta(); if (pap.DevolucionPapeleta(txtNroPapeleta.Text, cmbFisico.SelectedValue.ToString(), fec)) { MessageBox.Show("Se Actualizacion los datos de la papeleta exitosamente"); } else { MessageBox.Show("Error: No se Realizo la Actualizacion de la papeleta"); } break; default: MessageBox.Show("No se seleecciono Estado"); break; } } else { MessageBox.Show("La papeleta ya ha sido ingresada o aun no ha sido Asignada a un efectivo"); } } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } }
public bool ReasignarTalonario(int cant, String ini, String fin, String fec, String efe, String com, String cusu) { int cont = 0; bool fl = false; String codreltal = null; String codTal = null; String fecreltal = "", cipreltal = "", comreltal = "", ofireltal = ""; int inireltal = 0, finreltal = 0, cantreltal = 0, devreltal = 0, usureltal = 0; Conexion.Open(); cmd = new SqlCommand("SELECT id_relTalonario, inicio, fin, cantidad, devueltas, fecha_entrega, id_usuario, " + "cip, id_comisaria, numero_oficio FROM relTalonario WHERE inicio <= '" + ini + "' and fin >='" + ini + "' and inicio <= '" + fin + "' and fin >='" + fin + "'", Conexion.sqlConexion); reader = cmd.ExecuteReader(); if (reader.Read()) { codreltal = "" + (reader.GetInt64(0)); inireltal = Convert.ToInt32(reader.GetString(1)); finreltal = Convert.ToInt32(reader.GetString(2)); cantreltal = reader.GetInt32(3); devreltal = reader.GetInt32(4); DateTime fechaRel1 = reader.GetDateTime(5); fecreltal = fechaRel1.Year + "/" + fechaRel1.Month + "/" + fechaRel1.Day; usureltal = reader.GetInt32(6); cipreltal = reader.GetString(7); comreltal = reader.GetString(8); //ofireltal = reader.GetString(9); int iniAsigTal = Convert.ToInt32(ini); int finAsigTal = Convert.ToInt32(fin); codTal = obtenerId(ini, fin); DataTable dt = new DataTable(); if (iniAsigTal == inireltal && finAsigTal == finreltal) { Conexion.Open(); cmd = new SqlCommand("UPDATE RelTalonario SET ini='" + (inireltal + cant) + "', devueltas='" + 0 + "', faltantes='" + (cantreltal) + "', fecha_entrega='" + fec + "', id_usuario='" + cusu + "', cip='" + efe + "', id_comisaria='" + com + "' WHERE id_relTalonario='" + codreltal + "'", Conexion.sqlConexion); fl = (cmd.ExecuteNonQuery() > 0) ? true : false; } if (iniAsigTal == inireltal && finAsigTal < finreltal) { if (this.InsertRelTalonario(ini, fin, fec, efe, com, codTal, cusu, cant)) { Conexion.Open(); cmd = new SqlCommand("UPDATE RelTalonario SET inicio='" + (inireltal + cant) + "', cantidad='" + (cantreltal - cant) + "', devueltas='" + (devreltal - cant) + "' WHERE id_relTalonario='" + codreltal + "'", Conexion.sqlConexion); fl = (cmd.ExecuteNonQuery() > 0) ? true : false; } else { fl = false; } } if (inireltal < iniAsigTal && finAsigTal == finreltal) { if (this.InsertRelTalonario(ini, fin, fec, efe, com, codTal, cusu, cant)) { Conexion.Open(); cmd = new SqlCommand("UPDATE RelTalonario SET fin='" + (finreltal - cant) + "', cantidad='" + (cantreltal - cant) + "', devueltas='" + (devreltal - cant) + "' WHERE id_relTalonario='" + codreltal + "'", Conexion.sqlConexion); fl = (cmd.ExecuteNonQuery() > 0) ? true : false; } else { fl = false; } } if (inireltal < iniAsigTal && finAsigTal < finreltal) { if (this.InsertRelTalonario(ini, fin, fec, efe, com, codTal, cusu, cant)) { int finPaptal1 = (iniAsigTal - 1); int nroPaptal1 = iniAsigTal - inireltal; BDPapeleta pap = new BDPapeleta(); int devPaptal1 = pap.cantDevuelta(inireltal.ToString(), finPaptal1.ToString()); Conexion.Open(); cmd = new SqlCommand("UPDATE RelTalonario SET fin='" + finPaptal1 + "', cantidad='" + nroPaptal1 + "', devueltas='" + devPaptal1 + "', faltantes='" + (nroPaptal1 - devPaptal1) + "' WHERE id_relTalonario='" + codreltal + "'", Conexion.sqlConexion); if (cmd.ExecuteNonQuery() > 0) { int iniPapTal2 = (finAsigTal + 1); int nroPapTal2 = (finreltal - finAsigTal); int devPapTal2 = pap.cantDevuelta(iniPapTal2.ToString(), finreltal.ToString()); Conexion.Open(); cmd = new SqlCommand("INSERT INTO RelTalonario(inicio,fin,cantidad, devueltas, faltantes,fecha_entrega,id_usuario,id_talonario,cip,id_comisaria)" + " VALUES('" + iniPapTal2 + "','" + finreltal + "','" + nroPapTal2 + "','" + devPapTal2 + "','" + (nroPapTal2 - devPapTal2) + "','" + fecreltal + "','" + usureltal + "','" + codTal + "','" + cipreltal + "','" + comreltal + "')", Conexion.sqlConexion); fl = (cmd.ExecuteNonQuery() > 0) ? true : false; } else { fl = false; } } else { fl = false; } } if (fl) { String newCodAsigTal = ""; Conexion.Open(); cmd = new SqlCommand("SELECT id_relTalonario FROM relTalonario WHERE inicio='" + ini + "' AND fin='" + fin + "' ORDER BY id_relTalonario DESC", Conexion.sqlConexion); reader = cmd.ExecuteReader(); if (reader.Read()) { newCodAsigTal = "" + (reader.GetInt64(0)); } for (int i = 0; i < cant; i++) { BDPapeleta pap = new BDPapeleta(); String num = (int.Parse(ini) + i).ToString(); if (pap.asignarPapeleta(num, newCodAsigTal)) { cont++; } } } } Conexion.Close(); return(true); }
private void btnGuardar_Click(object sender, RoutedEventArgs e) { try { int cant = Convert.ToInt32(lblCantidad.Content); if (cant > 0) { if (codEfe != "" || codEfe != null) { BDTal tal = new BDTal(); String codTal = tal.obtenerId(txtRangoDel.Text, txtRangoAl.Text); if (codTal != null) { BDPapeleta pap = new BDPapeleta(); int numPapAsig = pap.isAsignado(txtRangoDel.Text, txtRangoAl.Text); if (numPapAsig == 0) { DateTime dt = dpFechaEnvio.SelectedDate.Value; String fecha = dt.Year + "/" + dt.Month + "/" + dt.Day; if (tal.entregarPapeletas(txtRangoDel.Text, txtRangoAl.Text, fecha, codEfe, cmbCom.SelectedValue as String, codTal, usuario, cant)) { CargarTablaTal(); if (flagArch) { DataTable dat = tal.obtenerDatos(txtRangoDel.Text, txtRangoAl.Text); Reportes rep = new Reportes(); rep.TalonariosEntregados(dat); ClearAll(); } MessageBox.Show("Se Asigno correctamente las papeletas"); } else { MessageBox.Show("Error: Al asignar las papeletas"); } } else { MessageBox.Show(numPapAsig + " papeletas dentro del rango ya han sido asignadas"); } } else { MessageBox.Show("Rango de papeletas no pertenece a un talonario"); } } else { MessageBox.Show("No se selecciono Efectivo"); } } else { MessageBox.Show("Error: Rango de Papeletas "); } } catch (Exception ex) { MessageBox.Show("Error:" + ex.ToString()); } }
public void CargarTabPap() { pap = new BDPapeleta(); dataGridPape.ItemsSource = pap.PapeletasaAsignar().DefaultView; }