Torna al Thread
protected void btnModifica_Click(object sender, EventArgs e)
{
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
string SQL = "SELECT * FROM photo_category WHERE ID=@S_SEZ_ID";
conn.Open();
MySqlCommand cmd = new MySqlCommand(SQL, conn);
cmd.Parameters.AddWithValue("@S_SEZ_ID", "" + Request.QueryString["id"] + "");
MySqlDataReader rdr = cmd.ExecuteReader();
string txtTitoloMod = txtTitolo.Text;
if (rdr.Read())
{
if (rdr["Name"].ToString() != txtTitolo.Text)
{
if (CheckDouble(txtTitoloMod) == true)
{
lblMsg.Text = "Esiste già categoria";
}
else
{
string Fromfile = Server.MapPath("../../../public/photo/" + rdr["Name"] + "");
rdr.Close();
string _SQL = "UPDATE photo_category set Name=@U_TITOLO,";
_SQL = _SQL + "info=@U_INFO,";
_SQL = _SQL + "stato=@U_STATO WHERE ID=@U_SEZ_ID";
MySqlCommand _cmd = new MySqlCommand(_SQL, conn);
_cmd.Parameters.AddWithValue("@U_TITOLO", txtTitolo.Text);
_cmd.Parameters.AddWithValue("@U_INFO", txtInfo.Text);
_cmd.Parameters.AddWithValue("@U_STATO", txtStato.Text);
_cmd.Parameters.AddWithValue("@U_SEZ_ID", "" + Request.QueryString["id"] + "");
_cmd.ExecuteNonQuery();
conn.Close();
conn.Open();
string __SQL = "UPDATE photo set catID=@U_SEZ_ID, _category=@U_SEZ, _dir=@U_DIR WHERE catID=@U_ID";
MySqlCommand __cmd = new MySqlCommand(__SQL, conn);
__cmd.Parameters.AddWithValue("@U_SEZ_ID", "" + Request.QueryString["id"] + "");
__cmd.Parameters.AddWithValue("@U_SEZ", "" + txtTitolo.Text + "");
__cmd.Parameters.AddWithValue("@U_DIR", "" + txtTitolo.Text + "");
__cmd.Parameters.AddWithValue("@U_ID", "" + Request.QueryString["id"] + "");
__cmd.ExecuteNonQuery();
conn.Close();
string Tofile = Server.MapPath("../../../public/photo/" + txtTitolo.Text + "");
DirectoryInfo folder = new DirectoryInfo(Server.MapPath("../../../public/photo/"));
if (folder.Exists)
{
Directory.Move(Fromfile, Tofile);
} Response.Redirect("default.aspx");
}
rdr.Close();
}
else
{
conn.Close();
string _SQL = "UPDATE photo_category set info=@U_INFO WHERE ID=@U_SEZ_ID";
conn.Open();
MySqlCommand _cmd = new MySqlCommand(_SQL, conn);
_cmd.Parameters.AddWithValue("@U_INFO", txtInfo.Text);
_cmd.Parameters.AddWithValue("@U_SEZ_ID", "" + Request.QueryString["id"] + "");
_cmd.ExecuteNonQuery();
Response.Write(txtInfo.Text);
conn.Close();
Response.Redirect("default.aspx");
}
}
}
}