C # version of the website news release system

zhaozj2021-02-16  55

When you write this article, you must first thank BBEN_H and JDXX, which is BBEN_H to replace this problem in C #, JDXX solves this problem, and also makes I remember some of the procedures you have done (Simple website news release System), now give it to everyone, hoping to learn from the ADO.NET to operate SQL Server database and DataGrid control components.

Database structure

Database Name: MyDB, Data Table Name: News News Table Structure ID (INT 4) Increment ID Biaoti (NVARCHAR 50) News Title Zhaizi (NVARCHAR 50) From Neirong (Ntext 16) News Content Shijian (NVARCHAR) 50) Image Path Counter (INT 4) Click on the program to connect the SQLServer database, where NetFireSoft is the name of my machine.

Website Press Release System Source Program: (Database is SQLServer) Add page (addNews.aspx) <% @ page language = "c #" debug = "true"%> <% @ import namespace = "system.data"%> <% @ Import name.sqlclient "%> website news information Add page </ title> <style type =" text / css "> <! - TABLE {font -Size: 9pt} body {font-size: 9pt} -> </ style> <script language = "c #" runat = "server"> void submit_click (object sender, eveentargs e) {// When click the Submit button after executing the following code SqlConnection MyConnection; SqlCommand MyCommand; String ConnStr; DateTime now = DateTime.Now; // link SQL Server database MyConnection = new SqlConnection ( "Initial Catalog = mydb; Data Source = netfiresoft; Integrated Security = SSPI;") MyConnection.Open (); string neirong2; neirong2 = server.htmlencode (neirong.text); string zh = "; string tmpstr =" "; for (int i = 0; i <neirong2.Length; i ) {zH = neirong2.substring (i, 1); if (en == ") {zh =" ";} if (zh ==" / n ") {zH =" <br> ";} if (zh == "/ t") {zh = "";} tmpstr = tmpstr zh;} neirong2 = tmpstr; if ((Biaoti.Text == ") || (neirong2 == "" ") {label1.text =" Title or content can't be empty! "} Else if (biaoti.text.length> = 100) {label1.text =" Your title is too long! "} Else if (img.text.length> = 100) {label1.text =" Your picture path is too long! "} Else {// Insert a new record into the database connstr =" Insert Into News (Biaoti, Zhaizi, Neirong, Shijian, IMG, Counter) Values ​​('" biaoti.text ",' " zhaizi.Text "','" </p> <p>Neirong2 "','" now.toTRING () "','" img.text "', 0)"; mycommand = new sqlcommand (connStr, myconnection); myCommand.executenonQuery (); label1.text = " Increased success! ";} Biaoti.text ="; zhaizi.text = "; neirong.text ="; img.text = "";} void reset_click (Object sender, eventargs e) {// After the cancel button, execute the following code biaoti.text = ""; zhaizi.text = "; neirong.text ="; img.text = "";} </ script> </ head> <body> <Table Width = "550" border = "1" cellspacing = "0" cellpadding = "0" align = "center" bordercolorlight = "# 666666" BordercoloRDark = "# fff"> <form runat = server> <tr bgcolor = "# cccccc" > <TD colspan = "2"> Website news information Add page </ td> </ tr> <tr> <td color = "2"> <td> </ tr> <tr> <td width = "78 "> Title: </ TD> <TD width =" 416 "> <asp: textbox id =" biaoti "size =" 50 "runat =" server "/> </ td> </ tr> <tr> <td Width = "78"> Excerpted from: </ td> <td width = "416"> <asp: textbox id = "zhaizi" size = "30" runat = "server" /> </ td> </ tr> < Tr> <TD Width = "78> Picture: </ TD> <TD Width =" 416 "> <asp: textbox id =" img "size =" 30 "runat =" server "/> </ td> < / TR> <TR> <TD Width = "78"> Content: </ TD> <TD WID TH = "416"> <asp: textbox id = "neirong" columns = "60" rows = "15" textmode = "multiline" runat = "server"> </ asp: textbox> </ td> </ TR> <Tr> <TD COLSPAN = "2"</p> <p>> </ Td> </ tr> <tr> <td colspan = "2"> <div align = "center"> <asp: button id = "submit" onclick = subsmit_click runat = "server" text = "Submit" > </ Asp: button> <ask = "reset" onclick = reset_click runat = "server" text = "cancel"> </ asp: button> </ div> </ td> </ tr> </ Form> </ table> <p align = "center"> <asp: label id = "label1" runat = "server" /> </ body> </ html> Show news header page (newsshow.aspx): To DataGrid Control Components) <% @ page language = "c #" debug = "true"%> <% @ Import namespace = "system.data"%> <% @ import namespace = "system.data.sqlclient"%> < HTML> <head> <title> Website press release system </ title> <script language = "c #" runat = "server"> // Execute the following program when just loaded.</p> <p>int startIndex; void Page_Load (Object Src, EventArgs E) {if (IsPostBack!) {startIndex = 0;} // binding DataGridBinding ();} // linked databases, binding DataGridvoid Binding () {SqlConnection MyConnection; String ConnStr ; MyConnection = new SqlConnection ( "Initial Catalog = mydb; Data Source = netfiresoft; Integrated Security = SSPI;"); myConnection.Open (); String strCom = "SELECT id, biaoti, zhaizi, counter, shijian FROM news ORDER BY id DESC "; DataSet myDataSet = new DataSet (); SqlDataAdapter myCommand = new SqlDataAdapter (strCom, MyConnection); // filled DataSet myCommand.Fill (myDataSet," news "); // Close link DataGrid1.DataSource = myDataSet.Tables [" . news "] DefaultView; // bind DataGrid DataGrid1.DataBind ();} void changePage (Object sender, DataGridPageChangedEventArgs e) {startIndex = e.NewPageIndex * DataGrid1.PageSize; DataGrid1.CurrentPageIndex = e.NewPageIndex; binding (); } </ Script> </ head> <body runat = server> <p align = "center"> <font size = " 3"> News Browse </ font> <form runat = server> <ask: dataGrid id = DataGrid1 Runat = "Server" ForeColor = "Black" PagerStyle-Mode = "NumericPages" Headerstyle-BackColor = "# AAAADD" AlternatingItemStyle-BackColor = "# FFFFCD" OnPageindexChanged = "ChangePage" PageSize = "10" AllowPaging = "True" Width = " 80% "Font-Name =" Verdana "Font-Size =" 8pt "autogeneratecolumns =" ​​False "> <Columns> <asp: HyperLinkColumn HeaderText =" title "DataNavigateUrlField =" id "DataNavigateUrlFormatString =" show.aspx id = {? 0} "</p> <p>DataTextField = "biaoti" Target = "_ new" /> <asp: BoundColumn HeaderText = "Taken" itemstyle-width = 20% DataField = zhaizi /> <asp: BoundColumn HeaderText = "clicks" itemstyle-width = 10% DataField = Counter /> <ask: BoundColumn Headeertext = "Posted" ItemStyle-Width = 20% DataField = shijian /> </ color> </ asp: datagrid> </ form> </ body> </ html> News Content Browsing Page (Show.aspx): <% @ page language = "c #" debug = "true"%> <% @ import name "%> <% @ import name"%> "system.data.sqlclient"%> <Html> <head> <title> News publishing system </ title> <style type = "text / css"> <! - Table {font-size: 9pt} input {font-size: 9pt} select {font- Size: 9pt} body {font-size: 9pt} A: link {color: # 000099; Text-Decoration: none} a: visited {color: # 000099; Text-Decoration: none} A: Hover {color: # 990000 Text-decoration: underline} Td {font-size: 9pt; line-height: 13pt;}. p1 {font-family: "Song"; font-size: 9pt} .p2 {} .p3 {font-family: "Song"; font-size: 12pt} -> </ style> <script language = "c #" runat = "server"> DataSet DS; DATAROW DR; String News id; void Page_Load (Object sender, EventArgs e) {SqlConnection MyConnection; String ConnStr, strCon; newsid = Request.Params [ "id"]; MyConnection = new SqlConnection ( "Initial Catalog = mydb; Data Source = netfiresoft; Integrated Security = SSPI; "); myConnection.Open (); String strCom =" SELECT biaoti, zhaizi, neirong, img, counter, shijian FROM news where id = " newsid; ds = new DataSet (); SqlDataAdapter myCommand = new SqlDataAdapter (strCom , Myconnection;</p> <p>MyCommand.Fill (DS, "News"); DR = DS.TABLES ["news"]. Rows [0]; strcon = "select counter" where id = " newsid; sqlcommand mycommand2 = new SQLCOMMand (Strcon, MyConnection) ); Sqldatarader reader = mycommand2.executeReader (); reader.read (); int i = reader.GetInt32 (0); i ; reader.close (); strcon = "Update news set counter =" i.toString () "Where (id =" newsid ")"; mycommand2.commandtext = strcon; mycommand2.executenononury (); myconnection.close ();} </ script> </ head> <body bgcolor = # ffffff "link = "# 000000"> <div align = "center" class = "p2"> <table width = "500" border = "0" cellspacing = "0" cellpadding = "0"> <tr> <TD> <div align = "Center"> News release system </ div> </ td> </ tr> <tr> <td> </ td> <TR> </ table> <Table Width = "500" border = "1" Cellspacing = "0" cellpadding = "0" bordercolordark = "# ffffff" bordercolorlight = "# cccccc"> <tr> <td background = "mmto.gif" Height = "15" width = "470"> <Table Width = "500" border = "0" cellspacing = "0" cellpadding = "0" background = "mmto.gif"> <tr> <td background = "mmto.gif"> </ td> <TD backg Round = "mmto.gif"> <div align = "right"> <img src = "printer.gif" width = "16" height = "14"> <a href="javascript:Window.print()"> Print this page </A> </ div> </ td> </ tr> </ Table> </ td> </ tr> <tr> <td width = "470> <table width =" 500 "</p> <p>Border = "0" cellspacing = "0" cellpadding = "0"> <tr align = "center"> <td class = "p3"> <br> <% = DR ["biaoti"]%> </ td> </ Tr> <trilign = "center"> <td> <div> <hr size = "1" width = "300"> <font color = "# 999999"> [<% = DR ["shijian"] %>] </ Font> <br> </ div> <td> </ tr> <tr> <td> <% IF (DR ["IMG"]! = "") {Response.write ("< IMG SRC = '" DR [" IMG "] "' border = 0 align = 'left' width = '20 'height =' 200 '> ");}%> <br> <% = DR [" neirong "]%> </ td> </ tr> <tr> <td> <br> <br> Taken: <% = dr [" zhaizi "]%> <br> </ td> </ tr> <tr > <TD> <div align = "right"> </ div> </ td> </ tr> </ Table> </ td> </ tr> <tr> <td height = "17> <table width = "498" Border = "0" cellspacing = "0" cellpadding = "0" mmto.gif "> <tr> <TD width =" 172 "background =" mmto.gif "> This message is viewed <font color = "# Ff3333"> [<% = DR ["counter"]%>] <td width = "172" background = "mmto.gif"> </ td> <TD Width = "1 34 "Background =" mmto.gif "> <p align =" right "> <a href="javascript:Window.close()"> Close this window </a> </ p> </ td> </ TR > </ Table> </ td> </ tr> </ table> <table width = "500" border = "0" cellspacing = "0" cellpadding = "0"> <tr> <td> <img src = "bian.gif" width =</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-19004.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="19004" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.055</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'X1wEc9cLavUV0C54NFO5i3eFoKLifhjUlp2CZsae7cRTqpptnD54Wl3vJcbsh8pzG5DBD97JqlDe3o481Xacug_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>