File manager - Edit - G:/PleskVhosts/indiaminerals.in/vgm.INFOFIXDEVELOPERS.COM/admin/DetailGridView.aspx.cs
Back
using DocumentFormat.OpenXml.Office2010.Excel; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.IO; using System.Linq; using System.Net.Http; using System.Threading.Tasks; using System.Web; using System.Web.Services; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using WebApp.LIBS; using static VGM.admin.DetailGridView; namespace VGM.admin { public partial class DetailGridView : BasePageClass { string cs = ConfigurationManager.ConnectionStrings["Gav"].ConnectionString; SqlDataAdapter da; protected void Page_Load(object sender, EventArgs e) { } [WebMethod] public static string GetCompanyData() { try { string cs = ConfigurationManager.ConnectionStrings["Gav"].ConnectionString; List<Dictionary<string, string>> data = new List<Dictionary<string, string>>(); using (SqlConnection connection = new SqlConnection(cs)) { connection.Open(); string selectQuery = "SELECT Id, FORMAT(JoiningDate, 'dd-MMM-yyyy') AS JoiningDate , Name, Contact_no, BirthDate, Address FROM detailform"; using (SqlCommand cmd = new SqlCommand(selectQuery, connection)) { using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { List<string> columns = new List<string>(); for (int i = 0; i < reader.FieldCount; i++) { columns.Add(reader.GetName(i)); } while (reader.Read()) { Dictionary<string, string> row = new Dictionary<string, string>(); foreach (string column in columns) { row[column] = reader[column].ToString(); } data.Add(row); } } } } } string jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(data); return jsonData; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Error in GetCompanyData: " + ex.Message); return "An error occurred while retrieving data from the database"; } } public class ContactInfo { public string Name { get; set; } public string ContactNo { get; set; } public string Status { get; set; } } protected void Send_Click(object sender, EventArgs e) { try { string[] ids = example1Id.Value.Split(','); List<ContactInfo> selectedContacts = new List<ContactInfo>(); foreach (var id in ids) { string contactNo = GetContactNoFromId(id.Trim()); string name = GetNameFromId(id.Trim()); if (!string.IsNullOrEmpty(contactNo) && !string.IsNullOrEmpty(name)) { selectedContacts.Add(new ContactInfo { Name = name, ContactNo = contactNo, Status = "" }); } } if (selectedContacts.Count > 0) { if (string.IsNullOrWhiteSpace(Message.Text)) { ShowSweetAlert("Error", "Please enter message for sending", "error"); return; } var messageTemplate = Message.Text; bool hasMessage = !string.IsNullOrEmpty(messageTemplate); foreach (var contact in selectedContacts) { var personalizedMessage = messageTemplate.Replace("{name}", contact.Name); if (hasMessage) { string whatsappUrl = $"https://wa.me/{contact.ContactNo}?text={Uri.EscapeDataString(personalizedMessage)}"; ScriptManager.RegisterStartupScript(this, this.GetType(), "OpenWhatsapp_" + contact.ContactNo, $@" setTimeout(function() {{ var newWindow = window.open('{whatsappUrl}', '_blank'); if (!newWindow) {{ alert('Popup blocked! Please allow popups to open WhatsApp.'); }} }}, 500);", true); contact.Status = "Successfully Sent"; } } Message.Text = ""; example1Id.Value = ""; } else { Response.Write("<script>alert('Please select at least one contact to send the message.');</script>"); Message.Text = ""; example1Id.Value = ""; } } catch (Exception ex) { Response.Write($"<script>alert('An error occurred: {ex.Message}');</script>"); } } protected void ShowSweetAlert(string title, string message, string icon) { string script = $@" Swal.fire({{ text: '{message}', icon: '{icon}', toast: true, position: 'top-right', showConfirmButton: false, timer: 5000, customClass: {{ popup: 'swal2-small' }} }});"; ScriptManager.RegisterStartupScript(this, GetType(), "alert", script, true); } private string GetContactNoFromId(string id) { string contactNo = string.Empty; string query = $"SELECT Contact_no FROM detailform WHERE Id = @Id"; string connectionString = ConfigurationManager.ConnectionStrings["Gav"].ConnectionString; using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@Id", id); connection.Open(); object result = command.ExecuteScalar(); if (result != null) { contactNo = result.ToString(); } } } return contactNo; } private string GetNameFromId(string id) { string name = string.Empty; string query = $"SELECT Name FROM detailform WHERE Id = @Id"; string connectionString = ConfigurationManager.ConnectionStrings["Gav"].ConnectionString; using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@Id", id); connection.Open(); object result = command.ExecuteScalar(); if (result != null) { name = result.ToString(); } } } return name; } protected System.Drawing.Color GetStatusColor(object dataItem) { if (dataItem != null && dataItem is ContactInfo) { ContactInfo contact = (ContactInfo)dataItem; if (contact.Status == "Successfully Sent") { return System.Drawing.Color.Green; } else if (contact.Status == "Failed") { return System.Drawing.Color.Red; } } return System.Drawing.Color.Black; } protected void Close_Click(object sender, EventArgs e) { mpe.Hide(); } } }
| ver. 1.4 |
Github
|
.
| PHP 7.3.33 | Generation time: 0.05 |
proxy
|
phpinfo
|
Settings