//Validaciones
    private static string ValidarImpresionEtiquetas(CImpresionEtiquetas pImpresionEtiquetas, CConexion pConexion)
    {
        string errores = "";

        if (pImpresionEtiquetas.IdImpresionTemplate.ToString() == "0")
        {
            errores = errores + "<span>*</span> El campo template esta vacío, favor de capturarlo.<br />";
        }

        if (pImpresionEtiquetas.Campo.ToString() == "")
        {
            errores = errores + "<span>*</span> El campo esta vacío, favor de seleccionarlo.<br />";
        }

        if (pImpresionEtiquetas.Etiqueta.ToString() == "")
        {
            errores = errores + "<span>*</span> El campo etiqueta esta vacío, favor de seleccionarlo.<br />";
        }

        if (errores != "")
        {
            errores = "<p>Favor de completar los siguientes requisitos:</p>" + errores;
        }

        return(errores);
    }
    public static string EditarImpresionEtiquetas(Dictionary <string, object> pImpresionEtiquetas)
    {
        CConexion ConexionBaseDatos = new CConexion();
        string    respuesta         = ConexionBaseDatos.ConectarBaseDatosSqlServer();

        CImpresionEtiquetas ImpresionEtiquetas = new CImpresionEtiquetas();

        ImpresionEtiquetas.LlenaObjeto(Convert.ToInt32(pImpresionEtiquetas["IdImpresionEtiquetas"]), ConexionBaseDatos);
        ImpresionEtiquetas.IdImpresionTemplate = Convert.ToInt32(pImpresionEtiquetas["IdImpresionTemplate"]);
        ImpresionEtiquetas.Campo    = Convert.ToString(pImpresionEtiquetas["Campo"]);
        ImpresionEtiquetas.Etiqueta = Convert.ToString(pImpresionEtiquetas["Etiqueta"]);

        string validacion = ValidarImpresionEtiquetas(ImpresionEtiquetas, ConexionBaseDatos);

        JObject oRespuesta = new JObject();

        if (validacion == "")
        {
            ImpresionEtiquetas.Editar(ConexionBaseDatos);
            oRespuesta.Add(new JProperty("Error", 0));
            ConexionBaseDatos.CerrarBaseDatosSqlServer();
        }
        else
        {
            oRespuesta.Add(new JProperty("Error", 1));
            oRespuesta.Add(new JProperty("Descripcion", validacion));
            ConexionBaseDatos.CerrarBaseDatosSqlServer();
        }
        return(oRespuesta.ToString());
    }
    public static string ObtenerFormaEditarImpresionEtiquetas(int IdImpresionEtiquetas)
    {
        CConexion ConexionBaseDatos             = new CConexion();
        string    respuesta                     = ConexionBaseDatos.ConectarBaseDatosSqlServer();
        int       puedeEditarImpresionEtiquetas = 0;
        JObject   oRespuesta                    = new JObject();
        JObject   oPermisos                     = new JObject();
        CUsuario  Usuario = new CUsuario();

        if (Usuario.TienePermisos(new string[] { "puedeEditarImpresionEtiquetas" }, ConexionBaseDatos) == "")
        {
            puedeEditarImpresionEtiquetas = 1;
        }
        oPermisos.Add("puedeEditarImpresionEtiquetas", puedeEditarImpresionEtiquetas);

        if (respuesta == "Conexion Establecida")
        {
            JObject             Modelo             = new JObject();
            CImpresionEtiquetas ImpresionEtiquetas = new CImpresionEtiquetas();
            ImpresionEtiquetas.LlenaObjeto(IdImpresionEtiquetas, ConexionBaseDatos);

            CImpresionTemplate ImpresionTemplate = new CImpresionTemplate();
            ImpresionTemplate.LlenaObjeto(ImpresionEtiquetas.IdImpresionTemplate, ConexionBaseDatos);

            CEmpresa Empresa = new CEmpresa();
            Empresa.LlenaObjeto(ImpresionTemplate.IdEmpresa, ConexionBaseDatos);

            CImpresionDocumento ImpresionDocumento = new CImpresionDocumento();
            ImpresionDocumento.LlenaObjeto(ImpresionTemplate.IdImpresionDocumento, ConexionBaseDatos);

            Modelo.Add(new JProperty("IdImpresionEtiquetas", ImpresionEtiquetas.IdImpresionEtiquetas));
            Modelo.Add(new JProperty("Templates", CImpresionTemplate.ObtenerJsonImpresionTemplates(ImpresionEtiquetas.IdImpresionTemplate, ConexionBaseDatos)));
            Modelo.Add(new JProperty("Campo", ImpresionEtiquetas.Campo));
            Modelo.Add(new JProperty("Etiqueta", ImpresionEtiquetas.Etiqueta.Substring(1, ImpresionEtiquetas.Etiqueta.Length - 2)));

            Modelo.Add(new JProperty("Permisos", oPermisos));
            oRespuesta.Add(new JProperty("Error", 0));
            oRespuesta.Add(new JProperty("Modelo", Modelo));
            ConexionBaseDatos.CerrarBaseDatosSqlServer();
        }
        else
        {
            oRespuesta.Add(new JProperty("Error", 1));
            oRespuesta.Add(new JProperty("Descripcion", "No hay conexion a Base de Datos"));
        }
        return(oRespuesta.ToString());
    }
    public static string CambiarEstatus(int pIdImpresionEtiquetas, bool pBaja)
    {
        //Abrir Conexion
        CConexion ConexionBaseDatos = new CConexion();
        string    respuesta         = ConexionBaseDatos.ConectarBaseDatosSqlServer();

        //¿La conexion se establecio?
        if (respuesta == "Conexion Establecida")
        {
            CImpresionEtiquetas ImpresionEtiquetas = new CImpresionEtiquetas();
            ImpresionEtiquetas.IdImpresionEtiquetas = pIdImpresionEtiquetas;
            ImpresionEtiquetas.Baja = pBaja;
            ImpresionEtiquetas.Eliminar(ConexionBaseDatos);
            respuesta = "0|ImpresionEtiquetasEliminado";
        }

        //Cerrar Conexion
        ConexionBaseDatos.CerrarBaseDatosSqlServer();
        return(respuesta);
    }
    public static string AgregarImpresionEtiquetas(Dictionary <string, object> pImpresionEtiquetas)
    {
        //Abrir Conexion
        CConexion ConexionBaseDatos = new CConexion();
        string    respuesta         = ConexionBaseDatos.ConectarBaseDatosSqlServer();

        //¿La conexion se establecio?
        if (respuesta == "Conexion Establecida")
        {
            CImpresionEtiquetas ImpresionEtiquetas = new CImpresionEtiquetas();
            ImpresionEtiquetas.IdImpresionTemplate = Convert.ToInt32(pImpresionEtiquetas["IdImpresionTemplate"]);
            ImpresionEtiquetas.Campo    = Convert.ToString(pImpresionEtiquetas["Campo"]);
            ImpresionEtiquetas.Etiqueta = Convert.ToString(pImpresionEtiquetas["Etiqueta"]);

            string validacion = ValidarImpresionEtiquetas(ImpresionEtiquetas, ConexionBaseDatos);

            JObject oRespuesta = new JObject();
            if (validacion == "")
            {
                ImpresionEtiquetas.Agregar(ConexionBaseDatos);
                oRespuesta.Add(new JProperty("Error", 0));
                ConexionBaseDatos.CerrarBaseDatosSqlServer();
            }
            else
            {
                oRespuesta.Add(new JProperty("Error", 1));
                oRespuesta.Add(new JProperty("Descripcion", validacion));
            }
            ConexionBaseDatos.CerrarBaseDatosSqlServer();
            return(oRespuesta.ToString());
        }
        else
        {
            return("1|" + respuesta);
        }
    }
