// 新增管理员账号
 protected void btn8_Click(object sender, EventArgs e)
 {
     if (!am.Check(txt7.Text.Trim()))
     {
         admins ad = new admins();
         ad.AdminId   = txt7.Text.Trim();
         ad.Pwd       = txt8.Text.Trim();
         ad.Name      = txt10.Text.Trim();
         ad.Cellphone = txt11.Text.Trim();
         ad.Email     = txt12.Text.Trim();
         ad.Creater   = Session["adminId"].ToString();
         am.Insert(ad);
         gridviewBind();
         ScriptManager.RegisterStartupScript(this, this.GetType(), "updateScript", "alert(\"新增成功\");", true);
     }
 }
예제 #2
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        #region 验证文件
        if (string.IsNullOrEmpty(fudExcel.FileName))
        {
            Response.Write("请选择上传文件!");
            return;
        }
        string extension = fudExcel.FileName.Substring(fudExcel.FileName.LastIndexOf('.'));

        if (extension == ".xlsx")
        {
            Response.Write("目前模板只支持Excel2003版文件,请转换后再导入!");
            return;
        }
        if (extension != ".xls")
        {
            Response.Write("上传文件扩展必须是(xls/xlsx)文件!");
            return;
        }
        #endregion
        string filepath = string.Empty;
        // 上传到服务器临时目录下
        string tempdir  = Server.MapPath("upload/");
        string filename = Guid.NewGuid() + extension;
        filepath = tempdir + filename;
        // 保存
        fudExcel.SaveAs(filepath);
        bool existsSheetname = false;
        // 读取到DataTable
        var data = ExcelDataSource(filepath, ref existsSheetname);
        if (!existsSheetname)
        {
            Response.Write("没有找到《模板工作表》工作表!");
            return;
        }

        // 删除临时文件
        System.IO.File.Delete(filepath);
        if (data == null)
        {
            Response.Write("解析Excel失败,请检查Excel是否符合模板要求!");
            return;
        }

        foreach (DataRow row in data.Rows)
        {
            string id     = row["编号"].ToString();
            var    arrRow = DataSource.Select("编号='" + id + "'");
            if (arrRow != null && arrRow.Length > 0)
            {
            }
            else
            {
                DataRow newrow = DataSource.NewRow();
                newrow["编号"] = row["编号"];
                newrow["名称"] = row["名称"];
                newrow["备注"] = row["备注"];

                AdminsManage am = new AdminsManage();
                admins       n  = new admins();
                n.AdminId   = newrow["编号"].ToString();
                n.Name      = newrow["名称"].ToString();
                n.Cellphone = newrow["备注"].ToString();
                n.Creater   = "120";
                n.Email     = "fefefe";
                n.Pwd       = "111";
                am.Insert(n);
                DataSource.Rows.Add(newrow);
            }
        }
        gvwRoleBind();
    }