Ejemplo n.º 1
0
        protected void BtnCargaArchivo_Click(object sender, EventArgs e)
        {
            if ((FileUpPDV.PostedFile != null) && (FileUpPDV.PostedFile.ContentLength > 0))
            {
                string fn           = System.IO.Path.GetFileName(FileUpPDV.PostedFile.FileName);
                string SaveLocation = Server.MapPath("PDV_Planning") + "\\" + fn;

                if (SaveLocation != string.Empty)
                {
                    if (FileUpPDV.FileName.ToLower().EndsWith(".xls"))
                    {
                        OleDbConnection  oConn1 = new OleDbConnection();
                        OleDbCommand     oCmd   = new OleDbCommand();
                        OleDbDataAdapter oDa    = new OleDbDataAdapter();
                        DataSet          oDs    = new DataSet();

                        DataTable dt = new DataTable();


                        FileUpPDV.PostedFile.SaveAs(SaveLocation);

                        // oConn1.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + SaveLocation + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\"";
                        oConn1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + SaveLocation + ";Extended Properties=\"Excel 8.0; HDR=YES;\"";
                        oConn1.Open();
                        oCmd.CommandText  = "SELECT * FROM [Hoja1$]";
                        oCmd.Connection   = oConn1;
                        oDa.SelectCommand = oCmd;
                        try
                        {
                            if (this.Session["scountry"].ToString() != null)
                            {
                                oDa.Fill(oDs);
                                dt = oDs.Tables[0];
                                if (dt.Columns.Count == 8)
                                {
                                    dt.Columns[0].ColumnName = "cod_PDV";
                                    dt.Columns[1].ColumnName = "cod_Reporte";
                                    dt.Columns[2].ColumnName = "cod_SubReporte";
                                    dt.Columns[3].ColumnName = "cod_Periodo";
                                    dt.Columns[4].ColumnName = "cod_Producto";
                                    dt.Columns[5].ColumnName = "cod_Marca";
                                    dt.Columns[6].ColumnName = "cod_Familia";
                                    dt.Columns[7].ColumnName = "cod_Categoria";

                                    Gvlog.DataSource = dt;
                                    Gvlog.DataBind();

                                    for (int i = 0; i <= Gvlog.Rows.Count - 1; i++)
                                    {
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&nbsp;", "");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#160;", "");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#193;", "Á");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#201;", "É");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#205;", "Í");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#211;", "Ó");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#218;", "Ú");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#225;", "á");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#233;", "é");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#237;", "í");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#243;", "ó");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#250;", "ú");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#209;", "Ñ");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#241;", "ñ");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&amp;", "&");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#176;", "o");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#186;", "o");

                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&nbsp;", "");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("  ", " ");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#160;", "");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#193;", "Á");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#201;", "É");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#205;", "Í");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#211;", "Ó");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#218;", "Ú");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#225;", "á");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#233;", "é");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#237;", "í");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#243;", "ó");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#250;", "ú");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#209;", "Ñ");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#241;", "ñ");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&amp;", "&");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#176;", "o");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#186;", "o");
                                    }

                                    DPlanning dplanning = new DPlanning();
                                    string    cod_PDV, cod_Reporte, cod_SubReporte, cod_Periodo, cod_Producto, cod_Marca, cod_Familia, cod_Categoria;
                                    Conexion  cn = new Conexion();

                                    bool sigue = true;
                                    for (int i = 0; i <= dt.Rows.Count - 1; i++)
                                    {                                       // llenaOperativosAsignaPDVOPE();
                                        cod_PDV        = dt.Rows[i][0].ToString().Trim();
                                        cod_Reporte    = dt.Rows[i][1].ToString().Trim();
                                        cod_SubReporte = dt.Rows[i][2].ToString().Trim();
                                        cod_Periodo    = dt.Rows[i][3].ToString().Trim();
                                        cod_Producto   = dt.Rows[i][4].ToString().Trim();
                                        cod_Marca      = dt.Rows[i][5].ToString().Trim();
                                        cod_Familia    = dt.Rows[i][6].ToString().Trim();
                                        cod_Categoria  = dt.Rows[i][7].ToString().Trim();



                                        DataSet ds = oCoon.ejecutarDataSet("UP_WEB_CONSULTAR_Existencia_Panel_ptoVenta", cod_PDV, cod_Reporte, cod_Periodo, LblPlanning.Text);

                                        if (ds.Tables[0].Rows.Count > 0)
                                        {
                                            if (ds.Tables[1].Rows.Count > 0)
                                            {
                                                DataTable tipo_reporte = oCoon.ejecutarDataTable("UP_WEBXPLORA_OPE_COMBO_TIPO_REPORTE_LISTAR", Convert.ToInt32(this.Session["company_id"].ToString().Trim()), cod_Reporte);

                                                if (tipo_reporte.Rows.Count > 0 && cod_SubReporte != "")//tiene subreporte
                                                {
                                                    //pasa

                                                    this.Session["cod_SubReporte"] = cod_SubReporte;

                                                    DataTable vistas = dplanning.ValidaTipoGestion(Convert.ToInt32(this.Session["company_id"].ToString().Trim()), this.Session["Planning_CodChannel"].ToString().Trim(), Convert.ToInt32(cod_Reporte)); //obtiene los valores booleanos para las vistas de paneles
                                                    this.Session["vistas"] = vistas;

                                                    CargarOpciones1();
                                                    insertar(cod_PDV, cod_Reporte, cod_SubReporte, cod_Periodo, LblPlanning.Text, cod_Producto, cod_Marca, cod_Familia, cod_Categoria);
                                                }
                                                else if (tipo_reporte.Rows.Count == 0 && cod_SubReporte == "")//no tiene subreporte
                                                {
                                                    //pasa

                                                    this.Session["cod_SubReporte"] = cod_SubReporte;

                                                    DataTable vistas = dplanning.ValidaTipoGestion(Convert.ToInt32(this.Session["company_id"].ToString().Trim()), this.Session["Planning_CodChannel"].ToString().Trim(), Convert.ToInt32(cod_Reporte)); //obtiene los valores booleanos para las vistas de paneles
                                                    this.Session["vistas"] = vistas;

                                                    CargarOpciones1();
                                                    insertar(cod_PDV, cod_Reporte, cod_SubReporte, cod_Periodo, LblPlanning.Text, cod_Producto, cod_Marca, cod_Familia, cod_Categoria);
                                                }
                                                else
                                                {
                                                    Pmensaje.CssClass      = "MensajesSupervisor";
                                                    lblencabezado.Text     = "Sr. Usuario";
                                                    lblmensajegeneral.Text = "El Reporte " + cod_Reporte + " no concuerda con el subreporte " + cod_SubReporte;
                                                    Mensajes_Usuario();
                                                    return;
                                                }
                                            }
                                            else
                                            {
                                                Pmensaje.CssClass      = "MensajesSupervisor";
                                                lblencabezado.Text     = "Sr. Usuario";
                                                lblmensajegeneral.Text = "El Reporte " + cod_Reporte + "o el periodo " + cod_Periodo + ". No es válido o no ha sido asignado a la campaña";
                                                Mensajes_Usuario();
                                                return;
                                            }
                                        }
                                        else
                                        {
                                            Pmensaje.CssClass      = "MensajesSupervisor";
                                            lblencabezado.Text     = "Sr. Usuario";
                                            lblmensajegeneral.Text = "El punto de venta " + cod_PDV + ". No es válido o no ha sido asignado a la campaña";
                                            Mensajes_Usuario();
                                            return;
                                        }
                                    }
                                }
                                else
                                {
                                    Gvlog.DataBind();
                                    Pmensaje.CssClass      = "MensajesSupervisor";
                                    lblencabezado.Text     = "Sr. Usuario";
                                    lblmensajegeneral.Text = "El archivo seleccionado no corresponde a un archivo de panel de puntos de venta válido. Por favor verifique la estructura que fue enviada a su correo.";
                                    Mensajes_Usuario();

                                    //System.Net.Mail.MailMessage correo = new System.Net.Mail.MailMessage();
                                    //correo.From = new System.Net.Mail.MailAddress("*****@*****.**");
                                    //correo.To.Add(this.Session["smail"].ToString());
                                    //correo.Subject = "Errores en archivo de asignación de puntos de venta";
                                    //correo.IsBodyHtml = true;
                                    //correo.Priority = System.Net.Mail.MailPriority.Normal;
                                    //string[] txtbody = new string[] { "Señor(a):" + "<br/>" +
                                    //        this.Session["nameuser"].ToString() + "<br/>" + "<br/>" +



                                    //        "El archivo que usted seleccionó para la carga de asignación de puntos de venta no cumple con una estructura válida." + "<br/>" +
                                    //        "Por favor verifique que tenga 4 columnas" + "<br/>" +  "<br/>" +
                                    //        "Sugerencia : identifique las columnas de la siguiente manera para su mayor comprensión" + "<br/>" +  "<br/>" +
                                    //        "Columna 1  : Nombre de Punto de Venta" + "<br/>" +
                                    //        "Columna 2  : Mercaderista"+ "<br/>" +
                                    //        "Columna 3  : Fecha inicio" + "<br/>" +
                                    //        "Columna 4  : Fecha fin" + "<br/>" + "<br/>" + "<br/>" +
                                    //        "Nota:  No es indispensable que las columnas se identifiquen de la misma manera como se describió anteriormente  , usted puede personalizar los nombres de las columnas del archivo ." +
                                    //        "Pero tenga en cuenta que debe ingresar la información de los puntos de venta en ese orden." + "<br/>" + "<br/>" + "<br/>" +
                                    //        "Cordial Saludo" + "<br/>" + "Administrador Xplora" };

                                    //correo.Body = string.Concat(txtbody);

                                    //System.Net.Mail.SmtpClient cliente = new System.Net.Mail.SmtpClient();
                                    //cliente.Host = "mail.lucky.com.pe";

                                    //try
                                    //{
                                    //    cliente.Send(correo);
                                    //}
                                    //catch (System.Net.Mail.SmtpException)
                                    //{
                                    //}
                                }
                            }
                            else
                            {
                                Pmensaje.CssClass      = "MensajesSupervisor";
                                lblencabezado.Text     = "Sr. Usuario";
                                lblmensajegeneral.Text = "Es indispensable que cierre sesión he inicie nuevamente. su sesión expiró.";
                                Mensajes_Usuario();
                            }
                        }
                        catch (Exception ex)
                        {
                            Pmensaje.CssClass      = "MensajesSupervisor";
                            lblencabezado.Text     = "Sr. Usuario";
                            lblmensajegeneral.Text = "El archivo seleccionado no corresponde a un archivo de panel de punto de venta. Por favor verifique que el nombre de la hoja donde estan los datos sea Hoja1";
                            Mensajes_Usuario();
                        }
                        oConn1.Close();
                    }
                    else
                    {
                        Pmensaje.CssClass      = "MensajesSupervisor";
                        lblencabezado.Text     = "Sr. Usuario";
                        lblmensajegeneral.Text = "Solo se permite cargar archivos en formato Excel 2003. Por favor verifique.";
                        Mensajes_Usuario();
                    }
                }
            }
            else
            {
                Pmensaje.CssClass      = "MensajesSupervisor";
                lblencabezado.Text     = "Sr. Usuario";
                lblmensajegeneral.Text = "Es indispensable seleccionar un archivo.";
                Mensajes_Usuario();
            }
        }
