Skip to content

Commit 8b302ea

Browse files
committed
报表
1 parent cda686e commit 8b302ea

File tree

94 files changed

+392
-1525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+392
-1525
lines changed

App/Codes/BaseController.cs

+90-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ public Account GetCurrentAccount()
4444

4545
}
4646
/// <summary>
47-
/// 导出数据集到excle
47+
/// 导出入库数据到excle
4848
/// </summary>
49-
/// <param name="titles">第一行显示的标题名称</param>
5049
/// <param name="fields">字段</param>
5150
/// <param name="query">数据集</param>
5251
/// <param name="path">excle模版的位置</param>
@@ -132,6 +131,95 @@ public string WriteExcleRuKu( string[] fields, dynamic[] query, string path = @"
132131
return string.Format("../../up/RuKu/{0}.xls", guid);
133132
//记录日志
134133

134+
}
135+
/// <summary>
136+
/// 导出报表证书信息查询数据到excle
137+
/// </summary>
138+
/// <param name="fields">字段</param>
139+
/// <param name="query">数据集</param>
140+
/// <param name="path">excle模版的位置</param>
141+
/// <param name="from">显示的标题默认行数为1</param>
142+
/// <returns></returns>
143+
public string WriteExcleVZHENGSHUXINXICHAXUN(string[] fields, dynamic[] query, string path = @"~/up/VZHENGSHUXINXICHAXUN.xls", int from = 1)
144+
{
145+
HSSFWorkbook _book = new HSSFWorkbook();
146+
string xlsPath = System.Web.HttpContext.Current.Server.MapPath(path);//物理路径
147+
148+
FileStream file = new FileStream(xlsPath, FileMode.Open, FileAccess.Read);//打开文件
149+
IWorkbook hssfworkbook = new HSSFWorkbook(file);//数据流进行编辑
150+
ISheet sheet = hssfworkbook.GetSheet("证书信息查询");//读取工作表
151+
string guid = Guid.NewGuid().ToString();//生产唯一标识
152+
string saveFileName = xlsPath.Path(@"BaoBiao/" + guid+ "VZHENGSHUXINXICHAXUN");
153+
154+
Dictionary<string, string> propertyName;
155+
PropertyInfo[] properties;
156+
//标题行
157+
var titles = "送检单位,证书单位,受理单位,出厂日期,器具名称,生产厂家,器具型号,出厂编号,准确度等级,检定日期,温度(℃),相对湿度(%),脉冲常数(imp/kWh),器具规格,检定/校准员,核验员,有效期(年),有效期至,证书/报告编号,证书类别,报告类别,授权/资质,发放状态,所属单位,委托单号,备注".Split(',');
158+
159+
var dd = sheet.GetRow(0).GetCell(1).CellStyle;
160+
161+
162+
163+
HSSFRow dataRow = sheet.CreateRow(0) as HSSFRow;
164+
165+
166+
ICellStyle cellStyle = hssfworkbook.CreateCellStyle();
167+
cellStyle.ShrinkToFit = true;
168+
for (int i = 0; i < titles.Length; i++)
169+
{
170+
if (!string.IsNullOrWhiteSpace(titles[i]))
171+
{
172+
var cell = dataRow.CreateCell(i);
173+
cell.CellStyle = dd;
174+
cell.SetCellValue(titles[i]); //列值
175+
176+
}
177+
}
178+
//内容行
179+
for (int i = 0; i < query.Length; i++)
180+
{
181+
propertyName = new Dictionary<string, string>();
182+
if (query[i] == null)
183+
{
184+
continue;
185+
}
186+
Type type = query[i].GetType();
187+
properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
188+
foreach (PropertyInfo property in properties)
189+
{
190+
object o = property.GetValue(query[i], null);
191+
if (!string.IsNullOrEmpty(property.Name) && o != null)
192+
{
193+
propertyName.Add(property.Name, o.ToString());
194+
}
195+
}
196+
int j = 0;
197+
dataRow = sheet.CreateRow(i + from) as HSSFRow;
198+
fields.All(a =>
199+
{
200+
201+
if (propertyName.ContainsKey(a)) //列名
202+
{
203+
var cell = dataRow.CreateCell(j);
204+
205+
cell.SetCellValue(propertyName[a]);
206+
//列值
207+
}
208+
j++;
209+
return true;
210+
});
211+
}
212+
sheet.ForceFormulaRecalculation = true;
213+
using (FileStream fileWrite = new FileStream(saveFileName, FileMode.Create))
214+
{
215+
hssfworkbook.Write(fileWrite);
216+
}
217+
218+
219+
//一般只用写这一个就OK了,他会遍历并释放所有资源,但当前版本有问题所以只释放sheet
220+
return string.Format("../../up/BaoBiao/{0}.xls", guid + "VZHENGSHUXINXICHAXUN");
221+
//记录日志
222+
135223
}
136224
/// <summary>
137225
/// 导出数据集到excle

App/Controllers/VZHENGSHUXINXICHAXUNController.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,26 @@ public JsonResult GetData(string id, int page, int rows, string order, string so
8585
});
8686
}
8787

