<!-- #include file="include/config.asp" -->
<!-- #include file="INCLUDE/skin.asp" -->
<!--#include file="include/conn.asp"-->
<!--#include file="z_bank_data.asp"-->
<!--#include file="z_bank_const.asp"-->
<%
'=========================================================
' File: z_bank_MasterWork.asp
' Version:1.0
' Date: 2003-7-20
' Script Written by 冰语，倚天电子，http://et8.126.com
'=========================================================
' Copyright (C) 2002,2003 et8.126.Com. All rights reserved.
' Web: ,http://et8.126.com
' Email: lupi@163.net
'=========================================================
dim disabled
dim Pcount
dim page
dim total
if not IsBankMaster then
    founderr=true
    Errmsg=Errmsg+"<br>"+"<li>看到你迎面向行长办公室而来，银行大楼的管理阿伯不得不仔细的瞧你两眼，发现你很眼生，对你温和的说：“咦，你好像不是本银行的行长啊！”</li>"
end if
if FoundErr then
    tit_fir="<a href='z_bank_index.asp'>社区银行</a>"
    tit="银行错误信息"
    call web_head(1,0,2,0,0)   
    call bank_error()
    call web_end(0)
else
    if request("MasterWork")="PFGrepay" then
        tit_fir="<a href='z_bank_index.asp'>社区银行</a>"
        tit="清理到期的贷款"
        call web_head(1,0,2,0,0)  
        call PFGrepay()
    elseif request("MasterWork")="BankMsg" then
        tit_fir="<a href='z_bank_index.asp'>社区银行</a>"
        tit="修改银行信息"
        call web_head(1,0,2,0,0)
        call BankMsg()
    elseif request("MasterWork")="MasterINS" then
        tit_fir="<a href='z_bank_index.asp'>社区银行</a>"
        tit="行长操作"
        call web_head(1,0,2,0,0)
        call MasterINS()
    elseif request("MasterWork")="delPFG" then
        tit_fir="<a href='z_bank_index.asp'>社区银行</a>"
        tit="清理到期贷款"
        call web_head(1,0,2,0,0)
        call delPFG()
    else
        tit_fir="<a href='z_bank_index.asp'>社区银行</a>"
        tit="行长办公室"
        call web_head(1,0,2,0,0)
        call main()
    end if
    if FoundErr=true then
        call bank_error()
    end if
    call web_end(0)
end if