Ejemplo n.º 2
0
        protected void BtnCargaArchivo_Click(object sender, EventArgs e)
        {
            if ((FileUpPDV.PostedFile != null) && (FileUpPDV.PostedFile.ContentLength > 0))
            {
                string fn           = System.IO.Path.GetFileName(FileUpPDV.PostedFile.FileName);
                string SaveLocation = Server.MapPath("PDV_Planning") + "\\" + fn;

                if (SaveLocation != string.Empty)
                {
                    if (FileUpPDV.FileName.ToLower().EndsWith(".xls"))
                    {
                        OleDbConnection  oConn1 = new OleDbConnection();
                        OleDbCommand     oCmd   = new OleDbCommand();
                        OleDbDataAdapter oDa    = new OleDbDataAdapter();
                        DataSet          oDs    = new DataSet();

                        DataTable dt = new DataTable();


                        FileUpPDV.PostedFile.SaveAs(SaveLocation);

                        // oConn1.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + SaveLocation + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\"";
                        oConn1.ConnectionString =
                            "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
                            + SaveLocation
                            + ";Extended Properties=\"Excel 8.0; HDR=YES;\"";

                        oConn1.Open();
                        oCmd.CommandText  = "SELECT * FROM [Hoja1$]";
                        oCmd.Connection   = oConn1;
                        oDa.SelectCommand = oCmd;

                        try{
                            if (this.Session["scountry"].ToString() != null)
                            {
                                oDa.Fill(oDs);
                                dt = oDs.Tables[0];

                                if (dt.Columns.Count == 4)
                                {
                                    dt.Columns[0].ColumnName = "Cod_PDV";
                                    dt.Columns[1].ColumnName = "Cod_Mercaderista";
                                    dt.Columns[2].ColumnName = "Fecha inicio";
                                    dt.Columns[3].ColumnName = "Fecha fin";

                                    Gvlog.DataSource = dt;
                                    Gvlog.DataBind();

                                    for (int i = 0; i <= Gvlog.Rows.Count - 1; i++)
                                    {
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&nbsp;", "");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#160;", "");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#193;", "Á");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#201;", "É");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#205;", "Í");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#211;", "Ó");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#218;", "Ú");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#225;", "á");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#233;", "é");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#237;", "í");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#243;", "ó");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#250;", "ú");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#209;", "Ñ");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#241;", "ñ");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&amp;", "&");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#176;", "o");
                                        Gvlog.Rows[i].Cells[0].Text = Gvlog.Rows[i].Cells[0].Text.Replace("&#186;", "o");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&nbsp;", "");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("  ", " ");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#160;", "");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#193;", "Á");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#201;", "É");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#205;", "Í");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#211;", "Ó");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#218;", "Ú");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#225;", "á");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#233;", "é");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#237;", "í");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#243;", "ó");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#250;", "ú");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#209;", "Ñ");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#241;", "ñ");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&amp;", "&");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#176;", "o");
                                        Gvlog.Rows[i].Cells[1].Text = Gvlog.Rows[i].Cells[1].Text.Replace("&#186;", "o");
                                    }

                                    string nombre_pdv;
                                    bool   sigue = true;
                                    for (int i = 0; i <= dt.Rows.Count - 1; i++)
                                    {
                                        llenaOperativosAsignaPDVOPE();

                                        nombre_pdv = dt.Rows[i][0].ToString().Trim();

                                        DataTable dtValidaNombre =
                                            oCoon.ejecutarDataTable("UP_WEBXPLORA_PLA_VALIDACIONES_CARGAMASIVAPDVOPE",
                                                                    "Nombre",
                                                                    LblPlanning.Text,
                                                                    dt.Rows[i][0].ToString().Trim());

                                        if (dtValidaNombre.Rows.Count > 0)
                                        {
                                            CbmPDV.DataSource     = dtValidaNombre;
                                            CbmPDV.DataTextField  = "pdv_Name";
                                            CbmPDV.DataValueField = "id_MPOSPlanning";
                                            CbmPDV.DataBind();

                                            sigue = true;
                                            Gvlog.Rows[i].Cells[0].Text = dtValidaNombre.Rows[0][0].ToString().Trim();
                                        }
                                        else
                                        {
                                            Pmensaje.CssClass      = "MensajesSupervisor";
                                            lblencabezado.Text     = "Sr. Usuario";
                                            lblmensajegeneral.Text = "El punto de venta " + Gvlog.Rows[i].Cells[0].Text + ". No es válido o no ha sido asignado a la campaña";
                                            Mensajes_Usuario();
                                            sigue = false;
                                            i     = dt.Rows.Count - 1;
                                        }

                                        if (sigue)
                                        {
                                            try{
                                                CmbOpePlanning.Items.FindByText(Gvlog.Rows[i].Cells[1].Text.ToUpper()).Selected = true;
                                                Gvlog.Rows[i].Cells[1].Text = CmbOpePlanning.SelectedItem.Value;
                                            }catch {
                                                Pmensaje.CssClass      = "MensajesSupervisor";
                                                lblencabezado.Text     = "Sr. Usuario";
                                                lblmensajegeneral.Text = "El mercaderista "
                                                                         + Gvlog.Rows[i].Cells[1].Text
                                                                         + ". No es válido o no ha sido asignado a la campaña";
                                                Mensajes_Usuario();
                                                sigue = false;
                                                i     = dt.Rows.Count - 1;
                                            }
                                        }

                                        if (sigue)
                                        {
                                            try{
                                                DateTime FechainicialPlanning = DateTime.Parse(this.Session["Fechainicial"].ToString().Trim());
                                                DateTime FechafinalPlanning   = DateTime.Parse(this.Session["Fechafinal"].ToString().Trim());
                                                DateTime FechaInicial         = DateTime.Parse(Gvlog.Rows[i].Cells[2].Text);
                                                DateTime Fechafinal           = DateTime.Parse(Gvlog.Rows[i].Cells[3].Text);
                                                if (FechaInicial > Fechafinal)
                                                {
                                                    Pmensaje.CssClass      = "MensajesSupervisor";
                                                    lblencabezado.Text     = "Sr. Usuario";
                                                    lblmensajegeneral.Text = "La fecha inicial no puede ser mayor a la fecha final";
                                                    Mensajes_Usuario();
                                                    sigue = false;
                                                    i     = dt.Rows.Count - 1;
                                                }

                                                if (FechaInicial < FechainicialPlanning || Fechafinal > FechafinalPlanning)
                                                {
                                                    Pmensaje.CssClass      = "MensajesSupervisor";
                                                    lblencabezado.Text     = "Sr. Usuario";
                                                    lblmensajegeneral.Text = "Las fechas deben estar dentro del rango : " + FechainicialPlanning.ToShortDateString() + " y " + FechafinalPlanning.ToShortDateString() + " que corresponden a las fechas de ejecución de la Campaña";
                                                    Mensajes_Usuario();
                                                    sigue = false;
                                                    i     = dt.Rows.Count - 1;
                                                }

                                                if (FechaInicial < DateTime.Today)
                                                {
                                                    Pmensaje.CssClass      = "MensajesSupervisor";
                                                    lblencabezado.Text     = "Sr. Usuario";
                                                    lblmensajegeneral.Text = "La fecha inicial debe ser igual o superior a la fecha actual";
                                                    Mensajes_Usuario();
                                                    sigue = false;
                                                    i     = dt.Rows.Count - 1;
                                                }

                                                Gvlog.Rows[i].Cells[2].Text = Gvlog.Rows[i].Cells[2].Text + " 01:00:00.000";
                                                Gvlog.Rows[i].Cells[3].Text = Gvlog.Rows[i].Cells[3].Text + " 23:59:00.000";
                                            } catch {
                                                Pmensaje.CssClass      = "MensajesSupervisor";
                                                lblencabezado.Text     = "Sr. Usuario";
                                                lblmensajegeneral.Text = "Formato de fecha no valido. Por favor verifique (dd/mm/aaaa)";
                                                Mensajes_Usuario();
                                                sigue = false;
                                                i     = dt.Rows.Count - 1;
                                            }
                                        }
                                    }

                                    if (sigue)
                                    {
                                        for (int i = 0; i <= Gvlog.Rows.Count - 1; i++)
                                        {
                                            DataTable dtconsulta =
                                                wsPlanning.Get_AsignacionDuplicadaPDV(
                                                    Convert.ToInt32(Gvlog.Rows[i].Cells[0].Text),
                                                    Convert.ToInt32(Gvlog.Rows[i].Cells[1].Text),
                                                    LblPlanning.Text);

                                            if (dtconsulta != null)
                                            {
                                                if (dtconsulta.Rows.Count == 0)   // 1 > 0

                                                {
                                                    PointOfSale_PlanningOper obj = new PointOfSale_PlanningOper();

                                                    EPointOfSale_PlanningOper RegistrarPointOfSale_PlanningOper =
                                                        obj.RegistrarAsignPDVaOperativo(
                                                            Convert.ToInt32(Gvlog.Rows[i].Cells[0].Text),
                                                            LblPlanning.Text,
                                                            Convert.ToInt32(Gvlog.Rows[i].Cells[1].Text),
                                                            Convert.ToDateTime(Gvlog.Rows[i].Cells[2].Text),
                                                            Convert.ToDateTime(Gvlog.Rows[i].Cells[3].Text), 0,
                                                            true,
                                                            Convert.ToString(this.Session["sUser"]),
                                                            DateTime.Now,
                                                            Convert.ToString(this.Session["sUser"]),
                                                            DateTime.Now);

                                                    obj.RegistrarTBL_EQUIPO_PTO_VENTA(
                                                        Convert.ToInt32(Gvlog.Rows[i].Cells[0].Text),
                                                        LblPlanning.Text,
                                                        Convert.ToInt32(Gvlog.Rows[i].Cells[1].Text),
                                                        Convert.ToDateTime(Gvlog.Rows[i].Cells[2].Text),
                                                        Convert.ToDateTime(Gvlog.Rows[i].Cells[3].Text));
                                                }
                                                else
                                                {
                                                    // metodo de actualizacion
                                                    PointOfSale_PlanningOper  obj = new PointOfSale_PlanningOper();
                                                    EPointOfSale_PlanningOper ActualizarPointOfSale_PlanningOper =
                                                        obj.ActualizarAsignPDVaOperativo(
                                                            Convert.ToInt32(dtconsulta.Rows[0][6].ToString().Trim()),
                                                            Convert.ToDateTime(Gvlog.Rows[i].Cells[2].Text),
                                                            Convert.ToDateTime(Gvlog.Rows[i].Cells[3].Text),
                                                            Convert.ToString(this.Session["sUser"]),
                                                            DateTime.Now);
                                                    try{
                                                        PointOfSale_PlanningOper ActualizarTBL_EQUIPO_PTO_VENTA = new PointOfSale_PlanningOper();
                                                        ActualizarTBL_EQUIPO_PTO_VENTA.ActualizarTBL_EQUIPO_PTO_VENTA(dtconsulta.Rows[0][5].ToString().Trim(), LblPlanning.Text,
                                                                                                                      Convert.ToInt32(Gvlog.Rows[i].Cells[1].Text), Convert.ToDateTime(Gvlog.Rows[i].Cells[2].Text), Convert.ToDateTime(Gvlog.Rows[i].Cells[3].Text));
                                                    }catch (Exception ex) {
                                                        Pmensaje.CssClass      = "MensajesSupervisor";
                                                        lblencabezado.Text     = "Sr. Usuario";
                                                        lblmensajegeneral.Text = "La campaña no existe en la base de datos de Nextel "
                                                                                 + ". Consulte con el Administrador Xplora";
                                                        Mensajes_Usuario();
                                                    }
                                                }
                                            }
                                        }

                                        Pmensaje.CssClass      = "MensajesSupConfirm";
                                        lblencabezado.Text     = "Sr. Usuario";
                                        lblmensajegeneral.Text = "Se ha asignado con éxito los puntos de venta para la campaña : " + LblPresupuestoPDV.Text;
                                        Mensajes_Usuario();
                                    }
                                }
                                else
                                {
                                    Gvlog.DataBind();
                                    Pmensaje.CssClass      = "MensajesSupervisor";
                                    lblencabezado.Text     = "Sr. Usuario";
                                    lblmensajegeneral.Text = "El archivo seleccionado no corresponde a un archivo de asignación "
                                                             + "de puntos de venta válido. Por favor verifique la estructura que fue enviada a su correo.";
                                    Mensajes_Usuario();

                                    System.Net.Mail.MailMessage correo = new System.Net.Mail.MailMessage();
                                    correo.From = new System.Net.Mail.MailAddress("*****@*****.**");
                                    correo.To.Add(this.Session["smail"].ToString());
                                    correo.Subject    = "Errores en archivo de asignación de puntos de venta";
                                    correo.IsBodyHtml = true;
                                    correo.Priority   = System.Net.Mail.MailPriority.Normal;
                                    string[] txtbody = new string[] { "Señor(a):" + "<br/>" +
                                                                      this.Session["nameuser"].ToString()
                                                                      + "<br/>"
                                                                      + "<br/>"
                                                                      + "El archivo que usted seleccionó para la carga de asignación de puntos de venta no cumple con una estructura válida."
                                                                      + "<br/>"
                                                                      + "Por favor verifique que tenga 4 columnas"
                                                                      + "<br/>"
                                                                      + "<br/>"
                                                                      + "Sugerencia : identifique las columnas de la siguiente manera para su mayor comprensión"
                                                                      + "<br/>"
                                                                      + "<br/>"
                                                                      + "Columna 1  : Nombre de Punto de Venta"
                                                                      + "<br/>"
                                                                      + "Columna 2  : Mercaderista"
                                                                      + "<br/>"
                                                                      + "Columna 3  : Fecha inicio"
                                                                      + "<br/>"
                                                                      + "Columna 4  : Fecha fin"
                                                                      + "<br/>"
                                                                      + "<br/>"
                                                                      + "<br/>"
                                                                      + "Nota:  No es indispensable que las columnas se identifiquen de la misma manera como se describió anteriormente "
                                                                      + ", usted puede personalizar los nombres de las columnas del archivo ."
                                                                      + "Pero tenga en cuenta que debe ingresar la información de los puntos de venta en ese orden."
                                                                      + "<br/>"
                                                                      + "<br/>"
                                                                      + "<br/>"
                                                                      + "Cordial Saludo" + "<br/>" + "Administrador Xplora" };

                                    correo.Body = string.Concat(txtbody);

                                    System.Net.Mail.SmtpClient cliente = new System.Net.Mail.SmtpClient();
                                    cliente.Host = "mail.lucky.com.pe";

                                    try {
                                        cliente.Send(correo);
                                    }catch (System.Net.Mail.SmtpException) {
                                    }
                                }
                            }
                            else
                            {
                                Pmensaje.CssClass      = "MensajesSupervisor";
                                lblencabezado.Text     = "Sr. Usuario";
                                lblmensajegeneral.Text = "Es indispensable que cierre sesión he inicie nuevamente. su sesión expiró.";
                                Mensajes_Usuario();
                            }
                        }
                        catch (Exception ex) {
                            Pmensaje.CssClass      = "MensajesSupervisor";
                            lblencabezado.Text     = "Sr. Usuario";
                            lblmensajegeneral.Text = "El archivo seleccionado no corresponde a un archivo de puntos de venta válido. "
                                                     + "Por favor verifique que el nombre de la hoja donde estan los datos sea Hoja1";
                            Mensajes_Usuario();
                        }
                        oConn1.Close();
                    }
                    else
                    {
                        Pmensaje.CssClass      = "MensajesSupervisor";
                        lblencabezado.Text     = "Sr. Usuario";
                        lblmensajegeneral.Text = "Solo se permite cargar archivos en formato Excel 2003. Por favor verifique.";
                        Mensajes_Usuario();
                    }
                }
            }
            else
            {
                Pmensaje.CssClass      = "MensajesSupervisor";
                lblencabezado.Text     = "Sr. Usuario";
                lblmensajegeneral.Text = "Es indispensable seleccionar un archivo.";
                Mensajes_Usuario();
            }
        }