Exemple #1
0
        /// <summary>
        /// 导入确认
        /// </summary>
        /// <param name="matchid"></param>
        /// <param name="fid"></param>
        /// <returns></returns>
        public ActionResult confirm(string matchid, string fid)
        {
            try
            {
                ViewBag.error   = "0";
                ViewBag.matchid = matchid;
                ViewBag.fid     = fid;

                List <tblmatchentity> lstMatchusers = new List <tblmatchentity>();

                DataTable data = NpoiHelper.XlSToDataTable(System.IO.Path.Combine(Server.MapPath("~/upload/file"), fid), "TTBM", 0);

                if (data == null || data.Rows.Count < 1)
                {
                    return(View(lstMatchusers));
                }

                GroupBll bll   = new GroupBll();
                tblmatch match = bll.GetMatchById(matchid);

                ViewBag.matchname = HttpUtility.HtmlEncode(match.Match_name);

                StringBuilder sbtError = new StringBuilder();

                int    sn       = 0;
                string lineid   = "";
                string teamno   = "";
                string teamname = "";
                string company  = "";
                int    year     = 0;

                foreach (DataRow row in data.Rows)
                {
                    sbtError.Clear();
                    year = 0;

                    if (string.IsNullOrEmpty(row["队员姓名"].ToString().Trim()))
                    {
                        continue;
                    }

                    //记录序号,以标记团队
                    if (!string.IsNullOrEmpty(row["序号"].ToString().Trim()))
                    {
                        sn = int.Parse(row["序号"].ToString().Trim());
                    }

                    if (!string.IsNullOrEmpty(row["路线名称"].ToString().Trim()))
                    {
                        lineid = row["路线名称"].ToString().Trim();

                        var d = bll.GetLineByName(lineid);
                        if (d == null)
                        {
                            sbtError.AppendFormat("[路线名称:{0}]不存在;", lineid);
                        }
                    }
                    if (!string.IsNullOrEmpty(row["队列号"].ToString().Trim()))
                    {
                        teamno = row["队列号"].ToString().Trim();
                    }

                    if (!string.IsNullOrEmpty(row["队名(6个字符以内)"].ToString().Trim()))
                    {
                        teamname = row["队名(6个字符以内)"].ToString().Trim();
                    }

                    if (!string.IsNullOrEmpty(row["单位名称"].ToString().Trim()))
                    {
                        company = row["单位名称"].ToString().Trim();
                    }


                    if (string.IsNullOrEmpty(row["性别"].ToString().Trim()))
                    {
                        sbtError.Append("[性别]不能为空;");
                    }

                    if (string.IsNullOrEmpty(row["身份证/护照"].ToString().Trim()))
                    {
                        sbtError.Append("[身份证/护照]不能为空;");
                    }
                    else
                    {
                        if (!System.Text.RegularExpressions.Regex.IsMatch(row["身份证/护照"].ToString().Trim(), @"^(^\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$"))
                        {
                            sbtError.Append("[身份证/护照]格式错误;");
                        }
                    }
                    if (!System.Text.RegularExpressions.Regex.IsMatch(row["手机号码"].ToString().Trim(), @"^[1]+[0-9]+\d{9}"))
                    {
                        sbtError.AppendFormat("[手机号码:{0}]格式错误;", row["手机号码"]);
                    }

                    if (!int.TryParse(row["年龄"].ToString().Trim(), out year))
                    {
                        sbtError.AppendFormat("[年龄:{0}]是否输入及正确;", row["年龄"]);
                    }
                    if (sbtError.Length > 0)
                    {
                        ViewBag.error = "-1";
                    }

                    tblmatchentity muser = new tblmatchentity();
                    muser.Pnov       = sn.ToString();
                    muser.Teamname   = teamname;
                    muser.Cardno     = row["身份证/护照"].ToString().Trim();
                    muser.Cardtype   = "1";
                    muser.Createtime = DateTime.Now;//.ToString("yyyy-MM-dd");
                    //muser.Leader = row["队员编号"].ToString().Trim() == "队长" ? 1 : 0;
                    muser.Match_Id    = "";
                    muser.Matchuserid = Guid.NewGuid().ToString();
                    muser.Mobile      = row["手机号码"].ToString().Trim();
                    muser.Nickname    = row["队员姓名"].ToString().Trim();
                    muser.Lineno      = lineid;
                    muser.LeaderM     = row["队员编号"].ToString().Trim() == "队长" ? "是" : "";
                    muser.Sexy        = row["性别"].ToString().Trim() == "男" ? 1 : 0;
                    muser.Age         = year;
                    muser.Mono        = row["是否健康"].ToString().Trim();
                    muser.Content     = HttpUtility.HtmlEncode(sbtError.ToString());

                    lstMatchusers.Add(muser);
                }

                return(View(lstMatchusers));
            }
            catch (Exception ex)
            {
                ILog log = LogManager.GetLogger(this.GetType());
                log.Error(ex);

                ViewBag.error = "-2";
                return(View());
            }
        }
