C#界面编程补充2——循环panel内的控件、删除列表选中项、文件操作、ADO.NET即datareader读取数据库、单窗体实现增删改查、多窗体实现增删改查

循环panel内的控件

在这里插入图片描述

删除列表选中项

在这里插入图片描述

 if (this.listView1.SelectedItems.Count == 0)
            {
                MessageBox.Show("没有选中项目");
                return;
            }
            ListViewItem item = this.listView1.SelectedItems[0];
            this.listView1.Items.Remove(item);

文件操作

打开文件的属性

在这里插入图片描述

判断文件是否存在,存在就强行覆盖

在这里插入图片描述

递归调用——复制和移动文件夹及文件夹里的所有文件

在这里插入图片描述

 //递归调用,复制和移动文件夹及文件夹里的所有文件
            Directory.CreateDirectory("end文件夹名称");
            DirectoryInfo startDir = new DirectoryInfo("start文件夹名称");
            foreach (FileInfo item in startDir.GetFiles())
            {
                item.CopyTo(endfile + "\\" + item.Name);
            }
            foreach (DirectoryInfo item in sartDir.GetDirectories())
            {
                string startPath = item.FullName;
                string endPath = endPath + "\\" + item.Name;
                copyFolder(startPath, endPath);
            }

读取文件内容并显示

在这里插入图片描述

       //方案1
            ListViewItem item = this.listView1.SelectedItems[0];
            this.listView1.Items.Remove(item);
            FileStream fs = new FileStream(this.textBox1.Text, FileMode.Open, FileAccess.Read);
            int len = (int)fs.Length;
            byte[] arrByte = new byte[len];
            fs.Read(arrByte, 0, len);
            this.textBox1.Text = Encoding.Default.GetString(arrByte);
            fs.Close();

在这里插入图片描述

 //方案2
            ListViewItem item = this.listView1.SelectedItems[0];
            this.listView1.Items.Remove(item);
            FileStream fs = new FileStream(this.textBox1.Text, FileMode.Open, FileAccess.Read);
            int len = (int)fs.Length;
            byte[] arrByte = new byte[len];
            int index = 0;
            int code = fs.ReadByte();
            while (code!=-1)
            {
                arrByte[index] = Convert.ToByte(code);
                code = fs.ReadByte();
                index++;
            }
            this.textBox1.Text = Encoding.Default.GetString(arrByte);
            fs.Close();

在这里插入图片描述

//方案3
            this.textBox1.Text = File.ReadAllText(this.textBox2.Text, Encoding.Default);

在这里插入图片描述

  //方案4
            FileStream fs = new FileStream(this.textBox1.Text, FileMode.Open, FileAccess.Read);
            StreamReader sd = new StreamReader(fs, Encoding.Default);
            this.textBox2.Text = sd.ReadToEnd();
            sd.Close();
            fs.Close();

在这里插入图片描述

ADO.NET即datareader读取数据库

添加数据第一种sqldataadapter方式:

在这里插入图片描述

添加数据第一种sqlcommand方式:

在这里插入图片描述

单窗体实现增删改查

增加

在这里插入图片描述

删除

在这里插入图片描述

修改

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

多窗体实现增删改查

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

123梦野

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值