File manager - Edit - G:/PleskVhosts/indiaminerals.in/vgm.INFOFIXDEVELOPERS.COM/admin/animal_detailmaster.aspx.cs
Back
using System; using System.Data.SqlClient; using System.Data; using System.Configuration; using WebApp.LIBS; using System.IO; using System.Web.UI; namespace VGM.admin { public partial class animal_detailmaster : BasePageClass { string cs = ConfigurationManager.ConnectionStrings["gav"].ConnectionString; SqlDataAdapter da, da1; protected void Page_Load(object sender, EventArgs e) { string tagNo = Request.QueryString["tag_no"]; string animalCategory = Request.QueryString["animal_category"]; if (!string.IsNullOrEmpty(tagNo) && !string.IsNullOrEmpty(animalCategory)) { FillRegistrationDropdown(tagNo, animalCategory); LoadRegistrationData(); } else { LoadRegistrationData(); } } private void FillRegistrationDropdown(string tagNo, string animalCategory) { try { registration.Items.Clear(); registration.Items.Add($"{tagNo} - {animalCategory}"); registration.SelectedIndex = 0; } catch (Exception ex) { Response.Write("<script>alert('An error occurred: " + ex.Message + "')</script>"); } } private void LoadRegistrationData() { try { da = new SqlDataAdapter("select * from registration", cs); DataSet dt = new DataSet(); da.Fill(dt); for (int i = 0; i < dt.Tables[0].Rows.Count; i++) { registration.Items.Add(dt.Tables[0].Rows[i][1] + " - " + dt.Tables[0].Rows[i][2]); } } catch (Exception ex) { // Handle any exceptions Response.Write("<script>alert('An error occurred: " + ex.Message + "')</script>"); } } protected void search_Click(object sender, EventArgs e) { try { DateTime startDate; DateTime endDate; string selectedItem = registration.SelectedItem.Text; string[] parts = selectedItem.Split('-'); if (DateTime.TryParse(TextBox1.Text, out startDate) && DateTime.TryParse(TextBox2.Text, out endDate)) { // Construct the SQL query to fetch the data with a join on "medicine" table string query = "SELECT o.S_no, o.Tag_no, o.Date, m.Medicine_name, o.Dose, o.OD_TID_BID " + "FROM observation o " + "INNER JOIN medicine m ON o.Medicine_id = m.ID " + "WHERE o.Tag_no = @TagNo AND o.Date >= @StartDate AND o.Date <= @EndDate"; using (SqlConnection con = new SqlConnection(cs)) using (SqlCommand cmd = new SqlCommand(query, con)) { cmd.Parameters.Add(new SqlParameter("@TagNo", registration.SelectedItem)); cmd.Parameters.Add(new SqlParameter("@StartDate", startDate)); cmd.Parameters.Add(new SqlParameter("@EndDate", endDate)); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); Gridview2.DataSource = dt; Gridview2.DataBind(); } } } catch (Exception ex) { Response.Write("<script>alert('An error occurred: " + ex.Message + "')</script>"); } } protected void submit_Click(object sender, EventArgs e) { try { string selectedItem = registration.SelectedItem.Text; string[] parts = selectedItem.Split('-'); if (parts.Length >= 2) { int tagno = int.Parse(parts[0].Trim()); string animalCategory = parts[1].Trim(); // Query to retrieve registration data based on tagno and animal category string registrationQuery = "SELECT * FROM registration WHERE Tag_no = @TagNo AND animal_category = @AnimalCategory"; using (SqlConnection connection = new SqlConnection(cs)) { connection.Open(); using (SqlCommand command = new SqlCommand(registrationQuery, connection)) { command.Parameters.AddWithValue("@TagNo", tagno); command.Parameters.AddWithValue("@AnimalCategory", animalCategory); SqlDataAdapter da = new SqlDataAdapter(command); DataTable dt = new DataTable(); da.Fill(dt); if (dt.Rows.Count > 0) { label11.Text = dt.Rows[0]["owner_name"].ToString(); label12.Text = dt.Rows[0]["owner_mobile_no"].ToString(); label13.Text = dt.Rows[0]["owner_address"].ToString(); label1.Text = dt.Rows[0]["animal_category"].ToString(); label2.Text = dt.Rows[0]["animal_arrived"].ToString(); label3.Text = dt.Rows[0]["species"].ToString(); label4.Text = dt.Rows[0]["age"].ToString(); label5.Text = dt.Rows[0]["gender"].ToString(); label6.Text = dt.Rows[0]["color"].ToString(); label7.Text = dt.Rows[0]["weight"].ToString(); label8.Text = dt.Rows[0]["dob"].ToString(); label9.Text = dt.Rows[0]["disease_diagnosis"].ToString(); label10.Text = dt.Rows[0]["prognosis"].ToString(); } else { Response.Write("<script>alert('Please insert Correct Tag no.')</script>"); } } } string query = "SELECT o.S_no, o.Tag_no, o.Date, m.Medicine_name, o.Dose, o.OD_TID_BID " + "FROM observation o " + "INNER JOIN medicine m ON o.Medicine_id = m.ID " + "WHERE o.Tag_no = @TagNo " + "ORDER BY o.S_no ASC"; using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["gav"].ConnectionString)) using (SqlCommand cmd = new SqlCommand(query, con)) { cmd.Parameters.Add(new SqlParameter("@TagNo", tagno)); SqlDataAdapter da = new SqlDataAdapter(cmd); DataTable dt1 = new DataTable(); da.Fill(dt1); Gridview2.DataSource = dt1; Gridview2.DataBind(); } using (SqlConnection connection = new SqlConnection(cs)) { connection.Open(); // Check if tag_no exists in the discharge database table string dischargeQuery = "SELECT Date, Time, Discharge FROM discharge WHERE Tag_no = @tag_no"; SqlCommand dischargeCommand = new SqlCommand(dischargeQuery, connection); dischargeCommand.Parameters.AddWithValue("@tag_no", tagno); SqlDataReader dischargeReader = dischargeCommand.ExecuteReader(); if (dischargeReader.Read()) { label15.Text = dischargeReader["Date"].ToString(); label17.Text = dischargeReader["Time"].ToString(); label19.Text = dischargeReader["Discharge"].ToString(); label14.Visible = true; label16.Visible = true; label18.Visible = true; label19.Visible = true; l1.Visible = true; } else { // No discharge data found, so let's check the death table dischargeReader.Close(); // Close the dischargeReader // Check if tag_no exists in the death database table string deathQuery = "SELECT Date, Time, Reason FROM death WHERE Tag_no = @tag_no"; SqlCommand deathCommand = new SqlCommand(deathQuery, connection); deathCommand.Parameters.AddWithValue("@tag_no", tagno); SqlDataReader deathReader = deathCommand.ExecuteReader(); if (deathReader.Read()) { label15.Text = deathReader["Date"].ToString(); label17.Text = deathReader["Time"].ToString(); label21.Text = deathReader["Reason"].ToString(); label14.Visible = true; label16.Visible = true; label20.Visible = true; label21.Visible = true; l2.Visible = true; // Hide the discharge-related labels label18.Visible = false; label19.Visible = false; } else { // Handle the case where tag_no is not found in either table } deathReader.Close(); // Close the deathReader } string uploadQuery = "SELECT * FROM upload WHERE Tag_no = @TagNo"; using (SqlConnection con = new SqlConnection(cs)) using (SqlCommand cmd = new SqlCommand(uploadQuery, con)) { cmd.Parameters.Add(new SqlParameter("@TagNo", tagno)); SqlDataAdapter uploadDa = new SqlDataAdapter(cmd); DataTable uploadDt = new DataTable(); uploadDa.Fill(uploadDt); Gridview4.DataSource = uploadDt; Gridview4.DataBind(); } } BindInvestigationData(); SaveToCSV(); } } catch (Exception ex) { Response.Write("<script>alert('An error occurred: " + ex.Message + "')</script>"); } } private void BindInvestigationData() { string tagNo = registration.Text; DataTable dtInvestigations = GetInvestigationData(tagNo); rptInvestigations.DataSource = dtInvestigations; rptInvestigations.DataBind(); } private DataTable GetInvestigationData(string tagNo) { DataTable dt = new DataTable(); // Connection string - Replace with your actual connection string string connectionString = ConfigurationManager.ConnectionStrings["gav"].ConnectionString; using (SqlConnection connection = new SqlConnection(connectionString)) { // Query to fetch data from the Investigation table based on Tag_no string query = "SELECT Date, Special_observation FROM investigation WHERE Tag_no = @TagNo"; using (SqlCommand command = new SqlCommand(query, connection)) { // Add parameters to the query command.Parameters.AddWithValue("@TagNo", tagNo); // Open the connection connection.Open(); // Execute the query and load data into DataTable using (SqlDataAdapter adapter = new SqlDataAdapter(command)) { adapter.Fill(dt); } } } return dt; } private void SaveToCSV() { try { string dateTime = DateTime.Now.ToString("yyyy-MM-dd"); string time = DateTime.Now.ToString("HH:mm:ss"); string tittle = "Animal Detail Master"; // Get additional details (you may customize this part) string details = "Additional details go here."; // 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