public partial class admin_aspx_default_bm_out_dbf : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
#region 创建dbf副本
string _f = "stu_info";
string tbl = Server.MapPath("/" + _f + ".dbf");
string fileTemName = _f + "_" + DateTime.Now.ToShortDateString();
string filetemPath = Server.MapPath("/dbf/" + fileTemName + ".dbf");
File.Copy(tbl, filetemPath, true);
#endregion
#region 创建连接
System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection();
string table = filetemPath;
string connStr = @"Driver={Microsoft Visual FoxPro Driver};SourceType=DBF;SourceDB=" + table + ";Exclusive=No;NULL=NO;Collate=Machine;BACKGROUNDFETCH=NO;DELETED=NO";
conn.ConnectionString = connStr;
conn.Open();
#endregion
#region 写入
DbObject db = new DbObject();
DataSet ds = db.GetDataSet("select * from bm_zhanghao where IsStuInfo=0 and flg=恭喜您,报名成功");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
OdbcCommand cmd = new OdbcCommand();
cmd.Connection = conn;
string sql = "insert into " + table + "([学号],[学生姓名],[性别名称],[证件号码],[年级],[班级名称],[专业名称],[学院名称],[层次名称],[形式名称],[学生类别名],[校区名称],[港澳侨台],[教工子女],[学制],[手机],[省份名称],[民族名称],[入学标志],[处理结果],[银行帐号],[准考证号]) values(" + ds.Tables[0].Rows[i]["jfh"].ToString() + "," + ds.Tables[0].Rows[i]["name"].ToString() + "," + GuanLian1(ds.Tables[0].Rows[i]["id"].ToString(), "bm_info", "xingbie") + "," + ds.Tables[0].Rows[i]["code"].ToString() + "," + System.DateTime.Now.Year.ToString() + ",自主招生班,自主招生,自主招生,报名费,一次性,,,,,,,,,,,," + ds.Tables[0].Rows[i]["kaohao"].ToString() + ");";
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
//更新IsStuInfo=1
// db.ExecuteSql("update bm_zhanghao set IsStuInfo=1 where id=" + ds.Tables[0].Rows[i]["id"].ToString());
}
ds.Clear();
ds.Dispose();
db.Dispose();
conn.Close();
conn.Dispose();
#endregion
#region 弹出导出对话框
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=学生信息导入_" + DateTime.Now.ToLongDateString() + ".dbf");
string filename = filetemPath;
Response.TransmitFile(filename);
#endregion
}
#region 整形绑定关联值
/// <summary>
/// 整形绑定关联值
/// </summary>
/// <param name="id">条件参数</param>
/// <returns></returns>
public string GuanLian(string id, string tbl, string fld)
{
string Rn = id;
if (!string.IsNullOrEmpty(id))
{
if (Fun.IsNumber(id))
{
DbObject db = new DbObject();
string sql = "select " + fld + " from " + tbl + " where id=" + id;
DataSet ds = db.GetDataSet(sql);
if (ds.Tables[0].Rows.Count > 0)
{
Rn = ds.Tables[0].Rows[0][0].ToString();
}
ds.Clear();
ds.Dispose();
db.Dispose();
}
}
return Rn;
}
private string GuanLian1(string id, string tbl, string fld)
{
string Rn = id;
if (!string.IsNullOrEmpty(id))
{
if (Fun.IsNumber(id))
{
DbObject db = new DbObject();
string sql = "select " + fld + " from " + tbl + " where uid=" + id;
DataSet ds = db.GetDataSet(sql);
if (ds.Tables[0].Rows.Count > 0)
{
Rn = ds.Tables[0].Rows[0][0].ToString();
}
ds.Clear();
ds.Dispose();
db.Dispose();
}
}
return Rn;
}
#endregion
}