public void AddLotteryDataSingle(Lottery_step1 item) { //人工選號 if ( item.lottery_num_1 != null && item.lottery_num_2 != null && item.lottery_num_3 != null && item.lottery_num_4 != null && item.lottery_num_5 != null && item.winner != null ) { db.Lottery_step1.Add(item); db.SaveChanges(); } }
public ActionResult AddSingleData(List <int> lottery_num, string emp_id) { if (lottery_num != null) { if (lottery_num.Count == 5) { Lottery_step1 item = new Lottery_step1(); item.winner = emp_id; item.lottery_num_1 = lottery_num[0]; item.lottery_num_2 = lottery_num[1]; item.lottery_num_3 = lottery_num[2]; item.lottery_num_4 = lottery_num[3]; item.lottery_num_5 = lottery_num[4]; item.create_date = DateTime.Now; //1.判斷此人員是否已經有號碼 if (service.GetLotteryDataSingle(item.winner) != null) { var lotteryNum = service.GetLotteryLlist(item.winner).Count(); if (lotteryNum >= maxlottery) { //回傳錯誤,已達號碼上限 return(Json(new { status = "error", responseText = String.Format("此人員已有{0}組號碼產生!", maxlottery) })); } else { //有號碼,新增第2筆以上 //人工選號 service.AddLotteryDataSingle(item); return(Json(new { status = "success", responseText = String.Format("新增成功,第{0}筆", lotteryNum + 1) })); } } else { //沒號碼,新增一組號碼 //人工選號 service.AddLotteryDataSingle(item); return(Json(new { status = "success", responseText = "新增成功" })); } } } return(Json(new { status = "error", responseText = "數字錯誤!" })); }
public Lottery_step1 AddLotteryDataSingleRandom(string random_emp_id) { //隨機選號 Random rnd = new Random(Guid.NewGuid().GetHashCode()); List <int> randomList = Enumerable.Range(minNum, maxNum).OrderBy(q => rnd.Next()).Take(5).ToList(); randomList.Sort(); var lottery_item = new Lottery_step1() { lottery_num_1 = randomList[0], lottery_num_2 = randomList[1], lottery_num_3 = randomList[2], lottery_num_4 = randomList[3], lottery_num_5 = randomList[4], winner = random_emp_id }; db.Lottery_step1.Add(lottery_item); db.SaveChanges(); return(lottery_item); }
public void AddLotteryData() { //List<Lottery_step1> myLists = new List<Lottery_step1>(); for (int x = 1; x <= allCount; x++) {//電腦自動選號(多組、但是未確認有無重複) Random rnd = new Random(Guid.NewGuid().GetHashCode()); List <int> randomList = Enumerable.Range(minNum, maxNum).OrderBy(q => rnd.Next()).Take(5).ToList(); randomList.Sort(); var lottery_item = new Lottery_step1() { lottery_num_1 = randomList[0], lottery_num_2 = randomList[1], lottery_num_3 = randomList[2], lottery_num_4 = randomList[3], lottery_num_5 = randomList[4] }; //myLists.Add(lottery_item); db.Lottery_step1.Add(lottery_item); } db.SaveChanges(); }
public ActionResult AddSingleDataRandom(string random_emp_id) { //電腦自動選號(僅自動新增1筆) //判斷有無員工編號 if (random_emp_id != null) { //1.判斷此人員是否已經有號碼 if (service.GetLotteryDataSingle(random_emp_id) != null) { var lotteryNum = service.GetLotteryLlist(random_emp_id).Count(); if (lotteryNum >= maxlottery) { //回傳錯誤,已達號碼上限 return(Json(new { status = "error", responseText = String.Format("此人員已有{0}組號碼產生!", maxlottery) })); } else { //有號碼,新增第2筆以上 //電腦自動選號 Lottery_step1 lottery_item = new Lottery_step1(); lottery_item = service.AddLotteryDataSingleRandom(random_emp_id); return(Json(new { status = "success", responseText = lottery_item }, JsonRequestBehavior.AllowGet)); } } else { //沒號碼,新增一組號碼 //電腦自動選號 Lottery_step1 lottery_item = service.AddLotteryDataSingleRandom(random_emp_id); return(Json(new { status = "success", responseText = lottery_item }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { status = "error", responseText = "無此人員" }, JsonRequestBehavior.AllowGet)); } }
public Lottery_step1 GetLotteryDataSingle(string winner) { Lottery_step1 x = db.Lottery_step1.FirstOrDefault(s => s.winner == winner); return(x); }