예제 #1
0
        private void OnTicketTagAdded(string obj)
        {
            var cachedTag = AppServices.MainDataContext.SelectedDepartment.TicketTagGroups.Single(
                x => x.Id == SelectedTicketTag.Id);

            Debug.Assert(cachedTag != null);
            var ctag = cachedTag.TicketTags.SingleOrDefault(x => x.Name.ToLower() == CustomTag.ToLower());

            if (ctag == null && cachedTag.SaveFreeTags)
            {
                using (var workspace = WorkspaceFactory.Create())
                {
                    var tt = workspace.Single <TicketTagGroup>(x => x.Id == SelectedTicketTag.Id);
                    Debug.Assert(tt != null);
                    var tag = tt.TicketTags.SingleOrDefault(x => x.Name.ToLower() == CustomTag.ToLower());
                    if (tag == null)
                    {
                        tag = new TicketTag()
                        {
                            Name = CustomTag
                        };
                        tt.TicketTags.Add(tag);
                        workspace.Add(tag);
                        workspace.CommitChanges();
                    }
                }
            }
            DataContext.SelectedTicket.UpdateTag(SelectedTicketTag, new TicketTag {
                Name = CustomTag
            });
            CustomTag = string.Empty;
            InvokeTagUpdated(SelectedTicketTag);
        }
예제 #2
0
 private static void OnWorkperiodStatusChanged(EventParameters <WorkPeriod> obj)
 {
     if (obj.Topic == EventTopicNames.WorkPeriodStatusChanged)
     {
         using (var ws = WorkspaceFactory.Create())
         {
             if (ws.Count <Recipe>() > 0)
             {
                 if (!AppServices.MainDataContext.IsCurrentWorkPeriodOpen)
                 {
                     var pc = InventoryService.GetCurrentPeriodicConsumption(ws);
                     if (pc.Id == 0)
                     {
                         ws.Add(pc);
                     }
                     ws.CommitChanges();
                 }
                 else
                 {
                     if (AppServices.MainDataContext.PreviousWorkPeriod != null)
                     {
                         var pc = InventoryService.GetPreviousPeriodicConsumption(ws);
                         if (pc != null)
                         {
                             InventoryService.CalculateCost(pc, AppServices.MainDataContext.PreviousWorkPeriod);
                             ws.CommitChanges();
                         }
                     }
                 }
             }
         }
     }
 }
예제 #3
0
        private IWorkspace PrepareWorkspace(string fileName)
        {
            Assembly ass = Assembly.GetExecutingAssembly();
            var      lp  = new Uri(ass.CodeBase);
            string   pth = Path.GetDirectoryName(lp.LocalPath);

            pth = Path.Combine(pth, "..\\..\\..\\Magentix.Presentation");
            LocalSettings.AppPath         = pth;
            LocalSettings.CurrentLanguage = "tr";
            var dataFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\tests";

            if (!Directory.Exists(dataFolder))
            {
                Directory.CreateDirectory(dataFolder);
            }
            var filePath = string.Format("{0}\\{1}", dataFolder, fileName);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            WorkspaceFactory.UpdateConnection(filePath);
            var workspace = WorkspaceFactory.Create();

            CustomerEntityType = new EntityType {
                Name = "Customers", EntityName = "Customer"
            };
            CustomerEntityType.EntityCustomFields.Add(new EntityCustomField {
                EditingFormat = "(###) ### ####", FieldType = 0, Name = "Phone"
            });
            workspace.Add(CustomerEntityType);
            workspace.CommitChanges();

            return(workspace);
        }
