protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { if (!string.IsNullOrEmpty(Session["UserId"] as string)) { LotteryWebService.DBService lws = new LotteryWebService.DBService(); LotteryWebService.TicketInfo ti = new LotteryWebService.TicketInfo(); ti = lws.GetTicketInfo(); if (ti.Status != 0) { Availability.InnerHtml = ti.TicketCount.ToString(); ProductPrice.InnerHtml = ti.TicketPrice.ToString(); } } else { Response.Redirect("Login.aspx", false); Context.ApplicationInstance.CompleteRequest(); } } } catch (Exception ex) { ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + ex.Message.Replace("\'", " ") + "');", true); } }
public TicketInfo GetTicketInfo() { try { ti = new TicketInfo(); SqlCon.Open(); using (SqlCmd = new SqlCommand("SELECT ((CASE WHEN User1 IS NULL THEN 1 ELSE 0 END)+(CASE WHEN User2 IS NULL THEN 1 ELSE 0 END)+(CASE WHEN User3 IS NULL THEN 1 ELSE 0 END)+(CASE WHEN User4 IS NULL THEN 1 ELSE 0 END)+(CASE WHEN User5 IS NULL THEN 1 ELSE 0 END)+(CASE WHEN User6 IS NULL THEN 1 ELSE 0 END)+(CASE WHEN User7 IS NULL THEN 1 ELSE 0 END)+(CASE WHEN User8 IS NULL THEN 1 ELSE 0 END)+(CASE WHEN User9 IS NULL THEN 1 ELSE 0 END)+(CASE WHEN User10 IS NULL THEN 1 ELSE 0 END)) AS TicketCount,TicketNo,TicketPrice,PriceAmount,CloseDate FROM TicketInfo ORDER BY TicketNo DESC", SqlCon)) { Sqldr = SqlCmd.ExecuteReader(); if (Sqldr.Read()) { ti.TicketCount = Sqldr.GetInt32(0); ti.TicketNo = Sqldr.GetValue(1).ToString(); ti.TicketPrice = Sqldr.GetInt32(2); ti.PriceAmount = Sqldr.GetInt32(3); ti.CloseDate = Sqldr.GetDateTime(4); ti.Status = 1; } SqlCon.Close(); return(ti); } } catch (Exception ex) { ti.Status = 0; ti.Error = ex.Message; if (SqlCon.State == ConnectionState.Open) { SqlCon.Close(); } return(ti); } }