Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为我的esurvey应用程序创建.csv文件。我怎么开始?_C#_Wpf_Xaml_Visual Studio 2013_Windows Store Apps - Fatal编程技术网

C# 为我的esurvey应用程序创建.csv文件。我怎么开始?

C# 为我的esurvey应用程序创建.csv文件。我怎么开始?,c#,wpf,xaml,visual-studio-2013,windows-store-apps,C#,Wpf,Xaml,Visual Studio 2013,Windows Store Apps,我在编写Esurvey应用程序(使用Windows应用商店C#XAML)时遇到了问题,我真的需要帮助。我需要创建一个包含所有结果(radiobutton选择和文本输入)的.csv数据库,但我甚至不确定从哪里开始 有人能帮我吗?我正在使用Visual Studio Community 2013 using FYPPrototype1.Common; using System; using System.Collections.Generic; using System.IO; using Syst

我在编写Esurvey应用程序(使用Windows应用商店C#XAML)时遇到了问题,我真的需要帮助。我需要创建一个包含所有结果(radiobutton选择和文本输入)的.csv数据库,但我甚至不确定从哪里开始

有人能帮我吗?我正在使用Visual Studio Community 2013

using FYPPrototype1.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Popups;

// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234237

namespace FYPPrototype1
{
/// <summary>
/// A basic page that provides characteristics common to most applications.
/// </summary>
/// 


public sealed partial class SurveyPage1 : Page
{

    private NavigationHelper navigationHelper;
    private ObservableDictionary defaultViewModel = new ObservableDictionary();

    /// <summary>
    /// This can be changed to a strongly typed view model.
    /// </summary>
    public ObservableDictionary DefaultViewModel
    {
        get { return this.defaultViewModel; }
    }

    /// <summary>
    /// NavigationHelper is used on each page to aid in navigation and 
    /// process lifetime management
    /// </summary>
    public NavigationHelper NavigationHelper
    {
        get { return this.navigationHelper; }
    }


    public SurveyPage1()
    {
        this.InitializeComponent();
        this.navigationHelper = new NavigationHelper(this);
        this.navigationHelper.LoadState += navigationHelper_LoadState;
        this.navigationHelper.SaveState += navigationHelper_SaveState;
    }

    /// <summary>
    /// Populates the page with content passed during navigation. Any saved state is also
    /// provided when recreating a page from a prior session.
    /// </summary>
    /// <param name="sender">
    /// The source of the event; typically <see cref="NavigationHelper"/>
    /// </param>
    /// <param name="e">Event data that provides both the navigation parameter passed to
    /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
    /// a dictionary of state preserved by this page during an earlier
    /// session. The state will be null the first time a page is visited.</param>
    private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
    {
        if (e.PageState != null && e.PageState.ContainsKey("rbNumber1") && e.PageState.ContainsKey("rbNumber2") && e.PageState.ContainsKey("rbNumber3") && e.PageState.ContainsKey("rbNumber4"))
        {
            radioExcellent.IsChecked = (bool)e.PageState["rbNumber1"];
            radioGood.IsChecked = (bool)e.PageState["rbNumber2"];
            radioPoor.IsChecked = (bool)e.PageState["rbNumber3"];
            radioAverage.IsChecked = (bool)e.PageState["rbNumber4"];
        }
    }

    /// <summary>
    /// Preserves state associated with this page in case the application is suspended or the
    /// page is discarded from the navigation cache.  Values must conform to the serialization
    /// requirements of <see cref="SuspensionManager.SessionState"/>.
    /// </summary>
    /// <param name="sender">The source of the event; typically <see cref="NavigationHelper"/></param>
    /// <param name="e">Event data that provides an empty dictionary to be populated with
    /// serializable state.</param>
    private void navigationHelper_SaveState(object sender, SaveStateEventArgs e)
    {
        e.PageState["rbNumber1"] = radioExcellent.IsChecked;
        e.PageState["rbNumber2"] = radioGood.IsChecked;
        e.PageState["rbNumber3"] = radioPoor.IsChecked;
        e.PageState["rbNumber4"] = radioAverage.IsChecked;
    }

    #region NavigationHelper registration

    /// The methods provided in this section are simply used to allow
    /// NavigationHelper to respond to the page's navigation methods.
    /// 
    /// Page specific logic should be placed in event handlers for the  
    /// <see cref="GridCS.Common.NavigationHelper.LoadState"/>
    /// and <see cref="GridCS.Common.NavigationHelper.SaveState"/>.
    /// The navigation parameter is available in the LoadState method 
    /// in addition to page state preserved during an earlier session.

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        navigationHelper.OnNavigatedTo(e);
    }

    protected override void OnNavigatedFrom(NavigationEventArgs e)
    {
        navigationHelper.OnNavigatedFrom(e);
    }

    #endregion

    private async void Button_S1_S2(object sender, RoutedEventArgs e)
    {
        if (radioExcellent.IsChecked != true && radioGood.IsChecked != true && radioAverage.IsChecked != true && radioPoor.IsChecked != true)
        {
            MessageDialog md = new MessageDialog("Please select an option before proceeding!");
            await md.ShowAsync();
        }

        else
        {
            this.Frame.Navigate(typeof(SurveyPage2));
        }
    }
}
}
使用FYPPrototype1.Common;
使用制度;
使用System.Collections.Generic;
使用System.IO;
使用System.Linq;
使用System.Runtime.InteropServices.WindowsRuntime;
使用系统文本;
使用Windows基金会;
使用Windows。
使用Windows.UI.Xaml;
使用Windows.UI.Xaml.Controls;
使用Windows.UI.Xaml.Controls.Primitives;
使用Windows.UI.Xaml.Data;
使用Windows.UI.Xaml.Input;
使用Windows.UI.Xaml.Media;
使用Windows.UI.Xaml.Navigation;
使用Windows.UI.Popups;
//基本页面项目模板记录在http://go.microsoft.com/fwlink/?LinkId=234237
命名空间FYPPrototype1
{
/// 
///提供大多数应用程序通用特性的基本页面。
/// 
/// 
公共密封部分类调查第1页:第页
{
私人导航助手导航助手;
private observedictionary defaultViewModel=new observedictionary();
/// 
///可以将其更改为强类型视图模型。
/// 
公共可观测默认视图模型
{
获取{返回this.defaultViewModel;}
}
/// 
///NavigationHelper在每个页面上用于帮助导航和
///过程生命周期管理
/// 
公共导航帮助器导航帮助器
{
获取{返回this.navigationHelper;}
}
公共调查第1页()
{
this.InitializeComponent();
this.navigationHelper=新的navigationHelper(this);
this.navigationHelper.LoadState+=navigationHelper\u LoadState;
this.navigationHelper.SaveState+=navigationHelper\u SaveState;
}
/// 
///使用导航期间传递的内容填充页面。任何保存的状态也会
///从上一个会话重新创建页面时提供。
/// 
/// 
///事件的来源;通常是
/// 
///提供传递给的导航参数的事件数据
///最初请求此页面时,以及
///此页在早期版本中保留的状态词典
///第一次访问页面时,状态将为空。
私有void navigationHelper_LoadState(对象发送方,LoadStateEventArgs e)
{
如果(e.PageState!=null&&e.PageState.ContainsKey(“rbNumber1”)和&e.PageState.ContainsKey(“rbNumber2”)和&e.PageState.ContainsKey(“rbNumber3”)和&e.PageState.ContainsKey(“rbNumber4”))
{
radioExcellent.IsChecked=(bool)e.PageState[“rbNumber1”];
radioood.IsChecked=(bool)e.PageState[“rbNumber2”];
radioPoor.IsChecked=(bool)e.PageState[“rbNumber3”];
radioAverage.IsChecked=(bool)e.PageState[“rbNumber4”];
}
}
/// 
///保留与此页关联的状态,以防应用程序挂起或
///页已从导航缓存中丢弃。值必须符合序列化
///的要求。
/// 
///事件的来源;通常是
///提供要填充的空字典的事件数据
///可序列化状态。
私有void navigationHelper_SaveState(对象发送方,SaveStateEventArgs e)
{
e、 PageState[“rbNumber1”]=radioExcellent.IsChecked;
e、 PageState[“rbNumber2”]=已检查射线食品;
e、 PageState[“rbNumber3”]=radioPoor.IsChecked;
e、 PageState[“rbNumber4”]=无线电平均值。已检查;
}
#区域导航助手注册
///本节中提供的方法仅用于允许
///NavigationHelper以响应页面的导航方法。
/// 
///特定于页面的逻辑应该放在
/// 
///和。
///导航参数在LoadState方法中可用
///除了先前会话期间保留的页面状态之外。
受保护的覆盖无效OnNavigatedTo(NavigationEventArgs e)
{
navigationHelper.OnNavigatedTo(e);
}
受保护的覆盖无效OnNavigatedFrom(NavigationEventArgs e)
{
navigationHelper.OnNavigatedFrom(e);
}
#端区
专用异步无效按钮\u S1\u S2(对象发送方,路由目标)
{
if(radioExcellent.IsChecked!=true&&radioood.IsChecked!=true&&radioAverage.IsChecked!=true&&radioPoor.IsChecked!=true)
{
MessageDialog md=newmessagedialog(“请在继续之前选择一个选项!”);
等待md.ShowAsync();
}
其他的
{
this.Frame.Navigate(typeof(SurveyPage2));
}
}
}
}