예제 #4
0
 public bool StopWorkPeriod(string description)
 {
     using (var w = WorkspaceFactory.Create())
     {
         using (var tran = w.BeginTransaction())
         {
             try
             {
                 _workPeriodDao.StopWorkPeriod(description, w);
                 foreach (var workPeriodProcessor in WorkPeriodProcessors)
                 {
                     workPeriodProcessor.ProcessWorkPeriodEnd(CurrentWorkPeriod);
                 }
                 if (tran != null)
                 {
                     tran.Commit();
                 }
             }
             catch (Exception e)
             {
                 if (tran != null)
                 {
                     tran.Rollback();
                 }
                 _logService.LogError(e);
                 return(false);
             }
         }
     }
     _applicationStateSetter.ResetWorkPeriods();
     return(true);
 }
 public void Constructor_NullUnconfiguredProject_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>("unconfiguredProject", () =>
     {
         new TestSourceFilePropertiesProvider(null, WorkspaceFactory.Create(""), IProjectThreadingServiceFactory.Create());
     });
 }
예제 #6
0
            public Customer UpdateCustomer(Customer customer)
            {
                if (customer == Customer.Null)
                {
                    return(Customer.Null);
                }

                if (customer.Id == 0)
                {
                    using (var workspace = WorkspaceFactory.Create())
                    {
                        workspace.Add(customer);
                        workspace.CommitChanges();
                    }
                    return(customer);
                }

                var result = _workspace.Single <Customer>(
                    x => x.Id == customer.Id &&
                    x.Name == customer.Name &&
                    x.Address == customer.Address &&
                    x.PhoneNumber == customer.PhoneNumber &&
                    x.Note == customer.Note);

                if (result == null)
                {
                    result = _workspace.Single <Customer>(x => x.Id == customer.Id);
                    Debug.Assert(result != null);
                    result.Address     = customer.Address;
                    result.Name        = customer.Name;
                    result.PhoneNumber = customer.PhoneNumber;
                    result.Note        = customer.Note;
                }
                return(result);
            }
        private IWorkspace PrepareWorkspace(string fileName)
        {
            Assembly ass = Assembly.GetExecutingAssembly();
            var      lp  = new Uri(ass.CodeBase);
            string   pth = Path.GetDirectoryName(lp.LocalPath);

            pth = Path.Combine(pth, "..\\..\\..\\Magentix.Presentation");
            LocalSettings.AppPath         = pth;
            LocalSettings.CurrentLanguage = "en";
            var dataFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\tests";

            if (!Directory.Exists(dataFolder))
            {
                Directory.CreateDirectory(dataFolder);
            }
            var filePath = string.Format("{0}\\{1}", dataFolder, fileName);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            WorkspaceFactory.UpdateConnection(filePath);
            var workspace = WorkspaceFactory.Create();

            workspace.CommitChanges();
            return(workspace);
        }
예제 #8
0
 private EntityStateValue UpdateEntityStateEH(int entityId, string stateName, string state, string quantityExp, int retries)
 {
     if (entityId == 0)
     {
         return(null);
     }
     using (var w = WorkspaceFactory.Create())
     {
         var stateValue = w.Single <EntityStateValue>(x => x.EntityId == entityId);
         if (stateValue == null)
         {
             stateValue = new EntityStateValue {
                 EntityId = entityId
             };
             w.Add(stateValue);
         }
         stateValue.SetStateValue(stateName, state, quantityExp);
         try
         {
             w.CommitChanges();
         }
         catch (DbUpdateException)
         {
             if (retries > 3)
             {
                 throw;
             }
             return(UpdateEntityStateEH(entityId, stateName, state, quantityExp, ++retries));
         }
         return(stateValue);
     }
 }
예제 #9
0
        public void StartWorkPeriod(string description, decimal cashAmount, decimal creditCardAmount, decimal ticketAmount)
        {
            using (var workspace = WorkspaceFactory.Create())
            {
                _lastTwoWorkPeriods = null;

                var latestWorkPeriod = workspace.Last <WorkPeriod>();
                if (latestWorkPeriod != null && latestWorkPeriod.StartDate == latestWorkPeriod.EndDate)
                {
                    return;
                }

                var now       = DateTime.Now;
                var newPeriod = new WorkPeriod
                {
                    StartDate        = now,
                    EndDate          = now,
                    StartDescription = description,
                    CashAmount       = cashAmount,
                    CreditCardAmount = creditCardAmount,
                    TicketAmount     = ticketAmount
                };

                workspace.Add(newPeriod);
                workspace.CommitChanges();
                _lastTwoWorkPeriods = null;
            }
        }
