public ActionResult Publish(Publish data) { MySqlConnection myConn = new MySqlConnection(TaqtiController.connectionString); myConn.Open(); MySqlCommand cmd = new MySqlCommand(TaqtiController.connectionString); cmd = myConn.CreateCommand(); int percentage = 0; if (data.percentage > 79) { percentage = 1; } if (string.IsNullOrEmpty(data.url)) { cmd.CommandText = "INSERT into mypoetry(name,title,text,date,mozun) VALUES (@name,@title,@text,@date,@mozun);"; cmd.Parameters.AddWithValue("@name", (string)data.name); cmd.Parameters.AddWithValue("@title", (string)data.title); cmd.Parameters.AddWithValue("@text", (string)data.text); cmd.Parameters.AddWithValue("@date", DateTime.Now); cmd.Parameters.AddWithValue("@mozun", percentage); } else { cmd.CommandText = "INSERT into mypoetry(name,url,title,text,date,mozun) VALUES (@name,@url,@title,@text,@date,@mozun);"; cmd.Parameters.AddWithValue("@name", (string)data.name); cmd.Parameters.AddWithValue("@url", (string)data.url); cmd.Parameters.AddWithValue("@title", (string)data.title); cmd.Parameters.AddWithValue("@text", (string)data.text); cmd.Parameters.AddWithValue("@date", DateTime.Now); cmd.Parameters.AddWithValue("@mozun", percentage); } cmd.ExecuteNonQuery(); myConn.Close(); int id = 0; myConn.Open(); cmd = new MySqlCommand(TaqtiController.connectionString); cmd = myConn.CreateCommand(); cmd.CommandText = "select max(id) from mypoetry;"; MySqlDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { id = dataReader.GetInt32(0); } myConn.Close(); return PartialView("_Publish", id); }
public ActionResult Poetry(int id) { string taqtiObject = ""; MySqlConnection myConn; MySqlDataReader dataReader; myConn = new MySqlConnection(TaqtiController.connectionString); myConn.Open(); MySqlCommand cmd = new MySqlCommand(TaqtiController.connectionString); cmd = myConn.CreateCommand(); cmd.CommandText = "select * from mypoetry where id = @id"; cmd.Parameters.AddWithValue("@id",id); dataReader = cmd.ExecuteReader(); Publish p = new Publish(); while (dataReader.Read()) { p.id = dataReader.GetInt32(0); p.text = dataReader.GetString(4); p.name = dataReader.GetString(1); p.title = dataReader.GetString(3); try { taqtiObject = dataReader.GetString(5); } catch { } try { p.url = dataReader.GetString(2); } catch { } } myConn.Close(); return View(p); }
// GET: MyPoetry public ActionResult Index(int? page) { List<Publish> pt = new List<Publish>(); 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 mypoetry where publish = '1';"; dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { maxCount = dataReader.GetInt32(0); } myConn.Close(); maxPages = maxCount / 18; residue = maxCount - maxPages * 18; 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 mypoetry where publish = '1' order by id DESC limit 0,18"; dataReader2 = cmd2.ExecuteReader(); while (dataReader2.Read()) { Publish p = new Publish(); p.id = dataReader2.GetInt32(0); p.text = dataReader2.GetString(4); p.name = dataReader2.GetString(1); p.title = dataReader2.GetString(3); try { p.url = dataReader2.GetString(2); } catch { } try { p.date = dataReader2.GetDateTime(6); } catch { } p.mozun = dataReader2.GetInt32(8); 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 mypoetry where publish = '1' order by id DESC limit @init,@count"; if (page == maxPages && residue > 0) { cmd2.Parameters.AddWithValue("@init", (page - 1) * 18); cmd2.Parameters.AddWithValue("@count", residue); } else { cmd2.Parameters.AddWithValue("@init", (page - 1) * 18); cmd2.Parameters.AddWithValue("@count", 18); } dataReader2 = cmd2.ExecuteReader(); while (dataReader2.Read()) { Publish p = new Publish(); p.id = dataReader2.GetInt32(0); p.text = dataReader2.GetString(4); p.name = dataReader2.GetString(1); p.title = dataReader2.GetString(3); try { p.url = dataReader2.GetString(2); } catch { } try { p.date = dataReader2.GetDateTime(6); } catch { } p.mozun = dataReader2.GetInt32(8); p.maxpages = maxPages; p.currentPage = (int)page; pt.Add(p); } myConn2.Close(); } return View(pt); }
public ActionResult MyPoetry2(int id) { string taqtiObject = ""; MySqlConnection myConn; MySqlDataReader dataReader; myConn = new MySqlConnection(TaqtiController.connectionString); myConn.Open(); MySqlCommand cmd = new MySqlCommand(TaqtiController.connectionString); cmd = myConn.CreateCommand(); cmd.CommandText = "select * from mypoetry where id = @id"; cmd.Parameters.AddWithValue("@id", id); dataReader = cmd.ExecuteReader(); Publish p = new Publish(); while (dataReader.Read()) { p.id = dataReader.GetInt32(0); p.text = dataReader.GetString(4); p.name = dataReader.GetString(1); p.title = dataReader.GetString(3); try { taqtiObject = dataReader.GetString(5); } catch { } try { p.url = dataReader.GetString(2); } catch { } } myConn.Close(); List<int> met = new List<int>(); Scansion scn = new Scansion(); scn.fuzzy = false; scn.freeVerse = false; scn.isChecked = false; scn.errorParam = 2; scn.meter = met; List<scanOutput> lst = new List<scanOutput>(); if (string.IsNullOrEmpty(taqtiObject)) { foreach (string line in p.text.Split('\n')) { if (!string.IsNullOrWhiteSpace(line)) scn.addLine(new Lines(line.Trim())); } lst = scn.scanLines(); if (lst.Count == 0) { scanOutput sc = new scanOutput(); sc.identifier = id; sc.poet = p.name; sc.title = p.title; sc.text = p.text; sc.url = p.url; lst.Add(sc); } else { lst[0].identifier = id; lst[0].poet = p.name; lst[0].title = p.title; lst[0].text = p.text; lst[0].url = p.url; } XmlSerializer ser = new XmlSerializer(typeof(List<scanOutput>)); StringWriter textWriter = new StringWriter(); ser.Serialize(textWriter, lst); MySqlConnection myConn2 = new MySqlConnection(TaqtiController.connectionString); myConn2.Open(); MySqlCommand cmd2 = new MySqlCommand(TaqtiController.connectionString); cmd2 = myConn2.CreateCommand(); cmd2.CommandText = "update mypoetry set taqtiObject = @object where id = @id;"; cmd2.Parameters.AddWithValue("@object", (string)textWriter.ToString()); cmd2.Parameters.AddWithValue("@id", p.id); cmd2.ExecuteNonQuery(); myConn2.Close(); } else { XmlSerializer ser = new XmlSerializer(typeof(List<scanOutput>)); StringReader reader = new StringReader(taqtiObject); lst = (List<scanOutput>)ser.Deserialize(reader); lst[0].identifier = id; lst[0].poet = p.name; lst[0].title = p.title; lst[0].text = p.text; lst[0].url = p.url; } return PartialView("_Poetry", crunch(lst)); }