public override async Task <List <Item> > GetPagedItemsAsync(DataGridParameters currentDataGridParameters) //int startPage, int currentPageSize) { IItemRepository _ItemRepository = _AppUnitOfWork.itemRepository(); DataGridItems <Item> _dataGridItems = await _ItemRepository.GetPagedDataEagerWithFilterAndOrderByAsync(currentDataGridParameters); List <Item> _Items = _dataGridItems.Entities.ToList(); _GridSettings.TotalItems = _dataGridItems.TotalRecordCount; return(_Items); }
public override async Task <List <ItemCategoryLookup> > GetPagedItemsAsync(DataGridParameters currentDataGridParameters) //int startPage, int currentPageSize) { IItemCategoryLookupRepository _itemCategoryLookupRepository = _AppUnitOfWork.itemCategoryLookupRepository(); //_gridSettings.TotalItems = await _itemCategoryLookupRepository.CountAsync(); // get the total number of items to use for paging. DataGridItems <ItemCategoryLookup> _dataGridItems = await _itemCategoryLookupRepository.GetPagedDataEagerWithFilterAndOrderByAsync(currentDataGridParameters); List <ItemCategoryLookup> _itemCategoryLookups = _dataGridItems.Entities.ToList(); _GridSettings.TotalItems = _dataGridItems.TotalRecordCount; return(_itemCategoryLookups); }
// Combox 选中修改函数 private void detailProcessName_SelectionChanged(object sender, SelectionChangedEventArgs e) { string strProcessName; // 选中一个进程名 加载所有记录信息 ComboBoxItem item = detailProcessName.SelectedItem as ComboBoxItem; if (item == null) // 我们删除combobox项也会触发SeletedChanged { return; } strProcessName = item.Content.ToString(); DirectoryInfo directoryInfo = new DirectoryInfo(System.Environment.CurrentDirectory + "\\record"); FileInfo[] fileInfo = directoryInfo.GetFiles(); DataGridItems.Clear(); foreach (FileInfo file in fileInfo) { if (string.Equals(file.Name.Substring(0, strProcessName.Length), strProcessName, StringComparison.OrdinalIgnoreCase) && file.Name.Substring(strProcessName.Length, 1).Equals("-")) { writeRecordFile(file.DirectoryName + "\\" + file.Name, strProcessName, "PID:" + file.Name.Substring(strProcessName.Length + 1, file.Name.LastIndexOf('.') - strProcessName.Length - 1)); Thread.Sleep(10); // 文件流 快速读取会出错 } } // 更新source 刷新列表 runTimeList.DataContext = DataGridItems; // 计算总时间 更新StatusBar // ---> 想法预留 把过去遗留的文件合并 软件多次开启 肯定会残留大量短小文件 到一定程度 应该把他们合并 // - 合并只保留这几个文件里记录的总运行时间 放入一个文件 进程名-Old.txt TimeSpan TempTime; TimeSpan AllRunningTime = new TimeSpan(); foreach (DataGridItem Temp in DataGridItems) { if (Temp.runningTime == null || Temp.runningTime == "error ending" || Temp.runningTime == "still running") { continue; } TempTime = TimeSpan.Parse(Temp.runningTime); AllRunningTime += TempTime; } this.runningTime.Text = "已经运行: " + AllRunningTime.ToString(); return; }
private bool addNewItem(params string[] items) { DataGridItem newItem = new DataGridItem(); int num = 0; foreach (string item in items) { switch (num) { case 0: { newItem.Identification = item; break; } case 1: { newItem.startingTime = item; break; } case 2: { newItem.endingTime = item; break; } case 3: { newItem.runningTime = item; break; } } num++; } DataGridItems.Add(newItem); return(true); }
public async Task <DataGridItems <ItemAttributeLookup> > GetPagedDataEagerWithFilterAndOrderByAsync(DataGridParameters currentDataGridParameters) // (int startPage, int currentPageSize) { DataGridItems <ItemAttributeLookup> _dataGridData = null; DbSet <ItemAttributeLookup> _table = _Context.Set <ItemAttributeLookup>(); try { _Logger.LogDebug($"Getting all records with eager loading of ItemAttributeLookup order by an filter Data Grid Parameters: {currentDataGridParameters.ToString()}"); // get a list of Order bys and filters List <OrderByParameter <ItemAttributeLookup> > _orderByExpressions = GetOrderByExpressions(currentDataGridParameters.SortParams); List <Expression <Func <ItemAttributeLookup, bool> > > _filterByExpressions = GetFilterByExpressions(currentDataGridParameters.FilterParams); // start with a basic Linq Query with Eager loading IQueryable <ItemAttributeLookup> _query = _table.Include(ial => ial.ItemAttributeVarietyLookups.Take(AppUnitOfWork.CONST_MAX_DETAIL_PAGES)); //only take the first 50 if ((_orderByExpressions != null) && (_orderByExpressions.Count > 0)) { // add order bys if (_orderByExpressions.Count == 1) { _query = _orderByExpressions[0].IsAscending ? _query.OrderBy(_orderByExpressions[0].OrderByExperssion) : _query.OrderByDescending(_orderByExpressions[0].OrderByExperssion); } else // we are only catering for one ThenBy, we could add more if else's here { _query = _orderByExpressions[0].IsAscending ? (_orderByExpressions[1].IsAscending ? _query.OrderBy(_orderByExpressions[0].OrderByExperssion).ThenBy(_orderByExpressions[1].OrderByExperssion) : _query.OrderBy(_orderByExpressions[0].OrderByExperssion).ThenByDescending(_orderByExpressions[1].OrderByExperssion)) : (_orderByExpressions[1].IsAscending ? _query.OrderByDescending(_orderByExpressions[0].OrderByExperssion).ThenBy(_orderByExpressions[1].OrderByExperssion) : _query.OrderByDescending(_orderByExpressions[0].OrderByExperssion).ThenByDescending(_orderByExpressions[1].OrderByExperssion)); } } else // default sort { _query = _query.OrderBy(ial => ial.OrderBy); } //This is functionally comes from //https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/expression-trees/how-to-use-expression-trees-to-build-dynamic-queries //now the per column filters if (!String.IsNullOrEmpty(currentDataGridParameters.CustomFilter) || _filterByExpressions != null) { Expression <Func <ItemAttributeLookup, bool> > _queryWhere = PredicateBuilder.New <ItemAttributeLookup>(true); if (!String.IsNullOrEmpty(currentDataGridParameters.CustomFilter)) { _queryWhere = _queryWhere.And(ial => ((ial.AttributeName.ToLower().Contains(currentDataGridParameters.CustomFilter)) || (ial.Notes.ToLower().Contains(currentDataGridParameters.CustomFilter)))); } if (_filterByExpressions != null) { foreach (var flt in _filterByExpressions) { _queryWhere = _queryWhere.And(flt); } } _query = _query.Where(_queryWhere); // (_queryWhere); } //now we can add the page stuff - first get the count to return _dataGridData = new DataGridItems <ItemAttributeLookup>(); _dataGridData.TotalRecordCount = _query.Count(); _query = _query .Skip((currentDataGridParameters.CurrentPage - 1) * currentDataGridParameters.PageSize) .Take(currentDataGridParameters.PageSize); // take 3 pages at least. // and execute _dataGridData.Entities = await _query.ToListAsync(); } catch (Exception ex) { _AppUnitOfWork.LogAndSetErrorMessage($"!!!Error Getting all records from ItemAttributeLookupRepository: {ex.Message} - Inner Exception {ex.InnerException}"); #if DebugMode throw; // #Debug? #endif } return(_dataGridData); }
// 删除监视 private void deleteMonitor_Click(object sender, RoutedEventArgs e) { // 移除combox选项 if (detailProcessName.SelectedItem == null) { MessageBox.Show("请选择一个监视进程", "警告"); return; } string deleteProcessName = (string)((ComboBoxItem)detailProcessName.SelectedItem).Content; // 保存string detailProcessName.Items.RemoveAt(detailProcessName.SelectedIndex); // 修改ini文件 ulong processMonitorNumber = 0; processMonitorNumber = GetPrivateProfileInt("monitor", "number", 0, inifilePath); StringBuilder strProcessName = new StringBuilder(255); bool bIsMove = false; // 删除 ini中的监视条目 --- 不能是简单的删除 不然下次遍历的时候 就会少遍历 中间缺失了一项 // 所以我们在遍历的时候 在删除指定条目后 要将后面的向前移动 不能出现key的缺失情况 for (ulong i = 1; i <= processMonitorNumber; i++) // ! <= { GetPrivateProfileString("monitor", i.ToString(), "", strProcessName, 255, inifilePath); if (bIsMove) //删除后面的键值往前移动 { // 首先得到自己的KEY值 GetPrivateProfileString("monitor", i.ToString(), "", strProcessName, 255, inifilePath); // 写入到上一个key WritePrivateProfileString("monitor", (i - 1).ToString(), strProcessName.ToString(), inifilePath); continue; } if (strProcessName.Equals(deleteProcessName)) // 找到要删除的那个key { bIsMove = true; // 告诉后面的key值往前移动 通过覆盖来删除 } } // 删除最后一个key WritePrivateProfileString("monitor", processMonitorNumber.ToString(), null, inifilePath); // 修改监视个数 processMonitorNumber--; if (!WritePrivateProfileString("monitor", "number", processMonitorNumber.ToString(), inifilePath)) { System.Windows.MessageBox.Show("revise monitor number failed"); } // 从监视列表中删除 lock (monitorlist) { foreach (MonitorNode monitorNode in monitorlist) { if (monitorNode.ProcessName.Equals(deleteProcessName, StringComparison.InvariantCultureIgnoreCase)) { monitorlist.Remove(monitorNode); break; } } } // 清空list DataGridItems.Clear(); viewSource.Source = DataGridItems; runTimeList.DataContext = viewSource; }
// DataGrid 菜单条目 // list菜单处理函数 private void deleteItem_Click(object sender, RoutedEventArgs e) { // 拷贝一份listView ObservableCollection <DataGridItem> temp = new ObservableCollection <DataGridItem>(DataGridItems); int index = runTimeList.SelectedIndex; if (index == -1) { System.Windows.MessageBox.Show("未选中条目"); return; } DataGridItems.Clear(); temp.RemoveAt(index); // 修改文件 List <string> txtLine; FileStream fs; StreamWriter streamWriter; String strTemp; byte[] Byte; // TXT文件操作 要全部注意编码问题 标识UTF-8 ComboBoxItem item = detailProcessName.SelectedItem as ComboBoxItem; if (item == null) // 我们删除combobox项也会触发SeletedChanged { return; } string strRecordFileName = recordDirectory + "\\" + item.Content.ToString() + ".txt"; if (IsFileExists(strRecordFileName)) { txtLine = new List <String>(File.ReadAllLines(strRecordFileName, Encoding.UTF8)); // 将所有数据读出来 为修改准备 txtLine.RemoveAt(index); // 移除一行 fs = File.Open(strRecordFileName, FileMode.Create, FileAccess.ReadWrite); // 创建同名文件 覆盖原文件 streamWriter = new StreamWriter(fs, Encoding.UTF8); foreach (string strline in txtLine) // 一行行写入文件中 { strTemp = strline + '\n'; // 每行末尾的 \n Byte = System.Text.Encoding.UTF8.GetBytes(strTemp); fs.Write(Byte, 0, Byte.Length); } fs.Close(); } else { System.Windows.MessageBox.Show("无法修改文件"); } // 将temp送回ListviewItem 然后更新列表 DataGridItems = temp; viewSource.Source = DataGridItems; runTimeList.DataContext = viewSource; return; }