private void Btn_confirm(object sender, RoutedEventArgs e) { Label lbl = (sender as Label); Grid grid = (Grid)lbl.Parent; CommentObj c = Model.comments[int.Parse(cmt.id)]; TextBox t = ((TextBox)grid.FindName("commentText")); if (delete) { t.Text = "This comment has been deleted"; c.deleted = "1"; } else if (edit) { Edit.Visibility = Visibility.Visible; Delete.Visibility = Visibility.Visible; } c.edit(t.Text); setEditedVisible(c.editedDate, c.editedTime); Model.WriteCommentsToFile(false); Confirm.Visibility = Visibility.Hidden; Cancel.Visibility = Visibility.Hidden; edit = delete = false; t.BorderBrush = System.Windows.Media.Brushes.Transparent; t.IsReadOnly = true; }
/// <summary> /// /// </summary> /// <param name="comment"></param> /// <param name="ico"> expects complete path to icon file</param> /// <param name="user"></param> public ViewSingleCommentTemplate(CommentObj c) { InitializeComponent(); cmt = c; delete = edit = false; commentText.Text = c.commentText; commentDate.Content = c.commentDate; commentTime.Content = c.commentTime; // commentUserIco.Source = Model.users[c.userName].userIco; delayed source creation commentUserIco.Source = Constants.PathToSource(Constants.Paths_Images.getImagesUserIconsPath() + Model.users[c.userName].userIco); commentUserName.Content = c.userName; RecipeLink.Content = c.parentRecipe; if (c.editedDate.Length > 0) { setEditedVisible(c.editedDate, c.editedTime); } if (cmt.deleted == "1" || Model.user == null || !Model.user.userName.Equals(c.userName)) {//true Edit.Visibility = Visibility.Hidden; Delete.Visibility = Visibility.Hidden; } }
public void GetCommentsFromFile() { Trace.WriteLine("opening comments file at " + Constants.Paths_Data.GetCommentsFilePath()); StreamReader file = new StreamReader(Constants.Paths_Data.GetCommentsFilePath()); string line; file.ReadLine(); List <string[]> commentStrings = new List <string[]>(); while ((line = file.ReadLine()) != null) { //id date_time userName recipe content String[] comment = line.Split('\t'); commentStrings.Add(comment); } foreach (String[] comment in commentStrings) { CommentObj commentObj = new CommentObj(comment); int id = int.Parse(commentObj.id); nextCommentId = Math.Max(nextCommentId, id + 1); comments.Add(id, commentObj); } //associate with users foreach (int key in comments.Keys) { CommentObj c = comments[key]; try { Model.recipes[c.parentRecipe].AddComment(c); Trace.WriteLine(string.Format("adding comment for user {0} to userObj {1}", c.userName, Model.users[c.userName].userName)); Model.users[c.userName].AddComment(c); }catch (KeyNotFoundException ex) { Trace.WriteLine(ex.Message); Trace.WriteLine(ex.StackTrace); } } //associate with recipes }
public void Btn_Send(object sender, RoutedEventArgs e) { Trace.WriteLine("comment send"); //id date_time userName recipe content int key = Model.nextCommentId++; string localDate = GetDateTime(); string user = Model.user.userName; string recipe = recipeName.Text; string comment = commentText.Text; CommentObj c = new CommentObj(new string[] { "" + key, localDate, "_", "0", user, recipe, comment }); Model.comments.Add(key, c); Model.recipe.AddComment(c); Model.user.AddComment(c); MainWindow._viewCommentHistory.ConfigComments(); Model.WriteCommentsToFile(true); commentsList.Children.Add(new ViewSingleCommentTemplate(c)); commentText.Text = ""; MainWindow._viewMain.ancestor.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); MainWindow._viewMain.maxOffset_Y -= MainWindow._viewMain.ancestor.ActualHeight; Common.updateOffset(new Point(0, MainWindow._viewMain.maxOffset_Y), MainWindow._viewComment); // Switcher.Switch(MainWindow.Views.favorites); }
public void AddComment(CommentObj c) { Trace.WriteLine(string.Format("adding comment {0} {1} to user {2}", c.id, c.commentText, c.userName)); comments.Add(c); }
public void AddComment(CommentObj c) { comments.Add(c); }