Exemplo n.º 1
0
        protected void BuildReport(string file = null, Type reportType = null, bool checkEmptyData = false)
        {
            if (reportType != null && report == null)
            {
                report = (BaseReport)Activator.CreateInstance(reportType, Conn, properties);
            }
            report.ReportCaption = report.ReportCaption ?? "test report";

            if (file == null)
            {
                file = "test.xls";
            }
            _fileName = file;
            if (File.Exists(file))
            {
                File.Delete(file);
            }
            ProfileHelper.Start();
            report.CheckEmptyData = checkEmptyData;
            ArHelper.WithSession(s => {
                report.Session = s;
                report.Write(Path.GetFullPath(file));
            });
            ProfileHelper.Stop();
        }
Exemplo n.º 2
0
        public List <T> Find <T>()
        {
            var criteria = DetachedCriteria.For <T>()
                           .CreateAlias("HomeRegion", "hr");

            if (!String.IsNullOrEmpty(SearchText))
            {
                criteria.Add(Expression.Like("Name", SearchText, MatchMode.Anywhere));
            }

            DetachedCriteria countSubquery = NHibernate.CriteriaTransformer.TransformToRowCount(criteria);

            _lastRowsCount = ArHelper.WithSession <int>(
                s => countSubquery.GetExecutableCriteria(s).UniqueResult <int>());

            criteria.AddOrder(Order.Asc("Name"));
            criteria.AddOrder(Order.Asc("hr.Name"));

            if (CurrentPage > 0)
            {
                criteria.SetFirstResult(CurrentPage * PageSize);
            }

            criteria.SetMaxResults(PageSize);

            var list = ArHelper.WithSession(
                s => criteria.GetExecutableCriteria(s).List <T>())
                       .ToList();

            return(list);
        }
Exemplo n.º 3
0
        public List <T> Find <T>()
        {
            var criteria = DetachedCriteria.For <T>()
                           .CreateAlias("PromotionOwnerSupplier", "s", JoinType.InnerJoin);

            if (PromotionStatus == Controllers.PromotionStatus.Enabled)
            {
                criteria.Add(Expression.Eq("Status", true));
            }
            else if (PromotionStatus == Controllers.PromotionStatus.Disabled)
            {
                criteria.Add(Expression.Eq("Status", false));
            }

            criteria.Add(Expression.Or(Expression.Eq("Moderated", true), Expression.And(Expression.IsNotNull("Moderator"), Expression.Eq("Moderated", false))));

            if (!String.IsNullOrEmpty(SearchSupplier))
            {
                criteria.Add(Expression.Like("s.Name", SearchSupplier, MatchMode.Anywhere));
            }

            if (!String.IsNullOrEmpty(SearchText))
            {
                criteria.Add(Expression.Like("Name", SearchText, MatchMode.Anywhere));
            }

            ApplySort(criteria);

            return(ArHelper.WithSession(s => criteria
                                        .GetExecutableCriteria(s).List <T>())
                   .ToList()
                   .GroupBy(i => ((dynamic)i).Id)
                   .Select(g => g.First())
                   .ToList());
        }
Exemplo n.º 4
0
        public bool Perform(ExecuteWhen exec,
                            IEngineContext context,
                            IController controller,
                            IControllerContext controllerContext)
        {
            ArHelper.WithSession(s => {
                var regionMask = SecurityContext.Administrator.RegionMask;
                s.EnableFilter("RegionFilter").SetParameter("AdminRegionMask", regionMask);

                if (SecurityContext.Administrator.HavePermisions(PermissionType.ViewDrugstore) &&
                    SecurityContext.Administrator.HavePermisions(PermissionType.ViewSuppliers))
                {
                    return;
                }

                if (SecurityContext.Administrator.HavePermisions(PermissionType.ViewDrugstore))
                {
                    s.EnableFilter("DrugstoreOnlyFilter");
                }

                if (SecurityContext.Administrator.HavePermisions(PermissionType.ViewSuppliers))
                {
                    s.EnableFilter("SupplierOnlyFilter");
                }
            });
            return(true);
        }
