存档

‘Code’ 分类的存档

C#中常用JS语句

2010年5月28日 Kimi 2 条评论

有时候在开发中,经常输出一些js与客户端实现交互,虽然说是c#的其实好多js的,需要的朋友可以收藏下。
1. 输出语句 document.write(“”); 输出语句
2.JS中的注释为//
3.传统的HTML文档顺序是:document->html->(head,body)
4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,document)
5.得到表单中元素的名称和值:document.getElementById(“表单中元素的ID號”).name(或value)
6.一个小写转大写的JS: document.getElementById(“output”).value = document.getElementById(“input”).value.toUpperCase();
7.JS中的值类型:String,Number,Boolean,Null,Object,Function
8.JS中的字符型转换成数值型:parseInt(),parseFloat()
9.JS中的数字转换成字符型:(“” 变量)
10.JS中的取字符串长度是:(length)
11.JS中的字符与字符相连接使用 號.
12.JS中的比较操作符有:==等于,!=不等于,>,>=,<.<=
13.JS中声明变量使用:var来进行声明
14.JS中的判断语句结构:if(condition){}else{}
15.JS中的循环结构:for([initial expression];[condition];[upadte expression]) {inside loop}
16.循环中止的命令是:break
17.JS中的函数定义:function functionName([parameter],…){statement[s]}
18.当文件中出现多个form表单时.可以用document.forms[0],document.forms[1]来代替.
19.窗口:打开窗口window.open(), 关闭一个窗口:window.close(), 窗口本身:self
20.状態栏的设置:window.status=”字符”;
阅读全文…

Tags: ,
分类: Code 标签: ,

根据数据库中宁波公园的经纬度信息在Google地图上标出每个公园的位置并连线

2010年5月6日 Kimi 没有评论

数据库中含有宁波一些公园的详细信息,包括经纬度。要求将经纬度信息读取出来并调用Google Map的API服务在地图上标识出这些公园的位置。刚开始时想通过一个函数将一个buffer流写如到一个xml中并保存的,但JavaScript中调用时可能是事先预读入了,所以每次执行时都提示错误,只有当第二次这个xml真正存在时执行才会有用。为了这个问题纠结了很久结果还是不行,于是采用老师今天课堂上展示的成品中用的方法,果然奏效了。-_-||
运行效果图:

draw.:

< %@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
< %@page import = "java.util.*"%>
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Airport Locator</title>
</head>
<body>
<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAATmoH83Ly9iQx1uFnEHAlDBTwM0brOpm-All5BF6PoaKBxRWWERS1Yg55rmr66zkZ8YxvBZy71GJpEw"
      type="text/javascript"></script>
<style>
	#map {
		border:		1px solid #000000;
		height:		600px;
		width:		1000px;
	}
 
</style>
<script type="text/javascript">
    //< ![CDATA[
        var map;
    	var markers = [];
        var point = [];
        var i = 0;
		$(document).ready(function() {
			if (GBrowserIsCompatible()) {
				// Initialize the map.
				map = new GMap2(document.getElementById("map"));
				map.addControl(new GLargeMapControl());
				map.setCenter(new GLatLng(29.873519444400,121.554127777800), 13);
                                map.addControl(new GMapTypeControl());
                                $.ajax({type:"GET",url:"writexml.jsp",dataType:"xml",
					success:function(data,textStatus) {
						$("marker",data).each(function() {
							// Attributes for each marker.
	            			var lat = parseFloat($(this).attr("lat"));
	            			var lng = parseFloat($(this).attr("lng"));
	            			point[i] = new GLatLng(lat,lng);
 
	            			var html = $("html",this).text();
                                        //alert("Hello");
	            			// Create the marker.
	            			var marker = new GMarker(point[i]);
	            			i = i+1;
					        GEvent.addListener(marker, "click", function() {
								marker.openInfoWindowHtml(html);
					        });
 
	            			map.addOverlay(marker);
						});
                                        var polyline = new GPolyline(point, "#FF0000", 10);
                                        map.addOverlay(polyline);
					},
 
					error:function(XMLHTTPRequest,textStatus,errorThrow){
						alert("There was an error retrieving the marker information.");
					}});
			}
		});
 
		$(document.body).unload(function() {
			if (GBrowserIsCompatible()) {
				GUnload();
			}
		});
   //]]>