sub main()
  Response.Write "<table cellpadding=3 cellspacing=1 align=center width=98% border='2' bordercolor='"&web_var(web_color,3)&"'>"&_
    "<tr><th align=center class=bg_3><form action=z_bank_MasterWork.asp?bankid="&BankID&"&MasterWork=BankMsg method=post>银行基本信息设置</td></tr>"&_
    "<tr><td class=tablebody1 align=left>"
  Response.Write "银行名称：　　<input type=text name=bankname size=10 value="&BankName&" disabled> （注册后只有管理员可改）<br><img src=yaoyue.gif height=5><br>"&_
                 "行长名字：　　<input type=text name=bankmaster size=10 value="&BankMaster&" "
                 if EveryBody=true then
                     Response.Write " disabled> （非公行行长可以改，但改后就等于把银行送人，你将一无所有，要谨慎）<br><img src=yaoyue.gif height=5><br>"
                 else
                     Response.Write "> （非公行行长可以改，但改后就等于把银行送人，你将一无所有，要谨慎）<br><img src=yaoyue.gif height=5><br>"
                 end if
  Response.Write "库存的魅力值：<input type=text name=loveliness size=10 value="&Loveliness&" disabled> （仅为非公行行长作为参考值，不可直接修改）<br><img src=yaoyue.gif height=5><br>"&_
                 "库存的现金：　<input type=text name=StockPile size=10 value="&StockPile&" disabled> （仅为非公行行长作为参考，不可直接修改）<br><img src=yaoyue.gif height=5><br>"&_
                 "销户手继费：　<input type=text name=log_on size=10 value="&log_on&"> （可以输入从"&L_trade&"到1000之间的整数）<br><img src=yaoyue.gif height=5><br>"&_
                 "银行说明：　　<input type=text name=msg size=16 maxlength=30 value="&MSG&"> （银行的说明，如欢迎语等，最多三十个字）<br><img src=yaoyue.gif height=5><br>"&_
                 "魅力贷款倍数：<input type=text name=zhml size=10 value="&ZHML&"> （客户用魅力贷款时的倍数，填5至40之间的整数，只有库存魅力为0和没有人贷款时可修改）<br><img src=yaoyue.gif height=5><br>"&_
                 "转汇最低积分：<input type=text name=EP size=10 value="&EP&"> （积分要到达多少才可使用转帐汇款功能，10至1000之间的整数）<br><img src=yaoyue.gif height=5><br>"&_
                 "开户最低积分：<input type=text name=integral size=10 value="&integral&"> （开户需要的最低积分，10至1000之间的整数）<br><img src=yaoyue.gif height=5><br>"&_
                 "贷款最高次数：<input type=text name=PFGTimes size=10 value="&PFGTimes&"> （每个客户最多只能同时贷几笔款，到达则必须最少还一笔才能再贷，3至9之间的整数）<br><img src=yaoyue.gif height=5><br>"&_
                 "<br><b>注意</b>：魅力贷款倍数同时也影响买卖魅力的数值，卖魅力给银行为所填数的两倍，向银行买魅力为所填数的四倍。"&_
                 "</td></tr><tr><td align=center class=tablebody2><input type=submit name=s value=修改 onclick=""return confirm('确定修改？');""></td></form></tr></table>"
  if not EveryBody then
      if StockPile < RegBank then
          disabled=" disabled"
      else
          disabled=""
      end if
      Response.Write "<table cellpadding=3 cellspacing=1 align=center width=98% border='2' bordercolor='"&web_var(web_color,3)&"'>"&_
                     "<tr><th align=center>非公行行长取款或扩充处</td></tr>"&_
                     "<tr><td class=tablebody1 align=left valign=middle><br>"&_
                     "<form action=z_bank_MasterWork.asp?bankid="&BankID&"&MasterWork=MasterINS method=post>&nbsp;<input type=text name=AppOrGet size=10>&nbsp;&nbsp;取出魅力&nbsp;<input type=radio name=num value=1>&nbsp;&nbsp;扩充魅力<input type=radio name=num value=2>&nbsp;&nbsp;取出现金&nbsp;<input type=radio name=num value=3"&disabled&">&nbsp;&nbsp;扩充金额&nbsp;<input type=radio name=num value=4>&nbsp;&nbsp;<input type=submit name=s value=操作></form>"&_
                     "<b>说明：</b><br>"&_
                     "1.取出魅力为把银行库存的魅力值转成你自己的魅力值。<br>"&_
                     "2.扩充魅力为把你现有的魅力值转成银行的库存，用来卖给客户的，魅力金钱，你喜欢哪一个多一些呢？<br>"&_
                     "3.取出现金为把银行库存的金钱转为你的现金，只有当库存大于<font color=#ff0000><b>"&RegBank&"</b></font>"&Curr&"时才能操作。<br>"&_
                     "4.扩充现金为把自己的现金加入银行的库存中。<br>"&_
                     "5.想知道银行库存的魅力值和金钱有多少，看上的的基本信息。<br>"
      Response.Write "</td></tr></table>"
  end if
  Response.Write "<table cellpadding=3 cellspacing=1 align=center width=98% border='2' bordercolor='"&web_var(web_color,3)&"'>"&_
                 "<tr><th align=center>其它操作</td></tr>"&_
                 "<tr><td class=tablebody1 align=center valign=middle>"
                 if OpenEventsLog then
                     Response.Write "<input type=button name=t1 value=查看事件记录 onclick=""window.open('z_bank_ClientEvents.asp?bankid="&BankID&"&action=events');"">　"
                 end if
  Response.Write "<input type=button name=t2 value=客户管理 onclick=""javascrip:window.open('z_bank_ClientEvents.asp?bankid="&BankID&"');"">　<input type=submit name=s value=清理到期的贷款 onclick=""javascript:location.href='z_bank_MasterWork.asp?bankid="&BankID&"&MasterWork=PFGrepay';""></td></tr></table>"
