Пример #1
0
        protected void btnImportar_Click(object sender, EventArgs e)
        {
            try
            {
                string path = Server.MapPath("~/App_Data/RadUploadTemp") + "\\" + NombreArchivo;

                if (NombreArchivo != null)
                {
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    foreach (UploadedFile f in RadUpload1.UploadedFiles)
                    {
                        f.SaveAs(path, true);
                    }

                    OleDbConnection con = default(OleDbConnection);

                    string strConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0 xml;HDR=YES;IMEX=1;\"";
                    con = new OleDbConnection(strConn);
                    con.Open();
                    DataTable        dt   = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                    string           hoja = dt.Rows[0].ItemArray[2].ToString().Replace("'", "");
                    OleDbCommand     cmd  = new OleDbCommand("select * from [" + hoja + "]", con);
                    OleDbDataAdapter dad  = new OleDbDataAdapter();
                    dad.SelectCommand = cmd;
                    DataSet ds = new DataSet();
                    try
                    {
                        dad.Fill(ds);
                    }
                    catch (Exception ex)
                    {
                        Alerta(ex.Message);
                    }
                    con.Close();


                    Sesion Sesion = new Sesion();
                    Sesion = (Sesion)Session["Sesion" + Session.SessionID];

                    int    Id_Emp = 0;
                    int?   Id_Cd  = 0;
                    int?   Id_Rik = 0;
                    int?   Id_Cte = 0;
                    int    estatus_rentabilidad = 0;
                    double rentabilidad         = 0;
                    int    SeCargaron           = 0;
                    int    NoSeCargaron         = 0;

                    dtDet.Clear();

                    int x = 0;

                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        Id_Emp = 0;
                        Id_Cd  = 0;
                        Id_Rik = null;
                        Id_Cte = null;
                        estatus_rentabilidad = 0;
                        rentabilidad         = 0.0;

                        if (!Convert.IsDBNull(row[0]))
                        {
                            //INICIA CONVERSION
                            Id_Emp = Convert.ToInt32(row[0]);
                            Id_Cd  = Convert.ToInt32(row[1]);
                            Id_Rik = Convert.ToInt32(row[2]);
                            Id_Cte = Convert.ToInt32(row[3]);
                            estatus_rentabilidad = Convert.ToInt32(row[4]);
                            rentabilidad         = Convert.ToDouble(row[5]);

                            #region validar

                            //if (Convert.ToString(row[1]) == "1")
                            //{



                            if (estatus_rentabilidad != 0 && estatus_rentabilidad != 1)
                            {
                                Alerta("Movimiento se encuentra en estatus no valido  " + Id_Cd.ToString() + " " + Convert.ToString(row[3]) + " " + Convert.ToString(row[4]));
                                return;
                            }


                            ////if (Math.Round(Convert.ToDouble(Doc_Importe) - Convert.ToDouble(Doc_Pagado), 2) <= 0)
                            ////{
                            ////    Alerta("Movimiento no tiene saldo positivo; imposible aplicarle un pago " + MovStr + " " + Convert.ToString(row[2]) + " " + Convert.ToString(row[3]));
                            ////    return;
                            ////}


                            #endregion validar
                            x++;
                            dtDet.Rows.Add(
                                x,
                                Id_Emp,
                                Id_Cd,
                                Id_Rik,
                                Id_Cte,
                                estatus_rentabilidad,
                                rentabilidad
                                );
                            SeCargaron++;
                        }
                    }
                    RgDet.Rebind();
                    ///AQUI
                    RgDet.DataSource = null;
                    RgDet.Rebind();
                    RgDet.DataSource = dtDet;
                    RgDet.Rebind();
                    if (NoSeCargaron > 0)
                    {
                        Alerta("Se Importaron Registros : " + SeCargaron.ToString() + "<BR></BR>" + "Registros no encontrados : " + NoSeCargaron.ToString());
                    }
                    else
                    {
                        Alerta("Se Importaron Registros : " + SeCargaron.ToString());
                    }

                    ////txtTotal.Text = Total.ToString();
                }
                else
                {
                    Alerta("Seleccione la plantilla a cargar. ");
                }
            }

            catch (Exception ex)
            {
                Alerta(ex.Message.Replace("'", ""));
            }
        }
