码迷,mamicode.com
首页 > 其他好文 > 详细

简单的批量导入的实现

时间:2018-09-05 17:52:46      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:sage   common   col   isnull   必须   form   reg   muse   itop   

//JS:

$("#btnInsert").click(function (e) {

        var b = $("#txtMore").val()

        var tmp1 = $("#txtMore").val().split("\n"); //过滤换行符,获取每一行的数据

        var tmp = "";

        var a = "";

        for (i = 0; i < tmp1.length; i++)

        {

            tmp1[i] = tmp1[i].replace(/\s+/g, ‘ ‘); //过滤字符串前面的空格

            tmp1[i] = tmp1[i].replace(/(^\s*)|(\s*$)/g, ‘‘); //过滤字符串中间的空格

            tmp = tmp1[i].split(" ");//过滤空格,获取每行里面的三个数据

//下面是对数据做判断生成log提示用户,还没做全

            if (tmp.length != 3) {

                a += "第" + i + 1 + "行数据格式不正确!\n";

            }

            if (!tmp[2] == "" && tmp[2].length < 6)

                a += "第" + i + 1 + "行第三个密码长度必须超过6位\n";

        }

        if (a != "")

        {

            aler(a);

            return false;

        }

      

        return true;

      });

  

//c#:

  try

            {

                 BasePage_Common bp = new BasePage_Common();

                if (string.IsNullOrEmpty(txtMore.Text))

                {

                    MessageBox.Show(this, "批量用户数据不能为空,请输入用户");

                    return;

                }

        var tmp1 = txtMore.Text.Split(new Char[] {‘\r‘, ‘\n‘ },StringSplitOptions.RemoveEmptyEntries);

                String[] tmp;

       List<UserInfo_Base> List = new List<UserInfo_Base>();

                for (var i = 0; i < tmp1.Length; i++)

                {

         var entity =ConversionHelper.NameValueCollectionToGeneric<UserInfo_Base>(Request.Form);

                    tmp1[i] = tmp1[i].ToString().Replace("\t", " ");

                    tmp1[i] = new Regex("[\\s]+").Replace(tmp1[i], " ");

                    tmp1[i] = tmp1[i].Trim();

                    tmp=tmp1[i].Split(‘ ‘);

                    if (tmp.Length!= 3)

                        throw new LogicError("非法访问");//如果用户跳过js验证,说明是非法用户

                    entity.TrueName = tmp[0].ToString();

                    entity.LoginName = tmp[1].ToString();

                    if (tmp[2].Length < 6)

                        throw new LogicError("密码长度不能小于6位");

                    entity.LoginPWD = tmp[2].ToString();

                    List.Add(entity); //用List装数据

                }

                var nentity = sys.Insert(Request.Url.ToString(), "systemuser", "systemuser_add", bp.UserIP, LoginUser.UserID, List); //因为采用的是多层架构所以直接调用DAL层,遍历List执行插入操作,执行成功事务Commit;

                if (nentity)

                    MessageBox.Show(this," ","添加成功","user.aspx");

            }

            catch (LogicError lgex)

            {

                LogHelper.Debug(lgex.Message);

                MessageBox.Show(this, lgex.Message);

              }

简单的批量导入的实现

标签:sage   common   col   isnull   必须   form   reg   muse   itop   

原文地址:https://www.cnblogs.com/cxd1997/p/9591938.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!