//Referans Ekleme-Post public ActionResult worksadd(works work, HttpPostedFileBase foto) { works w = new works(); if (online() == false) { return(RedirectToAction("Login", "Security")); } try { if (foto != null) { WebImage img = new WebImage(foto.InputStream); FileInfo fotoinfo = new FileInfo(foto.FileName); string newfoto = Guid.NewGuid().ToString() + fotoinfo.Extension; img.Resize(600, 400); img.Save("~/Image/worksImage/" + newfoto); work.worksImage = "~/Image/worksImage/" + newfoto; db.works.Add(work); db.SaveChanges(); var wid = db.works.Where(x => x.worksName == work.worksName && x.worksImage == work.worksImage).FirstOrDefault(); process(wid.worksId, "works", "Eklendi"); } return(RedirectToAction("works", "Admin")); } catch (Exception ex) { return(RedirectToAction("Error", "Home", new { ex = ex })); } }
public ActionResult PublishArticle(string title, string coreSentences, string flag, string context) { AjaxResult ajaxResult = new AjaxResult(); //判断是否登录 if (isLogin() == null) { ajaxResult.Result = DoResult.UnSession; ajaxResult.PromptMsg = "还未登录,请先登录!"; } else { if (title == "" || coreSentences == "" || flag == "" || context == "") { ajaxResult.Result = DoResult.Failed; ajaxResult.PromptMsg = "请将所有信息添加完整!"; } else { works work = new works(); user u = (user)Session["USER"]; int uid = u.Uid; string name = u.Name; work.Uid = uid; work.Flag = int.Parse(flag); work.Context = context; work.Title = title; work.CoreSentence = coreSentences; work.author = name; //保存图片及路径 string imagePath = Request.MapPath("~/Uppictures/" + Request.Files["image"].FileName); Request.Files["image"].SaveAs(imagePath); work.Image = "/Uppictures/" + Request.Files["image"].FileName; //work.Image = imagePath;//会拒绝访问,因为绝对路径访问属于访问外部资源 System.Diagnostics.Debug.Write("自定义错误:" + work.ToString()); if (Op_Works.Add(work)) { ajaxResult.Result = DoResult.Success; ajaxResult.PromptMsg = "上传成功"; ajaxResult.RetValue = int.Parse(flag); } else { ajaxResult.Result = DoResult.Failed; ajaxResult.PromptMsg = "上传失败,请重试"; } } } return(Json(ajaxResult)); }
//根据作者查找作品 public static List <works> FindArticleByUid(int id) { //string constr= ConfigurationManager.ConnectionStrings["qhj_aspEntities"].ConnectionString; string constr = "Server=localhost;UserId=root;Password=qhj12345;Database=qhj_asp;pooling=false;CharSet=utf8;port=3306"; MySqlConnection conn = new MySqlConnection(constr); try { conn.Open(); string mySql = "select * from works where Uid=@uid"; MySqlCommand sqlcmd2 = new MySqlCommand(mySql, conn); MySqlParameter p1 = new MySqlParameter("@uid", MySqlDbType.Int32); p1.Value = id; sqlcmd2.Parameters.Add(p1); List <works> workList = new List <works>(); MySqlDataReader sqlreader = sqlcmd2.ExecuteReader(); while (sqlreader.Read()) { //txtName.Text = sqlreader["列名"].ToString(); works temp = new works(); temp.Wid = Convert.ToInt32(sqlreader["Wid"]); temp.Uid = Convert.ToInt32(sqlreader["Uid"]); temp.Flag = Convert.ToInt32(sqlreader["Flag"]); temp.Context = sqlreader["Context"].ToString(); temp.Image = sqlreader["Image"].ToString(); temp.Title = sqlreader["Title"].ToString(); temp.CoreSentence = sqlreader["CoreSentence"].ToString(); temp.author = sqlreader["author"].ToString(); workList.Add(temp); } return(workList); } catch (Exception ex) { Debug.WriteLine("Error: " + ex.Message); } finally { conn.Close(); conn.Dispose(); } return(null); }
public ActionResult WorkDetails(works work) { using (var dc = new MySQLEntities()) { if (work.idWorks == Guid.Empty) { work.idWorks = Guid.NewGuid(); dc.works.Add(work); dc.SaveChanges(); } else { dc.Entry(work).State = EntityState.Modified; dc.SaveChanges(); } } return(RedirectToAction("Works")); //if (idWorksAsString == null) //{ // return HttpNotFound(); //} //try //{ // using (var dc = new MySQLEntities()) // { // Guid idWorks = new Guid(idWorksAsString); // var elementMySQL = dc.works.Find(idWorks); // return PartialView(elementMySQL); // }; //} //catch (Exception ex) //{ //return HttpNotFound(); //} }
public ActionResult ShowDetail(int wid) { works w = Op_Works.FindArticleByWid(wid); return(View(w)); }
=> (queue ?? throw new ArgumentNullException(nameof(queue))).DoWorkAsync(works, priority, cancellation, attemptsCount, enqueueAll);
=> (queue ?? throw new ArgumentNullException(nameof(queue))).DoWorkAsync(works, cancellation, attemptsCount);
//添加作品 public static bool Add(works work) { //string constr= ConfigurationManager.ConnectionStrings["qhj_aspEntities"].ConnectionString; string constr = "Server=localhost;UserId=root;Password=qhj12345;Database=qhj_asp;pooling=false;CharSet=utf8;port=3306"; MySqlConnection conn = new MySqlConnection(constr); try { conn.Open(); int uid = work.Uid; int flag = work.Flag; string context = work.Context; string image = work.Image; string title = work.Title; string core = work.CoreSentence; string author = work.author; string mySql = "INSERT INTO works(Uid,Flag,Context,Image,Title,CoreSentence,author) VALUES(@uid,@flag,@context,@image,@title,@core,@author)"; MySqlCommand sqlcmd2 = new MySqlCommand(mySql, conn); MySqlParameter p1 = new MySqlParameter("@uid", MySqlDbType.Int32); p1.Value = uid; MySqlParameter p2 = new MySqlParameter("@flag", MySqlDbType.Int32); p2.Value = flag; MySqlParameter p3 = new MySqlParameter("@context", MySqlDbType.Text); p3.Value = context; MySqlParameter p4 = new MySqlParameter("@image", MySqlDbType.VarChar); p4.Value = image; MySqlParameter p5 = new MySqlParameter("@title", MySqlDbType.VarChar); p5.Value = title; MySqlParameter p6 = new MySqlParameter("@core", MySqlDbType.VarChar); p6.Value = core; MySqlParameter p7 = new MySqlParameter("@author", MySqlDbType.VarChar); p7.Value = author; sqlcmd2.Parameters.Add(p1); sqlcmd2.Parameters.Add(p2); sqlcmd2.Parameters.Add(p3); sqlcmd2.Parameters.Add(p4); sqlcmd2.Parameters.Add(p5); sqlcmd2.Parameters.Add(p6); sqlcmd2.Parameters.Add(p7); int iResult = sqlcmd2.ExecuteNonQuery(); if (iResult > 0) { return(true); } } catch (Exception ex) { Debug.WriteLine("Error: " + ex.Message); } finally { conn.Close(); conn.Dispose(); } return(false); }
/// <summary> /// 存储作品到works表;存储作品和多个成员关系 /// </summary> /// <param name="typeId">类型在type表中的id</param> /// <param name="title">作品标题</param> /// <param name="time">作品完成时间</param> /// <param name="introduction">作品简介</param> /// <param name="workPicName">作品图片文件名(不含路径)</param> /// <param name="link">作品链接</param> void submitWork(int typeId,string title,string time, string introduction, string workPicName,string link) { using (var db = new ITStudioEntities()) { var work = new works(); // 要添加的作品 work.typeId = typeId; work.picture = workPicName; work.title = title; work.introduction = introduction; work.time = time; work.link = link; db.works.Add(work); db.SaveChanges(); int workId = work.id; // works work2 = db.works.SingleOrDefault(a => a.picture == work.picture); //意义不明,可能是为了获取刚添加的作品。 // 存储多个作者到 workmap 表 for (int i = 0; i < ChklstAuthors.Items.Count; i++) // 遍历CheckBoxList { if (ChklstAuthors.Items[i].Selected == true) { int memberId = 1; if (Filter.IsNumeric(ChklstAuthors.Items[i].Value)) { memberId = Convert.ToInt32(ChklstAuthors.Items[i].Value); } var map = new workmap(); map.memberId = memberId; map.workId = workId; db.workmap.Add(map); db.SaveChanges(); } } } }