你如何实现CSV格式? [英] How do you implement CSV format?

查看:129
本文介绍了你如何实现CSV格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为员工数据输入应用创建了一个Windows窗体。我根本不确定如何使用CSV格式,以便每个员工在文本文件中都有自己的行,它将被保存到。



谢谢!



我尝试过的事情:



使用系统; 
使用System.Collections.Generic;使用System.ComponentModel
;
使用System.Data;使用System.Drawing
;
使用System.IO;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
使用System.Windows.Forms;
使用System.Windows.Input;
使用System.Text.RegularExpressions;


命名空间EmployeeInfo
{
公共部分类EmployeeInfo:Form
{
public object reader {get;私人集; }

public EmployeeInfo()
{
InitializeComponent();
}

private void button1_Click(object sender,EventArgs e)
{
using(StreamWriter objWriter = new StreamWriter(EmployeeData.txt))
{
objWriter.Write(FnameBox.Text);
objWriter.Write(LnameBox.Text);
objWriter.Write(addressBox.Text);
objWriter.Write(stateBox.Text);
objWriter.Write(cityBox.Text);
objWriter.Write(zipCodeBox.Text);
objWriter.Write(phoneBox.Text);
objWriter.Write(emailBox.Text);

if(FnameBox.Text ==|| LnameBox.Text ==|| addressBox.Text ==|| stateBox.Text ==|| cityBox.Text = =|| zipCodeBox.Text ==|| phoneBox.Text ==|| emailBox.Text ==)
{
//显示弹出框
MessageBox .Show(所有字段必须完成,错误);
FnameBox.Focus(); //将焦点设置为lastNameTextBox
return;
} //结束如果

if(!Regex.Match(FnameBox.Text,^ [AZ] [a-zA-Z] * $)。成功)
{
//名字不正确
MessageBox.Show(请输入有效的名字,消息);
FnameBox.Focus();
返回;
}
if(!Regex.Match(LnameBox.Text,^ [AZ] [a-zA-Z] * $)。成功)
{
//姓氏不正确
MessageBox.Show(请输入有效的姓氏,消息);
LnameBox.Focus();
返回;
} //结束如果
//如果地址格式无效则显示消息
if(!Regex.Match(addressBox.Text,@^ [0-9] + \s +([ a-zA-Z] + | [a-zA-Z] + \ [[a-zA-Z] +)$)。成功)
{
//地址错误
MessageBox.Show(请输入有效地址,消息);
addressBox.Focus();
返回;
} //结束如果
if(!Regex.Match(stateBox.Text,@^([a-zA-Z] + | [a-zA-Z] + \ s [a] -zA-Z] +)$)。成功)
{
//城市不正确
MessageBox.Show(请输入有效状态,消息);
stateBox.Focus();
返回;
} //如果
结束//如果状态格式无效则显示消息
if(!Regex.Match(cityBox.Text,@^([a-zA-Z] + | [ a-zA-Z] + \ [[a-zA-Z] +)$)。成功)
{
//状态不正确
MessageBox.Show(请输入有效城市,消息);
cityBox.Focus();
返回;
} //如果
结束//如果邮政编码格式无效则显示消息
if(!Regex.Match(zipCodeBox.Text,@^ \d {5} $)。成功)
{
// zip不正确
MessageBox.Show(请输入有效的邮政编码,留言);
zipCodeBox.Focus();
返回;
} //结束如果
//如果电话号码格式无效则显示消息
if(!Regex.Match(phoneBox.Text,@^ [1-9] \d {2 } - [1-9] \d {2} -\d {4} $)。成功)
{
//电话号码不正确
MessageBox.Show(请输入有效的电话号码,消息);
phoneBox.Focus();
返回;
} //结束如果
if(!Regex.Match(emailBox.Text,@^([a-zA-Z] + | [a-zA-Z] + \ s [a] -zA-Z] +)$)。成功)
{
//电话号码不正确
MessageBox.Show(请输入有效的电子邮件,消息);
emailBox.Focus();
返回;
} //结束如果
}
this.Hide(); //隐藏主窗口,而MessageBox显示
MessageBox.Show(输入的信息\\ n有效和保存);
}

private void button2_Click(object sender,EventArgs e)
{
FnameBox.Text =;
LnameBox.Text =;
addressBox.Text =;
stateBox.Text =;
cityBox.Text =;
zipCodeBox.Text =;
phoneBox.Text =;
emailBox.Text =;
}
}
}