88-
88+
/// <summary>
89+
/// 导出报告
90+
/// </summary>
91+
/// <param name="page">页码</param>
92+
/// <param name="rows">每页显示的行数</param>
93+
/// <param name="order">排序字段</param>
94+
/// <param name="sort">升序asc(默认)还是降序desc</param>
95+
/// <param name="search">查询条件</param>
96+
/// <returns></returns>
97+
[HttpPost]
98+
[SupportFilter]
99+
public ActionResult GetData2(string order, string sort, string search)
100+
{
101+
int total = 0;
102+
List<VZHENGSHUXINXICHAXUN> queryData = m_BLL.GetByParam(null, 1, 9999, "desc", "ID", search, ref total);
103+
string[] fields = "SONGJIANDANWEI,ZHENGSHUDANWEI,SHOULIDANWEI,CHUCHANGRIQI,QIJUMINGCHENG,SHENGCHANCHANGJIA,QIJUXINGHAO,CHUCHANGBIANHAO,ZHUNQUEDUDENGJI,JIANDINGRIQI,WENDU,XIANGDUISHIDU,MOCHONGCHANGSHU,QIJUGUIGE,JIANDINGXIAOZHUNYUAN,HEYANYUAN,YOUXIAOQI,YOUXIAOQIZHI,ZHENGSHUBAOGAOBIANHAO,ZHENGSHULEIBIE,BAOGAOLEIBIE,SHOUQUANZIZHI,FAFANGZHUANGTAI,SUOSHUDANWEI,WEITUODANWEI,BEIZHU".Split(',');
104+
var a = Content(WriteExcleVZHENGSHUXINXICHAXUN(fields, queryData.ToArray()));
105+
return a;
106+
107+
}
89108
IBLL.IVZHENGSHUXINXICHAXUNBLL m_BLL;
90109

91110
ValidationErrors validationErrors = new ValidationErrors();

App/Views/VZHENGSHUXINXICHAXUN/Index.cshtml

+44-18
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626
@Html.LabelFor(model => model.SHOULIDANWEI):
2727
</div>
2828
<div class="input_search-field">
29-
<input type='text' id='SHOULIDANWEI' />
29+
@Html.DropDownList("SHOULIDANWEI", Models.SysFieldModels.GetSysField("Appliance", "ACCEPT_ORGNIZATION"),"请选择")
3030
</div>
3131
</div>
3232
<div class="input_search">
3333
<div class="input_search-label">
3434
@Html.LabelFor(model => model.YOUXIAOQIZHI):
3535
</div>
3636
<div class='input_search-field-time'>
37-
<input type="text" id="YOUXIAOQIZHIStart_Time2" onclick="WdatePicker({ maxDate: '#F{$dp.$D(\'YOUXIAOQIZHIStart_Time\');}' })" />
37+
<input type="text" id="YOUXIAOQIZHIStart_Time" onclick="WdatePicker({ maxDate: '#F{$dp.$D(\'YOUXIAOQIZHIStart_Time\');}' })" />
3838
<span>到</span>
39-
<input type="text" id="YOUXIAOQIZHIEnd_Time2" onclick="WdatePicker({ minDate: '#F{$dp.$D(\'YOUXIAOQIZHIEnd_Time\');}' })" />
39+
<input type="text" id="YOUXIAOQIZHIEnd_Time" onclick="WdatePicker({ minDate: '#F{$dp.$D(\'YOUXIAOQIZHIEnd_Time\');}' })" />
4040
</div>
4141
</div>
4242
<div class="input_search">
@@ -113,14 +113,6 @@
113113
</select>
114114
</div>
115115
</div>
116-
<div class="input_search">
117-
<div class="input_search-label">
118-
@Html.LabelFor(model => model.SHOULIDANWEI):
119-
</div>
120-
<div class="input_search-field">
121-
<input type='text' id='SHOULIDANWEI' />
122-
</div>
123-
</div>
124116
<div class='input_search' style="padding-top:10px;">
125117
<a href="#" onclick="flexiQuery()" class="easyui-linkbutton" data-options="iconCls:'icon-search'">
126118
查 询
@@ -198,13 +190,13 @@
198190
199191
toolbar: [
200192
201-
//{
202-
// text: '详细',
203-
// iconCls: 'icon-search',
204-
// handler: function () {
205-
// return getView();
206-
// }
207-
//}
193+
{
194+
text: '打印报告',
195+
iconCls: 'icon-print',
196+
handler: function () {
197+
return flexiExport();
198+
}
199+
}
208200
],
209201
columns: [[
210202
@@ -327,6 +319,40 @@
327319
return false;
328320
}
329321
322+
//“导出”按钮 在6.0版本中修改
323+
function flexiExport() {
330324
325+
//将查询条件按照分隔符拼接成字符串
326+
var search = "";
327+
$('#divQuery').find(":text,:selected,select,textarea,:hidden,:checked,:password").each(function () {
328+
if (this.id)
329+
if (this.id == "FAFANGZHUANGTAI" && this.value == "报告未领取") {
330+
search = search + this.id + "&^";
331+
}
332+
else {
333+
search = search + this.id + "&" + this.value + "^";
334+
}
335+
else
336+
if (this.id == "FAFANGZHUANGTAI" && this.value == "报告未领取") {
337+
search = search + this.id + "&^";
338+
}
339+
else {
340+
search = search + this.id + "&" + this.value + "^";
341+
}
342+
});
343+
344+
345+
$.post('../VZHENGSHUXINXICHAXUN/GetData2',
346+
{
347+
348+
sortName: $('#flexigridData').datagrid('options').sortName,
349+
sortOrder: $('#flexigridData').datagrid('options').sortOrder,
350+
search: search
351+
}, function (res) {
352+
window.location.href = res;
353+
354+
355+
});
356+
};
331357
</script>
332358

0 commit comments

Comments
 (0)