PageRenderTime 17ms CodeModel.GetById 4ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/beta/admin/costs.asp

http://github.com/khaneh/Orders
ASP | 238 lines | 229 code | 3 blank | 6 comment | 27 complexity | efb944a3c85a89af70ebad097649e377 MD5 | raw file
  1<%@LANGUAGE="VBSCRIPT" CODEPAGE="1256"%><%
  2' Admin
  3PageTitle="���� ��������"
  4SubmenuItem=11
  5%>
  6<!--#include file="top.asp" -->
  7<%
  8function echoOperationType(operationID, driverID)
  9	result="<select name='operationType'>"
 10	set rss = Conn.Execute("select * from cost_operation_type where driver_id=" & driverID)
 11	while not rss.eof
 12		result = result & "<option value='" & rss("id") & "'"
 13		if cint(rss("id")) = operationID then result = result & " selected='selected'"
 14		result = result & ">" & rss("name") & "</option>"
 15		rss.moveNext
 16	wend
 17	result = result & "</select>"
 18	echoOperationType = result
 19	rss.close
 20end function
 21 
 22if request("act")="" or request("act")="" then
 23%>
 24	<form method=post action='?act=add&step=costCenters'>
 25		<span>���� �����:</span>
 26		<input type=text name='costCenterName'>
 27		<input type=submit value='����� ���'>
 28	</form>
 29	<%
 30	set rs=Conn.Execute("SELECT cost_centers.id,cost_centers.name, count(cost_drivers.id) as driverCount FROM cost_centers left outer join cost_drivers on cost_centers.id=cost_drivers.cost_center_id group by cost_centers.id,cost_centers.name")
 31	while not rs.eof
 32		response.write("<a title='��� ����� ���� ����� ���� ����' href='?act=show&step=driver&id="&rs("id")&"'>"&rs("Name")&"(���� "&rs("driverCount")&" ������)</a>")
 33		if CInt(rs("driverCount"))=0 then response.write("<a style='margin:0 10 0 0;' title='���� ��� ��� ��� ���� ���� ����' href='?act=del&step=center&id="&rs("id")&"'>��� ���� �� ��� ����!</a>")
 34		response.write("<br>")	
 35		rs.moveNext
 36	wend
 37	rs.close
 38elseif request("act")="add" then  '------------------ ADD ACTION ----------------
 39	if request("step")="costCenters" and request.form("costCenterName")<>"" then 
 40		'--------------- add cost center ------------------
 41		Conn.Execute("Insert into cost_centers ([Name]) VALUES (N'"&request.form("costCenterName")&"')")
 42		msg="���� ����� " & "<b><i>" & request.form("costCenterName") & "</i></b>" & " ����� ��."
 43		response.redirect "?msg=" & Server.URLEncode(msg)
 44	elseif request("step")="operationType" and request("opName")<>"" then
 45		'-------------- add operation type -----------------
 46		Conn.Execute("INSERT INTO cost_operation_type (driver_id,name) VALUES ("&request("driverID")&",N'"&request("opName")&"')")
 47		msg="������ " & "<b><i>" & request.form("opName") & "</i></b>" & " ����� ��."
 48		response.redirect "?act=show&step=driver&id="&request("centerID")&"&msg=" & Server.URLEncode(msg)
 49	elseif request("step")="driver" then
 50		'------------------ add driver ---------------------
 51		isTime="0"
 52		isCount="0"
 53		isDirect="0"
 54		isContinuous="0"
 55		if request.form("isTime")="on" then isTime="1"
 56		if request.form("isCount")="on" then isCount="1"
 57		if request.form("isDirect")="on" then isDirect="1"
 58		if request.form("isContinuous")="on" then isContinuous="1"
 59		driverName=sqlsafe(request.form("driverName"))
 60		id=cint(request("centerID"))
 61		rate=cdbl(request("rate"))
 62		sql="INSERT INTO cost_drivers ([name],[cost_center_id],[rate],[is_direct],is_countinuous,is_time,is_count) VALUES (N'"& driverName & "'," & id & "," & rate & "," & isDirect & ","&isContinuous&", " & isTime & "," & isCount & ")"
 63		response.write(sql)
 64		Conn.Execute(sql)
 65		msg="������ ���� ��� �� ���� ����� ����� ��"
 66		response.redirect "?step=driver&act=show&id="&id&"&msg=" & Server.URLEncode(msg)
 67	end if
 68elseif request("act")="del" then '----------------------- DELETE -------------------------------
 69	if request("step")="center" then 
 70		if cint(request("id"))>0 then  
 71			Conn.Execute("delete cost_centers where id="&request("id"))
 72			msg="���� ����� ��� ��."
 73			response.redirect "?msg=" & Server.URLEncode(msg)
 74		end if
 75	elseif request("step")="diver" then 
 76		if isNumeric(request("rowID")) then
 77			set rs=Conn.Execute("SELECT * from costs where driver_id=" & cint(request("rowID")))
 78			if rs.eof then 
 79				Conn.Execute("DELETE cost_operation_type WHERE driver_id=" & cint(request("rowID")))
 80				Conn.Execute("DELETE cost_drivers WHERE id=" & cint(request("rowID")))
 81				msg="������ ���� ��� � �����ʝ��� ������ ��� ��"
 82			else
 83				msg="��� �� ��� ������ ������� ��� �� ��� ���� �� ������"
 84			end if
 85			rs.close
 86			response.redirect "?step=driver&act=show&id="&request("id")&"&msg=" & Server.URLEncode(msg)
 87		end if
 88	elseif request("step")="operationType" then
 89		if isNumeric(request("rowID")) then
 90			set rs=Conn.Execute("SELECT * from costs where operation_type=" & cint(request("rowID")))
 91			if rs.eof then 
 92				Conn.Execute("DELETE cost_operation_type WHERE id=" & cint(request("rowID")))
 93				msg="������ ���� ��� ��� ��"
 94			else
 95				msg="��� �� ��� ������ ������� ��� �� ��� ���� �� ������"
 96			end if
 97			response.redirect "?step=driver&act=show&id="&request("id")&"&msg=" & Server.URLEncode(msg)
 98		end if
 99	end if