Exemple #2
0
        public ActionResult beginimp(string matchid, string fid)
        {
            try
            {
                List <tblmatchentity> lstMatchusers = new List <tblmatchentity>();

                DataTable data = NpoiHelper.XlSToDataTable(System.IO.Path.Combine(Server.MapPath("~/upload/file"), fid), "TTBM", 0);

                GroupBll bll   = new GroupBll();
                tblmatch match = bll.GetMatchById(matchid);

                int    sn       = 0;
                string lineid   = "";
                string teamno   = "";
                string teamname = "";
                string company  = "";
                int    year     = 0;
                int    dm       = 0;

                foreach (DataRow row in data.Rows)
                {
                    year = 0;

                    if (string.IsNullOrEmpty(row["队员姓名"].ToString().Trim()))
                    {
                        continue;
                    }

                    //记录序号,以标记团队
                    if (!string.IsNullOrEmpty(row["序号"].ToString().Trim()))
                    {
                        sn = int.Parse(row["序号"].ToString().Trim());
                    }

                    if (!string.IsNullOrEmpty(row["路线名称"].ToString().Trim()))
                    {
                        var d = bll.GetLineByName(row["路线名称"].ToString().Trim());
                        lineid = d.Lineid;
                    }

                    if (!string.IsNullOrEmpty(row["队列号"].ToString().Trim()))
                    {
                        teamno = row["队列号"].ToString().Trim();
                        int.TryParse(teamno, out dm);
                    }
                    if (!string.IsNullOrEmpty(row["队名(6个字符以内)"].ToString().Trim()))
                    {
                        teamname = row["队名(6个字符以内)"].ToString().Trim();
                    }

                    if (!string.IsNullOrEmpty(row["单位名称"].ToString().Trim()))
                    {
                        company = row["单位名称"].ToString().Trim();
                    }

                    tblmatchentity muser = new tblmatchentity();
                    muser.Pnov     = sn.ToString();
                    muser.Teamname = teamname;
                    muser.Teamno   = dm;
                    muser.Cardno   = row["身份证/护照"].ToString().Trim();
                    muser.Cardtype = "1";
                    muser.Leader   = row["队员编号"].ToString().Trim() == "队长" ? 1 : 0;
                    muser.Match_Id = matchid;
                    muser.Mobile   = row["手机号码"].ToString().Trim();
                    muser.Nickname = row["队员姓名"].ToString().Trim();
                    muser.Lineno   = lineid;
                    muser.Sexy     = row["性别"].ToString().Trim() == "男" ? 1 : 0;
                    muser.Passwd   = company;
                    int.TryParse(row["年龄"].ToString().Trim(), out year);
                    muser.Age  = year;
                    muser.Mono = row["是否健康"].ToString().Trim();

                    lstMatchusers.Add(muser);
                }

                int        count = 0;
                TeamRegBll tbll  = new TeamRegBll();
                int        res   = tbll.ImpTeams(lstMatchusers, ref count);
                return(RedirectToAction("importsuccess", new { m = HttpUtility.UrlEncode(match.Match_name), s = HttpUtility.UrlEncode(string.Format("已成功导入{0}个队伍,{1}个队员信息", count, res)) }));
            }
            catch (Exception ex)
            {
                ILog log = LogManager.GetLogger(this.GetType());
                log.Error(ex);
                return(new EmptyResult());
            }
        }