end sub
'读取到期贷款
sub PFGrepay()
  if not isnumeric(request("page")) or request("page")="" then
      page=1
  else
      page=cint(request("page"))
  end if
  set crs=server.CreateObject("adodb.recordset")
  csql="select p.PID,p.PaymentForGoods,p.P_Accrual,p.ByDetainCP,p.DateAndTime,u.name from PaymentForGoods p inner join bankuser u on u.bankuserid=p.bankuserid where u.bankid="&BankID&" and datediff('d',datediff('d',p.DateAndTime,'"&now()&"'),"&P_repay&") < 0"
  crs.Open csql,cjconn,1,1
  if crs.bof and crs.eof then
      founderr=true
      Errmsg=Errmsg+"<br>"+"<li>没有任何到期的贷款。</li>"
      exit sub
  end if
%>
<table cellpadding=0 cellspacing=0 border=0 width="95%" align=center><tr><td>有些人贷款后就很长时间没来，这些贷款到期后也不会自动清理，就得行长动手清理了。</td></tr></table>
<form name=PFG action=z_bank_MasterWork.asp?bankid=<%=BankID%>&MasterWork=delPFG method=post>
<TABLE cellPadding=3 cellSpacing=1 class=tableborder1 align=center>
<TR valign=middle>
<Th height=25 width=60>贷款ID</Th>
<Th width=120>用户名</Th>
<Th width=120>贷款数</Th>
<Th width=120>贷款利息</Th>
<Th width=120>所押魅力值</Th>
<Th width=*>贷款时间</Th>
<Th width=40>清理</Th>
</TR>
<%
      crs.PageSize = 20
      total = crs.recordcount
      Pcount = crs.pagecount
      if page < 1 then page = 1
      if page > Pcount then page = Pcount
      crs.move (page-1)*crs.pagesize
      ii = 0
      do while not crs.eof and ii < crs.pagesize
%>
  <TR> 
    <TD align=middle class=tablebody2 width=60><%=crs(0)%></TD> 
    <TD align=middle class=tablebody1 width=120><%=crs(5)%></TD> 
    <TD align=middle class=tablebody2  width=120><%=crs(1)%></TD> 
    <TD align=middle class=tablebody1 width=120><%=crs(2)%></TD>
    <TD align=middle class=tablebody2  width=120><%=crs(3)%></TD> 
    <TD align=middle class=tablebody1 width=*><%=crs(4)%></TD>
    <TD align=middle class=tablebody2  width=40><input type=checkbox name=PID value=<%=crs(0)%>></TD>
</TR> 
<%
          ii = ii+1
          crs.movenext
      loop
      Response.Write "</table>"
      call PageFooter()
      Response.Write "<br><table cellpadding=0 cellspacing=0 border=0 width=95% align=center><tr><td><input type=submit name=action value=清理>　<input type=button name=t value=返办公室 onclick=""javascript:location.href='z_bank_MasterWork.asp?bankid="&BankID&"';""> 选中所有显示的记录：<input type=checkbox name=chkall value=on onclick=""CheckAll(this.form)"">　</td></tr></table></form>"
  crs.Close
  set crs = nothing
%>
<script language="JavaScript">
<!--
function CheckAll(form)  {
  for (var i=0;i<form.elements.length;i++)    {
    var e = form.elements[i];
    if (e.name != 'chkall')       e.checked = form.chkall.checked; 
   }
  }
//-->
</script>
<%
end sub
sub PageFooter()
  Response.Write  "<table border=0 cellpadding=0 cellspacing=3 width=95% align=center>"&_
                  "<tr><td valign=middle nowrap>"&_
                  "页次：<font color=#ff0000><b>"&page&"</b></font>/<b>"&Pcount&"</b>页"&_
			     " 每页<font color=#ff0000><b>"&Forum_Setting(11)&"</b></font>条记录 总共有<font color=#ff0000><b>"&total&"</b></font>条记录</td>"&_
			     "<td valign=middle nowrap><div align=right><p>分页： "
			if page > 4 then
			    Response.Write "<a href=bank_MasterWork.asp?bankid="&bankID&"&MasterWork=PFGrepay&page=1>[1]</a>..."
			end if
			if Pcount>page+3 then
			    ii=page+3
			else
			    ii=Pcount
			end if
			for i=page-3 to ii
			    if not i < 1 then
			        if i=cint(page) then
			            Response.Write "<font color=#ff000000>["&i&"]</font>"
			        else
			            Response.Write "<a href=z_bank_MasterWork.asp?bankid="&bankID&"&MasterWork=PFGrepay&page="&i&">["&i&"]</a>"
			        end if
			    end if
			next
			if page+3 < Pcount then
			    Response.Write "...<a href=z_bank_MasterWork.asp?bankid="&bankID&"&MasterWork=PFGrepay&page="&Pcount&">["&Pcount&"]</a>"
			end if
			response.write "</p></div></td></tr></table>"