100elseif request("act")="edit" then '------------------- EDIT -----------------------
101	if request("step")="driver" then 
102		isTime="0"
103		isCount="0"
104		isDirect="0"
105		isContinuous="0"
106		if request.form("isTime")="on" then isTime="1"
107		if request.form("isCount")="on" then isCount="1"
108		if request.form("isDirect")="on" then isDirect="1"
109		if request.form("isContinuous")="on" then isContinuous="1"
110		driverName=sqlsafe(request.form("driverName"))
111		id=cint(request("centerID"))
112		rate=cdbl(request("rate"))
113		unitSize=sqlsafe(request.form("unitSize"))
114		rowID=request.form("rowID")
115		sql="update cost_drivers SET [name]=N'"& driverName & "',[rate]=" & rate & ", [is_direct]=" & isDirect & ", is_countinuous="&isContinuous &",is_time=" & isTime & ", is_count=" & isCount & " WHERE id="&rowID
116		'response.write(sql)
117		Conn.Execute(sql)
118		msg="������ ���� ��� ���� ����� ��"
119		response.redirect "?step=driver&act=show&id="&id&"&msg=" & Server.URLEncode(msg)
120	elseif request("step")="operationType" then
121		sql="UPDATE cost_operation_type set [name]=N'"&request("opName")&"' WHERE id=" & request("id")
122		Conn.Execute(sql)
123		msg="������ ���� ��� ���� ����� ��"
124		response.redirect "?step=driver&act=show&id="&request("centerID")&"&msg=" & Server.URLEncode(msg)
125	end if
126elseif request("act")="show" then '---------------------- SHOW ------------------------------------
127	if request("step")="driver" then	
128		if isNumeric(request("id")) then 
129			id=request("id")
130			set rsCost= Conn.Execute("SELECT * FROM cost_centers where id="&id)
131			if rsCost.eof then 
132				response.write("���! ��� ���� ����� ��� ���!!!!!!!")
133				response.end
134			end if
135			costCenterName=rsCost("name")
136			rsCost.close
137			sql = "SELECT * FROM cost_drivers WHERE cost_center_id="&id
138			'response.write sql
139			set rs=Conn.Execute(sql)
140			%>
141			<a title="��Ґ�� �� ���� ���� ��������" href="costs.asp">������ ���� ����� <%=costCenterName%></a>
142			<br><br>
143			<table border="0" cellpadding="0" cellspacing="0">
144				<tr>
145					<td align="center"><b>���</b></td>
146					<td align="center"><b>����</b></td>
147					<td align="center"><b>�����</b></td>
148					<td align="center"><b>����</b></td>
149					<td align="center"><b>������</b></td>
150					<td align="center"><b>����ʐ�</b></td>
151					<td colspan=2></td>
152				</tr>
153				<%
154				while not rs.eof
155					%>
156					<tr>
157						<form method=post action='?act=edit&step=driver&centerID=<%=id%>'>							
158							<td><input type="text" name="driverName" value="<%=rs("name")%>"></td>
159							<td>
160								<input type=hidden name='rowID' value='<%=rs("id")%>'>
161								<input type="checkbox" name="isTime" <%if rs("is_time") then response.write "checked='checked'"%>>
162							</td>
163							<td>
164								<input type="checkbox" name="isCount" <%if rs("is_count") then response.write "checked='checked'"%>>
165							</td>
166							<td><input type=text name='rate' value='<%=rs("rate")%>' style='direction:LTR;'></td>
167							<td><input type=checkbox name='isDirect' <% if rs("is_direct")="True" then response.write "checked" %>></td>
168							<td><input type=checkbox name='isContinuous' <% if rs("is_countinuous")="True" then response.write "checked"%>></td>
169							<td><input type=submit value='������� ����� ���' ></td>
170							<td><input type=button value='��� ���' onclick='if (confirm("��� ����� ����� �� ��������� ��� ������ � ���� �����ʝ��� ������ �� ��� ���Ͽ\n\n")) window.location="costs.asp?act=del&step=driver&rowID=<%=rs("id")%>&id=<%=id%>";'></td>
171						</form>
172					</tr>
173					<tr bgcolor="#AAFFFF">
174						<td colspan="8" align="center"><b>�����ʝ��</b></td>
175					</tr>
176					<%
177					set rsop=Conn.Execute("select * from cost_operation_type where driver_id=" & rs("id"))
178					if rsop.eof then 
179					%>
180					<tr bgcolor="#AAFFFF">
181						<td colspan="8" align="center"><font color="red">��� ������� ���� ���! </font></td>
182					</tr>
183					
184					<%
185					end if
186					while not rsop.eof
187					%>
188					<tr bgcolor="#AAFFFF">
189						<form method="post" action="?act=edit&step=operationType&centerID=<%=id%>">
190							<td colspan="6">
191								<input type="hidden" name="id" value="<%=rsop("id")%>">
192								<input name="opName" type="text" value="<%=rsop("name")%>">
193							</td>
194							<td><input type=submit value='������� ����� ���' ></td>
195							<td><input type=button value='��� ���' onclick='if (confirm("��� ����� ����� �� ��������� ��� ������ �� ��� ���Ͽ\n\n")) window.location="costs.asp?act=del&step=operationType&rowID=<%=rsop("id")%>&id=<%=id%>";'></td>
196						</form
197					</tr>
198					<%
199						rsop.moveNext
200					wend
201					rsop.close
202					%>
203					<tr bgcolor="#AAAAFF">
204						<form method="post" action="?act=add&step=operationType&centerID=<%=id%>">
205							<td colspan="1" align="center">��� ������ �� ���� ����</td>
206							<td colspan="5">
207								<input type="text" name="opName">
208								<input type="hidden" name="driverID" value="<%=rs("id")%>">
209							</td>
210							<td colspan="2" align="center">
211								<input type="submit" name="action" value="����� ���">
212							</td>
213						</form>
214					</tr>
215					<%
216					rs.moveNext
217				wend
218				rs.close
219				%>
220				<tr>
221					<form method=post action='?act=add&step=driver&centerID=<%=id%>'>
222						<td><input type="text" name="driverName"></td>
223						<td><input type="checkbox" name="isTime" checked='checked'></td>
224						<td><input type="checkbox" name="isCount" checked='checked'></td>
225						<td><input type=text name='rate' style='direction:LTR;'></td>
226						<td><input type=checkbox name='isDirect'></td>
227						<td><input type=checkbox name='isContinuous'></td>
228						<td colspan=2 align=center><input type=submit name='action' value='����� ���'></td>
229					</form>
230				</tr>
231			</table>
232			
233			<%
234		end if	
235	end if
236end if	
237%>
238<!--#include file="tah.asp" -->