Exemplo n.º 1
0
        public static void FileUploadComplete(object sender, DevExpress.Web.FileUploadCompleteEventArgs e)
        {
            #region Variables
            ct_anio_fiscal_List        ListaAnioFiscal = new ct_anio_fiscal_List();
            ct_plancta_List            ListaPlancta    = new ct_plancta_List();
            List <ct_plancta_Info>     ListaPlan       = new List <ct_plancta_Info>();
            List <ct_anio_fiscal_Info> ListaAnio       = new List <ct_anio_fiscal_Info>();

            int     cont = 0;
            decimal IdTransaccionSession = Convert.ToDecimal(SessionFixed.IdTransaccionSessionActual);
            int     IdEmpresa            = Convert.ToInt32(SessionFixed.IdEmpresa);
            #endregion


            Stream stream = new MemoryStream(e.UploadedFile.FileBytes);
            if (stream.Length > 0)
            {
                IExcelDataReader reader = null;
                reader = ExcelReaderFactory.CreateOpenXmlReader(stream);

                #region Plan de cuentas
                while (reader.Read())
                {
                    if (!reader.IsDBNull(0) && cont > 0)
                    {
                        //var IdCtaCble = Convert.ToString(reader.GetValue(0));
                        //var pc_clave_corta = reader.GetValue(1) == null || string.IsNullOrEmpty(reader.GetString(1)) ? "" : reader.GetString(1);
                        //var pc_Cuenta = reader.GetString(2);
                        //var IdCtaCIdCtaCblePadreble = reader.GetValue(3) == null || string.IsNullOrEmpty(Convert.ToString(reader.GetValue(3))) ? null : Convert.ToString(reader.GetValue(3));
                        //var pc_Naturaleza = Convert.ToString(reader.GetValue(4));
                        //var IdNivelCta = Convert.ToInt32(reader.GetValue(5));
                        //var pc_EsMovimiento_bool = Convert.ToString(reader.GetValue(6)) == "SI" ? true : false;
                        //var pc_EsMovimiento = Convert.ToString(reader.GetValue(6)) == "SI" ? "S" : "N";
                        //var IdGrupoCble = Convert.ToString(reader.GetValue(7));

                        ct_plancta_Info info = new ct_plancta_Info
                        {
                            IdEmpresa            = IdEmpresa,
                            IdCtaCble            = Convert.ToString(reader.GetValue(0)),
                            pc_clave_corta       = reader.GetValue(1) == null || string.IsNullOrEmpty(reader.GetString(1)) ? "" : reader.GetString(1),
                            pc_Cuenta            = reader.GetString(2),
                            IdCtaCblePadre       = reader.GetValue(3) == null || string.IsNullOrEmpty(Convert.ToString(reader.GetValue(3))) ? null : Convert.ToString(reader.GetValue(3)),
                            pc_Naturaleza        = Convert.ToString(reader.GetValue(4)),
                            IdNivelCta           = Convert.ToInt32(reader.GetValue(5)),
                            pc_EsMovimiento_bool = Convert.ToString(reader.GetValue(6)) == "SI" ? true : false,
                            pc_EsMovimiento      = Convert.ToString(reader.GetValue(6)) == "SI" ? "S" : "N",
                            IdGrupoCble          = Convert.ToString(reader.GetValue(7))
                        };
                        ListaPlan.Add(info);
                    }
                    else
                    {
                        cont++;
                    }
                }
                #endregion

                cont = 0;
                //Para avanzar a la siguiente hoja de excel
                reader.NextResult();

                #region Cuentas contables por anio
                while (reader.Read())
                {
                    if (!reader.IsDBNull(0) && cont > 0)
                    {
                        int    Anio              = Convert.ToInt32(reader.GetValue(0));
                        string IdCtaCble         = reader.GetValue(1).ToString();
                        ct_anio_fiscal_Info info = new ct_anio_fiscal_Info
                        {
                            IdanioFiscal      = Anio,
                            af_fechaIni       = new DateTime(Anio, 1, 1),
                            af_fechaFin       = new DateTime(Anio, 12, 31),
                            info_anio_ctautil = new ct_anio_fiscal_x_cuenta_utilidad_Info
                            {
                                IdEmpresa    = IdEmpresa,
                                IdCtaCble    = IdCtaCble,
                                IdanioFiscal = Anio,
                            },
                        };
                        ListaAnio.Add(info);
                    }
                    else
                    {
                        cont++;
                    }
                }
                #endregion

                ListaPlancta.set_list(ListaPlan, IdTransaccionSession);
                ListaAnioFiscal.set_list(ListaAnio, IdTransaccionSession);
            }
        }