app.expert.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. using BizCom;
  2. using SQLData;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Web;
  11. using Utils.ImageUtils;
  12. namespace SiteCore.Handler
  13. {
  14. public partial class app
  15. {
  16. public void get_expert()
  17. {
  18. DataStruct dStruct = GetPostStruct();
  19. List<string> lw = new List<string>();
  20. string key = GetPostString("key");
  21. if (key.Length > 0) lw.Add(string.Format("name like '%{0}%'", key));
  22. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  23. dStruct.Order = "sort asc";
  24. DataTable dt = WebCache.GetData("s_expert", dStruct);
  25. conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  26. }
  27. public void upload_expert_imgs()
  28. {
  29. UserObj uo = GetUserEntity();
  30. if (uo == null) return;
  31. int uid = uo.userid;
  32. string tag = GetPostString("tag");
  33. HttpPostedFile postFile = null;
  34. List<string> lstFile = new List<string>();
  35. int c = con.Request.Files.Count;
  36. if (c > 0)
  37. {
  38. for (int i = 0; i < c; i++)
  39. {
  40. string errMsg = "";
  41. postFile = con.Request.Files[i];
  42. if (!ImageHandler.CheckImage(postFile, out errMsg))
  43. {
  44. conError(errMsg);
  45. return;
  46. }
  47. string fileName = uid + DateTime.Now.ToFileTimeUtc() + ".jpg";
  48. string sourceExt = Path.GetExtension(postFile.FileName);
  49. if (sourceExt == ".gif")
  50. {
  51. fileName = uid + DateTime.Now.ToFileTimeUtc() + ".gif";
  52. postFile.SaveAs(webConfig.expertPath + "\\" + fileName);
  53. }
  54. else
  55. {
  56. string saveFile = Path.Combine(webConfig.expertPath, fileName);
  57. string result = "";
  58. using (System.Drawing.Image imgThumb = System.Drawing.Image.FromStream(postFile.InputStream))
  59. {
  60. result = ImageMaker.ToThumbnailImages(imgThumb, saveFile, 800, "", 9, 3);
  61. }
  62. }
  63. lstFile.Add(fileName);
  64. }
  65. }
  66. string fs = "";
  67. if (lstFile.Count > 0) fs = string.Join(",", lstFile.ToArray());
  68. conSuccess("上传成功", "{\"fname\":\"" + fs + "\"}");
  69. }
  70. public void expert_question()
  71. {
  72. UserObj uo = GetUserEntity();
  73. if (uo == null) return;
  74. int uid = uo.userid;
  75. if (UrlPostParmsCheck("eid,con"))
  76. {
  77. int eid = GetPostInt("eid");
  78. string sex = GetPostString("sex");
  79. string birthday = GetPostString("birthday");
  80. string mobile = GetPostString("mobile");
  81. string con = GetPostString("con");
  82. con = con.Replace("\r\n", "<br>").Replace("\n", "<br>");
  83. con = con.Replace(" ", "&nbsp;");
  84. string images = GetPostString("images").TrimEnd(',');
  85. SExpertQuestion entity = new SExpertQuestion();
  86. entity.AddTime = DateTime.Now;
  87. entity.UserID = uid;
  88. entity.ExpertID = eid;
  89. entity.Sex = sex;
  90. entity.Mobile = mobile;
  91. entity.BirthDay = birthday;
  92. entity.Con = con;
  93. entity.Imgs = images;
  94. entity.Create();
  95. conSuccess("提交提问!");
  96. return;
  97. }
  98. conError("错误的参数");
  99. }
  100. public void get_expertquestion()
  101. {
  102. if (UrlPostParmsCheck("eid"))
  103. {
  104. int eid = GetPostInt("eid");
  105. DataStruct dStruct = GetPostStruct();
  106. List<string> lw = new List<string>();
  107. lw.Add("ExpertID=" + eid);
  108. dStruct.Order = "addtime desc";
  109. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  110. dStruct.Fileds = "id,nickname,userpic,con,repnum,imgs,addtime,sex,answer,ansmp3,mp3len,anstime,STUFF((select top 2 '§'+userpic+'№'+nickname+'№'+convert(varchar(20),addtime,120)+'№'+convert(varchar(1),sex)+'№'+con from view_expertquestionreply as b where b.questionid=view_expertquestion.id order by AddTime desc for xml path('')),1,1,'') as items";
  111. DataTable dt = WebCache.GetData("view_expertquestion", dStruct);
  112. conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  113. return;
  114. }
  115. }
  116. public void upload_expert_mp3()
  117. {
  118. UserObj uo = GetUserEntity();
  119. if (uo == null) return;
  120. int uid = uo.userid;
  121. string tag = GetPostString("tag");
  122. HttpPostedFile postFile = null;
  123. List<string> lstFile = new List<string>();
  124. int c = con.Request.Files.Count;
  125. if (c > 0)
  126. {
  127. for (int i = 0; i < c; i++)
  128. {
  129. string errMsg = "";
  130. postFile = con.Request.Files[i];
  131. if (!ImageHandler.CheckMp3(postFile, out errMsg))
  132. {
  133. conError(errMsg);
  134. return;
  135. }
  136. //
  137. string fileName = uid + DateTime.Now.ToFileTimeUtc() + ".mp3";
  138. //string sourceExt = Path.GetExtension(postFile.FileName);
  139. //fileName = uid + DateTime.Now.ToFileTimeUtc() + ".mp3";
  140. postFile.SaveAs(webConfig.expertPath + "\\" + fileName);
  141. lstFile.Add(fileName);
  142. }
  143. }
  144. string fs = "";
  145. if (lstFile.Count > 0) fs = string.Join(",", lstFile.ToArray());
  146. conSuccess("上传成功", "{\"fname\":\"" + fs + "\"}");
  147. }
  148. public void reply_expertquestion()
  149. {
  150. UserObj uo = GetUserEntity();
  151. if (uo == null) return;
  152. int uid = uo.userid;
  153. if (UrlPostParmsCheck("qid"))
  154. {
  155. int qid = GetPostInt("qid");
  156. string con = GetPostString("con");
  157. string mp3 = GetPostString("mp3");
  158. string mp3len = GetPostString("mp3len");
  159. SExpertQuestion entity = SExpertQuestion.Get(qid);//,uo.expertid
  160. if (entity == null)
  161. {
  162. conError("只允许该专家回复!");
  163. return;
  164. }
  165. else
  166. {
  167. entity.AnsMp3 = mp3;
  168. entity.Mp3Len = mp3len;
  169. entity.Answer = con;
  170. entity.AnsTime = DateTime.Now;
  171. entity.Update();
  172. conSuccess("回复完成!");
  173. return;
  174. }
  175. }
  176. conError("错误的参数");
  177. }
  178. public void ins_expertquestionreply()
  179. {
  180. UserObj uo = GetUserEntity();
  181. if (uo == null) return;
  182. int uid = uo.userid;
  183. int expid = uo.expertid;
  184. if (UrlPostParmsCheck("qid,con"))
  185. {
  186. successFlag = true;
  187. int qid = GetPostInt("qid");
  188. int pid = GetPostInt("pid");
  189. string con = GetPostString("con");
  190. string imgs = GetPostString("images");
  191. string mp3 = GetPostString("mp3");
  192. SExpertQuestion entity = SExpertQuestion.Get(qid);
  193. if (entity == null)
  194. {
  195. conError("找不到问题!");
  196. return;
  197. }
  198. if (entity.ExpertID == uo.expertid || uid == entity.UserID)
  199. {
  200. SExpertQuestionReply reply = new SExpertQuestionReply();
  201. reply.AddTime = DateTime.Now;
  202. reply.ParentID = pid;
  203. reply.UserID = uid;
  204. reply.Con = con;
  205. reply.QuestionID = qid;
  206. reply.Mp3 = mp3;
  207. reply.Create();
  208. entity.repNum += 1;
  209. entity.Update();
  210. conSuccess("已回复");
  211. return;
  212. }
  213. else
  214. {
  215. conError("只允许该问题的提问者及专家回复问题");
  216. return;
  217. }
  218. //if(entity.ExpertID)
  219. }
  220. conError("错误的参数");
  221. }
  222. public void get_expertquestionreply()
  223. {
  224. if(UrlPostParmsCheck("qid"))
  225. {
  226. int eid = GetPostInt("qid");
  227. DataStruct dStruct = GetPostStruct();
  228. List<string> lw = new List<string>();
  229. lw.Add("QuestionID=" + eid);
  230. dStruct.Order = "addtime desc";
  231. dStruct.MainWhere = string.Join(" and ", lw.ToArray());
  232. dStruct.Fileds = "id,nickname,userpic,con,addtime,0 as likenum,sex";
  233. DataTable dt = WebCache.GetData("view_expertquestionreply", dStruct);
  234. conGridJson(dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2LowerAjaxJson(dt));
  235. return;
  236. }
  237. }
  238. }
  239. }