/// <summary> /// 新增赛事 /// </summary> /// <param name="ent"></param> /// <returns></returns> public int AddMatch(tblmatch ent) { using (var db = new BFdbContext()) { return(db.Insert <tblmatch>(ent)); } }
/// <summary> /// 删除赛事 /// </summary> /// <param name="ids"></param> /// <returns></returns> public int DeleteMatch(List <string> ids) { using (var db = new BFdbContext()) { int res = 0; using (var tx = db.BeginTransaction()) { try { foreach (string id in ids) { tblmatch ent = db.tblmatch.FirstOrDefault(p => p.Match_id == id); ent.Status = "2"; db.TUpdate <tblmatch>(ent); } db.SaveChanges(); tx.Commit(); } catch (Exception ex) { tx.Rollback(); throw ex; } } return(res); } }
/// <summary> /// 更新赛事 /// </summary> /// <param name="ent"></param> /// <returns></returns> public int EditMatch(tblmatch ent) { using (var db = new BFdbContext()) { tblmatch match = db.tblmatch.FirstOrDefault(p => p.Match_id == ent.Match_id); match.Match_name = ent.Match_name; match.Content = ent.Content; match.Area1 = ent.Area1; match.Area2 = ent.Area2; match.Date1 = ent.Date1; match.Date2 = ent.Date2; match.Date3 = ent.Date3; match.Date4 = ent.Date4; match.Pic1 = ent.Pic1; match.Pic2 = ent.Pic2; match.Status = ent.Status; return(db.Update <tblmatch>(match)); } }
public ActionResult Create(FormCollection fc) { var model = new tblmatch(); model.Match_id = Guid.NewGuid().ToString(); model.Match_name = fc["Match_name"].ToString(); model.Content = fc["Content"].ToString(); model.Area1 = fc["Area1"].ToString(); model.Area2 = fc["Area2"].ToString(); if (fc["Date1"] != null) { model.Date1 = DateTime.Parse(fc["Date1"].ToString()); } if (fc["Date2"] != null) { model.Date2 = DateTime.Parse(fc["Date2"].ToString()); } if (fc["Date3"] != null) { model.Date3 = DateTime.Parse(fc["Date3"].ToString()); } if (fc["Date4"] != null) { model.Date4 = DateTime.Parse(fc["Date4"].ToString()); } string filename = ""; // 上传文件 HttpFileCollectionBase files = Request.Files; HttpPostedFileBase file = files["Pic1"]; if (file != null) { filename = file.FileName.Substring(file.FileName.LastIndexOf(".") + 1); if ((filename.ToUpper() == "PNG" || filename.ToUpper() == "JPG") && file.ContentLength / 1024 < 2000) { string path = Server.MapPath("~/UploadFiles/"); filename = "productfile_" + DateTime.Now.ToString("yyyyMMddHHmmss") + "." + filename; file.SaveAs(path + filename); } else { ViewBag.ErrorMsg = "<font color='red'>只能上传PNG或JPG格式的图片且大小不超过2M</font>"; return(View()); } } else { ViewBag.ErrorMsg = "<font color='red'>获取文件错误</font>"; return(View(model)); } model.Pic1 = filename; //------ HttpPostedFileBase file2 = files["Pic2"]; if (file2 != null) { string filename2 = file2.FileName.Substring(file2.FileName.LastIndexOf(".") + 1); if ((filename2.ToUpper() == "PNG" || filename2.ToUpper() == "JPG") && file2.ContentLength / 1024 < 2000) { string path = Server.MapPath("~/UploadFiles/"); filename = "thumbnailfile_" + DateTime.Now.ToString("yyyyMMddHHmmss") + "." + filename2; file2.SaveAs(path + filename); } else { ViewBag.ErrorMsg = "<font color='red'>只能上传PNG或JPG格式的图片且大小不超过2M</font>"; return(View()); } model.Pic2 = filename; } model.Status = fc["optStatus"].ToString(); var bll = new MatchBll(); try { bll.AddMatch(model); } catch (ValidException ex) { this.ModelState.AddModelError(ex.Name, ex.Message); return(View(model)); } return(this.RefreshParent()); }
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()); } }
/// <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()); } }