</script>
<div id="map"></div>
</body>
</html>

阅读全文…

Tags: , ,
分类: Code 标签: , ,

编写数据库存储过程实现商品出库

2010年4月26日 Kimi 没有评论

数据库的表结构如下

存储过程ap_popWhpro脚本:

alter procedure ap_popWhpro
	@pro_id		int,
	@wh_id		int,
	@num		int,
	@sum		money	output
as
begin
	declare
		@pos1		int,
		@pos2		int,
		@totNum		int,
		@curNum		int,
		@curPrice	money,
		--@sum		money,
		@sqlCmd		nvarchar(200),
		@fldNum		varchar(10),
		@fldPrice	varchar(10)
	select @pos1 = pos1, @pos2 = pos2, @totNum = totNum
		from whproduct
		where pro_id = @pro_id and wh_id = @wh_id
	if @totNum &lt; @num 	begin 		return -1 	end 	set @sum = 0 	while @num &gt; 0
	begin
		if @pos1&gt;8
		begin
			set @pos1 = @pos1 % 8
		end
		set @fldNum = 'num' + Convert(varchar(2), @pos1)
		set @fldPrice = 'price' + Convert(varchar(2), @pos1)
		set @sqlCmd = 'select @curNum = ' + @fldNum + ',@curPrice = '+ @fldPrice +' from whproduct where pro_id = @pro_id and wh_id = @wh_id'
		exec sp_executesql @sqlCmd, N'@curNum int output,@curPrice int output,@wh_id int, @pro_id int',@curNum output,@curPrice output,@wh_id, @pro_id
		if @curNum &lt; @num
		begin
			set @num = @num - @curNum
			set @pos1 = @pos1 + 1
			set @sum = @sum + @curPrice*@curNum
			set @sqlCmd = 'update whProduct set ' + @fldNum + ' = 0 ' + ', totNum = totNum - ' + Convert(varchar(5), @curNum) + 'where pro_id = @pro_id and wh_id = @wh_id'
		end
		else
		begin
			set @sqlCmd = 'update whProduct set ' + @fldNum + ' = ' + Convert(varchar(5), @curNum - @num)
					+ ', totNum = totNum - ' + Convert(varchar(5), @num) + 'where  pro_id = @pro_id and wh_id = @wh_id'
			set @num = 0
			set @sum = @sum + @curPrice*(@curNum - @num)
			set @pos1 = @pos1 + 1
		end
		exec sp_executesql @sqlCmd, N'@wh_id int, @pro_id int', @wh_id, @pro_id
	end
	set @sqlCmd = 'update whProduct set pos1 = ' + Convert(varchar(2), @pos1-1)
			+ 'where  pro_id = @pro_id and wh_id = @wh_id'
	exec sp_executesql @sqlCmd, N'@wh_id int, @pro_id int', @wh_id, @pro_id
end

执行存储过程的脚本:

select * from whproduct
 
declare
	@total	money
execute ap_popWhpro 1001,102,20,@total output
select @total totalmoney
 
select * from whproduct

执行效果:
第一排是执行前表中的数据,第二排是出库商品的总金额,第三排是执行后表的数据

Tags: ,
分类: Code 标签: ,

Services Manager实现简单服务管理

2010年4月17日 Kimi 5 条评论

前一阵子发现以前写的用于快速启动和停止服务的程序有点问题,特别表现在MySQL上,每次和其他服务一起同时执行启动或者停止,它总是不能有效执行。大致分析了一下,可能是用了process类来调用cmd程序,然后再write命令时有点问题。所以就想把它改进一下,后来改着改着发现又要把Oracle的停止与启动再加进去,这样一来就太麻烦了,于是觉得不怎么智能,以后要再装什么软件要用到服务的时候还得再改,太麻烦了。于是乎,我就萌生了从写一个智能点的又方便自己使用的管理程序。

