コード例 #1
0
        protected Crime GetCrime(string id)
        {
            SqlCommand cmd = sqlConnection.CreateCommand();

            cmd.CommandType = CommandType.Text;

            cmd.CommandText = "Select * from crimes WHERE id=" + id;
            SqlDataReader sqlr = null;

            try {
                sqlr = cmd.ExecuteReader();
                if (sqlr.Read())
                {
                    Crime c = new Crime();
                    c.description = sqlr.GetString(5);
                    c.type        = sqlr.GetString(1);
                    c.location    = sqlr.GetString(2);
                    c.date        = sqlr.GetDateTime(3);
                    c.time        = sqlr.GetTimeSpan(4);
                    return(c);
                }
                else
                {
                    return(null);
                }
            }
            finally {
                sqlr?.Close();
                cmd.Dispose();
            }
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!Page.IsPostBack)
            {
                if (!String.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    this.TextBox1.Text = Request.QueryString["id"];
                    Crime crime = GetCrime(TextBox1.Text);
                    if (crime != null)
                    {
                        TextBox2.Text = crime.description;
                        TextBox3.Text = crime.location;
                        TextBox4.Text = crime.time.ToString();
                        TextBox5.Text = crime.date.ToString("dd.MM.yyyy");
                        ShowWitness(Request.QueryString["id"]);
                        ReloadSuspects();
                    }
                    else
                    {
                        // TODO crime not found
                    }
                }
                else
                {
                    // TODO bad params, show error
                }

                if (Session["policeName"] != null)
                {
                    PoliceName.Text = Session["policeName"].ToString();
                }
                else
                {
                    // Prevent opening police page if user isn't logged in
                    Response.Redirect("~/Login.aspx");
                }
            }
        }