示例#6
0
    public void ImprimirEtiquetasArreglos(JObject pJDocumento, int pIdImpresionTemplate, string pRutaTemplate, CConexion pConexion)
    {
        CImpresionEtiquetas         ImpresionEtiquetas = new CImpresionEtiquetas();
        Dictionary <string, object> Parametros         = new Dictionary <string, object>();

        Parametros.Add("IdImpresionTemplate", pIdImpresionTemplate);

        object oEndOfDoc = "\\endofdoc"; /* \endofdoc es un bookmark predefinido */
        Object oMissing  = System.Reflection.Missing.Value;

        Word.Range wrdRng = documentoWord.Bookmarks.get_Item(ref oEndOfDoc).Range;
        int        ind    = 0;
        object     oPos;
        double     dPos = aplicacionWord.InchesToPoints(10);

        foreach (JProperty oPropiedadDocumento in pJDocumento.Properties())
        {
            if (oPropiedadDocumento.Value.Type.ToString() == "Object")
            {
                JObject JTablaConceptos = new JObject();
                JTablaConceptos = (JObject)pJDocumento[oPropiedadDocumento.Name];
                foreach (JProperty oPropiedadTabla in JTablaConceptos.Properties())
                {
                    if (oPropiedadTabla.Name == "Tipo")
                    {
                        if (oPropiedadTabla.Value.ToString() == "Conceptos")
                        {
                            for (int i = 1; i <= documentoWord.Tables.Count; i++)
                            {
                                Word.Table wTable = documentoWord.Tables[i];
                                Word.Cell  pCell  = wTable.Cell(1, 1);

                                if (wTable.ID != null && wTable.ID == "tblReceptor")
                                {
                                    foreach (CImpresionEtiquetas oImpresionEtiqueta in ImpresionEtiquetas.LlenaObjetosFiltros(Parametros, pConexion))
                                    {
                                        Word.Range rangePlantilla = wTable.Range;

                                        int rc = wTable.Rows.Count;
                                        // Selecciona y copia el renglon Layout.
                                        rangePlantilla.Start = 1;
                                        rangePlantilla.End   = wTable.Rows[rc].Cells[wTable.Rows[rc].Cells.Count].Range.End;
                                        rangePlantilla.Find.ClearFormatting();
                                        rangePlantilla.Find.Text = oImpresionEtiqueta.Etiqueta;
                                        rangePlantilla.Find.Replacement.ClearFormatting();


                                        if (pJDocumento[oImpresionEtiqueta.Campo] != null)
                                        {
                                            rangePlantilla.Find.Replacement.Text = pJDocumento[oImpresionEtiqueta.Campo].ToString();
                                        }
                                        object replaceAll = Word.WdReplace.wdReplaceAll;
                                        rangePlantilla.Find.Execute(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref replaceAll, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                                    }
                                }

                                if (wTable.ID != null && wTable.ID == JTablaConceptos["NombreTabla"].ToString())
                                {
                                    bool pRowsNum = false;
                                    if (wTable.Rows.Count > 1)
                                    {
                                        pRowsNum = true;
                                    }

                                    int contador = 1;
                                    // Layaout
                                    foreach (JObject JInventario in JTablaConceptos["Inventarios"])
                                    {
                                        contador = contador + 1;
                                        Word.Range range = wTable.Range;

                                        // Renglon Layout
                                        int selectedRow = 1;

                                        // Selecciona y copia el renglon Layout.
                                        range.Start = wTable.Rows[selectedRow].Cells[1].Range.Start;
                                        range.End   = wTable.Rows[selectedRow].Cells[wTable.Rows[selectedRow].Cells.Count].Range.End;
                                        range.Copy();

                                        // Inserta renglon nuevo al final de la tabla.
                                        wTable.Rows.Add(ref oMissing);

                                        // Mueve el cursor a la primera celda del renglon nuevo.
                                        range.Start = wTable.Rows[wTable.Rows.Count].Cells[1].Range.Start;
                                        range.End   = range.Start;

                                        // Pega los valores del renglon layout al renglon nuevo.
                                        range.Paste();

                                        int m = wTable.Rows.Count;

                                        Word.Row  renglonPlantilla = wTable.Rows[m];
                                        Word.Cell celdaPlantilla   = renglonPlantilla.Cells[1];

                                        for (int x = 1; x <= celdaPlantilla.Tables.Count; x++)
                                        {
                                            bool sRowsNum = false;
                                            if (celdaPlantilla.Tables[x].Rows.Count > 3)
                                            {
                                                sRowsNum = true;
                                            }
                                            foreach (CImpresionEtiquetas oImpresionEtiqueta in ImpresionEtiquetas.LlenaObjetosFiltros(Parametros, pConexion))
                                            {
                                                Word.Range rangePlantilla = wTable.Range;

                                                // Selecciona y copia el renglon Layout.
                                                rangePlantilla.Start = celdaPlantilla.Tables[x].Rows[1].Cells[1].Range.Start;
                                                rangePlantilla.End   = celdaPlantilla.Tables[x].Rows[1].Cells[celdaPlantilla.Tables[x].Rows[1].Cells.Count].Range.End;
                                                rangePlantilla.Find.ClearFormatting();
                                                rangePlantilla.Find.Text = oImpresionEtiqueta.Etiqueta;
                                                rangePlantilla.Find.Replacement.ClearFormatting();

                                                if (JInventario[oImpresionEtiqueta.Campo] != null)
                                                {
                                                    rangePlantilla.Find.Replacement.Text = JInventario[oImpresionEtiqueta.Campo].ToString();
                                                }
                                                object replaceAll = Word.WdReplace.wdReplaceAll;
                                                rangePlantilla.Find.Execute(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref replaceAll, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                                            }

                                            foreach (JObject JConcepto in JInventario["Lista"])
                                            {
                                                Word.Range sRange = celdaPlantilla.Tables[x].Range;

                                                // Selecciona y copia el renglon Layout.
                                                sRange.Start = celdaPlantilla.Tables[x].Rows[3].Cells[1].Range.Start;
                                                sRange.End   = celdaPlantilla.Tables[x].Rows[3].Cells[celdaPlantilla.Tables[x].Rows[3].Cells.Count].Range.End;
                                                sRange.Copy();

                                                // Inserta renglon nuevo al final de la tabla.
                                                celdaPlantilla.Tables[x].Rows.Add(ref oMissing);

                                                // Mueve el cursor a la primera celda del renglon nuevo.
                                                sRange.Start = celdaPlantilla.Tables[x].Rows[celdaPlantilla.Tables[x].Rows.Count].Cells[1].Range.Start;
                                                sRange.End   = sRange.Start;

                                                // Pega los valores del renglon layout al renglon nuevo.
                                                sRange.Paste();

                                                foreach (CImpresionEtiquetas oImpresionEtiqueta in ImpresionEtiquetas.LlenaObjetosFiltros(Parametros, pConexion))
                                                {
                                                    Word.Range rowRange = wTable.Range;

                                                    // Selecciona y copia el renglon Layout.
                                                    sRange.Find.ClearFormatting();
                                                    sRange.Find.Text = oImpresionEtiqueta.Etiqueta;
                                                    sRange.Find.Replacement.ClearFormatting();

                                                    if (JConcepto[oImpresionEtiqueta.Campo] != null)
                                                    {
                                                        sRange.Find.Replacement.Text = JConcepto[oImpresionEtiqueta.Campo].ToString();
                                                    }
                                                    object replaceAll = Word.WdReplace.wdReplaceAll;
                                                    sRange.Find.Execute(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref replaceAll, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                                                }
                                            }
                                            if (sRowsNum)
                                            {
                                                JObject JTotal = new JObject();
                                                JTotal = (JObject)JInventario["Total"];

                                                Word.Range sRange = celdaPlantilla.Tables[x].Range;

                                                // Selecciona y copia el renglon Layout.
                                                sRange.Start = celdaPlantilla.Tables[x].Rows[4].Cells[1].Range.Start;
                                                sRange.End   = celdaPlantilla.Tables[x].Rows[4].Cells[celdaPlantilla.Tables[x].Rows[4].Cells.Count].Range.End;
                                                sRange.Copy();

                                                // Inserta renglon nuevo al final de la tabla.
                                                celdaPlantilla.Tables[x].Rows.Add(ref oMissing);

                                                // Mueve el cursor a la primera celda del renglon nuevo.
                                                sRange.Start = celdaPlantilla.Tables[x].Rows[celdaPlantilla.Tables[x].Rows.Count].Cells[1].Range.Start;
                                                sRange.End   = sRange.Start;

                                                // Pega los valores del renglon layout al renglon nuevo.
                                                sRange.Paste();

                                                foreach (CImpresionEtiquetas oImpresionEtiqueta in ImpresionEtiquetas.LlenaObjetosFiltros(Parametros, pConexion))
                                                {
                                                    Word.Range rowRange = wTable.Range;

                                                    // Selecciona y copia el renglon Layout.
                                                    sRange.Find.ClearFormatting();
                                                    sRange.Find.Text = oImpresionEtiqueta.Etiqueta;
                                                    sRange.Find.Replacement.ClearFormatting();

                                                    if (JTotal[oImpresionEtiqueta.Campo] != null)
                                                    {
                                                        sRange.Find.Replacement.Text = JTotal[oImpresionEtiqueta.Campo].ToString();
                                                    }
                                                    object replaceAll = Word.WdReplace.wdReplaceAll;
                                                    sRange.Find.Execute(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref replaceAll, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                                                }
                                                celdaPlantilla.Tables[x].Rows[4].Delete();
                                            }
                                            celdaPlantilla.Tables[x].Rows[3].Delete();
                                        }
                                    }

                                    if (pRowsNum)
                                    {
                                        Word.Range sRange = wTable.Range;

                                        // Selecciona y copia el renglon Layout.
                                        sRange.Start = wTable.Rows[2].Cells[1].Range.Start;
                                        sRange.End   = wTable.Rows[2].Cells[wTable.Rows[2].Cells.Count].Range.End;
                                        sRange.Copy();

                                        // Inserta renglon nuevo al final de la tabla.
                                        wTable.Rows.Add(ref oMissing);

                                        // Mueve el cursor a la primera celda del renglon nuevo.
                                        sRange.Start = wTable.Rows[wTable.Rows.Count].Cells[1].Range.Start;
                                        sRange.End   = sRange.Start;

                                        // Pega los valores del renglon layout al renglon nuevo.
                                        sRange.Paste();

                                        foreach (CImpresionEtiquetas oImpresionEtiqueta in ImpresionEtiquetas.LlenaObjetosFiltros(Parametros, pConexion))
                                        {
                                            Word.Range rangePlantilla = wTable.Range;

                                            // Selecciona y copia el renglon Layout.
                                            rangePlantilla.Find.ClearFormatting();
                                            rangePlantilla.Find.Text = oImpresionEtiqueta.Etiqueta;
                                            rangePlantilla.Find.Replacement.ClearFormatting();


                                            if (pJDocumento[oImpresionEtiqueta.Campo] != null)
                                            {
                                                rangePlantilla.Find.Replacement.Text = pJDocumento[oImpresionEtiqueta.Campo].ToString();
                                            }
                                            object replaceAll = Word.WdReplace.wdReplaceAll;
                                            rangePlantilla.Find.Execute(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref replaceAll, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                                        }
                                        wTable.Rows[2].Delete();
                                    }
                                    wTable.Rows[1].Delete();
                                }
                            }
                        }
                    }
                }
            }
        }
    }