File manager - Edit - G:/PleskVhosts/indiaminerals.in/vgm.INFOFIXDEVELOPERS.COM/admin/Upload.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 System.IO; using System.Net; using WebApp.LIBS; namespace VGM.admin { public partial class Upload : BasePageClass { string cs = ConfigurationManager.ConnectionStrings["gav"].ConnectionString; SqlDataAdapter da, da1; private string uploadedFilePath; private DataTable dt; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string tagNo = Request.QueryString["tag_no"]; if (!string.IsNullOrEmpty(tagNo)) { registration.Text = tagNo; } DataTable dt = Session["DocumentTable"] as DataTable; if (dt == null) { dt = new DataTable(); dt.Columns.Add("upload_date", typeof(string)); dt.Columns.Add("Document_name", typeof(string)); dt.Columns.Add("Document_pic", typeof(string)); Session["DocumentTable"] = dt; } else { dt = (DataTable)Session["DocumentTable"]; } } } protected void add_Click(object sender, EventArgs e) { try { DataTable dt = Session["DocumentTable"] as DataTable; if (dt == null) { dt = new DataTable(); dt.Columns.Add("upload_date", typeof(string)); dt.Columns.Add("Document_name", typeof(string)); dt.Columns.Add("Document_pic", typeof(string)); } if (fileUploadControl.HasFile) { string fileName = Path.GetFileName(fileUploadControl.FileName); string filePath = Server.MapPath("~/Images/" + fileName); // Save to the "Images" folder on your server fileUploadControl.SaveAs(filePath); DataRow row = dt.NewRow(); row["upload_date"] = date.Text; row["Document_name"] = name.Text; row["Document_pic"] = "~/Images/" + fileName; // Store the relative URL to the document dt.Rows.Add(row); Gridview1.DataSource = dt; Gridview1.DataBind(); date.Text = ""; upload.Text = ""; name.Text = ""; name.Focus(); } } catch(Exception ex) { Response.Write("<script>alert('An error occurred: " + ex.Message + "')</script>"); } } protected void submit2_Click(object sender, EventArgs e) { try { if (string.IsNullOrWhiteSpace(registration.Text)) { Response.Write("<script>alert('Please enter Tag_no')</script>"); } else { DataTable dt = Session["DocumentTable"] as DataTable; if (dt != null && dt.Rows.Count > 0) { using (SqlConnection connection = new SqlConnection(cs)) { connection.Open(); // Check if there are existing documents for the given Tag_no foreach (DataRow row in dt.Rows) { using (SqlCommand checkCommand = new SqlCommand("SELECT COUNT(*) FROM upload WHERE Tag_no = @Tag_no AND Document_pic = @Document_pic", connection)) { checkCommand.Parameters.AddWithValue("@Tag_no", registration.Text); checkCommand.Parameters.AddWithValue("@Document_pic", row["Document_pic"]); int existingDocuments = (int)checkCommand.ExecuteScalar(); // If there are existing documents, you can handle it here if (existingDocuments > 0) { // Handle the case where the document already exists // You can display a message or take appropriate action } else { // Insert the document into the database using (SqlCommand insertCommand = new SqlCommand("INSERT INTO upload (Tag_no, upload_date, Document_name, Document_pic) VALUES (@Tag_no, @upload_date, @Document_name, @Document_pic)", connection)) { insertCommand.Parameters.AddWithValue("@Tag_no", registration.Text); insertCommand.Parameters.AddWithValue("@upload_date", row["upload_date"]); insertCommand.Parameters.AddWithValue("@Document_name", row["Document_name"]); insertCommand.Parameters.AddWithValue("@Document_pic", row["Document_pic"]); insertCommand.ExecuteNonQuery(); } } } } } // Show a success message Response.Write("<script>if(confirm('Data inserted successfully.')){ window.location = 'Upload_list.aspx'; }</script>"); Gridview1.DataSource = dt; Gridview1.DataBind(); // Clear input fields and set focus date.Text = ""; upload.Text = ""; name.Text = ""; registration.Focus(); Gridview1.DataSource = null; Gridview1.DataBind(); } SaveToCSV(); } } catch(Exception ex) { Response.Write("<script>alert('An error occurred: " + 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 = "Upload Documents"; // Get additional details (you may customize this part) string details = $"Tag no. {registration.Text} Document Uploaded"; // 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>"); } } protected void Gridview1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "DeleteRow") { int rowIndex = Convert.ToInt32(e.CommandArgument); DataTable dt = Session["DocumentTable"] as DataTable; // Retrieve the DataTable from Session if (dt != null) { if (dt.Rows.Count > rowIndex) { // Remove the row from the DataTable dt.Rows.RemoveAt(rowIndex); Session["DocumentTable"] = dt; // Update the DataTable in Session // Rebind the GridView to reflect the updated data Gridview1.DataSource = dt; Gridview1.DataBind(); } } } } protected void submit_Click(object sender, EventArgs e) { try { string statusAdmitted = "Admitted"; string statusOwn = "Own"; da = new SqlDataAdapter("select * from registration where tag_no = '" + registration.Text + "' and (status = '" + statusAdmitted + "' OR status = '" + statusOwn + "')", cs); DataTable dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count > 0) { label2.Text = dt.Rows[0]["owner_name"].ToString(); label3.Text = dt.Rows[0]["owner_mobile_no"].ToString(); label4.Text = dt.Rows[0]["owner_address"].ToString(); label6.Text = dt.Rows[0]["animal_category"].ToString(); label8.Text = dt.Rows[0]["dob"].ToString(); label10.Text = dt.Rows[0]["age"].ToString(); label12.Text = dt.Rows[0]["color"].ToString(); label14.Text = dt.Rows[0]["gender"].ToString(); label16.Text = dt.Rows[0]["weight"].ToString(); label18.Text = dt.Rows[0]["species"].ToString(); label20.Text = dt.Rows[0]["disease_diagnosis"].ToString(); label22.Text = dt.Rows[0]["prognosis"].ToString(); } else { Response.Write("<script>alert('Please insert Correct Tag no.')</script>"); } } catch(Exception ex) { Response.Write("<script>alert('An error occurred: " + ex.Message + "')</script>"); } } } }
| ver. 1.4 |
Github
|
.
| PHP 7.3.33 | Generation time: 0.04 |
proxy
|
phpinfo
|
Settings