//---------------------------------------------------------------------------
//注意：ReportDelete由用户界面操作触发执行!
//---------------------------------------------------------------------------
String _message = "";
int _rights = -1;

//---------------------------------------------------------------------------
bool HasAdministratorRole()
{
	TADOQuery qryCustom = new TADOQuery(nil);
	qryCustom.ConnectionString = _opacsconnection;
	int iDepartmentKey = 0;
	String sDepartment = GetConfigStr("SysLogon", "sLastDepartment"); 
	String sQuerySQL = "select * from dd_department";
	sQuerySQL = AddWhereCondition(sQuerySQL, "department_name='" + sDepartment + "'");
	qryCustom.Close();
	qryCustom.SQL.Text = sQuerySQL;
	try
	{
		qryCustom.Open();
		iDepartmentKey = qryCustom.FieldByName("department_key").AsInteger;
	}
	except
	{
		delete qryCustom;
		return false;
	}
	////
	String sDoctorRights = "";
	String sDoctorName = GetConfigStr("SysLogon", "sLastDoctorName");
	String sAccounts = GetConfigStr("SysLogon", "sLastAccounts");
	sQuerySQL = "select * from dd_doctor";
	sQuerySQL = AddWhereCondition(sQuerySQL, "department_key=" + IntToStr(iDepartmentKey));
	sQuerySQL = AddWhereCondition(sQuerySQL, "doctor_name='" + sDoctorName + "'");
	sQuerySQL = AddWhereCondition(sQuerySQL, "doctor_accounts='" + sAccounts + "'");
	qryCustom.Close();
	qryCustom.SQL.Text = sQuerySQL;
	try
	{
		qryCustom.Open();
		sDoctorRights = qryCustom.FieldByName("doctor_rights").AsString;
	}
	except
	{
		delete qryCustom;
		return false;
	}
	delete qryCustom;
	////
	if (Pos("管理员", sDoctorRights) > 0)
		return true;
		
	return false;
}

//---------------------------------------------------------------------------
int GetRights()
{
	int iValidDay = 3; // 单位：天
	
	bool bAdministrator = HasAdministratorRole();
	if (bAdministrator) // 管理员可以修改
		return 1;
	
	TDateTime dtReport = _qryStudy.FieldByName("report_dttm").AsDateTime;
	if (Now() - dtReport > iValidDay)
	{
		_message = "报告已超过修改时限，不能删除！";
		return -1;
	}
		
	return 1;
}

//---------------------------------------------------------------------------
// 主程序
//---------------------------------------------------------------------------
{
	_rights = GetRights();
}

//---------------------------------------------------------------------------