12
返回列表 发新帖
楼主: JohnChu
收起左侧

[软件] 求助生成“字典”

[复制链接]
高蒙々
发表于 2012-12-16 15:17:57 | 显示全部楼层
本帖最后由 高蒙々 于 2012-12-16 15:20 编辑
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Text;
  6. using System.Windows.Forms;
  7. using System.IO;

  8. namespace WindowsFormsApplication1
  9. {
  10.     public partial class Form1 : Form
  11.     {
  12.         public Form1()
  13.         {
  14.             InitializeComponent();
  15.         }
  16.         private string FileS(string path)
  17.         {
  18.             FileStream fs = File.Create(path);
  19.             fs.Close();
  20.             return path;
  21.         }
  22.         private string StreamW(string path,string content)
  23.         {
  24.             StreamWriter sw = new StreamWriter(path);
  25.             sw.Write(content);
  26.             sw.Flush();
  27.             sw.Close();
  28.             return path;
  29.         }
  30.         
  31.         private void button1_Click(object sender, EventArgs e)
  32.         {
  33.            Random ran=new Random();
  34.             int   r=ran.Next(50,100);//随机生成50~100之间的数
  35.             string startTime = this.textBox1.Text;//起始时间
  36.             string endTime = this.textBox2.Text;//结束时间
  37.             DateTime startT = DateTime.Parse(startTime);//转换
  38.             DateTime endT = DateTime.Parse(endTime);
  39.             int i = (endT - startT).Days;//timespan 时间差
  40.             string[] dateStr = new string[i+1];//不加1少一天
  41.             for (int j = 0; j < i; j++)
  42.             {
  43.                 dateStr[j] = (startT.AddDays(j).ToString("yyyyMMdd"));//时间格式
  44.                 listView1.Items.Add(new ListViewItem(dateStr[j]));//加入listview
  45.                 string s = Application.StartupPath + "//" + String.Format("{0}.txt", dateStr[j]);//可以修改自己的路径            Application.StartupPath指启动目录
  46.                FileS(s);//创建
  47.                 string str0="统计文件";
  48.                 string str1="日期:"+dateStr[j].ToString();
  49.                 string str2="收入:"+r.ToString()+"元";
  50.                 StreamW(s, str0+Environment.NewLine+str1+Environment.NewLine+str2);//写入
  51.             }
  52.         }

  53.         private void button2_Click(object sender, EventArgs e)
  54.         {
  55.               System.Diagnostics.Process.Start("explorer.exe",Application.StartupPath);  
  56.           }
  57.       
  58.     }
  59.     }
复制代码
这个一个c#WindowsForm小程序 希望给你有所帮助

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?快速注册

x

评分

参与人数 1经验 +5 收起 理由
yloko + 5 感谢解答: )

查看全部评分

JohnChu
 楼主| 发表于 2012-12-16 21:11:29 | 显示全部楼层
高蒙々 发表于 2012-12-16 15:17
这个一个c#WindowsForm小程序 希望给你有所帮助

谢谢
秋$风
发表于 2012-12-21 22:59:47 | 显示全部楼层
流光里有一个小工具,可以生成字典
您需要登录后才可以回帖 登录 | 快速注册

本版积分规则

手机版|杀毒软件|软件论坛| 卡饭论坛

Copyright © KaFan  KaFan.cn All Rights Reserved.

Powered by Discuz! X3.4( 沪ICP备2020031077号-2 ) GMT+8, 2025-5-17 00:37 , Processed in 0.105299 second(s), 15 queries .

卡饭网所发布的一切软件、样本、工具、文章等仅限用于学习和研究,不得将上述内容用于商业或者其他非法用途,否则产生的一切后果自负,本站信息来自网络,版权争议问题与本站无关,您必须在下载后的24小时之内从您的电脑中彻底删除上述信息,如有问题请通过邮件与我们联系。

快速回复 客服 返回顶部 返回列表