Esempio n. 1
0
        public MainForm()
        {
            InitializeComponent();
            this.thesisRecordBindingSource.Add(MainThread.getInstance().ThesisRecord);
            this.viewModelBindingSource.Add(ViewModel.getInstance());
            this.readerConfigBindingSource.Add(ReaderConfig.getInstance());
            this.inventoryRecordBindingSource.Add(InventoryStore.getInstance().SelectedInventoryRecord);

            this.fileSelectListBox.DataSource           = DiscContents.getInstance().MaskedFileInfoList;
            this.fileSelectListBox.DisplayMember        = "MaskedFileName";
            this.allFileListBox.DataSource              = DiscContents.getInstance().DisplayFileInfoList;
            this.allFileListBox.DisplayMember           = "DisplayFileName";
            this.inventoryMatchesComboBox.DataSource    = MainThread.getInstance().MatchingInventoryList;
            this.inventoryMatchesComboBox.DisplayMember = "DisplayString";

            ViewModel.getInstance().ProgressBar          = this.progressBar;
            PdfReaderHelper.getInstance().ContainerPanel = this.pdfReaderPanel;

            Version version = Assembly.GetExecutingAssembly().GetName().Version;

            this.Text = Text + " - v" + version.Major + "." + version.Minor + "." + version.Build;

            this.chineseAbstractTextBox.KeepLineBreaks = true;
            this.englishAbstractTextBox.KeepLineBreaks = true;

            this.menuPanel.DataBindings.Add(new Binding("Visible", this.viewModelBindingSource, "ShowMenu", true, DataSourceUpdateMode.OnPropertyChanged));
            this.pdfTextsTextArea.DataBindings.Add(new Binding("Visible", this.viewModelBindingSource, "ShowPdfTexts", true, DataSourceUpdateMode.OnPropertyChanged));
        }
