コード例 #1
0
        private void btnRegistrar_Click(object sender, System.EventArgs e)
        {
            //Guardar
            string agencia     = ddlAgencia.SelectedValue;
            string nitReceptor = txtNITReceptor.Text.Trim();
            string planilla    = ddlPlanilla.SelectedValue;

            //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;
            }
            //Receptor
            if (!DBFunctions.RecordExist("SELECT NIT from DBXSCHEMA.VTRANSPORTE_NITSRELACION where nit='" + nitReceptor + "';"))
            {
                Response.Write("<script language='javascript'>alert('El nit del receptor no es valido.');</script>");
                return;
            }
            //Conseguir papeleria
            string numDocumento = Anticipos.TraerSiguienteAnticipoVirtual();
            string numLineaS;
            string tipoUnidad;
            string docReferencia = txtNumDocReferencia.Text.Trim();

            docReferencia = (docReferencia.Length == 0)?"NULL":"'" + docReferencia + "'";

            string placa = lblPlaca.Text.Trim();

            if (placa.Length == 0)
            {
                placa = "NULL";
            }
            else
            {
                placa = "'" + placa + "'";
            }
            if (planilla.Length == 0)
            {
                planilla  = "NULL";
                numLineaS = "NULL";
            }
            else
            {
                numLineaS = DBFunctions.SingleData("SELECT NUMERO_LINEAS+1 FROM DBXSCHEMA.MPLANILLAVIAJE WHERE MPLA_CODIGO=" + planilla);
            }
            tipoUnidad = DBFunctions.SingleData("SELECT tund_consumo FROM DBXSCHEMA.TGASTOS_TRANSPORTES WHERE TCON_CODIGO=" + ddlConcepto.SelectedValue);
            ArrayList sqlStrings = new ArrayList();

            //Actualizar papeleria
            sqlStrings.Add("INSERT INTO DBXSCHEMA.MCONTROL_PAPELERIA  VALUES('ANT'," + numDocumento + ",'V',0,'" + lblFecha.Text + "',0," + agencia + ",'" + lblFecha.Text + "','" + nitResponsable + "',0,'" + lblFecha.Text + "',NULL,NULL,NULL,NULL,NULL,NULL,NULL," + planilla + ",NULL,NULL,'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "');");
            //Insertar servicio/anticipo
            if (ddlConcepto.SelectedValue == "288")
            {
                placa = ddlAgencia.SelectedValue;
            }

            sqlStrings.Add("INSERT INTO DBXSCHEMA.MGASTOS_TRANSPORTES VALUES('ANT'," + numDocumento + ",'V','" + lblFecha.Text + "'," + placa + "," + planilla + "," + numLineaS + "," + ddlConcepto.SelectedValue + "," + agencia + ",'" + nitResponsable + "','" + nitReceptor + "','" + lblDescripcion.Text + "'," + lblCantidad.Text.Replace(",", "") + ",'" + tipoUnidad + "'," + lblValorUnidad.Text.Replace(",", "") + "," + lblValorTotal.Text.Replace(",", "") + ",'A'," + docReferencia + ");");

            //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))
            {
                if (Tools.Browser.IsMobileBrowser())
                {
                    Response.Redirect(ConfigurationManager.AppSettings["MainMobileIndexPage"] + "?process=Comercial.ServiciosAnticipos&path=" + Request.QueryString["path"] + "&act=1&ant=" + numDocumento);
                }
                else
                {
                    Response.Redirect(ConfigurationManager.AppSettings["MainIndexPage"] + "?process=Comercial.ServiciosAnticipos&path=" + Request.QueryString["path"] + "&act=1&ant=" + numDocumento);
                }
            }
            else
            {
                lblError.Text += "Error: " + DBFunctions.exceptions;
            }
        }
