2022-03-15 17:36:38 +08:00
using BLL ;
2023-02-01 16:23:55 +08:00
using Newtonsoft.Json ;
2022-03-15 17:36:38 +08:00
using System ;
using System.Collections.Generic ;
2023-02-01 16:23:55 +08:00
using System.Configuration ;
2022-03-15 17:36:38 +08:00
using System.Data ;
using System.Data.SqlClient ;
using System.Linq ;
namespace FineUIPro.Web.ProjectData
{
public partial class ProjectList : PageBase
{
2023-02-01 16:23:55 +08:00
/// <summary>
/// 定义项
/// </summary>
public string URLToken
{
get
{
return ( string ) ViewState [ "URLToken" ] ;
}
set
{
ViewState [ "URLToken" ] = value ;
}
}
2022-03-15 17:36:38 +08:00
#region 加 载
/// <summary>
/// 加载页面
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load ( object sender , EventArgs e )
{
if ( ! IsPostBack )
{
////权限按钮方法
this . GetButtonPower ( ) ;
Funs . DropDownPageSize ( this . ddlPageSize ) ;
if ( this . CurrUser ! = null & & this . CurrUser . PageSize . HasValue )
{
Grid1 . PageSize = this . CurrUser . PageSize . Value ;
}
this . ddlPageSize . SelectedValue = Grid1 . PageSize . ToString ( ) ;
// 绑定表格
this . BindGrid ( ) ;
}
}
#endregion
#region 绑 定 数 据
/// <summary>
/// 绑定数据
/// </summary>
private void BindGrid ( )
{
string strSql = "SELECT Project.ProjectId,Project.ProjectCode,Project.ProjectName,unit.UnitName,Project.StartDate,Project.EndDate,Project.ProjectAddress,ShortName, ConstructionMoney,"
+ @" (CASE WHEN ProjectState='" + BLL . Const . ProjectState_2 + "' THEN '暂停中' WHEN ProjectState='" + BLL . Const . ProjectState_3 + "' THEN '已完工' ELSE '施工中' END) AS ProjectStateName,Project.ProjectState"
+ @" ,ProjectMoney,DATEDIFF(DAY,Project.StartDate,GETDATE()) AS DayCount,ProjectType.ProjectTypeName AS ProjectTypeName,sysConst.ConstText as ProjectStateName2"
+ @" FROM Base_Project AS Project LEFT JOIN Base_Unit as unit on unit.UnitId=Project.UnitId "
+ @" LEFT JOIN Base_ProjectType AS ProjectType ON Project.ProjectType =ProjectType.ProjectTypeId"
+ @" LEFT JOIN Sys_Const AS sysConst ON Project.ProjectState2 =sysConst.ConstValue AND sysConst.GroupId= '" + BLL . ConstValue . GroupId_ProjectState + "' "
+ @" WHERE 1=1 " ;
List < SqlParameter > listStr = new List < SqlParameter > ( ) ;
if ( ! string . IsNullOrEmpty ( this . txtProjectName . Text . Trim ( ) ) )
{
strSql + = " AND ProjectName LIKE @ProjectName" ;
listStr . Add ( new SqlParameter ( "@ProjectName" , "%" + this . txtProjectName . Text . Trim ( ) + "%" ) ) ;
}
if ( this . ckState . SelectedValue ! = "0" )
{
if ( this . ckState . SelectedValue = = "1" )
{
strSql + = " AND (ProjectState = '1' OR ProjectState IS NULL)" ;
}
else
{
strSql + = " AND (ProjectState = @states )" ;
listStr . Add ( new SqlParameter ( "@states" , this . ckState . SelectedValue ) ) ;
}
}
SqlParameter [ ] parameter = listStr . ToArray ( ) ;
DataTable tb = SQLHelper . GetDataTableRunText ( strSql , parameter ) ;
Grid1 . RecordCount = tb . Rows . Count ;
Grid1 . DataSource = this . GetPagedDataTable ( Grid1 , tb ) ;
Grid1 . DataBind ( ) ;
}
#endregion
#region Grid
/// <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 ( ) ;
}
protected void Grid1_Sort ( object sender , FineUIPro . GridSortEventArgs e )
{
BindGrid ( ) ;
}
#endregion
/// <summary>
/// 双击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Grid1_RowDoubleClick ( object sender , GridRowClickEventArgs e )
{
if ( Grid1 . SelectedRowIndexArray . Length = = 0 )
{
Alert . ShowInTop ( "请至少选择一条记录!" , MessageBoxIcon . Warning ) ;
return ;
}
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "ProjectSetView.aspx?ProjectId={0}" , Grid1 . SelectedRowID , "查看 - " ) ) ) ;
}
2023-02-01 16:23:55 +08:00
/// <summary>
/// 关联摄像头
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnMonitor_Click ( object sender , EventArgs e )
{
if ( ! string . IsNullOrEmpty ( Grid1 . SelectedRowID ) )
{
string url = ConfigurationManager . AppSettings [ "Video_URL" ] ;
string username = ConfigurationManager . AppSettings [ "Video_USER" ] ;
string password = ConfigurationManager . AppSettings [ "Video_PW" ] ;
if ( string . IsNullOrEmpty ( URLToken ) )
{
String res = BLL . CommonService . CreateGetHttpResponse ( url + "api/v1/login?username=" + username + "&password=" + Funs . EncryptionPassword ( password ) ) ;
Dictionary < string , string > dicres = JsonConvert . DeserializeObject < Dictionary < string , string > > ( res ) ;
URLToken = dicres [ "URLToken" ] ;
}
var project = Funs . DB . Base_Project . FirstOrDefault ( x = > x . ProjectId = = Grid1 . SelectedRowID ) ;
string resUserInfor = BLL . CommonService . CreateGetHttpResponse ( url + "api/v1/user/info?token=" + URLToken + "&username=" + project . ProjectCode ) ;
if ( "user not found" . Equals ( resUserInfor ) | | "远程服务器返回错误: (400) 错误的请求。" . Equals ( resUserInfor ) )
{
string resUserSave = BLL . CommonService . CreateGetHttpResponse ( url + "api/v1/user/save?token=" + URLToken + "&ID=0&Username=" + project . ProjectCode + "&Role=操作员,观众&Enable=true" ) ;
Dictionary < string , string > dicUserSave = JsonConvert . DeserializeObject < Dictionary < string , string > > ( resUserSave ) ;
project . MonitorId = dicUserSave [ "ID" ] ;
string newPassWord = Funs . EncryptionPassword ( DateTime . Now . Ticks . ToString ( ) ) ;
newPassWord = newPassWord . Substring ( newPassWord . Length - 9 , 8 ) ;
string resResPS = BLL . CommonService . CreateGetHttpResponse ( url + "api/v1/user/resetpassword?token=" + URLToken + "&id=" + dicUserSave [ "ID" ] + "&password=" + newPassWord ) ;
project . MonitorPW = newPassWord ;
Funs . DB . SubmitChanges ( ) ;
}
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "ProjectMonitorList.aspx?ProjectCode={0}&Id={1}&URLToken={2}" , project . ProjectCode , project . MonitorId , URLToken , "查看 - " ) ) ) ;
}
else
{
ShowNotify ( "请选择项目进入!" , MessageBoxIcon . Warning ) ;
}
}
2022-03-15 17:36:38 +08:00
/// <summary>
/// 查看
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnView_Click ( object sender , EventArgs e )
{
PageContext . RegisterStartupScript ( Window1 . GetShowReference ( String . Format ( "ProjectSetView.aspx?ProjectId={0}" , Grid1 . SelectedRowID , "查看 - " ) ) ) ;
}
#region 获 取 按 钮 权 限
/// <summary>
/// 获取按钮权限
/// </summary>
/// <param name="button"></param>
/// <returns></returns>
private void GetButtonPower ( )
{
if ( Request . Params [ "value" ] = = "0" )
{
return ;
}
var buttonList = BLL . CommonService . GetAllButtonList ( this . CurrUser . LoginProjectId , this . CurrUser . UserId , Const . SeverProjectListMenuId ) ;
if ( buttonList . Count ( ) > 0 )
{
}
}
#endregion
#region 查 询
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void TextBox_TextChanged ( object sender , EventArgs e )
{
this . BindGrid ( ) ;
}
#endregion
#region 项 目 经 理
/// <summary>
/// 施工经理
/// </summary>
/// <param name="unitId"></param>
/// <returns></returns>
protected string ConvertConstructionManager ( object projectId )
{
return BLL . ProjectService . GetConstructionManagerName ( projectId . ToString ( ) ) ;
}
/// <summary>
/// 施工分包商
/// </summary>
/// <param name="unitId"></param>
/// <returns></returns>
protected string ConvertSubcontractor ( object projectId )
{
string unitName = string . Empty ;
if ( projectId ! = null )
{
unitName = ProjectService . getProjectUnitNameByUnitType ( projectId . ToString ( ) , Const . ProjectUnitType_2 ) ;
}
return unitName ;
}
protected string ConvertOwn ( object projectId )
{
string unitName = string . Empty ;
if ( projectId ! = null )
{
unitName = ProjectService . getProjectUnitNameByUnitType ( projectId . ToString ( ) , Const . ProjectUnitType_4 ) ;
}
return unitName ;
}
#endregion
#region 导 出 按 钮
/// 导出按钮
/// </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 ;
this . Grid1 . PageSize = this . Grid1 . RecordCount ;
this . BindGrid ( ) ;
Response . Write ( GetGridTableHtml ( Grid1 ) ) ;
Response . End ( ) ;
}
#endregion
/// <summary>
/// 进入项目现场
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnEnter_Click ( object sender , EventArgs e )
{
if ( ! string . IsNullOrEmpty ( Grid1 . SelectedRowID ) )
{
string url = "~/indexProject.aspx?projectId=" + Grid1 . SelectedRowID ;
UserService . UpdateLastUserInfo ( this . CurrUser . UserId , null , false , Grid1 . SelectedRowID ) ;
PageContext . Redirect ( url , "_top" ) ;
}
else
{
ShowNotify ( "请选择项目进入!" , MessageBoxIcon . Warning ) ;
}
}
}
}