Esempio n. 2
0
        public void UpdateQuality_WhenSellByDateHasPassed_QualityDegradesTwiceAsFast()
        {
            // Arrange
            var program = new Program {
                Items = InventoryStore.GetItems()
            };

            var itemsWithQualityDegradingTwiceAsFast = program.Items
                                                       .Where(item => !item.Name.Equals("Aged Bried"))
                                                       .Where(item => !item.Name.Equals("Sulfuras, Hand of Ragnaros"));

            var pickedItem = itemsWithQualityDegradingTwiceAsFast.First();

            // Until sell by date is reached
            while (pickedItem.SellIn >= 0)
            {
                program.UpdateQuality();
            }

            var previousQuality = pickedItem.Quality;

            // Act
            program.UpdateQuality();

            // Assert
            Assert.Equal(pickedItem.Quality, previousQuality - 2);
        }
        /// <summary>
        /// Find an item in Inventory Store by InventoryStore Id
        /// </summary>
        /// <param name="inventoryStoreId"></param>
        /// <returns></returns>
        public async Task <InventoryStore> FindById(int inventoryStoreId)
        {
            //Find Product by productId in Inventory Store
            InventoryStore inventoryStoreItem = await _context.InventoryStore.AsNoTracking().FirstOrDefaultAsync(i => i.InventoryStoreId == inventoryStoreId);

            //Log Information
            _logger.LogInformation($"Executed query to find Inventory Store Item by InventoryStoreId :{inventoryStoreId}.");

            //Return Product from Inventory Store
            return(inventoryStoreItem);
        }
        public async Task <Dictionary <string, IDictionary <string, string> > > Expired([FromHeader] string auth)
        {
            string user;

            if ((user = JwtBuilder.UserJwtToken(auth).Result) == null || !UserStore.Exists(user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return(null);
            }

            HttpContext.Response.Headers.Add("auth", auth);
            return(await InventoryStore.expire_warning(user));
        }
        /// <summary>
        ///  Add a new Product to Inventory Store
        /// </summary>
        /// <param name="inventoryItem"></param>
        /// <returns></returns>
        public async Task <int> Add(InventoryStore inventoryItem)
        {
            //Add a new product to context
            EntityEntry <InventoryStore> entry = _context.Add(inventoryItem);

            //Save changes to store
            await _context.SaveChangesAsync();

            //Log Information
            _logger.LogInformation($"Executed command to add a new product with ProductId:{inventoryItem.ProductId} and name : {inventoryItem.ProductName} to the Inventory Store with id : {entry.Entity.ProductId} ");

            //Return InventoryItemId
            return(entry.Entity.InventoryStoreId);
        }
Esempio n. 6
0
        public Tests()
        {
            inventoryStore = new InventoryStore();

            items.Add(new InventoryModel
            {
                Sku      = 1,
                Name     = "test",
                Quantity = 2,
                Price    = 3.43f
            });

            cart = new Cart(items);
        }
        public bool Remove([FromHeader] string auth, [FromRoute] string uid)
        {
            string user;

            if ((user = JwtBuilder.UserJwtToken(auth).Result) == null || !UserStore.Exists(user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return(false);
            }

            HttpContext.Response.Headers.Add("auth", auth);

            return(InventoryStore.Remove(uid, user).Result);
        }
Esempio n. 8
0
        public void UpdateQuality_WhenItemIsConjuredManaCake_QualityDegradesTwiceAsFast()
        {
            // Arrange
            var program = new Program {
                Items = InventoryStore.GetItems()
            };
            var conjuredManaCake = GetItem(program.Items, "Conjured Mana Cake");
            var quality          = conjuredManaCake.Quality;

            // Act
            program.UpdateQuality();

            // Assert
            Assert.Equal(quality - 2, conjuredManaCake.Quality);
        }
Esempio n. 9
0
        public void UpdateQuality_WhenItemIsAgedBrie_QualityIncreasesTheOlderItGets()
        {
            // Arrange
            var program = new Program {
                Items = InventoryStore.GetItems()
            };
            var agedBrie        = GetItem(program.Items, "Aged Brie");
            var agedBrieQuality = agedBrie.Quality;

            // Act
            program.UpdateQuality();

            // Assert
            ++agedBrieQuality;
            Assert.Equal(agedBrie.Quality, agedBrieQuality);
        }
        public async Task <IDictionary <string, string> > All([FromHeader] string auth)
        {
            string user;

            if ((user = JwtBuilder.UserJwtToken(auth).Result) == null || !UserStore.Exists(user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return(null);
            }

            HttpContext.Response.Headers.Add("auth", auth);

            var res = await InventoryStore.GetAll(user);

            return(res);
        }
Esempio n. 11
0
        public void UpdateQuality_WhenItemIsSulfuras_SellInIsAlwaysZeroAndQualityIsAlwaysEighty()
        {
            // Arrange
            var program = new Program {
                Items = InventoryStore.GetItems()
            };

            // Act
            program.UpdateQuality();

            // Assert
            var sulfuras = program.Items.FirstOrDefault(item => item.Name.Equals("Sulfuras, Hand of Ragnaros"));

            Assert.NotNull(sulfuras);
            Assert.Equal(sulfuras.Quality, 80);
            Assert.Equal(sulfuras.SellIn, 0);
        }
Esempio n. 12
0
        public void UpdateQuality_WhenQualityIsUpdated_QualityIsNeverNegative()
        {
            // Arrange
            var program = new Program {
                Items = InventoryStore.GetItems()
            };

            // Act
            for (int quality = 0; quality < 51; quality++)
            {
                program.UpdateQuality();
            }

            // Assert
            Assert.All(program.Items, item =>
            {
                Assert.True(item.Quality >= 0, "Quality should be 0 but it was negative");
            });
        }
        public async void Edit([FromHeader] string auth, [FromForm] string uid, [FromForm] string name)
        {
            string user;

            if ((user = JwtBuilder.UserJwtToken(auth).Result) == null || !UserStore.Exists(user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return;
            }

            HttpContext.Response.Headers.Add("auth", auth);
            if (InventoryStore.ExistName(name, user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Conflict;
                return;
            }

            await InventoryStore.EditName(user, uid, name);
        }
        public async void Share([FromHeader] string auth, [FromForm] string uid, [FromForm] string friend)
        {
            string user;

            if ((user = JwtBuilder.UserJwtToken(auth).Result) == null || !UserStore.Exists(user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return;
            }

            HttpContext.Response.Headers.Add("auth", auth);
            if (!InventoryStore.Exists(uid, user).Result || !UserStore.Exists(friend).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }

            await InventoryStore.Share(uid, user, friend);
        }
        public async void AddProduct([FromHeader] string auth, [FromForm] string product, [FromForm] int quantity,
                                     [FromForm] string uid, [FromForm] DateTime expire)
        {
            string user;

            if ((user = JwtBuilder.UserJwtToken(auth).Result) == null || !UserStore.Exists(user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return;
            }

            HttpContext.Response.Headers.Add("auth", auth);
            if (!ProductStore.Exists(product).Result || !InventoryStore.Exists(uid, user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }

            await InventoryStore.Add_prod(uid, product, quantity, expire, user);
        }
        public async void Add([FromHeader] string auth, [FromForm] string name)
        {
            string user;

            if ((user = JwtBuilder.UserJwtToken(auth).Result) == null || !UserStore.Exists(user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return;
            }

            HttpContext.Response.Headers.Add("auth", auth);
            if (InventoryStore.ExistName(name, user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Conflict;
            }
            else
            {
                await InventoryStore.Add(new Inventory <OwnedProduct>(name), user);
            }
        }
        public async Task <Inventory <OwnedProduct> > Info([FromHeader] string auth, [FromRoute] string uid)
        {
            string user;

            if ((user = JwtBuilder.UserJwtToken(auth).Result) == null || !UserStore.Exists(user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return(null);
            }

            HttpContext.Response.Headers.Add("auth", auth);
            var u = await InventoryStore.Get(uid, user);

            if (u != null)
            {
                return(u);
            }
            HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
            return(null);
        }
Esempio n. 18
0
        public void UpdateQuality_WhenItemIsBackstagePasses_QualityIncreasesUntilSellInDate()
        {
            var program = new Program {
                Items = InventoryStore.GetItems()
            };
            var backstagePass = GetItem(program.Items, "Backstage passes to a TAFKAL80ETC concert");

            var quality = backstagePass.Quality;
            var sellIn  = backstagePass.SellIn;

            while (sellIn > -1)
            {
                program.UpdateQuality();

                if (sellIn > 10)
                {
                    quality += 1;
                }
                else if (sellIn > 5)
                {
                    quality += 2;
                }
                else if (sellIn > 0)
                {
                    quality += 3;
                }
                else
                {
                    quality = 0;
                }

                if (quality > 50)
                {
                    quality = 50;
                }

                Assert.Equal(quality, backstagePass.Quality);

                sellIn -= 1;
            }
        }
        public async void EditProduct([FromHeader] string auth, [FromForm] string product,
                                      [FromForm] string uid, [FromForm] DateTime?expire = null, [FromForm] long?quantity = null)
        {
            string user;

            if ((user = JwtBuilder.UserJwtToken(auth).Result) == null || !UserStore.Exists(user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return;
            }

            HttpContext.Response.Headers.Add("auth", auth);
            if (!ProductStore.Exists(product).Result || !InventoryStore.Exists(uid, user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                return;
            }

            var date = expire != null ? new LocalDateTime((DateTime)expire) : null;
            await InventoryStore.Restock(uid, product, user, quantity, date);
        }
        /// <summary>
        /// Update an item in Inventory Store
        /// </summary>
        /// <param name="inventoryItem"></param>
        /// <returns></returns>
        public async Task Update(InventoryStore inventoryItem)
        {
            // Find the product in Inventory Store by productId
            InventoryStore inventoryItemInStore = await FindById(inventoryItem.ProductId);

            if (inventoryItemInStore == null)
            {
                //Log Error and throw an ArgumentNullException
                _logger.LogError($"Not Found : Product with ProductId:{inventoryItem.ProductId} in Inventory Store");
                throw new ArgumentNullException($"Not Found : Product with ProductId:{inventoryItem.ProductId} in Inventory Store");
            }

            //Update product in context
            _context.Set <InventoryStore> ().Update(inventoryItem);

            //Log Information
            _logger.LogInformation($"Executed command to update product for ProductId : {inventoryItem.ProductId} to store:");

            //Save changes to Store
            await _context.SaveChangesAsync();
        }
Esempio n. 21
0
        public void UpdateQuality_WhenQualityIsUpdated_QualityNeverExceedsFifty()
        {
            // Arrange
            var program = new Program {
                Items = InventoryStore.GetItems()
            };

            // Act
            for (int quality = 0; quality < 51; quality++)
            {
                program.UpdateQuality();
            }

            // Assert
            Assert.All(program.Items, item =>
            {
                if (!item.Name.Equals("Sulfuras, Hand of Ragnaros"))
                {
                    Assert.True(item.Quality <= 50, $"Quality from item {item.Name} should be up to 50 only, but it was {item.Quality}");
                }
            });
        }
        public async Task <List <MinimalRecipe> > Search([FromHeader] string auth, [FromForm] string keys, [FromForm] string inventory)
        {
            string user;

            if ((user = JwtBuilder.UserJwtToken(auth).Result) == null || !UserStore.Exists(user).Result)
            {
                HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return(null);
            }

            List <MinimalRecipe> list;

            HttpContext.Response.Headers.Add("auth", auth);
            if (inventory != null)
            {
                var inv = InventoryStore.Get(inventory, user).Result;
                if (inv == null)
                {
                    HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                    return(null);
                }

                var r = new List <Product>(inv._products);
                list = RecipeSearch.SearchMinimalRecipe(API_KEY, 10, r);
            }

            else
            {
                list = RecipeSearch.SearchMinimalRecipe(API_KEY, 10, keys);
            }

            foreach (var v in list)
            {
                await RecipeStore.Add(v);
            }

            return(list);
        }
        /// <summary>
        ///  Delete a product from Inventory Store
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        public async Task Delete(int productId)
        {
            // Find the product in store by productId
            InventoryStore inventoryStoreItem = await FindByProductId(productId);

            if (inventoryStoreItem == null)
            {
                //Log Error and throw an ArgumentNullException
                _logger.LogError($"Not Found : Product with ProductId:{productId} in Inventory Store");
                throw new ArgumentNullException($"Not Found : Product with ProductId:{productId} in Inventory Store");
            }

            //Detach
            _context.Entry(inventoryStoreItem).State = EntityState.Detached;

            //Remove Product from context
            _context.Set <InventoryStore> ().Remove(inventoryStoreItem);

            //Log Information
            _logger.LogInformation($"Executed command to delete product with productId : {productId} from store.");

            //Save changes to Store
            await _context.SaveChangesAsync();
        }
Esempio n. 24
0
 public ValantController()
 {
     ItemRepository = new InventoryStore();
 }
        protected void validateWithSelectedInventory()
        {
            if (!_enableValidation)
            {
                return;
            }

            // Prevent loop
            _enableValidation = false;

            Color EMPTY_VALUE_COLOR    = Color.Yellow;
            Color CONFLICT_VALUE_COLOR = Color.Pink;
            Color MATCH_VALUE_COLOR    = Color.LightGreen;

            ViewModel viewModel = ViewModel.getInstance();

            viewModel.ChineseNameInputColor  = SystemColors.Window;
            viewModel.EnglishNameInputColor  = SystemColors.Window;
            viewModel.StudentIdInputColor    = SystemColors.Window;
            viewModel.DegreeInputColor       = SystemColors.Window;
            viewModel.YearInputColor         = SystemColors.Window;
            viewModel.ProgramInputColor      = SystemColors.Window;
            viewModel.TitleInputColor        = SystemColors.Window;
            viewModel.AccessInputColor       = SystemColors.Window;
            viewModel.ReceivedDateInputColor = SystemColors.Window;

            InventoryRecord invRecord = InventoryStore.getInstance().SelectedInventoryRecord;

            if (invRecord == null || String.IsNullOrEmpty(invRecord.RecordId))
            {
                return;
            }

            ThesisRecord thesisRecord = MainThread.getInstance().ThesisRecord;

            // Chinese Name
            if (thesisRecord.ChineseName == null)
            {
                thesisRecord.ChineseName = "";
            }
            if (String.IsNullOrEmpty(thesisRecord.ChineseName) && String.IsNullOrEmpty(invRecord.ChineseName))
            {
                viewModel.ChineseNameInputColor = CONFLICT_VALUE_COLOR;
            }
            else if (String.IsNullOrEmpty(thesisRecord.ChineseName) && !String.IsNullOrEmpty(invRecord.ChineseName))
            {
                thesisRecord.ChineseName        = invRecord.ChineseName;
                viewModel.ChineseNameInputColor = EMPTY_VALUE_COLOR;
            }
            else if (!String.IsNullOrEmpty(thesisRecord.ChineseName) && String.IsNullOrEmpty(invRecord.ChineseName))
            {
                viewModel.ChineseNameInputColor = EMPTY_VALUE_COLOR;
            }
            else
            {
                viewModel.ChineseNameInputColor = thesisRecord.ChineseName.Equals(invRecord.ChineseName) ? MATCH_VALUE_COLOR : CONFLICT_VALUE_COLOR;
            }

            // English Name
            if (thesisRecord.EnglishName == null)
            {
                thesisRecord.EnglishName = "";
            }
            if (String.IsNullOrEmpty(thesisRecord.EnglishName) && String.IsNullOrEmpty(invRecord.Name))
            {
                viewModel.EnglishNameInputColor = CONFLICT_VALUE_COLOR;
            }
            else if (String.IsNullOrEmpty(thesisRecord.EnglishName) && !String.IsNullOrEmpty(invRecord.Name))
            {
                thesisRecord.EnglishName        = invRecord.Name;
                viewModel.EnglishNameInputColor = EMPTY_VALUE_COLOR;
            }
            else if (!String.IsNullOrEmpty(thesisRecord.EnglishName) && String.IsNullOrEmpty(invRecord.Name))
            {
                viewModel.EnglishNameInputColor = EMPTY_VALUE_COLOR;
            }
            else
            {
                viewModel.EnglishNameInputColor = thesisRecord.EnglishName.Equals(invRecord.Name) ? MATCH_VALUE_COLOR : CONFLICT_VALUE_COLOR;
            }

            // Student ID
            if (thesisRecord.StudentId == null)
            {
                thesisRecord.StudentId = "";
            }
            if (String.IsNullOrEmpty(thesisRecord.StudentId) && String.IsNullOrEmpty(invRecord.StudentNo))
            {
                viewModel.StudentIdInputColor = CONFLICT_VALUE_COLOR;
            }
            else if (String.IsNullOrEmpty(thesisRecord.StudentId) && !String.IsNullOrEmpty(invRecord.StudentNo))
            {
                thesisRecord.StudentId        = invRecord.StudentNo;
                viewModel.StudentIdInputColor = EMPTY_VALUE_COLOR;
            }
            else if (!String.IsNullOrEmpty(thesisRecord.StudentId) && String.IsNullOrEmpty(invRecord.StudentNo))
            {
                viewModel.StudentIdInputColor = EMPTY_VALUE_COLOR;
            }
            else
            {
                viewModel.StudentIdInputColor = thesisRecord.StudentId.Equals(invRecord.StudentNo) ? MATCH_VALUE_COLOR : CONFLICT_VALUE_COLOR;
            }

            // Degree
            if (String.IsNullOrEmpty(thesisRecord.Degree))
            {
                viewModel.DegreeInputColor = CONFLICT_VALUE_COLOR;
            }
            else
            {
                viewModel.DegreeInputColor = EMPTY_VALUE_COLOR;
            }

            // Year
            if (thesisRecord.Year == null)
            {
                thesisRecord.Year = "";
            }
            if (String.IsNullOrEmpty(thesisRecord.Year) && String.IsNullOrEmpty(invRecord.GradYear))
            {
                viewModel.YearInputColor = CONFLICT_VALUE_COLOR;
            }
            else if (String.IsNullOrEmpty(thesisRecord.Year) && !String.IsNullOrEmpty(invRecord.GradYear))
            {
                thesisRecord.Year        = invRecord.GradYear;
                viewModel.YearInputColor = EMPTY_VALUE_COLOR;
            }
            else if (!String.IsNullOrEmpty(thesisRecord.Year) && String.IsNullOrEmpty(invRecord.GradYear))
            {
                viewModel.YearInputColor = EMPTY_VALUE_COLOR;
            }
            else
            {
                viewModel.YearInputColor = thesisRecord.Year.Equals(invRecord.GradYear) ? MATCH_VALUE_COLOR : CONFLICT_VALUE_COLOR;
            }

            // Programme
            if (thesisRecord.Programme == null)
            {
                thesisRecord.Programme = "";
            }
            if (String.IsNullOrEmpty(thesisRecord.Programme) && String.IsNullOrEmpty(invRecord.Program))
            {
                viewModel.ProgramInputColor = CONFLICT_VALUE_COLOR;
            }
            else if (String.IsNullOrEmpty(thesisRecord.Programme) && !String.IsNullOrEmpty(invRecord.Program))
            {
                thesisRecord.Programme      = invRecord.Program;
                viewModel.ProgramInputColor = EMPTY_VALUE_COLOR;
            }
            else if (!String.IsNullOrEmpty(thesisRecord.Programme) && String.IsNullOrEmpty(invRecord.Program))
            {
                viewModel.ProgramInputColor = EMPTY_VALUE_COLOR;
            }
            else
            {
                viewModel.ProgramInputColor = thesisRecord.Programme.Equals(invRecord.Program) ? MATCH_VALUE_COLOR : CONFLICT_VALUE_COLOR;
            }

            // Title
            if (thesisRecord.ThesisTitle == null)
            {
                thesisRecord.ThesisTitle = "";
            }
            if (String.IsNullOrEmpty(thesisRecord.ThesisTitle) && String.IsNullOrEmpty(invRecord.Title))
            {
                viewModel.TitleInputColor = CONFLICT_VALUE_COLOR;
            }
            else if (String.IsNullOrEmpty(thesisRecord.ThesisTitle) && !String.IsNullOrEmpty(invRecord.Title))
            {
                thesisRecord.ThesisTitle  = invRecord.Title;
                viewModel.TitleInputColor = EMPTY_VALUE_COLOR;
            }
            else if (!String.IsNullOrEmpty(thesisRecord.ThesisTitle) && String.IsNullOrEmpty(invRecord.Title))
            {
                viewModel.TitleInputColor = EMPTY_VALUE_COLOR;
            }
            else
            {
                viewModel.TitleInputColor = thesisRecord.ThesisTitle.Equals(invRecord.Title) ? MATCH_VALUE_COLOR : CONFLICT_VALUE_COLOR;
            }

            // Access
            if (String.IsNullOrEmpty(thesisRecord.AccessMode) && String.IsNullOrEmpty(invRecord.Access))
            {
                thesisRecord.AccessMode    = InventoryStore.AccessModeMap[InventoryStore.ACCESS_MODE_RESTRICTED_KEY];
                viewModel.AccessInputColor = CONFLICT_VALUE_COLOR;
            }
            else if (String.IsNullOrEmpty(thesisRecord.AccessMode) && !String.IsNullOrEmpty(invRecord.Access))
            {
                thesisRecord.AccessMode    = invRecord.Access;
                viewModel.AccessInputColor = EMPTY_VALUE_COLOR;
            }
            else
            {
                viewModel.AccessInputColor = thesisRecord.AccessMode.Equals(invRecord.Access) ? MATCH_VALUE_COLOR : CONFLICT_VALUE_COLOR;
            }

            // Received Date
            if (thesisRecord.ReceivedDate == null && invRecord.Received == null)
            {
                thesisRecord.ReceivedDate        = DateTime.Now;
                viewModel.ReceivedDateInputColor = CONFLICT_VALUE_COLOR;
            }
            else if (thesisRecord.ReceivedDate == null && invRecord.Received != null)
            {
                thesisRecord.ReceivedDate        = DateTime.ParseExact(invRecord.Received, DiscContentsProcessor.DEFAULT_DATE_FORMAT, CultureInfo.InvariantCulture);
                viewModel.ReceivedDateInputColor = EMPTY_VALUE_COLOR;
            }
            else
            {
                viewModel.ReceivedDateInputColor = thesisRecord.ReceivedDate.Equals(invRecord.Received) ? MATCH_VALUE_COLOR : CONFLICT_VALUE_COLOR;
            }

            // Prevent loop
            _enableValidation = true;
        }
Esempio n. 26
0
 private void inventoryMatchesComboBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     InventoryStore.getInstance().updateSelectedInventoryRecord((InventoryRecord)this.inventoryMatchesComboBox.SelectedItem);
 }
Esempio n. 27
0
        static void Main(string[] args)
        {
            //number of items which can be added in inventory, can be any number
            var numberOfItems = 100;
            var userInput     = string.Empty;

            //to indicate if adding items to inventory is finished
            bool stageOneFinished = false;

            var currentCart = new List <InventoryModel> {
            };

            //derived classed initialization
            InventoryStore inventory    = new InventoryStore();
            Cart           shoppingCart = new Cart(inventory.items);

            //loop so console application doesn't get closed
            for (int i = 0; i < numberOfItems; i++)
            {
                if (!stageOneFinished)
                {
                    //display message just once, on opening app
                    if (i == 0)
                    {
                        Console.WriteLine("Add items to inventory in expected input format: \nADD sku(number) name(string) quantity(number) price(number i.e 3.5)");
                    }

                    //read user input
                    userInput = Console.ReadLine().ToUpper();

                    //check for user command ADD
                    if (userInput.Contains("ADD"))
                    {
                        //check number of elements in user input, splitted by space
                        if (userInput.Split(' ').Length == 5)
                        {
                            int   sku, quantity;
                            float price;
                            //try parse array elements
                            bool   convertSku      = int.TryParse(userInput.Split(' ')[1], out sku);
                            string name            = userInput.Split(' ')[2].ToLower();
                            bool   convertQuantity = int.TryParse(userInput.Split(' ')[3], out quantity);
                            bool   convertPrice    = float.TryParse(userInput.Split(' ')[4].Replace('.', ','), out price);

                            //check if all elements are succesfully parsed, if yes call add method
                            if (convertSku && convertQuantity && convertPrice)
                            {
                                inventory.Add(sku, name, quantity, price);
                            }
                            else
                            {
                                Console.WriteLine("Add item in expected input format!");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Some input parameters missing!");
                        }
                    }
                    //user END command
                    else if (userInput.Contains("END"))
                    {
                        inventory.End();
                        //set stage one to finished
                        stageOneFinished = true;
                        userInput        = string.Empty;
                    }
                }

                else
                {
                    //display message just once, on proceeding to stage two
                    if (inventory.items.Count == i - 1)
                    {
                        Console.WriteLine("Additem to the current shopping cart in expected input format: \nADD sku(number) quantity(number)");
                    }

                    userInput = Console.ReadLine().ToUpper();

                    if (userInput.Contains("ADD"))
                    {
                        if (userInput.Split(' ').Length == 3)
                        {
                            int  sku, quantity;
                            bool convertSku      = int.TryParse(userInput.Split(' ')[1], out sku);
                            bool convertQuantity = int.TryParse(userInput.Split(' ')[2], out quantity);

                            if (convertSku && convertQuantity)
                            {
                                currentCart = shoppingCart.Add(sku, quantity);
                            }
                            else
                            {
                                Console.WriteLine("Add item in expected input format!");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Some input parameters missing!");
                        }
                    }

                    else if (userInput.Contains("REMOVE"))
                    {
                        if (userInput.Split(' ').Length == 3)
                        {
                            var sku      = int.Parse(userInput.Split(' ')[1]);
                            var quantity = int.Parse(userInput.Split(' ')[2]);

                            currentCart = shoppingCart.Remove(sku, quantity);
                        }
                    }

                    //call cart checkout method
                    else if (userInput.Contains("CHECKOUT"))
                    {
                        shoppingCart.Checkout(currentCart);
                    }

                    //exist console app
                    else if (userInput.Contains("END"))
                    {
                        shoppingCart.End();
                    }
                }
            }
        }