Пример #1
0
    private void LlenarEstados()
    {
        try
        {
            BL_ASIGNACION_RECURSOS obj = new BL_ASIGNACION_RECURSOS();
            DataTable dtResultado      = new DataTable();

            foreach (DataListItem FilaFactor in DataListRecursos.Items)
            {
                int id = (int)DataListRecursos.DataKeys[FilaFactor.ItemIndex];
                dtResultado = obj.LIST_ASIGNACION_DETALLE_POR_ID(id);

                RadioButtonList RadioEstados = ((RadioButtonList)FilaFactor.FindControl("RadioEstados"));
                RadioEstados.SelectedValue = dtResultado.Rows[0]["FLG_ATENDIDO"].ToString();

                RadioEstados.DataSource     = GetEstado();
                RadioEstados.DataTextField  = GetEstado().Columns["ValueMember"].ToString();
                RadioEstados.DataValueField = GetEstado().Columns["DisplayMember"].ToString();
                RadioEstados.DataBind();
            }
        }
        catch (Exception ex)
        {
            UC_MessageBox.Show(Page, Page.GetType(), "Ocurrio un error :" + ex.Message);
            return;
        }
    }
Пример #2
0
    protected void LogIn(object sender, EventArgs e)
    {
        string     pMesajeResp   = string.Empty;
        BE_Usuario oBE_Usuario   = new BE_Usuario(Email.Text.Trim(), Password.Text.Trim());
        BE_Usuario oBE_Usuario_R = new BE_Usuario();
        BE_Usuario objUsuario_R  = new BE_Usuario();

        BL_Seguridad obj_Usuario = new BL_Seguridad();
        DataTable    dt          = new DataTable();

        oBE_Usuario_R = new BL_Seguridad().f_LogeoUsuario_B(oBE_Usuario, ref pMesajeResp);
        if (string.IsNullOrEmpty(oBE_Usuario_R.f_Usuario_E))
        {
            objUsuario_R = new BL_Seguridad().f_LogeoUsuarioSinRol_B(oBE_Usuario, ref pMesajeResp);
            if (string.IsNullOrEmpty(objUsuario_R.f_Usuario_E))
            {
                UC_MessageBox.Show(Page, this.GetType(), pMesajeResp);
            }
            else
            {
                Session["IDE_USUARIO"] = objUsuario_R.f_Usuario_E.ToString();
                string url = objUsuario_R.f_UrlDefault_E;
                Response.Redirect(url);
            }
        }
        else
        {
            string url = oBE_Usuario_R.f_UrlDefault_E;
            //string url = "~/Bienvenido.aspx";
            Response.Redirect(url);
        }
    }
    protected void btnCarga_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            string FileName   = Path.GetFileName(FileUpload1.PostedFile.FileName);
            string Extension  = Path.GetExtension(FileUpload1.PostedFile.FileName);
            string FolderPath = ConfigurationManager.AppSettings["FolderPath"];

            if (ValidaExtension(Extension))
            {
                string FilePath = Server.MapPath(FolderPath + FileName);
                try
                {
                    if (System.IO.File.Exists(FilePath))
                    {
                        File.Delete(FilePath);
                    }
                    FileUpload1.SaveAs(FilePath);

                    Import_To_Grid(FilePath, Extension, "Yes");
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                UC_MessageBox.Show(Page, Page.GetType(), "Formato no permitido");
                return;
            }
        }
    }
    protected void btnYes_Click(object sender, EventArgs e)
    {
        BL_RO     obj         = new BL_RO();
        DataTable dtResultado = new DataTable();

        string tipoCambio       = string.IsNullOrEmpty(txtTipoCambio.Text) ? "0.00" : txtTipoCambio.Text;
        string Monto            = string.IsNullOrEmpty(txtMonto.Text) ? "0.00" : txtMonto.Text;
        string MontoContractual = string.IsNullOrEmpty(txtMontoContractual.Text) ? "0.00" : txtMontoContractual.Text;
        string Estado           = ddlEstado.SelectedValue;


        dtResultado = obj.registro_Proyectos(
            txtCodigo.Text,
            txtdescripcion.Text,
            txtContrato.Text,
            ddlMoneda.SelectedValue,
            txtCliente.Text,
            txtInicio.Text,
            txtTermino.Text,
            Convert.ToDecimal(tipoCambio),
            txtProgramado.Text,
            string.Empty,
            Session["IDE_USUARIO"].ToString(),
            Convert.ToInt32(ddlEmpresaEditar.SelectedValue),
            Estado,
            Convert.ToDecimal(Monto),
            Convert.ToDecimal(MontoContractual)
            );

        if (dtResultado.Rows.Count > 0)
        {
            string estado = dtResultado.Rows[0]["ESTADO"].ToString();
            if (estado == "1")
            {
                Limpiar();
                ListarProyectos();
                string cleanMessage = "Proyecto registrado correctamente";
                ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + cleanMessage + "');", true);
            }
            else if (estado == "2")
            {
                Limpiar();
                ListarProyectos();
                string cleanMessage = "Proyecto Actualizado";
                ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + cleanMessage + "');", true);
            }
            else
            {
                string cleanMessage = "Proyecto no registrado, Verificar Datos ingresados";
                ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + cleanMessage + "');", true);
            }
        }
        else
        {
            txtCodigo.Focus();
            UC_MessageBox.Show(Page, this.GetType(), "Proyecto no registrado, Verificar Datos ingresados");
            return;
        }
    }
Пример #5
0
    private void ListarPep()
    {
        try
        {
            BL_LOG_SOLPED obj         = new BL_LOG_SOLPED();
            DataTable     dtResultado = new DataTable();

            foreach (ListViewItem FilaFactor in lstRol.Items)
            {
                DropDownList ddlPep = ((DropDownList)FilaFactor.FindControl("ddlPep"));
                string       codigo = lstRol.DataKeys[FilaFactor.DisplayIndex].Value.ToString();

                dtResultado = obj.uspSEL_LOG_MATERIALES_PEP_IDE_MATERIAL(codigo);

                ddlPep.DataSource     = dtResultado;
                ddlPep.DataTextField  = dtResultado.Columns["PEP_DETALLE"].ToString();
                ddlPep.DataValueField = dtResultado.Columns["PEP"].ToString();
                ddlPep.DataBind();

                //dtResultado.AsDataView
                //DataView dv = ds.Tables[0].DefaultView;
                DataView dv = new DataView(dtResultado);
                //dv.RowFilter = "FLG_CAMBIO='" + false + "'";
                foreach (DataRowView dr in dv)
                {
                    foreach (ListItem item in ddlPep.Items)
                    {
                        if (Convert.ToBoolean(dr["FLG_CAMBIO"].ToString()) == false)
                        {
                            item.Attributes.Add("style", "background-color:#3399FF;color:white;font-weight:bold;");
                        }
                        else
                        {
                            item.Attributes.Add("style", "background-color:#3399FF;color:red;font-weight:bold;");
                        }
                    }
                }

                //foreach (ListItem item in ddlPep.Items)
                //{

                //    string x = dtResultado.Columns["FLG_CAMBIO"].ToString();
                //    if (x == "0")
                //    {
                //        item.Attributes.Add("style", "background-color:#3399FF;color:white;font-weight:bold;");
                //    }
                //}
            }
            // ModalRegistro.Show();
        }
        catch (Exception ex)
        {
            UC_MessageBox.Show(Page, Page.GetType(), "Ocurrio un error al Consultar :" + ex.Message);
            return;
        }
    }
