Exemple #1
0
 public EditForum(Forum ForumToEdit)
 {
     TempForum = ForumToEdit;
     InitializeComponent();
     ForumTextBox.Focus();
     ForumTextBox.Text = ForumToEdit.ForumName;
 }
Exemple #2
0
 public AddForum( Forum ForumToAdd)
 {
     TempForum = ForumToAdd;
     InitializeComponent();
     ForumTextBox.Focus();
 }
Exemple #3
0
 //edit
 private void EditForumButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (ForumsDataGrid.SelectedIndex == -1)
             throw new Exception("Select any forum.");
         int selForumID = (ForumsDataGrid.SelectedValue as Forum).ForumID;
         Forum ForumToEdit = new Forum();
         ForumToEdit.ForumName = (ForumsDataGrid.SelectedValue as Forum).ForumName;
         EditForum editForum = new EditForum(ForumToEdit);
         editForum.ShowDialog();
         if (ForumToEdit.ForumName == null || ForumToEdit.ForumName == "")
             throw new Exception("You should write smth!");
         (from q in forumEntities.Forum
          where q.ForumID == selForumID
          select q).First().ForumName = ForumToEdit.ForumName;
         forumEntities.SaveChanges();
         FillShowForumTab();
     }
     catch (Exception excpt)
     {
         MessageBox.Show(excpt.Message);
     }
 }
Exemple #4
0
 //add
 private void AddForumButton_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         ForumsDataGrid.ItemsSource = null;
         this.IsEnabled = false;
         Forum ForumToAdd = new Forum();
         AddForum addForum = new AddForum(ForumToAdd);
         addForum.ShowDialog();
         if (ForumToAdd.ForumName == null)
             throw new Exception("none");
         if (ForumToAdd.ForumName == "")
             throw new Exception("Write forum's name!");
         ForumToAdd.CreateDate = DateTime.Now;
         ForumToAdd.TopicsCount = 0;
         ForumToAdd.LastPostID = null;
         ForumToAdd.UserId = UserLogined.UserId;
         //check for uniq
         var f = from q in forumEntities.Forum
                 where q.ForumName == ForumToAdd.ForumName
                 select q;
         if (f.Count() != 0)
             throw new Exception("Such forum already exists!");
         forumEntities.Forum.AddObject(ForumToAdd);
         forumEntities.SaveChanges();
     }
     catch (Exception excpt)
     {
         if(excpt.Message != "none")
             MessageBox.Show(excpt.Message);
     }
     finally
     {
         FillShowForumTab();
         this.IsEnabled = true;
     }
 }
Exemple #5
0
 //del
 private void ForumsDataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Delete)
     {
         ForumExt ForumExtToDel = (ForumsDataGrid.SelectedValue as ForumExt);
         Forum ForumToDel = new Forum();
         ForumToDel.CreateDate = ForumExtToDel.CreateDate;
         ForumToDel.ForumID = ForumExtToDel.ForumID;
         ForumToDel.ForumName = ForumExtToDel.ForumName;
         ForumToDel.LastPostID = ForumExtToDel.LastPostID;
         ForumToDel.TopicsCount = ForumExtToDel.TopicsCount;
         ForumToDel.UserId = ForumExtToDel.UserId;
         DB.DelTopicsBelongToForum(ForumToDel.ForumID);
         var forumdel = from q in forumEntities.Forum
                  where q.ForumID == ForumToDel.ForumID
                  select q;
         forumEntities.DeleteObject(forumdel.First());
     }
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Forum EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToForum(Forum forum)
 {
     base.AddObject("Forum", forum);
 }
 /// <summary>
 /// Create a new Forum object.
 /// </summary>
 /// <param name="forumID">Initial value of the ForumID property.</param>
 /// <param name="topicsCount">Initial value of the TopicsCount property.</param>
 /// <param name="forumName">Initial value of the ForumName property.</param>
 /// <param name="createDate">Initial value of the CreateDate property.</param>
 /// <param name="userId">Initial value of the UserId property.</param>
 public static Forum CreateForum(global::System.Int32 forumID, global::System.Int32 topicsCount, global::System.String forumName, global::System.DateTime createDate, global::System.Guid userId)
 {
     Forum forum = new Forum();
     forum.ForumID = forumID;
     forum.TopicsCount = topicsCount;
     forum.ForumName = forumName;
     forum.CreateDate = createDate;
     forum.UserId = userId;
     return forum;
 }