Exemple #3
0
        public JsonResult ImpTeams(string matchid)
        {
            try
            {
                DataTable data = NpoiHelper.XlSToDataTable(@"C:\Work\Vki\MyDoc\MyFile\dx_dev\定向赛团体报名统计表.xlsx", "test", 0);

                if (data == null || data.Rows.Count < 1)
                {
                    return(RepReurnError("上传的文件中没有数据"));
                }

                StringBuilder sbtError = new StringBuilder();

                List <tblusers>      lstUsers      = new List <tblusers>();
                List <tblteams>      lstTeams      = new List <tblteams>();
                List <tblmatchusers> lstMatchusers = new List <tblmatchusers>();

                int    sn       = 0;
                string lineid   = "";
                string teamno   = "";
                string teamname = "";
                string company  = "";

                foreach (DataRow row in data.Rows)
                {
                    //记录序号,以标记团队
                    if (!string.IsNullOrEmpty(row["序号"].ToString().Trim()))
                    {
                        sn = int.Parse(row["序号"].ToString().Trim());
                    }

                    if (!string.IsNullOrEmpty(row["线路号"].ToString().Trim()))
                    {
                        lineid = row["线路号"].ToString().Trim();
                    }

                    if (!string.IsNullOrEmpty(row["队列号"].ToString().Trim()))
                    {
                        teamno = row["队列号"].ToString().Trim();
                    }

                    if (!string.IsNullOrEmpty(row["队名(6个字符以内)"].ToString().Trim()))
                    {
                        teamname = row["队名(6个字符以内)"].ToString().Trim();
                    }

                    if (!string.IsNullOrEmpty(row["公司名称"].ToString().Trim()))
                    {
                        company = row["公司名称"].ToString().Trim();
                    }

                    if (string.IsNullOrEmpty(row["队员编号"].ToString().Trim()))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(row["性别"].ToString().Trim()))
                    {
                        sbtError.Append("[性别]不能为空;");
                    }

                    if (string.IsNullOrEmpty(row["身份证/护照"].ToString().Trim()))
                    {
                        sbtError.Append("[身份证/护照]不能为空;");
                    }

                    if (!System.Text.RegularExpressions.Regex.IsMatch(row["手机号"].ToString().Trim(), @"^[1]+[0-9]+\d{9}"))
                    {
                        sbtError.AppendFormat("[手机号:{0}]格式错误;", row["手机号"]);
                    }

                    tblusers usr = new tblusers();
                    usr.cardtype = "1";
                    usr.Mobile   = row["手机号"].ToString().Trim();
                    usr.sexy     = row["性别"].ToString().Trim() == "男" ? "1" : "0";
                    usr.Status   = 1;
                    usr.userid   = Guid.NewGuid().ToString();
                    lstUsers.Add(usr);

                    tblteams tm = new tblteams();
                    tm.teamid     = Guid.NewGuid().ToString();
                    tm.Company    = "";
                    tm.Createtime = DateTime.Now;
                    tm.Eventid    = 1;
                    tm.Lineid     = lineid;
                    tm.match_id   = matchid;
                    tm.Status     = 1;
                    tm.Teamname   = teamname;
                    tm.Teamno     = teamno;
                    //tm.Userid
                    lstTeams.Add(tm);
                }
            }
            catch (Exception ex)
            {
                ILog log = LogManager.GetLogger(this.GetType());
                log.Error(ex);
                return(RepReurnError("导入过程中出现错误"));
            }

            return(RepReurnOK());
        }