Esempio n. 1
0
        public void SetSortingBy(string type)
        {
            if (!Enum.TryParse(type, true, out SortByType result))
                return;

            SortBy = result;
        }
Esempio n. 2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="sortBy"></param>
 /// <param name="sortByType"></param>
 /// <param name="sortDirection"></param>
 public ClassSorter(string sortBy, SortByType sortByType, SortDirection
                    sortDirection)
 {
     this.sortBy        = sortBy;
     this.sortByType    = sortByType;
     this.sortDirection = sortDirection;
 }
Esempio n. 3
0
        private void SortBySelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            switch ((string)(SortBySelector.SelectedItem as ComboBoxItem).Tag)
            {
            case "Hue":
                sortByType = SortByType.Hue;
                break;

            case "Brightness":
                sortByType = SortByType.Brightness;
                break;

            case "Name":
                sortByType = SortByType.Name;
                break;

            case "RGB":
                sortByType = SortByType.RGB;
                break;

            default:
                sortByType = SortByType.Hue;
                break;
            }
            GenerateColorGrid();
        }
Esempio n. 4
0
        public static string[] GetImagesFromPath(string path, string url, SortByType sortByType)
        {
            url ??= "";

            var saveToPath = Path.Combine(path, url);

            if (!Directory.Exists(saveToPath))
            {
                return(Array.Empty <string>());
            }

            // Get all files
            var files = Directory.GetFiles(saveToPath).Select(s => s);

            if (!files.Any())
            {
                return(Array.Empty <string>());
            }

            var imageExtension = new string[] { ".jpg", ".png", ".gif" };

            files = files.Where(w => imageExtension.Contains(new FileInfo(w).Extension.ToLower()));

            // Filter files by
            files = sortByType == SortByType.Name ? FileHelpers.SortFilesByName(files) : FileHelpers.SortFilesByDate(files);

            // Filtered files to array
            var filteredFiles = files.Select(m => m.Remove(0, m.LastIndexOf('\\') + 1)).ToArray();

            for (var i = 0; i < filteredFiles.Length; i++)
            {
                var oldString = filteredFiles[i];
                if (oldString.Contains('/'))
                {
                    filteredFiles[i] = oldString[oldString.LastIndexOf("/", StringComparison.Ordinal)..].Replace("/", "");
Esempio n. 5
0
 public SourceRequest()
 {
     this.sourceField       = SourceType.Web;
     this.offsetField       = 0;
     this.countField        = 10;
     this.sortByField       = SortByType.Default;
     this.resultFieldsField = ((ResultFieldMask.Title | ResultFieldMask.Description)
                               | ResultFieldMask.Url);
 }
Esempio n. 6
0
        public static Expression <Func <Game, object> > GetExpressionForSorting(SortByType sortType)
        {
            Expression <Func <Game, object> > predicate = null;

            if (sortType == SortByType.Newest)
            {
                predicate = x => x.DateOfAddition;
            }
            if (sortType == SortByType.MostCommented)
            {
                predicate = x => x.Comments.Count();
            }
            if (sortType == SortByType.PriceAsc || sortType == SortByType.PriceDesc)
            {
                predicate = x => x.Price;
            }

            return(predicate);
        }
Esempio n. 7
0
        public static decimal GetTotalOutcome(DateTime date, SortByType sortByType = SortByType.All)
        {
            decimal result = 0;

            switch (sortByType)
            {
            case SortByType.All:
                result = Connection
                         .Table <Transaction>().ToList().
                         Where(t => t.TransactionType == (short)TransactionType.Outcome).
                         Sum(t => t.RealValue);
                break;

            case SortByType.Day:
                result = Connection
                         .Table <Transaction>().ToList().
                         Where(t => t.TransactionType == (short)TransactionType.Outcome &&
                               t.DateOfTransaction.ToLocalTime().Year == date.Year &&
                               t.DateOfTransaction.ToLocalTime().Month == date.Month &&
                               t.DateOfTransaction.ToLocalTime().Day == date.Day).
                         Sum(t => t.RealValue);
                break;

            case SortByType.Month:
                result = Connection
                         .Table <Transaction>().ToList().
                         Where(t => t.TransactionType == (short)TransactionType.Outcome &&
                               t.DateOfTransaction.ToLocalTime().Month == date.Month &&
                               t.DateOfTransaction.ToLocalTime().Month == date.Month).
                         Sum(t => t.RealValue);
                break;

            case SortByType.Year:
                result = Connection
                         .Table <Transaction>().ToList().
                         Where(t => t.TransactionType == (short)TransactionType.Outcome &&
                               t.DateOfTransaction.ToLocalTime().Year == date.Year).
                         Sum(t => t.RealValue);
                break;
            }

            return(result);
        }
Esempio n. 8
0
        // [Authorize(oAppConst.AccessPolicies.LevelTwo)] /// Done
        public async Task <IActionResult> Get(
            int selectedPage,
            int maxNumberPerItemsPage,
            int filterProductStoreId,
            string filterProductCategory,
            string searchValue       = "",
            string filterProductUnit = "",
            string filterStatus      = "",
            bool isAccendingSort     = true,
            SortByType sortByType    = SortByType.product)
        {
            try
            {
                bool.TryParse(filterStatus, out bool boolFilterStatus);
                int.TryParse(filterProductCategory, out int filterProductCategoryId);
                ProductUnitType productUnitType = ProductUnitType.Grams;
                switch (filterProductUnit)
                {
                case nameof(ProductUnitType.Grams):
                    productUnitType = ProductUnitType.Grams;
                    break;

                case nameof(ProductUnitType.Kg):
                    productUnitType = ProductUnitType.Kg;
                    break;

                case nameof(ProductUnitType.PerItem):
                    productUnitType = ProductUnitType.PerItem;
                    break;

                default:
                    filterProductUnit = oAppConst.GetAllRecords;
                    break;
                }
                int totalCount = await DbContext.StoreProducts
                                 .Where(sp => filterProductStoreId.Equals(oAppConst.GetAllRecords)?true : sp.Store.Id == filterProductStoreId)
                                 .Where(sp => filterProductUnit.Equals(oAppConst.GetAllRecords) ? true : sp.Product.Unit == productUnitType)
                                 .Where(sp => filterProductCategory.Equals(oAppConst.GetAllRecords) ? true : sp.Product.Category.Id == filterProductCategoryId)
                                 .CountAsync(sp => searchValue.Equals(oAppConst.GetAllRecords) ? true : (sp.Product.Name.Contains(searchValue) || sp.Product.Id.ToString().Contains(searchValue)))
                                 .ConfigureAwait(false);

                /// Include the necessary properties
                IIncludableQueryable <oStoreProduct, oCategory> product = DbContext.StoreProducts
                                                                          .Include(sp => sp.Store)
                                                                          .Include(sp => sp.Product)
                                                                          .ThenInclude(p => p.Category);

                IQueryable sortedList;
                if (isAccendingSort)
                {
                    sortedList = sortByType switch
                    {
                        SortByType.category => product.OrderBy(sp => sp.Product.Category.Name),
                        SortByType.price => product.OrderBy(sp => sp.Product.Price),
                        SortByType.unit => product.OrderBy(sp => sp.Product.Unit),
                        SortByType.unitQuantity => product.OrderBy(sp => sp.Product.UnitQuantity),
                        SortByType.status => product.OrderBy(sp => sp.Status),
                        _ => product.OrderBy(sp => sp.Product.Name),
                    }
                }
                ;
                else
                {
                    sortedList = sortByType switch
                    {
                        SortByType.category => product.OrderByDescending(sp => sp.Product.Category.Name),
                        SortByType.price => product.OrderByDescending(sp => sp.Product.Price),
                        SortByType.unit => product.OrderByDescending(sp => sp.Product.Unit),
                        SortByType.unitQuantity => product.OrderByDescending(sp => sp.Product.UnitQuantity),
                        SortByType.status => product.OrderByDescending(sp => sp.Status),
                        _ => product.OrderByDescending(sp => sp.Product.Name),
                    }
                };

                List <oStoreProduct> list = await product
                                            .Where(sp => filterProductStoreId.Equals(oAppConst.GetAllRecords)?true : sp.Store.Id == filterProductStoreId)
                                            .Where(sp => filterProductUnit.Equals(oAppConst.GetAllRecords) ? true : sp.Product.Unit == productUnitType)
                                            .Where(sp => filterProductCategory.Equals(oAppConst.GetAllRecords) ? true : sp.Product.Category.Id == filterProductCategoryId)
                                            .Where(sp => searchValue.Equals(oAppConst.GetAllRecords) ? true : (sp.Product.Name.Contains(searchValue) || sp.Product.Id.ToString().Contains(searchValue)))
                                            .Skip((selectedPage - 1) * maxNumberPerItemsPage)
                                            .Take(maxNumberPerItemsPage)
                                            .ToListAsync()
                                            .ConfigureAwait(false);


                //int totalCount = await DbContext.Products
                //    .Where(c => filterProductUnit.Equals(oAppConst.GetAllRecords) ? true : c.Unit == productUnitType)
                //    .Where(c => filterProductCategory.Equals(oAppConst.GetAllRecords) ? true : c.Category.Id == filterProductCategoryId)
                //    .CountAsync(c => searchValue.Equals(oAppConst.GetAllRecords) ? true : c.Name.Contains(searchValue))
                //    .ConfigureAwait(false);

                //List<oProduct> list = await DbContext.Products
                //    .OrderBy(c => c.Name)
                //    .Where(c => filterProductUnit.Equals(oAppConst.GetAllRecords) ? true : c.Unit == productUnitType)
                //    .Where(c => filterProductCategory.Equals(oAppConst.GetAllRecords) ? true : c.Category.Id == filterProductCategoryId)
                //    .Include(t => t.StoreProducts)
                //    .Skip((selectedPage - 1) * maxNumberPerItemsPage)
                //    .Take(maxNumberPerItemsPage)
                //    .ToListAsync()
                //    .ConfigureAwait(false);
                //foreach (oProduct product in list)
                //{
                //    product.StoreProducts = product.StoreProducts.Where(t => t.StoreId == filterProductStoreId).ToList();
                //}
                /// return the list of Categories
                return(Ok(new { list, totalCount }));
            }
 public SourceRequest() {
     this.sourceField = SourceType.Web;
     this.offsetField = 0;
     this.countField = 10;
     this.sortByField = SortByType.Default;
     this.resultFieldsField = ((ResultFieldMask.Title | ResultFieldMask.Description) 
                 | ResultFieldMask.Url);
 }
Esempio n. 10
0
        private void initializeUI()
        {
            try
            {
                this.Width = Globals.ThisAddIn.iTempWidth;
                this.Height = Globals.ThisAddIn.iTempHeight;

                BrightIdeasSoftware.TextOverlay textOverlay = this.listItems.EmptyListMsgOverlay as BrightIdeasSoftware.TextOverlay;
                textOverlay.TextColor = Color.FromArgb(255, 96, 96, 96);
                textOverlay.BackColor = System.Drawing.Color.White;
                textOverlay.BorderWidth = 0;
                textOverlay.InsetY = 0;
                textOverlay.Font = new System.Drawing.Font("Serif", 9);

                rbd = new BrightIdeasSoftware.RowBorderDecoration();
                rbd.BorderPen = new Pen(Color.FromArgb(170, Color.DarkGray), 1);
                rbd.FillBrush = new SolidBrush(Color.FromArgb(40, Color.Black));
                rbd.BoundsPadding = new Size(-2, -2);
                rbd.CornerRounding = 6.0f;
                this.listItems.SelectedRowDecoration = rbd;
                this.listItems.CellToolTip.ReshowDelay = 0;

                alternateRBD = new BrightIdeasSoftware.RowBorderDecoration();
                alternateRBD.BorderPen = new Pen(Color.LightGray, 1);
                alternateRBD.FillBrush = null;
                alternateRBD.BoundsPadding = new Size(2, 0);
                alternateRBD.CornerRounding = 0;

                this.menuitemSortBy.DropDownItems.AddRange(getSortByMenuItems());
                this.menuitemSortBy.DropDownItems.Add(new ToolStripSeparator());
                this.menuitemSortBy.DropDownItems.AddRange(getSortByDirectionMenuItems());
                ((ToolStripMenuItem)this.menuitemSortBy.DropDownItems[Properties.Settings.Default.DEFAULT_SORTBY + ""]).CheckState = CheckState.Indeterminate;
                ((ToolStripMenuItem)this.menuitemSortBy.DropDownItems[Properties.Settings.Default.DEFAULT_SORTBY + ""]).Checked = true;

                this.contextmenuSortBy.Items.AddRange(getSortByMenuItems());
                this.contextmenuSortBy.Items.Add(new ToolStripSeparator());
                this.contextmenuSortBy.Items.AddRange(getSortByDirectionMenuItems());
                ((ToolStripMenuItem)this.contextmenuSortBy.Items[Properties.Settings.Default.DEFAULT_SORTBY + ""]).CheckState = CheckState.Indeterminate;
                ((ToolStripMenuItem)this.contextmenuSortBy.Items[Properties.Settings.Default.DEFAULT_SORTBY + ""]).Checked = true;

                currentSortBy = (SortByType)Properties.Settings.Default.DEFAULT_SORTBY;
                DragSource dragSource = new DragSource();
                this.listItems.DragSource = dragSource;
                dragSource.endDragEvent +=new EndDragDelegate(dragSource_endDragEvent);

                this.treeFolders.ShowNodeToolTips = true;
                this.treeFolders.ShowLines = true;
                this.btnMore.Enabled = false;
                this.btnSearch.BackgroundImageLayout = ImageLayout.Center;
                buildSearchOptionsContextMenu();
                buildFilterFieldsContextMenu();
                buildImageList();
                prepareLayout();
                positionSplitter();
                //將來可能需要加上開關QuickStart的checkbox by Gene
                if (this.chkQuickStartTip.Checked)
                {
                    Properties.Settings.Default.DEFAULT_SHOWQUICKSTART = true;
                }
                try
                {
                    disableClickSounds();
                }
                catch { }
                if (Properties.Settings.Default.DEFAULT_SHOWQUICKSTART)
                {
                    QuickStart quickstart = new QuickStart(Properties.Settings.Default.URL_QUICKSTART);
                    quickstart.Show();
                }
                btnTemplate.PerformClick();
            }
            catch (Exception ex)
            {
                this.log.WriteLine(LogType.Error, "MasterControl::initializeUI", ex.ToString());
            }
        }
Esempio n. 11
0
        private void resetCurrentSortByMenu(SortByType type)
        {
            this.bIsAscending = true;
            foreach (ToolStripMenuItem item in menuitemSortBy.DropDownItems.OfType<ToolStripMenuItem>())
            {
                if (item.Checked)
                    item.Checked = false;

                if (item.Tag + "" == "sortdescending")
                    item.Checked = false;
                else if (item.Tag + "" == "sortascending")
                {
                    item.CheckState = CheckState.Indeterminate;
                    item.Checked = true;
                }
                else if ((SortByType)item.Tag == type)
                {
                    item.Checked = true;
                    item.CheckState = CheckState.Indeterminate;
                }
            }
            foreach (ToolStripMenuItem item in contextmenuSortBy.Items.OfType<ToolStripMenuItem>())
            {
                if (item.Checked)
                    item.Checked = false;

                if (item.Tag + "" == "sortdescending")
                    item.Checked = false;
                else if (item.Tag + "" == "sortascending")
                {
                    item.CheckState = CheckState.Indeterminate;
                    item.Checked = true;
                }
                else if ((SortByType)item.Tag == type)
                {
                    item.Checked = true;
                    item.CheckState = CheckState.Indeterminate;
                }
            }
        }
Esempio n. 12
0
        private void itemSortby_Click(object sender, EventArgs e)
        {
            try
            {
                ToolStripMenuItem currentItem = (ToolStripMenuItem)sender;
                currentSortBy = (SortByType)currentItem.Tag;
                Properties.Settings.Default.DEFAULT_SORTBY = (int)currentSortBy;
                foreach (ToolStripMenuItem item in menuitemSortBy.DropDownItems.OfType<ToolStripMenuItem>())
                {
                    if (item.Checked && item.Tag.ToString() != "sortascending" && item.Tag.ToString() != "sortdescending")
                        item.Checked = false;

                    if (item.Text == currentItem.Text)
                    {
                        item.CheckState = CheckState.Indeterminate;
                        item.Checked = true;
                    }
                }
                foreach (ToolStripMenuItem item in contextmenuSortBy.Items.OfType<ToolStripMenuItem>())
                {
                    if (item.Checked && item.Tag.ToString() != "sortascending" && item.Tag.ToString() != "sortdescending")
                        item.Checked = false;

                    if (item.Text == currentItem.Text)
                    {
                        item.CheckState = CheckState.Indeterminate;
                        item.Checked = true;
                    }
                }
                inputSearch_TextChanged(null, null);
                listItems.Focus();
            }
            catch (Exception ex)
            {
                this.log.WriteLine(LogType.Error, "MasterControl::itemSortby_Click", ex.ToString());
            }
        }
Esempio n. 13
0
        public static Dictionary <string, decimal> GetTotalOutcomePerCategory(DateTime date, SortByType sortByType = SortByType.All)
        {
            Dictionary <string, decimal> result = new Dictionary <string, decimal>();

            switch (sortByType)
            {
            case SortByType.All:
                foreach (var pair in Connection.Table <Transaction>().
                         Where(t => t.TransactionType == (short)TransactionType.Outcome).
                         ToList().
                         GroupBy(t => t.Category).
                         Select(a => new { Name = a.Key, Total = a.Sum(b => b.RealValue) }))
                {
                    result.Add(pair.Name, pair.Total);
                }
                break;

            case SortByType.Day:
                foreach (var pair in Connection.Table <Transaction>().
                         Where(t => t.TransactionType == (short)TransactionType.Outcome).
                         ToList().
                         Where(
                             t => t.DateOfTransaction.ToLocalTime().Year == date.Year &&
                             t.DateOfTransaction.ToLocalTime().Month == date.Month &&
                             t.DateOfTransaction.ToLocalTime().Day == date.Day).
                         GroupBy(t => t.Category).
                         Select(a => new { Name = a.Key, Total = a.Sum(b => b.RealValue) }))
                {
                    result.Add(pair.Name, pair.Total);
                }
                break;

            case SortByType.Month:
                foreach (var pair in Connection.Table <Transaction>().
                         Where(t => t.TransactionType == (short)TransactionType.Outcome).
                         ToList().
                         Where(
                             t => t.DateOfTransaction.ToLocalTime().Year == date.Year &&
                             t.DateOfTransaction.ToLocalTime().Month == date.Month).
                         GroupBy(t => t.Category).
                         Select(a => new { Name = a.Key, Total = a.Sum(b => b.RealValue) }))
                {
                    result.Add(pair.Name, pair.Total);
                }
                break;

            case SortByType.Year:
                foreach (var pair in Connection.Table <Transaction>().
                         Where(t => t.TransactionType == (short)TransactionType.Outcome).
                         ToList().
                         Where(t => t.DateOfTransaction.ToLocalTime().Year == date.Year).
                         GroupBy(t => t.Category).
                         Select(a => new { Name = a.Key, Total = a.Sum(b => b.RealValue) }))
                {
                    result.Add(pair.Name, pair.Total);
                }
                break;
            }

            return(result);
        }
Esempio n. 14
0
 public static decimal GetBalance(DateTime date, SortByType sortByType = SortByType.All)
 {
     return(GetTotalIncome(date, sortByType) - GetTotalOutcome(date, sortByType));
 }