Пример #2
0
        protected void btnImportar_Click(object sender, EventArgs e)
        {
            try
            {
                string path = Server.MapPath("~/App_Data/RadUploadTemp") + "\\" + NombreArchivo;

                if (NombreArchivo != null)
                {
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    foreach (UploadedFile f in RadUpload1.UploadedFiles)
                    {
                        f.SaveAs(path, true);
                    }

                    OleDbConnection con = default(OleDbConnection);

                    string strConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=\"Excel 12.0 xml;HDR=YES;IMEX=1;\"";
                    con = new OleDbConnection(strConn);
                    con.Open();
                    DataTable        dt   = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
                    string           hoja = dt.Rows[0].ItemArray[2].ToString().Replace("'", "");
                    OleDbCommand     cmd  = new OleDbCommand("select * from [" + hoja + "]", con);
                    OleDbDataAdapter dad  = new OleDbDataAdapter();
                    dad.SelectCommand = cmd;
                    DataSet ds = new DataSet();
                    try
                    {
                        dad.Fill(ds);
                    }
                    catch (Exception ex)
                    {
                        Alerta(ex.Message);
                    }
                    con.Close();


                    Sesion Sesion = new Sesion();
                    Sesion = (Sesion)Session["Sesion" + Session.SessionID];

                    string EMPRESA        = "";
                    string Nomina         = "";
                    string NOMBRE         = "";
                    string PUESTO         = "";
                    Double?Sueldo         = 0;
                    Double CuentadeGastos = 0;
                    Double Despensa       = 0;
                    Double Gasolina       = 0;
                    Double TOTAL          = 0;
                    int    SeCargaron     = 0;
                    int    NoSeCargaron   = 0;

                    dtDet.Clear();

                    int x = 0;



                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        EMPRESA        = "";
                        Nomina         = "";
                        NOMBRE         = "";
                        PUESTO         = "";
                        Sueldo         = 0;
                        CuentadeGastos = 0;
                        Despensa       = 0;
                        Gasolina       = 0;
                        TOTAL          = 0;



                        //INICIA CONVERSION
                        EMPRESA        = Convert.ToString(row[0]);
                        Nomina         = Convert.ToString(row[1]);
                        NOMBRE         = Convert.ToString(row[2]);
                        PUESTO         = Convert.ToString(row[3]);
                        Sueldo         = Convert.ToDouble(row[4]);
                        CuentadeGastos = Convert.ToDouble(row[5]);
                        Despensa       = Convert.ToDouble(row[6]);

                        Gasolina = Convert.ToDouble(row[7]);

                        TOTAL = Convert.ToDouble(row[8]);



                        #region validar

                        //if (Convert.ToString(row[1]) == "1")
                        //{
                        int id_empresa = 0;

                        if (EMPRESA == "KEY")
                        {
                            id_empresa = 1;
                        }
                        else
                        {
                            id_empresa = 2;
                        }



                        ////if (Doc_Estatus == "B")
                        ////{
                        ////    Alerta("Movimiento se encuentra cancelado; imposible aplicarle un pago " + MovStr + " " + Convert.ToString(row[2]) + " " + Convert.ToString(row[3]));
                        ////    return;
                        ////}
                        ////else if (Doc_Estatus == "C")
                        ////{
                        ////    Alerta("Movimiento se encuentra en status capturado; imposible aplicarle un pago " + MovStr + " " + Convert.ToString(row[2]) + " " + Convert.ToString(row[3]));
                        ////    return;
                        ////}

                        ////if (Math.Round(Convert.ToDouble(Doc_Importe) - Convert.ToDouble(Doc_Pagado), 2) <= 0)
                        ////{
                        ////    Alerta("Movimiento no tiene saldo positivo; imposible aplicarle un pago " + MovStr + " " + Convert.ToString(row[2]) + " " + Convert.ToString(row[3]));
                        ////    return;
                        ////}


                        #endregion validar


                        Colaborador colaborador = ConsultarColaboradorEmpleado(Convert.ToInt32(Nomina), id_empresa);
                        if (colaborador.Id_Empleado != 0)
                        {
                            //jfcv el sueldo no lo multiplico por el 30.4
                            //Sueldo = colaborador.Sueldo_Variable * 30.4;
                            Sueldo = colaborador.Sueldo_Variable;
                            ///que busque el numero de nomina y vea si coincide el nombre con el de la bd
                            ///que busqeu el puesto y mande warnings
                            ///
                            x++;
                            dtDet.Rows.Add(
                                x,
                                EMPRESA,
                                Nomina,
                                NOMBRE,
                                PUESTO,
                                Sueldo,
                                CuentadeGastos,
                                Despensa,
                                Gasolina,
                                TOTAL
                                );


                            SeCargaron++;
                        }
                        else
                        {
                            NoSeCargaron++;
                        }
                    }
                    RgDet.Rebind();
                    ///AQUI
                    RgDet.DataSource = null;
                    RgDet.Rebind();
                    RgDet.DataSource = dtDet;
                    RgDet.Rebind();
                    if (NoSeCargaron > 0)
                    {
                        Alerta("Se Importaron Registros : " + SeCargaron.ToString() + "<BR></BR>" + "Empleados no encontrados : " + NoSeCargaron.ToString());
                    }
                    else
                    {
                        Alerta("Se Importaron Registros : " + SeCargaron.ToString());
                    }

                    ////txtTotal.Text = Total.ToString();
                }
                else
                {
                    Alerta("Seleccione la plantilla a cargar. ");
                }
            }

            catch (Exception ex)
            {
                Alerta(ex.Message.Replace("'", ""));
            }
        }