1212
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
using BLL;
|
||||
using BLL.Common;
|
||||
using BLL.CQMS.Comprehensive;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
|
||||
|
||||
namespace FineUIPro.Web.Transfer
|
||||
{
|
||||
@@ -22,13 +29,12 @@ namespace FineUIPro.Web.Transfer
|
||||
{
|
||||
GetButtonPower();
|
||||
BindGrid();
|
||||
|
||||
this.btnNew.OnClientClick = Window1.GetShowReference("PunchlistFromEdit.aspx") + "return false;";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据绑定
|
||||
/// </summary>
|
||||
public void BindGrid()
|
||||
public DataTable DataSql()
|
||||
{
|
||||
string strSql = @"select *
|
||||
,(CASE isnull(IsEng,0) WHEN 1 THEN 'Y' ELSE 'N' END) IsEngStr
|
||||
@@ -38,10 +44,10 @@ namespace FineUIPro.Web.Transfer
|
||||
List<SqlParameter> listStr = new List<SqlParameter>();
|
||||
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
|
||||
|
||||
if (!string.IsNullOrEmpty(this.txtNum_NO.Text.Trim()))
|
||||
if (!string.IsNullOrEmpty(this.txtRaised_By.Text.Trim()))
|
||||
{
|
||||
strSql += " AND Num_NO like @Num_NO";
|
||||
listStr.Add(new SqlParameter("@Num_NO", "%" + this.txtNum_NO.Text.Trim() + "%"));
|
||||
strSql += " AND Raised_By = @Raised_By";
|
||||
listStr.Add(new SqlParameter("@Raised_By", this.txtRaised_By.Text.Trim()));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(this.txtSystem_No.Text.Trim()))
|
||||
{
|
||||
@@ -96,16 +102,49 @@ namespace FineUIPro.Web.Transfer
|
||||
if (!string.IsNullOrEmpty(ddlMatI.SelectedValue.Trim()))
|
||||
{
|
||||
strSql += " AND IsMatI = @IsMatI";
|
||||
listStr.Add(new SqlParameter("@IsMatI", ddlMatI.SelectedValue.Trim() == "Y" ? 1 : 0));
|
||||
listStr.Add(new SqlParameter("@IsMatI", ddlMatI.SelectedValue.Trim()));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(ddlPunchType.SelectedValue.Trim()))
|
||||
{
|
||||
strSql += " AND Punch_Type = @Punch_Type";
|
||||
listStr.Add(new SqlParameter("@Punch_Type", ddlPunchType.SelectedValue.Trim()));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(ddlCat.SelectedValue.Trim()))
|
||||
{
|
||||
strSql += " AND Cat = @Cat";
|
||||
listStr.Add(new SqlParameter("@Cat", ddlCat.SelectedValue.Trim()));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(txtAction_By.Text.Trim()))
|
||||
{
|
||||
strSql += " AND Action_By = @Action_By";
|
||||
listStr.Add(new SqlParameter("@Action_By", txtAction_By.Text.Trim()));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(txtPIC.Text.Trim()))
|
||||
{
|
||||
strSql += " AND PIC = @PIC";
|
||||
listStr.Add(new SqlParameter("@PIC", txtPIC.Text.Trim()));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(txtPIC_WUH.Text.Trim()))
|
||||
{
|
||||
strSql += " AND PIC_WUH = @PIC_WUH";
|
||||
listStr.Add(new SqlParameter("@PIC_WUH", txtPIC_WUH.Text.Trim()));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(ddlStatus.SelectedValue.Trim()))
|
||||
{
|
||||
strSql += " AND Status = @Status";
|
||||
listStr.Add(new SqlParameter("@Status", ddlStatus.SelectedValue.Trim()));
|
||||
}
|
||||
strSql += " order by Num_No ";
|
||||
SqlParameter[] parameter = listStr.ToArray();
|
||||
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
|
||||
return SQLHelper.GetDataTableRunText(strSql, parameter);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据绑定
|
||||
/// </summary>
|
||||
public void BindGrid()
|
||||
{
|
||||
DataTable tb = DataSql();
|
||||
Grid1.RecordCount = tb.Rows.Count;
|
||||
var table = this.GetPagedDataTable(Grid1, tb);
|
||||
Grid1.DataSource = table;
|
||||
@@ -277,13 +316,13 @@ namespace FineUIPro.Web.Transfer
|
||||
{
|
||||
if (buttonList.Contains(BLL.Const.BtnAdd))
|
||||
{
|
||||
//this.btnNew.Hidden = false;
|
||||
this.btnNew.Hidden = false;
|
||||
btnMenuAttachA.Hidden = false;
|
||||
btnMenuAttachB.Hidden = false;
|
||||
}
|
||||
if (buttonList.Contains(BLL.Const.BtnModify))
|
||||
{
|
||||
//this.btnMenuModify.Hidden = false;
|
||||
this.btnMenuModify.Hidden = false;
|
||||
this.Grid1.EnableRowDoubleClickEvent = true;
|
||||
btnMenuAttachA.Hidden = false;
|
||||
btnMenuAttachB.Hidden = false;
|
||||
@@ -304,25 +343,140 @@ namespace FineUIPro.Web.Transfer
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 附件上传
|
||||
#region 编辑
|
||||
/// <summary>
|
||||
/// 附件上传
|
||||
/// 右键编辑事件
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void btnAttach_Click(object sender, EventArgs e)
|
||||
protected void btnMenuModify_Click(object sender, EventArgs e)
|
||||
{
|
||||
var buttonList = BLL.CommonService.GetAllButtonList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.PunchlistFromMenuId);
|
||||
if (buttonList.Contains(BLL.Const.BtnAdd))
|
||||
if (Grid1.SelectedRowIndexArray.Length == 0)
|
||||
{
|
||||
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../AttachFile/webuploader.aspx?type=0&toKeyId={0}&path=FileUpload/Transfer/PunchlistFrom&menuId={1}", this.CurrUser.LoginProjectId + "PunchlistFrom", BLL.Const.PunchlistFromMenuId)));
|
||||
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
else
|
||||
string id = Grid1.SelectedRowID;
|
||||
var accidentPersonRecord = Funs.DB.Transfer_PunchlistFrom.FirstOrDefault(p => p.Id == id);
|
||||
if (accidentPersonRecord == null)
|
||||
{
|
||||
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/Transfer/PunchlistFrom&menuId={1}", this.CurrUser.LoginProjectId + "PunchlistFrom", BLL.Const.PunchlistFromMenuId)));
|
||||
|
||||
Alert.ShowInTop("修改的数据已经不存在,请检查!", MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("PunchlistFromEdit.aspx?Id={0}", id, "编辑 - ")));
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// 导出按钮
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void btnOut_Click(object sender, EventArgs e)
|
||||
{
|
||||
string rootPath = Server.MapPath("~/");
|
||||
string initTemplatePath = string.Empty;
|
||||
string uploadfilepath = string.Empty;
|
||||
string newUrl = string.Empty;
|
||||
string filePath = string.Empty;
|
||||
initTemplatePath = "File\\Excel\\DataOut\\PunchlistFrom导出模板.xlsx";
|
||||
uploadfilepath = rootPath + initTemplatePath;
|
||||
|
||||
DataTable tb = DataSql();
|
||||
if (tb.Rows.Count <= 0)
|
||||
{
|
||||
ShowNotify("没有要导出的数据!!!", MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
newUrl = uploadfilepath.Replace("导出模板","导出数据").Replace(".xlsx",DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx");
|
||||
File.Copy(uploadfilepath, newUrl);
|
||||
NPOI.SS.UserModel.IWorkbook workbook;
|
||||
using (FileStream stream = new FileStream(newUrl, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(stream);
|
||||
}
|
||||
|
||||
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
|
||||
|
||||
int i = 2;
|
||||
foreach (DataRow tbRow in tb.Rows)
|
||||
{
|
||||
NPOI.SS.UserModel.IRow row = sheet.CreateRow(i);
|
||||
NPOI.SS.UserModel.ICell cell;
|
||||
cell = row.CreateCell(0);
|
||||
cell.SetCellValue(tbRow["Num_NO"]==null?"": tbRow["Num_NO"].ToString());
|
||||
cell = row.CreateCell(1);
|
||||
cell.SetCellValue(tbRow["System_No"] == null ? "" : tbRow["System_No"].ToString());
|
||||
cell = row.CreateCell(2);
|
||||
cell.SetCellValue(tbRow["Sub_Sys_No"] == null ? "" : tbRow["Sub_Sys_No"].ToString());
|
||||
cell = row.CreateCell(3);
|
||||
cell.SetCellValue(tbRow["DESCRIPTION"] == null ? "" : tbRow["DESCRIPTION"].ToString());
|
||||
|
||||
cell = row.CreateCell(5);
|
||||
cell.SetCellValue(tbRow["Cat"] == null ? "" : tbRow["Cat"].ToString());
|
||||
cell = row.CreateCell(6);
|
||||
cell.SetCellValue(tbRow["Raised_By"] == null ? "" : tbRow["Raised_By"].ToString());
|
||||
cell = row.CreateCell(7);
|
||||
cell.SetCellValue(tbRow["Date_Raised"] == DBNull.Value ? "" :Convert.ToDateTime(tbRow["Date_Raised"]).ToString("yyyy-MM-dd"));
|
||||
cell = row.CreateCell(8);
|
||||
cell.SetCellValue(tbRow["Disc"] == null ? "" : tbRow["Disc"].ToString());
|
||||
cell = row.CreateCell(9);
|
||||
cell.SetCellValue(tbRow["IsEngStr"] == null ? "" : tbRow["IsEngStr"].ToString());
|
||||
cell = row.CreateCell(10);
|
||||
cell.SetCellValue(tbRow["IsMatIStr"] == null ? "" : tbRow["IsMatIStr"].ToString());
|
||||
cell = row.CreateCell(11);
|
||||
cell.SetCellValue(tbRow["Punch_Type"] == null ? "" : tbRow["Punch_Type"].ToString());
|
||||
cell = row.CreateCell(12);
|
||||
cell.SetCellValue(tbRow["Required_Date"] == DBNull.Value ? "" : Convert.ToDateTime(tbRow["Required_Date"]).ToString("yyyy-MM-dd"));
|
||||
cell = row.CreateCell(13);
|
||||
cell.SetCellValue(tbRow["Action_By"] == null ? "" : tbRow["Action_By"].ToString());
|
||||
cell = row.CreateCell(14);
|
||||
cell.SetCellValue(tbRow["PIC"] == null ? "" : tbRow["PIC"].ToString());
|
||||
cell = row.CreateCell(15);
|
||||
cell.SetCellValue(tbRow["PIC_WUH"] == null ? "" : tbRow["PIC_WUH"].ToString());
|
||||
cell = row.CreateCell(16);
|
||||
cell.SetCellValue(tbRow["Correction_Action"] == null ? "" : tbRow["Correction_Action"].ToString());
|
||||
|
||||
cell = row.CreateCell(18);
|
||||
cell.SetCellValue(tbRow["Actual_Date"] == DBNull.Value ? "" : Convert.ToDateTime(tbRow["Actual_Date"]).ToString("yyyy-MM-dd"));
|
||||
cell = row.CreateCell(19);
|
||||
cell.SetCellValue(tbRow["Cleared_By"] == null ? "" : tbRow["Cleared_By"].ToString());
|
||||
cell = row.CreateCell(20);
|
||||
cell.SetCellValue(tbRow["Cleared_Date"] == DBNull.Value ? "" : Convert.ToDateTime(tbRow["Cleared_Date"]).ToString("yyyy-MM-dd"));
|
||||
cell = row.CreateCell(21);
|
||||
cell.SetCellValue(tbRow["Confirmed_By"] == null ? "" : tbRow["Confirmed_By"].ToString());
|
||||
cell = row.CreateCell(22);
|
||||
cell.SetCellValue(tbRow["Confirmed_Date"] == DBNull.Value ? "" : Convert.ToDateTime(tbRow["Confirmed_Date"]).ToString("yyyy-MM-dd"));
|
||||
cell = row.CreateCell(23);
|
||||
cell.SetCellValue(tbRow["Verified_By"] == null ? "" : tbRow["Verified_By"].ToString());
|
||||
cell = row.CreateCell(24);
|
||||
cell.SetCellValue(tbRow["Verified_Date"] == DBNull.Value ? "" : Convert.ToDateTime(tbRow["Verified_Date"]).ToString("yyyy-MM-dd"));
|
||||
cell = row.CreateCell(25);
|
||||
cell.SetCellValue(tbRow["Status"] == null ? "" : tbRow["Status"].ToString());
|
||||
cell = row.CreateCell(26);
|
||||
cell.SetCellValue(tbRow["Remark"] == null ? "" : tbRow["Remark"].ToString());
|
||||
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
// 第三步:写入文件流
|
||||
using (FileStream stream = new FileStream(newUrl, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
workbook.Write(stream);
|
||||
workbook.Close();
|
||||
}
|
||||
string fileName = Path.GetFileName(newUrl);
|
||||
FileInfo info = new FileInfo(newUrl);
|
||||
long fileSize = info.Length;
|
||||
Response.Clear();
|
||||
Response.ContentType = "application/x-zip-compressed";
|
||||
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
|
||||
Response.AddHeader("Content-Length", fileSize.ToString());
|
||||
Response.TransmitFile(newUrl, 0, fileSize);
|
||||
Response.Flush();
|
||||
Response.Close();
|
||||
File.Delete(newUrl);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user