using System;
using System.Collections
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Text;
using System.Data.Odbc;
using EC;

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
}

随机推荐

  1. 数据结构:链表(python版)

    #!/usr/bin/env python # -*- coding:utf-8 -*- # Author: Minion Xu class LinkedListUnderflow(ValueErro ...

  2. CSS 知识点

    1:display:block:比较常用于<a><span>这两个标签——因为这两个标签非块元素,如果不用display:block定义一下,因为a标签没有结构,就是没有宽高, ...

  3. 今天起改用mac的marsedit写博

    最近一直使用mac来工作,所以写博也相应改为marsedit. 初步感觉还是不错的,越来越发现mac其实也适合在工作中使用,生活上当然不在话下. 从高富帅的x220t变成屌丝的macbook小白(升级 ...

  4. android应用程序fps meter[帧数显示]的分析 —— 浅谈root的风险 (1)

    fps meter是常用的检测帧率的软件,该软件需要root权限才能工作,一直比较好奇它一个apk是如何知道系统当前的帧率情况的,就针对此apk分析了一下其工作原理. Apk组成 首先看一下apk的组 ...

  5. C# T4 模板 数据库实体类生成模板(带注释,娱乐用)

     说明:..,有些工具生成实体类没注释,不能和SqlServer的MS_Description属性一起使用,然后照着网上的资源,随便写了个生成模板,自娱自乐向,其实卵用都没有参考教程    1.htt ...

  6. Java的多线程实现生产/消费模式

    Java的多线程实现生产/消费模式 在Java的多线程中,我们经常使用某个Java对象的wait(),notify()以及notifyAll() 方法实现多线程的通讯,今天就使用Java的多线程实现生 ...

  7. Codeforces Round #491 (Div. 2)

    Codeforces Round #491 (Div. 2) https://codeforces.com/contest/991 A #include<bits/stdc++.h> us ...

  8. finally知识讲解

    finally语句一定会执行吗,很多人认为一定会,其实未必,只有与 finally 相对应的 try 语句块得到执行的情况下,finally 语句块才会执行.假如在try语句之前执行了return操作 ...

  9. 047——VUE中css过渡动作实例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. (zxing.net)一维码EAN 8的简介、实现与解码

    一.简介 一维码EAN 8:属于国际标准条码,由8个数字组成,属EAN的简易编码形式(EAN缩短码).当包装面积小于120平方公分以下无法使用标准码时,可以申请使用缩短码. 依结构的不同,EAN条码可 ...