多工段查询存放到DataTable到List<DataTable>集合在C#里面做汇总
private void btnQuery_Click(object sender, EventArgs e)
{
if (cboxFactory.Text=="")
{
MessageBox.Show("请选择厂别!","系统提示");
return;
}
fname = cboxFactory.Text;
//gongyi = cmbGongYi.Text.Trim();
List gongDuans = new List();//工段数组
gongyi = new List();
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
if (checkedListBox1.GetItemChecked(i))
{
gongDuans.Add(checkedListBox1.Items[i].ToString());
}
}
for (int i = 0; i < checkedListBox2.Items.Count; i++)
{
if (checkedListBox2.GetItemChecked(i))
{
gongyi.Add(checkedListBox2.Items[i].ToString());
}
}
backgroundWorker1.RunWorkerAsync(gongDuans);
ChangState();
}
Thread myThread;
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
myThread = Thread.CurrentThread;
List<string> gongDuans =(List<string>)e.Argument;
String gongyis = "";
if (gongyi.Count > 0)
{
for (int j = 0; j < gongyi.Count; j++)
{
gongyis = gongyis + gongyi[j];
if (j != gongyi.Count-1) gongyis = gongyis + "-";
}
}
if (gongDuans.Count>0)
{
List<DataTable> dts = new List<DataTable>();
for (int i = 0; i < gongDuans.Count; i++)
{
if (!backgroundWorker1.CancellationPending)
{
dts.Add(GetDuiZhi(gongDuans[i],fname,gongyis));
}
}
backgroundWorker1.ReportProgress(100, dts);
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
try
{
List<DataTable> dtPays = e.UserState as List<DataTable>;
Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook();
workbook.Open(Application.StartupPath + @"\Templates\在制品堆积表1.xlt");
Aspose.Cells.Worksheet sheet = workbook.Worksheets[0];//第一个工作表
sheet.Cells["B2"].PutValue(cboxFactory.Text);
quTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
sheet.Cells["J2"].PutValue(quTime);
int lastIndex = 3;
#region 构造带汇总的新集合
List<DataTable> dtNewPays = new List<DataTable>();
if (dtPays != null && dtPays.Count > 0)
{
foreach (DataTable item in dtPays)
{
DataRow newRow = item.NewRow();
int orderPaiNum=0
,Lnum=0
,Tnum=0
,duiZhiNum=0
,rong=0;
decimal LAh = 0
, TAh = 0;
//newRow["gongDuan"] = item.Rows[0]["gongDuan"].ToString()+"合计";
orderPaiNum = Convert.ToInt32(item.Compute("sum(orderPaiNum)", "true") is DBNull ? 0 : item.Compute("sum(orderPaiNum)", "true"));
newRow["orderPaiNum"] = orderPaiNum;
Lnum = Convert.ToInt32(item.Compute("sum(Lnum)", "true") is DBNull ? 0 : item.Compute("sum(Lnum)", "true"));
newRow["Lnum"] = Lnum;
Tnum = Convert.ToInt32(item.Compute("sum(Tnum)", "true") is DBNull ? 0 : item.Compute("sum(Tnum)", "true"));
newRow["Tnum"] = Tnum;
duiZhiNum = Convert.ToInt32(item.Compute("sum(duiZhiNum)", "true") is DBNull ? 0 : item.Compute("sum(duiZhiNum)", "true"));
//if (newRow["gongDuan"].ToString()=="制片合计")
// newRow["duiZhiNum"] = Convert.ToInt32(duiZhiNum/2);
//else
newRow["duiZhiNum"] =duiZhiNum;
rong = Convert.ToInt32(item.Compute("sum(rong)", "true") is DBNull ? 0 : item.Compute("sum(rong)", "true"));
newRow["rong"] = rong;
LAh = Convert.ToDecimal(item.Compute("sum(LAh)", "true") is DBNull ? 0 : item.Compute("sum(LAh)", "true"));
newRow["LAh"] = LAh;
TAh = Convert.ToDecimal(item.Compute("sum(TAh)", "true") is DBNull ? 0 : item.Compute("sum(TAh)", "true"));
newRow["TAh"] = TAh;
item.Rows.Add(newRow);
//新增列(该列隐藏)
//item.Columns.Add(new DataColumn("duiZhiNum1", typeof(Int32)));
//foreach (DataRow row in item.Rows)
//{
// //制片堆积个数除以2
// if (row["gongDuan"].ToString() == "制片")
// row["duiZhiNum1"] = Convert.ToDouble(row["duiZhiNum"]) / 2;
// else
// row["duiZhiNum1"] = row["duiZhiNum"];
//}
//清除0
DataTable dtWithOutZrro = ClearZero(item);
dtNewPays.Add(dtWithOutZrro);
//foreach (DataRow row in item.Rows)
//{
// oderPaiNum += Convert.ToInt32(row["oderPaiNum"].ToString() == "" ? "0" : row["oderPaiNum"].ToString());
// Lnum += Convert.ToInt32(row["Lnum"].ToString() == "" ? "0" : row["Lnum"].ToString());
// Tnum += Convert.ToInt32(row["Tnum"].ToString() == "" ? "0" : row["Tnum"].ToString());
// duiZhiNum += Convert.ToInt32(row["duiZhiNum"].ToString() == "" ? "0" : row["duiZhiNum"].ToString());
// rong += Convert.ToInt32(row["rong"].ToString() == "" ? "0" : row["rong"].ToString());
// LAh += Convert.ToDecimal(row["LAh"].ToString() == "" ? "0" : row["LAh"].ToString());
// TAh+=Convert.ToDecimal(row["TAh"].ToString() == "" ? "0" : row["TAh"].ToString())
//}
}
}
#endregion
if (dtNewPays != null && dtNewPays.Count > 0)
{
for (int i = 0; i < dtNewPays.Count; i++)
{
DataTable dt = dtNewPays[i];
if (dt.Rows.Count > 0)
{
sheet.Cells.ImportDataTable(dt, false, "A" + (lastIndex + 1));
lastIndex += dt.Rows.Count;
}
}
}
sheet.Cells.DeleteRows(lastIndex, 2);
MemoryStream ms = workbook.SaveToStream();
ms.Seek(0, SeekOrigin.Begin);
fpSpread1.OpenExcel(ms);
ms.Close();
fpSpread1.Sheets[0].RowCount = lastIndex + 3;
fpSpread1.Sheets[0].ColumnCount = 16;
//fpSpread1.Sheets[0].Columns[13].Visible = false;
fpSpread1.Sheets[0].OperationMode = FarPoint.Win.Spread.OperationMode.ReadOnly;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// 清除零值
/// </summary>
/// <returns></returns>
public DataTable ClearZero(DataTable dt)
{
DataTable result = dt.Clone();
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = result.NewRow();
for (int j = 0; j < dt.Columns.Count; j++)
{
if (dt.Rows[i][j].ToString() == "0" || dt.Rows[i][j].ToString() == "0.00%")
{
dr[j] = DBNull.Value;
}
else
{
dr[j] = dt.Rows[i][j];
}
}
result.Rows.Add(dr);
}
return result;
}
多工段查询存放到DataTable到List<DataTable>集合在C#里面做汇总的更多相关文章
- 从数据库得到的结果集存放到List集合中
一.业务阐述 在开发中查询的数据库结果集,既要连接数据库.执行数据库操作.关闭数据库,还要把结果集的记录人为的设置到自己封装的DAO中等一系列的重复代码. 本文主要是想解决:用户只需要得到数据库连接, ...
- 获取项目中文件,存放到Debug中。
说起这个,还真是费了一般功夫. 说个最简单的方法: 第一步:把需要生成到Debug中的文件放到项目中(注意:当前文件夹目录是什么样的,存放到Debug中也是什么样) 第二部:设置文件属性中 复制到输出 ...
- Solr(六)Solr索引数据存放到HDFS下
Solr索引数据存放到HDFS下 一 新建solr core hdfs 方法:http://www.cnblogs.com/Matchman/p/7287385.html 二 修改solrconfig ...
- C#将图片存放到SQL SERVER数据库中的方法
本文实例讲述了C#将图片存放到SQL SERVER数据库中的方法.分享给大家供大家参考.具体如下: 第一步: ? 1 2 3 4 5 6 7 8 9 10 //获取当前选择的图片 this.pictu ...
- 乐视云监控数据存放到influxdb中
3.9 监控.告警系统 监控报警我们分PaaS平台和业务应用两大类. PaaS平台主要聚焦在基础设施和LeEngine的各个服务组件的监控报警(比如主机CPU,内存,IO,磁盘空间,LeEng ...
- 【PHP】如何将SESSION数据存放到Redis中
在php中,SESSION的数据默认是存放到文件中,这样性能不仅不高,而且不利于扩展.在搭建集群后,默认存放到文件中就不适用了.所以,我们一般将SESSION自定义,让SESSION中的数据存放到 数 ...
- 在DataTable中执行DataTable.Select("条件")返回DataTable;
转:http://blog.csdn.net/hcf_force/article/details/7779062 1.在DataTable中执行DataTable.Select("条件&qu ...
- DataTable.select() 返回 DataTable
DataTable.select() 默认返回值为 DataRow[]数组 代码来自网络: /**/ /// <summary> /// 执行DataTable中的查询返回新的DataTa ...
- 在DataTable中执行DataTable.Select("条件")
.在DataTable中执行DataTable.Select("条件")返回DataTable: // <summary> // 执行DataTable中的查询返回 ...
随机推荐
- extjs 6.2 helloworld
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Openjudge-NOI题库-垂直直方图
题目描述 Description 写一个程序从输入文件中去读取四行大写字母(全都是大写的,每行不超过72个字符),然后用柱状图输出每个字符在输入文件中出现的次数.严格地按照输出样例来安排你的输出格式. ...
- <hdu-2032>杨辉三角
这是杭电hdu上杨辉三角的链接:http://acm.hdu.edu.cn/showproblem.php?pid=2032 Problem Description: 还记得中学时候学过的杨辉三角吗 ...
- 使用android的mediaplayer做成 一个demo,欢迎测试使用
附件是为一个定制视频产品而简单的写了一个demo,用来说明android的mediaplayer是如何使用的. http://files.cnblogs.com/guobaPlayer/palyerD ...
- html5获取图片的宽高
var fr = new FileReader; fr.readAsDataURL($("#inputFileId").files[0]); fr.onload = functio ...
- SSLv3协议、TLSv1.2协议配置不对导致javax.ws.rs.ProcessingException: java.net.SocketException: Connection reset
SSl:Secure Sockets Layer 安全套接层 TLS:Transport Layer Security传输层安全 是为网络通信提供安全及数据完整性的一种安全协议.TLS与SSL在传输层 ...
- Base algorithm
今天介绍几种常见的算法,在面试中或许能派上用场 1.字符串倒转 //Reverse a string public static string Reverse(string ori) { string ...
- MSMQ小Demo
Demo基于http://www.cnblogs.com/zhili/p/MSMQ.html Server代码: using System.Messaging; using System.Text; ...
- TheSeventhWeekJavaText
如何用二维数组绘制五子棋盘 在定义一个棋盘类,声明一个二维字符数组,为每一个数组元素赋值为"+",打印输出就是一个简单地棋盘,如下图: 然后定义BufferedReader的实例对 ...
- SPA UI-router
------------------------------------------------------------------------------------ SPA SPA(单页面应用): ...