public static List <Poetry> returnPoetry(string meterName) { List <Poetry> pt = new List <Poetry>(); if (!string.IsNullOrEmpty(meterName)) { MySqlConnection myConn; MySqlDataReader dataReader; myConn = new MySqlConnection(TaqtiController.connectionString); myConn.Open(); MySqlCommand cmd = new MySqlCommand(TaqtiController.connectionString); cmd = myConn.CreateCommand(); //cmd.CommandText = "select * from Poetry where meterID like '%" + meterName + "%' order by RAND() limit 4"; cmd.CommandText = "SELECT a.* FROM poetry a INNER JOIN (SELECT title,poet,meterID FROM poetry where meterID like @meterName GROUP BY poet order by rand()) b ON a.title = b.title and a.meterID = b.meterID limit 0,4"; cmd.Parameters.AddWithValue("@meterName", "%" + meterName.Trim() + "%"); dataReader = cmd.ExecuteReader(); int typeId = -1;; while (dataReader.Read()) { Poetry p = new Poetry(); p.id = dataReader.GetInt32(0); p.poet = dataReader.GetString(1); p.title = dataReader.GetString(2); typeId = dataReader.GetInt32(3); p.meters = dataReader.GetString(5); if (typeId == 0) { p.type = "غزل"; } else if (typeId == 1) { p.type = "نظم"; } else if (typeId == 2) { p.type = "رباعی"; } else if (typeId == 3) { p.type = "قطعہ"; } else if (typeId == 4) { p.type = "آزاد نظم"; } else if (typeId == 5) { p.type = "شعر"; } pt.Add(p); } myConn.Close(); } return(pt); }
public ActionResult Poetry(Poetry pt) { if (User.Identity.Name.Equals("Mahdi") || User.Identity.Name.Equals("zeesh")) { myConn = new MySqlConnection(TaqtiController.connectionString); myConn.Open(); MySqlCommand cmd = new MySqlCommand(TaqtiController.connectionString); cmd = myConn.CreateCommand(); cmd.CommandText = "select max(id) as id from Poetry;"; dataReader = cmd.ExecuteReader(); int id3 = 0; while (dataReader.Read()) { id3 = dataReader.GetInt32(0); } myConn.Close(); MySqlConnection myConn2 = new MySqlConnection(TaqtiController.connectionString); MySqlCommand cmd2 = new MySqlCommand(TaqtiController.connectionString); myConn2.Open(); string type = ""; if (pt.type.Equals("غزل")) { type = "0"; } else if (pt.type.Equals("نظم")) { type = "1"; } else if (pt.type.Equals("رباعی")) { type = "2"; } else if (pt.type.Equals("قطعہ")) { type = "3"; } else if (pt.type.Equals("آزاد نظم")) { type = "4"; } else if (pt.type.Equals("شعر")) { type = "5"; } cmd2 = myConn2.CreateCommand(); cmd2.CommandText = "INSERT into Poetry(ID,poet,type,title,text,meterID) VALUES (@id,@poet,@type,@title,@text,@meterID)"; cmd2.Parameters.AddWithValue("@id", id3 + 1); cmd2.Parameters.AddWithValue("@poet", (string)pt.poet); cmd2.Parameters.AddWithValue("@type", (string)type); cmd2.Parameters.AddWithValue("@title", (string)pt.title); cmd2.Parameters.AddWithValue("@text", (string)pt.text); cmd2.Parameters.AddWithValue("@meterID", (string)pt.meters); cmd2.ExecuteNonQuery(); myConn2.Close(); // TempData["Inp"] = data; myConn = new MySqlConnection(TaqtiController.connectionString); myConn.Open(); cmd = new MySqlCommand(TaqtiController.connectionString); cmd = myConn.CreateCommand(); cmd.CommandText = "select max(id) as id from dataEntry;"; dataReader = cmd.ExecuteReader(); int id4 = 0; while (dataReader.Read()) { id4 = dataReader.GetInt32(0); } myConn.Close(); myConn2 = new MySqlConnection(TaqtiController.connectionString); cmd2 = new MySqlCommand(TaqtiController.connectionString); myConn2.Open(); cmd2 = myConn2.CreateCommand(); cmd2.CommandText = "INSERT into dataEntry(ID,name,whichtable,whichid,time) VALUES (@id,@name,@table,@tableid,@time)"; cmd2.Parameters.AddWithValue("@id", id4 + 1); cmd2.Parameters.AddWithValue("@name", (string)User.Identity.Name); cmd2.Parameters.AddWithValue("@table", (string)"Poetry"); cmd2.Parameters.AddWithValue("@tableid", id3); cmd2.Parameters.AddWithValue("@time", DateTime.Now); cmd2.ExecuteNonQuery(); myConn2.Close(); return RedirectToAction("Poetry"); } else { return RedirectToAction("Error"); } }
public static bool find(string meterName) { List <Poetry> pt = new List <Poetry>(); MySqlConnection myConn; MySqlDataReader dataReader; myConn = new MySqlConnection(TaqtiController.connectionString); myConn.Open(); MySqlCommand cmd = new MySqlCommand(TaqtiController.connectionString); cmd = myConn.CreateCommand(); cmd.CommandText = "select * from Poetry where meterID like @meterName order by id DESC"; cmd.Parameters.AddWithValue("@meterName", "%" + meterName + "%"); dataReader = cmd.ExecuteReader(); int typeId = -1;; while (dataReader.Read()) { Poetry p = new Poetry(); p.id = dataReader.GetInt32(0); p.poet = dataReader.GetString(1); p.title = dataReader.GetString(2); typeId = dataReader.GetInt32(3); p.meters = dataReader.GetString(5); if (typeId == 0) { p.type = "غزل"; } else if (typeId == 1) { p.type = "نظم"; } else if (typeId == 2) { p.type = "رباعی"; } else if (typeId == 3) { p.type = "قطعہ"; } else if (typeId == 4) { p.type = "آزاد نظم"; } else if (typeId == 5) { p.type = "شعر"; } pt.Add(p); } myConn.Close(); if (pt.Count > 0) { return(true); } else { return(false); } }
public static List<Poetry> returnPoetry(string meterName) { List<Poetry> pt = new List<Poetry>(); if (!string.IsNullOrEmpty(meterName)) { MySqlConnection myConn; MySqlDataReader dataReader; myConn = new MySqlConnection(TaqtiController.connectionString); myConn.Open(); MySqlCommand cmd = new MySqlCommand(TaqtiController.connectionString); cmd = myConn.CreateCommand(); //cmd.CommandText = "select * from Poetry where meterID like '%" + meterName + "%' order by RAND() limit 4"; cmd.CommandText = "SELECT a.* FROM poetry a INNER JOIN (SELECT title,poet,meterID FROM poetry where meterID like @meterName GROUP BY poet order by rand()) b ON a.title = b.title and a.meterID = b.meterID limit 0,4"; cmd.Parameters.AddWithValue("@meterName", "%" + meterName.Trim() + "%"); dataReader = cmd.ExecuteReader(); int typeId = -1; ; while (dataReader.Read()) { Poetry p = new Poetry(); p.id = dataReader.GetInt32(0); p.poet = dataReader.GetString(1); p.title = dataReader.GetString(2); typeId = dataReader.GetInt32(3); p.meters = dataReader.GetString(5); if (typeId == 0) { p.type = "غزل"; } else if (typeId == 1) { p.type = "نظم"; } else if (typeId == 2) { p.type = "رباعی"; } else if (typeId == 3) { p.type = "قطعہ"; } else if (typeId == 4) { p.type = "آزاد نظم"; } else if (typeId == 5) { p.type = "شعر"; } pt.Add(p); } myConn.Close(); } return pt; }
public static bool find(string meterName) { List<Poetry> pt = new List<Poetry>(); MySqlConnection myConn; MySqlDataReader dataReader; myConn = new MySqlConnection(TaqtiController.connectionString); myConn.Open(); MySqlCommand cmd = new MySqlCommand(TaqtiController.connectionString); cmd = myConn.CreateCommand(); cmd.CommandText = "select * from Poetry where meterID like @meterName order by id DESC"; cmd.Parameters.AddWithValue("@meterName", "%"+ meterName + "%"); dataReader = cmd.ExecuteReader(); int typeId = -1; ; while (dataReader.Read()) { Poetry p = new Poetry(); p.id = dataReader.GetInt32(0); p.poet = dataReader.GetString(1); p.title = dataReader.GetString(2); typeId = dataReader.GetInt32(3); p.meters = dataReader.GetString(5); if (typeId == 0) { p.type = "غزل"; } else if (typeId == 1) { p.type = "نظم"; } else if (typeId == 2) { p.type = "رباعی"; } else if (typeId == 3) { p.type = "قطعہ"; } else if (typeId == 4) { p.type = "آزاد نظم"; } else if (typeId == 5) { p.type = "شعر"; } pt.Add(p); } myConn.Close(); if (pt.Count > 0) return true; else return false; }
public ActionResult Search(string searchString) { List<Poetry> pt = new List<Poetry>(); MySqlConnection myConn; MySqlDataReader dataReader; myConn = new MySqlConnection(TaqtiController.connectionString); myConn.Open(); MySqlCommand cmd = new MySqlCommand(TaqtiController.connectionString); cmd = myConn.CreateCommand(); cmd.CommandText = "select * from Poetry where text like @search order by id DESC"; cmd.Parameters.AddWithValue("@search","%"+searchString+"%"); dataReader = cmd.ExecuteReader(); int typeId = -1; ; while (dataReader.Read()) { Poetry p = new Poetry(); p.id = dataReader.GetInt32(0); p.poet = dataReader.GetString(1); p.title = dataReader.GetString(2); p.text = dataReader.GetString(4); typeId = dataReader.GetInt32(3); p.meters = dataReader.GetString(5); //string pattern = searchString; string pattern = "^.*" + searchString + ".*$"; Regex rg = new Regex(pattern,RegexOptions.Multiline); string k = ""; int limit = 30; foreach (Match m in rg.Matches(p.text)) { k += m.Value.Replace(searchString, "<b>" + searchString + "</b>") + "<br>"; //if(m.Index > limit) //{ // k += "... " + p.text.Substring(m.Index - limit, limit + searchString.Length).Replace(searchString,"<b>" + searchString + "</b>") + " ... "; //} //else if(p.text.Length > limit + m.Index) //{ // k += p.text.Substring(0, searchString.Length + limit ).Replace(searchString, "<b>" + searchString + "</b>") + " ... "; //} //else //{ // k += "... " + p.text.Substring(0, m.Index + searchString.Length).Replace(searchString, "<b>" + searchString + "</b>") + " ... "; //} } p.text = k; if (typeId == 0) { p.type = "غزل"; } else if (typeId == 1) { p.type = "نظم"; } else if (typeId == 2) { p.type = "رباعی"; } else if (typeId == 3) { p.type = "قطعہ"; } else if (typeId == 4) { p.type = "آزاد نظم"; } else if (typeId == 5) { p.type = "شعر"; } p.searchString = searchString; pt.Add(p); } myConn.Close(); return View(pt); }
public ActionResult Poetry(int id,string searchString) { myConn = new MySqlConnection(connectionString); myConn.Open(); MySqlCommand cmd = new MySqlCommand(connectionString); Poetry p = new Poetry(); int typeId = -1; cmd = myConn.CreateCommand(); cmd.CommandText = "select * from poetry where id = @id;"; cmd.Parameters.AddWithValue("@id", id + 65536); dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { p.searchString = searchString; p.id = dataReader.GetInt32(0); p.poet = dataReader.GetString(1); p.title = dataReader.GetString(2); typeId = dataReader.GetInt32(3); p.text = dataReader.GetString(4); p.meters = dataReader.GetString(5); if (typeId == 0) { p.type = "غزل"; } else if (typeId == 1) { p.type = "نظم"; } else if (typeId == 2) { p.type = "رباعی"; } else if (typeId == 3) { p.type = "قطعہ"; } else if (typeId == 4) { p.type = "آزاد نظم"; } else if (typeId == 5) { p.type = "شعر"; } } myConn.Close(); return View(p); }
public ActionResult Meters(string meter) { List<Poetry> pt = new List<Poetry>(); MySqlConnection myConn; MySqlDataReader dataReader; myConn = new MySqlConnection(TaqtiController.connectionString); myConn.Open(); MySqlCommand cmd = new MySqlCommand(TaqtiController.connectionString); cmd = myConn.CreateCommand(); cmd.CommandText = "select * from Poetry where meterID like @met order by id DESC"; cmd.Parameters.AddWithValue("@met", "%" + meter.Replace("_", "/").Trim() + "%"); dataReader = cmd.ExecuteReader(); int typeId = -1; while (dataReader.Read()) { Poetry p = new Poetry(); p.id = dataReader.GetInt32(0); p.poet = dataReader.GetString(1); p.title = dataReader.GetString(2); typeId = dataReader.GetInt32(3); p.meters = dataReader.GetString(5); if (typeId == 0) { p.type = "غزل"; } else if (typeId == 1) { p.type = "نظم"; } else if (typeId == 2) { p.type = "رباعی"; } else if (typeId == 3) { p.type = "قطعہ"; } else if (typeId == 4) { p.type = "آزاد نظم"; } else if (typeId == 5) { p.type = "شعر"; } pt.Add(p); } myConn.Close(); if (pt.Count == 0) { return RedirectToAction("MeterNotFound","Examples"); } else { return View(pt); } }
public ActionResult Index(int? page) { List<Poetry> pt = new List<Poetry>(); MySqlConnection myConn; MySqlDataReader dataReader; myConn = new MySqlConnection(TaqtiController.connectionString); myConn.Open(); MySqlCommand cmd = new MySqlCommand(TaqtiController.connectionString); cmd = myConn.CreateCommand(); int maxCount = 1; int maxPages = 1; int residue = 0; cmd.CommandText = "select count(id) from Poetry;"; dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { maxCount = dataReader.GetInt32(0); } myConn.Close(); maxPages = maxCount / 15; residue = maxCount - maxPages * 15; if (residue > 0) { maxPages = maxPages + 1; } if (page == null || page == 1) { MySqlConnection myConn2; MySqlDataReader dataReader2; myConn2 = new MySqlConnection(TaqtiController.connectionString); myConn2.Open(); MySqlCommand cmd2 = new MySqlCommand(TaqtiController.connectionString); cmd2 = myConn2.CreateCommand(); cmd2.CommandText = "select * from Poetry order by id DESC limit 0,15"; dataReader2 = cmd2.ExecuteReader(); int typeId = -1; ; while (dataReader2.Read()) { Poetry p = new Poetry(); p.id = dataReader2.GetInt32(0); p.poet = dataReader2.GetString(1); p.title = dataReader2.GetString(2); p.text = dataReader2.GetString(4); typeId = dataReader2.GetInt32(3); p.meters = dataReader2.GetString(5); if (typeId == 0) { p.type = "غزل"; } else if (typeId == 1) { p.type = "نظم"; } else if (typeId == 2) { p.type = "رباعی"; } else if (typeId == 3) { p.type = "قطعہ"; } else if (typeId == 4) { p.type = "آزاد نظم"; } else if (typeId == 5) { p.type = "شعر"; } p.maxpages = maxPages; p.currentPage = 1; pt.Add(p); } myConn2.Close(); } else { MySqlConnection myConn2; MySqlDataReader dataReader2; myConn2 = new MySqlConnection(TaqtiController.connectionString); myConn2.Open(); MySqlCommand cmd2 = new MySqlCommand(TaqtiController.connectionString); cmd2 = myConn2.CreateCommand(); cmd2.CommandText = "select * from Poetry order by id DESC limit @init,@count"; if (page == maxPages && residue > 0) { cmd2.Parameters.AddWithValue("@init", (page - 1) * 15); cmd2.Parameters.AddWithValue("@count", residue); } else { cmd2.Parameters.AddWithValue("@init", (page - 1) * 15); cmd2.Parameters.AddWithValue("@count", 15); } dataReader2 = cmd2.ExecuteReader(); int typeId = -1; ; while (dataReader2.Read()) { Poetry p = new Poetry(); p.id = dataReader2.GetInt32(0); p.poet = dataReader2.GetString(1); p.title = dataReader2.GetString(2); typeId = dataReader2.GetInt32(3); p.text = dataReader2.GetString(4); p.meters = dataReader2.GetString(5); if (typeId == 0) { p.type = "غزل"; } else if (typeId == 1) { p.type = "نظم"; } else if (typeId == 2) { p.type = "رباعی"; } else if (typeId == 3) { p.type = "قطعہ"; } else if (typeId == 4) { p.type = "آزاد نظم"; } else if (typeId == 5) { p.type = "شعر"; } p.maxpages = maxPages; p.currentPage = (int)page; pt.Add(p); } myConn2.Close(); } return View(pt); }
public ActionResult Poets(string poet) { List<Poetry> pt = new List<Poetry>(); MySqlConnection myConn; MySqlDataReader dataReader; myConn = new MySqlConnection(TaqtiController.connectionString); myConn.Open(); MySqlCommand cmd = new MySqlCommand(TaqtiController.connectionString); cmd = myConn.CreateCommand(); if (poet.Equals("غالب")) { cmd.CommandText = "select * from Poetry where poet like '" + "اسد اللہ خان غالب" + "' order by secid"; } else { cmd.CommandText = "select * from Poetry where poet like '" + poet + "' order by secid"; } dataReader = cmd.ExecuteReader(); int typeId = -1; while (dataReader.Read()) { Poetry p = new Poetry(); p.id = dataReader.GetInt32(0); p.poet = dataReader.GetString(1); p.title = dataReader.GetString(2); typeId = dataReader.GetInt32(3); p.meters = dataReader.GetString(5); if (typeId == 0) { p.type = "غزل"; } else if (typeId == 1) { p.type = "نظم"; } else if (typeId == 2) { p.type = "رباعی"; } else if (typeId == 3) { p.type = "قطعہ"; } else if (typeId == 4) { p.type = "آزاد نظم"; } else if (typeId == 5) { p.type = "شعر"; } pt.Add(p); } myConn.Close(); return View(pt); }