这是我的应用程序的截图,以防你需要参考


这是我的老师想要的输出,但我不知道如何制作,如图所示:(

你可以这样做,其中“greetingOutputText”是关键

private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            // Restore values stored in session state.
            if (e.PageState != null && e.PageState.ContainsKey("greetingOutputText"))
            {
                greetingOutput.Text = e.PageState["greetingOutputText"].ToString();
            }
        }



private void navigationHelper_SaveState(object sender, SaveStateEventArgs e)
        {
            e.PageState["greetingOutputText"] = greetingOutput.Text;

        }

这将对您有所帮助。

您的navigationHelper\u SaveState方法为空??这是因为我不知道如何:(我已经尝试过了,但对于单选按钮选择,它无法将字符串转换为boolEverything。现在一切正常。感谢您的帮助!您可能知道如何为我的Esurvey应用程序创建数据库吗?我需要将结果保存到.csv文件中,以便在Microsoft Excel上查看。@Kuyo签出并重试。这些可能有助于保存数据。)ta to.csv文件。:)嗨,Akansha,再次感谢您提供的链接!我正试图找出如何使csv工作,但它非常模糊…您能再次用代码示例指导我吗?这是我的surveypage1,有4个单选按钮(上面编辑)。我应该如何开始?我在这里提出了一个新问题: