File manager - Edit - G:/PleskVhosts/indiaminerals.in/vgm.INFOFIXDEVELOPERS.COM/admin/animal_master.aspx.cs
Back
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data; using System.Configuration; using WebApp.LIBS; using System.IO; namespace VGM.admin { public partial class animal_master : BasePageClass { string cs = ConfigurationManager.ConnectionStrings["gav"].ConnectionString; SqlDataAdapter da1; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { da1 = new SqlDataAdapter("select * from animal_master", cs); DataTable dt1 = new DataTable(); da1.Fill(dt1); Gridview1.DataSource = dt1; Gridview1.DataBind(); } } protected void Button1_Click1(object sender, EventArgs e) { try { using (SqlConnection connection = new SqlConnection(cs)) { connection.Open(); // Ensure textBox1.Text is not empty or null before inserting if (!string.IsNullOrEmpty(textBox1.Text)) { string insertQuery = "INSERT INTO animal_master (animal_name ) VALUES (@animalName)"; using (SqlCommand cmd = new SqlCommand(insertQuery, connection)) { cmd.Parameters.AddWithValue("@animalName", textBox1.Text); cmd.ExecuteNonQuery(); } Response.Write("<script>alert('Record Inserted')</script>"); SaveToCSV(); // Refresh the GridView da1 = new SqlDataAdapter("SELECT * FROM animal_master", connection); DataTable dt1 = new DataTable(); da1.Fill(dt1); Gridview1.DataSource = dt1; Gridview1.DataBind(); } else { Response.Write("<script>alert('Please enter a valid animal name.')</script>"); } } } catch (Exception ex) { Response.Write("<script>alert('Error: " + ex.Message + "')</script>"); } } private void SaveToCSV() { try { string dateTime = DateTime.Now.ToString("yyyy-MM-dd"); string time = DateTime.Now.ToString("HH:mm:ss"); string tittle = "Animal Master"; // Get additional details (you may customize this part) string details = $"New Animal {textBox1.Text} Added"; // Combine date, time, and details in CSV format with comma delimiter string contentToSave = $"\"{dateTime}\",\"{time}\",\"{tittle}\",\"{details}\""; // Specify the path to the CSV file (including the file name) string filePath = Server.MapPath("~/data/LogData.csv"); // Check if the directory exists, if not, create it string directoryPath = Path.GetDirectoryName(filePath); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } // Check if the file exists, if not, create and add headers if (!File.Exists(filePath)) { File.WriteAllText(filePath, "Date,Time,Tittle,Details" + Environment.NewLine); } // Save the content to the file File.AppendAllText(filePath, contentToSave + Environment.NewLine); } catch (Exception ex) { Response.Write("<script>alert('An error occurred while saving to CSV: " + ex.Message + "')</script>"); } } } }
| ver. 1.4 |
Github
|
.
| PHP 7.3.33 | Generation time: 0.08 |
proxy
|
phpinfo
|
Settings