<!-- #include file="../../include.asp" -->

<%
'<!--
'################################################
'	 名称	:会社選択処理
'	 作成日:2002/8/9
'	 作成者:山崎
'	 目的 :会社の選択を処理する。
'	 概要	:
'	<<入力チェック>>
'	・未選択のチェック
'	修正:2002/8/26:山崎:SV会社一覧の変更	に伴う変更
'################################################
'-->
'
%>

<%
main()
Sub main()

	If Not(SessionCheck()) Then
		Exit Sub
	End If

	Dim Kurikoshi
	Kurikoshi = Request("Kurikoshi")

	Dim WebCollaboRiyo
	WebCollaboRiyo = Request("WBCLB")
	If WebCollaboRiyo <> "1" Then
		WebCollaboRiyo = "0"
	End If

	Dim DaihyoTorishimariyaku
	Dim DaihyoTorishimariyakuJyusyo

	Dim KaisyaCD
	KaisyaCD = Request("KaisyaCD")
	Dim ref
	ref = Request("ref")

	Dim Query, Content, Content2
	Query = "exec SPM会社取得 '" & GB_SystemCD & "','" & GB_EnshuCD & "', '" & KaisyaCD & "'"
'Response.Write(Query)
'Exit Sub
	Set Content = OpenQuery(Query)
	Do While Not(Content.BOF Or Content.EOF)

		If LCase(Content.Fields("会社CD")) = LCase(KaisyaCD) Then
			Dim GyosyuCD
			GyosyuCD = Content.Fields("業種CD")
			Session(HomeAlias & "KaisyaCD") = KaisyaCD
			Session(HomeAlias & "Gyosyu") = Content.Fields("業種CD")
			Session(HomeAlias & "GyosyuMeisyo") = Content.Fields("業種名称")
			Session(HomeAlias & "KaisyaMeisyo") = Content.Fields("会社名称")
			Session(HomeAlias & "KaisyaRyakuMeisyo") = Content.Fields("会社略名称")
			Session(HomeAlias & "JisyaFlag") = Content.Fields("自社フラグ")
			Session(HomeAlias & "ShijyoCD") = Content.Fields("市場CD")
			DaihyoTorishimariyaku = Content.Fields("代表取締役")
			DaihyoTorishimariyakuJyusyo = Content.Fields("代表取締役住所")

			If 0=1 Then
			ElseIf GyosyuCD = "S" Then
				Session(HomeAlias & "GyosyuKubun") = "S"
				Session(HomeAlias & "GyosyuColor") = "#33CC99"
				Session(HomeAlias & "GyosyuColorObj") = "g"
			ElseIf GyosyuCD = "B" Then
				Session(HomeAlias & "GyosyuKubun") = "B"
				'Session(HomeAlias & "GyosyuKubun") = "BS"	'銀行で商社科目を利用する場合(保留中)
				Session(HomeAlias & "GyosyuColor") = "#7499E5"
				Session(HomeAlias & "GyosyuColorObj") = "b"
			ElseIf GyosyuCD = "U" Then
				Session(HomeAlias & "GyosyuKubun") = "S"
				Session(HomeAlias & "GyosyuColor") = "#D9BC83"
				Session(HomeAlias & "GyosyuColorObj") = "o"
			ElseIf GyosyuCD = "K" Then
				Session(HomeAlias & "GyosyuKubun") = "S"
				Session(HomeAlias & "GyosyuColor") = "#AD82D9"
				Session(HomeAlias & "GyosyuColorObj") = "p"
			End If

			'代表取締役を社員台帳に登録(070607小野)
			'会社選択時に必ず社員番号1が作成されるため
			'社員が一人も存在しない場合にのみ動作させる
			'その場合は代表取締役フラグも立てる
'			Query = "exec SPK社員台帳一覧2 '" & GB_SystemCD & "','" & EnshuCD & "', '" & KaisyaCD & "'"
'			Set Content = OpenQuery(Query)
'			If Content.BOF Or Content.EOF Then
'				Query = "exec SPK社員台帳更新2 '" & GB_SystemCD & "', '" & EnshuCD & "', '" & KaisyaCD & "', 1"
'				Query = Query & ", '" & DaihyoTorishimariyaku & "', null, 0, '', '" & DaihyoTorishimariyakuJyusyo & "', '', '', '代表取締役', null, null"
'				Query = Query & ", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0"
'				DebugQuery(Query)
'				Set Content = OpenQuery(Query)
'				Query = "exec SPK社員台帳更新_代表取締役 '" & GB_SystemCD & "'"
'				Query = Query & ", '" & EnshuCD & "'"
'				Query = Query & ", '" & KaisyaCD & "'"
'				Query = Query & ", 1"
'				Set Content = OpenQuery(Query)
'			End If

			'生徒NO	'個人学習の場合=学生番号、グループ学習の場合=会社CD
			If Session(HomeAlias & "EnshuKubun") = "P" Then
				Session(HomeAlias & "SeitoNo") = Session(HomeAlias & "GakuseiNo")
			Else
				Session(HomeAlias & "SeitoNo") = Session(HomeAlias & "KaisyaCD")
			End If


			Query = "exec SPV演習履歴登録 '" & GB_SystemCD & "','" & GB_EnshuCD & "', '" & KaisyaCD & "', '" & GB_GakuseiNo & "'"
DebugQuery(Query)
			Set Content = OpenQuery(Query)

			'代表取締役が居なければ作成ロジックに飛ばす
			Query = "exec SPK社員台帳一覧2 '" & GB_SystemCD & "','" & EnshuCD & "', '" & KaisyaCD & "'"
			Set Content2 = OpenQuery(Query)
			Do While Not(Content2.BOF Or Content2.EOF)
				If "" & Content2.Fields("代表取締役フラグ") = "1" Then
					If PackageMode = 1 Then
						Response.Redirect("/" & HomeAlias & "/user/bk/menu_cyac.asp?Kurikoshi=" & Kurikoshi)
					Else
						Response.Redirect("/" & HomeAlias & "/user/bk/menu_" & LCase(GyosyuCD) & ".asp?ref="& ref & "&WBCLB=" & WebCollaboRiyo & "&Kurikoshi=" & Kurikoshi)
					End If
				End If
				Content2.MoveNext
			Loop
			Response.Redirect("/" & HomeAlias & "/user/bk/daihyotorishimariyaku.asp?ref="& ref & "&WBCLB=" & WebCollaboRiyo)

		End If

'Response.Write("ここ")

		Content.MoveNext
	Loop


	'会社が選択されていなければ自社設定に飛ばす ※電商くん連携演習に無理やり入った場合の対処(180507小野)
	Response.Redirect("/" & HomeAlias & "/user/bk/regcorp.asp")


	'Response.Write("会社が選択されていません")
%>
<a href="JavaScript:history.go(-1)">戻る</a>
<%
End Sub
%>