Ejemplo n.º 1
0
        private void AddOperator()
        {
            var op = new Operator
            {
                Name = OperatorName
            };

            App.Locator.Import.OperatorsList.Add(op);
            App.Locator.Import.Operators.Add(op);
            App.Locator.Import.SelectedOperator = op;

            View.ViewLocator.AddOperatorView.Visibility = System.Windows.Visibility.Hidden;
            OperatorName = string.Empty;
        }
Ejemplo n.º 2
0
        public bool SetOperatorLocker(Operator op, User user, bool _lock)
        {
            if (IsNoLocking)
                return true;

            bool wasException = false;
            var logSession = Helpers.Old.Log.SessionStart("DataAccess.SetOperatorLocker()", true);
            bool result = false;

            try
            {
                using (var dc = exelconverterEntities2.New())
                {
                    if (_lock)
                    {
                        DateTime curDate = GetServerDateTime();

                        //Берем исключительно последнюю блокировку для данного оператора
                        var currentLock = dc.locks.Where(l => l.id_company == op.Id).OrderByDescending(l => l.locked_to).FirstOrDefault();
                        if (currentLock != null)
                        {
                            //Если это блокировка текущего пользователя или если это старая блокировка (пофиг кем сделанная)
                            if (currentLock.id_user == user.Id || currentLock.locked_to < curDate)
                            {
                                currentLock.locked_to = GetDateTimeToLock(curDate);
                                currentLock.id_user = (int)user.Id;
                                dc.SaveChanges();
                                result = true;
                            }
                        } else
                        {
                            dc.locks.Add(new locks() { id_company = (int)op.Id, id_user = (int)user.Id, locked_to = GetDateTimeToLock(curDate) });
                            dc.SaveChanges();
                            result = true;
                        }
                    } else
                    {
                        foreach (var currentLock in dc.locks.Where(l => l.id_company == op.Id && l.id_user == user.Id).ToArray())
                            dc.locks.Remove(currentLock);

                        dc.SaveChanges();
                        result = true;
                    }
                }
            }
            catch(Exception ex)
            {
                wasException = true;
                Helpers.Old.Log.Add(logSession, ex.GetExceptionText());
            }
            finally
            {
                Helpers.Old.Log.SessionEnd(logSession, wasException);
            }
            return result;
        }
Ejemplo n.º 3
0
        public void SetExportedRulesForOperator(Operator op, SheetRulePair[] exportRules)
        {
            bool wasException = false;
            var logSesson = Helpers.Old.Log.SessionStart(string.Format("DataAccess.SetExportedRulesForOperator(id:{0})", op == null ? "null" : op.Id.ToString()), true);
            try
            {
                using (var dc = exelconverterEntities2.New())
                {
                    string ruleString = string.Empty;

                    var validRules = exportRules
                                        .Where(i => i.Rule != null && !string.IsNullOrWhiteSpace(i.Sheet?.Name ?? i.SheetName))
                                        .Select(i => string.Format("{0}:{1}", i.Rule.Id, i.Sheet?.Name ?? i.SheetName))
                                        .ToArray();
                    if (validRules.Length > 0)
                        ruleString = validRules.Aggregate((s1, s2) => $"{s1};{s2}");

                    var export_rule =
                        dc
                        .operator_export_rule
                        .FirstOrDefault(r => r.operator_id == op.Id);

                    if (export_rule != null)
                    {
                        if (export_rule.export_rules != ruleString)
                        {
                            export_rule.export_rules = ruleString;
                            dc.SaveChanges();
                        }
                    } else
                    {
                        dc.operator_export_rule.Add(
                            new operator_export_rule() { operator_id = (int)op.Id, export_rules = ruleString }
                            );
                        dc.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                wasException = true;
                Helpers.Old.Log.Add(logSesson, ex.GetExceptionText());
                throw ex;
            }
            finally
            {
                Helpers.Old.Log.SessionEnd(logSesson, wasException);
            }
        }
Ejemplo n.º 4
0
 public ExelConvertionRule[] GetRulesByOperator(Operator op)
 {
     return GetRulesByOperator(new int[] { (int)op.Id });
 }
Ejemplo n.º 5
0
        public Operator[] GetOperators(int[] ids = null)
        {
            Operator[] result = new Operator[] {};
            var logSession = Helpers.Old.Log.SessionStart("DataAccess.GetOperators()", true);
            bool wasException = false;
            try
            {
                int[] lIds = ids == null ? new int[] { } : ids;

                using (var dc = alphaEntities.New())
                {
                    result = dc.companies
                        .Where(c => c.type == "operator")
                        .Where(c => lIds.Count() == 0 || lIds.Contains((int)c.id))
                        .Select(c =>
                                new Operator()
                                    {
                                        Id = c.id,
                                        Name = c.name,
                                        Notes = c.notes
                                    }
                            )
                        .ToArray();
                }
            }
            catch(Exception ex)
            {
                wasException = true;
                Log.Add(ex.GetExceptionText());
            }
            finally
            {
                Helpers.Old.Log.SessionEnd(logSession, wasException);
            }
            return result;
        }
Ejemplo n.º 6
0
        public Dictionary<Operator, User> GetOperatorLockers(Operator operatorFilter = null)
        {
            var result = new Dictionary<Operator, User>();
            if (IsNoLocking)
                return result;

            var logSession = Helpers.Old.Log.SessionStart(string.Format("DataAccess.GetOperatorLockers(operatorFilter:'{0}')", operatorFilter == null ? "null" : operatorFilter.Id.ToString()), true);
            bool wasException = false;
            try
            {
                DateTime startDateTime = GetServerDateTime();

                long opId = operatorFilter == null ? -1 : operatorFilter.Id;

                using (var dbApp = exelconverterEntities2.New())
                using (var dbMain = alphaEntities.New())
                {
                    var curLocks =
                        (
                            from l in dbApp.locks.Where(
                                l => (l.locked_to > startDateTime)
                                     && (opId == -1 || l.id_company == opId)
                                ).ToList()
                            join user in dbMain.users on l.id_user equals user.id
                            join op in dbMain.companies on l.id_company equals op.id
                            select new
                            {
                                User = new User()
                                {
                                    Id = user.id,
                                    Login = user.login,
                                    Name = user.name,
                                    Surname = user.surname,
                                    Patronymic = user.patronymic
                                }
                                ,
                                Operator = new Operator()
                                    {
                                        Id = op.id,
                                        Name = op.name
                                    }
                            }
                        ).ToList();

                    foreach (var l in curLocks)
                        result.Add(l.Operator, l.User);
                }
            }
            catch(Exception ex)
            {
                wasException = true;
                Helpers.Old.Log.Add(logSession, ex.GetExceptionText());
            }
            finally
            {
                Helpers.Old.Log.SessionEnd(logSession, wasException);
            }
            return result;
        }
Ejemplo n.º 7
0
 public User GetOperatorLocker(Operator op)
 {
     var res = GetOperatorLockers(op);
     return res.Select(o => o.Value).FirstOrDefault();
 }
Ejemplo n.º 8
0
        public SheetRulePair[] GetExportRulesIdByOperator(Operator op, IQueryable<ExelSheet> existedSheets)
        {
            var result = new SheetRulePair[] { };
            bool wasException = false;
            var logSesson = Helpers.Old.Log.SessionStart(string.Format("DataAccess.GetExportRulesIdByOperator(id:{0})", op == null ? "null" : op.Id.ToString()), true);
            try
            {
                using (var dc = exelconverterEntities2.New())
                {
                    string export_rule =
                        dc
                        .operator_export_rule
                        .Where(r => r.operator_id == op.Id && r.export_rules != null)
                        .Select(r=>r.export_rules)
                        .FirstOrDefault();

                    if (!string.IsNullOrWhiteSpace(export_rule))
                        result =
                            export_rule
                            .Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
                            .Select(i =>
                                {
                                    var prts = i.Split(new char[] { ':' });
                                    if (prts.Length == 2)
                                        return new SheetRulePair(existedSheets)
                                            {
                                                Rule = op.MappingRules.FirstOrDefault(r => r.Id.ToString() == prts[0]),
                                                SheetName = prts[1].ToLower().Trim()
                                            };
                                        else return null;
                                })
                            .Where(i => i != null)
                            .ToArray();
                }
            }
            catch (Exception ex)
            {
                wasException = true;
                Helpers.Old.Log.Add(logSesson, ex.GetExceptionText());
                throw ex;
            }
            finally
            {
                Helpers.Old.Log.SessionEnd(logSesson, wasException);
            }

            return result;
        }