Exemplo n.º 5
0
        public IList <MailSendLog> Find()
        {
            return(ArHelper.WithSession(s => {
                var query = s.QueryOver <MailSendLog>();
                query.JoinQueryOver(m => m.Update, JoinType.LeftOuterJoin);
                var mailJoin = query.JoinQueryOver(l => l.Mail, JoinType.InnerJoin);
                var user = query.JoinQueryOver(l => l.User, JoinType.InnerJoin);
                query.JoinQueryOver(l => l.Recipient, JoinType.InnerJoin);
                mailJoin.JoinQueryOver(m => m.Attachments, JoinType.LeftOuterJoin);

                if (Client != null)
                {
                    user.Where(u => u.Client == Client);
                }

                if (User != null)
                {
                    query.Where(l => l.User == User);
                }

                if (Supplier != null)
                {
                    mailJoin.Where(m => m.Supplier == Supplier);
                }

                var dummy = mailJoin
                            .Where(m => m.LogTime >= Period.Begin && m.LogTime < Period.End.AddDays(1))
                            .OrderBy(m => m.LogTime).Desc;
                query.TransformUsing(Transformers.DistinctRootEntity);
                return query.List();
            }));
        }
Exemplo n.º 6
0
        public void BaseTest()
        {
            var client = new Client();
            IList <BaseItemForTable> result = new List <BaseItemForTable>();

            using (new SessionScope()) {
                ArHelper.WithSession(s => {
                    client = new DataMother(s).CreateClientAndUsers();

                    var filter       = new AnalysisOfWorkDrugstoresFilter(1000);
                    filter.Session   = s;
                    filter.Regions   = new ulong[] { client.HomeRegion.Id };
                    filter.AutoOrder = (int)AutoOrderStatus.NotUsed;
                    result           = filter.Find();

                    var appHelper = new AppHelper(context);
                    PrepareHelper(appHelper);

                    foreach (var baseItemForTable in result)
                    {
                        baseItemForTable.SetHelpers(appHelper);
                    }
                    Assert.That(result.Count, Is.GreaterThan(0));

                    var clientIds = result.Select(r => ((AnalysisOfWorkFiled)r).Id).ToList();
                    var Id        = client.Id.ToString();
                    Assert.IsTrue(clientIds.Any(r => r.Contains(Id)));
                });
            }
        }
Exemplo n.º 7
0
 public IList <DocumentReceiveLog> GetLoadedDocumentLogs()
 {
     return(ArHelper.WithSession(
                session => session.CreateCriteria(typeof(DocumentReceiveLog))
                .Add(Expression.Eq("SendUpdateLogEntity", this))
                .AddOrder(Order.Desc("LogTime"))
                .List <DocumentReceiveLog>()));
 }
Exemplo n.º 8
0
        private static IEnumerable <SwitchOffCounts> GetExcelSwitchOffClients(SwitchOffClientsFilter filter)
        {
            var criteria = filter.GetCriteria();

            filter.ApplySort(criteria);

            return(ArHelper.WithSession(s => filter.Find(s, true)).ToList());
        }
Exemplo n.º 9
0
 public static void SetupParametersForTriggerLogging()
 {
     ArHelper.WithSession(session => SetupParametersForTriggerLogging(new {
         InUser = SecurityContext.Administrator.UserName,
         InHost = SecurityContext.Administrator.Host
     },
                                                                      session));
 }
 public static void DeleteAuditRecords(Account account)
 {
     ArHelper.WithSession(s => {
         s.CreateSQLQuery("delete from Billing.PayerAuditRecords where ObjectId = :id and ObjectType = :type")
         .SetParameter("id", account.ObjectId)
         .SetParameter("type", account.ObjectType)
         .ExecuteUpdate();
     });
 }
 public Tab(Type type)
 {
     Id    = type.Name;
     Name  = BindingHelper.GetDescription(type);
     Type  = type;
     Items = ArHelper.WithSession(
         s => s.CreateCriteria(type)
         .AddOrder(Order.Asc("Name"))
         .List());
 }