end sub

sub BankMsg()
  dim BankMaster,Log_on,MSG,NZHML,integral,EP,PFGTimes,FoundUser,NotFoundBankUser
  if not isnumeric(Request.Form("log_on")) or not isnumeric(Request.Form("ZHML")) or not isnumeric(Request.Form("EP")) or not isnumeric(Request.Form("integral")) or not isnumeric(Request.Form("PFGTimes")) then
      FoundErr=true
      Errmsg=Errmsg+"<br>"+"<li>销户费、贷款倍数、转帐汇所需的最低积分、开户最低积分和最大贷款次数必须是数字。"
      Exit sub
  end if
  if EveryBody=true then
      BankMaster=login_username
  else
      BankMaster=trim(Request.Form("BankMaster"))
  end if
  Log_on=int(Request.Form("log_on"))
  MSG=trim(Request.Form("MSG"))
  NZHML=int(Request.Form("zhml"))
  integral=int(Request.Form("integral"))
  EP=int(Request.Form("EP"))
  PFGTimes=int(Request.Form("PFGTimes"))
  FoundUser=false
  FoundBankUser=false
  if Log_on < L_trade or Log_on > 1000 then
      FoundErr=true
      Errmsg=Errmsg+"<br>"+"<li>销户手续费请输入"&L_trade&"到1000之间的整数"
  end if
  if len(MSG) > 30 then
      FoundErr=true
      Errmsg=Errmsg+"<br>"+"<li>银行说明不能大于三十个字符"
  end if
  if PaymentForGoods > 0 or loveliness > 0 then
      if NZHML <> ZHML then
          FoundErr=true
          Errmsg=Errmsg+"<br>"+"<li>在银行还有贷款或库存魅力值不为0时，不允许修改贷款倍数。"
      end if
  elseif NZHML < 5 or NZHML > 40 then
      FoundErr=true
      Errmsg=Errmsg+"<br>"+"<li>贷款倍数请输入5至40之间的整数"
  end if
  if EP < 200 or EP > 1000 then
      FoundErr=true
      Errmsg=Errmsg+"<br>"+"<li>转帐汇款需要的最低积分请输入200至1000之间的整数"
  end if
  if integral > 1000 then
      FoundErr=true
      Errmsg=Errmsg+"<br>"+"<li>开户最低值请输入0至1000之间的整数"
  end if
  if PFGTimes < 3 or PFGTimes > 10 then
      FoundErr=true
      Errmsg=Errmsg+"<br>"+"<li>贷款的最高次数请输入3至9之间的整数"
  end if
  if  EveryBody=false then
      if BankMaster <> login_username then
          csql="select name from bankuser where bankid="&BankID&" and name='"&BankMaster&"'"
          set crs=cjconn.execute (csql)
          if crs.bof and crs.eof then
              NotFoundBankUser=true
          else
              NotFoundBankUser=false
          end if
          csql="select username from user_data where username='"&BankMaster&"'"
          set crs=conn.execute (csql)
          if crs.bof and crs.eof then
              FoundErr=true
              Errmsg=Errmsg+"<br>"+"<li>没找到你所输入的行长用户名，请确认该用户名存在！"
              exit sub
          else
              FoundUser=true
          end if
          set crs=nothing
          if NotFoundBankUser and FoundUser then
              cjconn.execute ("insert into bankuser (bankid,name,CurrDeposit,events) values ("&BankID&",'"&BankMaster&"',"&L_trade&",'"&L_trade&"|开户|"&now()&"')")
              conn.execute ("update user_data set emoney=emoney-"&L_trade&" where username='"&BankMaster&"'")
          end if
      end if
  end if
  if not FoundErr then
      cjconn.execute ("update bank set bankmaster='"&BankMaster&"',log_on="&Log_on&",msg='"&MSG&"',ZHML="&NZHML&",EP="&EP&",integral="&integral&",PFGTimes="&PFGTimes&" where bankid="&BankID)
      call yaoyue_banksuc()
  end if
