protected void btnSubmit_Click(object sender, EventArgs e) { try { var mt = new MatchTicket { ID = MatchGuid }; mt.Single(); DateTime deadline; if (!string.IsNullOrEmpty(tbDeadline.Text.Trim()) && DateTime.TryParse(tbDeadline.Text.Trim(), out deadline)) { mt.Deadline = deadline; } else { mt.Deadline = mt.PlayTime.AddMonths(-2).AddDays(-7); } if (!string.IsNullOrEmpty(tbWaitingDeadline.Text.Trim()) && DateTime.TryParse(tbWaitingDeadline.Text.Trim(), out deadline)) { mt.WaitingDeadline = deadline; } else { mt.WaitingDeadline = mt.PlayTime.AddMonths(-1).AddDays(+7); } if (!string.IsNullOrEmpty(ddlAllowMemberClass.SelectedValue)) { mt.AllowMemberClass = Convert.ToInt16(ddlAllowMemberClass.SelectedValue); } else { mt.AllowMemberClass = null; } mt.IsActive = cbIsActive.Checked; mt.Remark = tbRemark.Text.Trim(); mt.ProductCode = ddlProductCode.SelectedValue; // Check whether MatchTicket Instance in DB if (mt.Any()) { mt.Update(); MatchTicket.Cache.RefreshCache(); ClientScript.RegisterClientScriptBlock(typeof(string), "succeed", "alert('更新成功');window.location.href=window.location.href", true); } else { mt.Create(); MatchTicket.Cache.RefreshCache(); ClientScript.RegisterClientScriptBlock(typeof(string), "succeed", "alert('添加成功');window.location.href = 'AdminMatchTicket.aspx'", true); } } catch (Exception ex) { ClientScript.RegisterClientScriptBlock(typeof(string), "failed", $"alert('{ex.Message}')", true); } }
private void InitForm() { if (MatchGuid != Guid.Empty) { var mt = new MatchTicket { ID = MatchGuid }; mt.Single(); // Get Match Info lblMatchGuid.Text = mt.ID.ToString(); if (mt.LeagueGuid.HasValue && !string.IsNullOrEmpty(mt.LeagueName)) lblLeagueName.Text = $"<em>{mt.LeagueName}</em>"; else lblLeagueName.Text = "无"; lblTeamName.Text = !string.IsNullOrEmpty(mt.TeamName) ? $"<em>{mt.TeamName}</em>" : "无"; lblIsHome.Text = mt.IsHome ? "主场" : "客场"; lblRound.Text = mt.Round?.ToString() ?? "/"; lblPlayTime.Text = $"<em>{mt.PlayTimeLocal.ToString("yyyy-MM-dd HH:mm")}</em>"; lblResultInfo.Text = $"<em>{mt.ResultInfo}</em>"; // Get Ticket Info ddlProductCode.SelectedValue = mt.ProductCode; tbDeadline.Text = mt.Deadline.ToString("yyyy-MM-dd"); tbWaitingDeadline.Text = mt.WaitingDeadline.ToString("yyyy-MM-dd"); ddlAllowMemberClass.SelectedValue = mt.AllowMemberClass?.ToString() ?? string.Empty; cbIsActive.Checked = mt.IsActive; tbRemark.Text = mt.Remark; //Bind MatchOrder data of this MatchTicket BindItemData(); //gvMatchOrder.DataSource = mt.OrderTicketList; //gvMatchOrder.DataBind(); } else { ClientScript.RegisterClientScriptBlock(typeof(string), "succeed", "alert('选定的比赛不存在');window.location.href = 'AdminMatchTicket.aspx'", true); } }