예제 #10
0
 public void TagOrders(IEnumerable <Order> selectedOrders, OrderTagGroup orderTagGroup, OrderTag orderTag)
 {
     foreach (var selectedOrder in selectedOrders)
     {
         var result = selectedOrder.ToggleOrderTag(orderTagGroup, orderTag, _applicationState.CurrentLoggedInUser.Id);
         if (orderTagGroup.SaveFreeTags && orderTagGroup.OrderTags.All(x => x.Name != orderTag.Name))
         {
             using (var v = WorkspaceFactory.Create())
             {
                 var og = v.Single <OrderTagGroup>(x => x.Id == orderTagGroup.Id);
                 if (og != null)
                 {
                     var lvTagName = orderTag.Name.ToLower();
                     var t         = v.Single <OrderTag>(x => x.Name.ToLower() == lvTagName);
                     if (t == null)
                     {
                         var ot = new OrderTag();
                         ot.InjectFrom <CloneInjection>(orderTag);
                         og.OrderTags.Add(ot);
                         v.CommitChanges();
                         _cacheService.ResetOrderTagCache();
                     }
                 }
             }
         }
         _automationService.NotifyEvent(result ? RuleEventNames.OrderTagged : RuleEventNames.OrderUntagged,
                                        new
         {
             Order         = selectedOrder,
             OrderTagName  = orderTagGroup.Name,
             OrderTagValue = orderTag.Name
         });
     }
 }
예제 #11
0
        public void SaveFreeTicketTag(int id, string freeTag)
        {
            if (string.IsNullOrEmpty(freeTag))
            {
                return;
            }

            using (var workspace = WorkspaceFactory.Create())
            {
                var tt = workspace.Single <TicketTagGroup>(x => x.Id == id);
                Debug.Assert(tt != null);
                var tag = tt.TicketTags.FirstOrDefault(x => x.Name.ToLower() == freeTag.ToLower());

                if (tag != null)
                {
                    return;
                }
                tag = new TicketTag {
                    Name = freeTag
                };
                tt.TicketTags.Add(tag);
                workspace.Add(tag);
                workspace.CommitChanges();
                _cacheService.ResetTicketTagCache();
            }
        }
예제 #12
0
        private static void AddTransaction(int customerId, decimal amount, string description, PaymentType paymentType, TransactionType transactionType)
        {
            using (var workspace = WorkspaceFactory.Create())
            {
                if (transactionType == TransactionType.Income || transactionType == TransactionType.Expense)
                {
                    var c = new CashTransaction
                    {
                        Amount          = amount,
                        Date            = DateTime.Now,
                        Name            = description,
                        PaymentType     = (int)paymentType,
                        TransactionType = (int)transactionType,
                        UserId          = AppServices.CurrentLoggedInUser.Id,
                        CustomerId      = customerId
                    };
                    workspace.Add(c);
                }
                else
                {
                    var c = new AccountTransaction
                    {
                        Amount          = amount,
                        Date            = DateTime.Now,
                        Name            = description,
                        TransactionType = (int)transactionType,
                        UserId          = AppServices.CurrentLoggedInUser.Id,
                        CustomerId      = customerId
                    };
                    workspace.Add(c);
                }

                workspace.CommitChanges();
            }
        }
예제 #13
0
 public override void Reset()
 {
     _taxTemplates     = null;
     _calculationTypes = null;
     _terminals        = null;
     _globalSettings.ResetCache();
     Workspace = WorkspaceFactory.Create();
 }
