C#文件读写demo

时间:2022-02-01 13:22:57
【文件属性】:

文件名称:C#文件读写demo

文件大小:412KB

文件格式:RAR

更新时间:2022-02-01 13:22:57

C# 文件读写

namespace CreatFile { public partial class ArgumentsHelper : Form { public ArgumentsHelper() { InitializeComponent(); } string _filename = "00000000000000"; string pars = null; private void bt_Summit_Click(object sender, EventArgs e) { try { //线路车辆信息表 string lcinfo = txt_LineNum.Text + "*" + txt_TeamNum.Text + "*" + txt_BusNum.Text + "*" + txt_TerminalNum.Text + "#"; //扇区城市代码表 string section = txt_Section1.Text + "*" + txt_Section2.Text + "*" + txt_Section3.Text + "*" + txt_Section4.Text + "*" + txt_Section5.Text + "*" + txt_Section6.Text + "&" + txt_CityNum.Text + "#"; //卡类时间间隔表 0*2@1*2@2*2@3*2@4*2@5*2@6*2@7*2@8*2@9*2#卡类时间间隔 string cardtypeinterval = txt_CardType0.Text + "*" + txt_Inerval0.Text + "@" + txt_CardType1.Text + "*" + txt_Inerval1.Text + "@" + txt_CardType2.Text + "*" + txt_Inerval2.Text + "@" + txt_CardType3.Text + "*" + txt_Inerval3.Text + "@" + txt_CardType4.Text + "*" + txt_Inerval4.Text + "@" + txt_CardType5.Text + "*" + txt_Inerval5.Text + "@" + txt_CardType6.Text + "*" + txt_Inerval6.Text + "@" + txt_CardType7.Text + "*" + txt_Inerval7.Text + "@" + txt_CardType8.Text + "*" + txt_Inerval8.Text + "@" + txt_CardType9.Text + "*" + txt_Inerval9.Text + "#"; //卡类表 0*1*2*3*4*5*6*7*8*9# 卡类 string cardtype = txt_CardsType0.Text + "*" + txt_CardsType1.Text + "*" + txt_CardsType2.Text + "*" + txt_CardsType3.Text + "*" + txt_CardsType4.Text + "*" + txt_CardsType5.Text + "*" + txt_CardsType6.Text + "*" + txt_CardsType7.Text + "*" + txt_CardsType8.Text + "*" + txt_CardsType9.Text + "#"; //余额不足表 0*500@1*500@2*500@3*500@4*500@5*500@6*500@7*500@8*500@9*500@17*500# 余额不足金额 string lessbalance = txt_BalanceCardType0.Text + "*" + (int.Parse(txt_Balance0.Text) * 1).ToString() + "@" + txt_BalanceCardType1.Text + "*" + (int.Parse(txt_Balance1.Text) * 1).ToString() + "@" + txt_BalanceCardType2.Text + "*" + (int.Parse(txt_Balance2.Text) * 1).ToString() + "@" + txt_BalanceCardType3.Text + "*" + (int.Parse(txt_Balance3.Text) * 1).ToString() + "@" + txt_BalanceCardType4.Text + "*" + (int.Parse(txt_Balance4.Text) * 1).ToString() + "@" + txt_BalanceCardType5.Text + "*" + (int.Parse(txt_Balance5.Text) * 1).ToString() + "@" + txt_BalanceCardType6.Text + "*" + (int.Parse(txt_Balance6.Text) * 1).ToString() + "@" + txt_BalanceCardType7.Text + "*" + (int.Parse(txt_Balance7.Text) * 1).ToString() + "@" + txt_BalanceCardType8.Text + "*" + (int.Parse(txt_Balance8.Text) * 1).ToString() + "@" + txt_BalanceCardType9.Text + "*" + (int.Parse(txt_Balance9.Text) * 1).ToString() + "#"; //01*000000*235959# 时段 string times = "01*000000*235959#"; //0*01*100*1@1*01*100*2@2*01*100*3@3*01*100*4@4*01*100*4@5*01*100*4@6*01*100*4@7*01*100*4@8*0 //1*100*4@9*01*100*4@17*01*100*2# 消费金额 string amount = txt_TransactionCardType0.Text + "*01*" + txt_Conversion0.Text + "*" + (int.Parse(txt_Amount0.Text) * 1).ToString() + "@" + txt_TransactionCardType1.Text + "*01*" + txt_Conversion1.Text + "*" + (int.Parse(txt_Amount1.Text) * 1).ToString() + "@" + txt_TransactionCardType2.Text + "*01*" + txt_Conversion2.Text + "*" + (int.Parse(txt_Amount2.Text) * 1).ToString() + "@" + txt_TransactionCardType3.Text + "*01*" + txt_Conversion3.Text + "*" + (int.Parse(txt_Amount3.Text) * 1).ToString() + "@" + txt_TransactionCardType4.Text + "*01*" + txt_Conversion4.Text + "*" + (int.Parse(txt_Amount4.Text) * 1).ToString() + "@" + txt_TransactionCardType5.Text + "*01*" + txt_Conversion5.Text + "*" + (int.Parse(txt_Amount5.Text) * 1).ToString() + "@" + txt_TransactionCardType6.Text + "*01*" + txt_Conversion6.Text + "*" + (int.Parse(txt_Amount6.Text) * 1).ToString() + "@" + txt_TransactionCardType7.Text + "*01*" + txt_Conversion7.Text + "*" + (int.Parse(txt_Amount7.Text) * 1).ToString() + "@" + txt_TransactionCardType8.Text + "*01*" + txt_Conversion8.Text + "*" + (int.Parse(txt_Amount8.Text) * 1).ToString() + "@" + txt_TransactionCardType9.Text + "*01*" + txt_Conversion9.Text + "*" + (int.Parse(txt_Amount9.Text) * 1).ToString() + "#"; //0# 转乘优惠 //0#0#0#0#0#44&35;*7309@35*4250@35*3130@35*3180@35*3120@35*7300@35*2144@35*3300@35*1130@35*2230@35*1250@35*6217@35*2155@35*2153#3*10*30*00&1*0*0*2*1*0*3*2*1# 分段消费 string others = "0#0#0#0#0#0#0#"; //100000# 余额过大 string overbalance = (int.Parse(txt_OverBalance.Text) * 1).ToString() + "#"; //组合所有参数表 pars = (lcinfo + section + cardtypeinterval + cardtype + lessbalance + times + amount + others + overbalance).Trim (); } catch (Exception ex) { MessageBox.Show(ex.Message); } //获取日期做文件名 _filename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString () + DateTime.Now.Hour.ToString () + DateTime.Now.Minute.ToString () + DateTime.Now.Second.ToString ()+".cs"; //创建文件 Stream st = File.Create(_filename); //FileStream fs = new FileStream(); //关闭STream对象对文件的访问 st.Close(); //指定写入文件 StreamWriter sw = new StreamWriter(Application.StartupPath + "\\"+_filename); //开始写入内容 sw.WriteLine(pars); //关闭写入对象 sw.Close(); MessageBox.Show("保存成功"); this.WindowState = FormWindowState.Minimized; //打开指定文件夹并选定文件 //Process.Start("explorer.exe", "/select, " + _filename); } private void Form1_Load(object sender, EventArgs e) { } } }


【文件预览】:
CreatFile
----CreatFile()
--------Program.cs(492B)
--------SetForm.cs(3KB)
--------ArgumentsHelper.resx(6KB)
--------obj()
--------bin()
--------ArgumentsHelper.cs(8KB)
--------ArgumentsHelper.Designer.cs(74KB)
--------CreatFile.csproj(4KB)
--------SerializableClass.cs(534B)
--------SetForm.resx(6KB)
--------Properties()
--------SetForm.Designer.cs(4KB)
----CreatFile.sln(1KB)
----CreatFile.suo(24KB)
----Setup1()
--------Release()
--------Debug()
--------Setup1.vdproj(37KB)

网友评论