| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- using BizCom;
- using SQLData;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Web;
- using Utils;
- using Utils.ImageUtils;
- using Utils.Serialization;
- namespace SiteCore.Handler
- {
- public partial class app
- {
- #region 贴子
- public void get_index_assnpost()
- {
- DataStruct dStruct = GetPostStruct();
- List<string> lw = new List<string>();
- string key = GetPostString("key");
- if (key.Length > 0) lw.Add(string.Format("name like '%{0}%'", key));
- lw.Add("isoffice=1");
- dStruct.Order = "isnull(lastreplytime,addtime) desc,addtime desc";
- dStruct.MainWhere = string.Join(" and ", lw.ToArray());
- dStruct.Fileds = "id,assnid,assnname,assnlogo,userpic,username,addtime,lastreplytime,title,isoffice,viewnum,replynum,images,sex";
- DataTable dt = WebCache.GetData("view_assnpost", dStruct);
- conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
- }
- public void get_assnpost()
- {
- //if (UrlPostParmsCheck("aid"))
- //{
- DataStruct dStruct = GetPostStruct();
- List<string> lw = new List<string>();
- //int id = 8;
- int id = GetPostInt("aid");
- if (id > 0)
- {
- lw.Add("AssnID=" + id);
- }
- string key = GetPostString("key");
- if (key.Length > 0) lw.Add(string.Format("name like '%{0}%'", key));
- dStruct.Order = "istop desc,isnull(lastreplytime,addtime) desc,addtime desc";
- dStruct.MainWhere = string.Join(" and ", lw.ToArray());
- dStruct.Fileds = "id,describe,userpic,username,addtime,lastreplytime,title,istop,isoffice,viewnum,replynum,images,sex";
- DataTable dt = WebCache.GetData("view_assnpost", dStruct);
- conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
- return;
- //}
- //conError("错误的参数");
- }
- public void get_assnpostdetail()
- {
- UserObj uo = GetUserEntity();
- if (uo == null) return;
- int uid = uo.userid;
- if (UrlPostParmsCheck("pid"))
- {
- int id = GetPostInt("pid");
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("select id,username,userpic,sex,con,ispc,addtime,istop,title,isoffice,viewnum,replynum,images,votetype,votepernum,expiretime,PostTypeID as ptype, '§' as vitems,(select count(0) from s_assnpostvoteperson where postid=view_assnpost.id) as vnum,(select voteids from s_assnpostvoteperson where postid={0} and userid={1}) as vids from view_assnpost where id={0} ;", id, uid);
- sql.AppendFormat("select * from s_assnpostvote where postid={0} order by id asc;",id);
- sql.AppendFormat(";", id, uid);
- DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
- DataTable dt = ds.Tables[0];
- string con = Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt);
- string items = Utils.Serialization.JsonString.DataTable2LowerAjaxJson(ds.Tables[1]);
- //string voteids = "";
- //if(ds.Tables[2]!=null && ds.Tables[2].Rows.Count > 0)
- //{
- // voteids = ds.Tables[2].Rows[0]["voteids"].ToString();
- //}
- con = con.Replace("\"§\"", items);
- //if (dt != null && dt.Rows.Count > 0)
- // dt.Rows[0]["vitems"] = items;
- //lw.Add("ID=" + id);
- //dStruct.Order = "addtime desc";
- //dStruct.MainWhere = string.Join(" and ", lw.ToArray());
- //dStruct.Fileds = "id,assnid,assnname,assnlogo,username,userpic,sex,con,addtime,istop,title,isoffice,viewnum,replynum,images,(select count(0) from s_assnpostvoteperson where postid=view_assnpost.id) as vnum";
- //DataTable dt = WebCache.GetData("view_assnpost", dStruct);
- conGridJson(1,con);
- return;
- }
- conError("错误的参数");
- }
- public void upload_assnpost_img()
- {
- UserObj uo = GetUserEntity();
- if (uo == null) return;
- int uid = uo.userid;
- string tag = GetPostString("tag");
- HttpPostedFile postFile = null;
- List<string> lstFile = new List<string>();
- int c = con.Request.Files.Count;
- if (c > 0)
- {
- for (int i = 0; i < c; i++)
- {
- string errMsg = "";
- postFile = con.Request.Files[i];
- if (!ImageHandler.CheckImage(postFile, out errMsg))
- {
- conError(errMsg);
- return;
- }
- string fileName = uid + DateTime.Now.ToFileTimeUtc() + ".jpg";
- string sourceExt = Path.GetExtension(postFile.FileName);
- if (sourceExt == ".gif")
- {
- fileName = uid + DateTime.Now.ToFileTimeUtc() + ".gif";
- postFile.SaveAs(webConfig.assnPath + "\\post\\" + fileName);
- }
- else
- {
- string saveFile = Path.Combine(webConfig.assnPath + "\\post", fileName);
- string result = "";
- using (System.Drawing.Image imgThumb = System.Drawing.Image.FromStream(postFile.InputStream))
- {
- result = ImageMaker.ToThumbnailImages(imgThumb, saveFile, 800, "", 9, 3);
- }
- }
- lstFile.Add(fileName);
- }
- }
- string fs = "";
- if (lstFile.Count > 0) fs = string.Join(",", lstFile.ToArray());
- conSuccess("上传成功", "{\"fname\":\"" + fs + "\"}");
- }
- public void top_assnpost()
- {
- UserObj uo = GetUserEntity();
- if (uo == null) return;
- int uid = uo.userid;
- if (UrlPostParmsCheck("pid,istop"))
- {
- int pid = GetPostInt("pid");
- int st = GetPostInt("istop");
- SAssnPost.UpdateIsTop(pid, st);
- conSuccess("操作完成!");
- return;
- }
- conError("错误的参数");
- }
- public void ins_assnpost()
- {
- UserObj uo = GetUserEntity();
- if (uo == null) return;
- int uid = uo.userid;
- if (UrlPostParmsCheck("title,con"))
- {
- int pid = GetPostInt("pid");
- int aid = GetPostInt("aid");
- string title = GetPostString("title");
- string con = GetPostString("con");
- int ptype = GetPostInt("ptype");
- int vtype = GetPostInt("vtype");
- string vitems = GetPostString("vitems");
- int vpn = GetPostInt("vpernum");
- string expire = GetPostString("expiretime");
- con = con.Replace("\r\n", "<br>").Replace("\n", "<br>");
- con = con.Replace(" ", " ");
- string images = GetPostString("images").TrimEnd(',');
- SAssnPost entity;
- if (pid > 0)
- {
- entity = SAssnPost.Get(pid, uid);
- entity.UpdateTime = DateTime.Now;
- }
- else {
- entity = new SAssnPost();
- entity.AddTime = DateTime.Now;
- entity.UserID = uid;
- entity.AssnID = aid;
- entity.viewNum = 2;
- }
- if (vitems != "")
- {
- entity.voteItem = vitems;
- entity.voteType = vtype;
- entity.PostTypeID = ptype;
- entity.votePerNum = vpn;
- entity.ExpireTime = Convert.ToDateTime(expire);
- }
- entity.Title = title;
- entity.Describe = con.Substring(0, 45);
- entity.Con = con;
- entity.Images = images.TrimEnd(',');
- string pub = GetPostString("isoffice");
- if (pub != "") entity.isOffice = Convert.ToBoolean(pub);
- else entity.isOffice = true;
- //entity.imgNum = images.Split(',').Length;
- StringBuilder sql = new StringBuilder();
- if (pid > 0)
- {
- entity.Update();
- if (vitems != "")
- {
- string[] vArr = vitems.Split('№');
- string[] tArr;
- for (int i = 0; i < vArr.Length; i++)
- {
- tArr = vArr[i].Split('§');
- if(tArr[0]=="") sql.AppendFormat("insert into s_assnpostvote(postid,itemname) values({0},'{1}') ;", entity.ID, tArr[1]);
- else sql.AppendFormat("update s_assnpostvote set itemname='{2}' where postid={0} and id={1};", entity.ID, tArr[0], tArr[1]);
- //sql.AppendFormat("update s_assnpostvote set itemname='{2}' where postid={0} and id={1};", entity.ID, tArr[0], tArr[1]);
- }
- if (sql.Length > 0) DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
- }
- conSuccess("己修改贴子!");
- }
- else
- {
- entity.Create();
- if (vitems != "")
- {
- string[] vArr = vitems.Split('№');
- string[] tArr;
- for (int i = 0; i < vArr.Length; i++)
- {
- //tArr = vArr[i].Split('§');
- sql.AppendFormat("insert into s_assnpostvote(postid,itemname) values({0},'{1}') ;", entity.ID, vArr[i]);
- //if (tArr[0] == "") sql.AppendFormat("insert into s_assnpostvote(postid,itemname) values({0},'{1}') ;", entity.ID, tArr[0]);
- //else sql.AppendFormat("update s_assnpostvote set itemname='{2}' where postid={0} and id={1};", entity.ID, tArr[0], tArr[1]);
- //sql.AppendFormat("update s_assnpostvote set itemname='{2}' where postid={0} and id={1};", entity.ID, tArr[0], tArr[1]);
- }
- if (sql.Length > 0) DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
- }
-
- conSuccess("发贴成功!");
- }
- return;
- }
- conError("错误的参数");
- }
- public void ins_assnpostvote()
- {
- UserObj uo = GetUserEntity();
- if (uo == null) return;
- int uid = uo.userid;
- if (UrlPostParmsCheck("pid,vids"))
- {
- int pid = GetPostInt("pid");
- string vids = GetPostString("vids");
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("if (select count(0) from s_assnpostvoteperson where postid={0} and userid={1})<1 begin ", pid, uid);
- sql.AppendFormat("insert into s_assnpostvoteperson(userid,postid,voteids,addtime)values({0},{1},'{2}',getdate()) ;", uid,pid,vids);
- sql.AppendFormat("update s_assnpostvote set votenum=votenum+1 where postid={0} and id in ({1}) ;", pid, vids);
- sql.Append(" end ");
- DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
- //SAssnPostVotePerson entity = new SAssnPostVotePerson();
- //entity.UserID = uid;
- //entity.VoteIDs = vids;
- //entity.AddTime = DateTime.Now;
- //entity.Create();
- conSuccess("己投票!");
- return;
- }
- conError("错误的参数");
- }
- public void del_assnpost()
- {
- UserObj uo = GetUserEntity();
- if (uo == null) return;
- int uid = uo.userid;
- if (UrlPostParmsCheck("pid"))
- {
- int pid = GetPostInt("pid");
- //sp_del_assnpost
- SqlParameter[] sqlParameter ={
- new SqlParameter("@pid", SqlDbType.Int, 4),
- new SqlParameter("@uid", SqlDbType.Int, 4),
- new SqlParameter("@result",SqlDbType.NVarChar,100)};
- sqlParameter[0].Value = pid;
- sqlParameter[1].Value = uid;
- sqlParameter[2].Direction = ParameterDirection.Output;
- SAssnPost.ExecuteNonQueryStore("sp_del_assnpost", sqlParameter);
- string result = sqlParameter[2].Value.ToString();
- if (result.Substring(0, 2) == "0|")
- {
- conError(result.Split('|')[1]);
- }
- else
- {
- string c = result.Split('|')[1];
- conSuccess(c);
- }
- return;
- }
- conSuccess("错误的参数");
- }
- public void get_assnpostreply()
- {
- if (UrlPostParmsCheck("pid"))
- {
- DataStruct dStruct = GetPostStruct();
- List<string> lw = new List<string>();
- int id = GetPostInt("pid");
- //id = 92;re
- int sort = GetPostInt("sort");
- if (id > 0)
- {
- lw.Add("PostID=" + id);
- if (sort == 1) dStruct.Order = "addtime desc";
- else dStruct.Order = "addtime asc";
- dStruct.MainWhere = string.Join(" and ", lw.ToArray());
- dStruct.Fileds = "id,username,userpic,con,images,addtime,likenum,sex,STUFF((select top 2 '§'+username+'№'+convert(varchar(20),addtime,120)+'№'+convert(varchar(1),sex)+'№'+con from view_assnpostreply as b where b.parentid=view_assnpostreply.id order by AddTime desc for xml path('')),1,1,'') as items";
- DataTable dt = WebCache.GetData("view_assnpostreply", dStruct);
- conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
- return;
- }
- }
- conError("错误的参数");
- }
- public void get_assnpostreplysec()
- {
- if (UrlPostParmsCheck("postid,rid"))
- {
- DataStruct dStruct = GetPostStruct();
- List<string> lw = new List<string>();
- int postid = GetPostInt("postid");
- int rid = GetPostInt("rid");
- //id = 92;
- int sort = GetPostInt("sort");
- lw.Add("PostID=" + postid);
- lw.Add("parentid=" + rid);
- //lw.Add("ParentID=0");
- if (sort == 1) dStruct.Order = "addtime desc";
- else dStruct.Order = "addtime asc";
- dStruct.MainWhere = string.Join(" and ", lw.ToArray());
- dStruct.Fileds = "id,username,parentid as pid,con,addtime";
- DataTable dt = WebCache.GetData("view_assnpostreply", dStruct);
- conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
- return;
- }
- conError("错误的参数");
- }
- public void ins_assnpostreply()
- {
- UserObj uo = GetUserEntity();
- if (uo == null) return;
- int uid = uo.userid;
- if (UrlPostParmsCheck("pid,con"))
- {
- successFlag = true;
- int pid = GetPostInt("pid");
- int fid = GetPostInt("fid");
- string con = GetPostString("con");
- string imgs = GetPostString("images");
- SAssnPost entity = SAssnPost.Get(pid);
- if (entity == null)
- {
- conError("找不到该贴!");
- return;
- }
- SAssnPostReply reply = new SAssnPostReply();
- reply.AddTime = DateTime.Now;
- reply.ParentID = fid;
- reply.UserID = uid;
- reply.Con = con;
- reply.Images = imgs.TrimEnd(',');
- reply.PostID = pid;
- reply.Create();
- entity.replyNum += 1;
- entity.LastReplyTime = DateTime.Now;
- entity.Update();
- conSuccess("回复了!");
- return;
- }
- conError("错误的参数");
- }
- public void del_assnpostreply()
- {
- if (UrlPostParmsCheck("postid,repid"))
- {
- int postid = GetPostInt("postid");
- int repid = GetPostInt("repid");
- SAssnPostReply.Del(repid, postid);
- conSuccess("己删除");
- return;
- }
- conError("错误的参数");
- }
- public void get_myassnpost()
- {
- UserObj uo = GetUserEntity();
- if (uo == null) return;
- int uid = uo.userid;
- string tag = GetPostString("tag");
- DataStruct dStruct = GetPostStruct();
- List<string> lw = new List<string>();
- //int id = 8;
- if (tag == "reply")
- {
- lw.Add("id in (select postid from s_assnpostreply where userid=" + uid + ")");
- }
- else
- {
- lw.Add("userid=" + uid);
- }
- string key = GetPostString("key");
- if (key.Length > 0) lw.Add(string.Format("title like '%{0}%'", key));
- dStruct.Order = "addtime desc";
- dStruct.MainWhere = string.Join(" and ", lw.ToArray());
- dStruct.Fileds = "id,describe,addtime,title,viewnum,replynum,isoffice,images";
- DataTable dt = WebCache.GetData("view_assnpost", dStruct);
- conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
- return;
- }
- #endregion
- }
- }
|