• 打卡成功


    namespace Clock.UI.Controllers
    {
    using System.Data.OleDb;
    using System.Data;
    using System.Data.SqlClient;
    using Clock.BLL;
    using Clock.Model;
    using Newtonsoft.Json;
    public class ClockController : Controller
    {
    UsersClockBLL clockBLL = new UsersClockBLL();
    // GET: Clock
    public ActionResult Index()
    {
    return View();
    }
    public ActionResult Execl()
    {
    return View();
    }
    [HttpPost]
    public string GetExcel()
    {
    //获取所选文件
    HttpPostedFileBase getFile = Request.Files["Excel"];
    if (getFile != null)
    {
    //获得所选文件名
    string fileName = Server.MapPath("~/Content/") + getFile.FileName;
    if (!System.IO.File.Exists(fileName))
    getFile.SaveAs(fileName);
    //把Excel当做数据源连接
    string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties=Excel 12.0;";
    //打开Excel
    OleDbConnection conn = new OleDbConnection(connStr);
    conn.Open();
    //查询Excel
    string sql = "select * from [Sheet1$]";
    OleDbCommand cmd = new OleDbCommand(sql, conn);
    //初始化适配器
    OleDbDataAdapter adapter = new OleDbDataAdapter();
    //获取查出来的Excel表
    adapter.SelectCommand = cmd;
    //初始化dataset并通过适配器赋值
    DataSet ds = new DataSet();
    adapter.Fill(ds);
    //获得ds的第一个表并添加到dataGridView1显示
    DataTable dt = ds.Tables[0];
    for (int i = 0; i < dt.Rows.Count; i++)
    {
    string sqlStr = string.Format("insert into UsersClock(Department, Name, Num, ClockDate, position) values('{0}','{1}','{2}','{3}','{4}')", dt.Rows[i]["Department"], dt.Rows[i]["Name"], dt.Rows[i]["Num"], dt.Rows[i]["ClockDate"], dt.Rows[i]["position"]);
    DBhelper.AddOrDeleteOrUpdate(sqlStr, CommandType.Text);
    }
    conn.Close();
    return "导入成功!";
    }
    else
    {
    return "导入失败!";
    }
    }
    /// <summary>
    /// 显示打卡记录
    /// </summary>
    /// <returns></returns>
    public ActionResult ShowUsersClock()
    {
    return View();
    }

    /// <summary>
    /// 获得所有打卡记录
    /// </summary>
    /// <returns></returns>
    [HttpGet]
    public JsonResult GetUsersClocks()
    {
    List<UsersClock> clocksList = clockBLL.GetUsersClocks();
    return Json(clocksList,JsonRequestBehavior.AllowGet);
    }
    }
    }


    @{
    Layout = null;
    }

    <!DOCTYPE html>
    <script src="~/Content/jquery-3.1.1.js"></script>
    <script>
    $(function () {
    $.ajax({
    url: "/Clock/GetUsersClocks",
    type: "get",
    success: function (data) {
    $(data).each(function (index,data) {
    $("#getData").append("<tr><td>" + data.ID + "</td><td>" + data.Department + "</td><td>" + data.Name + "</td><td>" + data.Num + "</td><td>" + data.ClockDate + "</td><td>" + data.position + "</td></tr>");
    })
    }
    })
    })
    </script>
    <html>
    <head>
    <meta name="viewport" content="width=device-width" />
    <title>ShowUsersClock</title>
    </head>
    <body>
    <table id="getData">
    <tr>
    <td>ID</td>
    <td>所属部门</td>
    <td>姓名</td>
    <td>打卡号</td>
    <td>打卡日期</td>
    <td>职位</td>
    </tr>

    </table>
    <div>
    </div>
    </body>
    </html>


    @{
    Layout = null;
    }

    <!DOCTYPE html>
    <script src="~/Content/jquery-3.1.1.js"></script>
    <script>
    $(function () {
    $("#btnToLead").click(function () {
    $.ajax({
    url: "/Clock/GetExcel",
    contentType: false,
    processData: false,
    cache: false,
    data: new FormData($("#formData")[0]),
    type: 'POST',
    success: function (data) {
    alert(data);
    }
    })
    })
    })
    </script>
    <html>
    <head>
    <meta name="viewport" content="width=device-width" />
    <title>Execl</title>
    </head>
    <body>
    <div>
    <form id="formData" method="post" enctype="multipart/form-data">
    <input id="File1" type="file" accept=".xls,.xlsx" name="Excel" />
    <input id="btnToLead" type="button" value="导入" />
    </form>
    </div>
    </body>
    </html>

  • 相关阅读:
    NodeMCU快速上云集锦
    云数据库 MySQL 8.0 重磅发布,更适合企业使用场景的RDS数据库
    MySQL 8.0 技术详解
    为更强大而生的开源关系型数据库来了!阿里云RDS for MySQL 8.0 正式上线!
    阿里云CDN技术掌舵人文景:相爱相杀一路狂奔的这十年
    容器服务kubernetes federation v2实践五:多集群流量调度
    Helm V3 新版本发布
    Serverless助力AI计算:阿里云ACK Serverless/ECI发布GPU容器实例
    详解TableStore模糊查询——以订单场景为例
    洛谷P2727 01串 Stringsobits
  • 原文地址:https://www.cnblogs.com/Tbwe/p/10001898.html
Copyright © 2020-2023  润新知