Пример #6
0
 private void BtnYes_Click(object sender, RoutedEventArgs e)
 {
     _msgresult = MessageBoxResult.Yes;
     if (EditBoxName.Text == "")
     {
         UC_MessageBox.ShowMsgBox("配方名称不能为空", "错误");
     }
     else
     {
         ProfileValue = new Tuple <string, string>(EditBoxName.Text, EditBoxRemark.Text);
         Close();
     }
 }
Пример #7
0
 private void BtnYes_Click(object sender, RoutedEventArgs e)
 {
     _msgresult = MessageBoxResult.Yes;
     if (EditBoxName.Text == "")
     {
         UC_MessageBox.ShowMsgBox("名称不能为空", "错误");
     }
     else
     {
         ProfileValue = EditBoxName.Text;
         Close();
     }
 }
Пример #8
0
    //protected void Seleccionar(object sender, ImageClickEventArgs e)
    //{
    //    string pMesajeResp = string.Empty;
    //    ImageButton btnAdd = ((ImageButton)sender);
    //    int item = Convert.ToInt32(btnAdd.CommandArgument);



    //    BL_Session.Usuario = lstRol.DataKeys[item -1].Values["IDE_USUARIO"].ToString();
    //    BL_Session.IdSistema = (int)lstRol.DataKeys[item - 1].Values["IdSistema"];
    //    BL_Session.Perfil = (int)lstRol.DataKeys[item - 1].Values["IdPerfil"];
    //    BL_Session.PerfilNombre = lstRol.DataKeys[item - 1].Values["Descripcion"].ToString();
    //    BL_Session.UsuarioNombre = lstRol.DataKeys[item - 1].Values["DES_NOMBRE_USUARIO"].ToString();


    //    Response.Redirect(lstRol.DataKeys[item - 1].Values["UrlDefault"].ToString());


    //}

    protected void LogIn(object sender, EventArgs e)
    {
        string     pMesajeResp   = string.Empty;
        DataTable  dtResultado   = new DataTable();
        BE_Usuario oBE_Usuario   = new BE_Usuario(Email.Text.Trim(), Password.Text.Trim());
        BE_Usuario oBE_Usuario_R = new BE_Usuario();

        oBE_Usuario_R = new BL_Seguridad().f_LogeoDatos_B(oBE_Usuario, ref pMesajeResp);
        if (string.IsNullOrEmpty(oBE_Usuario_R.f_Usuario_E))
        {
            UC_MessageBox.Show(Page, this.GetType(), pMesajeResp);
        }

        else
        {
            BL_Seguridad objSeg = new BL_Seguridad();
            dtResultado = objSeg.ListarSistemas(Email.Text.Trim());
            if (dtResultado.Rows.Count == 1)
            {
                BE_Usuario oBE_user   = new BE_Usuario();
                BE_Usuario oBE_Acceso = new BE_Usuario();
                oBE_user.f_Usuario_E   = Email.Text.Trim();
                oBE_user.f_Password_E  = Password.Text.Trim();
                oBE_user.f_IdSistema_E = dtResultado.Rows[0]["IdSistema"].ToString();
                oBE_Acceso             = new BL_Seguridad().f_LogeoUsuario_B(oBE_user, ref pMesajeResp);

                if (string.IsNullOrEmpty(oBE_Acceso.f_Usuario_E))
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + pMesajeResp + "');", true);
                }

                else
                {
                    string url = oBE_Acceso.f_UrlDefault_E;
                    Response.Redirect(url);
                }
            }
            else
            {
                Response.Redirect("~/Login/Main.aspx");
                //lstRol.DataSource = dtResultado;
                //lstRol.DataBind();
                //ModalRegistro.Show();
            }
            //string url = oBE_Usuario_R.f_UrlDefault_E;
            //Response.Redirect(url);
        }
    }
Пример #9
0
    protected void Actualizar_Indicador(object sender, ImageClickEventArgs e)
    {
        BL_RO     obj         = new BL_RO();
        DataTable dtResultado = new DataTable();

        ImageButton  btnSave           = ((ImageButton)sender);
        GridViewRow  row               = btnSave.NamingContainer as GridViewRow;
        string       pk                = GridPEP.DataKeys[row.RowIndex].Values[0].ToString();
        DropDownList ddlGridIndicador  = (DropDownList)row.FindControl("ddlGridIndicador");
        TextBox      txtDescripcionPep = (TextBox)row.FindControl("txtDescripcionPep");


        obj.actualizar_Indicador_PEP(Convert.ToInt32(pk), Convert.ToInt32(ddlGridIndicador.SelectedValue), txtDescripcionPep.Text);
        Listar_IndicadoresPEP();
        UC_MessageBox.Show(Page, Page.GetType(), txtDescripcionPep.Text + " : Se actualizo al indicador " + ddlGridIndicador.SelectedItem);
        return;
    }
