app.assn.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. using BizCom;
  2. using SQLData;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Data.SqlClient;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Web;
  12. using Utils;
  13. using Utils.ImageUtils;
  14. using Utils.Serialization;
  15. namespace SiteCore.Handler
  16. {
  17. public partial class app
  18. {
  19. #region 贴子
  20. public void get_index_assnpost()
  21. {
  22. DataStruct dStruct = GetPostStruct();
  23. List<string> lw = new List<string>();
  24. string key = GetPostString("key");
  25. if (key.Length > 0) lw.Add(string.Format("name like '%{0}%'", key));
  26. lw.Add("isoffice=1");
  27. dStruct.Order = "isnull(lastreplytime,addtime) desc,addtime desc";
  28. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  29. dStruct.Fileds = "id,assnid,assnname,assnlogo,userpic,username,addtime,lastreplytime,title,isoffice,viewnum,replynum,images,sex";
  30. DataTable dt = WebCache.GetData("view_assnpost", dStruct);
  31. conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  32. }
  33. public void get_assnpost()
  34. {
  35. //if (UrlPostParmsCheck("aid"))
  36. //{
  37. DataStruct dStruct = GetPostStruct();
  38. List<string> lw = new List<string>();
  39. //int id = 8;
  40. int id = GetPostInt("aid");
  41. if (id > 0)
  42. {
  43. lw.Add("AssnID=" + id);
  44. }
  45. string key = GetPostString("key");
  46. if (key.Length > 0) lw.Add(string.Format("name like '%{0}%'", key));
  47. dStruct.Order = "istop desc,isnull(lastreplytime,addtime) desc,addtime desc";
  48. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  49. dStruct.Fileds = "id,describe,userpic,username,addtime,lastreplytime,title,istop,isoffice,viewnum,replynum,images,sex";
  50. DataTable dt = WebCache.GetData("view_assnpost", dStruct);
  51. conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  52. return;
  53. //}
  54. //conError("错误的参数");
  55. }
  56. public void get_assnpostdetail()
  57. {
  58. UserObj uo = GetUserEntity();
  59. if (uo == null) return;
  60. int uid = uo.userid;
  61. if (UrlPostParmsCheck("pid"))
  62. {
  63. int id = GetPostInt("pid");
  64. StringBuilder sql = new StringBuilder();
  65. 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);
  66. sql.AppendFormat("select * from s_assnpostvote where postid={0} order by id asc;",id);
  67. sql.AppendFormat(";", id, uid);
  68. DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
  69. DataTable dt = ds.Tables[0];
  70. string con = Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt);
  71. string items = Utils.Serialization.JsonString.DataTable2LowerAjaxJson(ds.Tables[1]);
  72. //string voteids = "";
  73. //if(ds.Tables[2]!=null && ds.Tables[2].Rows.Count > 0)
  74. //{
  75. // voteids = ds.Tables[2].Rows[0]["voteids"].ToString();
  76. //}
  77. con = con.Replace("\"§\"", items);
  78. //if (dt != null && dt.Rows.Count > 0)
  79. // dt.Rows[0]["vitems"] = items;
  80. //lw.Add("ID=" + id);
  81. //dStruct.Order = "addtime desc";
  82. //dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  83. //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";
  84. //DataTable dt = WebCache.GetData("view_assnpost", dStruct);
  85. conGridJson(1,con);
  86. return;
  87. }
  88. conError("错误的参数");
  89. }
  90. public void upload_assnpost_img()
  91. {
  92. UserObj uo = GetUserEntity();
  93. if (uo == null) return;
  94. int uid = uo.userid;
  95. string tag = GetPostString("tag");
  96. HttpPostedFile postFile = null;
  97. List<string> lstFile = new List<string>();
  98. int c = con.Request.Files.Count;
  99. if (c > 0)
  100. {
  101. for (int i = 0; i < c; i++)
  102. {
  103. string errMsg = "";
  104. postFile = con.Request.Files[i];
  105. if (!ImageHandler.CheckImage(postFile, out errMsg))
  106. {
  107. conError(errMsg);
  108. return;
  109. }
  110. string fileName = uid + DateTime.Now.ToFileTimeUtc() + ".jpg";
  111. string sourceExt = Path.GetExtension(postFile.FileName);
  112. if (sourceExt == ".gif")
  113. {
  114. fileName = uid + DateTime.Now.ToFileTimeUtc() + ".gif";
  115. postFile.SaveAs(webConfig.assnPath + "\\post\\" + fileName);
  116. }
  117. else
  118. {
  119. string saveFile = Path.Combine(webConfig.assnPath + "\\post", fileName);
  120. string result = "";
  121. using (System.Drawing.Image imgThumb = System.Drawing.Image.FromStream(postFile.InputStream))
  122. {
  123. result = ImageMaker.ToThumbnailImages(imgThumb, saveFile, 800, "", 9, 3);
  124. }
  125. }
  126. lstFile.Add(fileName);
  127. }
  128. }
  129. string fs = "";
  130. if (lstFile.Count > 0) fs = string.Join(",", lstFile.ToArray());
  131. conSuccess("上传成功", "{\"fname\":\"" + fs + "\"}");
  132. }
  133. public void top_assnpost()
  134. {
  135. UserObj uo = GetUserEntity();
  136. if (uo == null) return;
  137. int uid = uo.userid;
  138. if (UrlPostParmsCheck("pid,istop"))
  139. {
  140. int pid = GetPostInt("pid");
  141. int st = GetPostInt("istop");
  142. SAssnPost.UpdateIsTop(pid, st);
  143. conSuccess("操作完成!");
  144. return;
  145. }
  146. conError("错误的参数");
  147. }
  148. public void ins_assnpost()
  149. {
  150. UserObj uo = GetUserEntity();
  151. if (uo == null) return;
  152. int uid = uo.userid;
  153. if (UrlPostParmsCheck("title,con"))
  154. {
  155. int pid = GetPostInt("pid");
  156. int aid = GetPostInt("aid");
  157. string title = GetPostString("title");
  158. string con = GetPostString("con");
  159. int ptype = GetPostInt("ptype");
  160. int vtype = GetPostInt("vtype");
  161. string vitems = GetPostString("vitems");
  162. int vpn = GetPostInt("vpernum");
  163. string expire = GetPostString("expiretime");
  164. con = con.Replace("\r\n", "<br>").Replace("\n", "<br>");
  165. con = con.Replace(" ", "&nbsp;");
  166. string images = GetPostString("images").TrimEnd(',');
  167. SAssnPost entity;
  168. if (pid > 0)
  169. {
  170. entity = SAssnPost.Get(pid, uid);
  171. entity.UpdateTime = DateTime.Now;
  172. }
  173. else {
  174. entity = new SAssnPost();
  175. entity.AddTime = DateTime.Now;
  176. entity.UserID = uid;
  177. entity.AssnID = aid;
  178. entity.viewNum = 2;
  179. }
  180. if (vitems != "")
  181. {
  182. entity.voteItem = vitems;
  183. entity.voteType = vtype;
  184. entity.PostTypeID = ptype;
  185. entity.votePerNum = vpn;
  186. entity.ExpireTime = Convert.ToDateTime(expire);
  187. }
  188. entity.Title = title;
  189. entity.Describe = con.Substring(0, 45);
  190. entity.Con = con;
  191. entity.Images = images.TrimEnd(',');
  192. string pub = GetPostString("isoffice");
  193. if (pub != "") entity.isOffice = Convert.ToBoolean(pub);
  194. else entity.isOffice = true;
  195. //entity.imgNum = images.Split(',').Length;
  196. StringBuilder sql = new StringBuilder();
  197. if (pid > 0)
  198. {
  199. entity.Update();
  200. if (vitems != "")
  201. {
  202. string[] vArr = vitems.Split('№');
  203. string[] tArr;
  204. for (int i = 0; i < vArr.Length; i++)
  205. {
  206. tArr = vArr[i].Split('§');
  207. if(tArr[0]=="") sql.AppendFormat("insert into s_assnpostvote(postid,itemname) values({0},'{1}') ;", entity.ID, tArr[1]);
  208. else sql.AppendFormat("update s_assnpostvote set itemname='{2}' where postid={0} and id={1};", entity.ID, tArr[0], tArr[1]);
  209. //sql.AppendFormat("update s_assnpostvote set itemname='{2}' where postid={0} and id={1};", entity.ID, tArr[0], tArr[1]);
  210. }
  211. if (sql.Length > 0) DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  212. }
  213. conSuccess("己修改贴子!");
  214. }
  215. else
  216. {
  217. entity.Create();
  218. if (vitems != "")
  219. {
  220. string[] vArr = vitems.Split('№');
  221. string[] tArr;
  222. for (int i = 0; i < vArr.Length; i++)
  223. {
  224. //tArr = vArr[i].Split('§');
  225. sql.AppendFormat("insert into s_assnpostvote(postid,itemname) values({0},'{1}') ;", entity.ID, vArr[i]);
  226. //if (tArr[0] == "") sql.AppendFormat("insert into s_assnpostvote(postid,itemname) values({0},'{1}') ;", entity.ID, tArr[0]);
  227. //else sql.AppendFormat("update s_assnpostvote set itemname='{2}' where postid={0} and id={1};", entity.ID, tArr[0], tArr[1]);
  228. //sql.AppendFormat("update s_assnpostvote set itemname='{2}' where postid={0} and id={1};", entity.ID, tArr[0], tArr[1]);
  229. }
  230. if (sql.Length > 0) DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  231. }
  232. conSuccess("发贴成功!");
  233. }
  234. return;
  235. }
  236. conError("错误的参数");
  237. }
  238. public void ins_assnpostvote()
  239. {
  240. UserObj uo = GetUserEntity();
  241. if (uo == null) return;
  242. int uid = uo.userid;
  243. if (UrlPostParmsCheck("pid,vids"))
  244. {
  245. int pid = GetPostInt("pid");
  246. string vids = GetPostString("vids");
  247. StringBuilder sql = new StringBuilder();
  248. sql.AppendFormat("if (select count(0) from s_assnpostvoteperson where postid={0} and userid={1})<1 begin ", pid, uid);
  249. sql.AppendFormat("insert into s_assnpostvoteperson(userid,postid,voteids,addtime)values({0},{1},'{2}',getdate()) ;", uid,pid,vids);
  250. sql.AppendFormat("update s_assnpostvote set votenum=votenum+1 where postid={0} and id in ({1}) ;", pid, vids);
  251. sql.Append(" end ");
  252. DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
  253. //SAssnPostVotePerson entity = new SAssnPostVotePerson();
  254. //entity.UserID = uid;
  255. //entity.VoteIDs = vids;
  256. //entity.AddTime = DateTime.Now;
  257. //entity.Create();
  258. conSuccess("己投票!");
  259. return;
  260. }
  261. conError("错误的参数");
  262. }
  263. public void del_assnpost()
  264. {
  265. UserObj uo = GetUserEntity();
  266. if (uo == null) return;
  267. int uid = uo.userid;
  268. if (UrlPostParmsCheck("pid"))
  269. {
  270. int pid = GetPostInt("pid");
  271. //sp_del_assnpost
  272. SqlParameter[] sqlParameter ={
  273. new SqlParameter("@pid", SqlDbType.Int, 4),
  274. new SqlParameter("@uid", SqlDbType.Int, 4),
  275. new SqlParameter("@result",SqlDbType.NVarChar,100)};
  276. sqlParameter[0].Value = pid;
  277. sqlParameter[1].Value = uid;
  278. sqlParameter[2].Direction = ParameterDirection.Output;
  279. SAssnPost.ExecuteNonQueryStore("sp_del_assnpost", sqlParameter);
  280. string result = sqlParameter[2].Value.ToString();
  281. if (result.Substring(0, 2) == "0|")
  282. {
  283. conError(result.Split('|')[1]);
  284. }
  285. else
  286. {
  287. string c = result.Split('|')[1];
  288. conSuccess(c);
  289. }
  290. return;
  291. }
  292. conSuccess("错误的参数");
  293. }
  294. public void get_assnpostreply()
  295. {
  296. if (UrlPostParmsCheck("pid"))
  297. {
  298. DataStruct dStruct = GetPostStruct();
  299. List<string> lw = new List<string>();
  300. int id = GetPostInt("pid");
  301. //id = 92;re
  302. int sort = GetPostInt("sort");
  303. if (id > 0)
  304. {
  305. lw.Add("PostID=" + id);
  306. if (sort == 1) dStruct.Order = "addtime desc";
  307. else dStruct.Order = "addtime asc";
  308. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  309. 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";
  310. DataTable dt = WebCache.GetData("view_assnpostreply", dStruct);
  311. conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  312. return;
  313. }
  314. }
  315. conError("错误的参数");
  316. }
  317. public void get_assnpostreplysec()
  318. {
  319. if (UrlPostParmsCheck("postid,rid"))
  320. {
  321. DataStruct dStruct = GetPostStruct();
  322. List<string> lw = new List<string>();
  323. int postid = GetPostInt("postid");
  324. int rid = GetPostInt("rid");
  325. //id = 92;
  326. int sort = GetPostInt("sort");
  327. lw.Add("PostID=" + postid);
  328. lw.Add("parentid=" + rid);
  329. //lw.Add("ParentID=0");
  330. if (sort == 1) dStruct.Order = "addtime desc";
  331. else dStruct.Order = "addtime asc";
  332. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  333. dStruct.Fileds = "id,username,parentid as pid,con,addtime";
  334. DataTable dt = WebCache.GetData("view_assnpostreply", dStruct);
  335. conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  336. return;
  337. }
  338. conError("错误的参数");
  339. }
  340. public void ins_assnpostreply()
  341. {
  342. UserObj uo = GetUserEntity();
  343. if (uo == null) return;
  344. int uid = uo.userid;
  345. if (UrlPostParmsCheck("pid,con"))
  346. {
  347. successFlag = true;
  348. int pid = GetPostInt("pid");
  349. int fid = GetPostInt("fid");
  350. string con = GetPostString("con");
  351. string imgs = GetPostString("images");
  352. SAssnPost entity = SAssnPost.Get(pid);
  353. if (entity == null)
  354. {
  355. conError("找不到该贴!");
  356. return;
  357. }
  358. SAssnPostReply reply = new SAssnPostReply();
  359. reply.AddTime = DateTime.Now;
  360. reply.ParentID = fid;
  361. reply.UserID = uid;
  362. reply.Con = con;
  363. reply.Images = imgs.TrimEnd(',');
  364. reply.PostID = pid;
  365. reply.Create();
  366. entity.replyNum += 1;
  367. entity.LastReplyTime = DateTime.Now;
  368. entity.Update();
  369. conSuccess("回复了!");
  370. return;
  371. }
  372. conError("错误的参数");
  373. }
  374. public void del_assnpostreply()
  375. {
  376. if (UrlPostParmsCheck("postid,repid"))
  377. {
  378. int postid = GetPostInt("postid");
  379. int repid = GetPostInt("repid");
  380. SAssnPostReply.Del(repid, postid);
  381. conSuccess("己删除");
  382. return;
  383. }
  384. conError("错误的参数");
  385. }
  386. public void get_myassnpost()
  387. {
  388. UserObj uo = GetUserEntity();
  389. if (uo == null) return;
  390. int uid = uo.userid;
  391. string tag = GetPostString("tag");
  392. DataStruct dStruct = GetPostStruct();
  393. List<string> lw = new List<string>();
  394. //int id = 8;
  395. if (tag == "reply")
  396. {
  397. lw.Add("id in (select postid from s_assnpostreply where userid=" + uid + ")");
  398. }
  399. else
  400. {
  401. lw.Add("userid=" + uid);
  402. }
  403. string key = GetPostString("key");
  404. if (key.Length > 0) lw.Add(string.Format("title like '%{0}%'", key));
  405. dStruct.Order = "addtime desc";
  406. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  407. dStruct.Fileds = "id,describe,addtime,title,viewnum,replynum,isoffice,images";
  408. DataTable dt = WebCache.GetData("view_assnpost", dStruct);
  409. conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  410. return;
  411. }
  412. #endregion
  413. }
  414. }