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 lw = new List(); 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 lw = new List(); //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 lstFile = new List(); 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", "
").Replace("\n", "
"); 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 lw = new List(); 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 lw = new List(); 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 lw = new List(); //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 } }