Пример #1
0
        //Registrar remesa
        private void btnRegistrar_Click(object sender, System.EventArgs e)
        {
            //Guardar Remesa
            string ruta = ddlRuta.SelectedValue, planilla = ddlPlanilla.SelectedValue, agencia = ddlAgencia.SelectedValue;
            string nitEmisor = txtNITEmisor.Text.Trim(), nombreEmisor = txtNITEmisora.Text.Trim(), apellidoEmisor = txtNITEmisorb.Text.Trim(), tnitEmisor = txtNITEmisorc.SelectedValue, telefonoEmisor = txtNITEmisord.Text.Trim(), direccionEmisor = txtNITEmisore.Text.Trim();
            string nitReceptor = txtNITReceptor.Text.Trim(), nombreReceptor = txtNITReceptora.Text.Trim(), apellidoReceptor = txtNITReceptorb.Text.Trim(), tnitReceptor = txtNITReceptorc.SelectedValue, telefonoReceptor = txtNITReceptord.Text.Trim(), direccionReceptor = txtNITReceptore.Text.Trim();
            double totalE;

            try{
                totalE = Convert.ToDouble(lblTotal.Text);
                if (totalE < 0)
                {
                    throw(new Exception());
                }
            }
            catch {
                Response.Write("<script language='javascript'>alert('Total no valido.');</script>");
                return;
            }

            //Responsable
            string nitResponsable = DBFunctions.SingleData("select mnit_nit from DBXSCHEMA.susuario where susu_login='******';");

            if (nitResponsable.Length == 0)
            {
                Response.Write("<script language='javascript'>alert('El usuario actual (responsable) no tiene un NIT asociado.');</script>");
                return;
            }
            //Conseguir papeleria
            string numDocumento = Encomiendas.TraerSiguienteEncomiendaVirtual();

            if (numDocumento.Length == 0)
            {
                Response.Write("<script language='javascript'>alert('No hay papeleria disponible.');</script>");
                return;
            }
            string numLineaS;

            if (planilla.Length > 0)
            {
                numLineaS = DBFunctions.SingleData("SELECT NUMERO_LINEAS+1 FROM DBXSCHEMA.MPLANILLAVIAJE WHERE MPLA_CODIGO=" + planilla);
                if (numLineaS.Length == 0)
                {
                    numLineaS = "1";
                }
            }
            else
            {
                numLineaS = "NULL";
                planilla  = "NULL";
            }
            ruta = "'" + ruta + "'";

            ArrayList sqlStrings    = new ArrayList();
            string    ciudad        = DBFunctions.SingleData("SELECT PCIU_CODIGO FROM DBXSCHEMA.MAGENCIA WHERE MAG_CODIGO=" + agencia + ";");
            string    docReferencia = txtNumDocReferencia.Text.Trim();

            docReferencia = (docReferencia.Length == 0)?"NULL":"'" + docReferencia + "'";
            string placa = txtPlaca.Text;

            placa = (placa.Length == 0)?"NULL":"'" + placa + "'";
            string NitComodin   = "NS";
            string nitEmisor1   = nitEmisor;
            string nitReceptor1 = nitReceptor;

            //Guardar NITs si no existen
            //Emisor
            if (nitEmisor == NitComodin)
            {
                nitEmisor1 = "REMENV" + numDocumento;
                if (!DBFunctions.RecordExist("SELECT MPAS_NIT FROM dbxschema.mpasajero WHERE MPAS_NIT='" + nitEmisor1 + "';"))
                {
                    sqlStrings.Add("INSERT INTO DBXSCHEMA.mpasajero VALUES('" + nitEmisor1 + "','" + nombreEmisor + "',NULL,'" + apellidoEmisor + "',NULL,'" + direccionEmisor + "','" + ciudad + "','" + telefonoEmisor + "','ND','ND');");
                }
            }
            else
            if (!DBFunctions.RecordExist("SELECT MPAS_NIT FROM dbxschema.mpasajero WHERE MPAS_NIT='" + nitEmisor + "';"))
            {
                sqlStrings.Add("INSERT INTO DBXSCHEMA.mpasajero VALUES('" + nitEmisor + "','" + nombreEmisor + "',NULL,'" + apellidoEmisor + "',NULL,'" + direccionEmisor + "','" + ciudad + "','" + telefonoEmisor + "','ND','ND');");
            }
            //Receptor

            if (nitReceptor == NitComodin)
            {
                nitReceptor1 = "REMREC" + numDocumento;
                if (!DBFunctions.RecordExist("SELECT MPAS_NIT FROM dbxschema.mpasajero WHERE MPAS_NIT='" + nitReceptor1 + "';"))
                {
                    sqlStrings.Add("INSERT INTO DBXSCHEMA.mpasajero VALUES('" + nitReceptor1 + "','" + nombreReceptor + "',NULL,'" + apellidoReceptor + "',NULL,'" + direccionReceptor + "','" + ciudad + "','" + telefonoReceptor + "','ND','ND');");
                }
            }
            else
            if (nitEmisor != nitReceptor && !DBFunctions.RecordExist("SELECT MPAS_NIT FROM dbxschema.mpasajero WHERE MPAS_NIT='" + nitReceptor + "';"))
            {
                sqlStrings.Add("INSERT INTO DBXSCHEMA.mpasajero VALUES('" + nitReceptor + "','" + nombreReceptor + "',NULL,'" + apellidoReceptor + "',NULL,'" + direccionReceptor + "','" + ciudad + "','" + telefonoReceptor + "','ND','ND');");
            }

            //Actualizar papeleria
            sqlStrings.Add("INSERT INTO DBXSCHEMA.MCONTROL_PAPELERIA  VALUES('REM'," + numDocumento + ",'V',0,'" + DateTime.Now.ToString("yyyy-MM-dd") + "',0," + agencia + ",'" + DateTime.Now.ToString("yyyy-MM-dd") + "','" + nitResponsable + "',0,'" + DateTime.Now.ToString("yyyy-MM-dd") + "',NULL,NULL,NULL,NULL,NULL,NULL,NULL," + planilla + ",NULL,NULL,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');");

            //Insertar encomienda
            sqlStrings.Add("INSERT INTO DBXSCHEMA.MENCOMIENDAS VALUES('REM'," + numDocumento + ",'V'," + agencia + ",'" + nitResponsable + "',null,null," + planilla + "," + numLineaS + "," + ruta + ",'" + nitEmisor1 + "','" + direccionEmisor + "','" + telefonoEmisor + "','" + nitReceptor1 + "','" + direccionReceptor + "','" + telefonoReceptor + "','" + lblDescripcion.Text + "'," + lblUnidades.Text.Replace(",", "") + "," + lblPeso.Text.Replace(",", "") + "," + lblVolumen.Text.Replace(",", "") + "," + lblPorcentajeIVA.Text.Replace(",", "") + "," + lblValorIVA.Text.Replace(",", "") + "," + lblCostoEncomienda.Text.Replace(",", "") + ",0," + lblAvaluo.Text.Replace(",", "") + "," + totalE.ToString("0") + ",'" + lblFecha.Text + "',NULL,'A'," + docReferencia + "," + placa + ");");

            //Actualizar planilla->num linea si es Real
            if (!planilla.Equals("NULL"))
            {
                sqlStrings.Add("UPDATE DBXSCHEMA.MPLANILLAVIAJE SET NUMERO_LINEAS=NUMERO_LINEAS+1 WHERE MPLA_CODIGO=" + planilla + ";");
            }

            if (DBFunctions.Transaction(sqlStrings))
            {
                lblNumDocumento.Text    = numDocumento;
                pnlImprimir.Visible     = true;
                pnlCrear.Visible        = false;
                ViewState["Encomienda"] = numDocumento;
            }
            else
            {
                lblError.Text += "Error: " + DBFunctions.exceptions + "<br><br>";
                return;
            }
        }
