Line 1: using System;
Line 2: using System.Configuration;
Line 3: using System.Data;
Line 4: using System.Data.SqlClient;
Line 5: using System.IO;
Line 6: using System.Linq;
Line 7: using System.Net;
Line 8: using System.Net.Mail;
Line 9: using System.Security.Cryptography;
Line 10: using System.Text;
Line 11: using System.Threading;
Line 12: using System.Web;
Line 13: using System.Web.Security;
Line 14: using System.Web.UI;
Line 15: using System.Web.UI.HtmlControls;
Line 16: using System.Web.UI.WebControls;
Line 17: using System.Web.UI.WebControls.WebParts;
Line 18: using System.Xml.Linq;
Line 19:
Line 20: public class MasterClass
Line 21: {
Line 22: public static string CustomerSessionId;
Line 23:
Line 24: public static string GetProjectName()
Line 25: {
Line 26: return MasterClass.StringValue("SELECT ProjectName FROM ProjectDetail order by Auto");
Line 27: }
Line 28:
Line 29: public static string GetMobileNo()
Line 30: {
Line 31: return MasterClass.StringValue("SELECT MobileNo FROM ProjectDetail order by Auto");
Line 32: }
Line 33:
Line 34: public static string GetEmail()
Line 35: {
Line 36: return MasterClass.StringValue("SELECT Email FROM ProjectDetail order by Auto");
Line 37: }
Line 38:
Line 39: public static string GetAddress()
Line 40: {
Line 41: return MasterClass.StringValue("SELECT Address FROM ProjectDetail order by Auto");
Line 42: }
Line 43:
Line 44: public static string GetWebsiteAddress()
Line 45: {
Line 46: return MasterClass.StringValue("SELECT WebsiteAddress FROM ProjectDetail order by Auto");
Line 47: }
Line 48: public static string ConvertDate(String Date)
Line 49: {
Line 50: if (Date != "")
Line 51: {
Line 52: Date = Date.Replace("/", "-");
Line 53: String[] NewDate = Date.Split('-');
Line 54: return (NewDate[1] + "-" + NewDate[0] + "-" + NewDate[2]);
Line 55: }
Line 56: else
Line 57: {
Line 58: return Date;
Line 59: }
Line 60: }
Line 61:
Line 62: public static int FillDDL(DropDownList DDl, string Sql, string DataTextField, string DataValueField)
Line 63: {
Line 64: int n = 0;
Line 65: SqlConnection sqlconn;
Line 66: sqlconn = new SqlConnection();
Line 67: sqlconn.ConnectionString = MasterClass.Getconnection();
Line 68: SqlCommand sqlcmd = new SqlCommand(Sql, sqlconn);
Line 69: SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
Line 70: DataSet ds = new DataSet();
Line 71: da.Fill(ds);
Line 72: DDl.DataSource = ds;
Line 73: DDl.DataTextField = DataTextField;
Line 74: DDl.DataValueField = DataValueField;
Line 75: DDl.DataBind();
Line 76: return (n);
Line 77: }
Line 78:
Line 79: public static int FillCheckBoxList(CheckBoxList Chk, string Sql, string DataTextField, string DataValueField)
Line 80: {
Line 81: int n = 0;
Line 82: SqlConnection sqlconn;
Line 83: sqlconn = new SqlConnection();
Line 84: sqlconn.ConnectionString = MasterClass.Getconnection();
Line 85: SqlCommand sqlcmd = new SqlCommand(Sql, sqlconn);
Line 86: SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
Line 87: DataSet ds = new DataSet();
Line 88: da.Fill(ds);
Line 89: Chk.DataSource = ds;
Line 90: Chk.DataTextField = DataTextField;
Line 91: Chk.DataValueField = DataValueField;
Line 92: Chk.DataBind();
Line 93: return (n);
Line 94: }
Line 95:
Line 96: public static DataTable Query(string sqlstr)
Line 97: {
Line 98: string ConnectionString = Getconnection();
Line 99: SqlConnection cn = new SqlConnection(ConnectionString);
Line 100: SqlDataAdapter adp = new SqlDataAdapter(sqlstr, cn);
Line 101: DataSet ds = new DataSet();
Line 102: adp.Fill(ds);
Line 103: DataTable dt = ds.Tables[0];
Line 104: return (dt);
Line 105: }
Line 106:
Line 107: public static string Getconnection()
Line 108: {
Line 109: //string ConnectionString = "Initial Catalog=Db_adityatutors;Data Source=103.143.46.56;User ID=Db_adityatutors;Pwd=Lp7~3no2";
Line 110: string ConnectionString = "Initial Catalog=Db_adityatutors;Data Source=103.120.178.33;User ID=Db_adityatutors;Pwd=F&2pgx48";
Line 111: return ConnectionString;
Line 112: }
Line 113:
Line 114: public static int NonQuery(string sqlstr)
Line 115: {
Line 116: string ConnectionString = Getconnection();
Line 117: SqlConnection cn = new SqlConnection(ConnectionString);
Line 118: cn.Open();
Line 119: SqlCommand cmd = new SqlCommand(sqlstr, cn);
Line 120: int n = cmd.ExecuteNonQuery();
Line 121: cn.Close();
Line 122: return (n);
Line 123: }
Line 124:
Line 125: public static int ScalerQuery(string sqlstr)
Line 126: {
Line 127: string ConnectionString = Getconnection();
Line 128: SqlConnection cn = new SqlConnection(ConnectionString);
Line 129: cn.Open();
Line 130: SqlCommand cmd = new SqlCommand(sqlstr, cn);
Line 131: int n = Convert.ToInt32(cmd.ExecuteScalar());
Line 132: cn.Close();
Line 133: return n;
Line 134: }
Line 135:
Line 136: public static string StringValue(string sqlstr)
Line 137: {
Line 138: string ConnectionString = Getconnection();
Line 139: SqlConnection cn = new SqlConnection(ConnectionString);
Line 140: cn.Open();
Line 141: SqlCommand cmd = new SqlCommand(sqlstr, cn);
Line 142: String n = Convert.ToString(cmd.ExecuteScalar());
Line 143: cn.Close();
Line 144: return n;
Line 145: }
Line 146:
Line 147: public static void ExporttoExcel(DataTable dt, string Name, string TitleName)
Line 148: {
Line 149: GridView GridView1 = new GridView();
Line 150: GridView1.AllowPaging = false;
Line 151: GridView1.DataSource = dt;
Line 152: GridView1.DataBind();
Line 153: if (GridView1.Rows.Count > 0)
Line 154: {
Line 155: HttpContext.Current.Response.Clear();
Line 156: HttpContext.Current.Response.Buffer = true;
Line 157: HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + Name + ".xls");
Line 158: HttpContext.Current.Response.Charset = "";
Line 159: HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
Line 160: StringWriter sw = new StringWriter();
Line 161: HtmlTextWriter hw = new HtmlTextWriter(sw);
Line 162:
Line 163: for (int i = 0; i < GridView1.Rows.Count; i++)
Line 164: {
Line 165: //Apply text style to each Row
Line 166: GridView1.Rows[i].Attributes.Add("class", "textmode");
Line 167: }
Line 168: GridView1.RenderControl(hw);
Line 169:
Line 170: //style to format numbers to string
Line 171: string style = @"<style> .textmode { mso-number-format:\@; } </style>";
Line 172: HttpContext.Current.Response.Write(style);
Line 173: HttpContext.Current.Response.Output.Write(TitleName);
Line 174: HttpContext.Current.Response.Output.Write("\n\n");
Line 175: HttpContext.Current.Response.Output.Write(sw.ToString());
Line 176: HttpContext.Current.Response.Flush();
Line 177: HttpContext.Current.Response.End();
Line 178: }
Line 179: }
Line 180:
Line 181: public static string Encrypt(string pstrText)
Line 182: {
Line 183: string pstrEncrKey = "JSDG345$#%asd;#";
Line 184: byte[] byKey = { };
Line 185: byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
Line 186: byKey = System.Text.Encoding.UTF8.GetBytes(pstrEncrKey.Substring(0, 8));
Line 187: DESCryptoServiceProvider des = new DESCryptoServiceProvider();
Line 188: byte[] inputByteArray = Encoding.UTF8.GetBytes(pstrText);
Line 189: MemoryStream ms = new MemoryStream();
Line 190: CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);
Line 191: cs.Write(inputByteArray, 0, inputByteArray.Length);
Line 192: cs.FlushFinalBlock();
Line 193: return Convert.ToBase64String(ms.ToArray());
Line 194: }
Line 195:
Line 196: public static string Decrypt(string pstrText)
Line 197: {
Line 198: pstrText = pstrText.Replace(" ", "+");
Line 199: string pstrDecrKey = "JSDG345$#%asd;#";
Line 200: byte[] byKey = { };
Line 201: byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
Line 202: byte[] inputByteArray = new byte[pstrText.Length];
Line 203:
Line 204: byKey = System.Text.Encoding.UTF8.GetBytes(pstrDecrKey.Substring(0, 8));
Line 205: DESCryptoServiceProvider des = new DESCryptoServiceProvider();
Line 206: inputByteArray = Convert.FromBase64String(pstrText);
Line 207: MemoryStream ms = new MemoryStream();
Line 208: CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
Line 209: cs.Write(inputByteArray, 0, inputByteArray.Length);
Line 210: cs.FlushFinalBlock();
Line 211: System.Text.Encoding encoding = System.Text.Encoding.UTF8;
Line 212: return encoding.GetString(ms.ToArray());
Line 213: }
Line 214:
Line 215: public static void SendSms(string MobileNo, string Msg, string TemplateId)
Line 216: {
Line 217: try
Line 218: {
Line 219: //string Abc = HttpContext.Current.Request.Url.Host;
Line 220: //if (Abc != "localhost")
Line 221: //{
Line 222: //string senderusername = "smst";
Line 223: //string senderpassword = "123456";
Line 224: //string senderid = "ADITYA";
Line 225: string sURL;
Line 226: StreamReader objReader;
Line 227: //http://103.16.101.52:8080/sendsms/bulksms?username=smst-aditya&password=123456&type=0&dlr=1&destination=9838248479&source=ADITYA&message=test
Line 228: //sURL = "http://103.16.101.52:8080/sendsms/bulksms?username=smst-aditya&password=123456&type=0&dlr=1&destination=" + MobileNo + "&source=ADITYA&message=" + Msg + "";
Line 229:
Line 230: sURL = "http://103.16.101.52:/sendsms/bulksms?username=smst-aditya&password=123456&type=0&dlr=1&destination=" + MobileNo + "&source=ADITYT&message=" + Msg + "&entityid=1601100000000002110&tempid=" + TemplateId;
Line 231: System.Net.WebRequest wrGETURL;
Line 232: wrGETURL = System.Net.WebRequest.Create(sURL);
Line 233:
Line 234: Stream objStream;
Line 235: objStream = wrGETURL.GetResponse().GetResponseStream();
Line 236: objReader = new StreamReader(objStream);
Line 237: objReader.Close();
Line 238: //}
Line 239: }
Line 240: catch (Exception ex)
Line 241: {
Line 242:
Line 243: }
Line 244: }
Line 245:
Line 246: public static void ExporttoExcel(DataTable dt, string Name)
Line 247: {
Line 248: GridView GridView1 = new GridView();
Line 249: GridView1.AllowPaging = false;
Line 250: GridView1.DataSource = dt;
Line 251: GridView1.DataBind();
Line 252: if (GridView1.Rows.Count > 0)
Line 253: {
Line 254: HttpContext.Current.Response.Clear();
Line 255: HttpContext.Current.Response.Buffer = true;
Line 256: HttpContext.Current.Response.AddHeader("content-disposition",
Line 257: "attachment;filename=" + Name + ".xls");
Line 258: HttpContext.Current.Response.Charset = "";
Line 259: HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
Line 260: StringWriter sw = new StringWriter();
Line 261: HtmlTextWriter hw = new HtmlTextWriter(sw);
Line 262:
Line 263: for (int i = 0; i < GridView1.Rows.Count; i++)
Line 264: {
Line 265: //Apply text style to each Row
Line 266: GridView1.Rows[i].Attributes.Add("class", "textmode");
Line 267: }
Line 268: GridView1.RenderControl(hw);
Line 269:
Line 270: //style to format numbers to string
Line 271: string style = @"<style> .textmode { mso-number-format:\@; } </style>";
Line 272: HttpContext.Current.Response.Write(style);
Line 273: HttpContext.Current.Response.Output.Write(sw.ToString());
Line 274: HttpContext.Current.Response.Flush();
Line 275: HttpContext.Current.Response.End();
Line 276: }
Line 277: }
Line 278:
Line 279: public static string RemoveSpecialCharacters(string str)
Line 280: {
Line 281: StringBuilder sb = new StringBuilder();
Line 282: foreach (char c in str)
Line 283: {
Line 284: if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '.' || c == '_')
Line 285: {
Line 286: sb.Append(c);
Line 287: }
Line 288: }
Line 289: return sb.ToString();
Line 290: }
Line 291:
Line 292: private static Random random = new Random();
Line 293:
Line 294: public static string Gethostname()
Line 295: {
Line 296: string host = HttpContext.Current.Request.Url.Host.ToLower();
Line 297: if (host != "localhost")
Line 298: host = "https://adityatutors.com/";
Line 299: else
Line 300: host = "http://" + host + ":" + HttpContext.Current.Request.Url.Port + "/";
Line 301: return (host);
Line 302: }
Line 303: }
|