Пример #10
0
        private bool DebugTool(ToolDataBase para)
        {
            try
            {
                switch (para.ToolType)
                {
                case EnumToolType.LineTool:
                {
                    var ToolData = para as LineToolData;
                    HalconVision.Instance.Debug_FindLine(0, ToolData.Polarity, ToolData.SelectType, ToolData.Contrast, ToolData.CaliperNum);
                    return(true);
                }

                case EnumToolType.CircleTool:
                {
                }
                break;

                case EnumToolType.PairTool:
                {
                    PairToolData data = para as PairToolData;
                    HalconVision.Instance.Debug_FindPair(0, data.Polarity, data.SelectType, data.ExpectPairNum, data.Contrast, data.CaliperNum);
                    return(true);
                }

                case EnumToolType.FlagTool:
                {
                    FlagToolDaga data = para as FlagToolDaga;
                    AddFlag(data);
                }
                break;

                default:
                    break;
                }
                return(true);
            }
            catch (Exception ex)
            {
                UC_MessageBox.ShowMsgBox("Error", ex.Message, MsgType.Error);
                return(false);
            }
        }
    protected void registrarCompetencias(int IDE_EVAL_EXAMEN)
    {
        try
        {
            int Cod;
            for (int i = 0; i < ListView1.Items.Count; i++) // aqui se recorre toda la lista
            {
                ListViewItem    Fila = ListView1.Items[i];
                RadioButtonList rb   = (RadioButtonList)Fila.FindControl("RadioButtonList1"); // aqui esta elnombre de tu control en la lista y tienes q cambiar RadioButtonList x tu check

                if (rb.SelectedValue != string.Empty)
                {
                    Cod = Convert.ToInt32(ListView1.DataKeys[i].Values[0].ToString()); // extraer key

                    string cleanMessage = string.Empty;

                    BE_RRHH_FORMATIVO_EXAM_CARTILLA obj = new BE_RRHH_FORMATIVO_EXAM_CARTILLA();
                    obj.IDE_EXAMEN      = 0;
                    obj.IDE_PREGUNTA    = Cod;
                    obj.IDE_NOTA        = Convert.ToInt32(rb.SelectedValue);
                    obj.EVALUADOR       = Session["IDE_USUARIO"].ToString();
                    obj.EVALUADO        = Session["DNI_EVALUADO"].ToString();
                    obj.IDE_EVAL_EXAMEN = IDE_EVAL_EXAMEN;
                    obj.IDE_PROGRAMA    = Convert.ToInt32(Session["IDE_PROGRAMA"]);

                    int rpta = 0;

                    rpta = new BL_RRHH_FORMATIVO_EXAM_CARTILLA().uspINS_RRHH_FORMATIVO_EXAM_CARTILLA(obj);
                    if (rpta > 0)
                    {
                        cleanMessage = "Registro satisfactorio";
                        ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + cleanMessage + "');", true);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            UC_MessageBox.Show(Page, Page.GetType(), "Ocurrio un error al Consultar :" + ex.Message);
            return;
        }
    }
Пример #12
0
 protected void btnProcesar_Click(object sender, EventArgs e)
 {
     if (FileUpload1.FileBytes.Length <= 0)
     {
     }
     else
     {
         string path          = Path.GetFileName(FileUpload1.PostedFile.FileName);
         string fileExtension = Path.GetExtension(path).ToLower();
         if (ValidaExtension(fileExtension))
         {
             Bulk_Insert(FileUpload1, "dbo.TMP_LOGISTICA_REG_ALMACEN", img1);
         }
         else
         {
             UC_MessageBox.Show(Page, Page.GetType(), "Formato no permitido");
             return;
         }
     }
 }
Пример #13
0
    protected void btnEliminar_Click(object sender, EventArgs e)
    {
        BL_CJI3      obj         = new BL_CJI3();
        BL_Seguridad objSeg      = new BL_Seguridad();
        DataTable    dtResultado = new DataTable();

        dtResultado = obj.eliminar_periodo(Convert.ToInt32(ddlAnio.SelectedValue), Convert.ToInt32(ddlMes.SelectedValue));
        string estado = dtResultado.Rows[0]["ESTADO"].ToString();

        if (estado == "1")
        {
            objSeg.auditoria_procesos("CJI3", Session["IDE_USUARIO"].ToString(), "");

            UC_MessageBox.Show(Page, this.GetType(), "Periodo eliminado satisfactoriamente");
        }
        else
        {
            UC_MessageBox.Show(Page, this.GetType(), "No existen registros ha eliminar");
            return;
        }
    }
Пример #14
0
    protected void btnProcesar_Click(object sender, EventArgs e)
    {
        //System.Threading.Thread.Sleep(5000);

        if (FileUpload1.FileBytes.Length <= 0)
        {
        }
        else
        {
            string path          = Path.GetFileName(FileUpload1.PostedFile.FileName);
            string fileExtension = Path.GetExtension(path).ToLower();
            if (ValidaExtension(fileExtension))
            {
                Bulk_Insert(FileUpload1, "dbo.TMP_LOG_INDICADORES_ASIGNACION", img1);
            }
            else
            {
                UC_MessageBox.Show(Page, Page.GetType(), "Formato no permitido");
                return;
            }
        }
    }
    private void OpcionesRespuestaCar()
    {
        try
        {
            BL_PERSONAL obj = new BL_PERSONAL();
            DataTable   dt  = new DataTable();
            dt = obj.ListarParametros_orden("RRHH_FORMATIVO_EXAM_CARTILLA", "NIVEL_EXIGENCIA");
            //int Cod = 0;

            BL_RRHH_FORMATIVO_EXAM_CARTILLA objEx = new BL_RRHH_FORMATIVO_EXAM_CARTILLA();
            DataTable dtEx = new DataTable();

            foreach (ListViewItem FilaFactor in ListView1.Items)
            {
                RadioButtonList RadioButtonList1 = ((RadioButtonList)FilaFactor.FindControl("RadioButtonList1"));

                RadioButtonList1.DataSource     = dt;
                RadioButtonList1.DataTextField  = "RESUMEN_ORDEN";
                RadioButtonList1.DataValueField = "ID_PARAMETRO";
                RadioButtonList1.DataBind();


                string codePregunta = ListView1.DataKeys[FilaFactor.DisplayIndex].Value.ToString();


                dtEx = objEx.uspSEL_RESPUESTA_EXAM_CARTILLA(Convert.ToInt32(codePregunta), Session["IDE_USUARIO"].ToString(), Session["DNI_EVALUADO"].ToString(), Convert.ToInt32(lblCodigo.Text), Convert.ToInt32(Session["IDE_PROGRAMA"].ToString()));
                if (dtEx.Rows.Count > 0)
                {
                    RadioButtonList1.SelectedValue = dtEx.Rows[0]["IDE_NOTA"].ToString();
                }
            }
        }
        catch (Exception ex)
        {
            UC_MessageBox.Show(Page, Page.GetType(), "Ocurrio un error al Consultar :" + ex.Message);
            return;
        }
    }
    protected void registrarEspecificas(int IDE_EVAL_EXAMEN)
    {
        try
        {
            int Cod;
            for (int i = 0; i < ListView2.Items.Count; i++) // aqui se recorre toda la lista
            {
                ListViewItem    Fila = ListView2.Items[i];
                RadioButtonList rb   = (RadioButtonList)Fila.FindControl("RadioButtonList2"); // aqui esta elnombre de tu control en la lista y tienes q cambiar RadioButtonList x tu check

                if (rb.SelectedValue != string.Empty)
                {
                    Cod = Convert.ToInt32(ListView2.DataKeys[i].Values[0].ToString()); // extraer key

                    string cleanMessage = string.Empty;

                    BE_RRHH_FORMATIVO_EXAM_CARTILLA obj = new BE_RRHH_FORMATIVO_EXAM_CARTILLA();
                    obj.IDE_EXAMEN      = 0;
                    obj.IDE_PREGUNTA    = Cod;
                    obj.IDE_NOTA        = Convert.ToInt32(rb.SelectedValue);
                    obj.EVALUADOR       = Session["IDE_USUARIO"].ToString();
                    obj.EVALUADO        = Session["DNI_EVALUADO"].ToString();
                    obj.IDE_EVAL_EXAMEN = IDE_EVAL_EXAMEN;
                    obj.IDE_PROGRAMA    = Convert.ToInt32(Session["IDE_PROGRAMA"]);

                    int rpta = 0;

                    rpta = new BL_RRHH_FORMATIVO_EXAM_CARTILLA().uspINS_RRHH_FORMATIVO_EXAM_CARTILLA(obj);
                }
            }
        }
        catch (Exception ex)
        {
            UC_MessageBox.Show(Page, Page.GetType(), "Ocurrio un error al Consultar :" + ex.Message);
            return;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        HiddenField1.Value = Request.QueryString["Usuario"];

        string Requ_Numero      = Request.QueryString["Requ_Numero"];
        string Reqd_CodLinea    = Request.QueryString["Reqd_CodLinea"];
        string Reqs_Correlativo = Request.QueryString["Reqs_Correlativo"];

        Boolean correo = email_bien_escrito(HiddenField1.Value);

        if (correo == true)
        {
            BL_RRHH_COMPETENCIAS_EVAL obj = new BL_RRHH_COMPETENCIAS_EVAL();
            DataTable dtResultado         = new DataTable();
            dtResultado = obj.uspSEL_RRHH_PERSONAL_EMPRESA_POR_CORREO(HiddenField1.Value);
            if (dtResultado.Rows.Count > 0)
            {
                //Session["IDE_USUARIO"] =

                string     pMesajeResp = string.Empty;
                BE_Usuario oBE_Usuario = new BE_Usuario();
                oBE_Usuario.f_Usuario_E = dtResultado.Rows[0]["ID_DNI"].ToString();

                BE_Usuario objUsuario_R = new BE_Usuario();

                BL_Seguridad obj_Usuario = new BL_Seguridad();
                objUsuario_R = new BL_Seguridad().f_LogeoUsuarioExterno(oBE_Usuario, ref pMesajeResp);
                if (string.IsNullOrEmpty(objUsuario_R.f_Usuario_E))
                {
                    UC_MessageBox.Show(Page, this.GetType(), pMesajeResp);
                }
                else
                {
                    Session["IDE_USUARIO"] = objUsuario_R.f_Usuario_E.ToString();


                    Response.Redirect("~/CAREMENOR/PDC_Adjunto.aspx?Requ_Numero='" + Requ_Numero.Trim() + "'&Reqd_CodLinea='" + Reqd_CodLinea.Trim() + "'&Reqs_Correlativo='" + Reqs_Correlativo + "'");
                }
            }
            else
            {
                Response.Redirect("~/RRHH/Contacto.aspx");
            }
        }
        else
        {
            string     pMesajeResp = string.Empty;
            BE_Usuario oBE_Usuario = new BE_Usuario();
            oBE_Usuario.f_Usuario_E = HiddenField1.Value;

            BE_Usuario objUsuario_R = new BE_Usuario();

            BL_Seguridad obj_Usuario = new BL_Seguridad();
            objUsuario_R = new BL_Seguridad().f_LogeoUsuarioExterno(oBE_Usuario, ref pMesajeResp);
            if (string.IsNullOrEmpty(objUsuario_R.f_Usuario_E))
            {
                UC_MessageBox.Show(Page, this.GetType(), pMesajeResp);
            }
            else
            {
                Session["IDE_USUARIO"] = objUsuario_R.f_Usuario_E.ToString();

                Response.Redirect("~/CAREMENOR/PDC_Adjunto.aspx?Requ_Numero=" + Requ_Numero.Trim() + "&Reqd_CodLinea=" + Reqd_CodLinea.Trim() + "&Reqs_Correlativo=" + Reqs_Correlativo);
            }
        }
    }
    protected void Bulk_Insert_Almacen(FileUpload FileUpload1, string tabla, Image img)
    {
        string excelPath = Server.MapPath("~/File/") + Path.GetFileName(FileUpload1.PostedFile.FileName);

        FileUpload1.SaveAs(excelPath);

        string conString = string.Empty;
        string extension = Path.GetExtension(FileUpload1.PostedFile.FileName);

        switch (extension)
        {
        case ".xls":     //Excel 97-03
            conString = ConfigurationManager.ConnectionStrings["Excel03ConString"].ConnectionString;
            break;

        case ".xlsx":     //Excel 07 or higher
            conString = ConfigurationManager.ConnectionStrings["Excel07+ConString"].ConnectionString;
            break;
        }
        conString = string.Format(conString, excelPath);
        using (OleDbConnection excel_con = new OleDbConnection(conString))
        {
            excel_con.Open();
            string    sheet1      = excel_con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows[0]["TABLE_NAME"].ToString();
            DataTable dtExcelData = new DataTable();

            //[OPTIONAL]: It is recommended as otherwise the data will be considered as String by default.


            dtExcelData.Columns.AddRange(new DataColumn[19]
            {
                new DataColumn("N° Entrega", typeof(string)),
                new DataColumn("Clase", typeof(string)),
                new DataColumn("N° Traslado", typeof(string)),
                new DataColumn("Codigo", typeof(string)),
                new DataColumn("Descripcion", typeof(string)),
                new DataColumn("Destinatario", typeof(string)),
                new DataColumn("P/Compra", typeof(string)),
                new DataColumn("Centro", typeof(string)),
                new DataColumn("Almacén", typeof(string)),
                new DataColumn("Elemento PEP", typeof(string)),
                new DataColumn("Cantidad", typeof(float)),
                new DataColumn("U/M", typeof(string)),
                new DataColumn("Fecha salida", typeof(DateTime)),
                new DataColumn("G/Remision", typeof(string)),
                new DataColumn("Transporte", typeof(string)),
                new DataColumn("Placa", typeof(string)),
                new DataColumn("Chofer", typeof(string)),
                new DataColumn("Fecha Llegada", typeof(DateTime)),
                new DataColumn("Observaciones", typeof(string))
            });

            using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM [" + sheet1 + "]", excel_con))
            {
                oda.Fill(dtExcelData);
                int x = Convert.ToInt32(dtExcelData.Rows.Count);
            }
            excel_con.Close();


            string consString = ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString;
            using (SqlConnection con = new SqlConnection(consString))
            {
                using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(con))
                {
                    //Set the database table name
                    sqlBulkCopy.DestinationTableName = tabla;
                    try
                    {
                        //[OPTIONAL]: Map the Excel columns with that of the database table
                        sqlBulkCopy.ColumnMappings.Add("N° Entrega", "num_entrega");
                        sqlBulkCopy.ColumnMappings.Add("Clase", "cod_clase");
                        sqlBulkCopy.ColumnMappings.Add("N° Traslado", "num_traslado");
                        sqlBulkCopy.ColumnMappings.Add("Codigo", "cod_material");
                        sqlBulkCopy.ColumnMappings.Add("Descripcion", "gls_material");
                        sqlBulkCopy.ColumnMappings.Add("Destinatario", "cod_destino");
                        sqlBulkCopy.ColumnMappings.Add("P/Compra", "num_doc_compra");
                        sqlBulkCopy.ColumnMappings.Add("Centro", "cod_centro");
                        sqlBulkCopy.ColumnMappings.Add("Almacén", "cod_almacen");
                        sqlBulkCopy.ColumnMappings.Add("Elemento PEP", "cod_pep");
                        sqlBulkCopy.ColumnMappings.Add("Cantidad ", "num_cantidad");
                        sqlBulkCopy.ColumnMappings.Add("U/M", "cod_unidadUM");
                        sqlBulkCopy.ColumnMappings.Add("Fecha salida", "Fecha_salida");
                        sqlBulkCopy.ColumnMappings.Add("G/Remision", "G_Remision");
                        sqlBulkCopy.ColumnMappings.Add("Transporte", "gls_transporte");
                        sqlBulkCopy.ColumnMappings.Add("Placa", "gls_placa");
                        sqlBulkCopy.ColumnMappings.Add("Chofer", "gls_chofer");
                        sqlBulkCopy.ColumnMappings.Add("Fecha Llegada", "Fecha_Llegada");
                        sqlBulkCopy.ColumnMappings.Add("Observaciones", "gls_observacion");
                        con.Open();
                        sqlBulkCopy.WriteToServer(dtExcelData);
                        gvwAsignacion.DataSource = dtExcelData;
                        gvwAsignacion.DataBind();
                        con.Close();

                        img.Visible  = true;
                        img.ImageUrl = "~/imagenes/check.png";
                    }
                    catch (Exception ex)
                    {
                        img.Visible  = true;
                        img.ImageUrl = "~/imagenes/Error.png";
                        UC_MessageBox.Show(Page, Page.GetType(), "Error en archivo : " + ex.Message);
                        return;
                    }
                }
            }
        }
    }
    protected void Bulk_Insert_Vacios(FileUpload FileUpload1, string tabla, Image img)
    {
        string cleanMessage;

        try
        {
            string fileName         = Path.GetFileName(FileUpload1.PostedFile.FileName);
            string fileExtension    = Path.GetExtension(FileUpload1.PostedFile.FileName);
            string connectionString = string.Empty;

            string fullPath = Path.Combine(Server.MapPath("~/File/"), fileName);

            if (System.IO.File.Exists(fullPath))
            {
                File.Delete(fullPath);
            }
            FileUpload1.SaveAs(fullPath);

            if (fileExtension.ToUpper() == ".XLS")
            {
                connectionString = (Convert.ToString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=") + fullPath) + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"";
            }
            else if (fileExtension.ToUpper() == ".XLSX")
            {
                connectionString = (Convert.ToString("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=") + fullPath) + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
            }

            OleDbConnection con = new OleDbConnection(connectionString);
            OleDbCommand    cmd = new OleDbCommand();
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.Connection  = con;
            OleDbDataAdapter dAdapter       = new OleDbDataAdapter(cmd);
            DataTable        dtExcelRecords = new DataTable();
            con.Open();
            DataTable dtExcelSheetName  = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
            string    getExcelSheetName = dtExcelSheetName.Rows[0]["Table_Name"].ToString();
            cmd.CommandText        = (Convert.ToString("SELECT * FROM [") + getExcelSheetName) + "]";
            dAdapter.SelectCommand = cmd;
            dAdapter.Fill(dtExcelRecords);
            con.Close();



            string consString = ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString;
            using (SqlConnection conx = new SqlConnection(consString))
            {
                conx.Open();
                // Get a reference to a single row in the table.
                DataRow[] rowArray = dtExcelRecords.Select();

                using (SqlBulkCopy bulkCopy = new SqlBulkCopy(conx))
                {
                    bulkCopy.DestinationTableName = tabla;

                    try
                    {
                        // Write the array of rows to the destination.
                        bulkCopy.BulkCopyTimeout = 5000;
                        bulkCopy.BatchSize       = 50000;
                        bulkCopy.WriteToServer(rowArray);
                        img.Visible  = true;
                        img.ImageUrl = "~/imagenes/check.png";
                    }
                    catch (Exception ex)
                    {
                        img.Visible  = true;
                        img.ImageUrl = "~/imagenes/Error.png";
                        UC_MessageBox.Show(Page, Page.GetType(), "Error en archivo : " + ex.Message);
                        return;
                    }
                }
            }//using
        }
        catch (System.IO.IOException e)
        {
            img.Visible  = true;
            img.ImageUrl = "~/imagenes/Error.png";
            // hay borrar los datos
            BL_LOGISTICA obj         = new BL_LOGISTICA();
            DataTable    dtResultado = new DataTable();
            dtResultado = obj.Eliminar_Tabla_ReporteGeneral();

            cleanMessage = e.Message + " Intente cambiar la extension de los Archivos a .XLS(libro 97-2003)";
            ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + cleanMessage + "');", true);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        lblCorreo.Text = Request.QueryString["Usuario"];
        IDE_CARTA      = Request.QueryString["IDE_CARTA"];
        IDE_APROBACION = Request.QueryString["IDE_APROBACION"];
        Boolean correo = email_bien_escrito(lblCorreo.Text);

        if (correo == true)
        {
            BL_RRHH_COMPETENCIAS_EVAL obj = new BL_RRHH_COMPETENCIAS_EVAL();
            DataTable dtResultado         = new DataTable();
            dtResultado = obj.uspSEL_RRHH_PERSONAL_EMPRESA_POR_CORREO(lblCorreo.Text);
            if (dtResultado.Rows.Count > 0)
            {
                //Session["IDE_USUARIO"] =

                string     pMesajeResp = string.Empty;
                BE_Usuario oBE_Usuario = new BE_Usuario();
                oBE_Usuario.f_Usuario_E = dtResultado.Rows[0]["ID_DNI"].ToString();

                BE_Usuario objUsuario_R = new BE_Usuario();

                BL_Seguridad obj_Usuario = new BL_Seguridad();
                objUsuario_R = new BL_Seguridad().f_LogeoUsuarioExterno(oBE_Usuario, ref pMesajeResp);
                if (string.IsNullOrEmpty(objUsuario_R.f_Usuario_E))
                {
                    UC_MessageBox.Show(Page, this.GetType(), pMesajeResp);
                }
                else
                {
                    Session["IDE_USUARIO"]       = objUsuario_R.f_Usuario_E.ToString();
                    Session["IDE_CARTA_APROBAR"] = Request.QueryString["IDE_CARTA"];
                    Session["IDE_APROBACION"]    = Request.QueryString["IDE_APROBACION"];
                    //string url = objUsuario_R.f_UrlDefault_E;
                    //Response.Redirect(url);
                    Response.Redirect("~/OPERACIONES/CartaCobranzasAprobaciones.aspx");
                }
            }
            else
            {
                Response.Redirect("~/RRHH/Contacto.aspx");
            }
        }
        else
        {
            string     pMesajeResp = string.Empty;
            BE_Usuario oBE_Usuario = new BE_Usuario();
            oBE_Usuario.f_Usuario_E = lblCorreo.Text;

            BE_Usuario objUsuario_R = new BE_Usuario();

            BL_Seguridad obj_Usuario = new BL_Seguridad();
            objUsuario_R = new BL_Seguridad().f_LogeoUsuarioExterno(oBE_Usuario, ref pMesajeResp);
            if (string.IsNullOrEmpty(objUsuario_R.f_Usuario_E))
            {
                UC_MessageBox.Show(Page, this.GetType(), pMesajeResp);
            }
            else
            {
                Session["IDE_USUARIO"]       = objUsuario_R.f_Usuario_E.ToString();
                Session["IDE_CARTA_APROBAR"] = Request.QueryString["IDE_CARTA"];
                Session["IDE_APROBACION"]    = Request.QueryString["IDE_APROBACION"];
                Response.Redirect("~/OPERACIONES/CartaCobranzasAprobaciones.aspx");
            }
        }
    }
Пример #21
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //string hash = HashEmailForGravatar(email);

        lblCorreo.Text = Request.QueryString["correo"];
        IDE_FASE       = Request.QueryString["IDE_FASE"];
        IDE_FICHA      = Request.QueryString["IDE_FICHA"];
        IDE_EXAMEN     = Request.QueryString["IDE_EXAMEN"];
        Boolean correo = email_bien_escrito(lblCorreo.Text);

        if (correo == true)
        {
            BL_RRHH_COMPETENCIAS_EVAL obj = new BL_RRHH_COMPETENCIAS_EVAL();
            DataTable dtResultado         = new DataTable();
            dtResultado = obj.uspSEL_RRHH_PERSONAL_EMPRESA_POR_CORREO(lblCorreo.Text);
            if (dtResultado.Rows.Count > 0)
            {
                //Session["IDE_USUARIO"] =

                string     pMesajeResp = string.Empty;
                BE_Usuario oBE_Usuario = new BE_Usuario();
                oBE_Usuario.f_Usuario_E = dtResultado.Rows[0]["ID_DNI"].ToString();

                BE_Usuario objUsuario_R = new BE_Usuario();

                BL_Seguridad obj_Usuario = new BL_Seguridad();
                objUsuario_R = new BL_Seguridad().f_LogeoUsuarioExterno(oBE_Usuario, ref pMesajeResp);
                if (string.IsNullOrEmpty(objUsuario_R.f_Usuario_E))
                {
                    UC_MessageBox.Show(Page, this.GetType(), pMesajeResp);
                }
                else
                {
                    Session["IDE_USUARIO"] = objUsuario_R.f_Usuario_E.ToString();
                    Session["IDE_FASE"]    = IDE_FASE;
                    Session["IDE_FICHA"]   = IDE_FICHA;
                    Session["IDE_EXAMEN"]  = IDE_EXAMEN;

                    Response.Redirect("~/RRHH/FormativoExamen.aspx");
                }
            }
            else
            {
                Response.Redirect("~/RRHH/Contacto.aspx");
            }
        }
        else
        {
            string     pMesajeResp = string.Empty;
            BE_Usuario oBE_Usuario = new BE_Usuario();
            oBE_Usuario.f_Usuario_E = lblCorreo.Text;

            BE_Usuario objUsuario_R = new BE_Usuario();

            BL_Seguridad obj_Usuario = new BL_Seguridad();
            objUsuario_R = new BL_Seguridad().f_LogeoUsuarioExterno(oBE_Usuario, ref pMesajeResp);
            if (string.IsNullOrEmpty(objUsuario_R.f_Usuario_E))
            {
                UC_MessageBox.Show(Page, this.GetType(), pMesajeResp);
            }
            else
            {
                Session["IDE_EXAMEN"]  = IDE_EXAMEN;
                Session["IDE_USUARIO"] = objUsuario_R.f_Usuario_E.ToString();
                Session["IDE_FASE"]    = IDE_FASE;
                Session["IDE_FICHA"]   = IDE_FICHA;
                Response.Redirect("~/RRHH/FormativoExamen.aspx");
            }
        }
    }
    protected void btnProcesar_Click(object sender, EventArgs e)
    {
        //System.Threading.Thread.Sleep(5000);
        //LOGISTICA_ME5A
        try
        {
            if (FileUpload1.FileBytes.Length <= 0 && FileUpload2.FileBytes.Length <= 0 && FileUpload3.FileBytes.Length <= 0 && FileUpload4.FileBytes.Length <= 0 &&
                FileUpload5.FileBytes.Length <= 0 && FileUpload6.FileBytes.Length <= 0)
            {
            }
            else
            {
                BL_LOGISTICA obj         = new BL_LOGISTICA();
                DataTable    dtResultado = new DataTable();
                dtResultado = obj.Eliminar_Tabla_ReporteGeneral();

                string path          = Path.GetFileName(FileUpload1.PostedFile.FileName);
                string fileExtension = Path.GetExtension(path).ToLower();
                if (ValidaExtension(fileExtension))
                {
                    Bulk_Insert(FileUpload1, "dbo.LOGISTICA_ME5A", img1);
                }
                else
                {
                    UC_MessageBox.Show(Page, Page.GetType(), "Formato no permitido para ME5A");
                    return;
                }

                ////////////////    ME2N       ///////////////////
                string path2          = Path.GetFileName(FileUpload2.PostedFile.FileName);
                string fileExtension2 = Path.GetExtension(path2).ToLower();
                if (ValidaExtension(fileExtension2))
                {
                    Bulk_Insert(FileUpload2, "dbo.LOGISTICA_ME2N", img2);
                }
                else
                {
                    UC_MessageBox.Show(Page, Page.GetType(), "Formato no permitido para ME2N");
                    return;
                }

                ////////////////    ZMM033       ///////////////////
                string path3          = Path.GetFileName(FileUpload3.PostedFile.FileName);
                string fileExtension3 = Path.GetExtension(path3).ToLower();
                if (ValidaExtension(fileExtension3))
                {
                    Bulk_Insert(FileUpload3, "dbo.LOGISTICA_ZMM033", img3);
                }
                else
                {
                    UC_MessageBox.Show(Page, Page.GetType(), "Formato no permitido para ZMM033");
                    return;
                }

                ////////////////    ZMM033C       ///////////////////
                string path4          = Path.GetFileName(FileUpload4.PostedFile.FileName);
                string fileExtension4 = Path.GetExtension(path4).ToLower();
                if (ValidaExtension(fileExtension4))
                {
                    Bulk_Insert_Vacios(FileUpload4, "dbo.LOGISTICA_ZMM033", img4);
                    Bulk_Insert_Vacios(FileUpload4, "dbo.LOGISTICA_ZMM033C", img4);
                }
                else
                {
                    UC_MessageBox.Show(Page, Page.GetType(), "Formato no permitido para ZMM033 Concluidas");
                    return;
                }

                ////////////////    ME80FN       ///////////////////
                string path5          = Path.GetFileName(FileUpload5.PostedFile.FileName);
                string fileExtension5 = Path.GetExtension(path5).ToLower();
                if (ValidaExtension(fileExtension5))
                {
                    Bulk_Insert(FileUpload5, "dbo.LOGISTICA_ME80FN_REP", img5);
                }
                else
                {
                    UC_MessageBox.Show(Page, Page.GetType(), "Formato no permitido para ME80FN Repartos");
                    return;
                }


                ////////////////    ME80FN_HIS       ///////////////////
                string path6          = Path.GetFileName(FileUpload6.PostedFile.FileName);
                string fileExtension6 = Path.GetExtension(path6).ToLower();
                if (ValidaExtension(fileExtension6))
                {
                    Bulk_Insert(FileUpload6, "dbo.LOGISTICA_ME80FN_HIS", img6);
                }
                else
                {
                    UC_MessageBox.Show(Page, Page.GetType(), "Formato no permitido para ME80FN Historicos");
                    return;
                }

                ////////////////    SSK       ///////////////////
                //string path7 = Path.GetFileName(FileUpload7.PostedFile.FileName);
                //string fileExtension7 = Path.GetExtension(path7).ToLower();
                //if (ValidaExtension(fileExtension7))
                //{
                //    //Bulk_Insert
                //    Bulk_Insert(FileUpload7, "dbo.LOGISTICA_REG_ALMACEN", img7);
                //}
                //else
                //{
                //    UC_MessageBox.Show(Page, Page.GetType(), "Formato no permitido para Almacen SSK");
                //    return;

                //}

                //exportarXLS_Plantilla();
                exportarXLS();
            }
        }

        catch (Exception ex)
        {
            // hay borrar los datos
            BL_LOGISTICA obj         = new BL_LOGISTICA();
            DataTable    dtResultado = new DataTable();
            dtResultado = obj.Eliminar_Tabla_ReporteGeneral();

            string cleanMessage = ex.Message + " Intente cambiar la extension de los Archivo Almacen a .XLS(libro 97-2003)";;
            ScriptManager.RegisterStartupScript(this, typeof(Page), "invocarfuncion", "doAlert('" + cleanMessage + "');", true);
        }
    }
    protected void exportarXLS_Plantilla()
    {
        BL_LOGISTICA obj        = new BL_LOGISTICA();
        DataTable    dtbReporte = new DataTable();
        string       empresa    = RdoEmpresa.SelectedValue;

        dtbReporte = obj.ListarProcesao_ReporteGlobal(empresa);

        int Col; int Fil;

        try
        {
            Excel.Application excelApp = new Excel.Application();



            string workbookPath = Server.MapPath("~/Plantilla/ReporteGlobal.xltx");

            Excel.Workbook excelWorkbook = null;

            try
            {
                excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0,
                                                        false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true,
                                                        false, 0, true, false, false);
            }
            catch
            {
                excelWorkbook = excelApp.Workbooks.Add();
            }


            Excel.Sheets excelSheets = excelWorkbook.Worksheets;

            string          currentSheet   = "Reporte General";
            Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet);

            // The following gets cell A1 for editing
            //Excel.Range excelCell = (Excel.Range)excelWorksheet;

            if (dtbReporte.Rows.Count > 0)
            {
                Col = 1;
                Fil = 2;

                foreach (DataRow objRow in dtbReporte.Rows)
                {
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col]).Value      = objRow[0];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 1]).Value  = objRow[1];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 2]).Value  = objRow[2];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 3]).Value  = objRow[3];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 4]).Value  = objRow[4];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 5]).Value  = objRow[5];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 6]).Value  = objRow[6];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 7]).Value  = objRow[7];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 8]).Value  = objRow[8];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 9]).Value  = objRow[9];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 10]).Value = objRow[10];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 11]).Value = objRow[11];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 12]).Value = objRow[12];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 13]).Value = objRow[13];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 14]).Value = objRow[14];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 15]).Value = objRow[15];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 16]).Value = objRow[16];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 17]).Value = objRow[17];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 18]).Value = objRow[18];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 19]).Value = objRow[19];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 20]).Value = objRow[20];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 21]).Value = objRow[21];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 22]).Value = objRow[22];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 23]).Value = objRow[23];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 24]).Value = objRow[24];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 25]).Value = objRow[25];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 26]).Value = objRow[26];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 27]).Value = objRow[27];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 28]).Value = objRow[28];
                    ((Excel.Range)excelWorksheet.Cells[Fil, Col + 29]).Value = objRow[29];

                    //.Cells[Fil, Col + 30] = objRow.Item[30)
                    //.Cells[Fil, Col + 31] = objRow.Item[31)



                    Fil = Fil + 1;
                }

                excelApp.Visible = true;
                return;
            }
            else
            {
                UC_MessageBox.Show(Page, this.GetType(), "Error al realizar calculo en Reporte Global.");
                return;
            }
            //exportarXLS(dtbReporte);
        }
        catch (Exception ex)
        {
            UC_MessageBox.Show(Page, this.GetType(), ex.Message);
            return;
        }
        finally
        {
        }
    }
