コード例 #1
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            await popup.Show("轻触屏幕以查看图片信息");

            if (e.Parameter.GetType() == typeof(PostPic))
            {
                isLocal = false;
                Pic     = e.Parameter as PostPic;
                ID      = Pic.Id;
                BitmapImage bmp  = new BitmapImage();
                BitmapImage bmp0 = new BitmapImage();
                bmp.UriSource    = new Uri(Pic.Jpeg_url);
                bmp0.UriSource   = new Uri(Pic.Preview_url);
                img.Source       = bmp;
                img0.Source      = bmp0;
                img.ImageOpened += Img_ImageOpened;
                img0.Visibility  = Visibility.Visible;
                ring.Visibility  = Visibility.Visible;
            }
            else if (e.Parameter.GetType() == typeof(StorageFile))
            {
                file    = e.Parameter as StorageFile;
                isLocal = true;
                Stream stream = await file.OpenStreamForReadAsync();

                var         randomAccessStream = new InMemoryRandomAccessStream();
                var         outputStream       = randomAccessStream.GetOutputStreamAt(0);
                BitmapImage bmp = new BitmapImage();
                await RandomAccessStream.CopyAsync(stream.AsInputStream(), outputStream);

                await bmp.SetSourceAsync(randomAccessStream);

                img.Source      = bmp;
                ring.Visibility = Visibility.Collapsed;
                img0.Visibility = Visibility.Collapsed;
            }
        }
コード例 #2
0
    public void postClick(object sender, EventArgs e)
    {
        Control  button     = sender as Control;
        DateTime myDateTime = DateTime.UtcNow;

        if (PostPic.HasFile)
        {
            //Using a try statement allows us to output debugging problems.
            try
            {
                string filename = PostPic.FileName;
                PostPic.SaveAs(Server.MapPath("~/pictures/postpics/") + filename);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Upload status: The file could not be uploaded. The following error occured: " + ex.Message);
            }
        }

        if (Int32.Parse(Session["UserId"].ToString()) % 2 == 0)
        {
            String replyPost = HiddenThing.Value;
            if (replyPost != null && replyPost != "")             // this would be a comment on another post
            {
                int parentId = Int32.Parse(replyPost);
                //Connect to the database and check to see if user already exists, if it does, compare the password
                string        connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
                SqlConnection conn             = new SqlConnection(connectionString);
                string        query            = "insert into postt (ptext, ptimestamp, phascom, puserid, ppicfile, pcode, commentid) values (@posttext, @timestamp, @hascom, @userid, @picfile, @codetext, @parentid);";
                SqlCommand    com = new SqlCommand(query, conn);
                conn.Open();

                com.Parameters.AddWithValue("@posttext", WriteTextBox.Text);
                com.Parameters.AddWithValue("@timestamp", myDateTime.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                com.Parameters.AddWithValue("@parentid", parentId);                 // set the parent field of this post
                com.Parameters.AddWithValue("@hascom", 0);
                com.Parameters.AddWithValue("@picfile", PostPic.FileName);
                com.Parameters.AddWithValue("@codetext", WriteCodeBox.Text);
                com.Parameters.AddWithValue("@userid", Int32.Parse(Session["UserId"].ToString()));

                com.ExecuteNonQuery();

                // now update the parent posts hascom field to indicate it has a comment
                string updateQuery = "update postt set phascom=1 where postid=" + parentId + ";";
                com = new SqlCommand(updateQuery, conn);

                com.ExecuteNonQuery();
                conn.Close();
            }
            else
            {
                //Connect to the database and check to see if user already exists, if it does, compare the password
                string        connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
                SqlConnection conn             = new SqlConnection(connectionString);
                string        query            = "insert into postt (ptext, ptimestamp, phascom, puserid, ppicfile, pcode) values (@posttext, @timestamp, @hascom, @userid, @picfile, @codetext);";
                SqlCommand    com = new SqlCommand(query, conn);
                conn.Open();

                com.Parameters.AddWithValue("@posttext", WriteTextBox.Text);
                com.Parameters.AddWithValue("@timestamp", myDateTime.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                com.Parameters.AddWithValue("@hascom", 0);
                com.Parameters.AddWithValue("@picfile", PostPic.FileName);
                com.Parameters.AddWithValue("@codetext", WriteCodeBox.Text);
                com.Parameters.AddWithValue("@userid", Int32.Parse(Session["UserId"].ToString()));

                com.ExecuteNonQuery();

                conn.Close();
            }
        }
        else
        {
            //Connect to the database and check to see if user already exists, if it does, compare the password
            SqlConnection conn  = new SqlConnection(connectionString);
            string        query = "insert into postt (ptext, ptimestamp, phascom, pgroupid, ppicfile, pcode) values (@posttext, @timestamp, @hascom, @groupid, @picfile, @codetext);";
            SqlCommand    com   = new SqlCommand(query, conn);
            conn.Open();

            com.Parameters.AddWithValue("@posttext", WriteTextBox.Text);
            com.Parameters.AddWithValue("@timestamp", myDateTime.ToString("yyyy-MM-dd HH:mm:ss.fff"));
            com.Parameters.AddWithValue("@hascom", 0);
            com.Parameters.AddWithValue("@picfile", PostPic.FileName);
            com.Parameters.AddWithValue("@codetext", WriteCodeBox.Text);
            com.Parameters.AddWithValue("@groupid", Int32.Parse(Session["UserId"].ToString()));

            com.ExecuteNonQuery();

            conn.Close();
        }

        WriteTextBox.Text = "";
        WriteCodeBox.Text = "";
        Response.Redirect(Request.RawUrl);
    }