/// <summary> /// Button click that initiates a search for diffrent locations. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void Button_Click(object sender, RoutedEventArgs e) { ListBoxItems.Clear(); XmlManager.LocationSheetList locationSheetList = new XmlManager.LocationSheetList(); //Make sure to not block UI await Task.Run(() => { try { locationSheetList = WebServiceAPIContext.ReceiveLocationList(_SearchLocation, _ConnectionString); } catch (Exception ex) { ShowErrorMessageBox(ex.Message); } if (locationSheetList.Error && locationSheetList.ExMsg != String.Empty) { ShowErrorMessageBox(locationSheetList.ExMsg); } }); if (locationSheetList.LocationSheets != null) { foreach (var x in locationSheetList.LocationSheets) { Encoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(x.Name)); ListBoxItems.Add(x); } } }
public void AddItem() { ListBoxItems.Add(new PUListBoxItemModel() { Header = "Line" + (ListBoxItems.Count + 1), Value = (ListBoxItems.Count + 1), }); }
private void InitCommand(Random random) { ListBoxItems.Clear(); var json = File.ReadAllText(@"Resources\json\block.json"); List <Block> blockLists = JsonConvert.DeserializeObject <List <Block> >(json); foreach (Block block in blockLists) { var contentItems = new ContentItems() { MetorInfos = new ObservableCollection <MetorInfo>() }; List <MetorInfo> data = block.data; foreach (MetorInfo metorInfo in data) { //new TransitionEffect().LetterNCircle(); var metor = new MetorInfo { Name = metorInfo.Name, Color = metorInfo.Color, Width = metorInfo.Width, Height = metorInfo.Height, View = metorInfo.View, Effect = new TransitionEffect() { Kind = kinds[random.Next(0, kinds.Count)], Duration = new TimeSpan(0, 0, 0, 0, 10) } }; contentItems.MetorInfos.Add(metor); } ListBoxItems.Add(contentItems); } //for (int i = 0; i < 2; i++) //{ // var contentItems = new ContentItems() { MetorInfos = new ObservableCollection<MetorInfo>() }; // for (int j = 0; j < 5; j++) // { // //var metorInfos = new ObservableCollection<MetorInfo>(); // var metor = new MetorInfo // { // Name = "应用" + j, // Color = new SolidColorBrush((Color)ColorConverter.ConvertFromString(colors[random.Next(0, colors.Count)])), // Width = random.Next(0, 8) < 4 ? 314 : 150, // Height = 150, // Effect = new TransitionEffect() // { // Kind = kinds[random.Next(0, kinds.Count)], // Duration = new TimeSpan(0, 0, 0, 0, 900) // } // }; // contentItems.MetorInfos.Add(metor); // } // ListBoxItems.Add(contentItems); //} }
public void LoadPlayListFromFile() { var serializer = new Serializer(); var pathList = serializer.DeserializeFromFile(); foreach (var item in pathList) { var songItem = GetSongInfo(item); ListBoxItems.Add(songItem); } }
/// <summary> /// Adds a new element to the combo /// </summary> /// <param name="item">item to add</param> /// <param name="index">position to adding</param> public int AddItem(object item, int index = -1) { var newItem = CreateItem(item); if (index == -1 || index == ListBoxItems.Count) { ListBoxItems.Add(newItem); return(ListBoxItems.Count - 1); } ListBoxItems.Insert(index, newItem); return(index); }
/// <summary> /// 获取初始数据 /// </summary> /// <param name="element"></param> private void AddRing(string ring) { try { ListBoxItem item = new ListBoxItem(); //加载资源字典 string packUri = @"/LifeService;component/WindowDictionary.xaml"; ResourceDictionary myResourceDictionary = Application.LoadComponent(new Uri(packUri, UriKind.Relative)) as ResourceDictionary; item.SetValue(ListBoxItem.StyleProperty, myResourceDictionary["OnlyBackgroundListBoxItemStyle"]); AlarmClockRingItemView clockView = new AlarmClockRingItemView(); AlarmClockRingItemViewModel clockViewModel = new AlarmClockRingItemViewModel(ring); clockViewModel.BackToMainView = ArrivedAtMainView; clockView.DataContext = clockViewModel; item.Content = clockView; ListBoxItems.Add(item); } catch (Exception e) { LogWriter.Instance.Error(e); } }
/// <summary> /// 添加闹钟 /// </summary> /// <param name="element"></param> /// <param name="model"></param> private void AddNewReminder(ListBox element, AlarmClockModel model) { try { ListBoxItem item = new ListBoxItem(); //加载资源字典 string packUri = @"/LifeService;component/WindowDictionary.xaml"; ResourceDictionary myResourceDictionary = Application.LoadComponent(new Uri(packUri, UriKind.Relative)) as ResourceDictionary; item.SetValue(ListBoxItem.StyleProperty, myResourceDictionary["NoBackgroundListBoxItemStyle"]); AlarmClockView clockView = new AlarmClockView(element); AlarmClockViewModel clockViewModel = new AlarmClockViewModel(); clockViewModel.DeleteFromListBox = DeleteFormListBox; clockViewModel.FetchData(model); clockView.DataContext = clockViewModel; item.Content = clockView; ListBoxItems.Add(item); } catch (Exception e) { LogWriter.Instance.Error(e); } }
private void InitializeComponent() { AvaloniaXamlLoader.Load(this); #region Designer PEM20_Button = this.FindControl <Button>("PEM20_Button"); PEM21_Button = this.FindControl <Button>("PEM21_Button"); PEM22_Button = this.FindControl <Button>("PEM22_Button"); PEM20_Path = this.FindControl <TextBlock>("PEM20_Path"); PEM21_Path = this.FindControl <TextBlock>("PEM21_Path"); PEM22_Path = this.FindControl <TextBlock>("PEM22_Path"); PEM20_ListBox = this.FindControl <ListBox>("PEM20_ListBox"); PEM21_ListBox = this.FindControl <ListBox>("PEM21_ListBox"); PEM22_ListBox = this.FindControl <ListBox>("PEM22_ListBox"); TimestampPicker = this.FindControl <DatePicker>("TimestampPicker"); UploadNotification = this.FindControl <TextBlock>("UploadNotification"); UploadDatabases = this.FindControl <Button>("UploadDatabases"); LoadAll = this.FindControl <Button>("LoadAll"); Analyse = this.FindControl <Button>("Analyse"); #endregion Designer PEM20_Button.Click += async(sender, e) => { OpenFileDialog openFileDialog = new OpenFileDialog { Title = "Open PEM 20 database" }; string[] files = await openFileDialog.ShowAsync(this); if (files.Any()) { PEM20_Path.Text = string.Join("; ", files).Replace("%20", " "); } }; PEM21_Button.Click += async(sender, e) => { OpenFileDialog openFileDialog = new OpenFileDialog { Title = "Open PEM 21 database" }; string[] files = await openFileDialog.ShowAsync(this); if (files.Any()) { PEM21_Path.Text = string.Join("; ", files).Replace("%20", " "); } }; PEM22_Button.Click += async(sender, e) => { OpenFileDialog openFileDialog = new OpenFileDialog { Title = "Open PEM 22 database" }; string[] files = await openFileDialog.ShowAsync(this); if (files.Any()) { PEM22_Path.Text = string.Join("; ", files).Replace("%20", " "); } }; UploadDatabases.Click += async(sender, e) => { Task t = new Task(async() => { string pickerTime = (TimestampPicker.SelectedDate ?? DateTime.Now).ToString("yyyyMMddhhmm"); TextWriter textWriter = new StreamWriter(File.OpenWrite("ssh.log")); using (SshClient ssh = new SshClient(ConfigurationManager.AppSettings["Host"], ConfigurationManager.AppSettings["Username"], ConfigurationManager.AppSettings["Password"])) { ssh.Connect(); void RunCommand(string command) { textWriter.WriteLine(command); SshCommand cmd = ssh.RunCommand(command); if (string.IsNullOrWhiteSpace(cmd.Error)) { textWriter.WriteLine(cmd.Result); } else { textWriter.WriteLine(cmd.Error); } } RunCommand($"mkdir { pickerTime }"); RunCommand($"mkdir -p { pickerTime }/PEM\\ 20"); RunCommand($"mkdir -p { pickerTime }/PEM\\ 21"); RunCommand($"mkdir -p { pickerTime }/PEM\\ 22"); ssh.Disconnect(); } await textWriter.FlushAsync(); using (SftpClient sftp = new SftpClient(ConfigurationManager.AppSettings["Host"], ConfigurationManager.AppSettings["Username"], ConfigurationManager.AppSettings["Password"])) { sftp.Connect(); void UploadFileAsync(TextBlock databasePath, string remotePath) { foreach (FileInfo file in databasePath.Text.Split(separator: ";".ToCharArray(), options: StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).Where(x => File.Exists(x)).Select(x => new FileInfo(x))) { string remoteFile = $"{ pickerTime }/{ remotePath }/{ file.Name }"; textWriter.WriteLine($"sftp { file.FullName } {remoteFile}"); try { sftp.UploadFile(file.OpenRead(), remoteFile); } catch (Exception ex) { textWriter.WriteLine(ex.Message); } } } UploadFileAsync(PEM20_Path, "PEM 20"); UploadFileAsync(PEM21_Path, "PEM 21"); UploadFileAsync(PEM22_Path, "PEM 22"); sftp.Disconnect(); } await textWriter.FlushAsync(); textWriter.Close(); }); t.Start(); await t; UploadNotification.Text = "Uploaded"; }; LoadAll.Click += async(sender, e) => { OpenFolderDialog openFolderDialog = new OpenFolderDialog { Title = "Open databases folder" }; string directory = await openFolderDialog.ShowAsync(this); if (Directory.Exists(directory)) { var files = Directory.EnumerateDirectories(directory).Select(x => new { PEM_No = Regex.Match(x, "PEM\\s\\d{2}").Value, Files = Directory.EnumerateFiles(x).Where(y => !y.Contains("_database") && !y.Contains("database-shm") && !y.Contains("database-wal")) }); foreach (var folder in files) { if (folder.Files.Any()) { switch (folder.PEM_No) { case "PEM 20": PEM20_Path.Text = string.Join("; ", folder.Files); break; case "PEM 21": PEM21_Path.Text = string.Join("; ", folder.Files); break; case "PEM 22": PEM22_Path.Text = string.Join("; ", folder.Files); break; } } } } }; Analyse.Click += (sender, e) => { LoadDatabase(PEM20_Path, PEM20_ListBox); LoadDatabase(PEM21_Path, PEM21_ListBox); LoadDatabase(PEM22_Path, PEM22_ListBox); void LoadDatabase(TextBlock path, ListBox list) { IEnumerable <string> databases = path.Text.Split(separator: ";".ToCharArray(), options: StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).Where(x => File.Exists(x)); foreach (string pathT in databases) { SQLiteConnection connection = new SQLiteConnection($"Data Source={ pathT }"); connection.Open(); GetData(connection, list.Items as IList); } } void GetData(SQLiteConnection connection, IList ListBoxItems) { try { SQLiteCommand command = connection.CreateCommand(); command.CommandText = "SELECT id, key as \"Activity ID\", userId as \"User\", time(totalTime/1000, \"unixepoch\") AS \"Time\" FROM activity WHERE totalTime IS NOT NULL ORDER BY userId, id"; Activity[] data = command.ExecuteReader().OfType <IDataRecord>().Select(x => new Activity { ID = int.Parse(x["id"].ToString()), ActivityID = x["Activity ID"].ToString(), User = x["User"].ToString(), Time = x["Time"].ToString() }).ToArray(); IEnumerable <CombinedActivity> combined = data.FullJoin(second: Activities, firstKeySelector: x => x.ActivityID, secondKeySelector: x => x.Key, firstSelector: x => new CombinedActivity { ID = x.ID, ActivityID = x.ActivityID, Time = TimeSpan.Parse(x.Time), User = x.User, ProperTime = TimeSpan.FromSeconds(0) }, secondSelector: x => new CombinedActivity { ID = -1, ActivityID = x.Key, Time = TimeSpan.FromSeconds(0), User = "******", ProperTime = x.Value }, bothSelector: (x, y) => new CombinedActivity { ID = x.ID, ActivityID = x.ActivityID, Time = TimeSpan.Parse(x.Time), User = x.User, ProperTime = y.Value }); #region Label { ListBoxItem lbi = new ListBoxItem(); ListBoxItems.Add(lbi); Grid grid = new Grid(); lbi.Content = grid; grid.ColumnDefinitions.Add(new ColumnDefinition(12, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(30, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(12, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(60, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(12, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(40, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(12, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(80, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(12, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(1, GridUnitType.Auto)); grid.ColumnDefinitions.Add(new ColumnDefinition(12, GridUnitType.Pixel)); grid.RowDefinitions.Add(new RowDefinition(12, GridUnitType.Pixel)); grid.RowDefinitions.Add(new RowDefinition(1, GridUnitType.Auto)); grid.RowDefinitions.Add(new RowDefinition(12, GridUnitType.Pixel)); TextBlock id = new TextBlock { Text = "ID" }; Grid.SetColumn(id, 1); Grid.SetRow(id, 1); grid.Children.Add(id); TextBlock aid = new TextBlock { Text = "Activity ID" }; Grid.SetColumn(aid, 3); Grid.SetRow(aid, 1); grid.Children.Add(aid); TextBlock usr = new TextBlock { Text = "User" }; Grid.SetColumn(usr, 5); Grid.SetRow(usr, 1); grid.Children.Add(usr); TextBlock time = new TextBlock { Text = "Time" }; Grid.SetColumn(time, 7); Grid.SetRow(time, 1); grid.Children.Add(time); TextBlock proper = new TextBlock { Text = "ProperTime" }; Grid.SetColumn(proper, 9); Grid.SetRow(proper, 1); grid.Children.Add(proper); lbi.IsEnabled = false; } #endregion Label foreach (CombinedActivity record in combined) { ListBoxItem lbi = new ListBoxItem(); ListBoxItems.Add(lbi); Grid grid = new Grid(); lbi.Content = grid; grid.ColumnDefinitions.Add(new ColumnDefinition(12, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(30, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(12, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(60, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(12, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(40, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(12, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(80, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(12, GridUnitType.Pixel)); grid.ColumnDefinitions.Add(new ColumnDefinition(1, GridUnitType.Auto)); grid.ColumnDefinitions.Add(new ColumnDefinition(12, GridUnitType.Pixel)); grid.RowDefinitions.Add(new RowDefinition(12, GridUnitType.Pixel)); grid.RowDefinitions.Add(new RowDefinition(1, GridUnitType.Auto)); grid.RowDefinitions.Add(new RowDefinition(12, GridUnitType.Pixel)); TextBlock id = new TextBlock { Text = record.ID.ToString() }; Grid.SetColumn(id, 1); Grid.SetRow(id, 1); grid.Children.Add(id); TextBlock aid = new TextBlock { Text = record.ActivityID }; Grid.SetColumn(aid, 3); Grid.SetRow(aid, 1); grid.Children.Add(aid); TextBlock usr = new TextBlock { Text = record.User }; Grid.SetColumn(usr, 5); Grid.SetRow(usr, 1); grid.Children.Add(usr); TextBlock time = new TextBlock { Text = record.Time.ToString() }; Grid.SetColumn(time, 7); Grid.SetRow(time, 1); grid.Children.Add(time); TextBlock proper = new TextBlock { Text = record.ProperTime.ToString() }; Grid.SetColumn(proper, 9); Grid.SetRow(proper, 1); grid.Children.Add(proper); lbi.Tapped += (tapped, ev) => { JoinCheck joinCheck = new JoinCheck(connection, record); joinCheck.Show(); }; } } finally { connection.Close(); } } }; TimestampPicker.SelectedDate = DateTime.Now; }
private void button_River_Click(object sender, RoutedEventArgs e) { ListBoxItems.Clear(); Rivers.ForEach(i => ListBoxItems.Add(i)); }
public void OnNew() { Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog(); openFileDialog.Multiselect = true; openFileDialog.Filter = "Bilder (*.BMP;*.JPG;*.GIF;*PNG;*JPEG)|*.BMP;*.JPG;*.GIF;*PNG;*JPEG|Video (*.mp4; *.avi;*.mpeg)|*.mp4;*.avi;*.mpeg|All files (*.*)|*.*"; openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); if (openFileDialog.ShowDialog() == true) { foreach (var file in openFileDialog.FileNames) { FileInfo fileInfo = new FileInfo(file); FileArt fileart; Filetype filetyp; switch (fileInfo.Extension.ToLower().Trim('.')) { case "jpeg": case "jpg": fileart = FileArt.Bild; filetyp = Filetype.JPEG; break; case "bmp": fileart = FileArt.Bild; filetyp = Filetype.BMP; break; case "png": fileart = FileArt.Bild; filetyp = Filetype.PNG; break; case "mp4": fileart = FileArt.Video; filetyp = Filetype.MP4; break; case "avi": fileart = FileArt.Video; filetyp = Filetype.AVI; break; default: fileart = FileArt.KeineDef; filetyp = Filetype.KeineDef; break; } if (fileart == FileArt.Bild) { Bitmap Biap = new Bitmap(file); //System.Diagnostics.Debug.WriteLine("File:" + file + " Breite:" + Biap.Width.ToString() + " Höhe:" + Biap.Height + " Verhältniss Bild:"+ (Biap.Width / Biap.Height).ToString() + " Verhätniss Fenster:" + (PresentationViewModelProp.Width/PresentationViewModelProp.Height).ToString()); } var item = new ListElementViewModel() { Filename = new Uri(file), Name = fileInfo.Name.Substring(0, fileInfo.Name.IndexOf('.')), ScrollOffset = 0, Art = fileart, Typ = filetyp, Height = PresentationViewModelProp.Height, Widht = PresentationViewModelProp.Width }; ListBoxItems.Add(item); item.PropertyChanged += ListElementPropertyChanged; } } }
public void OnLoad(string filename = "") { Microsoft.Win32.OpenFileDialog openDialog = new Microsoft.Win32.OpenFileDialog(); FileStream fs = null; if (filename == "") { openDialog.Filter = "Textfile (*.txt;|*.txt;)"; openDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (openDialog.ShowDialog() == true) { fs = new FileStream(openDialog.FileName, FileMode.Open, FileAccess.Read); } } else { fs = new FileStream(filename, FileMode.Open, FileAccess.Read); } if (fs != null) { using (StreamReader sr = new StreamReader(fs)) { while (sr.Peek() != -1) { var line = sr.ReadLine(); string[] elements = line.Split(new char[] { '#' }); if (File.Exists(elements[0].Remove(0, 8))) { FileInfo fileInfo = new FileInfo(elements[0].Remove(0, 8)); FileArt fileart; Filetype filetyp; switch (fileInfo.Extension.ToLower().Trim('.')) { case "jpeg": case "jpg": fileart = FileArt.Bild; filetyp = Filetype.JPEG; break; case "bmp": fileart = FileArt.Bild; filetyp = Filetype.BMP; break; case "png": fileart = FileArt.Bild; filetyp = Filetype.PNG; break; case "mp4": fileart = FileArt.Video; filetyp = Filetype.MP4; break; case "avi": fileart = FileArt.Video; filetyp = Filetype.AVI; break; default: fileart = FileArt.KeineDef; filetyp = Filetype.KeineDef; break; } var item = new ListElementViewModel() { Filename = new Uri(elements[0].Remove(0, 8)), Name = fileInfo.Name.Substring(0, fileInfo.Name.IndexOf('.')), ScrollOffset = Convert.ToDouble(elements[1]), Art = fileart, Typ = filetyp, Spiegeln = Convert.ToBoolean(elements[2]), Widht = Convert.ToDouble(elements[3]), Height = Convert.ToDouble(elements[4]) }; ListBoxItems.Add(item); item.PropertyChanged += ListElementPropertyChanged; } } } } }