예제 #14
0
 public void DeleteMenuItemPricesByPriceTag(string priceTag)
 {
     using (var workspace = WorkspaceFactory.Create())
     {
         workspace.Delete <MenuItemPrice>(x => x.PriceTag == priceTag);
         workspace.CommitChanges();
     }
 }
 protected override void BeforeDeleteItem(MenuItemPriceDefinition item)
 {
     using (var workspace = WorkspaceFactory.Create())
     {
         workspace.Delete <MenuItemPrice>(x => x.PriceTag == item.PriceTag);
         workspace.CommitChanges();
     }
 }
예제 #16
0
 public static void AddTimeCardEntry(TimeCardEntry timeCardEntry)
 {
     using (var workspace = WorkspaceFactory.Create())
     {
         workspace.Add(timeCardEntry);
         workspace.CommitChanges();
     }
 }
예제 #17
0
 private void SaveSelectedCustomer()
 {
     if (!SelectedCustomer.IsNotNew)
     {
         var ws = WorkspaceFactory.Create();
         ws.Add(SelectedCustomer.Model);
         ws.CommitChanges();
     }
 }
예제 #18
0
 public IList <Table> LoadTables(string selectedTableScreen)
 {
     if (_tableWorkspace != null)
     {
         _tableWorkspace.CommitChanges();
     }
     _tableWorkspace = WorkspaceFactory.Create();
     return(_tableWorkspace.Single <TableScreen>(x => x.Name == selectedTableScreen).Tables);
 }
예제 #19
0
            public void CreateTicket(Department department)
            {
                Debug.Assert(_workspace == null);
                Debug.Assert(Ticket == null);
                Debug.Assert(department != null);

                _workspace = WorkspaceFactory.Create();
                Ticket     = Ticket.Create(department);
            }
예제 #20
0
 public IList <Widget> LoadWidgets(string selectedResourceScreen)
 {
     if (_resoureceWorkspace != null)
     {
         _resoureceWorkspace.CommitChanges();
     }
     _resoureceWorkspace = WorkspaceFactory.Create();
     return(_resoureceWorkspace.Single <ResourceScreen>(x => x.Name == selectedResourceScreen).Widgets);
 }
예제 #21
0
 public void CreateTransactionDocument(Account selectedAccount, AccountTransactionDocumentType documentType, string description, decimal amount, decimal exchangeRate, IEnumerable <Account> accounts)
 {
     using (var w = WorkspaceFactory.Create())
     {
         var document = documentType.CreateDocument(selectedAccount, description, amount, exchangeRate, accounts != null ? accounts.ToList() : null);
         w.Add(document);
         w.CommitChanges();
     }
 }
예제 #22
0
 public IList <EntityScreenItem> LoadEntityScreenItems(string selectedEntityScreen)
 {
     if (_resoureceWorkspace != null)
     {
         _resoureceWorkspace.CommitChanges();
     }
     _resoureceWorkspace = WorkspaceFactory.Create();
     return(_resoureceWorkspace.Single <EntityScreen>(x => x.Name == selectedEntityScreen).ScreenItems);
 }
예제 #23
0
        public IEnumerable <AccountTransactionDocumentType> BatchCreateTransactionTypeDocuments(string[] values, IWorkspace workspace)
        {
            IList <AccountTransactionDocumentType> result = new List <AccountTransactionDocumentType>();

            if (values.Length > 0)
            {
                foreach (var item in values)
                {
                    var parts = item.Split(';');
                    if (parts.Count() > 3)
                    {
                        var name = parts[0].Trim();
                        if (workspace.Single <AccountTransactionDocumentType>(x => x.Name.ToLower() == name.ToLower()) != null)
                        {
                            continue;
                        }

                        var atName = parts[1].Trim();
                        var header = parts[2].Trim();

                        var accTemplate = workspace.Single <AccountType>(x => x.Name.ToLower() == atName.ToLower());
                        if (accTemplate == null)
                        {
                            using (var w = WorkspaceFactory.Create())
                            {
                                accTemplate = new AccountType {
                                    Name = atName
                                };
                                w.Add(accTemplate);
                                w.CommitChanges();
                            }
                        }

                        var resultItem = new AccountTransactionDocumentType
                        {
                            Name = name,
                            MasterAccountTypeId = accTemplate.Id,
                            ButtonHeader        = header,
                            ButtonColor         = "Gainsboro"
                        };

                        for (var i = 3; i < parts.Length; i++)
                        {
                            var n  = parts[i].ToLower();
                            var tt = workspace.Single <AccountTransactionType>(x => x.Name.ToLower() == n);
                            if (tt != null)
                            {
                                resultItem.TransactionTypes.Add(tt);
                            }
                        }

                        result.Add(resultItem);
                    }
                }
            }
            return(result);
        }
