public void Create(InforHistory inforHistory) { var parameters = new IDataParameter[] { new MySqlParameter("@P_PUBLISHERID", inforHistory.PublisherId), new MySqlParameter("@P_MD5", inforHistory.MD5), new MySqlParameter("@P_TITLE", inforHistory.Title), new MySqlParameter("@P_CONTENT", inforHistory.Content), new MySqlParameter("@P_URL", inforHistory.Url), new MySqlParameter("@P_PUBLISHTIME", inforHistory.PublishTime), new MySqlParameter("@P_REMARK", inforHistory.Remark), new MySqlParameter("@P_STARLEVEL", inforHistory.StarLevel), new MySqlParameter("@P_EDITTIME", inforHistory.EditTime), }; this.DbRequest.ExecuteNonQuery(this.ConnectionString, "P_INFORHISTORY_CREATE", parameters); }
private void button1_Click(object sender, EventArgs e) { var title = tb_title.Text.Trim(); var content = tb_content.Text.Trim(); var url = tb_url.Text.Trim(); var pubtime = dtp_publish_time.Value; var star = cmb_star_level.SelectedValue.ToString() == "0" ? (short?)null : Convert.ToInt16(cmb_star_level.SelectedValue); var remark = tb_remark.Text.Trim(); if (string.IsNullOrWhiteSpace(content)) { MessageBox.Show("文章内容不能为空。"); return; } var souceBytes = Encoding.UTF8.GetBytes(content); var md5CryptProvider = new MD5CryptoServiceProvider(); var outputBytes = md5CryptProvider.ComputeHash(souceBytes); var md5 = BitConverter.ToString(outputBytes); var existingRecord = _bizInfoMedia.GetSingleInforHistory(_publisher.Id, md5); if (existingRecord != null) { MessageBox.Show("同样的内容已经存在,不能重复添加"); return; } var infor = new InforHistory() { Content = content, CreateTime = DateTime.Now, EditTime = null, IsIgnored = false, MD5 = md5, PublisherId = _publisher.Id, PublishTime = pubtime, Remark = remark, Title = title, StarLevel = star, UpdateTime = DateTime.Now, Url = url, }; _bizInfoMedia.SaveNewPublications(new List<InforHistory>() { infor }); this.Close(); }