CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/CQMS/Check/JointCheck.aspx.cs

608 lines
25 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
namespace FineUIPro.Web.CQMS.Check
{
public partial class JointCheck : PageBase
{
/// <summary>
/// 项目id
/// </summary>
public string ProjectId
{
get
{
return (string)ViewState["ProjectId"];
}
set
{
ViewState["ProjectId"] = value;
}
}
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower()
{
if (Request.Params["value"] == "0")
{
return;
}
var buttonList = BLL.CommonService.GetAllButtonList(this.ProjectId, this.CurrUser.UserId, BLL.Const.JointCheckMenuId);
if (buttonList.Count() > 0)
{
if (buttonList.Contains(BLL.Const.BtnAdd))
{
this.btnNew.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnModify))
{
this.btnMenuModify.Hidden = false;
}
if (buttonList.Contains(BLL.Const.BtnDelete))
{
this.btnMenuDel.Hidden = false;
}
}
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ProjectId = CurrUser.LoginProjectId;
GetButtonPower();
btnNew.OnClientClick = Window1.GetShowReference("EditJointCheck.aspx") + "return false;";
//if (!string.IsNullOrEmpty(Request.Params["projectId"]) && Request.Params["projectId"] != this.ProjectId)
//{
// this.ProjectId = Request.Params["projectId"];
//}
//权限按钮方法
UnitService.InitUnitByProjectIdUnitTypeDropDownList(drpSponsorUnit, this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_2, true);
JointCheckService.Init(drpCheckType, true);
JointCheckService.InitState(drpState, true);
bindata();
}
}
//<summary>
//获取办理人姓名
//</summary>
//<param name="state"></param>
//<returns></returns>
protected string ConvertMan(object JointCheckId)
{
string userNames = string.Empty;
if (JointCheckId != null)
{
List<Model.Check_JointCheckApprove> list = BLL.JointCheckApproveService.GetJointCheckApprovesByJointCheckId(JointCheckId.ToString());
foreach (var a in list)
{
if (a != null)
{
if (a.ApproveMan != null)
{
if (!userNames.Contains(BLL.UserService.GetUserByUserId(a.ApproveMan).UserName))
{
userNames += UserService.GetUserByUserId(a.ApproveMan).UserName + ",";
}
}
}
}
if (!string.IsNullOrEmpty(userNames))
{
userNames = userNames.Substring(0, userNames.LastIndexOf(","));
}
}
return userNames;
}
/// <summary>
/// 把状态转换代号为文字形式
/// </summary>
/// <param name="state"></param>
/// <returns></returns>
protected string ConvertState(object state)
{
if (state != null)
{
if (state.ToString() == BLL.Const.JointCheck_ReCompile)
{
return "重新编制";
}
else if (state.ToString() == BLL.Const.JointCheck_Compile)
{
return "编制";
}
else if (state.ToString() == BLL.Const.JointCheck_Audit1)
{
return "分包专工回复";
}
else if (state.ToString() == BLL.Const.JointCheck_Audit2)
{
return "分包负责人审批";
}
else if (state.ToString() == BLL.Const.JointCheck_Audit3)
{
return "总包专工回复";
}
else if (state.ToString() == BLL.Const.JointCheck_Audit4)
{
return "总包负责人审批";
}
else if (state.ToString() == BLL.Const.JointCheck_Complete)
{
return "审批完成";
}
else if (state.ToString() == BLL.Const.JointCheck_Z)
{
return "整改中";
}
else if (state.ToString() == BLL.Const.JointCheck_Audit1R)
{
return "分包专工重新回复";
}
else
{
return "";
}
}
return "";
}
//<summary>
//获取检查类别
//</summary>
//<param name="state"></param>
//<returns></returns>
protected string ConvertCheckType(object CheckType)
{
if (CheckType != null)
{
string checkType = CheckType.ToString();
if (checkType == "1")
{
return "周检查";
}
else if (checkType == "2")
{
return "月检查";
}
else if (checkType == "3")
{
return "不定期检查";
}
else if (checkType == "4")
{
return "专业检查";
}
}
return "";
}
/// <summary>
/// 列表数据
/// </summary>
private void bindata()
{
string strSql = @"SELECT chec.JointCheckId,chec.JointCheckCode,chec.State,chec.CheckDate,chec.CheckName,chec.unitId,"
+ @" unit.UnitName,u.userName as CheckMan,chec.CheckType "
+ @" FROM Check_JointCheck chec"
+ @" left join Base_Unit unit on unit.unitId=chec.unitId"
+ @" left join sys_User u on u.userId = chec.CheckMan"
+ @" where chec.ProjectId=@ProjectId";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId));
strSql += " AND (chec.CheckDate>=@startTime or @startTime='') and (chec.CheckDate<=@endTime or @endTime='') ";
listStr.Add(new SqlParameter("@startTime", !string.IsNullOrEmpty(txtStartTime.Text.Trim()) ? txtStartTime.Text.Trim() + " 00:00:00" : ""));
listStr.Add(new SqlParameter("@endTime", !string.IsNullOrEmpty(txtEndTime.Text.Trim()) ? txtEndTime.Text.Trim() + " 23:59:59" : ""));
if (drpSponsorUnit.SelectedValue != BLL.Const._Null)
{
strSql += " AND chec.unitId=@unitId";
listStr.Add(new SqlParameter("@unitId", drpSponsorUnit.SelectedValue));
}
if (drpCheckType.SelectedValue != BLL.Const._Null)
{
strSql += " AND chec.CheckType=@CheckType";
listStr.Add(new SqlParameter("@CheckType", drpCheckType.SelectedValue));
}
if (drpState.SelectedValue != BLL.Const._Null)
{
strSql += " AND chec.State=@State";
listStr.Add(new SqlParameter("@State", drpState.SelectedValue));
}
//if (drpCNProfessional.SelectedValue != Const._Null)
//{
// strSql += " AND chec.CNProfessionalCode=@CNProfessionalCode";
// listStr.Add(new SqlParameter("@CNProfessionalCode", drpCNProfessional.SelectedValue));
//}
//if (drpQuestionType.SelectedValue != Const._Null)
//{
// strSql += " AND chec.QuestionType=@QuestionType";
// listStr.Add(new SqlParameter("@QuestionType", drpQuestionType.SelectedValue));
//}
//if (dpHandelStatus.SelectedValue != Const._Null)
//{
// if (dpHandelStatus.SelectedValue.Equals("1"))
// {
// strSql += " AND (chec.state='5' or chec.state='6')";
// }
// else if (dpHandelStatus.SelectedValue.Equals("2"))
// {
// strSql += " AND chec.state='7'";
// }
// else if (dpHandelStatus.SelectedValue.Equals("3"))
// {
// strSql += " AND DATEADD(day,1,chec.LimitDate)< GETDATE() and chec.state<>5 and chec.state<>6 and chec.state<>7";
// }
// else if (dpHandelStatus.SelectedValue.Equals("4"))
// {
// strSql += " AND DATEADD(day,1,chec.LimitDate)> GETDATE() and chec.state<>5 and chec.state<>6 and chec.state<>7";
// }
//}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
GvJoinCheck.RecordCount = tb.Rows.Count;
ddlPageSize.SelectedValue = GvJoinCheck.PageSize.ToString();
tb = GetFilteredTable(GvJoinCheck.FilteredData, tb);
var table = GetPagedDataTable(GvJoinCheck, tb);
GvJoinCheck.DataSource = table;
GvJoinCheck.DataBind();
}
protected void btnQuery_Click(object sender, EventArgs e)
{
bindata();
}
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
GvJoinCheck.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
bindata();
}
protected void GvJoinCheck_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
edit(sender, e);
}
protected void GvJoinCheck_PageIndexChange(object sender, GridPageEventArgs e)
{
bindata();
}
protected void GvJoinCheck_FilterChange(object sender, EventArgs e)
{
}
protected void GvJoinCheck_Sort(object sender, GridSortEventArgs e)
{
}
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
bindata();
}
protected void btnMenuModify_Click(object sender, EventArgs e)
{
edit(sender, e);
}
protected void btnMenuView_Click(object sender, EventArgs e)
{
if (GvJoinCheck.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string jointCheckId = GvJoinCheck.SelectedRowID.Split(',')[0];
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("JointCheckView.aspx?JointCheckId={0}", jointCheckId, "查看 - ")));
}
protected void btnMenuDel_Click(object sender, EventArgs e)
{
if (GvJoinCheck.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string jointCheckId = GvJoinCheck.SelectedRowID.Split(',')[0];
JointCheckDetailService.DeleteJointCheckDetailByJointCheckId(jointCheckId);
JointCheckApproveService.DeleteJointCheckApprovesByJointCheckId(jointCheckId);
JointCheckService.DeleteJointCheck(jointCheckId);
LogService.AddSys_Log(CurrUser, "001", jointCheckId, Const.JointCheckMenuId, "删除质量共检记录");
Alert.ShowInTop("删除成功!", MessageBoxIcon.Warning);
bindata();
}
protected void edit(object sender, EventArgs e)
{
if (GvJoinCheck.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录!", MessageBoxIcon.Warning);
return;
}
string JointCheckId = GvJoinCheck.SelectedRowID.Split(',')[0];
Model.Check_JointCheck jointCheck = BLL.JointCheckService.GetJointCheck(JointCheckId);
Model.Check_JointCheckApprove approve = BLL.JointCheckApproveService.GetJointCheckApproveByJointCheckId(JointCheckId, this.CurrUser.UserId);
if (jointCheck.State == BLL.Const.JointCheck_Complete)
{
Alert.ShowInTop("该记录已审批完成,请右键查看!", MessageBoxIcon.Warning);
return;
}
if (CurrUser.UserId == Const.sysglyId)
{
if (jointCheck.State == BLL.Const.JointCheck_Compile)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("EditJointCheck.aspx?JointCheckId={0}", JointCheckId, "查看 - ")));
}
else
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("EditJointCheckTwo.aspx?JointCheckId={0}", JointCheckId, "查看 - ")));
}
return;
}
if (approve != null)
{
if (!string.IsNullOrEmpty(approve.ApproveMan))
{
if (this.CurrUser.UserId == approve.ApproveMan || CurrUser.UserId == Const.sysglyId)
{
if (jointCheck.State == BLL.Const.JointCheck_Compile)
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("EditJointCheck.aspx?JointCheckId={0}", JointCheckId, "查看 - ")));
}
else
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("EditJointCheckTwo.aspx?JointCheckId={0}", JointCheckId, "查看 - ")));
}
return;
}
else
{
Alert.ShowInTop("您不是当前办理人,无法操作,请右键查看!", MessageBoxIcon.Warning);
return;
}
}
}
else
{
Alert.ShowInTop("您不是当前办理人,无法操作,请右键查看!", MessageBoxIcon.Warning);
return;
}
}
protected void btnRset_Click(object sender, EventArgs e)
{
drpSponsorUnit.SelectedIndex = 0;
drpCheckType.SelectedIndex = 0;
drpState.SelectedIndex = 0;
txtStartTime.Text = "";
txtEndTime.Text = "";
bindata();
}
#region
/// 导出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
string rootPath = Server.MapPath("~/");
string initTemplatePath = Const.JointCheckTempUrl;
string uploadfilepath = string.Empty;
string newUrl = string.Empty;
uploadfilepath = rootPath + initTemplatePath;
var lists = from x in Funs.DB.Check_JointCheck where x.ProjectId == this.CurrUser.LoginProjectId select x;
if (!string.IsNullOrEmpty(txtStartTime.Text.Trim()))
{
lists = lists.Where(x => x.CheckDate >= Funs.GetNewDateTime(txtStartTime.Text.Trim() + " 00:00:00"));
}
if (!string.IsNullOrEmpty(txtEndTime.Text.Trim()))
{
lists = lists.Where(x => x.CheckDate <= Funs.GetNewDateTime(txtEndTime.Text.Trim() + " 23:59:59"));
}
if (drpSponsorUnit.SelectedValue != BLL.Const._Null)
{
lists = lists.Where(x => x.UnitId == drpSponsorUnit.SelectedValue);
}
if (drpCheckType.SelectedValue != BLL.Const._Null)
{
lists = lists.Where(x => x.CheckType == drpCheckType.SelectedValue);
}
if (drpState.SelectedValue != BLL.Const._Null)
{
lists = lists.Where(x => x.State == drpState.SelectedValue);
}
if (lists != null)
{
string projectName = BLL.ProjectService.GetShortNameByProjectId(this.CurrUser.LoginProjectId);
newUrl = uploadfilepath.Replace("质量专项检查模板", "质量专项检查(" + projectName + DateTime.Now.ToString("yyyyMMdd") + "");
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);
workbook = new NPOI.HSSF.UserModel.HSSFWorkbook(stream);
}
// 创建单元格样式
NPOI.SS.UserModel.ICellStyle cellStyle = workbook.CreateCellStyle();
cellStyle.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
var font = workbook.CreateFont();
font.FontHeightInPoints = 11;
cellStyle.SetFont(font);
NPOI.SS.UserModel.ICellStyle cellStyle0 = workbook.CreateCellStyle();
cellStyle0.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
cellStyle0.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
cellStyle0.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;
var font0 = workbook.CreateFont();
font0.FontHeightInPoints = 12;
font0.IsBold = true;
cellStyle0.SetFont(font0);
// 第二步:创建新数据行
NPOI.SS.UserModel.ISheet sheet = workbook.GetSheetAt(0);
NPOI.SS.UserModel.IRow row = sheet.GetRow(0);
NPOI.SS.UserModel.ICell cell;
int i = 2;
foreach (var item in lists)
{
// 第二步:创建新数据行
row = sheet.CreateRow(i);
// 添加数据
cell = row.CreateCell(0);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.JointCheckCode);
cell = row.CreateCell(1);
cell.CellStyle = cellStyle;
cell.SetCellValue(BLL.UnitService.GetUnitNameByUnitId(item.UnitId));
cell = row.CreateCell(2);
cell.CellStyle = cellStyle;
string checkName = string.Empty;
if (item.CheckType == "1")
{
checkName = "周检查";
}
else if (item.CheckType == "2")
{
checkName = "月检查";
}
else if (item.CheckType == "3")
{
checkName = "不定期检查";
}
else if (item.CheckType == "4")
{
checkName = "专业检查";
}
cell.SetCellValue(checkName);
cell = row.CreateCell(3);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.CheckName);
cell = row.CreateCell(4);
cell.CellStyle = cellStyle;
cell.SetCellValue(item.CheckDate.HasValue ? string.Format("{0:yyyy-MM-dd}", item.CheckDate) : "");
cell = row.CreateCell(5);
cell.CellStyle = cellStyle;
cell.SetCellValue(BLL.UserService.GetUserNameByUserId(item.CheckMan));
cell = row.CreateCell(6);
cell.CellStyle = cellStyle;
string state = string.Empty;
if (item.State.ToString() == BLL.Const.JointCheck_ReCompile)
{
state = "重新编制";
}
else if (item.State.ToString() == BLL.Const.JointCheck_Compile)
{
state = "编制";
}
else if (item.State.ToString() == BLL.Const.JointCheck_Audit1)
{
state = "分包专工回复";
}
else if (item.State.ToString() == BLL.Const.JointCheck_Audit2)
{
state = "分包负责人审批";
}
else if (item.State.ToString() == BLL.Const.JointCheck_Audit3)
{
state = "总包专工回复";
}
else if (item.State.ToString() == BLL.Const.JointCheck_Audit4)
{
state = "总包负责人审批";
}
else if (item.State.ToString() == BLL.Const.JointCheck_Complete)
{
state = "审批完成";
}
else if (item.State.ToString() == BLL.Const.JointCheck_Z)
{
state = "整改中";
}
else if (item.State.ToString() == BLL.Const.JointCheck_Audit1R)
{
state = "分包专工重新回复";
}
cell.SetCellValue(state);
cell = row.CreateCell(7);
cell.CellStyle = cellStyle;
string userNames = string.Empty;
List<Model.Check_JointCheckApprove> list = BLL.JointCheckApproveService.GetJointCheckApprovesByJointCheckId(item.JointCheckId);
foreach (var a in list)
{
if (a != null)
{
if (a.ApproveMan != null)
{
if (!userNames.Contains(BLL.UserService.GetUserByUserId(a.ApproveMan).UserName))
{
userNames += UserService.GetUserByUserId(a.ApproveMan).UserName + ",";
}
}
}
}
if (!string.IsNullOrEmpty(userNames))
{
userNames = userNames.Substring(0, userNames.LastIndexOf(","));
}
cell.SetCellValue(userNames);
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);
}
else
{
Alert.ShowInTop("当前无记录,无法导出!", MessageBoxIcon.Warning);
}
}
#endregion
}
}