//public bool Export(Guid id, PriceImportLogStatus pilStatus, string path)
        //{
        //    DeleteExportFile(path);
        //    PriceImport pi = GetById(id);

        //    // TODO: Convert to MemoryStream.
        //    // TODO: Move hardcoded to translation file
        //    List<int> lst = GetIndexsForExport(id, pilStatus);

        //    DelimitedClassBuilder cb = CreateClassBuilder(pi.SeparationChar, pi.HaveHeader);
        //    FileHelperEngine engine = new FileHelperEngine(cb.CreateRecordClass());
        //    object[] items = engine.ReadFile(path + pi.ID + ".csv");
        //    object[] erroritems = new object[lst.Count];
        //    int i = 0;
        //    foreach (int error in lst)
        //    {
        //        erroritems[i] = items[error];
        //        i++;
        //    }
        //    engine.WriteFile(path + Resource.Business.GetString("ExportFile"), erroritems);


        //    return true;
        //}

        public MemoryStream Export(Guid id, PriceImportLogStatus pilStatus, string path)
        {
            PriceImport pi = GetById(id);

            List <int> lst = GetIndexsForExport(id, pilStatus);

            DelimitedClassBuilder cb     = CreateClassBuilder(pi.SeparationChar, pi.HaveHeader);
            FileHelperEngine      engine = new FileHelperEngine(cb.CreateRecordClass());

            object[] items      = engine.ReadFile(path + pi.ID + ".csv");
            object[] erroritems = new object[lst.Count];
            int      i          = 0;

            foreach (int error in lst)
            {
                erroritems[i] = items[error];
                i++;
            }

            MemoryStream stream = new MemoryStream();
            StreamWriter sw     = new StreamWriter(stream);

            engine.WriteStream(sw, erroritems);

            return(stream);
        }
        public IList <PriceImportLogView> GetList(Guid id, PriceImportLogStatus piLogStatus, int pageSize, int pageNumber, out int totalcount)
        {
            string hql = "SELECT COUNT(PI.Description) FROM PriceImport PI JOIN PI.LogResults PIL WHERE PI.ID = :Id AND PIL.Status = :Status";

            IQuery qcount = NHibernateSession.CreateQuery(hql).SetGuid("Id", id).SetEnum("Status", piLogStatus);

            totalcount = Convert.ToInt32(qcount.UniqueResult());

            hql = "SELECT PIL FROM PriceImport PI JOIN PI.LogResults PIL WHERE PI.ID = :Id AND PIL.Status = :Status";

            IQuery q = NHibernateSession.CreateQuery(hql);

            q.SetGuid("Id", id);
            q.SetEnum("Status", piLogStatus);

            if (pageNumber != 0 && pageSize != 0)
            {
                q.SetFirstResult((pageNumber * pageSize) - pageSize);
                q.SetMaxResults(pageSize);
            }

            q.SetResultTransformer(new NHibernate.Transform.AliasToBeanConstructorResultTransformer(typeof(PriceImportLogView).GetConstructors()[1]));

            IList <PriceImportLogView> pil = q.List <PriceImportLogView>();

            if (pil.Count > 0)
            {
                return(pil);
            }

            return(new List <PriceImportLogView>());
        }
        public List <int> GetIndexsForExport(Guid id, PriceImportLogStatus piLogStatus)
        {
            string hql = "SELECT PIL.FileIndex FROM PriceImport PI JOIN PI.LogResults PIL WHERE PI.ID = :Id AND PIL.Status = :Status";

            IQuery q = NHibernateSession.CreateQuery(hql);

            q.SetGuid("Id", id);
            q.SetEnum("Status", piLogStatus);

            List <int> pil = q.List <int>() as List <int>;

            if (pil.Count > 0)
            {
                return(pil);
            }

            return(new List <int>());
        }