解决方案

)。成功)
{
//名字不正确
MessageBox.Show(请输入有效的名字,消息);
FnameBox.Focus();
return;
}
if(!Regex.Match(LnameBox.Text,^ [AZ] [a-zA-Z] *


)。成功)
{
//姓氏不正确
MessageBox.Show(请输入有效的姓氏,消息);
LnameBox.Focus();
return;
} //结束如果
//如果地址格式无效则显示消息
if(!Regex.Match(addressBox.Text,@^ [0-9] + \s +([a-zA] -Z] + | [a-zA-Z] + \ [[a-zA-Z] +)


)。成功)
{
//地址不正确
MessageBox.Show(请输入有效地址,消息);
addressBox.Focus();
返回;
} //结束如果
if(!Regex.Match(stateBox.Text,@^([a-zA-Z] + | [a-zA-Z] + \ s [a] -Za-Z] +)

I've created a windows form for an employee data input app. I'm just not sure at all about how to use the CSV format so that each employee has it's own row in the text file it will be saved to.

Thanks!

What I have tried:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Input;
using System.Text.RegularExpressions;


namespace EmployeeInfo
{
    public partial class EmployeeInfo : Form
    {
        public object reader { get; private set; }

        public EmployeeInfo()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (StreamWriter objWriter = new StreamWriter("EmployeeData.txt"))
            {
                objWriter.Write(FnameBox.Text);
                objWriter.Write(LnameBox.Text);               
                objWriter.Write(addressBox.Text);              
                objWriter.Write(stateBox.Text);
                objWriter.Write(cityBox.Text);
                objWriter.Write(zipCodeBox.Text);
                objWriter.Write(phoneBox.Text);                
                objWriter.Write(emailBox.Text);
                
                if (FnameBox.Text == "" || LnameBox.Text == "" || addressBox.Text == "" || stateBox.Text == "" || cityBox.Text == "" || zipCodeBox.Text == "" || phoneBox.Text == "" || emailBox.Text == "")
                {
                    // display popup box
                    MessageBox.Show("All fields must be completed", "Error");
                    FnameBox.Focus(); // set focus to lastNameTextBox
                    return;
                } // end if 

                if (!Regex.Match(FnameBox.Text, "^[A-Z][a-zA-Z]*$").Success)
                {
                    // first name was incorrect
                    MessageBox.Show("Please input valid first name", "Message");
                    FnameBox.Focus();
                    return;              
                }
                if (!Regex.Match(LnameBox.Text, "^[A-Z][a-zA-Z]*$").Success)
                {
                    // last name was incorrect
                    MessageBox.Show("Please input valid last name", "Message");
                    LnameBox.Focus();
                    return;
                }// end if          
                 // if address format invalid show message
                if (!Regex.Match(addressBox.Text, @"^[0-9]+\s+([a-zA-Z]+|[a-zA-Z]+\s[a-zA-Z]+)$").Success)
                {
                    // address was incorrect
                    MessageBox.Show("Please input valid address", "Message");
                    addressBox.Focus();
                    return;
                } // end if 
                if (!Regex.Match(stateBox.Text, @"^([a-zA-Z]+|[a-zA-Z]+\s[a-zA-Z]+)$").Success)
                {
                    // city was incorrect
                    MessageBox.Show("Please input valid state", "Message");
                    stateBox.Focus();
                    return;
                }// end if 
                 // if state format invalid show message
                if (!Regex.Match(cityBox.Text, @"^([a-zA-Z]+|[a-zA-Z]+\s[a-zA-Z]+)$").Success)
                {
                    // state was incorrect
                    MessageBox.Show("Please input valid city", "Message");
                    cityBox.Focus();
                    return;
                } // end if 
                  // if zip code format invalid show message
                if (!Regex.Match(zipCodeBox.Text, @"^\d{5}$").Success)
                {
                    // zip was incorrect
                    MessageBox.Show("Please input valid zip code", "Message");
                    zipCodeBox.Focus();
                    return;
                } // end if
                  // if phone number format invalid show message
                if (!Regex.Match(phoneBox.Text, @"^[1-9]\d{2}-[1-9]\d{2}-\d{4}$").Success)
                {
                    // phone number was incorrect
                    MessageBox.Show("Please input valid phone number", "Message");
                    phoneBox.Focus();
                    return;
                }// end if 
                if (!Regex.Match(emailBox.Text, @"^([a-zA-Z]+|[a-zA-Z]+\s[a-zA-Z]+)$").Success)
                {
                    // phone number was incorrect
                    MessageBox.Show("Please input valid email", "Message");
                    emailBox.Focus();
                    return;
                }// end if 
            }
            this.Hide(); // hide main window while MessageBox displays
            MessageBox.Show("The Information Entered \\nIs Valid and Saved");
        }

        private void button2_Click(object sender, EventArgs e)
        {          
            FnameBox.Text = "";
            LnameBox.Text = "";
            addressBox.Text = "";
            stateBox.Text = "";
            cityBox.Text = "";
            zipCodeBox.Text = "";
            phoneBox.Text = "";
            emailBox.Text = "";
        }
    }
 }

解决方案

").Success) { // first name was incorrect MessageBox.Show("Please input valid first name", "Message"); FnameBox.Focus(); return; } if (!Regex.Match(LnameBox.Text, "^[A-Z][a-zA-Z]*


").Success) { // last name was incorrect MessageBox.Show("Please input valid last name", "Message"); LnameBox.Focus(); return; }// end if // if address format invalid show message if (!Regex.Match(addressBox.Text, @"^[0-9]+\s+([a-zA-Z]+|[a-zA-Z]+\s[a-zA-Z]+)


").Success) { // address was incorrect MessageBox.Show("Please input valid address", "Message"); addressBox.Focus(); return; } // end if if (!Regex.Match(stateBox.Text, @"^([a-zA-Z]+|[a-zA-Z]+\s[a-zA-Z]+)


这篇关于你如何实现CSV格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