public ActionResult ChangeHeadImage()
        {
            string username = Session["username"] as string;
            HttpPostedFileBase file = Request.Files["picture"];
            if (file != null)
            {
                string filename = Path.GetFileName(file.FileName);
                string[] names = filename.Split('.');
                string type = names[1];
                string newfilename = username + "." + type;

                OracleConnection conn = new ConnectTheDB().getDb();

                try
                {
                    conn.Open();
                    string updateStr = "update fake_user "
                          + " set headimg = '"
                          + newfilename
                          + "' where username = '******'";
                    OracleCommand cmd = new OracleCommand(updateStr, conn);
                    int insertedLines = cmd.ExecuteNonQuery();
                    Session.Add("headimg", newfilename);
                    conn.Close();
                    conn.Dispose();
                    return Upload(0, newfilename, file);

                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                    return RedirectToAction("UserPage", "Account");
                }

            }
            else
            {
                Debug.WriteLine("上传失败");
                return RedirectToAction("UserPage", "Account");
            }
        }
        //GET: \PhotoComment\PhotoShow
        //点击照片后跳到这张照片的展示页面,下面是所有评论的展示
        public ActionResult ReadComment()
        {
            string photoId;
            OracleConnection conn = new ConnectTheDB().getDb();
            conn.Open();
            if (Request.Form["photoid"] != null)
            {
                photoId = Request.Form["photoid"];
                Session.Add("currentPhotoId", photoId);
            }
            else
            {
                photoId = Session["currentPhotoId"] as string;
            }
            if (Request.Form["state"] != null)
            {
                string userName = Session["username"] as string;
                //@@@@
                Debug.WriteLine(userName);
                string photoComment_date = DateTime.Now.ToString();
                //@@@@
                Debug.WriteLine(photoComment_date);
                photoId = Session["currentPhotoId"] as string;
                //@@@@
                Debug.WriteLine(photoId);
                string content = Request.Form["state"];
                //@@@@
                Debug.WriteLine(content);
                try
                {
                    string selectStr = "select photoCommentId from photoComment";
                    //@@@@
                    Debug.WriteLine("lalala+4");
                    OracleCommand cmd = new OracleCommand(selectStr, conn);
                    OracleDataReader dr2 = cmd.ExecuteReader();
                    //@@@@
                    Debug.WriteLine("lalala+5");
                    int temp = 0;
                    while (dr2.Read())
                    {
                        if (Convert.ToInt32(dr2[0]) > temp)
                        {
                            temp = Convert.ToInt32(dr2[0]);
                        }
                    }
                    temp++;
                    string photoCommentId = temp.ToString();
                    //@@@@
                    Debug.WriteLine(photoCommentId);
                    string insertStr = "insert into photoComment(photoCommentId, photoId, content, photoComment_date, userName) values('"
                        + photoCommentId + "','"
                        + photoId + "','"
                        + content + "','"
                        + photoComment_date + "','"
                        + userName + "')";
                    //@@@@
                    Debug.WriteLine("lalala+7");
                    OracleCommand cmd2 = new OracleCommand(insertStr, conn);
                    //@@@@
                    Debug.WriteLine("lalala+8");
                    int insertedLines = cmd2.ExecuteNonQuery();
                    //@@@@
                    Debug.WriteLine("lalala+9");
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("向数据库写入数据出错!");
                }
            }
            try
            {

                string selectStr = "select * from photoComment where photoId = "+ photoId ;
                OracleCommand cmd = new OracleCommand(selectStr, conn);
                OracleDataReader dr = cmd.ExecuteReader();
                List<photoComment> pc = new List<photoComment>();
                while (dr.Read())                        //逐行读取数据库中的记录
                {
                    photoComment pcItem = new photoComment();
                    pcItem.photoCommentId = dr.GetString(0);
                    pcItem.photoId = dr.GetString(1);
                    pcItem.content = dr.GetString(2);
                    pcItem.photoComment_date = dr.GetString(3);
                    pcItem.userName = dr.GetString(4);
                    pc.Add(pcItem);
                }
                ViewData["photoId"] = photoId;
                ViewData["comment"] = pc;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("读取相册评论出错!");
            }
            string selectStr1 = "select * from photo where photoid=" + photoId;
            OracleCommand cmd1 = new OracleCommand(selectStr1, conn);
            OracleDataReader dr1 = cmd1.ExecuteReader();
            dr1.Read();
            ViewData["photoAddress"] = dr1["photoaddress"].ToString();

            //@@@@
            Debug.WriteLine(Request.Form["state"]);

            conn.Close();
            return View();
        }
        public ActionResult test()
        {
            OracleConnection conn = new ConnectTheDB().getDb();

            try
            {
                conn.Open();

                string insertStr = "insert into photoComment(photoCommentId, photoId, content, photoComment_date, userName) values('2', '1', '么么哒', '2015-07-16', 'lalala')";
                OracleCommand cmd1 = new OracleCommand(insertStr, conn);
                cmd1.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("向数据库写入数据出错!");
            }

            try
            {
                string selectStr = "select * from photoComment where photoId = '1'";
                OracleCommand cmd2 = new OracleCommand(selectStr, conn);
                OracleDataReader dr = cmd2.ExecuteReader();
                List<photoComment> pc = new List<photoComment>();

                while (dr.Read())                        //逐行读取数据库中的记录
                {
                    photoComment pcItem = new photoComment();
                    pcItem.photoCommentId = dr.GetString(0);
                    pcItem.photoId = dr.GetString(1);
                    pcItem.content = dr.GetString(2);
                    pcItem.photoComment_date = dr.GetString(3);
                    pcItem.userName = dr.GetString(4);
                    pc.Add(pcItem);
                }
                ViewData["photoId"] = 1;
                ViewData["comment"] = pc;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("读取相册评论出错!");
            }

            conn.Close();
            conn.Dispose();

            return View();
        }
        //发表新的评论同时也要更新话题的最新时间
        public ActionResult SaveComment(string comment)
        {
            Debug.WriteLine("new commend is " + comment);
            string username = Session["username"] as string;
            OracleConnection conn = new ConnectTheDB().getDb();
            try
            {
                conn.Open();
                string selectStr = "select count (topicid) from topiccomment";
                OracleCommand cmd = new OracleCommand(selectStr, conn);
                OracleDataReader dr = cmd.ExecuteReader();
                //Debug.WriteLine("获取数据成功!");
                dr.Read();
                int num = dr.GetInt32(0);
                string day = System.DateTime.Now.ToString("yyyy-MM-dd").Replace("-", "");
                string hour = System.DateTime.Now.ToString("HH:mm:ss").Replace(":", "");
                long time = Int64.Parse(day + hour);                     //获得当前的时间
                int viewnum = 0;
                Debug.WriteLine("count is " + num + " time is " + time);
                //string insertStr = "insert into test(id) values(500)";
                selectStr = "insert into topiccomment (topiccommentid,topicid,content,topiccomment_date,username) values(" + num + ","
                    + topicid + ",'" + comment + "'," + time + ",'" + username + "')";
                OracleCommand c = new OracleCommand(selectStr, conn);
                int insertedLines = c.ExecuteNonQuery();
                selectStr = "update topic set topic_date="+time+"where topicid="+topicid;
                OracleCommand u = new OracleCommand(selectStr, conn);
                insertedLines = u.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("读取出错!");
            }
            finally
            {
                conn.Close();
            }

            Response.Redirect("/Topic/selecttopic");
            return View();
        }
 // GET: Topic列表
 public ActionResult Index(string change)
 {
     Debug.WriteLine("change to "+change);
     int page=0;
     if (change == null)
     {
         page = 1;
     }else
     {
           page = Int32.Parse(change);
     }
     OracleConnection conn = new ConnectTheDB().getDb();
     try
     {
         conn.Open();
         string selectStr = "select * from Topic order by topic_date desc ";
         OracleCommand cmd = new OracleCommand(selectStr, conn);
         OracleDataReader dr = cmd.ExecuteReader();
         Debug.WriteLine("获取数据成功!");
         List<Topic> topics = new List<Topic>();
         int count=0;//用于记录当前的条目
         while (dr.Read())//获得数据库的topic然后传回给view
         {
             if (count >= pagecount * (page - 1)&& count < pagecount * page)//用于分页,每页十个条目
             {
                 Topic topic = new Topic();
                 topic.Topic_id = dr.GetString(0);
                 topic.Topic_name = dr.GetString(5);
                 topic.Topic_Content = dr.GetString(2);
                 topic.Topic_view = dr.GetInt32(4);
                 topic.username = dr.GetString(1);
                 topic.showdate = getrealtime(dr.GetInt64(3));
                 topics.Add(topic);
                // Debug.WriteLine(dr.GetString(0) + "," + dr.GetString(1) + "," + dr.GetString(2));
             }
             count++;
         }
         int allpages = 0;
         if (count == 0)
         {
             allpages = 1;
         }
         else if (count % pagecount == 0)
         {
             allpages = count / pagecount;
         }
         else
         {
             allpages = count / pagecount + 1;
         }
         ViewData["topics"] = topics;
         ViewData["current"] = page;
         ViewData["pages"] = allpages;
     }
     catch (Exception ex)
     {
         Debug.WriteLine("读取出错!");
     }
     finally
     {
         conn.Close();
     }
     return View();
 }
        //进入一个话题
        public ActionResult selecttopic(string id,string change)
        {
            Debug.WriteLine("change to " + change);
            OracleConnection conn = new ConnectTheDB().getDb();
            conn.Open();

            int page = 0;
            if (change == null)
            {
                page = 1;
            }
            else
            {
                page = Int32.Parse(change);
            }
            //如果是id=null的话,那么就属于发布评论,view数不加1
            if (id == null)
            {
                id = topicid;
            }
            else//属于新的view,要更新viewnum
            {
                string updateStr = "update topic set viewnum=viewnum+1 where topicid="+id+"";
                OracleCommand c = new OracleCommand(updateStr, conn);
                int insertedLines = c.ExecuteNonQuery();
                topicid = id;
            }

            try
            {
                //获得当前的话题
                string selectStr = "select * from Topic where topicid= '"+topicid+"'";
                OracleCommand cmd = new OracleCommand(selectStr, conn);
                OracleDataReader dr = cmd.ExecuteReader();
                Debug.WriteLine("获取数据成功!");
                while (dr.Read())//获得数据库的topic然后传回给view
                {
                    ViewData["topicname"] = dr.GetString(1);
                    ViewData["topiccontent"] = dr.GetString(2);
                    ViewData["topicdate"] = getrealtime(dr.GetInt64(3));
                }
                //获得当前的话题评论
                selectStr = "select TopicComment.content,topiccomment_date,TopicComment.username,headimg from TopicComment,fake_user where topicid='" + topicid + "'and fake_user.username=topiccomment.username order by topiccomment_date desc";
                OracleCommand oc = new OracleCommand(selectStr, conn);
                dr = oc.ExecuteReader();
                Debug.WriteLine("获取数据成功!");
                List<TopicComment> tcs = new List<TopicComment>();
                int count = 0;//用于记录当前的条目
                while (dr.Read())//获得数据库的topic然后传回给view
                {
                    if (count >= pagecount * (page - 1) && count < pagecount * page)//用于分页,每页十个条目
                    {
                        TopicComment tc = new TopicComment();
                        tc.content = dr.GetString(0);
                        //转化成为正常的时间格式
                        long t= dr.GetInt64(1);
                        tc.showdate = getrealtime(t);
                        tc.username = dr.GetString(2);
                        tc.userimg = dr.GetString(3);
                        tcs.Add(tc);
                        //Debug.WriteLine(dr.GetString(2) + "," + dr.GetInt64(3) + "," + dr.GetString(4));
                    }
                    count++;

                }
                ViewData["topicscommend"] = tcs;
                int allpages = 0;
                if (count==0)
                {
                    allpages = 1;
                }
                else if (count % pagecount == 0)
                {
                    allpages = count / pagecount;
                }else
                {
                    allpages = count / pagecount + 1;
                }
                ViewData["current"] = page;
                ViewData["pages"] = allpages;
            }
            catch (Exception ex)
            {
                Debug.WriteLine("读取出错!");
            }
            finally
            {
                conn.Close();
            }
            return View();
        }
 //发表新的评论同时也要更新话题的最新时间
 public ActionResult SaveMessage(string comment)
 {
     Debug.WriteLine("new commend is " + comment);
     //usrname session获得
     string username = Session["username"] as string;
     OracleConnection conn = new ConnectTheDB().getDb();
     try
     {
         conn.Open();
         string day = System.DateTime.Now.ToString("yyyy-MM-dd").Replace("-", "");
         string hour = System.DateTime.Now.ToString("HH:mm:ss").Replace(":", "");
         long time = Int64.Parse(day + hour);                     //获得当前的时间
         //string insertStr = "insert into test(id) values(500)";
         string selectStr = "insert into leavemessage (touser,fromuser,message,message_date) values('" + touser + "','"
             + username + "','" + comment + "'," + time + ")";
         OracleCommand c = new OracleCommand(selectStr, conn);
         int insertedLines = c.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         Debug.WriteLine("读取出错!");
     }
     finally
     {
         conn.Close();
     }
     Response.Redirect("/LeaveMessage/Index");
     return View();
 }
 // GET: LeaveMessage
 public ActionResult Index(string change)
 {
     //session for current friend
     string username = "******";
     touser = username;
     Debug.WriteLine("change to " + change);
     int page = 0;
     if (change == null)
     {
         page = 1;
     }
     else
     {
         page = Int32.Parse(change);
     }
     OracleConnection conn = new ConnectTheDB().getDb();
     try
     {
         conn.Open();
         string selectStr = "select fromuser,message,message_date,headimg from leavemessage,fake_user where username=fromuser and touser='******' order by message_date desc ";
         OracleCommand cmd = new OracleCommand(selectStr, conn);
         OracleDataReader dr = cmd.ExecuteReader();
         Debug.WriteLine("获取数据成功!");
         List<LeaveM> Messages = new List<LeaveM>();
         int count = 0;//用于记录当前的条目
         while (dr.Read())//获得数据库的topic然后传回给view
         {
             if (count >= pagecount * (page - 1) && count < pagecount * page)//用于分页,每页十个条目
             {
                 LeaveM Message = new LeaveM();
                 Message.fromU = dr.GetString(0);
                 Message.message = dr.GetString(1);
                 Message.showdate = getrealtime(dr.GetInt64(2));
                 Message.userimg = dr.GetString(3);
                 Messages.Add(Message);
                 Debug.WriteLine("image is "+Message.userimg);
             }
             count++;
         }
         int allpages = 0;
         if (count == 0)
         {
             allpages = 1;
         }
         else if (count % pagecount == 0)
         {
             allpages = count / pagecount;
         }
         else
         {
             allpages = count / pagecount + 1;
         }
         ViewData["Messages"] = Messages;
         ViewData["current"] = page;
         ViewData["pages"] = allpages;
     }
     catch (Exception ex)
     {
         Debug.WriteLine("读取出错!");
     }
     finally
     {
         conn.Close();
     }
     return View();
 }