private void Form1_Load(object sender, EventArgs e) { stockInfos = new XPQuery<StockInfo>(sess); stockHoldings = new XPQuery<StockHolding>(sess); stockFlows = new XPQuery<StockFlow>(sess); dailyCounts = new XPQuery<DailyCount>(sess); DailyCount todayCount; moneyFlows = new XPQuery<MoneyFlow>(sess); moneyHolding = new XPQuery<MoneyHolding>(sess).SingleOrDefault(); if (moneyHolding == null) { moneyHolding = new MoneyHolding(); moneyHolding.Save(); } if (stockHoldings.Count() > 0&&! new DayOfWeek[]{DayOfWeek.Sunday,DayOfWeek.Saturday}.Contains( DateTime.Today.DayOfWeek)) { todayCount= dailyCounts.SingleOrDefault(p => p.Date.Date == DateTime.Today); if (todayCount == null) { todayCount = new DailyCount() { Date = DateTime.Now }; todayCount.Save(); dailyCounts = new XPQuery<DailyCount>(sess); } } dgvDaily.DataSource = dailyCounts.ToList() ; comboBox1.DisplayMember = "Text"; comboBox1.ValueMember = "Value"; comboBox1.DataSource =EnumHelper.GetItems< StockTradeType>(); }
public string GetVerseTranslation(Session session, int numberOfBook, int numberOfChapter, int verseStart, int verseEnd = 0, string translationName = "NPI") { if (verseEnd == 0) { var index = $"{translationName}.{numberOfBook}.{numberOfChapter}.{verseStart}"; var verse = new XPQuery <Verse>(session).Where(x => x.Index == index).FirstOrDefault(); if (verse.IsNotNull()) { var verseText = verse.GetTranslationText(); if (verseText.IsNotNullOrWhiteSpace()) { return(verseText); } else { return(GetOtherVerseTranslation(session, numberOfBook, numberOfChapter, verseStart)); } } else { return(GetOtherVerseTranslation(session, numberOfBook, numberOfChapter, verseStart)); } } else { var predicate = PredicateBuilder.New <Verse>(); for (int i = verseStart; i < verseEnd + 1; i++) { var index = $"{translationName}.{numberOfBook}.{numberOfChapter}.{i}"; predicate = predicate.Or(x => x.Index == index); } var verses = new XPQuery <Verse>(session).Where(predicate); if (verses.Count() > 0) { if (verses.First().GetTranslationText().IsNotNullOrWhiteSpace()) { var versesText = String.Empty; foreach (var item in verses) { versesText += item.GetTranslationText() + " "; } return(versesText.Trim()); } else { return(GetOtherVersesTranslation(session, numberOfBook, numberOfChapter, verseStart, verseEnd)); } } else { return(GetOtherVersesTranslation(session, numberOfBook, numberOfChapter, verseStart, verseEnd)); } } }
public void Should_update_project() { var project = CreateProject(); project.Save(); const string changedname = "changedName"; project.Name = changedname; _repository.Update(project); var changedProject = _projectQuery.SingleOrDefault(p => p.Oid == project.Oid); Assert.AreEqual(1, _projectQuery.Count()); Assert.AreEqual(changedname, changedProject.Name); Assert.AreEqual(project.Identify, changedProject.Identify); }
public void InsertSimpleOrdCsv() { // arrange parameters var map1 = ObjectSpace.CreateObject <OrdinalToFieldMap>(); map1.SourceOrdinal = 0; map1.TargetName = "Description"; var map2 = ObjectSpace.CreateObject <OrdinalToFieldMap>(); map2.SourceOrdinal = 1; map2.TargetName = "Amount"; var param = ObjectSpace.CreateObject <ImportOrdinalsParam>(); param.OrdToFieldMaps.Add(map1); param.OrdToFieldMaps.Add(map2); param.ObjectTypeName = "MockFactObject"; string csvText = @"Hello 1,10 Hello 2,20 Hello 3,30"; var csvStream = ConvertToCsvStream(csvText); var request = ObjectSpace.CreateObject <ImportRequest>(); var logger = new ImportLogger(request); var xpoMapper = new XpoFieldMapper(); ICsvToXpoLoader loader = new OrdCsvToXpoInserter(param, csvStream, xpoMapper, logger); loader.Execute(); var inserted = new XPQuery <MockFactObject>(ObjectSpace.Session); MockFactObject obj = inserted.Where(x => x.Description == "Hello 3").FirstOrDefault(); Assert.AreEqual(3, inserted.Count()); Assert.AreEqual(30, obj.Amount); Assert.AreEqual(null, obj.MockLookupObject1); }
public void InsertSimpleHeaderCsv() { var xpoMapper = new XpoFieldMapper(); var param = GetHeadMockParamObject(); string csvText = @"Description,Amount Hello 1,10 Hello 2,20 Hello 3,30"; var csvStream = ConvertToCsvStream(csvText); ICsvToXpoLoader loader = new HeadCsvToXpoInserter(param, csvStream, xpoMapper, null); loader.Execute(); var inserted = new XPQuery <MockFactObject>(ObjectSpace.Session); MockFactObject obj = inserted.Where(x => x.Description == "Hello 3").FirstOrDefault(); Assert.AreEqual(3, inserted.Count()); Assert.AreEqual(30, obj.Amount); Assert.AreEqual(null, obj.MockLookupObject1); }
public int SaveMobileTransaction(MobileTransactionAPIModel model) { try { XPQuery <InventoryDeliveries> invDeliveries = session.Query <InventoryDeliveries>(); MobileTransaction mobile = new MobileTransaction(session); mobile.InventoryDeliveriesLocationID = null; mobile.MobileTransactionID = 0; mobile.Notes = ""; mobile.ScannedProductCode = model.code; mobile.UIDCode = GetUIDCode(model.code); mobile.SupplierID = clientRepo.GetClientByID(model.supplier_id, mobile.Session); mobile.ProductID = productRepo.GetProductByID(model.inventory_id, mobile.Session); mobile.tsUpdate = DateTime.Now; mobile.tsUpdateUserID = model.user_id; if (mobile.MobileTransactionID == 0) { mobile.tsInsert = model.created_at; mobile.tsInsertUserID = model.user_id; } mobile.InventoryDeliveriesLocationID = SaveInventoryDeliveriesLocation(model, mobile.Session); mobile.Quantity = invDeliveries.Count(inv => inv.PackagesUIDs.Contains(mobile.UIDCode));//kosovna količina mobile.Save(); return(mobile.MobileTransactionID); } catch (Exception ex) { string error = ""; CommonMethods.getError(ex, ref error); throw new Exception(CommonMethods.ConcatenateErrorIN_DB(DB_Exception.res_32, error, CommonMethods.GetCurrentMethodName())); } }
public int CountInventoryDeliverisByPackageUID(string uid, Session currentSession = null) { try { XPQuery <InventoryDeliveries> invDel = null; if (currentSession != null) { invDel = currentSession.Query <InventoryDeliveries>(); } else { invDel = session.Query <InventoryDeliveries>(); } return(invDel.Count(i => i.PackagesUIDs.Contains(uid))); } catch (Exception ex) { string error = ""; CommonMethods.getError(ex, ref error); throw new Exception(CommonMethods.ConcatenateErrorIN_DB(DB_Exception.res_34, error, CommonMethods.GetCurrentMethodName())); } }
public void UpdateSimpleHeaderCsv() { // arrange parameters var map1 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map1.SourceName = "Description"; map1.TargetName = map1.SourceName; map1.IsKeyField = true; var map2 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map2.SourceName = "Amount"; map2.TargetName = map2.SourceName; var param = ObjectSpace.CreateObject <ImportHeadersParam>(); param.HeaderToFieldMaps.Add(map1); param.HeaderToFieldMaps.Add(map2); param.ObjectTypeName = "MockFactObject"; // arrange XPO objects var obj1 = ObjectSpace.CreateObject <MockFactObject>(); obj1.Description = "Hello 1"; obj1.Amount = 10; var obj2 = ObjectSpace.CreateObject <MockFactObject>(); obj2.Description = "Hello 2"; obj2.Amount = 20; var obj3 = ObjectSpace.CreateObject <MockFactObject>(); obj3.Description = "Hello 3"; obj3.Amount = 30; ObjectSpace.CommitChanges(); // arrange loader string csvText = @"Description,Amount Hello 1,100 Hello 2,200 Hello 3,300"; var csvStream = ConvertToCsvStream(csvText); var request = ObjectSpace.CreateObject <ImportRequest>(); var logger = new ImportLogger(request); var xpoFieldMapper = new XpoFieldMapper(); ICsvToXpoLoader loader = new HeadCsvToXpoUpdater(param, csvStream, xpoFieldMapper, logger); // act loader.Execute(); // assert var updated = new XPQuery <MockFactObject>(ObjectSpace.Session); Assert.AreEqual(3, updated.Count()); // returns 6 because it inserts instead of updates MockFactObject result = updated.Where(x => x.Description == "Hello 1").FirstOrDefault(); Assert.AreEqual(100, result.Amount); result = updated.Where(x => x.Description == "Hello 2").FirstOrDefault(); Assert.AreEqual(200, result.Amount); result = updated.Where(x => x.Description == "Hello 3").FirstOrDefault(); Assert.AreEqual(300, result.Amount); }
public void InsertCashFlow() { #region Arrange var csvText = @"TranDate,Account,Activity,Counterparty,CounterCcyAmt,CounterCcy,Description,Source 21/03/2016,VHA ANZ 70086,AP Pymt,APPLE PTY LTD,-10000,AUD,Test transaction,Chris Tso"; var map1 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map1.SourceName = "TranDate"; map1.TargetName = map1.SourceName; var map2 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map2.SourceName = "Account"; map2.TargetName = map2.SourceName; map2.CreateMember = true; var map3 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map3.SourceName = "Activity"; map3.TargetName = map3.SourceName; map3.CreateMember = true; map3.CacheObject = true; var map4 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map4.SourceName = "Counterparty"; map4.TargetName = map4.SourceName; map4.CreateMember = true; map4.CacheObject = true; var map5 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map5.SourceName = "CounterCcyAmt"; map5.TargetName = map5.SourceName; var map6 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map6.SourceName = "CounterCcy"; map6.TargetName = map6.SourceName; map6.CreateMember = true; //map6.CacheObject = true; var map7 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map7.SourceName = "Description"; map7.TargetName = map7.SourceName; var map8 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map8.SourceName = "Source"; map8.TargetName = map8.SourceName; map8.CreateMember = true; map8.CacheObject = true; var param = ObjectSpace.CreateObject <ImportHeadersParam>(); param.HeaderToFieldMaps.Add(map1); param.HeaderToFieldMaps.Add(map2); param.HeaderToFieldMaps.Add(map3); param.HeaderToFieldMaps.Add(map4); param.HeaderToFieldMaps.Add(map5); param.HeaderToFieldMaps.Add(map6); param.HeaderToFieldMaps.Add(map7); param.HeaderToFieldMaps.Add(map8); param.ObjectTypeName = "CashFlow"; ObjectSpace.CommitChanges(); #endregion #region Act var csvStream = ConvertToCsvStream(csvText); var xpoMapper = new XpoFieldMapper(); ICsvToXpoLoader loader = new HeadCsvToXpoInserter(param, csvStream, xpoMapper, null); loader.Execute(); ObjectSpace.CommitChanges(); #endregion #region Assert var inserted = new XPQuery <CashFlow>(ObjectSpace.Session); Assert.AreEqual(1, inserted.Count()); var obj1 = inserted.FirstOrDefault(); Assert.NotNull(obj1.Account); Assert.NotNull(obj1.Activity); Assert.NotNull(obj1.Counterparty); Assert.NotNull(obj1.Source); Assert.NotNull(obj1.CounterCcy); #endregion }
public void InsertMock() { #region Arrange var csvText = @"Description,Amount,MockLookupObject1,MockLookupObject2 Hello 1,10,Parent 1,Parent B1 Hello 2,11,Parent 2,Parent B2 Hello 3,12,Parent 3,Parent B3 Hello 4,13,Parent 4,Parent B4 "; var map1 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map1.SourceName = "Description"; map1.TargetName = map1.SourceName; var map2 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map2.SourceName = "Amount"; map2.TargetName = map2.SourceName; var map3 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map3.SourceName = "MockLookupObject1"; map3.TargetName = map3.SourceName; map3.CreateMember = true; map3.CacheObject = true; var map4 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map4.SourceName = "MockLookupObject2"; map4.TargetName = map4.SourceName; map4.CreateMember = true; map4.CacheObject = true; var param = ObjectSpace.CreateObject <ImportHeadersParam>(); param.HeaderToFieldMaps.Add(map1); param.HeaderToFieldMaps.Add(map2); param.HeaderToFieldMaps.Add(map3); param.HeaderToFieldMaps.Add(map4); param.ObjectTypeName = "MockFactObject"; ObjectSpace.CommitChanges(); #endregion #region Act var csvStream = ConvertToCsvStream(csvText); var xpoMapper = new XpoFieldMapper(); ICsvToXpoLoader loader = new HeadCsvToXpoInserter(param, csvStream, xpoMapper, null); loader.Execute(); ObjectSpace.CommitChanges(); #endregion #region Assert var inserted = new XPQuery <MockFactObject>(ObjectSpace.Session); Assert.AreEqual(4, inserted.Count()); var obj1 = inserted.Where(x => x.Description == "Hello 1").FirstOrDefault(); var obj2 = inserted.Where(x => x.Description == "Hello 2").FirstOrDefault(); var obj3 = inserted.Where(x => x.Description == "Hello 3").FirstOrDefault(); var obj4 = inserted.Where(x => x.Description == "Hello 4").FirstOrDefault(); Assert.NotNull(obj1.MockLookupObject1); Assert.NotNull(obj1.MockLookupObject2); Assert.NotNull(obj2.MockLookupObject1); Assert.NotNull(obj2.MockLookupObject2); Assert.NotNull(obj3.MockLookupObject1); Assert.NotNull(obj3.MockLookupObject2); Assert.NotNull(obj4.MockLookupObject1); Assert.NotNull(obj4.MockLookupObject2); #endregion }
public int CreateIssueDocumentFromMobileTransactions(List <int> mobileTransactionsID, int userID, int buyerID) { UnitOfWork uow = XpoHelper.GetNewUnitOfWork(); XPQuery <MobileTransaction> mobileTrans = uow.Query <MobileTransaction>(); XPQuery <InventoryDeliveries> invDeliveries = uow.Query <InventoryDeliveries>(); var mobileTransactions = mobileTrans.Where(mt => mobileTransactionsID.Any(mti => mti == mt.MobileTransactionID)).ToList(); if (mobileTransactions != null && mobileTransactions.Count > 0) { var buyer = clientRepo.GetClientByID(buyerID, session); //from locationID we get buyer IssueDocument document = new IssueDocument(session); document.IssueDocumentID = 0; document.IssueNumber = GetNextIssueDocumentNumber(); document.BuyerID = buyer; document.IssueStatus = GetIssueDocumentStatusByCode(Enums.IssueDocumentStatus.DELOVNA); document.IssueDate = DateTime.Now; document.Name = $"Izdaja materiala za kupca: {buyer.Name}"; document.Notes = "Prenos iz mobilnih transkacij"; document.InternalDocument = "000000"; document.InvoiceNumber = DateTime.Now.Year.ToString() + "/000000"; document.tsInsert = DateTime.Now; document.tsInsertUserID = userID; document.tsUpdate = DateTime.Now; document.tsUpdateUserID = userID; document.Save(); var issueDocument = GetIssueDocumentByID(document.IssueDocumentID, uow); IssueDocumentPosition pos = null; foreach (var item in mobileTransactions) { pos = new IssueDocumentPosition(uow); pos.IssueDocumentID = issueDocument; pos.SupplierID = clientRepo.GetClientByID(item.SupplierID.ClientID, uow); //Kosovna količina pos.Quantity = item.Quantity <= 0 ? invDeliveries.Count(inv => inv.PackagesUIDs.Contains(item.UIDCode)) : item.Quantity;// če se še ni shranila količina na mobilnih transkacijah jo poiščemo v invnetoryDeliveries pos.UID250 = item.UIDCode; pos.Name = item.ProductID.Name; pos.Notes = "Prenos iz mobilnih transakcij"; pos.tsInsert = DateTime.Now; pos.tsInsertUserID = userID; pos.tsUpdate = DateTime.Now; pos.tsUpdateUserID = userID; pos.ProductID = productRepo.GetProductByID(item.ProductID.ProductID, uow); pos.MobileTransactionID = item; } uow.CommitChanges(); return(document.IssueDocumentID); } return(-1); }
public void InsertHeaderCsvWithLookupOfSpecificFields() { #region Arrange Parameters var map1 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map1.SourceName = "Description"; map1.TargetName = map1.SourceName; var map2 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map2.SourceName = "Amount"; map2.TargetName = map2.SourceName; var map3 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map3.SourceName = "MockLookupObject1"; map3.TargetName = map3.SourceName; map3.CreateMember = true; var map4 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map4.SourceName = "MockLookupObject2"; map4.TargetName = map4.SourceName; map4.CreateMember = false; var param = ObjectSpace.CreateObject <ImportHeadersParam>(); param.HeaderToFieldMaps.Add(map1); param.HeaderToFieldMaps.Add(map2); param.HeaderToFieldMaps.Add(map3); param.HeaderToFieldMaps.Add(map4); param.ObjectTypeName = "MockFactObject"; #endregion #region Arrange Mapper string csvText = @"Description,Amount,MockLookupObject1,MockLookupObject2 Hello 1,10,Apple,Handset Hello 2,20,Samsung,Marketing Hello 3,30,HTC,Credit"; var csvStream = ConvertToCsvStream(csvText); var request = ObjectSpace.CreateObject <ImportRequest>(); var logger = new ImportLogger(request); var xpoMapper = new XpoFieldMapper(); ICsvToXpoLoader loader = new HeadCsvToXpoInserter(param, csvStream, xpoMapper, logger); #endregion // act loader.Execute(); // assert var inserted = new XPQuery <MockFactObject>(ObjectSpace.Session); Assert.AreEqual(3, inserted.Count()); var obj = inserted.Where(x => x.Description == "Hello 3").FirstOrDefault(); Assert.AreEqual(30, obj.Amount); Assert.NotNull(obj.MockLookupObject1); Assert.Null(obj.MockLookupObject2); Assert.AreEqual(3, xpoMapper.LookupsNotFound[typeof(MockLookupObject2)].Count()); Assert.AreEqual(3, xpoMapper.LookupsNotFound[typeof(MockLookupObject1)].Count()); // why is this 6? Assert.AreEqual(2, xpoMapper.LookupsNotFound.Count()); }
public void InsertHeaderCsvWithLookup(bool createMember, bool cacheObject) { #region Arrange Param var map1 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map1.SourceName = "Description"; map1.TargetName = map1.SourceName; var map2 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map2.SourceName = "Amount"; map2.TargetName = map2.SourceName; var map3 = ObjectSpace.CreateObject <HeaderToFieldMap>(); map3.SourceName = "MockLookupObject1"; map3.TargetName = map3.SourceName; map3.CreateMember = createMember; map3.CacheObject = cacheObject; var param = ObjectSpace.CreateObject <ImportHeadersParam>(); param.HeaderToFieldMaps.Add(map1); param.HeaderToFieldMaps.Add(map2); param.HeaderToFieldMaps.Add(map3); param.ObjectTypeName = "MockFactObject"; #endregion #region Arrange Mapper string csvText = @"Description,Amount,MockLookupObject1 Hello 1,10,Apple Hello 2,20,Samsung Hello 3,30,HTC"; var csvStream = ConvertToCsvStream(csvText); var request = ObjectSpace.CreateObject <ImportRequest>(); var logger = new ImportLogger(request); var xpoFieldMapper = new XpoFieldMapper(); HeadCsvToXpoInserter loader = new HeadCsvToXpoInserter(param, csvStream, xpoFieldMapper, logger); #endregion // act xpoFieldMapper.LookupsNotFound.Add(typeof(MockLookupObject1), new List <string>() { "Apple", "Samsung", "HTC" }); loader.Execute(); // assert var inserted = new XPQuery <MockFactObject>(ObjectSpace.Session); Assert.AreEqual(3, inserted.Count()); var obj = inserted.Where(x => x.Description == "Hello 3").FirstOrDefault(); Assert.AreEqual(30, obj.Amount); Assert.AreEqual(3, xpoFieldMapper.LookupsNotFound[typeof(MockLookupObject1)].Count()); // parameterized assert if (createMember) { Assert.NotNull(obj.MockLookupObject1); } else if (!createMember) { Assert.Null(obj.MockLookupObject1); } }