コード例 #2
0
        private void btnGuardar_Click(object sender, System.EventArgs e)
        {
            string agencia = ddlAgencia.SelectedValue;
            //Responsable
            string   nitResponsable = DBFunctions.SingleData("select mnit_nit from DBXSCHEMA.susuario where susu_login='******';");
            DateTime fecha;

            if (nitResponsable.Length == 0)
            {
                Response.Write("<script language='javascript'>alert('El usuario actual (responsable) no tiene un NIT asociado.');</script>");
                return;
            }
            //Concepto
            if (ddlConcepto.SelectedValue.Length == 0)
            {
                Response.Write("<script language='javascript'>alert('Debe seleccionar el concepto.');</script>");
                return;
            }
            //Verificar placa
            if (txtPlaca.Text.Trim().Length > 0)
            {
                if (!DBFunctions.RecordExist("select mcat_placa from dbxschema.mbusafiliado where mcat_placa='" + txtPlaca.Text + "';"))
                {
                    Response.Write("<script language='javascript'>alert('La placa registrada no existe.');</script>");
                    return;
                }
            }
            else
            {
                txtPlaca.Text = null;
            }
            //Validaciones

            if (txtNITReceptor.Text.Trim().Length == 0)
            {
                Response.Write("<script language='javascript'>alert('Debe dar los datos del receptor.');</script>");
                return;
            }
            //Receptor
            if (!DBFunctions.RecordExist("SELECT NIT from DBXSCHEMA.VTRANSPORTE_NITSRELACION where nit='" + txtNITReceptor.Text.Trim() + "';"))
            {
                Response.Write("<script language='javascript'>alert('El nit del receptor no es valido.');</script>");
                return;
            }
            if (txtDescripcion.Text.Trim().Length == 0)
            {
                Response.Write("<script language='javascript'>alert('Debe dar la descripción.');</script>");
                return;
            }
            try{
                if (double.Parse(txtCantidad.Text) < 0)
                {
                    throw(new Exception());
                }
            }
            catch {
                Response.Write("<script language='javascript'>alert('La cantidad no es válida.');</script>");
                return;
            }
            try{
                if (double.Parse(txtValorUnidad.Text) < 0)
                {
                    throw(new Exception());
                }
            }
            catch {
                Response.Write("<script language='javascript'>alert('El valor de la unidad no es válido.');</script>");
                return;
            }
            try{
                if (double.Parse(txtValorTotal.Text) < 0)
                {
                    throw(new Exception());
                }
            }
            catch {
                Response.Write("<script language='javascript'>alert('El valor total no es válido.');</script>");
                return;
            }
            try{
                fecha = Convert.ToDateTime(txtFecha.Text);
            }
            catch
            {
                Response.Write("<script language='javascript'>alert('Fecha no válida.');</script>");
                return;
            }
            //Verifica cierre mensual y diario
            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;
            }
            string CargoUsuario = DBFunctions.SingleData("select pcar_codigo from DBXSCHEMA.MPERSONAL_AGENCIA_TRANSPORTES where mag_codigo=" + ddlAgencia.SelectedValue + "  and mnit_nit='" + nitResponsable + "';");
            double ValotTotal   = double.Parse(txtValorTotal.Text.Replace(",", ""));
            double ValorMaximo  = Convert.ToDouble(DBFunctions.SingleData("SELECT coalesce(valor_maximo_autorizacion,0) from DBXSCHEMA.MAUTORIZACION_GASTO_TRANSPORTE " +
                                                                          "WHERE mag_codigo=" + ddlAgencia.SelectedValue + "  and pcar_codigo=" + CargoUsuario + "  and  TCON_CODIGO = " + ddlConcepto.SelectedValue + ";"));

            if (ValotTotal > ValorMaximo)
            {
                Response.Write("<script language='javascript'>alert('El valor es mayor al maximo autorizado:$" + ValorMaximo.ToString("###,###,###") + " ');</script>");
                return;
            }
            lblFecha.Text           = txtFecha.Text;
            lblPlaca.Text           = txtPlaca.Text;
            lblDescripcion.Text     = txtDescripcion.Text.Trim();
            lblCantidad.Text        = txtCantidad.Text;
            lblValorUnidad.Text     = txtValorUnidad.Text;
            lblValorTotal.Text      = txtValorTotal.Text;
            lblNIT.Text             = txtNITReceptor.Text + "<br>" + txtNITReceptora.Text + " " + txtNITReceptorb.Text;
            lblNumDocumento.Text    = Anticipos.TraerSiguienteAnticipoVirtual();
            lblNumDocumentoRef.Text = txtNumDocReferencia.Text;
            pnlConfirma.Visible     = true;
            pnlDatos.Visible        = false;
            ddlAgencia.Enabled      = false;
            ddlPlanilla.Enabled     = false;
            ddlConcepto.Enabled     = false;
            txtPlaca.Enabled        = false;
        }