using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using IReaper.FileData;
using IReaper.CourseData;
using IReaper.Command;
namespace IReaper.CourseData{
public partial class CourseToolStripMenuItemFileType : ToolStripDropDownMenu
{
CoreDataType dataType = CoreDataType.CurrentSelectedCourses;
public CourseToolStripMenuItemFileType()
{
InitializeComponent();
}
public CourseToolStripMenuItemFileType(IContainer container)
{
container.Add(this);
InitializeComponent();
}
public new ContextMenuStrip ContextMenuStrip
{
get { return null; }
set { }
}
[Bindable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Browsable(false)]
public override ToolStripItemCollection Items
{
get
{
return base.Items;
}
}
/// <summary>
///
/// </summary>
public CoreDataType DataType
{
get { return dataType; }
set { dataType = value; }
}
protected override void OnOpening(CancelEventArgs e)
{
base.OnOpening(e);
ToolStripItem owner = this.OwnerItem;
if (owner == null)
return;
this.Tag = owner.Tag;
bool video, ppt, code, qa, wmv,mp3,mp4;
video = false;
ppt = false;
code = false;
qa = false;
mp3 = false;
wmv = false;
mp4 = false;
CourseCollection courses = Core.CoreData[dataType] as CourseCollection;
if (courses == null || courses.Count == 0)
{ }
else
{
/*
*
*/
string type = owner.Tag.ToString();
Course c = courses[0];
switch (type)
{
case "Remove":
for (int i = 0; i < courses.Count; i++)
{
c = courses[i];
code |= CourseFileData.IsCourseFileRemovable(c.Code);
video |= CourseFileData.IsCourseFileRemovable(c.Video);
ppt |= CourseFileData.IsCourseFileRemovable(c.PPT);
qa |= CourseFileData.IsCourseFileRemovable(c.QA);
wmv |= CourseFileData.IsCourseFileRemovable(c.WMV);
mp4 |= CourseFileData.IsCourseFileRemovable(c.MP4);
mp3 |= CourseFileData.IsCourseFileRemovable(c.MP3);
}
break;
case "Open":
code = CourseFileData.IsCourseFileFinished(c.Code);
video = CourseFileData.IsCourseFileFinished(c.Video);
ppt = CourseFileData.IsCourseFileFinished(c.PPT);
qa = CourseFileData.IsCourseFileFinished(c.QA);
wmv = CourseFileData.IsCourseFileFinished(c.WMV);
mp4 = CourseFileData.IsCourseFileFinished(c.MP4);
mp3 = CourseFileData.IsCourseFileFinished(c.MP3);
break;
case "Download":
for (int i = 0; i < courses.Count; i++)
{
c = courses[i];
code |= CourseFileData.IsCourseFileRunnable(c.Code);
video |= CourseFileData.IsCourseFileRunnable(c.Video);
ppt |= CourseFileData.IsCourseFileRunnable(c.PPT);
qa |= CourseFileData.IsCourseFileRunnable(c.QA);
wmv |= CourseFileData.IsCourseFileRunnable(c.WMV);
mp4 |= CourseFileData.IsCourseFileRunnable(c.MP4);
mp3 |= CourseFileData.IsCourseFileRunnable(c.MP3);
}
break;
case "Export":
for (int i = 0; i < courses.Count; i++)
{
c = courses[i];
code |= CourseFileData.IsCourseFileFinished(c.Code);
video |= CourseFileData.IsCourseFileFinished(c.Video);
ppt |= CourseFileData.IsCourseFileFinished(c.PPT);
qa |= CourseFileData.IsCourseFileFinished(c.QA);
wmv |= CourseFileData.IsCourseFileFinished(c.WMV);
mp4 |= CourseFileData.IsCourseFileFinished(c.MP4);
mp3 |= CourseFileData.IsCourseFileFinished(c.MP3);
}
break;
}
}
this.toolStripMenuItemCode.Enabled = code;
this.toolStripMenuItemSlides.Enabled = ppt;
this.toolStripMenuItemQA.Enabled = qa;
this.toolStripMenuItemVideo.Enabled = video;
this.toolStripMenuItemMP3.Enabled = mp3;
this.toolStripMenuItemMP4.Enabled = mp4;
this.toolStripMenuItemZune.Enabled = wmv;
this.toolStripMenuItemAll.Enabled = code | ppt | qa | video | mp3 | mp4 | wmv;
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void InvokeCourseFileFunction(object sender, EventArgs e)
{
ToolStripItem item = sender as ToolStripItem;
if (item == null)
return;
FileType fileType = FileType.None;
string senderName = item.Tag as string;
string taskName = "";
if (item.Owner != null)
{
taskName = item.Owner.Tag as string;
}
try
{
fileType = (FileType)Enum.Parse(typeof(FileType), senderName);
}
catch { }
CourseCollection courses = Core.CoreData[dataType] as CourseCollection;
CommandFamily family = CommandFamily.Command_Empty;
CommandBase command = null;
if (taskName == "Open")
{
command = CommandManager.GetCommand(CommandFamily.Command_OpenCourseFile);
command.ExecuteAsync(this, courses[0], fileType);
return;
}
else
{
switch (taskName)
{
case "Download":
family = CommandFamily.Command_DownloadFile;
List<CourseFileData> list = CourseFileDataManager.CreateFileList(courses, fileType, CourseFileData.IsCourseFileRunnable);
command = CommandManager.GetCommand(family);
command.ExecuteAsync(this, list, RemoveFileTaskTypeEnum.Completed);
break;
case "Remove":
family = CommandFamily.Command_RemoveFile;
list = CourseFileDataManager.CreateFileList(courses, fileType, CourseFileData.IsCourseFileRemovable);
command = CommandManager.GetCommand(family);
command.ExecuteAsync(this, list, RemoveFileTaskTypeEnum.Completed);
break;
case "Export":
if (this.exportDesinationFolderBrowser.ShowDialog() != DialogResult.OK)
{
return;
}
string folderPath = this.exportDesinationFolderBrowser.SelectedPath;
//get and copy the files set
courses = Core.CoreData[CoreDataType.CurrentSelectedCourses] as CourseCollection;
if (courses == null)
{ return; }
List<CourseFileData> files = CourseFileDataManager.CreateFileList(courses, fileType, CourseFileData.IsCourseFileFinished);
CourseFileData[] fileArray = new CourseFileData[files.Count];
files.CopyTo(fileArray, 0);
//
command = CommandManager.GetCommand(CommandFamily.Command_FileTransfer);
command.ExecuteAsync(this, fileArray, //CourseFileData[], the source
IReaper.FileUtils.OperationType.Copy, // the operation type
true, //
folderPath, //
IReaper.PathManager.PathPolicyType.Plain);
return;
}
}
}
}
}
|