end sub

sub MasterINS()
  dim AppOrGet,num,BankNum,UserNum
  if not isnumeric(Request.Form("AppOrGet")) then
      FoundErr=true
      Errmsg=Errmsg+"<br>"+"<li>请输入数字！"
      Exit sub
  end if
  AppOrGet=int(abs(Request.Form("AppOrGet")))
  num=Request.Form("num")
  if num = 1 then
      BankNum=" loveliness=loveliness-"&AppOrGet&" "
      UserNum=" userCP=userCP+"&AppOrGet&" "
      if AppOrGet > loveliness then
          FoundErr=true
          Errmsg=Errmsg+"<br>"+"<li>你输入的数值大于银行现在库存的魅力值！"
      end if
  elseif num = 2 then
      BankNum=" loveliness=loveliness+"&AppOrGet&" "
      UserNum=" userCP=userCP-"&AppOrGet&" "
      if AppOrGet > myuserCP then
          FoundErr=true
          Errmsg=Errmsg+"<br>"+"<li>你输入的数值大于你现有的魅力值！"
      end if
  elseif num = 3 then
      BankNum=" StockPile=StockPile-"&AppOrGet&" "
      UserNum=" emoney=emoney+"&AppOrGet&" "
      if StockPile - AppOrGet < RegBank then
          FoundErr=true
          Errmsg=Errmsg+"<br>"+"<li>你输入的数字使银行库存小于" & RegBank&Curr & "，请重新输入！"
      end if
  elseif num = 4 then
      BankNum=" StockPile=StockPile+"&AppOrGet&" "
      UserNum=" emoney=emoney-"&AppOrGet&" "
      if AppOrGet > usermoney and num = 4 then
          FoundErr=true
          Errmsg=Errmsg+"<br>"+"<li>想扩充银行的库存也得自己有足够的现金吧？你输入的数大于你的现金咯！"
      end if
  else
      FoundErr=true
      Errmsg=Errmsg+"<br>"+"<li>请选择操作项！"
  end if
  if not FoundErr then
      cjconn.execute ("update bank set "&BankNum&" where bankid="&BankID)
      conn.execute ("update user_data set "&UserNum&" where username='"&login_username&"'")
      call yaoyue_banksuc()
  end if
end sub

sub delPFG()
  dim PID,DetainCP,PFG
  PID=trim(Request.Form("PID"))
  if PID="" then
      FoundErr=true
      Errmsg=Errmsg+"<br>"+"<li>请选要清理的贷款！"
  else
      csql="select bankuserid,PaymentForGoods,P_Accrual,ByDetainCP from PaymentForGoods where PID in ("&PID&")"
      set crs=cjconn.execute (csql)
      if crs.BOF and crs.EOF then
          FoundErr=true
          Errmsg=Errmsg+"<br>"+"<li>请选要清理的贷款！"
      else
          do while not crs.EOF
              PFG=PFG+crs(1)
              DetainCP=DetainCP+crs(3)
              cjconn.execute ("update bankuser set PaymentForGoods=PaymentForGoods-"&crs(1)&",P_accrual=P_accrual-"&crs(2)&",ByDetainCP=ByDetainCp-"&crs(3)&" where bankuserid="&crs(0))
              crs.MoveNext
          loop
          cjconn.execute ("update bank set loveliness=loveliness+"&DetainCP&",PaymentForGoods=PaymentForGoods-"&PFG&" where bankid="&BankID)
          cjconn.execute ("delete from PaymentForgoods where PID in ("&PID&")")
          call yaoyue_banksuc()
      end if
      set crs=nothing
  end if
end sub
%>