Пример #2
0
        //Validar y pedir confirmacion
        private void btnGuardar_Click(object sender, System.EventArgs e)
        {
            string   ruta = ddlRuta.SelectedValue, planilla = ddlPlanilla.SelectedValue, agencia = ddlAgencia.SelectedValue;
            string   nitEmisor = txtNITEmisor.Text.Trim(), nombreEmisor = txtNITEmisora.Text.Trim(), apellidoEmisor = txtNITEmisorb.Text.Trim(), tnitEmisor = txtNITEmisorc.SelectedValue, telefonoEmisor = txtNITEmisord.Text.Trim(), direccionEmisor = txtNITEmisore.Text.Trim();
            string   nitReceptor = txtNITReceptor.Text.Trim(), nombreReceptor = txtNITReceptora.Text.Trim(), apellidoReceptor = txtNITReceptorb.Text.Trim(), tnitReceptor = txtNITReceptorc.SelectedValue, telefonoReceptor = txtNITReceptord.Text.Trim(), direccionReceptor = txtNITReceptore.Text.Trim();
            DateTime fecha = new DateTime();

            //DateTime fecha;
            //Validaciones
            if (ruta.Length == 0)
            {
                Response.Write("<script language='javascript'>alert('Debe seleccionar la ruta.');</script>");
                return;
            }
            // Verifica Bus
            string placa = txtPlaca.Text;

            if (placa.Length != 0)
            {
                string estado_bus = DBFunctions.SingleData("select testa_codigo from DBXSCHEMA.MBUSAFILIADO  where MCAT_PLACA='" + placa + "';");
                if (estado_bus.Length == 0 || estado_bus == "9")
                {
                    Response.Write("<script language='javascript'>alert(' El Bus esta Retirado o NO Existe.');</script>");
                    return;
                }
            }
            //fecha
            try
            {
                fecha = Convert.ToDateTime(txtFecha.Text);
            }
            catch
            {
                Response.Write("<script language='javascript'>alert('Fecha no válida.');</script>");
                return;
            }
            //Verifica cierre mensual

            int anio    = fecha.Year;
            int mes     = fecha.Month;
            int periodo = anio * 100 + mes;

            string estado = DBFunctions.SingleData("select estado_cierre from DBXSCHEMA.periodos_cierre_transporte where numero_periodo=" + periodo + ";");

            if (estado.Length == 0 || estado == "C")
            {
                Response.Write("<script language='javascript'>alert(' El periodo de la fecha esta cerrado o NO Existe.');</script>");
                return;
            }
            // Si existe es porque ya se contabilizo para la Agencia_dia
            if (DBFunctions.RecordExist("select MAG_CODIGO from DBXSCHEMA.DCIERRE_DIARIO_AGENCIA where MAG_CODIGO =  " + agencia + " and FECHA_CONTABILIZACION = '" + fecha.ToString("yyyy-MM-dd") + "';"))
            {
                Response.Write("<script language='javascript'>alert(' La Agencia-fecha ya se Contabilizo ');</script>");
                return;
            }

            //Emisor
            if (nitEmisor.Length == 0 || nombreEmisor.Length == 0 || apellidoEmisor.Length == 0 || tnitEmisor.Length == 0 || txtNITEmisorc.SelectedValue.Length == 0 || telefonoEmisor.Length == 0 || direccionEmisor.Length == 0)
            {
                Response.Write("<script language='javascript'>alert('Debe ingresar todos los datos del emisor.');</script>");
                return;
            }
            //Receptor
            if (nitReceptor.Length == 0 || nombreReceptor.Length == 0 || apellidoReceptor.Length == 0 || tnitReceptor.Length == 0 || txtNITReceptorc.SelectedValue.Length == 0 || telefonoReceptor.Length == 0 || direccionReceptor.Length == 0)
            {
                Response.Write("<script language='javascript'>alert('Debe ingresar todos los datos del receptor.');</script>");
                return;
            }
            //Valor de la remesa
            double unidades, peso, volumen, avaluo, costoEncomienda;

            try
            {
                unidades = double.Parse(txtUnidades.Text.Trim());
                if (unidades <= 0)
                {
                    throw(new Exception());
                }
                peso = double.Parse(txtPeso.Text.Trim());
                if (peso <= 0)
                {
                    throw(new Exception());
                }
                volumen = double.Parse(txtVolumen.Text.Trim());
                if (volumen <= 0)
                {
                    throw(new Exception());
                }
                avaluo = double.Parse(txtValorAvaluo.Text.Trim());
                if (avaluo <= 0)
                {
                    throw(new Exception());
                }
                costoEncomienda = double.Parse(txtCosto.Text.Trim());
                if (costoEncomienda < 0)
                {
                    throw(new Exception());
                }
            }
            catch
            {
                Response.Write("<script language='javascript'>alert('Uno de los valores de la encomienda no es válido.');</script>");
                return;
            }
            //Desabilitar controles y mostrar panel confirmacion
            ddlAgencia.Enabled      = false;
            ddlRuta.Enabled         = false;
            ddlPlanilla.Enabled     = false;
            txtNITEmisor.Enabled    = false;
            txtNITEmisora.Enabled   = false;
            txtNITEmisorb.Enabled   = false;
            txtNITEmisorc.Enabled   = false;
            txtNITEmisord.Enabled   = false;
            txtNITEmisore.Enabled   = false;
            txtNITReceptor.Enabled  = false;
            txtNITReceptora.Enabled = false;
            txtNITReceptorb.Enabled = false;
            txtNITReceptorc.Enabled = false;
            txtNITReceptord.Enabled = false;
            txtNITReceptore.Enabled = false;
            txtPlaca.Enabled        = false;
            pnlInicial.Visible      = false;
            pnlConfirmar.Visible    = true;

            //Calcular valores
            double porcentajeIva;
            double factorPeso, factorVolumen;

            try{ porcentajeIva = Convert.ToDouble(DBFunctions.SingleData("SELECT IVA_ENCOMIENDAS FROM DBXSCHEMA.CTRANSPORTES;")); }
            catch { porcentajeIva = 0; }
            try{
                factorPeso = Convert.ToDouble(DBFunctions.SingleData("SELECT VALOR_PESO FROM DBXSCHEMA.MRUTAS WHERE MRUT_CODIGO='" + ruta + "';"));
            }
            catch {
                Response.Write("<script language='javascript'>alert('Factor de peso no válido.');</script>");
                return;
            }
            try{
                factorVolumen = Convert.ToDouble(DBFunctions.SingleData("SELECT VALOR_VOLUMEN FROM DBXSCHEMA.MRUTAS WHERE MRUT_CODIGO='" + ruta + "';"));
            }
            catch {
                Response.Write("<script language='javascript'>alert('Factor de volumen no válido.');</script>");
                return;
            }
            double valorIVA   = (costoEncomienda * porcentajeIva) / 100;
            double costoTotal = costoEncomienda + valorIVA;

            lblNumDocumento.Text    = Encomiendas.TraerSiguienteEncomiendaVirtual();
            lblCostoEncomienda.Text = costoEncomienda.ToString("#,###,##0");
            lblPorcentajeIVA.Text   = (porcentajeIva > 0)?porcentajeIva.ToString():"0";
            lblValorIVA.Text        = valorIVA.ToString("#,###,##0");
            lblTotal.Text           = costoTotal.ToString("#,###,##0");
            lblDescripcion.Text     = txtDescripcion.Text;
            lblVolumen.Text         = txtVolumen.Text;
            lblPeso.Text            = txtPeso.Text;
            lblUnidades.Text        = txtUnidades.Text;
            lblAvaluo.Text          = txtValorAvaluo.Text;
            lblFecha.Text           = fecha.ToString("dd/MM/yyyy");
            lblNumDocumentoRef.Text = txtNumDocReferencia.Text;
        }