到网上去search了一下,C#中有一个叫servicecontroller的类是专门用来调用管理windows服务的,就用它。本来还想写个进度条的,但要用多线程,太麻烦,而且还要研究操作的执行时间,就省了吧。如果以后有空再去慢慢研究。

以前的程序:

现在的程序:

现在把程序放在这供大家挑错,欢迎各位踊跃找茬,找出的有奖,具体奖项面议。^_^
Services Manager(运行该软件需要.net运行环境。传送门:.net framework

Tags: , , ,
分类: Code 标签: , , ,

JSP+MSSQL实现数据分页显示

2010年4月8日 Kimi 没有评论

通过编写JSP代码在网页中将数据库中公园信息按照顺序进行分页显示,每页10条记录。
运行效果图:







JSP代码:

<%@page contentType="text/html;charset=utf-8"%>
<%@page import="java.util.*"%>
<%@ page  language="java" import="java.sql.*"%>
<%@include file="inc1.jsp"%>
<getGardenList>
<%! 
	public static String returnToBr(String sStr) { 
 
	if (sStr == null || sStr.equals("")) { 
	return ""; 
	} 	
	return sStr.trim(); 
	} 
 
 
%>
<%	
 
 //    ResultSet rs= null;
	 int pagecount=0;
	 int count=0;
	 int n;
	 String sql_query=""; 
	 String see="";
//	Connection conn = null;
//	Statement stmt = null;
//	int li_temp = 0;
	String pages = new			String(request.getParameter("pages").getBytes("ISO8859-1"),"utf-8");
//	if(findString == null)
//		findString = "";
//	System.out.println(findString);
 
 
	try
	{
		//连接数据库
		Class.forName(DBDriver);
		Connection conn=DriverManager.getConnection(DBLocation,DBUser,DBPwd);
 
		Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
		sql_query = "select * from yl_garden ";
		ResultSet rs=stmt.executeQuery(sql_query);
 
 
//	rs=stmt.executeQuery(sql_query);
%>	
<table width="100%" border="1">
  <tr>
    <td><div align="center">序号</div></td>
    <td><div align="center">名称</div></td>
    <td><div align="center">地址</div></td>
    <td><div align="center">级别</div></td>
  </tr>
  <%    rs.last();
		count=rs.getRow();
		rs.beforeFirst();
		n=(Integer.parseInt(pages)-1)*10;
		while(rs.next()){
			if(n>=rs.getRow())
				continue;	
			out.println("<tr>");
 
			see=rs.getString("gardenid");
			see= returnToBr(see);	
			out.println("<td>"+ see.trim()+"</td>");
 
			see=rs.getString("gardenname");
			see= returnToBr(see);	
			out.println("<td>"+ see.trim()+"</td>");
 
			see=rs.getString("gardenplace");
			see= returnToBr(see);	
			out.println("<td>"+ see.trim()+"</td>");
 
			see=rs.getString("gardenlevel");
			see= returnToBr(see);	
			out.println("<td>"+ see.trim()+"</td>");
 
	        out.println("</tr>");
			n++;
			if(n%10==0)
				break;
		}
		%>
		</table>
		<center><%out.println(pages);%>页,
			共<%if(count%10==0)
					pagecount=count/10;
				else
					pagecount=count/10+1;
				out.println(pagecount);
			%><br>
			<a href="flex_getGardenList.jsp?pages=1">最前一页</a><a href="flex_getGardenList.jsp?pages=
			<%if(Integer.parseInt(pages)==1)
				out.println(pages);
			  else
				out.println(Integer.parseInt(pages)-1);
			%>">上一页</a><a href="flex_getGardenList.jsp?pages=
			<%if(Integer.parseInt(pages)==pagecount)
				out.println(pages);
			  else
				out.println(Integer.parseInt(pages)+1);
			%>">下一页</a><a href="flex_getGardenList.jsp?pages=<%=pagecount%>">最后一页</a>
		</center>
		<%
		rs.close();
		stmt.close();
		conn.close();
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
%>
</getGardenList>
Tags: , ,
分类: Code 标签: , ,