Пример #24
0
    protected void Bulk_Insert_AlmacenSAP(FileUpload FileUpload1, string tabla, Image img)
    {
        string excelPath = Server.MapPath("~/File/") + Path.GetFileName(FileUpload1.PostedFile.FileName);

        FileUpload1.SaveAs(excelPath);

        string conString = string.Empty;
        string extension = Path.GetExtension(FileUpload1.PostedFile.FileName);

        switch (extension)
        {
        case ".xls":     //Excel 97-03
            conString = ConfigurationManager.ConnectionStrings["Excel03ConString"].ConnectionString;
            break;

        case ".xlsx":     //Excel 07 or higher
            conString = ConfigurationManager.ConnectionStrings["Excel07+ConString"].ConnectionString;
            break;
        }
        conString = string.Format(conString, excelPath);
        using (OleDbConnection excel_con = new OleDbConnection(conString))
        {
            excel_con.Open();
            string    sheet1      = excel_con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null).Rows[0]["TABLE_NAME"].ToString();
            DataTable dtExcelData = new DataTable();

            //[OPTIONAL]: It is recommended as otherwise the data will be considered as String by default.


            dtExcelData.Columns.AddRange(new DataColumn[13]
            {
                new DataColumn("Entrega", typeof(string)),
                new DataColumn("Clase de entrega", typeof(string)),
                new DataColumn("Documento modelo", typeof(string)),
                new DataColumn("Material", typeof(string)),
                new DataColumn("Denominación", typeof(string)),
                new DataColumn("Destinatario mcía.", typeof(string)),
                new DataColumn("Nombre destinatario de mercancías", typeof(string)),
                new DataColumn("Centro", typeof(string)),
                new DataColumn("Almacén", typeof(string)),
                new DataColumn("Nº stock especial", typeof(string)),
                new DataColumn("Cantidad entrega", typeof(float)),
                new DataColumn("Un.medida venta", typeof(string)),
                new DataColumn("Fecha salida mcías.", typeof(DateTime))
            });

            using (OleDbDataAdapter oda = new OleDbDataAdapter("SELECT * FROM [" + sheet1 + "]", excel_con))
            {
                oda.Fill(dtExcelData);
                int x = Convert.ToInt32(dtExcelData.Rows.Count);
            }
            excel_con.Close();


            string consString = ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString;
            using (SqlConnection con = new SqlConnection(consString))
            {
                using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(con))
                {
                    //Set the database table name
                    sqlBulkCopy.DestinationTableName = tabla;
                    try
                    {
                        //[OPTIONAL]: Map the Excel columns with that of the database table
                        sqlBulkCopy.ColumnMappings.Add("Entrega", "num_entrega");
                        sqlBulkCopy.ColumnMappings.Add("Clase de entrega", "cod_clase");
                        sqlBulkCopy.ColumnMappings.Add("Documento modelo", "num_traslado");
                        sqlBulkCopy.ColumnMappings.Add("Material", "cod_material");
                        sqlBulkCopy.ColumnMappings.Add("Denominación", "gls_material");
                        sqlBulkCopy.ColumnMappings.Add("Destinatario mcía.", "cod_destino");
                        sqlBulkCopy.ColumnMappings.Add("Nombre destinatario de mercancías", "num_doc_compra");
                        sqlBulkCopy.ColumnMappings.Add("Centro", "cod_centro");
                        sqlBulkCopy.ColumnMappings.Add("Almacén", "cod_almacen");
                        sqlBulkCopy.ColumnMappings.Add("Nº stock especial", "cod_pep");
                        sqlBulkCopy.ColumnMappings.Add("Cantidad entrega ", "num_cantidad");
                        sqlBulkCopy.ColumnMappings.Add("Un.medida venta", "cod_unidadUM");
                        sqlBulkCopy.ColumnMappings.Add("Fecha salida mcías.", "Fecha_salida");
                        con.Open();
                        sqlBulkCopy.WriteToServer(dtExcelData);
                        //gvwAsignacion.DataSource = dtExcelData;
                        //gvwAsignacion.DataBind();
                        con.Close();

                        img.Visible  = true;
                        img.ImageUrl = "~/imagenes/check.png";
                        BL_LOGISTICA obj = new BL_LOGISTICA();
                        DataTable    dtb = new DataTable();
                        dtb = obj.ProcesarRegistros_Almacen(RdoEmpresa.SelectedValue);
                    }
                    catch (Exception ex)
                    {
                        img.Visible  = true;
                        img.ImageUrl = "~/imagenes/Error.png";
                        EliminarTMP();
                        UC_MessageBox.Show(Page, Page.GetType(), "Error en archivo : " + ex.Message);
                        return;
                    }
                }
            }
        }
    }
