Changeset 14667

Show
Ignore:
Timestamp:
06/26/08 23:32:50 (5 years ago)
Author:
coma2n
Message:

platform/silverlight/eLearn/trunk: study追加機能を実装

Location:
platform/silverlight/eLearn/trunk
Files:
2 added
8 modified

Legend:

Unmodified
Added
Removed
  • platform/silverlight/eLearn/trunk/eLearn/Page.xaml

    r14610 r14667  
    11<UserControl x:Class="eLearn.Page" 
    22    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    3     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
     3    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     4    xmlns:v="clr-namespace:eLearn.UI" 
    45    Width="400" Height="220"> 
    56     
     
    3031                 
    3132                <StackPanel Grid.Column="1" HorizontalAlignment="Left" Margin="8,0,0,0"> 
    32                         <Button x:Name="addButton" Width="80" Content="追加" Style="{StaticResource button}" /> 
     33                        <Button x:Name="addButton" Width="80" Content="追加" 
     34                    Click="addButton_Click" Style="{StaticResource button}" /> 
     35             
    3336                        <Button x:Name="editButton" Width="80" Content="編集" IsEnabled="False" Margin="0,5,0,0" Style="{StaticResource button}" /> 
    3437                        <Button x:Name="remButton" Width="80" Content="削除" IsEnabled="False" Margin="0,5,0,0" Style="{StaticResource button}" /> 
    3538                </StackPanel> 
     39         
     40        <v:AddStudyView x:Name="addStudyView" Grid.ColumnSpan="2" Visibility="Collapsed" /> 
    3641    </Grid> 
    3742         
  • platform/silverlight/eLearn/trunk/eLearn/Page.xaml.cs

    r14610 r14667  
    9191        } 
    9292 
     93        /// <summary> 
     94        /// [追加] 
     95        /// </summary> 
     96        /// <param name="sender"></param> 
     97        /// <param name="e"></param> 
     98        private void addButton_Click(object sender, RoutedEventArgs e) { 
     99            addStudyView.Show(); 
     100        } 
     101 
    93102    } 
    94103} 
  • platform/silverlight/eLearn/trunk/eLearn/UI/QuestionView.xaml

    r14610 r14667  
    33    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    44    xmlns:data="clr-namespace:eLearn.UI.Data" 
    5         Width="360" Height="300"> 
     5        Width="360" Height="290"> 
    66     
    77    <UserControl.Resources> 
     
    7171    <Grid x:Name="LayoutRoot" Background="White"> 
    7272                <Grid.RowDefinitions> 
    73                         <RowDefinition Height="70" /> 
     73                        <RowDefinition Height="60" /> 
    7474                        <RowDefinition /> 
    7575                        <RowDefinition Height="40" /> 
  • platform/silverlight/eLearn/trunk/eLearn/eLearn.csproj

    r14610 r14667  
    7373    <Compile Include="StudyManager.cs" /> 
    7474    <Compile Include="StudyResult.cs" /> 
     75    <Compile Include="UI\AddStudyView.xaml.cs"> 
     76      <DependentUpon>AddStudyView.xaml</DependentUpon> 
     77    </Compile> 
    7578    <Compile Include="UI\Data\QuestionConverter.cs" /> 
    7679    <Compile Include="UI\FinishView.xaml.cs"> 
     
    9396      <Generator>MSBuild:MarkupCompilePass1</Generator> 
    9497      <SubType>Designer</SubType> 
     98    </Page> 
     99    <Page Include="UI\AddStudyView.xaml"> 
     100      <SubType>Page</SubType> 
     101      <Generator>MSBuild:MarkupCompilePass1</Generator> 
    95102    </Page> 
    96103    <Page Include="UI\FinishView.xaml"> 
  • platform/silverlight/eLearn/trunk/eLearn_Web/Content/Site.css

    r14610 r14667  
    11 
    22.page { 
     3        width: 400px; 
    34} 
    45 
    56.silverlight { 
    67    width: 400px; 
    7     height: 400px; 
     8    height: 330px; 
    89} 
    910 
    1011#header { 
    11     height: 55px; 
     12    margin-bottom: 20px; 
    1213} 
  • platform/silverlight/eLearn/trunk/eLearn_Web/Controllers/StudyController.cs

    r14610 r14667  
    2727using System.Web; 
    2828using System.Web.Mvc; 
     29using System.Net; 
     30using System.Linq; 
    2931using System.Text; 
    3032using System.Xml.Linq; 
    3133using System.Diagnostics; 
     34 
     35using Ele = System.Xml.Linq.XElement; 
     36using Attr = System.Xml.Linq.XAttribute; 
    3237 
    3338#endregion 
     
    4146    /// </summary> 
    4247    public sealed class StudyController : Controller { 
    43          
     48 
     49        #region const 
     50 
     51        /// <summary> 
     52        /// インデックスファイル 
     53        /// </summary> 
     54        private const string INDEX_FILE = "~/App_Data/Repo/index.xml"; 
     55        /// <summary> 
     56        /// コンテントファイルのフォーマット 
     57        /// </summary> 
     58        private const string CONTENT_FILE_FORMAT = "~/App_Data/Repo/study/{0}.xml"; 
     59 
     60        #endregion 
     61 
    4462        #region constructors 
    4563 
     
    5977        /// <returns>スタディ情報の一覧</returns> 
    6078        public ActionResult Index() { 
    61             var path = Request.MapPath("~/App_Data/Repo/index.xml"); 
     79            var path = Request.MapPath(INDEX_FILE); 
    6280 
    6381            using(var sr = new StreamReader(path, Encoding.UTF8)) { 
    64                 return Content(sr.ReadToEnd(), "text/xml", Encoding.UTF8); 
     82                return Content(sr.ReadToEnd(), "text/xml"); 
    6583            } 
    6684        } 
     
    7492            if(id != null) { 
    7593                try { 
    76                     var path = Request.MapPath(string.Format("~/App_Data/Repo/study/{0}.xml", id)); 
     94                    var path = Request.MapPath(string.Format(CONTENT_FILE_FORMAT, id)); 
    7795 
    7896                    using(var sr = new StreamReader(path, Encoding.UTF8)) { 
    79                         return Content(sr.ReadToEnd(), "text/xml", Encoding.UTF8); 
     97                        return Content(sr.ReadToEnd(), "text/xml"); 
    8098                    } 
    8199 
    82100                } catch(Exception exp) { 
    83                     throw new HttpException(404, "指定したスタディは存在しません", exp); 
     101                    throw new HttpException((int)HttpStatusCode.NotFound, "指定したStudyは存在しません。", exp); 
    84102                } 
    85103 
    86104            } else { 
    87                 throw new HttpException(400, "idを指定して下さい"); 
    88             } 
    89         } 
     105                throw new HttpException((int)HttpStatusCode.BadRequest, "[id]を指定して下さい。"); 
     106            } 
     107        } 
     108 
     109        /// <summary> 
     110        /// スタディを新規作成します。 
     111        /// </summary> 
     112        /// <param name="title">タイトル</param> 
     113        /// <returns>スタディ情報</returns> 
     114        public ActionResult New(string title) { 
     115            if(string.IsNullOrEmpty(title)) { 
     116                throw new HttpException((int)HttpStatusCode.BadRequest, "[title]を指定して下さい。"); 
     117            } 
     118            var indexXml = OpenIndex(); 
     119            var id = indexXml.Descendants("study").Max(s => (int)s.Attribute("id")) + 1; 
     120 
     121            indexXml.Root.Add( 
     122                new Ele("study", 
     123                    new Attr("id", id), new Attr("title", title) 
     124                ) 
     125            ); 
     126            SaveIndex(indexXml); 
     127 
     128            var contentXml = new XDocument( 
     129                new Ele("study", 
     130                    new Attr("id", id), new Attr("title", title) 
     131                ) 
     132            ); 
     133            return Content( 
     134                SaveContent(contentXml, id).ToString(), "text/xml" 
     135            ); 
     136        } 
     137 
     138        /// <summary> 
     139        /// 指定したIdのスタディを削除します。 
     140        /// </summary> 
     141        /// <param name="id">Id</param> 
     142        /// <returns>削除できたかどうか</returns> 
     143        public ActionResult Remove(int? id) { 
     144            if(id == null) { 
     145                throw new HttpException((int)HttpStatusCode.BadRequest, "[id]を指定して下さい。"); 
     146            } 
     147            var indexXml = OpenIndex(); 
     148 
     149            var study = indexXml.Descendants("study") 
     150                .FirstOrDefault(s => (int)s.Attribute("id") == id.Value); 
     151 
     152            if(study == null) { 
     153                throw new HttpException((int)HttpStatusCode.NotFound, "指定したStudyは存在しません。"); 
     154            } 
     155            study.Remove(); 
     156 
     157            SaveIndex(indexXml); 
     158 
     159            return Content("0", "text/plain"); 
     160        } 
     161 
     162        /// <summary> 
     163        /// 指定したIdのスタディに指定した質問を追加します。 
     164        /// </summary> 
     165        /// <param name="id">Id</param> 
     166        /// <param name="content">質問内容を表すXML</param> 
     167        /// <returns>スタディ情報</returns> 
     168        public ActionResult AddQuestion(int? id, string content) { 
     169            if(id == null || string.IsNullOrEmpty(content)) { 
     170                throw new HttpException((int)HttpStatusCode.BadRequest, "[id][content]を指定して下さい。"); 
     171            } 
     172            var xml = OpenContent(id); 
     173            xml.Root.Add(content); 
     174 
     175            return Content( 
     176                SaveContent(xml, id).ToString(), "text/xml" 
     177            ); 
     178        } 
     179 
     180        /// <summary> 
     181        /// 指定したIdのスタディの指定した位置の質問を削除します。 
     182        /// </summary> 
     183        /// <param name="id">Id</param> 
     184        /// <param name="index">質問の位置</param> 
     185        /// <returns>削除後のスタディ情報</returns> 
     186        public ActionResult RemoveQuestion(int? id, int? index) { 
     187            if(id == null || index == null) { 
     188                throw new HttpException((int)HttpStatusCode.BadRequest, "[id][index]を指定して下さい。"); 
     189            } 
     190            var contentXml = OpenContent(id); 
     191            // 一度リストに変換しないと駄目よ!! 
     192            contentXml.Descendants("question") 
     193                .Where((q, i) => i == index) 
     194                .ToList().ForEach(q => q.Remove()); 
     195             
     196            return Content( 
     197                SaveContent(contentXml, id).ToString(), "text/xml" 
     198            ); 
     199        } 
     200 
     201        #region private 
     202 
     203        /// <summary> 
     204        /// インデックスファイルを開きます。 
     205        /// </summary> 
     206        /// <returns>インデックスファイル</returns> 
     207        XDocument OpenIndex() { 
     208            return XDocument.Load(Request.MapPath(INDEX_FILE)); 
     209        } 
     210 
     211        /// <summary> 
     212        /// 指定したインデックスを保存します。 
     213        /// </summary> 
     214        /// <param name="xml">インデックス</param> 
     215        /// <returns>インデックス</returns> 
     216        XDocument SaveIndex(XDocument xml) { 
     217            xml.Save(Request.MapPath(INDEX_FILE)); 
     218 
     219            return xml; 
     220        } 
     221 
     222        /// <summary> 
     223        /// 指定したIdのコンテントを開きます。 
     224        /// </summary> 
     225        /// <param name="id">Id</param> 
     226        /// <returns>コンテント</returns> 
     227        XDocument OpenContent(int? id) { 
     228            return XDocument.Load( 
     229                Request.MapPath(string.Format(CONTENT_FILE_FORMAT, id)) 
     230            ); 
     231        } 
     232 
     233        /// <summary> 
     234        /// 指定したコンテントを保存します。 
     235        /// </summary> 
     236        /// <param name="xml">コンテント</param> 
     237        /// <param name="id">Id</param> 
     238        /// <returns>コンテント</returns> 
     239        XDocument SaveContent(XDocument xml, int? id) { 
     240            xml.Save( 
     241                Request.MapPath(string.Format(CONTENT_FILE_FORMAT, id)) 
     242            ); 
     243            return xml; 
     244        } 
     245 
     246        #endregion 
    90247 
    91248        #endregion 
  • platform/silverlight/eLearn/trunk/eLearn_Web/Views/Shared/Site.Master

    r14610 r14667  
    1010 
    1111<body> 
    12     <div id="header"> 
    13         <a href="../Home/Index.aspx"><img src="../Content/logo.png" border="0" /></a> 
    14     </div> 
    15     <div class="page"> 
    16         <asp:ContentPlaceHolder ID="MainContent" runat="server" /> 
    17     </div> 
     12    <table border="0" cellspacing="0" cellpadding="0" width="100%"> 
     13        <tr><td align="center"> 
     14            <table> 
     15                <tr><td align="left" class="page"> 
     16                    <div id="header"> 
     17                        <a href="../Home/Index.aspx"><img src="../Content/logo.png" border="0" /></a> 
     18                    </div> 
     19                     
     20                    <asp:ContentPlaceHolder ID="MainContent" runat="server" /> 
     21                </td></tr> 
     22            </table> 
     23        </td></tr> 
     24    </table> 
    1825</body> 
    1926</html> 
  • platform/silverlight/eLearn/trunk/eLearn_Web/eLearn_Web.csproj.user

    r14610 r14667  
    11<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
     2  <PropertyGroup> 
     3    <ProjectView>ProjectFiles</ProjectView> 
     4  </PropertyGroup> 
    25  <ProjectExtensions> 
    36    <VisualStudio>