private void pictureBox4_Click(object sender, EventArgs e)
        {
            if (pais_carta_manifiesto != "" && numero_carta_manifiesto != "" && numero_manifiesto != "")
            {
                Base   nueva             = new Base();
                string id_del_manifiesto = nueva.Quitar_espacios(nueva.Consulta("SELECT manifiestos_final.llave" +
                                                                                " FROM manifiestos_de_carga INNER JOIN(cartas_de_porte INNER JOIN(cartas_final INNER JOIN manifiestos_final ON cartas_final.llave = manifiestos_final.id_carta_porte) ON cartas_de_porte.llave = cartas_final.id_carta) ON manifiestos_de_carga.llave = manifiestos_final.id_manifiesto" +
                                                                                " WHERE(([cartas_de_porte].[codigo_pais] = '" + pais_carta_manifiesto + "') AND([cartas_de_porte].[numero_cartaporte] = " + numero_carta_manifiesto + ") AND([manifiestos_de_carga].[numero_manifiesto_pais] = " + numero_manifiesto + "))").Rows[0].ItemArray[0].ToString());

                DialogResult respuesta = new DialogResult();
                respuesta = MessageBox.Show("¿Seguro que desea eliminar el manifiesto " + numero_manifiesto + " de la carta de porte " + pais_carta_manifiesto + numero_carta_manifiesto, "Eliminar Manifiesto", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                if (respuesta.ToString() == "Yes")
                {
                    //////////////////////////////////
                    string comando = "DELETE" +
                                     " FROM Conductores_en_manifiesto" +
                                     " where[Conductores_en_manifiesto].[id_manifiestos] =" + id_del_manifiesto;
                    nueva.comando(comando);



                    //////////////////////////////////
                    string comando1 = "DELETE" +
                                      " FROM manifiestos_final" +
                                      " where[manifiestos_final].[llave] =" + id_del_manifiesto;
                    nueva.comando(comando1);


                    //////////////////////////////////
                    string comando2 = "DELETE" +
                                      " FROM manifiestos_de_carga" +
                                      " where[manifiestos_de_carga].[llave] =" + id_del_manifiesto;
                    nueva.comando(comando2);


                    Recargar();
                }
            }
        }
Beispiel #2
0
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            Base nueva = new Base();

            refrescar_valores();

            string busquedaEcu = "Select numero_cartaporte from cartas_de_porte where codigo_pais='EC' Order By numero_cartaporte asc";
            string busquedaCOL = "Select numero_cartaporte from cartas_de_porte where codigo_pais='CO' Order By numero_cartaporte asc";
            string busquedaPE  = "Select numero_cartaporte from cartas_de_porte where codigo_pais='PE' Order By numero_cartaporte asc";

            if (nueva.Consulta(busquedaEcu).Rows.Count != 0)
            {
                numeroEC = Convert.ToString(Convert.ToInt32(nueva.Consulta(busquedaEcu).Rows[nueva.Consulta(busquedaEcu).Rows.Count - 1].ItemArray[0]) + 1);
            }

            if (nueva.Consulta(busquedaCOL).Rows.Count != 0)
            {
                numeroCOL = Convert.ToString(Convert.ToInt32(nueva.Consulta(busquedaCOL).Rows[nueva.Consulta(busquedaCOL).Rows.Count - 1].ItemArray[0]) + 1);
            }

            if (nueva.Consulta(busquedaPE).Rows.Count != 0)
            {
                numeroPE = Convert.ToString(Convert.ToInt32(nueva.Consulta(busquedaPE).Rows[nueva.Consulta(busquedaPE).Rows.Count - 1].ItemArray[0]) + 1);
            }


            if (!string.IsNullOrEmpty(richTextBox1.Text) && !string.IsNullOrEmpty(richTextBox2.Text) && (comboBox1.Text == "EC" || comboBox1.Text == "CO" || comboBox1.Text == "PE"))
            {
                if (!nueva.Dato_en_consulta(nueva.Quitar_espacios(c2), "Select c2yc3 from Organizaciones_y_direcciones"))
                {
                    string comando1 = "INSERT INTO Organizaciones_y_direcciones(c2yc3) " +
                                      "VALUES('" + c2 + "')";
                    nueva.comando(comando1);
                }
                string codigo_emisor = nueva.Quitar_espacios(Convert.ToString(nueva.Consulta("Select id_organizacion from Organizaciones_y_direcciones where c2yc3 ='" + c2 + "'").Rows[0].ItemArray[0]));

                if (!nueva.Dato_en_consulta(nueva.Quitar_espacios(c3), "Select c2yc3 from Organizaciones_y_direcciones"))
                {
                    string comando2 = "INSERT INTO Organizaciones_y_direcciones(c2yc3) " +
                                      "VALUES('" + c3 + "')";
                    nueva.comando(comando2);
                }
                string codigo_receptor = nueva.Quitar_espacios(Convert.ToString(nueva.Consulta("Select id_organizacion from Organizaciones_y_direcciones where c2yc3 ='" + c3 + "'").Rows[0].ItemArray[0]));

                if (id == "-1")
                {
                    string numero = "";
                    if (comboBox1.Text == "EC")
                    {
                        numero = numeroEC;
                    }
                    else if (comboBox1.Text == "CO")
                    {
                        numero = numeroCOL;
                    }
                    else
                    {
                        numero = numeroPE;
                    }

                    string comando3 = "INSERT INTO cartas_de_porte (fecha_creacion,fecha_modificacion,codigo_pais,numero_cartaporte,c4,c5,c6,c7,c8,c9,c10,c11,c12) " +
                                      "VALUES(NOW(), NOW(), '" + comboBox1.Text + "', '" + numero + "', '" + c4 + "', '" + c5 + "', '" +
                                      c6 + "','" + c7 + "','" + c8 + "','" + c9 + "','" + c10 + "','" + c11 + "','" + c12 + "')";
                    nueva.comando(comando3);
                    numero_final_para_enviar_al_manifiesto = numero;
                }
                else
                {
                    string codigo_pais = comboBox1.Text;
                    string numero      = "";
                    if (comboBox1.Text == "EC")
                    {
                        numero = numeroEC;
                    }
                    else if (comboBox1.Text == "CO")
                    {
                        numero = numeroCOL;
                    }
                    else
                    {
                        numero = numeroPE;
                    }

                    DataTable codigopais = nueva.Consulta("Select cartas_de_porte.codigo_pais from cartas_final inner join cartas_de_porte on cartas_final.llave=cartas_de_porte.llave where cartas_final.llave = " + id + "");
                    if (nueva.Quitar_espacios(Convert.ToString(codigopais.Rows[0].ItemArray[0])) == comboBox1.Text)
                    {
                        DataTable numero_cartaporte = nueva.Consulta("Select cartas_de_porte.numero_cartaporte from cartas_final inner join cartas_de_porte on cartas_final.llave=cartas_de_porte.llave where cartas_final.llave = " + id + "");
                        numero      = nueva.Quitar_espacios(Convert.ToString(numero_cartaporte.Rows[0].ItemArray[0]));
                        codigo_pais = nueva.Quitar_espacios(Convert.ToString(codigopais.Rows[0].ItemArray[0]));
                    }

                    DataTable id_cartaporte = nueva.Consulta("Select cartas_de_porte.llave from cartas_final inner join cartas_de_porte on cartas_final.llave=cartas_de_porte.llave where cartas_final.llave = " + id);
                    string    comando       = "UPDATE cartas_de_porte SET fecha_modificacion=NOW(),codigo_pais='" + codigo_pais + "',numero_cartaporte='" + numero + "',c4='" + c4 + "',c5='" + c5 + "',c6='" + c6 + "',c7='" + c7 + "',C8='" + c8 + "',c9='" + c9 + "" +
                                              "',c10='" + c10 + "',c11='" + c11 + "',c12='" + c12 + "' WHERE llave=" + nueva.Quitar_espacios(Convert.ToString(id_cartaporte.Rows[0].ItemArray[0])) + "";
                    nueva.comando(comando);

                    numero_final_para_enviar_al_manifiesto = numero;
                }
                DataTable cartas = nueva.Consulta("Select llave from cartas_de_porte");

                if (id == "-1")
                {
                    string comando4 = "INSERT INTO Organizaciones_en_cartaportes " +
                                      "VALUES('" + nueva.Quitar_espacios(Convert.ToString(cartas.Rows[cartas.Rows.Count - 1].ItemArray[0])) + "','" + codigo_emisor + "','EMISOR')";
                    nueva.comando(comando4);

                    string comando5 = "INSERT INTO Organizaciones_en_cartaportes " +
                                      "VALUES('" + nueva.Quitar_espacios(Convert.ToString(cartas.Rows[cartas.Rows.Count - 1].ItemArray[0])) + "','" + codigo_receptor + "','RECEPTOR')";
                    nueva.comando(comando5);
                }
                else
                {
                    DataTable id_cartaporte = nueva.Consulta("Select cartas_de_porte.llave from cartas_final inner join cartas_de_porte on cartas_final.llave=cartas_de_porte.llave  where cartas_final.llave = " + id);
                    string    comando4      = "UPDATE Organizaciones_en_cartaportes SET id_organizacion='" + codigo_emisor + "' Where id_carta =" + id_cartaporte.Rows[0].ItemArray[0] + " and" +
                                              " papel_organizacion='EMISOR'";
                    nueva.comando(comando4);

                    string comando5 = "UPDATE Organizaciones_en_cartaportes SET id_organizacion='" + codigo_receptor + "' Where id_carta =" + id_cartaporte.Rows[0].ItemArray[0] + " and" +
                                      " papel_organizacion='RECEPTOR'";
                    nueva.comando(comando5);
                }

                if (id == "-1")
                {
                    string comando6 = "INSERT INTO cartas_final (id_carta, c13_1,c13_2,c14,c15,c16,c17_1,c17_2,c17_3,c17_4,c17_5,c17_6,c17_7,c17_8,c17_9,c17_10,c17_11,c17_12,c18,c19,c21,c22,dian) " +
                                      " VALUES('" + cartas.Rows[cartas.Rows.Count - 1].ItemArray[0] + "','" + c13_1 + "','" + c13_2 + "','" +
                                      c14 + "','" + c15 + "','" + c16 + "','" + c17_1 + "','" + c17_2 + "','" + c17_3 + "','" + c17_4 + "','" + c17_5 + "','" + c17_6 + "','" +
                                      c17_7 + "','" + c17_8 + "','" + c17_9 + "','" + c17_10 + "','" + c17_11 + "','" + c17_12 + "','" + c18 + "','" + c19 + "','" + c21 + "','" + c22 + "','" + dian + "')";
                    nueva.comando(comando6);

                    id           = cartas.Rows[cartas.Rows.Count - 1].ItemArray[0].ToString();
                    label34.Text = "EDITANDO CARTA DE PORTE";
                }
                else
                {
                    string comando6 = "UPDATE cartas_final SET c13_1='" + c13_1 + "',dian='" + dian + "',c13_2='" + c13_2 + "',c14='" + c14 + "'," +
                                      "c15='" + c15 + "',c16='" + c16 + "',c17_1='" + c17_1 + "',c17_2='" + c17_2 + "',c17_3='" + c17_3 + "',c17_4='" + c17_4 + "'," +
                                      "c17_5='" + c17_5 + "',c17_6='" + c17_6 + "',c17_7='" + c17_7 + "',c17_8='" + c17_8 + "',c17_9='" + c17_9 + "',c17_10='" + c17_10 + "'" +
                                      ",c17_11='" + c17_11 + "',c17_12='" + c17_12 + "',c18='" + c18 + "',c19='" + c19 + "',c21='" + c21 + "',c22='" + c22 + "'" +
                                      "WHERE llave=" + id;
                    nueva.comando(comando6);
                }
                MessageBox.Show("Se ha guardado exitosamente");
            }
            else
            {
                MessageBox.Show("No puede dejar el campo 2 y 3 vacíos, además se tiene que ingresar el código del país ", "Advertencia Ingreso de datos", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private void pictureBox3_Click(object sender, EventArgs e)
        {
            if (pais_carta != "" && numero_carta != "")
            {
                Base   nueva             = new Base();
                string id_carta_De_porte = nueva.Quitar_espacios(nueva.Consulta("SELECT cartas_final.llave" +
                                                                                " FROM cartas_de_porte INNER JOIN cartas_final ON cartas_de_porte.llave = cartas_final.id_carta" +
                                                                                " WHERE(([cartas_de_porte].[codigo_pais] = '" + pais_carta + "') AND([cartas_de_porte].[numero_cartaporte] = " + numero_carta + "))").Rows[0].ItemArray[0].ToString());

                DialogResult respuesta = new DialogResult();
                respuesta = MessageBox.Show("¿Seguro que desea eliminar la carta de porte " + pais_carta + numero_carta + " ? También se eliminarán todos los manifiestos que tenga.", "Eliminar Carta de Porte", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                DataTable id_manifiestos = nueva.Consulta("SELECT DISTINCT (manifiestos_de_carga.llave) AS Expr1" +
                                                          " FROM(manifiestos_de_carga INNER JOIN((cartas_de_porte INNER JOIN cartas_final ON cartas_de_porte.llave = cartas_final.id_carta) INNER JOIN manifiestos_final ON cartas_final.llave = manifiestos_final.id_carta_porte) ON manifiestos_de_carga.llave = manifiestos_final.id_manifiesto) INNER JOIN Conductores_en_manifiesto ON manifiestos_de_carga.llave = Conductores_en_manifiesto.id_manifiestos" +
                                                          " WHERE(((cartas_final.llave) = " + id_carta_De_porte + "))");

                if (respuesta.ToString() == "Yes")
                {
                    ////////////////////////////
                    string el_organi_carta = "DELETE " +
                                             " FROM Organizaciones_en_cartaportes " +
                                             " WHERE [Organizaciones_en_cartaportes].[id_carta] =" + id_carta_De_porte;
                    nueva.comando(el_organi_carta);

                    //////////////////////////////////
                    for (int i = 0; i < id_manifiestos.Rows.Count; i++)
                    {
                        string comando = "DELETE" +
                                         " FROM Conductores_en_manifiesto" +
                                         " where[Conductores_en_manifiesto].[id_manifiestos] =" + nueva.Quitar_espacios(id_manifiestos.Rows[i].ItemArray[0].ToString());
                        nueva.comando(comando);
                    }


                    //////////////////////////////////
                    for (int i = 0; i < id_manifiestos.Rows.Count; i++)
                    {
                        string comando = "DELETE" +
                                         " FROM manifiestos_final" +
                                         " where[manifiestos_final].[llave] =" + nueva.Quitar_espacios(id_manifiestos.Rows[i].ItemArray[0].ToString());
                        nueva.comando(comando);
                    }

                    //////////////////////////////////
                    for (int i = 0; i < id_manifiestos.Rows.Count; i++)
                    {
                        string comando = "DELETE" +
                                         " FROM manifiestos_de_carga" +
                                         " where[manifiestos_de_carga].[llave] =" + nueva.Quitar_espacios(id_manifiestos.Rows[i].ItemArray[0].ToString());
                        nueva.comando(comando);
                    }


                    string el_cartas_final = "DELETE FROM cartas_final where [cartas_final].[llave] =  " + id_carta_De_porte;
                    string el_cartas_porte = "DELETE FROM cartas_de_porte where [cartas_de_porte].[llave] =  " + id_carta_De_porte;

                    nueva.comando(el_cartas_final);
                    nueva.comando(el_cartas_porte);

                    Recargar();
                }
            }
        }