xinjiang/SGGL/FineUIPro.Web/HJGL/PersonManage/TestApplication.aspx.cs

437 lines
16 KiB
C#

using BLL;
using FineUIPro.Web.Controls;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using AspNet = System.Web.UI.WebControls;
using Model;
namespace FineUIPro.Web.HJGL.PersonManage
{
public partial class TestApplication : PageBase
{
#region
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.ddlPageSize.SelectedValue = Grid1.PageSize.ToString();
BLL.UnitService.InitUnitByProjectIdUnitTypeDropDownList(this.drpUnitId, this.CurrUser.LoginProjectId, BLL.Const.ProjectUnitType_2, true);
// 绑定表格
this.BindGrid();
}
}
/// <summary>
/// 数据绑定
/// </summary>
private void BindGrid()
{
string strSql = @"SELECT testApplication.ApplicationTestId,
testApplication.ProjectId,
testApplication.ConUnit,
testApplication.ConUnitWeldingEngineer,
testApplication.Certificate,
testApplication.CertificateValidity,
testApplication.PreTestDate,
testApplication.WelderClass,
testApplication.WelderCode,
testApplication.WelderName,
testApplication.IdentityCard,
testApplication.WeldingPosition,
testApplication.WeldingMethod,
testApplication.SpecimenSize,
testApplication.MaterialCategory,
testApplication.AppearanceEvaluation,
testApplication.FirstExamination,
testApplication.SecondExamination,
testApplication.WelderCondition,
testApplication.ExamDate,
testApplication.InvigilatorConfirmed,
testApplication.Area,
testApplication.ExamTrustDate,
testApplication.ExamTrustCode,
testApplication.CheckDate,
testApplication.CheckResult,
testApplication.NDTFilm,
testApplication.CheckUnit,
testApplication.OwnerNum,
Unit.UnitName,
u.UserName AS ConUnitWeldingEngineerName,
WeldingMethod.WeldingMethodCode,
workArea.WorkAreaName,
checkUnit.UnitName AS CheckUnitName"
+ @" FROM Welder_TestApplication AS testApplication"
+ @" LEFT JOIN Base_Unit AS Unit ON Unit.UnitId = testApplication.ConUnit"
+ @" LEFT JOIN Sys_User AS u ON u.UserId = testApplication.ConUnitWeldingEngineer"
+ @" LEFT JOIN Base_WeldingMethod AS WeldingMethod ON WeldingMethod.WeldingMethodId = testApplication.WeldingMethod"
+ @" LEFT JOIN ProjectData_WorkArea AS workArea ON workArea.WorkAreaId = testApplication.Area"
+ @" LEFT JOIN Base_Unit AS checkUnit ON checkUnit.UnitId = testApplication.CheckUnit"
+ @" WHERE testApplication.ProjectId=@projectId";
List<SqlParameter> listStr = new List<SqlParameter>();
listStr.Add(new SqlParameter("@projectId", this.CurrUser.LoginProjectId));
if (this.drpUnitId.SelectedValue != BLL.Const._Null)
{
strSql += " AND testApplication.ConUnit = @unitId";
listStr.Add(new SqlParameter("@unitId", this.drpUnitId.SelectedValue));
}
if (!string.IsNullOrEmpty(this.txtWelderName.Text.Trim()))
{
strSql += " AND testApplication.WelderName LIKE @welderName";
listStr.Add(new SqlParameter("@welderName", "%" + this.txtWelderName.Text.Trim() + "%"));
}
if (!string.IsNullOrEmpty(this.drpWelderCondition.SelectedValue))
{
strSql += " AND testApplication.WelderCondition = @welderCondition";
listStr.Add(new SqlParameter("@welderCondition", this.drpWelderCondition.SelectedValue));
}
if (!string.IsNullOrEmpty(this.txtStateDate.Text.Trim()))
{
strSql += " AND testApplication.ExamDate >= @startDate";
listStr.Add(new SqlParameter("@startDate", this.txtStateDate.Text.Trim()));
}
if (!string.IsNullOrEmpty(this.txtEndDate.Text.Trim()))
{
strSql += " AND testApplication.ExamDate <= @endDate";
listStr.Add(new SqlParameter("@endDate", this.txtEndDate.Text.Trim()));
}
if (this.CurrUser.UnitId != BLL.Const.UnitId_TCC)
{
var user = BLL.ProjectUserService.GetCurrProjectUserByUserId(this.CurrUser.UserId);
if (user != null)
{
if (!string.IsNullOrEmpty(user.RoleId) && user.RoleId.Contains(BLL.Const.CVWeldingManager))
{
strSql += " AND testApplication.WelderClass='土建'";
}
else
{
strSql += " AND testApplication.WelderClass <> '土建'";
}
}
}
SqlParameter[] parameter = listStr.ToArray();
DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter);
Grid1.RecordCount = tb.Rows.Count;
//tb = GetFilteredTable(Grid1.FilteredData, tb);
var table = this.GetPagedDataTable(Grid1, tb);
Grid1.DataSource = table;
Grid1.DataBind();
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnQuery_Click(object sender, EventArgs e)
{
BindGrid();
}
/// <summary>
/// 分页下拉选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
{
Grid1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
BindGrid();
}
/// <summary>
/// 排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_Sort(object sender, GridSortEventArgs e)
{
BindGrid();
}
/// <summary>
/// 改变索引事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_PageIndexChange(object sender, GridPageEventArgs e)
{
BindGrid();
}
/// <summary>
/// 关闭弹出窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close(object sender, WindowCloseEventArgs e)
{
BindGrid();
}
#endregion
#region
/// <summary>
/// 增加按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click(object sender, EventArgs e)
{
if (GetButtonPower(Const.BtnAdd))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("TestApplicationEdit.aspx", "新增 - ")));
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#endregion
#region
/// <summary>
/// 右键编辑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuEdit_Click(object sender, EventArgs e)
{
this.EditData();
}
/// <summary>
/// 编辑数据方法
/// </summary>
private void EditData()
{
if (GetButtonPower(Const.BtnModify))
{
if (Grid1.SelectedRowIndexArray.Length == 0)
{
Alert.ShowInTop("请至少选择一条记录", MessageBoxIcon.Warning);
return;
}
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("TestApplicationEdit.aspx?applicationTestId={0}", Grid1.SelectedRowID, "编辑 - ")));
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
/// <summary>
/// 行双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick(object sender, GridRowClickEventArgs e)
{
this.EditData();
}
#endregion
#region
/// <summary>
/// 右键删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDelete_Click(object sender, EventArgs e)
{
if (GetButtonPower(Const.BtnDelete))
{
if (Grid1.SelectedRowIndexArray.Length > 0)
{
string strShowNotify = string.Empty;
foreach (int rowIndex in Grid1.SelectedRowIndexArray)
{
string rowID = Grid1.DataKeys[rowIndex][0].ToString();
var testApplication = BLL.TestApplicationService.GetTestApplicationById(rowID);
if (testApplication != null)
{
string cont = judgementDelete(rowID);
if (string.IsNullOrEmpty(cont))
{
BLL.TestApplicationService.DeleteTestApplicationById(rowID);
}
else
{
strShowNotify += "焊工考试申请" + ":" + testApplication.WelderCode + cont;
}
}
}
BindGrid();
if (!string.IsNullOrEmpty(strShowNotify))
{
Alert.ShowInTop(strShowNotify, MessageBoxIcon.Warning);
}
else
{
ShowNotify("删除成功!", MessageBoxIcon.Success);
}
}
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
#region
/// <summary>
/// 判断是否可以删除
/// </summary>
/// <returns></returns>
private string judgementDelete(string id)
{
string content = string.Empty;
//if (Funs.DB.BS_WeldMethodItem.FirstOrDefault(x => x.WED_ID == id) != null)
//{
// content += "已在【焊口信息】中使用,不能删除!";
//}
return content;
}
#endregion
#endregion
#region
/// <summary>
/// 导入
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnImport_Click(object sender, EventArgs e)
{
if (GetButtonPower(Const.BtnAdd))
{
PageContext.RegisterStartupScript(Window1.GetShowReference(String.Format("TestApplicationDataIn.aspx", "导入 - ")));
}
else
{
Alert.ShowInTop("您没有这个权限,请与管理员联系!", MessageBoxIcon.Warning);
return;
}
}
/// <summary>
/// 导出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOut_Click(object sender, EventArgs e)
{
Response.ClearContent();
string filename = Funs.GetNewFileName();
Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("焊工考试申请" + filename, System.Text.Encoding.UTF8) + ".xls");
Response.ContentType = "application/excel";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Write(GetGridTableHtml(Grid1));
Response.End();
}
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
private string GetGridTableHtml(Grid grid)
{
StringBuilder sb = new StringBuilder();
grid.PageSize = this.Grid1.RecordCount;
BindGrid();
MultiHeaderTable mht = new MultiHeaderTable();
mht.ResolveMultiHeaderTable(Grid1.Columns);
sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
foreach (List<object[]> rows in mht.MultiTable)
{
sb.Append("<tr>");
foreach (object[] cell in rows)
{
int rowspan = Convert.ToInt32(cell[0]);
int colspan = Convert.ToInt32(cell[1]);
GridColumn column = cell[2] as GridColumn;
if (!column.Hidden)
{
sb.AppendFormat("<th{0}{1}{2}>{3}</th>",
rowspan != 1 ? " rowspan=\"" + rowspan + "\"" : "",
colspan != 1 ? " colspan=\"" + colspan + "\"" : "",
colspan != 1 ? " style=\"text-align:center;\"" : "",
column.HeaderText);
}
}
sb.Append("</tr>");
}
int j = 0;
foreach (GridRow row in grid.Rows)
{
sb.Append("<tr>");
int i = 0;
foreach (GridColumn column in mht.Columns)
{
string html = row.Values[column.ColumnIndex].ToString();
if (column.ColumnID == "tfNumber")
{
html = (row.FindControl("labNumber") as AspNet.Label).Text;
}
if (("IdentityCard" == column.ColumnID) && !string.IsNullOrEmpty(html))
{
sb.AppendFormat("<td style='vnd.ms-excel.numberformat:@;'>{0}</td>", html);
}
else
{
sb.AppendFormat("<td style=\"text-align:center;\">{0}</td>", html);
}
i++;
}
j++;
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
#endregion
#region
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private bool GetButtonPower(string button)
{
return BLL.CommonService.GetAllButtonPowerList(this.CurrUser.LoginProjectId, this.CurrUser.UserId, BLL.Const.HJGL_TestApplicationMenuId, button);
}
#endregion
}
}