codice:
<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MasterPage.master" validateRequest="false" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Odbc" %>
<%@ Import Namespace="System.Configuration" %>
<script runat="server">
String connectionString = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
Funzioni ut = new Funzioni();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txtNick.Text = "" + Session["User"] + "";
txtEmail.Text = "" + Session["Email"] + "";
}
}
protected void DropDownList1_Init(object sender, EventArgs e)
{
OdbcConnection conn = new OdbcConnection(connectionString);
string SQL = "SELECT * FROM news_category";
OdbcCommand objCommand = new OdbcCommand(SQL, conn);
conn.Open();
OdbcDataReader ddlValues;
ddlValues = objCommand.ExecuteReader();
DropDownList1.DataSource = ddlValues;
DropDownList1.DataValueField = "nCatId";
DropDownList1.DataTextField = "cName";
DropDownList1.DataBind();
conn.Close();
}
protected void btnAdd_Click(object sender, EventArgs e)
{
try
{
OdbcConnection objConn = new OdbcConnection(connectionString);
objConn.Open();
string sSQL = "INSERT INTO news (cCatId,_name,";
sSQL = sSQL + "_email,";
sSQL = sSQL + "_category,";
sSQL = sSQL + "_subject,";
sSQL = sSQL + "_contentHome,";
sSQL = sSQL + "_content,";
sSQL = sSQL + "_data,";
sSQL = sSQL + "_status)VALUES(";
sSQL = sSQL + "?,";
sSQL = sSQL + "?,";
sSQL = sSQL + "?,";
sSQL = sSQL + "?,";
sSQL = sSQL + "?,";
sSQL = sSQL + "?,";
sSQL = sSQL + "?,";
sSQL = sSQL + "?,";
sSQL = sSQL + "?)";
OdbcCommand cmd = new OdbcCommand(sSQL, objConn);
cmd.Parameters.AddWithValue("?", "" + DropDownList1.SelectedItem.Value + "");
cmd.Parameters.AddWithValue("?", "" + txtNick.Text + "");
cmd.Parameters.AddWithValue("?", "" + txtEmail.Text + "");
cmd.Parameters.AddWithValue("?", "" + DropDownList1.SelectedItem.Text + "");
cmd.Parameters.AddWithValue("?", "" + txtSubject.Text + "");
cmd.Parameters.AddWithValue("?", "" + txtHomePage.Text + "");
cmd.Parameters.AddWithValue("?", "" + txtMsg.Text + "");
cmd.Parameters.AddWithValue("?", "" + txtDatePub.Text + "");
cmd.Parameters.AddWithValue("?", "" + DDLock.SelectedItem.Value + "");
cmd.ExecuteNonQuery();
objConn.Close();
Response.Redirect("default.aspx");
}
catch (System.Exception exc)
{
lblMsg.Text = "" + exc.ToString() + "";
}
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script type="text/javascript" src="/jscripts/tiny_mce/tiny_mce.js"></script><script type="text/javascript">
tinyMCE.init({
// General options
mode: "textareas",
theme: "advanced",
plugins: "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
// Theme options
theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_statusbar_location: "bottom",
theme_advanced_resizing: true,
// Example content CSS (should be your site CSS)
content_css: "css/content.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url: "lists/template_list.js",
external_link_list_url: "lists/link_list.js",
external_image_list_url: "lists/image_list.js",
media_external_list_url: "lists/media_list.js",
// Replace values for the template plugin
template_replace_values: {
username: "Some User",
staffid: "991234"
}
});
</script></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table width="100%" border="0">
<tr>
<td width="25%"></td>
<td style="width:52%;">
<asp:Label ID="lblMsg" runat="server" Text="Label"></asp:Label>
</td>
<td width="75%"></td>
</tr>
<tr>
<td width="25%">Categoria</td>
<td style="width:52%;"> <asp:DropDownList ID="DropDownList1" runat="server" oninit="DropDownList1_Init">
</asp:DropDownList></td>
<td width="75%"></td>
</tr>
<tr>
<td>Titolo</td>
<td style="width:52%;"> <asp:TextBox ID="txtSubject" runat="server" Width="499px"></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtSubject" ErrorMessage="RequiredFieldValidator"
ValidationGroup="All">Richiesto Titolo</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Home Page</td>
<td style="width:52%;"> <asp:TextBox ID="txtHomePage" runat="server" Width="499px" TextMode="MultiLine"></asp:TextBox></td>
<td> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtHomePage" ErrorMessage="RequiredFieldValidator"
ValidationGroup="All">Richiesto Home page</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Messaggio</td>
<td style="width:52%;"> <asp:TextBox ID="txtMsg" runat="server" Width="499px" TextMode="MultiLine"></asp:TextBox>
</td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
ControlToValidate="txtMsg" ErrorMessage="RequiredFieldValidator"
ValidationGroup="All">Richiesto Messaggio</asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Nick</td>
<td style="width:52%;"><asp:TextBox ID="txtNick" runat="server"></asp:TextBox></td>
<td> <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
ControlToValidate="txtNick" ErrorMessage="Inserire Nome Utente"
ValidationGroup="All"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Email</td>
<td style="width:52%;"> <asp:TextBox ID="txtEmail" runat="server" Width="188px"></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
ControlToValidate="txtEmail" ErrorMessage="Inserire Email"
ValidationGroup="All"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Dara Ora Pubblicazione</td>
<td style="width:52%;"> <asp:TextBox ID="txtDatePub" runat="server"></asp:TextBox></td>
<td> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtDatePub" ErrorMessage="Errore scrivere data 00/00/0000"
ValidationExpression="^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$" ValidationGroup="All"></asp:RegularExpressionValidator>
<asp:CompareValidator ID="CompareValidator1" ControlToValidate="txtDatePub" Operator="DataTypeCheck" Type="date" runat="server" ErrorMessage="*Errore"></asp:CompareValidator>
</td>
</tr>
<tr>
<td>Stato di pubblicazione</td>
<td style="width:52%;"> <asp:DropDownList ID="DDLock" runat="server" AutoPostBack="True">
<asp:ListItem Value="0">N</asp:ListItem>
<asp:ListItem Value="1">Y</asp:ListItem>
</asp:DropDownList></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server"
ControlToValidate="DDLock" ErrorMessage="Inserire Stato" ValidationGroup="All"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td></td>
<td style="width:52%;">
<asp:Button ID="btnAdd" runat="server" Text="Aggiungi"
onclick="btnAdd_Click" ValidationGroup="All" /></td>
<td> </td>
</tr>
</table></asp:Content>