简单的批量导入的实现

2018-09-05 07:57:59来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

//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);

              }

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:WebService简单介绍(一)

下一篇:ie下警告console未定义