예제 #24
0
 public AccountTransactionDocument CreateTransactionDocument(Account selectedAccount, AccountTransactionDocumentType documentType, string description, decimal amount, decimal exchangeRate, IEnumerable <AccountData> accounts, IEnumerable <ForeignCurrency> currencies)
 {
     using (var w = WorkspaceFactory.Create())
     {
         var document = documentType.CreateDocument(selectedAccount, description, amount, exchangeRate, accounts != null ? accounts.ToList() : null, currencies.ToList());
         w.Add(document);
         w.CommitChanges();
         return(document);
     }
 }
        public async void SourceFileProperties_GetUnevalutedPropertyAsync(string code, string propertyName, string expectedValue)
        {
            var workspace       = WorkspaceFactory.Create(code);
            var projectFilePath = workspace.CurrentSolution.Projects.First().FilePath;
            var provider        = new TestSourceFilePropertiesProvider(IUnconfiguredProjectFactory.Create(filePath: projectFilePath), workspace, IProjectThreadingServiceFactory.Create());

            var properties    = provider.GetProperties(projectFilePath, null, null);
            var propertyValue = await properties.GetUnevaluatedPropertyValueAsync(propertyName);

            Assert.Equal(expectedValue, propertyValue);
        }
예제 #26
0
 public static void ResetCache()
 {
     _terminal  = null;
     _terminals = null;
     MainDataContext.ResetCache();
     PrintService.ResetCache();
     SettingService.ResetCache();
     SerialPortService.ResetCache();
     Dao.ResetCache();
     Workspace = WorkspaceFactory.Create();
 }
예제 #27
0
 public int CreateAccount(int accountTypeId, string accountName)
 {
     using (var w = WorkspaceFactory.Create())
     {
         var account = new Account {
             AccountTypeId = accountTypeId, Name = accountName
         };
         w.Add(account);
         w.CommitChanges();
         return(account.Id);
     }
 }
예제 #28
0
 public void UpdatePriceTag(string departmentName, string priceTag)
 {
     using (IWorkspace workspace = WorkspaceFactory.Create())
     {
         Department department = workspace.Single <Department>((Department y) => y.Name == departmentName, new Expression <Func <Department, object> > [0]);
         if (department != null)
         {
             department.PriceTag = priceTag;
             workspace.CommitChanges();
         }
     }
 }
 public void UpdatePriceTag(string departmentName, string priceTag)
 {
     using (var workspace = WorkspaceFactory.Create())
     {
         var department = workspace.Single <Department>(y => y.Name == departmentName);
         if (department != null)
         {
             department.PriceTag = priceTag;
             workspace.CommitChanges();
         }
     }
 }
예제 #30
0
 public void UpdateEntityData(EntityType entityType, string entityName, string fieldName, string value)
 {
     using (var w = WorkspaceFactory.Create())
     {
         var entity = w.Single <Entity>(x => x.Name == entityName && x.EntityTypeId == entityType.Id);
         if (entity != null)
         {
             entity.SetCustomData(fieldName, value);
             w.CommitChanges();
         }
     }
 }