File manager - Edit - G:/PleskVhosts/indiaminerals.in/vgm.INFOFIXDEVELOPERS.COM/admin/Discharge.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; using System.Data.SqlClient; using System.Configuration; using WebApp.LIBS; using System.IO; namespace VGM.admin { public partial class Discharge : BasePageClass { string cs = ConfigurationManager.ConnectionStrings["gav"].ConnectionString; SqlConnection con; SqlCommand cmd; SqlDataAdapter da; protected void Page_Load(object sender, EventArgs e) { } protected void submitButton_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>"); } } protected void submitButton2_Click1(object sender, EventArgs e) { string cs = ConfigurationManager.ConnectionStrings["gav"].ConnectionString; try { using (SqlConnection con = new SqlConnection(cs)) { con.Open(); string discharge; if (radio1.Checked) { discharge = "Discharge by Owner"; } else if(radio2.Checked) { discharge = "Transfer to Own Gaushala"; // Show TextBox1 only when "Transfer to Gaushala" } else { discharge = "Transfer to Other Gaushala"; TextBox1.Focus(); } string insertQuery = "INSERT INTO discharge (Tag_no, Date, Time, Discharge, gaushala_name) VALUES (@Tag_no, @Date, @Time, @Discharge, @gaushala_name)"; using (SqlCommand cmd = new SqlCommand(insertQuery, con)) { cmd.Parameters.Add("@Tag_no", SqlDbType.VarChar).Value = registration.Text; cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = Convert.ToDateTime(date.Text); cmd.Parameters.Add("@Time", SqlDbType.VarChar).Value = timePicker.Text; cmd.Parameters.Add("@Discharge", SqlDbType.VarChar).Value = discharge; cmd.Parameters.Add("@gaushala_name", SqlDbType.VarChar).Value = TextBox1.Text; cmd.ExecuteNonQuery(); } if(radio3.Checked) { string Close = "Other"; string updateQuery = "UPDATE registration SET status = @Close WHERE tag_no = @Tag_no"; using (SqlCommand updateCmd = new SqlCommand(updateQuery, con)) { updateCmd.Parameters.Add("@Close", SqlDbType.VarChar).Value = Close; updateCmd.Parameters.Add("@Tag_no", SqlDbType.VarChar).Value = registration.Text; updateCmd.ExecuteNonQuery(); } } else { string Close = "Discharge"; string updateQuery = "UPDATE registration SET status = @Close WHERE tag_no = @Tag_no"; using (SqlCommand updateCmd = new SqlCommand(updateQuery, con)) { updateCmd.Parameters.Add("@Close", SqlDbType.VarChar).Value = Close; updateCmd.Parameters.Add("@Tag_no", SqlDbType.VarChar).Value = registration.Text; updateCmd.ExecuteNonQuery(); } } // Redirect to Discharge_list.aspx after successful operations Response.Write("<script>alert('Data inserted successfully.'); window.location = 'Discharge_list.aspx';</script>"); } } catch (Exception ex) { Response.Write("<script>alert('An error occurred: " + ex.Message + "')</script>"); } SaveToCSV(); } private void SaveToCSV() { try { string dateTime = DateTime.Now.ToString("yyyy-MM-dd"); string time = DateTime.Now.ToString("HH:mm:ss"); string tittle = "Discharge"; // Get additional details (you may customize this part) string details; if(radio1.Checked) { details = $"Tag no. {registration.Text} Discharge By Owner"; } else { details = $"Tag no. {registration.Text} Tranfer to Gaushala"; } // 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.04 |
proxy
|
phpinfo
|
Settings