예제 #1
0
    protected void btnGuardar_Click(object sender, EventArgs e)
    {
        int numMaxDigitos = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["NroMaxDigitos"]);
        List <SCE_CARTEL_MODELO_CAMPO_BE> lstCartelModeloCampo = new List <SCE_CARTEL_MODELO_CAMPO_BE>();

        foreach (GridViewRow Row in grvCampos.Rows)
        {
            int i = Convert.ToInt32(Row.RowIndex);

            CARTEL_MODELO_CAMPO_BE = new SCE_CARTEL_MODELO_CAMPO_BE();

            CheckBox check = Row.FindControl("chkSelection") as CheckBox;

            if (check.Checked)
            {
                CARTEL_MODELO_CAMPO_BE.ID_CARTEL = Convert.ToInt32(hidIdCartel.Value);
                CARTEL_MODELO_CAMPO_BE.ID_MODELO = Convert.ToInt32(hidIdModelo.Value);
                CARTEL_MODELO_CAMPO_BE.ID_CAMPO  = Convert.ToInt32(grvCampos.Rows[i].Cells[0].Text);
                lstCartelModeloCampo.Add(CARTEL_MODELO_CAMPO_BE);
            }
        }

        CARTEL_MODELO_BL.ActualizarCMC(Convert.ToInt32(hidIdCartel.Value),
                                       Convert.ToInt32(hidIdModelo.Value),
                                       lstCartelModeloCampo,
                                       numMaxDigitos);

        //Util.RegisterAsyncAlert(upnlReglasCamp, "__Alerta__", Resources.Mensajes.msgCRCCAlertEjecución);

        pnlDetalle.Visible = false;

        GetData();
    }
        public SCE_CARTEL_MODELO_BE ObtenerPorID(int IdCartel, int IdModelo)
        {
            SCE_CARTEL_MODELO_BE BE = null;

            try
            {
                using (SqlConnection cn = new SqlConnection(SCE_SQLCONEXION.GetCadConexion(usrLogin)))
                {
                    cn.Open();

                    string sql = "SP_SCE_CARTEL_MODELO_GET1";

                    using (SqlCommand cmd = new SqlCommand(sql, cn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;

                        cmd.Parameters.AddWithValue("@ID_CARTEL", IdCartel);
                        cmd.Parameters.AddWithValue("@ID_MODELO", IdModelo);

                        SqlDataReader reader = cmd.ExecuteReader();

                        if (reader.Read())
                        {
                            BE = new SCE_CARTEL_MODELO_BE();

                            BE.ID_CARTEL   = Convert.ToInt32(reader["ID_CARTEL"]);
                            BE.ID_MODELO   = Convert.ToInt32(reader["ID_MODELO"]);
                            BE.CODIGO      = Convert.ToString(reader["CODIGO"]).Trim();
                            BE.DESCRIPCION = Convert.ToString(reader["DESCRIPCION"]).Trim();

                            /* LLENA LA LISTA DE CAMPOS DEL CARTEL-MODELO */
                            List <SCE_CARTEL_MODELO_CAMPO_BE> lstCARTELMODELOCAMPO = new List <SCE_CARTEL_MODELO_CAMPO_BE>();

                            SqlDataReader drCARTELMODELOCAMPO = null;
                            drCARTELMODELOCAMPO = getCampos(IdCartel, IdModelo);

                            while (drCARTELMODELOCAMPO.Read())
                            {
                                SCE_CARTEL_MODELO_CAMPO_BE CARTEL_MODELO_CAMPO = new SCE_CARTEL_MODELO_CAMPO_BE();
                                CARTEL_MODELO_CAMPO.ID_CAMPO      = drCARTELMODELOCAMPO.GetInt32(0);
                                CARTEL_MODELO_CAMPO.NOM_CAMPO     = drCARTELMODELOCAMPO.GetString(1);
                                CARTEL_MODELO_CAMPO.DESCRIPCION   = drCARTELMODELOCAMPO.GetString(2);
                                CARTEL_MODELO_CAMPO.FLAGPERTENECE = drCARTELMODELOCAMPO.GetInt32(3);

                                lstCARTELMODELOCAMPO.Add(CARTEL_MODELO_CAMPO);
                            }

                            BE.CAMPOS = lstCARTELMODELOCAMPO;
                        }

                        return(BE);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public List <SCE_CARTEL_MODELO_CAMPO_BE> grvCampos(int IdCartel, int IdModelo, int Digitos)
        {
            List <SCE_CARTEL_MODELO_CAMPO_BE> lstBE = new List <SCE_CARTEL_MODELO_CAMPO_BE>();
            SCE_CARTEL_MODELO_CAMPO_BE        BE    = null;

            try
            {
                using (SqlConnection cn = new SqlConnection(SCE_SQLCONEXION.GetCadConexion(usrLogin)))
                {
                    cn.Open();

                    string sql = "SP_SCE_CARTEL_MODELO_CAMPO_GET2";

                    using (SqlCommand cmd = new SqlCommand(sql, cn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@ID_CARTEL", IdCartel);
                        cmd.Parameters.AddWithValue("@ID_MODELO", IdModelo);
                        cmd.Parameters.AddWithValue("@DIGITOS", Digitos);

                        SqlDataReader reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            BE = new SCE_CARTEL_MODELO_CAMPO_BE();

                            BE.ID_CARTEL = Convert.ToInt32(reader["ID_CARTEL"]);
                            BE.ID_MODELO = Convert.ToInt32(reader["ID_MODELO"]);
                            BE.DIGITOS   = Convert.ToInt32(reader["DIGITOS"]);
                            BE.ID_CAMPO  = Convert.ToInt32(reader["ID_CAMPO"]);
                            BE.POSX      = Convert.ToString(reader["POS_X"]).Trim();
                            BE.POSY      = Convert.ToString(reader["POS_Y"]).Trim();
                            BE.ALIAS     = Convert.ToString(reader["CAMPO"]).Trim();
                            BE.NOM_CAMPO = Convert.ToString(reader["DESCRIPCION"]).Trim();

                            lstBE.Add(BE);
                        }

                        return(lstBE);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    protected void btnImportar_Click(object sender, EventArgs e)
    {
        System.Text.StringBuilder sbScript = new System.Text.StringBuilder();

        List <SCE_CARTEL_MODELO_CAMPO_BE> lstcmc = new List <SCE_CARTEL_MODELO_CAMPO_BE>();

        if (fuImportPlantillas.HasFile)
        {
            Session["sName"] = System.IO.Path.GetFileNameWithoutExtension(fuImportPlantillas.FileName);
            sExt             = System.Configuration.ConfigurationManager.AppSettings["EXCEL_FILE_EXTENCION"];
            Session["sPath"] = System.Configuration.ConfigurationManager.AppSettings["PATH_SERVER"] + Session["sName"] + sExt;

            if (ValidaExtension(sExt))
            {
                if (fuImportPlantillas.PostedFile.ContentLength > 4096)
                {
                    // Carga el archivo de la plantilla selecionada en el servidor
                    fuImportPlantillas.SaveAs((string)Session["sPath"]);

                    // Verificar si el archivo de la plantilla Excel tiene mas de una Hoja de Calculo
                    if (CARTEL_MODELO_BL.HaveMoreOneSheetExcel((string)Session["sPath"]) == true)
                    {
                        Util.RegisterAsyncAlert(upnlImportador, "__Alerta__", "La plantilla ha sido mal configurada porque tiene mas de una pestaña en esta. Por favor eliminar las pestañas adicionales y quede solo la que contiene el diseño de la plantilla y volver a reconfigurarla en el sistema.");

                        return;
                    }

                    // Obtiene los resultados de comparar los campos del Excel con los campos de la BD
                    bool   errores = false;
                    string PosFCX  = string.Empty;
                    string PosFCY  = string.Empty;

                    // Llena la grilla con el informe de la comparación del Excel y la BD
                    grvCampos.DataSource = CARTEL_MODELO_BL.GetInforme((string)Session["sPath"],
                                                                       Convert.ToInt32(hidIdCartel.Value),
                                                                       Convert.ToInt32(hidIdModelo.Value),
                                                                       Convert.ToInt32(hidDigitos.Value),
                                                                       ref errores,
                                                                       ref PosFCX,
                                                                       ref PosFCY);

                    grvCampos.DataBind();

                    if (errores == true) // En caso de que haiga diferencias entre el Excel y la BD
                    {
                        lblCartel.Text    = hidCartelModelo.Value.ToString();
                        lblDigitos.Text   = hidNroDigitos.Value.ToString();
                        lblPlantilla.Text = Session["sName"].ToString();

                        Util.RegisterAsyncAlert(upnlImportador, "__Alerta__", System.Configuration.ConfigurationManager.AppSettings["MCP_PNI"]);

                        upnlDetalleConf.Update();

                        sbScript.AppendFormat("document.getElementById('{0}').style.visibility='hidden';", btnVerPlantilla.ClientID);
                        Util.RegisterScript(upnlImportador, "__DesabilitaCtrol__", sbScript.ToString());

                        pnlBtnConfigurar.Visible  = false;
                        pnlDialgPlantilla.Visible = false;
                        pnlDetalle.Visible        = true;
                    }
                    else // En caso de que no haiga diferencias entre el Excel y la BD
                    {
                        // Convierte en PDF la plantilla Excel
                        CARTEL_MODELO_BL.ConvertExcelToPdf((string)Session["sPath"],
                                                           (System.Configuration.ConfigurationManager.AppSettings["PATH_SERVER"] + Session["sName"] + ".pdf"));

                        // Actualiza las tablas SCE_CARTEL_MODELO (NOM_PLANTILLA) y SCE_CARTEL_MODELO_CAMPO (Campos POS X y POS Y)
                        foreach (GridViewRow Row in grvCampos.Rows)
                        {
                            int i = Convert.ToInt32(Row.RowIndex);

                            CARTEL_MODELO_CAMPO_BE = new SCE_CARTEL_MODELO_CAMPO_BE();

                            CARTEL_MODELO_CAMPO_BE.ID_CAMPO = Convert.ToInt32(CAMPO_BL.GetIdCampo(Server.HtmlDecode(grvCampos.Rows[i].Cells[3].Text)));
                            CARTEL_MODELO_CAMPO_BE.POSX     = Server.HtmlDecode(grvCampos.Rows[i].Cells[1].Text);
                            CARTEL_MODELO_CAMPO_BE.POSY     = Server.HtmlDecode(grvCampos.Rows[i].Cells[2].Text);
                            lstcmc.Add(CARTEL_MODELO_CAMPO_BE);
                        }

                        // Actualiza la tabla SCE_CARTEL_MODELO (Campo NOM_PLANTILLA)
                        CARTEL_MODELO_BL.ActualizarCMC1(Convert.ToInt32(hidIdCartel.Value),
                                                        Convert.ToInt32(hidIdModelo.Value),
                                                        Convert.ToInt32(hidDigitos.Value),
                                                        Session["sName"].ToString(),
                                                        lstcmc,
                                                        PosFCX,
                                                        PosFCY);

                        // Llena el objeto con los resultados de la importacion realizada correctamente
                        CARTEL_MODELO_BE = CARTEL_MODELO_BL.ObtenerPorID1(Convert.ToInt32(hidIdCartel.Value),
                                                                          Convert.ToInt32(hidIdModelo.Value),
                                                                          Convert.ToInt32(hidDigitos.Value));

                        // Llena los labeles y la grilla con los campos que estan en la BD o NO
                        lblCartel.Text    = CARTEL_MODELO_BE.DESCRIPCION.ToString().Trim();
                        lblDigitos.Text   = CARTEL_MODELO_BE.NRODIGITOS.ToString().Trim();
                        lblPlantilla.Text = CARTEL_MODELO_BE.NOM_PLANTILLA.ToString().Trim();

                        /***********************************************************************************/
                        /*COPIA LA PLANTILLA EXCEL AL FILE SERVER POR SUPLANTACION DE WINDOWS*/
                        /***********************************************************************************/
                        //string strPathServer = System.Configuration.ConfigurationManager.AppSettings["PATH_SERVER"];
                        //string strPathFs = System.Configuration.ConfigurationManager.AppSettings["PATH_PLANTILLAS_FS"];

                        //string username = System.Configuration.ConfigurationManager.AppSettings["LOGIN_FS"];
                        //string password = System.Configuration.ConfigurationManager.AppSettings["PASSWORD_FS"];
                        //string domain = System.Configuration.ConfigurationManager.AppSettings["DOMINIO_FS"];

                        /***********************************************************************************/
                        /***********************************************************************************/

                        //// Create Impersonation Object
                        //WI impersonation = new WI(domain, username, password);

                        //// Start Impersonation
                        //impersonation.Impersonate();

                        ///*Copiar la plantilla Excel Generada en la servidor.*/
                        //FileInfo file = new FileInfo(Convert.ToString(Session["sPath"]));
                        //file.CopyTo(strPathFs + Session["sName"].ToString() + sExt, true);

                        //// Stop Impersonation
                        //impersonation.Revert();

                        /***********************************************************************************/
                        /***********************************************************************************/

                        //System.Security.Principal.WindowsImpersonationContext impersonationContext;
                        //impersonationContext = ((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();

                        ///*Copiar la plantilla Excel Generada en la servidor.*/
                        //FileInfo file = new FileInfo(Session["sPath"].ToString());
                        //file.CopyTo(strPathFs + Session["sName"].ToString() + sExt, true);

                        //impersonationContext.Undo();

                        /***********************************************************************************/
                        /***********************************************************************************/

                        //if (impersonateValidUser(username, domain, password))
                        //{
                        //    //Insert your code that runs under the security context of the authenticating user here.
                        //    /*Copiar la plantilla Excel Generada en la servidor.*/
                        //    FileInfo file = new FileInfo(Convert.ToString(Session["sPath"]));
                        //    file.CopyTo(strPathFs + Session["sName"].ToString() + sExt, true);

                        //    undoImpersonation();
                        //}
                        //else
                        //{
                        //    //Your impersonation failed. Therefore, include a fail-safe mechanism here.
                        //}

                        /***********************************************************************************/
                        /***********************************************************************************/



                        /***********************************************************************************/
                        /***********************************************************************************/

                        // Llena la grilla de informe de importación
                        grvCampos.DataSource = CARTEL_MODELO_BE.CAMPOS;
                        grvCampos.DataBind();

                        Util.RegisterAsyncAlert(upnlImportador, "__Alerta__", System.Configuration.ConfigurationManager.AppSettings["MCP_PIC"]);

                        upnlDetalleConf.Update();

                        sbScript.AppendFormat("document.getElementById('{0}').style.visibility='visible';", btnVerPlantilla.ClientID);
                        Util.RegisterScript(upnlImportador, "__DesabilitaCtrol__", sbScript.ToString());

                        /************************/
                        CargaCartelesModelo();
                        upnlBusqueda.Update();
                        /************************/

                        pnlBtnConfigurar.Visible  = false;
                        pnlDialgPlantilla.Visible = false;
                        pnlDetalle.Visible        = true;
                    }
                }
                else
                {
                    Util.RegisterAsyncAlert(upnlImportador, "__Alerta__", "El archivo exede el tamaño permitido");

                    pnlBtnConfigurar.Visible  = false;
                    pnlDialgPlantilla.Visible = true;

                    upnlImportador.Update();
                }
            }
            else
            {
                Util.RegisterAsyncAlert(upnlImportador, "__Alerta__", "El archivo no es de tipo Excel");

                pnlBtnConfigurar.Visible  = false;
                pnlDialgPlantilla.Visible = true;

                upnlImportador.Update();
            }
        }
        else
        {
            Util.RegisterAsyncAlert(upnlImportador, "__Alerta__", "No ha seleccionado el archivo");

            pnlBtnConfigurar.Visible  = false;
            pnlDialgPlantilla.Visible = true;

            upnlImportador.Update();
        }
    }
        public SCE_CARTEL_MODELO_BE ObtenerPorID1(int IdCartel, int IdModelo, int Digitos)
        {
            SCE_CARTEL_MODELO_BE BE = null;

            try
            {
                using (SqlConnection cn = new SqlConnection(SCE_SQLCONEXION.GetCadConexion(usrLogin)))
                {
                    cn.Open();

                    string sql = "SP_SCE_CARTEL_MODELO_GET2";

                    using (SqlCommand cmd = new SqlCommand(sql, cn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;

                        cmd.Parameters.AddWithValue("@ID_CARTEL", IdCartel);
                        cmd.Parameters.AddWithValue("@ID_MODELO", IdModelo);
                        cmd.Parameters.AddWithValue("@DIGITOS", Digitos);

                        SqlDataReader reader = cmd.ExecuteReader();

                        if (reader.Read())
                        {
                            BE = new SCE_CARTEL_MODELO_BE();

                            BE.NOM_CARTEL    = Convert.ToString(reader["NOM_CARTEL"]).Trim();
                            BE.NOM_MODELO    = Convert.ToString(reader["NOM_MODELO"]).Trim();
                            BE.DESCRIPCION   = Convert.ToString(reader["NOM_CARTEL"]).Trim() + '-' + Convert.ToString(reader["NOM_MODELO"]).Trim();
                            BE.NRODIGITOS    = Convert.ToString(reader["NRODIGITOS"]).Trim();
                            BE.NOM_PLANTILLA = Convert.ToString(reader["NOM_PLANTILLA"]).Trim();

                            /* LLENA LA LISTA DE CAMPOS DEL CARTEL-MODELO */
                            List <SCE_CARTEL_MODELO_CAMPO_BE> lstCARTELMODELOCAMPO = new List <SCE_CARTEL_MODELO_CAMPO_BE>();

                            SqlDataReader drCARTELMODELOCAMPO = null;
                            drCARTELMODELOCAMPO = getCampos1(IdCartel, IdModelo, Digitos);

                            while (drCARTELMODELOCAMPO.Read())
                            {
                                SCE_CARTEL_MODELO_CAMPO_BE CARTEL_MODELO_CAMPO = new SCE_CARTEL_MODELO_CAMPO_BE();
                                CARTEL_MODELO_CAMPO.ID_CAMPO    = drCARTELMODELOCAMPO.GetInt32(0);
                                CARTEL_MODELO_CAMPO.CAMPO       = drCARTELMODELOCAMPO.GetString(1).Trim();
                                CARTEL_MODELO_CAMPO.DESCRIPCION = drCARTELMODELOCAMPO.GetString(2).Trim();
                                if (!drCARTELMODELOCAMPO.IsDBNull(drCARTELMODELOCAMPO.GetOrdinal("POS_X")))
                                {
                                    CARTEL_MODELO_CAMPO.POSX = drCARTELMODELOCAMPO.GetString(3).Trim();
                                }

                                if (!drCARTELMODELOCAMPO.IsDBNull(drCARTELMODELOCAMPO.GetOrdinal("POS_Y")))
                                {
                                    CARTEL_MODELO_CAMPO.POSY = drCARTELMODELOCAMPO.GetString(4).Trim();
                                }

                                lstCARTELMODELOCAMPO.Add(CARTEL_MODELO_CAMPO);
                            }

                            BE.CAMPOS = lstCARTELMODELOCAMPO;
                        }

                        return(BE);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }