Exemplo n.º 1
0
        private void popupBankImportWindowShowAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e)
        {
            var importLine = View.CurrentObject as BankImportLine;

            newObjectSpace = Application.CreateObjectSpace(typeof(BankImportRule));

            var newRule = BankRuleFunctions.MakeRuleFromBankImportLine(importLine, newObjectSpace);

            e.View     = Application.CreateDetailView(newObjectSpace, newRule);
            e.View.Tag = View.CurrentObject;  //user by apply and save
        }
Exemplo n.º 2
0
        private void actMakeNewRules_Execute(object sender, SimpleActionExecuteEventArgs e)
        {
            try
            {
                var bankImport = e.CurrentObject as BankImport;
                var os         = View.ObjectSpace;

                var unassignedLines = bankImport.Lines.Where(x => x.Account == null && x.Ref5.Length > 0).ToList();

                var categoryType = GLCategoryEnum.Expense;

                foreach (var line in unassignedLines)
                {
                    var rule = os.FindObject <BankImportRule>(CriteriaOperator.Parse("[RuleName]=?", line.Ref5)); // just matching 5
                    if (rule != null)
                    {
                        line.Account = os.GetObject(rule.ToAccount);
                        continue;
                    }



                    var newRule = BankRuleFunctions.MakeRuleFromBankImportLine(line, os);

                    var ac = os.GetObject(bankImport.Account);
                    newRule.FromAccount = ac;

                    //var code = $"0{categoryType:D} {line.Ref5}";
                    var code      = line.Ref5;
                    var toAccount = os.FindObject <Account>(CriteriaOperator.Parse("Code=?", code)) ?? BankRuleFunctions.CreateAccount(code, categoryType, os);

                    newRule.RuleName  = line.Ref5;
                    newRule.ToAccount = toAccount;
                    os.ModifiedObjects.Add(newRule);
                    // line.Account = os.GetObject(rule.ToAccount);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                throw;
            }

            View.ObjectSpace.CommitChanges();
            View.ObjectSpace.Refresh();
        }