return io
},
createUploadForm: function(id, fileElementId)
{
//create form
var formId = 'jUploadForm' + id;
var fileId = 'jUploadFile' + id;
var form = $('');
var oldElement = $('#' + fileElementId);
var newElement = $(oldElement).clone();
$(oldElement).attr('id', fileId);
$(oldElement).before(newElement);
$(oldElement).appendTo(form);
//set attributes
$(form).css('position', 'absolute');
$(form).css('top', '-1200px');
$(form).css('left', '-1200px');
$(form).appendTo('body');
return form;
},
ajaxFileUpload: function(s) {
// TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
s = jQuery.extend({}, jQuery.ajaxSettings, s);
var id = new Date().getTime()
var form = jQuery.createUploadForm(id, s.fileElementId);
var io = jQuery.createUploadIframe(id, s.secureuri);
var frameId = 'jUploadFrame' + id;
var formId = 'jUploadForm' + id;
// Watch for a new set of requests
if ( s.global && ! jQuery.active++ )
{
jQuery.event.trigger( "ajaxStart" );
}
var requestDone = false;
// Create the request object
var xml = {}
if ( s.global )
jQuery.event.trigger("ajaxSend", [xml, s]);
// Wait for a response to come back
var uploadCallback = function(isTimeout)
{
var io = document.getElementById(frameId);
try
{
if(io.contentWindow)
{
xml.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;
xml.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;
}else if(io.contentDocument)
{
xml.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null;
xml.responseXML = io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document;
}
}catch(e)
{
jQuery.handleError(s, xml, null, e);
}
if ( xml || isTimeout == "timeout")
{
requestDone = true;
var status;
try {
status = isTimeout != "timeout" ? "success" : "error";
// Make sure that the request was successful or notmodified
if ( status != "error" )
{
// process the data (runs the xml through httpData regardless of callback)
var data = jQuery.uploadHttpData( xml, s.dataType );
// If a local callback was specified, fire it and pass it the data
if ( s.success )
s.success( data, status );
// Fire the global callback
if( s.global )
jQuery.event.trigger( "ajaxSuccess", [xml, s] );
} else
jQuery.handleError(s, xml, status);
} catch(e)
{
status = "error";
jQuery.handleError(s, xml, status, e);
}
// The request was completed
if( s.global )
jQuery.event.trigger( "ajaxComplete", [xml, s] );
// Handle the global AJAX counter
if ( s.global && ! --jQuery.active )
jQuery.event.trigger( "ajaxStop" );
// Process result
if ( s.complete )
s.complete(xml, status);
uploadHttpData: function( r, type ) {
var data = !type;
data = type == "xml" || data ? r.responseXML : r.responseText;
// If the type is "script", eval it in global context
if ( type == "script" )
jQuery.globalEval( data );
// Get the JavaScript object, if JSON is used.
if ( type == "json" )
eval( "data = " + data );
// evaluate scripts within html
if ( type == "html" )
jQuery("
三、doupFiles.ashx
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using System.Data.SqlClient;
using System.Web.Services;
using System.Web.Services.Protocols;
using FinancePortal.Utilities;
using System.Threading;
function ResultProcess(result, onsuccess, onerror) {
var pos = result.indexOf(":");
var status = result.substring(0, pos);
var text = result.substring(pos+1);
if( status == "success")
onsuccess(text);
else
onerror(text);
}
五、类UpFileLoad.cs
/*
* 说明:本类实现解压缩和上传文本文件到数据库表中
*/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.UI.MobileControls;
using System.IO;
using System.IO.Compression;
using System.Data.SqlClient;
using System.Text;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Diagnostics;
using Microsoft.VisualBasic;
using System.Xml;
using System.Xml.XPath;
using System.Collections.Generic;
using System.Text.RegularExpressions;
/// /// UpFileLoad 的摘要说明
/// public class UpFileLoad
{
/// /// 获取数据库连接字符串
/// private string connstring = System.Configuration.ConfigurationManager.AppSettings["DBConnection"];
public UpFileLoad()
{
/// /// 封装数据库名和上传类型名称
/// public class UpFileSet
{
public UpFileSet(string name, List upfiles)
{
m_dbName = name;
m_upFiles = upfiles;
}
/// /// 数据库名称
/// public string DbName
{
get { return m_dbName; }
}
public List M_upFiles
{
get { return m_upFiles; }
}
private string m_dbName; //数据库名
private List m_upFiles; //文件表名列表
}
/// /// 枚举类
/// public class EnuNumber
{
/// /// 类型-枚举
/// public enum enumDataType
{
Charge, //缴费
UsstCharge, //本专科缴费
NightCharge, //夜大缴费
MasterCharge, //研究生缴费
Outlay, //金费
Salary //工资
}
}
#region 操作文件
/// /// 操作文件夹及文件
/// public class CreateFolders
{
/// /// 读取文件夹的文件
/// ///
/// public static DirectoryInfo checkValidSessionPath(string FilePathName)
{
try
{
DirectoryInfo mainDir = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath(FilePathName));
return mainDir;
}
catch
{
throw;
}
}
}
#endregion
#region 操作数据表
public abstract class Command
{
/// /// Execute a SqlCommand (that returns no resultset) using an existing SQL Transaction
/// using the provided parameters.
/// ///
///
///
///
/// public static int ExecuteNonQuery(SqlTransaction trans, CommandType cmdType, string cmdText, params SqlParameter[] cmdParms)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandTimeout = 900;
PrepareCommand(cmd, trans.Connection, trans, cmdType, cmdText, cmdParms);
int val = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return val;
}
public static int ExecuteNonQuery(SqlTransaction trans, string cmdText, params SqlParameter[] cmdParms)
{
return ExecuteNonQuery(trans, CommandType.Text, cmdText, cmdParms);
}
/// /// Prepare a command for execution
/// ///
///
///
///
///
///
private static void PrepareCommand(SqlCommand commd, SqlConnection conn, SqlTransaction trans, CommandType cmdType, string cmdText, SqlParameter[] paras)
{
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
commd.Connection = conn;
commd.CommandText = cmdText;
if (trans != null)
commd.Transaction = trans;
commd.CommandType = cmdType;
if (paras != null)
{
foreach (SqlParameter para in paras)
{
commd.Parameters.Add(para);
}
}
}
}
#endregion
/// /// 操作同步数据标识
/// public static class UserStatus
{
private static bool _isUsered = false;
/// /// 是否正在上传文件
/// public static bool IsUsered
{
get { return UserStatus._isUsered; }
set { UserStatus._isUsered = value; }
}
}
六、xml文件UpLoadFiles.xml
七、Web.config
八、XSqlCenter.cs
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Xml;
using System.Xml.XPath;
using FinancePortal.Utilities;
using XSqlEngine.QueryManger;
using XSqlEngine.Request;
using XSqlEngine.Database.MSSql;
namespace FinancePortal
{
static class XSqlCenter
{
static XSqlCenter()
{
string path_ = HttpRuntime.AppDomainAppPath+ConfigurationManager.AppSettings["XSqlPath"];
string fileName_=ConfigurationManager.AppSettings["XSqlFile"];
using (FileStream file_ = File.Open(path_+"//"+fileName_, FileMode.Open))
{
s_xSqlManger = new XSqlManger(file_, path_);
}
string strConn_ = ConfigurationManager.AppSettings["DBConnection"];
s_dataAccess = new DataAccess(strConn_);
s_userKey = ConfigurationManager.AppSettings["userKey"];
double exp_;
if(!double.TryParse(ConfigurationManager.AppSettings["Expire"], out exp_))
throw new Exception("在配置文件中获取“Expire”失败。");
s_logExpire = TimeSpan.FromMinutes(exp_);
public static XSqlManger s_xSqlManger;
public static DataAccess s_dataAccess;
public static UserControl s_userCtrl;
public static FuncControl s_funcCtrl;
public static string s_userKey;
public static TimeSpan s_logExpire;
}
public class QueryEnvironment
{
public QueryEnvironment(HttpRequest request, XSqlManger manger)
{
m_reqData = new RequestData(request);
KeyValuePair fullQuery_
= manger.GetQueryInfoX(m_reqData.queryName);
m_xsqlInfo = fullQuery_.Key;
m_xDataTrans = fullQuery_.Value;
try
{
m_curUser = XSqlCenter.s_userCtrl.CheckUser(m_reqData.key);
}
catch
{
if (m_xsqlInfo.auth)
throw;
}
public class UserControl
{
public UserControl()
{}
public UserInfo Login(string userId, string psw)
{
string sql_ = "select rtrim(UserId) as UserId, rtrim(UserName) as UserName, BaseGroup, rtrim(Pid) as Pid, PswChange, ExtData"
+" from Users"
+" where UserId=@uid and Password=@psw";
SqlParameter[] uparams_ = new SqlParameter[2];
uparams_[0] = new SqlParameter("@uid", userId);
uparams_[1] = new SqlParameter("@psw", psw);
SqlDataReader dbuser_ = XSqlCenter.s_dataAccess.Execute(sql_, uparams_);
if (!dbuser_.Read())
throw new Exception("用户 "+userId+" 不存在或密码错误");
string oldKey_=null;
foreach (UserInfo oldUser_ in m_Users.Values)
{
if (oldUser_.id == userId)
{
oldKey_ = oldUser_.key;
break;
}
}
if (!string.IsNullOrEmpty(oldKey_))
m_Users.Remove(oldKey_);
if (m_Users.ContainsKey(user_.key))
m_Users[user_.key] = user_;
else
m_Users.Add(user_.key, user_);
return user_;
}
public void Logout(string key)
{
if (m_Users.ContainsKey(key))
m_Users.Remove(key);
}
public UserInfo CheckUser(string key)
{
if (!m_Users.ContainsKey(key))
throw new Exception("101,用户未登录");
UserInfo user_ = m_Users[key];
if (user_.logTime + XSqlCenter.s_logExpire < DateTime.Now)
{
m_Users.Remove(key);
throw new Exception("101,用户登录已经超时");
}
return user_;
}
public void ChangeMyPassword(string key, string oldPsw, string newPsw)
{
if (string.IsNullOrEmpty(oldPsw))
throw new Exception("旧密码无效。");
if (string.IsNullOrEmpty(newPsw))
throw new Exception("新密码无效。");
UserInfo user_=this.CheckUser(key);
string uid_ = user_.id;
string chkusr_ = "select count(*) from Users where UserId=@uid and Password=@psw";
string setpsw_ = "update Users set Password=@newPsw "
+ "where UserId=@uid and Password=@psw";
SqlParameter[] uparams_ = new SqlParameter[2];
SqlParameter[] cparams_ = new SqlParameter[3];
cparams_[0] = new SqlParameter("@uid", uid_);
cparams_[1] = new SqlParameter("@psw", oldPsw);
cparams_[2] = new SqlParameter("@newPsw", newPsw);
uparams_[0] = new SqlParameter("@uid", uid_);
uparams_[1] = new SqlParameter("@psw", oldPsw);
using (SqlDataReader dbuser_ = XSqlCenter.s_dataAccess.Execute(chkusr_, uparams_))
{
if (!dbuser_.Read())
throw new Exception("旧密码不匹配。");
int cu_ = dbuser_.GetInt32(0);
if(cu_<1)
throw new Exception("旧密码不匹配。");
}
public class FuncControl
{
public FuncControl()
{
string sql_ = "select FuncId, rtrim(FuncName) as FuncName, rtrim(text) as text, rtrim(Frame) as Frame, rtrim(FrameParam) as FrameParam"
+ ", rtrim(srcSelector) as srcSelector, rtrim(dstSelector) as dstSelector, ExtData"
+ " from Functions";
public FuncInfo getFunc(string name)
{
if (!m_Funcs.ContainsKey(name))
throw new Exception("功能 "+name+" 不存在.");
return m_Funcs[name];
}
private Dictionary m_Funcs = new Dictionary();
}
}
九、XSqlSet.xml
select(select
(SELECT rtrim(Name) as "@term",convert(varchar(20),InitDate,120) as "@createdate"
FROM {dbname}tblTerm ORDER BY ObjectID for xml path('term'),type) as "termSet",
(SELECT TOP 1 convert(varchar(20),ImportTime,120) as "@importtime",rtrim(UserId) as "@userid" FROM {dbname}SF_ImportLog ORDER BY objId DESC
for xml path('user'),type) as "LogSet"
for xml path('charge'), type).query('{:xQuery}')
select(select rtrim(TimeID) as "@TimeID",rtrim(GroupID) as "@groupID",
(rtrim(ATypeName)+','+rtrim(BTypeName)) as "@account",rtrim(Note) as "@note",
convert(varchar(20),ImportTime,120) as "@importtiem",rtrim(UserID) as "@userId"
FROM {dname}GZ_ImportLog ORDER BY TimeId DESC,GroupID DESC
for xml path('saraly'),type,root('saralys')).query('{:xQuery}')
现有工资数据列表:
数据时间
批次
账套
描述
上传时间
上传用户
{
for $saraly in /saralys/saraly
return
{data($saraly/@TimeID)}
{data($saraly/@groupID)}
{data($saraly/@account)}
{data($saraly/@note)}
{data($saraly/@importtiem)}
{data($saraly/@userId)}
}
DELETE FROM {dname}GZ_Employees WHERE TimeId='{timeId}' AND GroupID={groupId}
DELETE FROM {dname}GZ_EmployeeType WHERE TimeId='{timeId}' AND GroupID={groupId}
DELETE FROM {dname}GZ_Items WHERE TimeId='{timeId}' AND GroupID={groupId}
DELETE FROM {dname}GZ_Type_Field WHERE TimeId='{timeId}' AND GroupID={groupId}
DELETE FROM {dname}GZ_ImportLog WHERE TimeId='{timeId}' AND GroupID={groupId}
DELETE t1 FROM {dname}GZ_Password t1 LEFT JOIN {dname}GZ_Employees t2 ON t1.Employeeid=t2.EmployeeId WHERE t2.employeeid is null
select '删除成功!'
web.xml报错
The content of element type "web-app" must match "(icon?,display-
name?,description?,distributable?,context-param*,filter*,filter-mapping*,listener*,servlet*,s
JUnit4:Test文档中的解释:
The Test annotation supports two optional parameters.
The first, expected, declares that a test method should throw an exception.
If it doesn't throw an exception or if it
借鉴网上的思路,用java实现:
public class NoIfWhile {
/**
* @param args
*
* find x=1+2+3+....n
*/
public static void main(String[] args) {
int n=10;
int re=find(n);
System.o
在Linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file or directory。
分析:这是不同系统编码格式引起的:在windows系统中编辑的.sh文件可能有不可见字符,所以在Linux系统下执行会报以上异常信息。
解决:
1)在windows下转换:
利用一些编辑器如UltraEdit或EditPlus等工具
Binary search tree works well for a wide variety of applications, but they have poor worst-case performance. Now we introduce a type of binary search tree where costs are guaranteed to be loga