src/FingersDance.Control.Screen/UserControlScreen.xaml.cs
changeset 182 25b49d4f1635
parent 156 e16c8c913c65
child 186 83615722dbab
equal deleted inserted replaced
179:97ef988c92c2 182:25b49d4f1635
    17 {
    17 {
    18 	public partial class UserControlScreen
    18 	public partial class UserControlScreen
    19 	{
    19 	{
    20         public String contexteGrid;
    20         public String contexteGrid;
    21         public int id = 0;
    21         public int id = 0;
    22         public event EventHandler UC_Screen_NewSession;
    22         public event EventHandler UC_Screen_NewCutting;
    23         public MainViewModel MainViewModel;
    23         public MainViewModel MainViewModel;
    24         public ProjectViewModel Project = new ProjectViewModel();
    24         public CuttingViewModel Cutting;
    25         List<Session> sessions = new List<Session>();
    25         private List<Project> existingProjects = new List<Project>();
    26         User User = new User();
    26         User User = new User();
    27 
    27 
    28         public UserControlScreen(int id, MainViewModel mvmodel)
    28         public UserControlScreen(int id, MainViewModel mvmodel)
    29         {
    29         {
    30             try
    30             try
    31             {
    31             {
    32                 this.InitializeComponent();
    32                 this.InitializeComponent();
    33                 this.id = id;
    33                 this.id = id;
    34                 MainViewModel = mvmodel;
    34                 MainViewModel = mvmodel;
    35                 if (MainViewModel.Session.VideoPath.Equals(""))
    35                 if (MainViewModel.Project.VideoPath.Equals(""))
    36                 {
    36                 {
    37                     //1-Creation de la ListVideo
    37                     //1-Creation de la ListVideo
    38                     UserControlListVideo ListVideo = new UserControlListVideo();
    38                     UserControlListVideo ListVideo = new UserControlListVideo();
    39                     ListVideo.Name = "ListVideo1";
    39                     ListVideo.Name = "ListVideo1";
    40                     //2-Ajout de la ListVideo au ControlScreen
    40                     //2-Ajout de la ListVideo au ControlScreen
    45                 else
    45                 else
    46                     OpenProject();
    46                     OpenProject();
    47             }
    47             }
    48             catch (Exception)
    48             catch (Exception)
    49             {
    49             {
    50                 Project = null;
    50                 Cutting = null;
    51                 if (UC_Screen_NewSession != null)
    51                 if (UC_Screen_NewCutting != null)
    52                     UC_Screen_NewSession(this, new EventArgs());
    52                     UC_Screen_NewCutting(this, new EventArgs());
    53             }
    53             }
    54         }
    54         }
    55 
    55 
    56         //Rajout un UIElement vers la grid du screen.
    56         //Rajout un UIElement vers la grid du screen.
    57         public void AddToGrid(UIElement uie)
    57         public void AddToGrid(UIElement uie)
    65 
    65 
    66         private void ListVideo_EH_ItemVideo_ContactDown(object sender, EventArgs e)
    66         private void ListVideo_EH_ItemVideo_ContactDown(object sender, EventArgs e)
    67         {
    67         {
    68             try
    68             try
    69             {
    69             {
    70                 //1 rensegner la video choisie au screen
    70                 //1 renseigner la video choisie au screen et créer un nouveau projet à partir de ce chemin vidéo
    71                 MainViewModel.CreateSession(((UserControlListVideo)sender).VideoName, ((UserControlListVideo)sender).path);
    71                 MainViewModel.CreateProject(((UserControlListVideo)sender).VideoName, ((UserControlListVideo)sender).path);
    72                 //2-Supression du UC List Video
    72                 //2-Supression du UC List Video
    73                 LayoutRoot.Children.Remove((UserControlListVideo)sender);
    73                 LayoutRoot.Children.Remove((UserControlListVideo)sender);
    74                 OpenSession();
    74                 OpenProjectList();
    75             }
    75             }
    76             catch (Exception ex)
    76             catch (Exception ex)
    77             {
    77             {
    78                 Project = null;
    78                 Cutting = null;
    79                 if (UC_Screen_NewSession != null)
    79                 if (UC_Screen_NewCutting != null)
    80                     UC_Screen_NewSession(this, new EventArgs());
    80                     UC_Screen_NewCutting(this, new EventArgs());
    81             }
    81             }
    82         }
    82         }
    83 
    83 
    84         private void OpenSession()
    84         private void OpenProjectList()
    85         {
    85         {
    86             try
    86             try
    87             {
    87             {
    88                 sessions = LoadSessions(MainViewModel.Session.VideoPath);
    88                 existingProjects = LoadProjects(MainViewModel.Project.VideoPath);
    89                 UserControlListSession listSession = new UserControlListSession(sessions);
    89                 UserControlListSession listProject = new UserControlListSession(existingProjects);
    90                 listSession.Name = "ListSession";
    90                 listProject.Name = "ListProject";
    91                 LayoutRoot.Children.Add(listSession);
    91                 LayoutRoot.Children.Add(listProject);
    92                 listSession.EH_List_ContactDown += new EventHandler(listSession_EH_List_ContactDown);
    92                 listProject.EH_List_ContactDown += new EventHandler(listProject_EH_List_ContactDown);
    93             }
    93             }
    94             catch (Exception)
    94             catch (Exception)
    95             {
    95             {
    96                 Project = null;
    96                 Cutting = null;
    97                 if (UC_Screen_NewSession != null)
    97                 if (UC_Screen_NewCutting != null)
    98                     UC_Screen_NewSession(this, new EventArgs());
    98                     UC_Screen_NewCutting(this, new EventArgs());
    99             }
    99             }
   100         }
   100         }
   101 
   101 
   102         private List<Session> LoadSessions(string name)
   102         private List<Project> LoadProjects(string name)
   103         {
   103         {
   104             try
   104             // Does nothing because for the moment we do not load sessions when we know the video path, we just create a new session
   105             {
   105             try
   106                 return new List<Session>();
   106             {
       
   107                 return new List<Project>();
   107             }
   108             }
   108             catch (Exception) 
   109             catch (Exception) 
   109             {
   110             {
   110                 return new List<Session>();
   111                 return new List<Project>();
   111             }
   112             }
   112         }
   113         }
   113 
   114 
   114         void listSession_EH_List_ContactDown(object sender, EventArgs e)
   115         void listProject_EH_List_ContactDown(object sender, EventArgs e)
   115         {
   116         {
   116             try
   117             try
   117             {
   118             {
   118                 LayoutRoot.Children.Remove((UserControlListSession)sender);
   119                 LayoutRoot.Children.Remove((UserControlListSession)sender);
   119                 if (((UserControlListSession)sender).SelectedItem.Equals("New Session"))
   120                 if (((UserControlListSession)sender).SelectedItem.Equals("New Project"))
   120                 {
   121                 {
   121                     UserControlSessionInput SessionInput = new UserControlSessionInput();
   122                     UserControlSessionInput ProjectInput = new UserControlSessionInput();
   122                     SessionInput.Name = "SessionInput";
   123                     ProjectInput.Name = "ProjectInput";
   123                     LayoutRoot.Children.Add(SessionInput);
   124                     LayoutRoot.Children.Add(ProjectInput);
   124                     SessionInput.EH_SurfaceButtonSubmit_ContactDown += new System.EventHandler(this.SessionInput_EH_SurfaceButtonSubmit_ContactDown);
   125                     ProjectInput.EH_SurfaceButtonSubmit_ContactDown += new System.EventHandler(this.ProjectInput_EH_SurfaceButtonSubmit_ContactDown);
   125                 }
   126                 }
   126                 else
   127                 else
   127                 {
   128                 {
   128                     foreach (Session elt in sessions)
   129                     foreach (Project elt in existingProjects)
   129                     {
   130                     {
   130                         if (elt.Name.Equals(((UserControlListSession)sender).SelectedItem))
   131                         if (elt.Name.Equals(((UserControlListSession)sender).SelectedItem))
   131                         {
   132                         {
   132                             MainViewModel.Session.Projects = elt.Projects;
   133                             MainViewModel.Project.Project = elt;
   133                             OpenProject();
   134                             OpenProject();
   134                             return;
   135                             return;
   135                         }
   136                         }
   136                     }
   137                     }
   137                 }
   138                 }
   138             }
   139             }
   139             catch (Exception)
   140             catch (Exception)
   140             {
   141             {
   141                 Project = null;
   142                 Cutting = null;
   142                 if (UC_Screen_NewSession != null)
   143                 if (UC_Screen_NewCutting != null)
   143                     UC_Screen_NewSession(this, new EventArgs());
   144                     UC_Screen_NewCutting(this, new EventArgs());
   144             }
   145             }
   145         }
   146         }
   146 
   147 
   147         private void SessionInput_EH_SurfaceButtonSubmit_ContactDown(object sender, EventArgs e)
   148         private void ProjectInput_EH_SurfaceButtonSubmit_ContactDown(object sender, EventArgs e)
   148         {
   149         {
   149             try
   150             try
   150             {
   151             {
   151                 MainViewModel.Session.Alias = ((UserControlSessionInput)sender).Alias;
   152                 //MainViewModel.Project.Alias = ((UserControlSessionInput)sender).Alias;
   152                 MainViewModel.Session.Email = ((UserControlSessionInput)sender).Email;
   153                 //MainViewModel.Project.Email = ((UserControlSessionInput)sender).Email;
   153                 MainViewModel.Session.Description = ((UserControlSessionInput)sender).Description;
   154                 MainViewModel.Project.Description = ((UserControlSessionInput)sender).Description;
   154                 MainViewModel.Session.Name = ((UserControlSessionInput)sender).SessionName;
   155                 MainViewModel.Project.Name = ((UserControlSessionInput)sender).SessionName;
   155                 
   156                 
   156                 //2-Suppression UCSession Input
   157                 //2-Suppression UCSession Input
   157                 LayoutRoot.Children.Remove((UserControlSessionInput)sender);
   158                 LayoutRoot.Children.Remove((UserControlSessionInput)sender);
   158                 OpenProject();
   159                 OpenProject();
   159             }
   160             }
   160             catch (Exception ex) 
   161             catch (Exception ex) 
   161             {
   162             {
   162                 Project = null;
   163                 Cutting = null;
   163                 if (UC_Screen_NewSession != null)
   164                 if (UC_Screen_NewCutting != null)
   164                     UC_Screen_NewSession(this, new EventArgs());
   165                     UC_Screen_NewCutting(this, new EventArgs());
   165             }
   166             }
   166         }
   167         }
   167 
   168 
   168         private void OpenProject()
   169         private void OpenProject()
   169         {
   170         {
   170             try
   171             try
   171             {
   172             {
   172                 UserControlListProject listProjects = new UserControlListProject(MainViewModel.Session.Projects);
   173                 UserControlListProject listCuttings = new UserControlListProject(MainViewModel.Project.CuttingsDict);
   173                 listProjects.Name = "ListProjects";
   174                 listCuttings.Name = "listCuttings";
   174                 LayoutRoot.Children.Add(listProjects);
   175                 LayoutRoot.Children.Add(listCuttings);
   175                 listProjects.EH_Item_ContactDown += new EventHandler(listProjects_EH_Item_ContactDown);
   176                 listCuttings.EH_Item_ContactDown += new EventHandler(listCuttings_EH_Item_ContactDown);
   176             }
   177             }
   177             catch (Exception) 
   178             catch (Exception) 
   178             {
   179             {
   179                 Project = null;
   180                 Cutting = null;
   180                 if (UC_Screen_NewSession != null)
   181                 if (UC_Screen_NewCutting != null)
   181                     UC_Screen_NewSession(this, new EventArgs());
   182                     UC_Screen_NewCutting(this, new EventArgs());
   182             }
   183             }
   183         }
   184         }
   184 
   185 
   185         void listProjects_EH_Item_ContactDown(object sender, EventArgs e)
   186         void listCuttings_EH_Item_ContactDown(object sender, EventArgs e)
   186         {
   187         {
   187             try
   188             try
   188             {
   189             {
   189                 LayoutRoot.Children.Remove((UserControlListProject)sender);
   190                 LayoutRoot.Children.Remove((UserControlListProject)sender);
   190                 if (((UserControlListProject)sender).SelectedItem.Equals("New Project"))
   191                 if (((UserControlListProject)sender).SelectedItem.Equals("New Cutting"))
   191                 {
   192                 {
   192                     UserControlNewProject newProject = new UserControlNewProject(User);
   193                     UserControlNewProject newCutting = new UserControlNewProject(User);
   193                     newProject.Name = "newProject";
   194                     newCutting.Name = "newCutting";
   194                     LayoutRoot.Children.Add(newProject);
   195                     LayoutRoot.Children.Add(newCutting);
   195                     newProject.EH_NewProject_ContactDown += new EventHandler(newProject_EH_NewProject_ContactDown);
   196                     newCutting.EH_NewCutting_ContactDown += new EventHandler(newCutting_EH_NewProject_ContactDown);
   196                 } 
   197                 }
   197                 else
   198                 else
   198                 {
   199                 {
   199                     foreach(KeyValuePair<string, Project> elt in MainViewModel.Session.Projects)
   200                     foreach(KeyValuePair<string, Cutting> elt in MainViewModel.Project.CuttingsDict)
   200                         if (elt.Key.Equals(((UserControlListProject)sender).SelectedItem))
   201                         if (elt.Key.Equals(((UserControlListProject)sender).SelectedItem))
   201                         {
   202                         {
   202                             Project = new ProjectViewModel(elt.Value);
   203                             Cutting = new CuttingViewModel(elt.Value, 815);
   203                             if (UC_Screen_NewSession != null)
   204                             if (UC_Screen_NewCutting != null)
   204                                 UC_Screen_NewSession(this, new EventArgs());
   205                                 UC_Screen_NewCutting(this, new EventArgs());
   205                             return;
   206                             return;
   206                         }
   207                         }
   207                 }
   208                 }
   208             }
   209             }
   209             catch (Exception)
   210             catch (Exception)
   210             {
   211             {
   211                 Project = null;
   212                 Cutting = null;
   212                 if (UC_Screen_NewSession != null)
   213                 if (UC_Screen_NewCutting != null)
   213                     UC_Screen_NewSession(this, new EventArgs());
   214                     UC_Screen_NewCutting(this, new EventArgs());
   214             }
   215             }
   215         }
   216         }
   216 
   217 
   217         void newProject_EH_NewProject_ContactDown(object sender, EventArgs e)
   218         void newCutting_EH_NewProject_ContactDown(object sender, EventArgs e)
   218         {
   219         {
   219             try
   220             try
   220             {
   221             {
       
   222                 Console.WriteLine("newCutting_EH_NewProject_ContactDown");
   221                 LayoutRoot.Children.Remove((UserControlNewProject)sender);
   223                 LayoutRoot.Children.Remove((UserControlNewProject)sender);
   222                 Project = new ProjectViewModel(((UserControlNewProject)sender).Project);
   224                 Cutting = new CuttingViewModel(((UserControlNewProject)sender).Cutting, 850);
   223                 MainViewModel.Session.Projects.Add(Project.Name, Project.Project);
   225                 MainViewModel.Project.CuttingsDict.Add(Cutting.Title, ((UserControlNewProject)sender).Cutting);
   224                 if (UC_Screen_NewSession != null)
   226                 if (UC_Screen_NewCutting != null)
   225                     UC_Screen_NewSession(this, new EventArgs());
   227                     UC_Screen_NewCutting(this, new EventArgs());
   226             }
   228             }
   227             catch (Exception) 
   229             catch (Exception)
   228             {
   230             {
   229                 Project = null;
   231                 Cutting = null;
   230                 if (UC_Screen_NewSession != null)
   232                 if (UC_Screen_NewCutting != null)
   231                     UC_Screen_NewSession(this, new EventArgs());
   233                     UC_Screen_NewCutting(this, new EventArgs());
   232             }
   234             }
   233         }
   235         }
   234 	}
   236 	}
   235 }
   237 }