protected void LoginUser(object sender, EventArgs e) { string connectionString = @"Data Source=db4free.net; Database=centresportif420; user=centresportif420; password=stephane420;"; using (MySqlConnection cn = new MySqlConnection(connectionString)) { cn.Open(); queryStr = "SELECT * FROM centresportif420.personne WHERE codebarre='" + Server.HtmlEncode(((TextBox)(Login1.FindControl("UserName"))).Text) + "' AND motdepasse='" + Server.HtmlEncode(((TextBox)(Login1.FindControl("Password"))).Text) + "'"; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, cn); reader = cmd.ExecuteReader(); name = ""; while (reader.HasRows && reader.Read()) { name = reader.GetString(reader.GetOrdinal("nom")); role = reader.GetString(reader.GetOrdinal("role")); idpersonne = reader.GetString(reader.GetOrdinal("idpersonne")); Session["idpersonne"] = idpersonne; Session["urole"] = role; } if (reader.HasRows) { Session["uname"] = name; Response.BufferOutput = true; Response.Redirect("~/Account/Membre.aspx", false); FormsAuthentication.SetAuthCookie(Server.HtmlEncode(((TextBox)(Login1.FindControl("UserName"))).Text), true); } else { Response.Redirect("~/Account/Login.aspx", false); } reader.Close(); cn.Close(); } }
public string Maxsuivant(string sTable, string sChamp, string scond) { //int iCount = GetRecordCount(QC, sTable, ""); DeltaSQLTmp.CommandText = "SELECT (max(" + sChamp + ") + 1) as tmp FROM " + sTable; if (scond != "") { DeltaSQLTmp.CommandText = DeltaSQLTmp.CommandText + " WHERE " + scond; } MySql.Data.MySqlClient.MySqlDataReader Q = DeltaSQLTmp.ExecuteReader(); //Q.Read(); string Ret = ""; //if (Q.RecordCount != 0) //if (iCount != 0) if (Q.Read() && Q.GetValue(Q.GetOrdinal("tmp")).ToString() != "") { Ret = Q.GetValue(Q.GetOrdinal("tmp")).ToString(); } else { Ret = "1"; } Q.Close(); return(Ret); }
protected void Page_Load(object sender, EventArgs e) { try { connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connectionString); conn.Open(); userID = (String)Session["trainerID"]; String query = "SELECT * FROM webapppersonalfit.trainer AS T WHERE T.userID=" + userID + ";"; cmd = new MySql.Data.MySqlClient.MySqlCommand(query, conn); reader = cmd.ExecuteReader(); if (reader.HasRows && reader.Read()) { Username.Text = reader.GetString(reader.GetOrdinal("name")); short_intro.Text = reader.GetString(reader.GetOrdinal("short_intro")); long_intro.Text = reader.GetString(reader.GetOrdinal("long_intro")); avatar.ImageUrl = reader.GetString(reader.GetOrdinal("url_pic")); } addSpanOntoPlaceHolder(); conn.Close(); reader.Close(); } catch (Exception ex) { // } }
private void DoSQLQuery1() { try { String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); queryStr = ""; queryStr = "SELECT * FROM database.tbl_user WHERE tbl_user.id='" + Session["Id"] + "' "; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); while (reader.HasRows && reader.Read()) { education = reader.GetString(reader.GetOrdinal("education")); localisation = reader.GetString(reader.GetOrdinal("localisation")); } if (reader.HasRows) { // Session["uname"] = name; // userName = (String)(Session["utname"]); // Label14.Text = userName; LabelEducation.Text = education; LabelLocation.Text = localisation; } reader.Close(); conn.Close(); } catch (Exception e) { Console.WriteLine(e); } }
protected void loadDataToExerciseTable() { thColorStyle.BackColor = System.Drawing.ColorTranslator.FromHtml("#d9534f"); trColorSytle.BackColor = System.Drawing.ColorTranslator.FromHtml("#343a40"); try { connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connectionString); conn.Open(); String query = "SELECT * FROM webapppersonalfit.trainer"; cmd = new MySql.Data.MySqlClient.MySqlCommand(query, conn); reader = cmd.ExecuteReader(); while (reader.HasRows && reader.Read()) { String trainerID = reader.GetString(reader.GetOrdinal("userID")); String trainerName = reader.GetString(reader.GetOrdinal("name")); String cardTitle = reader.GetString(reader.GetOrdinal("name")); String cardContent = reader.GetString(reader.GetOrdinal("short_intro")); String picUrl = reader.GetString(reader.GetOrdinal("url_pic")); addCardOntoPlaceHolder(trainerID, trainerName, cardTitle, cardContent, picUrl); } reader.Close(); conn.Close(); } catch (Exception e) { //passwordTextBox.Value = e.ToString(); } }
//When Login has been Pressed protected void SubmitEventMethod(object sender, EventArgs e) { string username = Username.Text; string pass = Password.Text; query = "SELECT * FROM 17agileteam6db.users WHERE staff_no ='" + username + "' AND pass = '******';"; //checks user name and password DB db = new DB(); reader = db.Select(query); while (reader.HasRows && reader.Read()) { Session["role"] = reader.GetString(reader.GetOrdinal("role")); Session["firstName"] = reader.GetString(reader.GetOrdinal("first_name")); Session["lastName"] = reader.GetString(reader.GetOrdinal("last_name")); } if (reader.HasRows) { Session["loggedin"] = "Loggedin"; Session["StaffNo"] = Username.Text; Response.BufferOutput = true; Response.Redirect("Index.aspx", false); } else { //If username and password not found return false Session["failed"] = "failed"; Response.Redirect("Login.aspx", false); } reader.Close(); }
private void LoginWithPasswordHashFunction() { List <String> salthashList = null; List <String> namesList = null; try { connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connectionString); conn.Open(); String query = "SELECT slowHashSalt, firstname, middlename, lastname FROM webAppPersonalFit.userregistration WHERE username=?uname"; cmd = new MySql.Data.MySqlClient.MySqlCommand(query, conn); cmd.Parameters.AddWithValue("?uname", usernameTextBox.Text); reader = cmd.ExecuteReader(); while (reader.HasRows && reader.Read()) { if (salthashList == null) { salthashList = new List <String>(); namesList = new List <String>(); } String saltHashes = reader.GetString(reader.GetOrdinal("slowHashSalt")); //Console.WriteLine(saltHashes); salthashList.Add(saltHashes); String fullname = reader.GetString(reader.GetOrdinal("firstname")) + " " + reader.GetString(reader.GetOrdinal("lastname")); namesList.Add(fullname); } if (salthashList != null) { for (int i = 0; i < salthashList.Count; i++) { bool validUser = PasswordStorage.VerifyPassword(passwordTextBox.Text, salthashList[i]); if (validUser == true) { Session["UserName"] = namesList[i]; Response.BufferOutput = true; Response.Redirect("LoggedIn.aspx", false); } else { passwordTextBox.Text = "User not authenticated"; } } } reader.Close(); conn.Close(); } catch (Exception e) { Console.WriteLine(e); } }
private void DoSQLQueryPieFournisseur() { try { String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); queryStr = ""; queryStr = "SELECT * FROM database.detail WHERE detail.t1='" + Session["AnnPieFournisseur"] + "' AND detail.titre='Solde fournisseurs'"; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); while (reader.HasRows && reader.Read()) { fournisseur = reader.GetString(reader.GetOrdinal("t1")); DebitF1 = reader.GetInt32(reader.GetOrdinal("t2")); CreditF1 = reader.GetInt32(reader.GetOrdinal("t3")); SoldeF1 = reader.GetInt32(reader.GetOrdinal("t4")); } reader.Close(); conn.Close(); } catch (Exception e) { Console.WriteLine(e); } }
private void printForumPost() { String connString = System.Configuration.ConfigurationManager.ConnectionStrings["CredditConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); queryStr = ""; queryStr = "SELECT * FROM forum WHERE forumId='" + forumId + "'"; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); String post = ""; String name = ""; int accountID = 0; String dateTime = ""; String accountType = ""; while (reader.HasRows && reader.Read()) { post = reader.GetString(reader.GetOrdinal("post")); name = reader.GetString(reader.GetOrdinal("name")); dateTime = reader.GetString(reader.GetOrdinal("dateTime")); accountID = Int32.Parse(reader.GetString(reader.GetOrdinal("accountId"))); accountType = reader.GetString(reader.GetOrdinal("accountType")); } PostLabel.Text = post; NameLabel.Text = name; datetimeLabel.Text = dateTime; TypeLabel.Text = accountType; reader.Close(); conn.Close(); }
private void DoSQLQueryPieBanque() { try { String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); queryStr = ""; queryStr = "SELECT * FROM database.detail WHERE detail.titre='Solde banque'"; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); while (reader.HasRows && reader.Read()) { BIATD = reader.GetInt32(reader.GetOrdinal("t1")); BIATE = reader.GetInt32(reader.GetOrdinal("t2")); STB = reader.GetInt32(reader.GetOrdinal("t3")); } reader.Close(); conn.Close(); } catch (Exception e) { Console.WriteLine(e); } }
private void LoginWithPasswordHashFunction() { List <String> salthashList = null; List <String> namesList = null; try { String connString = System.Configuration.ConfigurationManager.ConnectionStrings["projectConnectionString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); querystr = "SELECT `slowHashSalt`, `first_name`, `last_name`, `user_id` FROM `project`.`client` WHERE username=?uname"; cmd = new MySql.Data.MySqlClient.MySqlCommand(querystr, conn); cmd.Parameters.AddWithValue("?uname", usernametextbox.Text); reader = cmd.ExecuteReader(); while (reader.HasRows && reader.Read()) { if (salthashList == null) { salthashList = new List <String>(); namesList = new List <String>(); } String saltHashes = reader.GetString(reader.GetOrdinal("slowHashSalt")); salthashList.Add(saltHashes); String fullname = reader.GetString(reader.GetOrdinal("first_name")) + " " + reader.GetString(reader.GetOrdinal("last_name")); namesList.Add(fullname); user_id = reader.GetString(reader.GetOrdinal("user_id")); } reader.Close(); //check to see whether the results from the query are empty if (salthashList != null) { for (int i = 0; i < salthashList.Count; i++) { querystr = ""; bool ValidUser = PasswordHash.ValidatePassword(userpasswordtextbox.Text, salthashList[i]); if (ValidUser == true) { Session["uname"] = namesList[i]; Session["user_id"] = user_id; Response.BufferOutput = true; Response.Redirect("LoggedIn.aspx", false); } else { userpasswordtextbox.Text = "User not authenticated"; } } } } catch (Exception ex) { userpasswordtextbox.Text = ex.ToString(); } }
private void DoSQLQueryy() { try { String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); queryStr = ""; queryStr = "SELECT * FROM database.tb WHERE tb.codeuser='******'"; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); z01 = ""; z02 = ""; z03 = ""; z04 = ""; z05 = ""; z06 = ""; z07 = ""; z08 = ""; z09 = ""; z10 = ""; while (reader.HasRows && reader.Read()) { z01 = reader.GetString(reader.GetOrdinal("z01")); z02 = reader.GetString(reader.GetOrdinal("z02")); z03 = reader.GetString(reader.GetOrdinal("z03")); z04 = reader.GetString(reader.GetOrdinal("z04")); z05 = reader.GetString(reader.GetOrdinal("z05")); z06 = reader.GetString(reader.GetOrdinal("z06")); z07 = reader.GetString(reader.GetOrdinal("z07")); z08 = reader.GetString(reader.GetOrdinal("z08")); z09 = reader.GetString(reader.GetOrdinal("z09")); z10 = reader.GetString(reader.GetOrdinal("z10")); } if (reader.HasRows) { LabelT1.Text = z01; LabelT2.Text = z02; LabelT3.Text = z03; LabelT4.Text = z04; LabelT5.Text = z05; LabelT6.Text = z06; LabelT7.Text = z07; LabelT8.Text = z08; LabelT9.Text = z09; LabelT10.Text = z10; LabelZ04.Text = z04; } reader.Close(); conn.Close(); } catch (Exception e) { Console.WriteLine(e); } }
private void DoSQLQueryyIm() { try { String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); String queryStr = ""; queryStr = "SELECT * FROM database.metadata WHERE metadata.codeuser='******' "; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); // z01 = ""; userName = ""; datee = ""; contentmeta = ""; while (reader.HasRows && reader.Read()) { userName = reader.GetString(reader.GetOrdinal("username")); iduser = reader.GetString(reader.GetOrdinal("iduser")); idmetadata3 = reader.GetInt32(reader.GetOrdinal("id")); datee = reader.GetString(reader.GetOrdinal("date")); contentmeta = reader.GetString(reader.GetOrdinal("content")); } if (reader.HasRows) { // Label3.Text = z01; Image2.ImageUrl = "~/ShowImage.ashx?id=" + iduser; Image3.ImageUrl = "~/ShowMetadata.ashx?codeuser="******"urole"]; Image4.ImageUrl = "~/ShowImage.ashx?id=" + Session["Id"]; LabelProfil.Text = userName; LabelDate.Text = datee; LabelContent.Text = contentmeta; } reader.Close(); String queryStr1 = ""; queryStr1 = "SELECT COUNT(id) as countlike FROM database.like WHERE like.idmetadata='" + idmetadata3 + "' "; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr1, conn); reader = cmd.ExecuteReader(); while (reader.HasRows && reader.Read()) { countlike = reader.GetString(reader.GetOrdinal("countlike")); } LabelLike.Text = countlike; conn.Close(); } catch (Exception e) { Console.WriteLine(e); } }
private void LoginWithPasswordHashFunction() { String saltHash = null; try { connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connectionString); conn.Open(); String query = "SELECT userID, slowHashSalt, firstname, middlename, lastname, isPT FROM webAppPersonalFit.userregistration WHERE username=?uname"; cmd = new MySql.Data.MySqlClient.MySqlCommand(query, conn); cmd.Parameters.AddWithValue("?uname", usernameTextBox.Value); reader = cmd.ExecuteReader(); if (reader.HasRows && reader.Read()) { String saltHashes = reader.GetString(reader.GetOrdinal("slowHashSalt")); //Console.WriteLine(saltHashes); saltHash = saltHashes; userID = "" + reader.GetInt16(reader.GetOrdinal("userID")); isPT = Convert.ToInt32(reader.GetByte(reader.GetOrdinal("isPT"))); } else { ValidationTextBoxLabel.Text = "Invalid Username or Password."; } if (saltHash != null) { bool validUser = PasswordStorage.VerifyPassword(passwordTextBox.Value, saltHash); if (validUser == true) { Session[userID] = userID; Response.BufferOutput = true; Server.Transfer("TrainerCatalog.aspx", true); } else { ValidationTextBoxLabel.Text = "Invalid Username or Password."; } } ValidationTextBoxLabel.Text = "Invalid Username or Password."; reader.Close(); conn.Close(); } catch (Exception e) { Console.WriteLine(e); } }
private void addVote(String TypeID, String ID) { /*looks for accountID*/ String myaccountID = (String)Session["accountID"]; String connString = System.Configuration.ConfigurationManager.ConnectionStrings["CredditConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); queryStr = "SELECT * FROM " + TypeID + " WHERE " + TypeID + "Id = '" + ID + "'"; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); String vote = ""; while (reader.HasRows && reader.Read()) { vote = reader.GetString(reader.GetOrdinal("vote")); } String updatevote = vote + "|" + myaccountID + "|"; conn.Close(); conn.Open(); queryStr = ""; queryStr = "UPDATE " + TypeID + " SET vote = '" + updatevote + "' WHERE " + TypeID + "Id = '" + ID + "'"; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); cmd.ExecuteReader(); conn.Close(); }
void Ekle(string kID) { int makaleID = 1; String connStr = System.Configuration.ConfigurationManager.ConnectionStrings["WebConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connStr); conn.Open(); queryStr = "SELECT * FROM tasarimdersi.yazarmakale WHERE ID= " + kID + " AND MakaleID = (SELECT MAX(MakaleID) FROM tasarimdersi.yazarmakale WHERE ID= " + kID + ")"; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); while (reader.HasRows && reader.Read()) { makaleID = reader.GetInt16(reader.GetOrdinal("MakaleID")) + 1; } conn.Close(); if (FileUpload1.HasFile) { if (FileUpload1.PostedFile.ContentType == "application/pdf") { if (FileUpload1.PostedFile.ContentLength < 10240000) { isim = Session["IDSes"].ToString() + "-" + makaleID; makaleIsim = isim + ".pdf"; makalePath = (Server.MapPath("//resimler//") + makaleIsim); FileUpload1.SaveAs(makalePath); } else { lblMesaj.InnerText = "Dosya boyutu maximum 10MB olmalıdır."; } } else { lblMesaj.InnerText = "Sadece pdf uzantılı dosyalar yüklenebilir."; } } else { lblMesaj.InnerText = "Lütfen bir dosya seçiniz."; } conn.Open(); queryStr = "INSERT INTO tasarimdersi.yazarmakale (ID,MakaleID,alan,baslik,aciklama,makalepdf,onay)" + "Values('" + kID + "','" + makaleID + "','" + Alan.Text + "','" + Baslik.Text + "','" + Aciklama.Text + "','" + makaleIsim + "','" + "Editör İncelemesinde" + "')"; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); cmd.ExecuteReader(); conn.Close(); Response.Redirect(Request.RawUrl); }
public static byte[] convertBlobToBufferData(String column,MySqlDataReader rdr) { int bufferSize = 1024; // Number of bytes to read at a time byte[] ImageData = new byte[bufferSize]; long nBytesReturned, startIndex = 0; int ordinal = rdr.GetOrdinal(column); string image = rdr.IsDBNull(ordinal) ? null : rdr.GetString(column); if (image != null) { startIndex = 0; nBytesReturned = rdr.GetBytes( ordinal, // Column index of BLOB column startIndex, // Start position of the byte to read ImageData, // Byte array to recieve BLOB data 0, // Start index of the array bufferSize // Size of buffer ); while (nBytesReturned == bufferSize) { startIndex += bufferSize; nBytesReturned = rdr.GetBytes(ordinal, startIndex, ImageData, 0, bufferSize); // Number of bytes returned is assigned to nBytesReturned } return ImageData; } else { return null; } }
private void DoSQLCountComment() { try { String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); String queryStr = ""; queryStr = "SELECT COUNT(id) as countcom FROM database.comment WHERE comment.codeuser='******' AND comment.idmetadata= (SELECT id from database.metadata WHERE metadata.codeuser='******') "; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); count = ""; while (reader.HasRows && reader.Read()) { count = reader.GetString(reader.GetOrdinal("countcom")); } if (reader.HasRows) { LaCountComment.Text = count; } reader.Close(); conn.Close(); } catch (Exception e) { Console.WriteLine(e); } }
public static int SafeGetInt(MySqlDataReader reader, string colName) { if (!reader.IsDBNull(reader.GetOrdinal(colName))) return reader.GetInt32(colName); else return default(int); }
private bool DoSQLQueryTest() { try { String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); String queryStr = ""; queryStr = "SELECT COUNT(id) as countindex FROM database.metadata WHERE metadata.codeuser='******' "; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); countindex = 0; while (reader.HasRows && reader.Read()) { countindex = reader.GetInt32(reader.GetOrdinal("countindex")); } if (countindex != 0) { return(true); } reader.Close(); conn.Close(); } catch (Exception ex) { Console.WriteLine(ex); } return(false); }
public static String SafeGetString(MySqlDataReader reader, string colName) { if (!reader.IsDBNull(reader.GetOrdinal(colName))) return reader.GetString(colName); else return string.Empty; }
public static DateTime SafeGetDateTime(MySqlDataReader reader, string colName) { if (!reader.IsDBNull(reader.GetOrdinal(colName))) return reader.GetDateTime(colName); else return default(DateTime); }
protected void addOrder() { string allTitles = null; int lastID = 0; string price = totalPrice + ""; string emailCustomer = actualCustomer.Email; for (int i = 0; i < movies.Count; i++) { allTitles = allTitles + movies[i].Title + "; "; } String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebbAppConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); queryStr = ""; queryStr = "insert into bookings (totalPrice,bookingdate,user_email) values ('" + price + "',now(),'" + emailCustomer + "');SELECT LAST_INSERT_ID();"; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); while (reader.Read()) { lastID = reader.GetInt32(reader.GetOrdinal("LAST_INSERT_ID()")); } conn.Close(); System.Diagnostics.Debug.WriteLine("Last id: " + lastID); for (int j = 0; j < movies.Count; j++) { insertMoviesIntoBooking(lastID, Convert.ToInt32(movies[j].Id)); insertNewRateRow(Convert.ToInt32(movies[j].Id), emailCustomer); } }
public bool Logar(string nickname, string senha) { Conexao(); bool logado = false; string sql = "select id, nickname, senha from Usuario where nickname= @nickname "; command = new MySqlCommand(sql, Conexao()); par = new MySqlParameter("@nickname", nickname); par.MySqlDbType = MySqlDbType.VarChar; command.Parameters.Add(par); reader = command.ExecuteReader(); string senhaUsuario; if (reader.Read()) { senhaUsuario = reader.GetValue(reader.GetOrdinal("SENHA")).ToString(); if (senhaUsuario.Equals(senha)) { logado = true; } } FecharConexao(); return logado; // command = new System.Data.SqlClient.SqlCommand(sql, conexão()); }
// This is used for saving the messages to the database. // The messages need to have correct userIDs - used to establish who sent them - and correct caseIdDs - used to establish which case the message belongs to. public String[] getUserIDcaseID() { // Array is tidier than multiple strings, make use of indexes. String[] IDs = new String[2]; IDs[0] = uID; // Populated with the Session method during Page_Load - no need to query DB for this. String connString = System.Configuration.ConfigurationManager.ConnectionStrings["projectConnectionString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); queryStr = ""; // Use case_name to obtain case ID from the allcases table. queryStr = "SELECT case_id FROM project.allcases WHERE case_name=?cname"; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); cmd.Parameters.AddWithValue("?cname", case_name); reader = cmd.ExecuteReader(); while (reader.HasRows && reader.Read()) { // Grab caseID. IDs[1] = reader.GetString(reader.GetOrdinal("case_id")); } reader.Close(); // Return the array, therefore method can be called and assigned to varaible due to return - efficient. return(IDs); }
protected void logIn() { email = textBoxEmail.Text; pass = textBoxPassword.Text; string loginemail = ""; string loginpass = ""; if (email != " ") { try { dbConnection dbc = dbConnection.Instance(); queryStr = "SELECT * from user where email = '" + email + "'"; reader = dbc.Select(queryStr); System.Diagnostics.Debug.WriteLine("read reader"); while (reader.Read()) { System.Diagnostics.Debug.WriteLine("reads"); loginemail = reader.GetString(reader.GetOrdinal("email")); loginpass = reader.GetString(reader.GetOrdinal("password")); System.Diagnostics.Debug.WriteLine(loginemail); } dbc.close(); if (loginemail.Equals(email) && loginpass.Equals(pass)) { Customers myCustomer = new Customers("Johan", "Nilsson", loginemail, loginpass, "gatan1", "01010101"); Session["myCustomer"] = myCustomer; labelName.Text = myCustomer.FirstName; } else { labelName.Text = "Invalid email or password"; Response.Redirect("Default.aspx"); } } catch (MySql.Data.MySqlClient.MySqlException ex) { Response.Redirect("Default.aspx"); labelName.Text = "Your email is not valid"; } } else { labelName.Text = "You must enter your email"; } }
public static String SafeGetString(MySqlDataReader reader, String columnname) { int colIndex = reader.GetOrdinal(columnname); if (!reader.IsDBNull(colIndex)) return reader.GetString(colIndex); else return String.Empty; }
private void DoSQLQuery() { try { String connString = System.Configuration.ConfigurationManager.ConnectionStrings["projectConnectionString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); querystr = ""; //querystr = "SELECT * FROM project.client WHERE user_password= '******' AND user_id= '" + Useridtextbox.Text + "'"; //cmd = new MySql.Data.MySqlClient.MySqlCommand(querystr, conn); querystr = "SELECT * FROM project.client WHERE user_password=?pword AND username=?uname"; cmd = new MySql.Data.MySqlClient.MySqlCommand(querystr, conn); cmd.Parameters.AddWithValue("?uname", usernametextbox.Text); cmd.Parameters.AddWithValue("?pword", userpasswordtextbox.Text); reader = cmd.ExecuteReader(); name = ""; while (reader.HasRows && reader.Read()) { name = reader.GetString(reader.GetOrdinal("first_name")) + " " + reader.GetString(reader.GetOrdinal("last_name")); } if (reader.HasRows) { Session["uname"] = name; Session["user_id"] = user_id; Response.BufferOutput = true; Response.Redirect("LoggedIn.aspx", false); } else { userpasswordtextbox.Text = "invalid user"; } reader.Close(); conn.Close(); } catch (Exception e) { userpasswordtextbox.Text = e.ToString(); } }
protected void DoSQLCountLike(object sender, EventArgs e) { try { String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); String queryStr = ""; queryStr = "SELECT id FROM database.metadata WHERE metadata.codeuser='******' "; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); while (reader.HasRows && reader.Read()) { idmetadata3 = reader.GetInt32(reader.GetOrdinal("id")); } reader.Close(); String queryStr3; idLike = 0; queryStr3 = ""; queryStr3 = "SELECT id FROM database.like WHERE like.idmetadata='" + idmetadata3 + "' AND like.iduser='******' "; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr3, conn); reader = cmd.ExecuteReader(); while (reader.HasRows && reader.Read()) { idLike = reader.GetInt32(reader.GetOrdinal("id")); } reader.Close(); if (idLike == 0) { String queryStr2 = ""; queryStr2 = "INSERT INTO database.like (iduser,idmetadata)VALUES('" + Session["Id"] + "','" + idmetadata3 + "')"; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr2, conn); cmd.ExecuteNonQuery(); } conn.Close(); DoSQLQueryyIm(); } catch (Exception ex) { Console.WriteLine(ex); } }
public static Agente GetAgente(MySqlDataReader rdr) { if (rdr.IsDBNull(rdr.GetOrdinal("CODAGENT"))) return null; Agente a = new Agente(); a.CodAgent = rdr.GetInt32("CODAGENT"); a.NomAgent = rdr.GetString("NOMAGENT"); return a; }
public static Albaran GetAlbaran(MySqlDataReader rdr) { if (rdr.IsDBNull(rdr.GetOrdinal("NUMALBAR"))) return null; Albaran a = new Albaran(); a.CodTipom = rdr.GetString("CODTIPOM"); a.NumAlbar = rdr.GetInt32("NUMALBAR"); a.FechaAlb = rdr.GetDateTime("FECHAALB"); a.TotalAlb = rdr.GetDecimal("TOTALALB"); return a; }
public static Usuario GetUsuario(MySqlDataReader rdr) { if (rdr.IsDBNull(rdr.GetOrdinal("CODUSU"))) return null; Usuario u = new Usuario(); u.CodUsu = rdr.GetInt32("CODUSU"); u.NomUsu = rdr.GetString("NOMUSU"); u.Login = rdr.GetString("LOGIN"); u.PasswordPropio = rdr.GetString("PASSWORD_PROPIO"); u.NivelAriges = rdr.GetInt32("NIVEL_ARIGES"); return u; }
protected void btnAdminLogin_Click(object sender, EventArgs e) { string connstring = System.Configuration.ConfigurationManager.ConnectionStrings["msuconnectionstring"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connstring); conn.Open(); using (conn) { using (cmd = new MySql.Data.MySqlClient.MySqlCommand("uspAdminLoginGet", conn)) { cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.Add("i_UserName", MySql.Data.MySqlClient.MySqlDbType.VarChar).Value = txtUserName.Text.Trim(); cmd.Parameters.Add("i_AdminID", MySql.Data.MySqlClient.MySqlDbType.VarChar).Value = txtAdminID.Text.Trim(); cmd.Parameters.Add("i_Password", MySql.Data.MySqlClient.MySqlDbType.VarChar).Value = txtPassword.Text.Trim(); reader = cmd.ExecuteReader(); username = ""; while (reader.HasRows && reader.Read()) { username = reader.GetString(reader.GetOrdinal("FirstName")); userid = reader.GetInt32(reader.GetOrdinal("AdminID")); } if (reader.HasRows) { Session["AdminName"] = username; Session["AdminId"] = userid; Response.BufferOutput = true; Response.Redirect("Admin.aspx", false); } else { string script = "alert(\"Invalid User Name or Password\")"; ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true); } } } reader.Close(); conn.Close(); }
protected void logInAmin() { email = textBoxEmail.Text; if (email != " ") { try { dbConnection dbc = dbConnection.Instance(); queryStr = "SELECT * from administrator where administratorEmail= '" + email + "'"; reader = dbc.Select(queryStr); while (reader.Read()) { id = reader.GetInt32(reader.GetOrdinal("administratorId")) + ""; name = reader.GetString(reader.GetOrdinal("administratorName")); pass = reader.GetString(reader.GetOrdinal("administratorPass")); } } catch (MySql.Data.MySqlClient.MySqlException ex) { labelName.Text = "Your email is not valid"; } } else { labelName.Text = "Are you the administrator?"; } if (pass.Equals(textBoxPassword.Text)) { labelName.Text = name; Administrator myAdministrator = new Administrator(id, name, email, pass); Session["myAdministrator"] = myAdministrator; } else { labelName.Text = "Invalid pass"; } checkBoxAdmin.Checked = false; }
private void DoSQLQueryPie1() { try { String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); if ((String)(Session["urole"]) == "1") { conn.Open(); queryStr = ""; queryStr = "SELECT * FROM database.detail WHERE detail.t1='" + Session["OfInterne"] + "' AND detail.titre='Suivi Prod'"; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); while (reader.HasRows && reader.Read()) { Qteof = reader.GetString(reader.GetOrdinal("t2")); Coupe = reader.GetString(reader.GetOrdinal("t3")); Montage = reader.GetString(reader.GetOrdinal("t4")); Controle = reader.GetString(reader.GetOrdinal("t5")); Finition = reader.GetString(reader.GetOrdinal("t6")); Exped = reader.GetString(reader.GetOrdinal("t7")); } reader.Close(); conn.Close(); } } catch (Exception e) { Console.WriteLine(e); } }
private void submitRadio() { String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); queryStr = ""; queryStr = "SELECT StudentName FROM selfevascore WHERE StudentName ='" + svr.Text + "' "; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Read(); check = reader.GetString(reader.GetOrdinal("StudentName")); } reader.Close(); conn.Close(); if (check == svr.Text) { conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); queryStr = ""; queryStr = "UPDATE selfevascore SET 3c ='" + RadioButtonList1.Text + "'+'" + RadioButtonList2.Text + "'+'" + RadioButtonList3.Text + "'+'" + RadioButtonList4.Text + "'+'" + RadioButtonList5.Text + "'+'" + RadioButtonList6.Text + "'+'" + RadioButtonList7.Text + "'+'" + RadioButtonList8.Text + "'+'" + RadioButtonList9.Text + "'+'" + RadioButtonList10.Text + "'WHERE StudentName = '" + svr.Text + "' "; Labelcheck.Text = "Changes Have been Submitted Successfully"; Labelcheck.ForeColor = System.Drawing.Color.Green; } else { conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); queryStr = ""; queryStr = "INSERT INTO selfevascore ( StudentName, 3c)" + "VALUES('" + svr.Text + "','" + RadioButtonList1.Text + "'+'" + RadioButtonList2.Text + "'+'" + RadioButtonList3.Text + "'+'" + RadioButtonList4.Text + "'+'" + RadioButtonList5.Text + "'+'" + RadioButtonList6.Text + "'+'" + RadioButtonList7.Text + "'+'" + RadioButtonList8.Text + "'+'" + RadioButtonList9.Text + "'+'" + RadioButtonList10.Text + "')"; Labelcheck.Text = "Submitted Successfully"; Labelcheck.ForeColor = System.Drawing.Color.Green; } cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); cmd.ExecuteReader(); conn.Close(); }
public void fetchUsers() { String conStr = System.Configuration.ConfigurationManager.ConnectionStrings["constr"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(conStr); conn.Open(); queryStr = "SELECT * FROM simple_asp_form.user"; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); String name; String mobile; String email; while (reader.HasRows && reader.Read()) { name = reader.GetString(reader.GetOrdinal("first_name")); mobile = reader.GetString(reader.GetOrdinal("mobile")); email = reader.GetString(reader.GetOrdinal("email")); TableRow row = new TableRow(); TableCell cell1 = new TableCell(); cell1.Text = name; TableCell cell2 = new TableCell(); cell2.Text = mobile; TableCell cell3 = new TableCell(); cell3.Text = email; row.Cells.Add(cell1); row.Cells.Add(cell2); row.Cells.Add(cell3); myTable.Rows.Add(row); } reader.Close(); conn.Close(); }
private void DoSQLQuery() { try { String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); queryStr = ""; queryStr = "SELECT * FROM database.email WHERE email.id='" + Session["Indexrec"] + "' "; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); while (reader.HasRows && reader.Read()) { mailFrom = reader.GetString(reader.GetOrdinal("emailFrom")); contentMail = reader.GetString(reader.GetOrdinal("content")); subjectMail = reader.GetString(reader.GetOrdinal("subject")); dateMail = reader.GetString(reader.GetOrdinal("date")); } if (reader.HasRows) { // Session["uname"] = name; // userName = (String)(Session["utname"]); // Label14.Text = userName; LabelMail.Text = mailFrom; LabelSubject.Text = subjectMail; LabelContent.Text = contentMail; LabelDate.Text = dateMail; } reader.Close(); conn.Close(); } catch (Exception e) { Console.WriteLine(e); } }
private void activateuser() { try { string connString = System.Configuration.ConfigurationManager.ConnectionStrings["MywebConnection"].ToString(); con = new MySql.Data.MySqlClient.MySqlConnection(connString); con.Open(); querystr = ""; querystr = "SELECT * FROM mydatabase.activation_table WHERE Email_id=?email AND Activation_Code=?code"; cmd = new MySqlCommand(querystr, con); cmd.Parameters.AddWithValue("?email", email.Text); cmd.Parameters.AddWithValue("?code", code.Text); reader = cmd.ExecuteReader(); name = ""; while (reader.HasRows && reader.Read()) { name = reader.GetString(reader.GetOrdinal("Activation_Code")); } if (reader.HasRows) { Session["uname"] = name; Response.BufferOutput = true; Response.Redirect("Registration.aspx", false); } else { email.Text = ""; code.Text = ""; ClientScript.RegisterStartupScript(Page.GetType(), "disablevalidation", "<script language='javascript' >disableall();</script>"); ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript' >alertMX('Invalid Email / Activation Code!');</script>"); } reader.Close(); con.Close(); } catch (MySqlException ex) { Console.WriteLine("{0} Exception caught.", ex); } finally { if (cmd != null) { cmd.Dispose(); } if (con != null) { con.Close(); } } }
public static DateTime GetMySQLDateTime(MySqlDataReader mySQLDataReader, String column) { DateTime dateTime = DateTime.MinValue; try { int index = mySQLDataReader.GetOrdinal(column); if (!mySQLDataReader.IsDBNull(index)) { MySqlDateTime mySQLDateTime = mySQLDataReader.GetMySqlDateTime(column); if (mySQLDateTime.Day > 0) { dateTime = mySQLDateTime.GetDateTime(); } } } catch (Exception ex) { log.Error(ex.Message); } return dateTime; }
private void calculatetheinfo() { string fromclassroomvariable = string.Empty; string toclassroomvariable = string.Empty; //experimentLabel.Text = fromclassroomvariable.Remove(0, 1); string fromclassroomnumbervariable = string.Empty; string toclassroomnumbervariable = string.Empty; string fromclassroomfloorfinal = string.Empty; string toclassroomfloorfinal = string.Empty; string fromclassroombuilding = string.Empty; string toclassroombuilding = string.Empty; verifythisfromtextbox.Text = string.Empty; verifythistotextbox.Text = string.Empty; fromclassroomvariable = FromTextbox.Text.ToUpper(); toclassroomvariable = ToTextbox.Text.ToUpper(); if (FromTextbox.Text == string.Empty || ToTextbox.Text == string.Empty) //SECOND CHECK IF ANY TEXTBOXES ARE EMPTY { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('check your shit, a textbox is empty');</script>"); } else { fromclassroomnumbervariable = FromTextbox.Text.Remove(0, 1); toclassroomnumbervariable = ToTextbox.Text.Remove(0, 1); fromclassroomfloorfinal = FromTextbox.Text.Substring(1, 1); toclassroomfloorfinal = ToTextbox.Text.Substring(1, 1); fromclassroombuilding = FromTextbox.Text.Remove(1, 3); toclassroombuilding = ToTextbox.Text.Remove(1, 3); } if (FromTextbox.Text.ToUpper() ==ToTextbox.Text.ToUpper()) //THIRD CHECK IF ANY TEXTBOXES ARE THE SAME { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('check your shit, your textboxes are the same');</script>"); } //experimentLabel.Text = fromclassroomvariable.Remove(0, 1); //Boolean fromclass; //Boolean toclass; string verifythisfrom = string.Empty; string verifythisto = string.Empty; String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString(); conn = new MySql.Data.MySqlClient.MySqlConnection(connString); conn.Open(); //COMMENT1 LINE==i think below between comment1 Line and comment2 Line are best to put algorithm queryStr = ""; queryStr = "SELECT * FROM uhdclassroomfinder.adjacenttable WHERE RoomFloor LIKE '%" + fromclassroomfloorfinal + "%' AND Room LIKE '%" + fromclassroomnumbervariable + "%' AND Room LIKE '%" + fromclassroombuilding + "%'"; //queryStr = "SELECT * FROM uhdclassroomfinder.adjacenttable"; //queryStr = "SELECT * FROM uhdclassroomfinder.adjacenttable WHERE Room = 'Room_7_N_729%' AND Adjacent LIKE '%Room_7_N_795%' "; //queryStr = "SELECT * FROM uhdclassroomfinder.adjacenttable WHERE Room='Elevator_4_N_1' AND Adjacent = 'Stair_4_N_2';"; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); name = ""; while (reader.HasRows && reader.Read()) { name = reader.GetString(reader.GetOrdinal("Room")); } if (reader.HasRows) { Session["uname"] = name; verifythisfrom= (String)Session["uname"]; verifythisfromtextbox.Text = verifythisfrom; //fromclass = true; } else { //Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Check your inputs, .');</script>"); //Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('from is not in database .');</script>"); verifythisfromtextbox.Text = string.Empty; verifythistotextbox.Text = string.Empty; Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('You have entered a class in the From: textbox that is incorrect or is not currently in database. Press ok and try again');</script>"); //fromclass = false; //Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('2222222 .');</script>"); //Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('fromclassvariable is "+fromclassroomvariable+ ". toclassroomvariable is " + toclassroomvariable+ ". fromclassroomnumbervariable is " + fromclassroomnumbervariable+ ". toclassroomnumbervariable is " + toclassroomnumbervariable + ". fromclassroomfloorfinal is " + fromclassroomfloorfinal + ". toclassroomfloorfinal is " + toclassroomfloorfinal + ". fromclassroombuilding is " + fromclassroombuilding + ". toclassroombuilding is " + toclassroombuilding + "');</script>"); } reader.Close(); queryStr = ""; queryStr = "SELECT * FROM uhdclassroomfinder.adjacenttable WHERE RoomFloor LIKE '%" + toclassroomfloorfinal + "%' AND Room LIKE '%" + toclassroomnumbervariable + "%' AND Room LIKE '%" + toclassroombuilding + "%'"; //queryStr = "SELECT * FROM uhdclassroomfinder.adjacenttable"; //queryStr = "SELECT * FROM uhdclassroomfinder.adjacenttable WHERE Room LIKE '%Room_7_N_729%' AND Adjacent LIKE '%Room_7_N_795%' "; //queryStr = "SELECT * FROM uhdclassroomfinder.adjacenttable WHERE Room='Elevator_4_N_1' AND Adjacent = 'Stair_4_N_2';"; cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); reader = cmd.ExecuteReader(); name = ""; while (reader.HasRows && reader.Read()) { name = reader.GetString(reader.GetOrdinal("Room")); } if (reader.HasRows)//THIS WORKS { //toclass = true; Session["uname"] = name; verifythisto = (String)Session["uname"]; verifythistotextbox.Text = verifythisto; } else { //toclass = false; //Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('to is not in database .');</script>"); verifythisfromtextbox.Text = string.Empty; verifythistotextbox.Text = string.Empty; Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('You have entered a class in the To: textbox that is incorrect or is not currently in database. Press ok and try again');</script>"); } if (verifythisfrom==string.Empty || verifythisto==string.Empty)//this works { //Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('one of your inputs is not a valid classroom. try again .');</script>"); //Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('from class and toclass are green .');</script>"); Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('verifythisfrom " + verifythisfrom + ".'verifythisto " + verifythisto + ".);</script>"); } else { allgreen(); //Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Check your inputs. Remember, you must enter the classnumber in complete. Ex. 'N413' ');</script>"); } reader.Close(); conn.Close(); //COMMENT2 LINE== ///queryStr = ""; //queryStr = "SELECT * FROM uhdclassroomfinder.adjacenttable WHERE firstroomnumber='" + FromTextbox.Text + "'"; /// queryStr = "SELECT * FROM uhdclassroomfinder.adjacenttable WHERE firstroomnumber='" + FromTextbox.Text + "'"; ///cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn); /// reader = cmd.ExecuteReader(); /// name = ""; /// while (HasRows && reader.Read()) ///{ ///name = ///reader.GetString(reader.GetOrdinal("secondroomnumber")); ///} ///exampletextbox2.Text = string.Empty; ///if (reader.HasRows) ///{ ///Session["uname"] = name; ///exampletextbox2.Text = (String)Session["uname"]; ///} ///else ///{ ///exampletextbox2.Text = "Invalid user"; ///} ///reader.Close(); ///conn.Close(); }
private void kelas_combo_SelectedIndexChanged(object sender, EventArgs e) { if (kelas_combo.Text.Equals("")) { ekskulSiswa_grid.DataSource = null; } else if (!kelas_combo.Text.Equals("")) { query = "select count(kode_eskul) as 'kode', kode_eskul from ekstrakurikuler where nama_eskul LIKE '%Pramuka%'"; myConn.Open(); myComm = new MySqlCommand(query, myConn); myReader = myComm.ExecuteReader(); string cekKode = ""; int status_pramuka = myReader.GetOrdinal("kode_eskul"); while (myReader.Read()) { cekKode = myReader.GetString("kode"); kodePramuka = myReader.IsDBNull(status_pramuka) ? string.Empty : myReader.GetString("kode_eskul"); } myConn.Close(); if (cekKode == "0") { MessageBox.Show("Ekstrakurikuler Pramuka belum ada di database"); } else if (cekKode != "0") { string pramuka = kodePramuka; if (siswadt().Rows.Count != 0) { foreach (DataRow row in siswadt().Rows) { query = "select count(kode_eskul) as 'kode' from deskripsieskul where kode_eskul = '" + pramuka + "' AND kode_kelas = '" + kelas_combo.SelectedValue.ToString() + "' AND nis_siswa ='" + row["NIS"].ToString() + "'"; myConn.Open(); myComm = new MySqlCommand(query, myConn); myReader = myComm.ExecuteReader(); string cekJumlah = ""; while (myReader.Read()) { cekJumlah = myReader.GetString("kode"); if (cekJumlah == "0") { field = "DEFAULT, '" + kelas_combo.SelectedValue.ToString() + "', '" + row["NIS"].ToString() + "', '" + kodePramuka + "', 'Aktif sebagai anggota'"; table = "deskripsieskul"; db.insertData(table, field); } } myConn.Close(); } } } viewMemberKelas(); } }
private static void _mediaReadFields(MySqlDataReader dataReader, PersistentMedia media) { uint flags = dataReader.IsDBNull(dataReader.GetOrdinal("flags")) ? (uint)0 : dataReader.GetUInt32("flags"); byte typVideo = dataReader.IsDBNull(dataReader.GetOrdinal("typVideo")) ? (byte)0 : dataReader.GetByte("typVideo"); media._mediaName = dataReader.IsDBNull(dataReader.GetOrdinal("MediaName")) ? string.Empty : dataReader.GetString("MediaName"); media._duration = dataReader.IsDBNull(dataReader.GetOrdinal("Duration")) ? default(TimeSpan) : dataReader.GetTimeSpan("Duration"); media._durationPlay = dataReader.IsDBNull(dataReader.GetOrdinal("DurationPlay")) ? default(TimeSpan) : dataReader.GetTimeSpan("DurationPlay"); media._folder = dataReader.IsDBNull(dataReader.GetOrdinal("Folder")) ? string.Empty : dataReader.GetString("Folder"); media._fileName = dataReader.IsDBNull(dataReader.GetOrdinal("FileName")) ? string.Empty : dataReader.GetString("FileName"); media._fileSize = dataReader.IsDBNull(dataReader.GetOrdinal("FileSize")) ? 0 : dataReader.GetUInt64("FileSize"); media.idFormat = dataReader.IsDBNull(dataReader.GetOrdinal("idFormat")) ? 0 : dataReader.GetUInt64("idFormat"); media._lastUpdated = _readDateTimeField(dataReader, "LastUpdated"); media._mediaStatus = (TMediaStatus)(dataReader.IsDBNull(dataReader.GetOrdinal("statusMedia")) ? 0 : dataReader.GetInt32("statusMedia")); media._mediaType = (TMediaType)(dataReader.IsDBNull(dataReader.GetOrdinal("typMedia")) ? 0 : dataReader.GetInt32("typMedia")); media._tCStart = dataReader.IsDBNull(dataReader.GetOrdinal("TCStart")) ? default(TimeSpan) : dataReader.GetTimeSpan("TCStart"); media._tCPlay = dataReader.IsDBNull(dataReader.GetOrdinal("TCPlay")) ? default(TimeSpan) : dataReader.GetTimeSpan("TCPlay"); media.idProgramme = dataReader.IsDBNull(dataReader.GetOrdinal("idProgramme")) ? 0 : dataReader.GetUInt64("idProgramme"); media._audioVolume = dataReader.IsDBNull(dataReader.GetOrdinal("AudioVolume")) ? 0 : dataReader.GetDecimal("AudioVolume"); media._audioLevelIntegrated = dataReader.IsDBNull(dataReader.GetOrdinal("AudioLevelIntegrated")) ? 0 : dataReader.GetDecimal("AudioLevelIntegrated"); media._audioLevelPeak = dataReader.IsDBNull(dataReader.GetOrdinal("AudioLevelPeak")) ? 0 : dataReader.GetDecimal("AudioLevelPeak"); media._audioChannelMapping = dataReader.IsDBNull(dataReader.GetOrdinal("typAudio")) ? TAudioChannelMapping.Stereo : (TAudioChannelMapping)dataReader.GetByte("typAudio"); media.HasExtraLines = (typVideo & (byte)0x80) > 0; media._videoFormat = (TVideoFormat)(typVideo & 0x7F); media._idAux = dataReader.IsDBNull(dataReader.GetOrdinal("idAux")) ? string.Empty : dataReader.GetString("idAux"); media._killDate = _readDateTimeField(dataReader, "KillDate"); media._mediaGuid = dataReader.IsDBNull(dataReader.GetOrdinal("MediaGuid")) ? Guid.Empty : dataReader.GetGuid("MediaGuid"); media._mediaEmphasis = (TMediaEmphasis)((flags >> 8) & 0xF); media._parental = (TParental)((flags >> 12) & 0xF); if (media is ServerMedia) ((ServerMedia)media)._doNotArchive = (flags & 0x1) != 0; media._mediaCategory = (TMediaCategory)((flags >> 4) & 0xF); // bits 4-7 of 1st byte }
private static UserPick MapUserPick(MySqlDataReader dr) { var pick = new UserPick { GameId = dr.GetInt64("gameId"), Id = dr.GetInt64("id"), OptionId = dr.GetInt64("gameOptionId"), OptionGroupId = dr.GetInt64("groupId"), OptionType = (GameOptionType) dr.GetInt32("type"), UserId = dr.GetInt64("userId") }; var outcomeOrdinal = dr.GetOrdinal("outcome"); if (!dr.IsDBNull(outcomeOrdinal)) { pick.Outcome = (OptionOutcome) dr.GetInt32(outcomeOrdinal); } return pick; }
/// <summary> /// Downloads the save. /// </summary> /// <param name="lun">Lun. Logged in User</param> /// <param name="path">Path. path for saving the zip</param> public void DownloadSave() { if (loggedIn) { string lun = LoggedInUser; int db_FileSize; byte[] rawData; FileStream fs; //int db_id; //string db_name; //string db_password; openConnection (true); try { string sql = "SELECT save, filesize FROM savebase.saves WHERE username=@username"; cmd = new MySqlCommand (sql, conn); cmd.CommandText = sql; cmd.Parameters.AddWithValue ("@username", lun); myData = cmd.ExecuteReader (); if (! myData.HasRows){ throw new Exception("There are no rows"); } myData.Read(); db_FileSize = myData.GetInt32("filesize"); if (db_FileSize <= 0) { // Debug.Log("no remote save found"); } else { rawData = new byte[db_FileSize]; myData.GetBytes(myData.GetOrdinal("save"), 0, rawData, 0, db_FileSize); fs = new FileStream(@path, FileMode.Create, FileAccess.Write); fs.Write(rawData, 0, db_FileSize); fs.Close(); myData.Close(); conn.Close(); Decompress(); if (SceneManager.GetActiveScene().buildIndex == 0) { feedback.enabled = true; feedbackText.text = "Savegame succesfully downloaded, press Load Game game now"; } } } catch (Exception ex) { Debug.Log (ex.Message.ToString ()); if (ex is MySqlException) { MySqlException ex2 = (MySqlException)ex; Debug.Log (ex2.Number); } Debug.Log (ex.ToString ()); throw ex; } finally { conn.Close (); } } }
public CoulomnInformations(MySqlDataReader reader) { this._Field = reader.GetString(reader.GetOrdinal("Field")); this._Type = reader.GetString(reader.GetOrdinal("Type")); if (!reader.IsDBNull(reader.GetOrdinal("Collation"))) { this._Collation = reader.GetString(reader.GetOrdinal("Collation")); } this._Null = reader.GetString(reader.GetOrdinal("Null")); this._Key = reader.GetString(reader.GetOrdinal("Key")); if (!reader.IsDBNull(reader.GetOrdinal("Default"))) { this._Default = reader.GetString(reader.GetOrdinal("Default")); } this._Extra = reader.GetString(reader.GetOrdinal("Extra")); this._Privileges = reader.GetString(reader.GetOrdinal("Privileges")); this._Comment = reader.GetString(reader.GetOrdinal("Comment")); }
//Update jumlah siswa di kelas public void jumlahSiswa() { try { this.field = "kode_kelas"; this.table = "kelas"; this.cond = "status_kelas = 'Aktif'"; DataTable dt = db.GetDataTable(field, table, cond); foreach (DataRow row in dt.Rows) { string query = "SELECT kode_kelas as 'Kode', count(*) as 'Jumlah' FROM detailkelassiswa INNER JOIN siswa USING (nis_siswa) " + "where kode_kelas = '" + row["kode_kelas"].ToString() + "' AND status_siswa != 'Tidak Aktif'"; myComm = new MySqlCommand(query, myConn); myConn.Open(); using (myReader = myComm.ExecuteReader()) { int kode_kelas = myReader.GetOrdinal("Kode"); while (myReader.Read()) { string kode = myReader.IsDBNull(kode_kelas) ? string.Empty : myReader.GetString("Kode"); string value = myReader.GetString("Jumlah"); string table2 = "kelas"; string field2 = "jumlah_siswa = '" + value + "'"; string cond2 = "kode_kelas = '" + kode + "'"; if (String.IsNullOrEmpty(kode)) { kode = row["kode_kelas"].ToString(); field2 = "jumlah_siswa = '" + value + "'"; cond2 = "kode_kelas = '" + kode + "'"; db.updateData(table2, field2, cond2); } else { db.updateData(table2, field2, cond2); } } } myReader.Close(); myConn.Close(); } } catch (MySqlException myex) { switch (myex.Number) { case 0: MessageBox.Show("Tidak bisa terkkoneksi ke Server."); break; case 1042: MessageBox.Show("Koneksi ke Database atau Server tidak ditemukan."); break; case 1045: MessageBox.Show("username/password salah."); break; default: MessageBox.Show("Terjadi kesalahan data atau aplikasi."); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private static ArchiveMedia _readArchiveMedia(MySqlDataReader dataReader, ArchiveDirectory dir) { byte typVideo = dataReader.IsDBNull(dataReader.GetOrdinal("typVideo")) ? (byte)0 : dataReader.GetByte("typVideo"); ArchiveMedia media = new ArchiveMedia() { idPersistentMedia = dataReader.GetUInt64("idArchiveMedia"), Directory = dir, }; _mediaReadFields(dataReader, media); ThreadPool.QueueUserWorkItem(o => media.Verify()); return media; }
public static string GetStringFromReader(MySqlDataReader reader, string columnName) { return reader.IsDBNull(reader.GetOrdinal(columnName)) ? null : reader.GetString(columnName); }
private static DateTime _readDateTimeField(MySqlDataReader dataReader, string fieldName) { DateTime result = default(DateTime); try { result = dataReader.IsDBNull(dataReader.GetOrdinal(fieldName)) ? default(DateTime) : DateTime.SpecifyKind(dataReader.GetDateTime(fieldName), DateTimeKind.Utc); } catch (Exception e) { Debug.WriteLine(e.Message, e.StackTrace); } return result; }
private MembershipUser GetUserFromReader(MySqlDataReader reader) { object providerUserKey = reader.GetInt32("userId"); string username = reader.GetString("name"); string email = null; if (!reader.IsDBNull(reader.GetOrdinal("Email"))) email = reader.GetString("Email"); string passwordQuestion = ""; if (!(reader.GetValue(reader.GetOrdinal("PasswordQuestion")) == DBNull.Value)) passwordQuestion = reader.GetString("PasswordQuestion"); string comment = ""; if (!(reader.GetValue(reader.GetOrdinal("Comment")) == DBNull.Value)) comment = reader.GetString("Comment"); bool isApproved = reader.GetBoolean("IsApproved"); bool isLockedOut = reader.GetBoolean("IsLockedOut"); DateTime creationDate = reader.GetDateTime("CreationDate"); DateTime lastLoginDate = new DateTime(); if (!(reader.GetValue(reader.GetOrdinal("LastLoginDate")) == DBNull.Value)) lastLoginDate = reader.GetDateTime("LastLoginDate"); DateTime lastActivityDate = reader.GetDateTime("LastActivityDate"); DateTime lastPasswordChangedDate = reader.GetDateTime("LastPasswordChangedDate"); DateTime lastLockedOutDate = new DateTime(); if (!(reader.GetValue(reader.GetOrdinal("LastLockedoutDate")) == DBNull.Value)) lastLockedOutDate = reader.GetDateTime("LastLockedoutDate"); MembershipUser u = new MembershipUser(Name, username, providerUserKey, email, passwordQuestion, comment, isApproved, isLockedOut, creationDate, lastLoginDate, lastActivityDate, lastPasswordChangedDate, lastLockedOutDate); return u; }
public static bool? getBool(MySqlDataReader dr, string column) { int ordinal = dr.GetOrdinal(column); if (dr.IsDBNull(ordinal)) { return null; } else { return dr.GetBoolean(ordinal); } }
private static UserRecord MapUserRecord(MySqlDataReader dr) { var record = new UserRecord(); record.Id = dr.GetInt64("id"); record.LastUpdated = dr.GetDateTime("lastUpdated"); record.Losses = dr.GetInt32("losses"); record.RecordType = (RecordType)dr.GetInt32("type"); record.Ties = dr.GetInt32("ties"); record.UserId = dr.GetInt64("userId"); record.UserName = dr.GetString("userName"); record.Wins = dr.GetInt32("wins"); if (!dr.IsDBNull(dr.GetOrdinal("season"))) { record.Season = dr.GetInt32("season"); } if (!dr.IsDBNull(dr.GetOrdinal("seasonType"))) { record.SeasonType = (SeasonType) dr.GetInt32("seasonType"); } if (!dr.IsDBNull(dr.GetOrdinal("week"))) { record.Week = dr.GetInt32("week"); } return record; }
public static double? getDouble(MySqlDataReader dr, string column) { int ordinal = dr.GetOrdinal(column); if (dr.IsDBNull(ordinal)) { return null; } else { return dr.GetDouble(ordinal); } }
private static LeagueInvitation MapInvitation(MySqlDataReader dr) { var invite = new LeagueInvitation { Created = dr.GetDateTime("created"), Email = dr.GetString("email"), Id = dr.GetInt64("id"), InvitationToken = dr.GetString("inviteToken"), LeagueId = dr.GetInt64("leagueId"), SentByUserId = dr.GetInt64("sentByUserId"), Status = (InviteStatus) dr.GetInt32("status") }; var userIdOrdinal = dr.GetOrdinal("userId"); var inviteSentOnOrdinal = dr.GetOrdinal("inviteSentOn"); var acceptedOnOrdinal = dr.GetOrdinal("acceptedOn"); if (!dr.IsDBNull(userIdOrdinal)) { invite.UserId = dr.GetInt64("userId"); } if (!dr.IsDBNull(inviteSentOnOrdinal)) { invite.InviteSentOn = dr.GetDateTime("inviteSentOn"); } if (!dr.IsDBNull(acceptedOnOrdinal)) { invite.AcceptedOn = dr.GetDateTime("acceptedOn"); } return invite; }
public static uint? getUInt(MySqlDataReader dr, string column) { int ordinal = dr.GetOrdinal(column); if (dr.IsDBNull(ordinal)) { return null; } else { return dr.GetUInt32(ordinal); } }
public void setProperty(MySqlDataReader reader) { this._Name = reader.GetString(reader.GetOrdinal("Name")); this._Engine = reader.GetString(reader.GetOrdinal("Engine")); this._Version = reader.GetInt64(reader.GetOrdinal("Version")); this._Row_format = reader.GetString(reader.GetOrdinal("Row_format")); if (!reader.IsDBNull(reader.GetOrdinal("Rows"))) { this._Rows = reader.GetInt64(reader.GetOrdinal("Rows")); } this._Avg_row_length = reader.GetInt64(reader.GetOrdinal("Avg_row_length")); this._Data_length = reader.GetInt64(reader.GetOrdinal("Data_length")); this._Max_data_length = reader.GetInt64(reader.GetOrdinal("Max_data_length")); this._Index_length = reader.GetInt64(reader.GetOrdinal("Index_length")); this._Data_free = reader.GetInt64(reader.GetOrdinal("Data_free")); if (!reader.IsDBNull(reader.GetOrdinal("Auto_increment"))) { this._Auto_increment = reader.GetInt64(reader.GetOrdinal("Auto_increment")); } if (!reader.IsDBNull(reader.GetOrdinal("Create_time"))) { this._Create_time = reader.GetDateTime(reader.GetOrdinal("Create_time")); } if (!reader.IsDBNull(reader.GetOrdinal("Update_time"))) { this._Update_time = reader.GetDateTime(reader.GetOrdinal("Update_time")); } if (!reader.IsDBNull(reader.GetOrdinal("Check_time"))) { this._Check_time = reader.GetDateTime(reader.GetOrdinal("Check_time")); } this._Collation = reader.GetString(reader.GetOrdinal("Collation")); if (!reader.IsDBNull(reader.GetOrdinal("Checksum"))) { this._Checksum = reader.GetInt64(reader.GetOrdinal("Checksum")); } this._Create_options = reader.GetString(reader.GetOrdinal("Create_options")); this._Comment = reader.GetString(reader.GetOrdinal("Comment")); }
public static string GetString(string fieldName, MySqlDataReader reader) { var ordinal = reader.GetOrdinal(fieldName); return reader.IsDBNull(ordinal) ? string.Empty : reader.GetString(ordinal); }
private static Event _EventRead(Engine engine, MySqlDataReader dataReader) { Event aEvent = new Event(engine); uint flags = dataReader.IsDBNull(dataReader.GetOrdinal("flagsEvent")) ? 0 : dataReader.GetUInt32("flagsEvent"); aEvent._idRundownEvent = dataReader.GetUInt64("idRundownEvent"); aEvent._layer = (VideoLayer)dataReader.GetSByte("Layer"); aEvent._eventType = (TEventType)dataReader.GetByte("typEvent"); aEvent._startType = (TStartType)dataReader.GetByte("typStart"); aEvent._scheduledTime = _readDateTimeField(dataReader, "ScheduledTime"); aEvent._duration = dataReader.IsDBNull(dataReader.GetOrdinal("Duration")) ? default(TimeSpan) : aEvent.Engine.AlignTimeSpan(dataReader.GetTimeSpan("Duration")); aEvent._scheduledDelay = dataReader.IsDBNull(dataReader.GetOrdinal("ScheduledDelay")) ? default(TimeSpan) : aEvent.Engine.AlignTimeSpan(dataReader.GetTimeSpan("ScheduledDelay")); aEvent._scheduledTC = dataReader.IsDBNull(dataReader.GetOrdinal("ScheduledTC")) ? TimeSpan.Zero : dataReader.GetTimeSpan("ScheduledTC"); aEvent._mediaGuid = (dataReader.IsDBNull(dataReader.GetOrdinal("MediaGuid"))) ? Guid.Empty : dataReader.GetGuid("MediaGuid"); aEvent._eventName = dataReader.IsDBNull(dataReader.GetOrdinal("EventName")) ? default(string) : dataReader.GetString("EventName"); var psb = dataReader.GetByte("PlayState"); aEvent._playState = (TPlayState)psb; if (aEvent._playState == TPlayState.Playing || aEvent._playState == TPlayState.Paused) aEvent._playState = TPlayState.Aborted; if (aEvent._playState == TPlayState.Fading) aEvent._playState = TPlayState.Played; aEvent._startTime = _readDateTimeField(dataReader, "StartTime"); aEvent._startTC = dataReader.IsDBNull(dataReader.GetOrdinal("StartTC")) ? TimeSpan.Zero : dataReader.GetTimeSpan("StartTC"); aEvent._requestedStartTime = dataReader.IsDBNull(dataReader.GetOrdinal("RequestedStartTime")) ? null : (TimeSpan?)dataReader.GetTimeSpan("RequestedStartTime"); aEvent._transitionTime = dataReader.IsDBNull(dataReader.GetOrdinal("TransitionTime")) ? default(TimeSpan) : dataReader.GetTimeSpan("TransitionTime"); aEvent._transitionType = (TTransitionType)dataReader.GetByte("typTransition"); aEvent._audioVolume = dataReader.IsDBNull(dataReader.GetOrdinal("AudioVolume")) ? 0 : dataReader.GetDecimal("AudioVolume"); aEvent._idProgramme = dataReader.IsDBNull(dataReader.GetOrdinal("idProgramme")) ? 0 : dataReader.GetUInt64("idProgramme"); aEvent._idAux = dataReader.IsDBNull(dataReader.GetOrdinal("IdAux")) ? default(string) : dataReader.GetString("IdAux"); aEvent._enabled = (flags & (1 << 0)) != 0; aEvent._hold = (flags & (1 << 1)) != 0; EventGPI.FromUInt64(ref aEvent._gPI, (flags >> 4) & EventGPI.Mask); aEvent._nextLoaded = false; return aEvent; }
public List<String> getUniqueConstraints(String SCHEMA_NAME, String TABLE_NAME) { List<String> items = new List<string>(); CultureInfo info = Thread.CurrentThread.CurrentCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-GB"); try { _command.CommandText = "SELECT" + " information_schema.KEY_COLUMN_USAGE.COLUMN_NAME," + " information_schema.TABLE_CONSTRAINTS.CONSTRAINT_NAME" + " FROM" + " information_schema.KEY_COLUMN_USAGE," + " information_schema.TABLE_CONSTRAINTS" + " WHERE" + " information_schema.TABLE_CONSTRAINTS.CONSTRAINT_NAME = information_schema.KEY_COLUMN_USAGE.CONSTRAINT_NAME" + " AND" + " information_schema.KEY_COLUMN_USAGE.CONSTRAINT_SCHEMA='" + SCHEMA_NAME + "'" + " AND" + " information_schema.KEY_COLUMN_USAGE.TABLE_NAME='" + TABLE_NAME + "'" + " AND" + " information_schema.TABLE_CONSTRAINTS.CONSTRAINT_TYPE='UNIQUE'" + " GROUP BY" + " COLUMN_NAME" + ";"; _reader = _command.ExecuteReader(); while (_reader.Read()) { items.Add(_reader.GetString(_reader.GetOrdinal("COLUMN_NAME"))); } } catch (MySqlException ex) { throw (ex); } finally { _reader.Close(); Thread.CurrentThread.CurrentCulture = info; } return items; }