Exemplo n.º 12
0
 public static Client FindClietnForBilling(uint clientCode)
 {
     return(ArHelper.WithSession(
                session => session.CreateCriteria(typeof(Client))
                .Add(Restrictions.Eq("Id", clientCode))
                .SetFetchMode("BillingInstance", FetchMode.Join)
                .SetFetchMode("HomeRegion", FetchMode.Join)
                .SetFetchMode("ContactGroupOwner", FetchMode.Join)
                .UniqueResult <Client>()));
 }
Exemplo n.º 13
0
        private static IEnumerable <RegistrationInformation> GetRegistrationInformation(UserFinderFilter filter)
        {
            var criteria = filter.GetCriteria();

            filter.ApplySort(criteria);

            return(ArHelper.WithSession(
                       s => criteria.GetExecutableCriteria(s).ToList <RegistrationInformation>())
                   .ToList());
        }
Exemplo n.º 14
0
        public virtual void ResetUin()
        {
            ArHelper.WithSession(session =>
                                 session.CreateSQLQuery(@"
update usersettings.UserUpdateInfo uui
	join Customers.Users u on uui.UserId = u.Id
set uui.AFCopyId = ''
where u.ClientId = :clientcode")
                                 .SetParameter("clientcode", Id)
                                 .ExecuteUpdate());
        }
        public void BaseTest()
        {
            var filter = new UserFinderFilter();

            filter.FinderType  = RegistrationFinderType.Addresses;
            filter.ExcludeType = ExcludesTypes.Hidden;
            var criteria = filter.GetCriteria();

            filter.ApplySort(criteria);
            var client = ArHelper.WithSession(s => criteria.GetExecutableCriteria(s).ToList <RegistrationInformation>()).ToList();
        }
Exemplo n.º 16
0
        public static void DeleteAuditRecords(object entity)
        {
            var auditRecord = new AuditRecord(entity);

            ArHelper.WithSession(s => {
                s.CreateSQLQuery("delete from Logs.ClientsInfo where ObjectId = :Id and Type = :Type")
                .SetParameter("Id", auditRecord.ObjectId)
                .SetParameter("Type", auditRecord.Type)
                .ExecuteUpdate();
            });
        }
Exemplo n.º 17
0
        public static void UpdateLogs(uint serviceId, object entity)
        {
            var auditRecord = new AuditRecord(entity);

            ArHelper.WithSession(s => s.CreateSQLQuery(@"
update logs.clientsinfo set ServiceId = :serviceId
where ObjectId = :objectId and Type = :Type")
                                 .SetParameter("serviceId", serviceId)
                                 .SetParameter("objectId", auditRecord.ObjectId)
                                 .SetParameter("Type", auditRecord.Type)
                                 .ExecuteUpdate());
        }
Exemplo n.º 18
0
        public bool Perform(ExecuteWhen exec,
                            IEngineContext context,
                            IController controller,
                            IControllerContext controllerContext)
        {
            ArHelper.WithSession(s => {
                var regionMask = SecurityContext.Administrator.RegionMask;
                s.EnableFilter("RegionFilter").SetParameter("AdminRegionMask", regionMask);
            });

            return(true);
        }
Exemplo n.º 19
0
        public IList <CallRecord> Find()
        {
            var searchText = String.IsNullOrEmpty(SearchText) ? String.Empty : SearchText.ToLower();

            searchText.Trim();
            searchText = Utils.StringToMySqlString(searchText);
            var sortFilter      = String.Format(" order by `{0}` {1} ", GetSortProperty(), GetSortDirection());
            var limit           = String.Format("limit {0}, {1}", Page * PageSize, PageSize);
            var searchCondition = String.IsNullOrEmpty(searchText) ? String.Empty :
                                  " and (LOWER({CallRecord}.`From`) like \"%" + searchText +
                                  "%\" or LOWER({CallRecord}.`To`) like \"%" + searchText +
                                  "%\" or LOWER({CallRecord}.NameFrom) like \"%" + searchText +
                                  "%\" or LOWER({CallRecord}.NameTo) like \"%" + searchText + "%\") ";

            if (CallType != null)
            {
                searchCondition += " and {CallRecord}.CallType = " + Convert.ToInt32(CallType);
            }

            IList <CallRecord> callList = null;
            var sql = @"
select {CallRecord.*}
from logs.RecordCalls {CallRecord}
where {CallRecord}.WriteTime > :BeginDate and {CallRecord}.WriteTime < :EndDate"
                      + searchCondition + sortFilter + limit;

            var countSql = @"
select count(*)
from logs.RecordCalls {CallRecord}
where {CallRecord}.WriteTime > :BeginDate and {CallRecord}.WriteTime < :EndDate" + searchCondition;

            countSql = countSql.Replace("{CallRecord}", "c");

            ArHelper.WithSession(session => {
                callList = session.CreateSQLQuery(sql)
                           .AddEntity(typeof(CallRecord))
                           .SetParameter("BeginDate", BeginDate)
                           .SetParameter("EndDate", EndDate.AddDays(1))
                           .List <CallRecord>();

                var count = Convert.ToInt32(session.CreateSQLQuery(countSql)
                                            .SetParameter("BeginDate", BeginDate)
                                            .SetParameter("EndDate", EndDate.AddDays(1))
                                            .UniqueResult());
                TotalPages = count / PageSize;
                if (count % PageSize > 0)
                {
                    TotalPages++;
                }
            });
            return(callList);
        }
        public static IList <PasswordChangeLogEntity> GetByLogin(string login, DateTime beginDate, DateTime endDate)
        {
            IList <PasswordChangeLogEntity> entity = null;

            ArHelper.WithSession(session => entity = session.CreateSQLQuery(@"
select {PasswordChangeLogEntity.*}
from logs.passwordchange {PasswordChangeLogEntity}
where LogTime >= :BeginDate and LogTime <= :EndDate and TargetUserName = :Login")
                                                     .AddEntity(typeof(PasswordChangeLogEntity))
                                                     .SetParameter("BeginDate", beginDate)
                                                     .SetParameter("EndDate", endDate)
                                                     .SetParameter("Login", login).List <PasswordChangeLogEntity>());
            return(entity);
        }
Exemplo n.º 21
0
        public virtual bool HaveUin()
        {
            var result = ArHelper.WithSession(session =>
                                              session.CreateSQLQuery(@"
select sum(length(concat(uui.AFCopyId))) = 0
from usersettings.UserUpdateInfo uui
	join Customers.Users u on uui.UserId = u.Id
where u.ClientId = :clientcode
group by u.ClientId")
                                              .SetParameter("clientcode", Id)
                                              .UniqueResult <long?>());

            return(result != null && result.Value == 0);
        }
Exemplo n.º 22
0
        public static void ProcessReport(BaseReport report, ReportsTypes type)
        {
            report.ReportCaption = report.ReportCaption ?? "Automate Created Report";
            ProfileHelper.Start();
            using (new SessionScope()) {
                ArHelper.WithSession(s => {
                    report.Session        = s;
                    report.CheckEmptyData = false;
                    report.Write(EnsureDeletion(type));
                });
            }

            ProfileHelper.Stop();
        }
        public IList <StatResult> Find()
        {
            var sql       = string.Format(@"
select 
c.id as ClientCode,
u.UserId,
c.Name as ClientName,
r1.Region as ClientRegion,
s.Name as SupplierName,
s.Id as SupplierId,
r2.Region as SupplierRegion,
dl.RowId DocumentId,
dl.FileName as DocumentFileName,
u.RequestTime,
db.Code ProcuctCode,
db.Product as ProductName,
db.Producer,
db.ProductId,
db.CertificateError
from Logs.CertificateRequestLogs l
	join Logs.AnalitFUpdates u on u.UpdateId = l.UpdateId
	join Customers.Users fu on fu.Id = u.UserId
	join Customers.Clients c on c.Id = fu.ClientId
	join Documents.DocumentBodies db on db.Id = l.DocumentBodyId
	join Documents.DocumentHeaders dh on dh.Id = db.DocumentId
	left join logs.Document_logs dl on dl.RowId = dh.DownloadId
	join Customers.Suppliers s on s.Id = dh.FirmCode
	join farm.Regions r1 on r1.RegionCode = c.RegionCode
	join farm.Regions r2 on r2.RegionCode = s.HomeRegion
where (u.RequestTime >= :StartDateParam AND u.RequestTime <= :EndDateParam)
	and c.MaskRegion & :RegionMaskParam > 0
	and fu.PayerId <> 921 and
l.CertificateId is null
order by {0} {1}
;", SortBy, SortDirection);
            var adminMask = SecurityContext.Administrator.RegionMask;

            if (Region != null)
            {
                adminMask &= Region.Id;
            }
            var result = ArHelper.WithSession(s => s.CreateSQLQuery(sql)
                                              .SetParameter("StartDateParam", Period.Begin)
                                              .SetParameter("EndDateParam", Period.End.AddDays(1))
                                              .SetParameter("RegionMaskParam", adminMask)
                                              .ToList <StatResult>());

            return(result);
        }
Exemplo n.º 24
0
        public virtual IEnumerable <AuditLogRecord> GetAuditLogs()
        {
            var messages = ArHelper.WithSession(s => {
                var service = Clients.Select(c => (Service)c).Concat(Suppliers.Select(sup => (Service)sup)).Concat(Addresses.Select(a => (Service)a.Client)).Distinct();
                return(service.SelectMany(ser => new MessageQuery(LogMessageType.User, LogMessageType.System).Execute(ser, s)));
            });

            return(messages.Select(m => new AuditLogRecord {
                ObjectId = m.ObjectId,
                Message = m.Message,
                Name = m.Name,
                OperatorName = m.Operator,
                LogType = m.Type,
                LogTime = m.WriteTime
            }));
        }
Exemplo n.º 25
0
        private static void MoveAdditionFiles()
        {
            var dirPath = @"\\acdcserv\WebApps\Data\Reports";
            //var dirPath = string.Empty;
            var files = ArHelper.WithSession(s => s.CreateSQLQuery(@"SELECT r.Id as PropId, f.Id FileId FROM reports.report_properties r
join reports.reports rp on  rp.ReportCode = r.ReportCode
join reports.filessendwithreport f on f.Report = rp.GeneralReportCode
where PropertyId = 438;")
                                             .ToList <FileProp>());

            foreach (var fileProp in files)
            {
                var from = Path.Combine(dirPath, fileProp.PropId.ToString());
                var to   = Path.Combine(dirPath, fileProp.FileId.ToString());
                File.Copy(from, to);
            }
        }
        public void Create_intersection_after_legal_entity_creation()
        {
            var client = DataMother.TestClient();
            var org    = new LegalEntity {
                Name  = "тараканов и сыновья",
                Payer = client.Payers.First()
            };

            session.Save(org);
            Maintainer.LegalEntityCreated(session, org);
            var count = ArHelper.WithSession(s =>
                                             s.CreateSQLQuery(@"select count(*) from Customers.Intersection where LegalEntityId = :LegalEntityId")
                                             .SetParameter("LegalEntityId", org.Id)
                                             .UniqueResult <long>());

            Assert.That(count, Is.GreaterThan(0));
        }
Exemplo n.º 27
0
        public static string[] LastCalls()
        {
            //сломан хибер

/*			return (from call in Queryable
 *                              where call.Id2 == IdentificationStatus.Unknow && call.Direction == CallDirection.Input
 *                              orderby call.LogTime descending
 *                              group call by call.From into c
 *                              select c.Key).Take(5).ToArray();
 */
            var criteria = DetachedCriteria.For <CallLog>()
                           .Add(Restrictions.Where <CallLog>(c => c.Id2 == IdentificationStatus.Unknow && c.Direction == CallDirection.Input))
                           .SetProjection(Projections.Group <CallLog>(l => l.From))
                           .AddOrder(Order.Desc("LogTime"))
                           .SetMaxResults(5);

            return(ArHelper.WithSession(s => criteria.GetExecutableCriteria(s).List <string>().ToArray()));
        }
Exemplo n.º 28
0
        public Administrator Run()
        {
            using (new SessionScope()) {
                return(ArHelper.WithSession(s => {
                    //нужно только для того что бы запустить в браузере
                    var admin = Administrator.GetByName(Environment.UserName);
                    if (admin == null)
                    {
                        admin = Administrator.CreateLocalAdministrator();
                        s.Save(admin);
                    }

                    var origin = SecurityContext.GetAdministrator;
                    SecurityContext.GetAdministrator = () => admin;
                    var defaults = s.Query <DefaultValues>().First();
                    if (defaults.SmartOrderAssortmentPrice == null)
                    {
                        var payer = new Payer("Тестовый плательщик");
                        var homeRegion = s.Load <Region>(1UL);
                        var supplier = new Supplier(homeRegion, payer)
                        {
                            Name = "Тестовый поставщик",
                            FullName = "Тестовый поставщик",
                            ContactGroupOwner = new ContactGroupOwner(ContactGroupType.ClientManagers)
                        };
                        supplier.RegionalData.Add(new RegionalData {
                            Region = homeRegion, Supplier = supplier
                        });
                        defaults.SmartOrderAssortmentPrice = supplier.AddPrice("Базовый", PriceType.Assortment);
                        s.Save(supplier);
                    }
                    SecurityContext.GetAdministrator = origin;

                    if (!s.Query <ParseAlgorithm>().Any(p => p.Name == "DbfSource"))
                    {
                        s.Save(new ParseAlgorithm("DbfSource"));
                    }

                    return admin;
                }));
            }
        }
Exemplo n.º 29
0
        public bool Perform(ExecuteWhen exec,
                            IEngineContext context,
                            IController controller,
                            IControllerContext controllerContext)
        {
            controllerContext.PropertyBag["ViewName"] =
                Path.GetFileNameWithoutExtension(context.Request.Uri.Segments.Last());
            controllerContext.PropertyBag["LocalPath"] =
                Path.GetFileNameWithoutExtension(context.Request.Uri.LocalPath);

            if (context.Session["AdminId"] != null)
            {
                ArHelper.WithSession(s => {
                    context.Session["Admin"] = s.Get <Admin>(context.Session["AdminId"]);
                });
            }
            controllerContext.PropertyBag["AccessEditLink"] = context.Session["Admin"] != null;
            controllerContext.PropertyBag["SiteAdress"]     = context.ApplicationPath + "/";
            return(true);
        }
        public IList <AuditRecord> Find()
        {
            return(ArHelper.WithSession(s => {
                uint id;
                uint.TryParse(SearchText, out id);
                var query = s.QueryOver <AuditRecord>()
                            .Where(l => l.WriteTime >= Period.Begin && l.WriteTime <= Period.End.AddDays(1))
                            .Where(l => l.MessageType.IsIn(Types.ToArray()))
                            .And(
                    Restrictions.On <AuditRecord>(l => l.Message).IsLike(SearchText, MatchMode.Anywhere) ||
                    Restrictions.On <AuditRecord>(l => l.Name).IsLike(SearchText, MatchMode.Anywhere) ||
                    Restrictions.On <AuditRecord>(l => l.ObjectId).IsLike(id));

                query.RootCriteria
                .CreateCriteria("Service", "s", JoinType.InnerJoin)
                .Add(Expression.Sql("s1_.HomeRegion & " + SecurityContext.Administrator.RegionMask + " > 0"));

                ApplySort(query.RootCriteria);
                query.Fetch(c => c.Administrator);
                return query.List <AuditRecord>();
            }));
        }