Пример #25
0
    protected void Bulk_Insert(FileUpload FileUpload1, string tabla, Image img)
    {
        string fileName         = Path.GetFileName(FileUpload1.PostedFile.FileName);
        string fileExtension    = Path.GetExtension(FileUpload1.PostedFile.FileName);
        string connectionString = string.Empty;

        string fullPath = Path.Combine(Server.MapPath("~/File/"), fileName);

        if (System.IO.File.Exists(fullPath))
        {
            File.Delete(fullPath);
        }
        FileUpload1.SaveAs(fullPath);

        if (fileExtension.ToUpper() == ".XLS")
        {
            connectionString = (Convert.ToString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=") + fullPath) + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"";
        }
        else if (fileExtension.ToUpper() == ".XLSX")
        {
            connectionString = (Convert.ToString("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=") + fullPath) + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
        }

        OleDbConnection con = new OleDbConnection(connectionString);
        OleDbCommand    cmd = new OleDbCommand();

        cmd.CommandType = System.Data.CommandType.Text;
        cmd.Connection  = con;
        OleDbDataAdapter dAdapter       = new OleDbDataAdapter(cmd);
        DataTable        dtExcelRecords = new DataTable();

        con.Open();
        DataTable dtExcelSheetName  = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
        string    getExcelSheetName = dtExcelSheetName.Rows[0]["Table_Name"].ToString();

        cmd.CommandText        = (Convert.ToString("SELECT * FROM [") + getExcelSheetName) + "]";
        dAdapter.SelectCommand = cmd;
        dAdapter.Fill(dtExcelRecords);
        con.Close();


        if (dtExcelRecords.Rows.Count > 0)
        {
            int cantidad = Convert.ToInt32(dtExcelRecords.Columns.Count);

            if (cantidad == 13)
            {
                Bulk_Insert_AlmacenSAP(FileUpload1, "dbo.TMP_LOGISTICA_REG_ALMACEN", img1);
            }
            else
            {
                string consString = ConfigurationManager.ConnectionStrings["Conexion"].ConnectionString;
                using (SqlConnection conx = new SqlConnection(consString))
                {
                    conx.Open();
                    // Get a reference to a single row in the table.
                    DataRow[] rowArray = dtExcelRecords.Select();

                    using (SqlBulkCopy bulkCopy = new SqlBulkCopy(conx))
                    {
                        bulkCopy.DestinationTableName = tabla;

                        try
                        {
                            // Write the array of rows to the destination.
                            bulkCopy.BulkCopyTimeout = 5000;
                            bulkCopy.BatchSize       = 50000;
                            bulkCopy.WriteToServer(rowArray);
                            img.Visible  = true;
                            img.ImageUrl = "~/imagenes/check.png";
                            BL_LOGISTICA obj = new BL_LOGISTICA();
                            DataTable    dtb = new DataTable();
                            dtb = obj.ProcesarRegistros_Almacen("");
                        }
                        catch (Exception ex)
                        {
                            img.Visible  = true;
                            img.ImageUrl = "~/imagenes/Error.png";
                            EliminarTMP();
                            UC_MessageBox.Show(Page, Page.GetType(), "Error en archivo : " + ex.Message);
                            return;
                        }
                    }
                }
            }
            rpt_Cuadro();
        }
        else
        {
            img.Visible  = true;
            img.ImageUrl = "~/imagenes/Error.png";
            EliminarTMP();
            //// hay borrar los datos
            //BL_LOGISTICA obj = new BL_LOGISTICA();
            //obj.Eliminar_CargaIndicadoresRendimiento();
        }
    }