
C#订单统计小程序
发布日期:2021-05-10 12:00:46
浏览次数:21
分类:精选文章
本文共 3943 字,大约阅读时间需要 13 分钟。
������Excel������������
1.1 ���������sheet���������������
������������������������������������
- ���������������������������������������������
- ������������������������������sheet���������
1.2 ���������sheet���������������
������������������������������
- ������������������������������
1.3 ���������������sheet���������������
- ������������������������������������������������A������
- ������������������������
������WinForm������
WinForm���������������
- ������������������������������������
- ���������������������������
- ���������������������������������������������������������
- ������������������������������������������
������������������
3.1 ������������������
private void openFileBtn_Click(object sender, EventArgs e){ if (openFileDialog1.ShowDialog(this) == DialogResult.OK) { File_Address_textBox1.Text = openFileDialog1.FileName; }}
3.2 ������������������
private void saveFileBtn_Click(object sender, EventArgs e){ if (saveFileDialog1.ShowDialog(this) == DialogResult.OK) { File_Address_textBox2.Text = saveFileDialog1.FileName; }}
3.3 ������������������
private void beginBtn_Click(object sender, EventArgs e){ // 1. ������������������ string constr = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + File_Address_textBox1.Text + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'"; OleDbConnection myConn = new OleDbConnection(constr); // 2. ������������ OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", myConn); OleDbDataAdapter db = new OleDbDataAdapter("SELECT * FROM [������$]", myConn); DataSet ds = new DataSet(); DataSet ds2 = new DataSet(); da.Fill(ds, "[Sheet1$]"); db.Fill(ds2, "[������$]"); myConn.Close(); // 3. ������������������ Listlists = new List (); foreach (DataRow d in ds.Tables[0].Rows) { orders item = new orders(); string name = d.ItemArray[1].ToString(); if (name == "") { continue; } int num = int.Parse(d.ItemArray[2].ToString()); foreach (orders temp in lists) { if (temp.name == name) { temp.num += num; break; } } if (!lists.Any(t => t.name == name)) { item.name = name; item.num = num; lists.Add(item); } } // 4. ������������������ foreach (DataRow d in ds2.Tables[0].Rows) { string name = d.ItemArray[0].ToString(); float price = float.Parse(d.ItemArray[1].ToString()); foreach (orders temp in lists) { if (temp.name == name) { temp.totle = temp.num * price; } } } saveExcelFile(lists);}
3.4 ������Excel������
private void saveExcelFile(Listlists){ StreamWriter strmWriterObj = new StreamWriter(File_Address_textBox2.Text, false, Encoding.UTF8); strmWriterObj.WriteLine("������,������,������,������"); foreach (orders temp in lists) { strmWriterObj.WriteLine(temp.name + "," + temp.num + "," + temp.price + "," + temp.totle); } strmWriterObj.WriteLine("���������," + GetTotalNum(lists) + ", , " + GetTotalPrice(lists)); strmWriterObj.Close(); MessageBox.Show("������������");}
���������������������
public class orders{ public string name { get; set; } = ""; public int num { get; set; } = 0; public float price { get; set; } = 0; public float totle { get; set; } = 0;}
������������������
private static int GetTotalNum(Listlists){ int total = 0; foreach (orders temp in lists) { total += temp.num; } return total;}private static float GetTotalPrice(List lists){ float total = 0; foreach (orders temp in lists) { total += temp.totle; } return total;}
发表评论
最新留言
初次前来,多多关照!
[***.217.46.12]2025年04月27日 18时18分36秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【JavaLearn】 # 培训(一)—— JavaSE查漏补缺
2021-05-10
SpringBoot找不到@EnableRety注解
2021-05-10
JQuery 基础 || 目前 jQuery 有三个大版本||JQuery快速入门
2021-05-10
简易计算器案例
2021-05-10
在Vue中使用样式——使用内联样式
2021-05-10
@pathVariable 映射URL绑定的占位符
2021-05-10
案例:验证用户名是否可用
2021-05-10
基于组件的案例:购物车
2021-05-10
实现简易前端路由
2021-05-10
桥接模式
2021-05-10
application.yml如何显示成小叶子图标
2021-05-10
MySQL 高级 - 存储过程 - 函数
2021-05-10
Explore Optimization
2021-05-10
js的知识点14
2021-05-10
MATLAB知识点1
2021-05-10
数据挖掘
2021-05-10
《区块链基础知识25讲》-第二十二讲-区块链的缺陷
2021-05-10
交换机基础知识 - 从零开始学习
2021-05-10
Kali Linux 内网渗透教程 - ARP欺骗攻击 | 超详细
2021-05-10