2021-04-30 10:28:37 +08:00
using BLL ;
using System ;
using System.Collections.Generic ;
using System.Data ;
using System.Data.SqlClient ;
2024-03-05 09:52:53 +08:00
using System.IO ;
2021-04-30 10:28:37 +08:00
using System.Linq ;
namespace FineUIPro.Web.TestRun.DriverHse
{
public partial class HseLicense : PageBase
{
2024-03-05 09:52:53 +08:00
#region 加 载 页 面
2021-04-30 10:28:37 +08:00
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
GetButtonPower ( ) ;
2024-03-05 09:52:53 +08:00
InitTree ( ) ; //加载类别树
}
}
#region 绑 定 资 料 库 类 别
/// <summary>
/// 绑定资料库树节点
/// </summary>
private void InitTree ( )
{
this . tvDataTypeInit . Nodes . Clear ( ) ;
TreeNode node = new TreeNode ( ) ;
node . Text = "作业类别" ;
node . NodeID = "0" ;
node . Expanded = true ;
this . tvDataTypeInit . Nodes . Add ( node ) ;
var types = BLL . TestRunLicenseTypeService . GetTestRunLicenseTypeList ( ) ;
foreach ( var q in types )
{
TreeNode newNode = new TreeNode ( ) ;
newNode . ToolTip = q . LicenseTypeName ;
newNode . Text = q . LicenseTypeName ;
newNode . NodeID = q . LicenseTypeId ;
newNode . EnableExpandEvent = true ;
newNode . EnableClickEvent = true ;
node . Nodes . Add ( newNode ) ;
2021-04-30 10:28:37 +08:00
}
}
#endregion
2024-03-05 09:52:53 +08:00
#endregion
#region 树 点 击 事 件
/// <summary>
/// 资料库类别树点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void tvDataTypeInit_NodeCommand ( object sender , TreeCommandEventArgs e )
{
BindGrid ( ) ;
}
#endregion
2021-04-30 10:28:37 +08:00
#region 数 据 绑 定
2024-03-05 09:52:53 +08:00
/// <summary>
/// 数据绑定
/// </summary>
2021-04-30 10:28:37 +08:00
public void BindGrid ( )
{
string strSql = @ "SELECT driver.HseLicenseId,
driver . ProjectId ,
driver . Code ,
2024-03-05 09:52:53 +08:00
driver . LicenseTypeId ,
2021-04-30 10:28:37 +08:00
driver . ApplyUnit ,
2024-03-05 09:52:53 +08:00
driver . ApplyMan ,
driver . HeaderMan ,
driver . WorkAddress ,
driver . WorkContents ,
2021-04-30 10:28:37 +08:00
driver . Remark ,
2024-03-05 09:52:53 +08:00
TestRunLicenseType . LicenseTypeName "
+ @" FROM DriverHse_HseLicense AS driver "
+ @" LEFT JOIN Base_TestRunLicenseType AS TestRunLicenseType ON TestRunLicenseType.LicenseTypeId = driver.LicenseTypeId WHERE driver.ProjectId=@projectId" ;
2021-04-30 10:28:37 +08:00
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
listStr . Add ( new SqlParameter ( "@projectId" , this . CurrUser . LoginProjectId ) ) ;
2024-03-05 09:52:53 +08:00
if ( ! string . IsNullOrEmpty ( this . tvDataTypeInit . SelectedNodeID ) )
{
strSql + = " AND driver.LicenseTypeId=@licenseTypeId" ;
listStr . Add ( new SqlParameter ( "@licenseTypeId" , this . tvDataTypeInit . SelectedNodeID ) ) ;
}
if ( ! string . IsNullOrEmpty ( this . txtCode . Text . Trim ( ) ) )
2021-04-30 10:28:37 +08:00
{
2024-03-05 09:52:53 +08:00
strSql + = " AND driver.Code like @code" ;
listStr . Add ( new SqlParameter ( "@code" , "%" + this . txtCode . Text . Trim ( ) + "%" ) ) ;
2021-04-30 10:28:37 +08:00
}
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 ( ) ;
}
#endregion
#region 分 页
/// <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 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 , FineUIPro . GridSortEventArgs e )
{
Grid1 . SortDirection = e . SortDirection ;
Grid1 . SortField = e . SortField ;
BindGrid ( ) ;
}
#endregion
2024-03-05 09:52:53 +08:00
#region 查 询
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2021-04-30 10:28:37 +08:00
protected void btnSearch_Click ( object sender , EventArgs e )
{
BindGrid ( ) ;
}
#endregion
#region 关 闭 弹 出 窗 口
/// <summary>
/// 关闭弹出窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Window1_Close ( object sender , WindowCloseEventArgs e )
{
2024-03-05 09:52:53 +08:00
InitTree ( ) ;
2021-04-30 10:28:37 +08:00
BindGrid ( ) ;
}
#endregion
2024-03-05 09:52:53 +08:00
#region 维 护 类 别
/// <summary>
/// 增加类别
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuAdd_Click ( object sender , EventArgs e )
{
//string id = this.tvDataTypeInit.SelectedNodeID;
//if (!string.IsNullOrEmpty(id))
//{
PageContext . RegisterStartupScript ( Window2 . GetShowReference ( String . Format ( "TestRunLicenseTypeEdit.aspx?type={1}" , "add" , "编辑 - " ) ) ) ;
//}
}
/// <summary>
/// 修改类别
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuModify2_Click ( object sender , EventArgs e )
{
string id = this . tvDataTypeInit . SelectedNodeID ;
if ( ! string . IsNullOrEmpty ( id ) & & id ! = "0" )
{
PageContext . RegisterStartupScript ( Window2 . GetShowReference ( String . Format ( "TestRunLicenseTypeEdit.aspx?licenseTypeId={0}&type={1}" , id , "edit" , "编辑 - " ) ) ) ;
}
else
{
Alert . ShowInTop ( "请选择类别" , MessageBoxIcon . Warning ) ;
return ;
}
}
/// <summary>
/// 删除类别
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMenuDel2_Click ( object sender , EventArgs e )
{
string id = this . tvDataTypeInit . SelectedNodeID ;
if ( ! string . IsNullOrEmpty ( id ) & & id ! = "0" )
{
Model . Base_TestRunLicenseType testRunLicenseType = BLL . TestRunLicenseTypeService . GetLicenseTypeById ( id ) ;
if ( testRunLicenseType ! = null )
{
BLL . TestRunLicenseTypeService . DeleteTestRunLicenseTypeById ( id ) ;
}
}
else
{
Alert . ShowInTop ( "请选择类别" , MessageBoxIcon . Warning ) ;
return ;
}
InitTree ( ) ;
}
#endregion
#region 增 加 按 钮
/// <summary>
/// 增加
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnNew_Click ( object sender , EventArgs e )
{
if ( this . tvDataTypeInit . SelectedNode ! = null )
{
if ( this . tvDataTypeInit . SelectedNodeID ! = "0" )
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "HseLicenseEdit.aspx?licenseTypeId={0}" , this . tvDataTypeInit . SelectedNode . NodeID , "新增 - " ) ) ) ;
}
else
{
Alert . ShowInTop ( "请选择类别!" , MessageBoxIcon . Warning ) ;
}
}
else
{
Alert . ShowInTop ( "请选择树节点!" , MessageBoxIcon . Warning ) ;
}
}
#endregion
2021-04-30 10:28:37 +08:00
#region 编 辑
protected void btnMenuModify_Click ( object sender , EventArgs e )
{
EditData ( ) ;
}
/// <summary>
/// Grid行双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick ( object sender , GridRowClickEventArgs e )
{
EditData ( ) ;
}
/// <summary>
/// 编辑
/// </summary>
private void EditData ( )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInTop ( "请至少选择一条记录" , MessageBoxIcon . Warning ) ;
return ;
}
2024-03-05 09:52:53 +08:00
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "HseLicenseEdit.aspx?hseLicenseId={0}" , Grid1 . SelectedRowID , "编辑 - " ) ) ) ;
2021-04-30 10:28:37 +08:00
}
#endregion
#region 删 除
2024-03-05 09:52:53 +08:00
/// <summary>
/// 右键删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2021-04-30 10:28:37 +08:00
protected void btnMenuDel_Click ( object sender , EventArgs e )
{
if ( Grid1 . SelectedRowIndexArray . Length > 0 )
{
foreach ( int rowIndex in Grid1 . SelectedRowIndexArray )
{
string rowID = Grid1 . DataKeys [ rowIndex ] [ 0 ] . ToString ( ) ;
2024-03-05 09:52:53 +08:00
var hseLicense = BLL . HseLicenseService . GetHseLicenseById ( rowID ) ;
if ( hseLicense ! = null )
2021-04-30 10:28:37 +08:00
{
BLL . HseLicenseService . DeleteHseLicenseById ( rowID ) ;
}
}
BindGrid ( ) ;
ShowNotify ( "删除数据成功!" , MessageBoxIcon . Success ) ;
}
}
#endregion
#region Grid行点击事件
/// <summary>
/// Grid行点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2024-03-05 09:52:53 +08:00
protected void Grid1_RowCommand ( object sender , GridCommandEventArgs e )
{
string id = Grid1 . DataKeys [ e . RowIndex ] [ 0 ] . ToString ( ) ;
if ( e . CommandName = = "AttachUrl" )
{
PageContext . RegisterStartupScript ( WindowAtt . GetShowReference ( String . Format ( "../../AttachFile/webuploader.aspx?type=-1&toKeyId={0}&path=FileUpload/TestRun/DriverHse/HseLicense&menuId={1}" , id , BLL . Const . HseLicenseMenuId ) ) ) ;
}
}
2021-04-30 10:28:37 +08:00
#endregion
#region 权 限 设 置
/// <summary>
/// 权限设置
/// </summary>
private void GetButtonPower ( )
{
var buttonList = BLL . CommonService . GetAllButtonList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , BLL . Const . HseLicenseMenuId ) ;
if ( buttonList . Count ( ) > 0 )
{
if ( buttonList . Contains ( BLL . Const . BtnAdd ) )
{
2024-03-05 09:52:53 +08:00
this . btnDownLoad . Hidden = false ;
2021-04-30 10:28:37 +08:00
this . btnNew . Hidden = false ;
2024-03-05 09:52:53 +08:00
this . btnMenuAdd . Hidden = false ;
2021-04-30 10:28:37 +08:00
}
if ( buttonList . Contains ( BLL . Const . BtnModify ) )
{
2024-03-05 09:52:53 +08:00
this . btnDownLoad . Hidden = false ;
2021-04-30 10:28:37 +08:00
this . btnMenuModify . Hidden = false ;
2024-03-05 09:52:53 +08:00
this . btnMenuModify2 . Hidden = false ;
2021-04-30 10:28:37 +08:00
this . Grid1 . EnableRowDoubleClickEvent = true ;
}
if ( buttonList . Contains ( BLL . Const . BtnDelete ) )
{
this . btnMenuDel . Hidden = false ;
2024-03-05 09:52:53 +08:00
this . btnMenuDel2 . Hidden = false ;
2021-04-30 10:28:37 +08:00
}
}
}
#endregion
2024-03-05 09:52:53 +08:00
#region 下 载 模 板
protected void btnDownLoad_Click ( object sender , EventArgs e )
{
if ( this . tvDataTypeInit . SelectedNode ! = null )
{
if ( this . tvDataTypeInit . SelectedNodeID ! = "0" )
{
Model . AttachFile attachFile = BLL . AttachFileService . GetAttachFile ( this . tvDataTypeInit . SelectedNodeID , BLL . Const . HseLicenseMenuId ) ;
if ( attachFile ! = null )
{
PageContext . RegisterStartupScript ( Confirm . GetShowReference ( "是否确认下载作业类别模板?" , String . Empty , MessageBoxIcon . Question , PageManager1 . GetCustomEventReference ( false , "Confirm_OK" ) , PageManager1 . GetCustomEventReference ( "Confirm_Cancel" ) ) ) ;
}
else
{
Alert . ShowInTop ( "模板不存在,请先上传模板!" , MessageBoxIcon . Warning ) ;
}
}
else
{
Alert . ShowInTop ( "请选择类别!" , MessageBoxIcon . Warning ) ;
}
}
else
{
Alert . ShowInTop ( "请选择树节点!" , MessageBoxIcon . Warning ) ;
}
}
/// <summary>
/// 下载导入模板
/// </summary>
protected void PageManager1_CustomEvent ( object sender , CustomEventArgs e )
{
if ( e . EventArgument = = "Confirm_OK" )
{
string rootPath = Server . MapPath ( "~/" ) ;
string initTemplatePath = string . Empty ;
string uploadfilepath = string . Empty ;
Model . AttachFile attachFile = BLL . AttachFileService . GetAttachFile ( this . tvDataTypeInit . SelectedNodeID , BLL . Const . HseLicenseMenuId ) ;
initTemplatePath = attachFile . AttachUrl ;
uploadfilepath = rootPath + initTemplatePath ;
string fileName = Path . GetFileName ( initTemplatePath ) ;
FileInfo info = new FileInfo ( uploadfilepath ) ;
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 ( uploadfilepath , 0 , fileSize ) ;
Response . Flush ( ) ;
Response . Close ( ) ;
}
}
#endregion
2021-04-30 10:28:37 +08:00
}
}