//public static string GetHDDSerialNumber(string drive) //{ // //check to see if the user provided a drive letter // //if not default it to "C" // if (drive == "" || drive == null) // { // drive = "C"; // } // //create our ManagementObject, passing it the drive letter to the // //DevideID using WQL // ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + drive + ":\""); // //bind our management object // disk.Get(); // //return the serial number // return disk["VolumeSerialNumber"].ToString(); //} public static void writeLoginLogs(int userid, int eventid, String desc) { ModelUserLogs log = new ModelUserLogs(); log.user_id = userid; log.event_id = eventid; log.log_description = desc; userlogs.Insert(log); }
//Insert statement public Boolean Insert(ModelUserLogs model) { try { string query = "INSERT INTO tb_users_log(user_id,event_id,log_description,log_date) VALUES(" + model.user_id + "," + model.event_id + ",'" + model.log_description + "','" + DateTime.Now.ToString() + "')"; //open connection //if (this.OpenConnection() == true) //{ using (MySqlConnection connection = new MySqlConnection(Configurations.MysqlStr)) { connection.Open(); //create command and assign the query and connection from the constructor MySqlCommand cmd = new MySqlCommand(query, connection); //Execute command cmd.ExecuteNonQuery(); } //close connection //this.CloseConnection(); //} //else { // this.CloseConnection(); // if (this.OpenOffineConnection() == true) // { // //Create Command // SQLiteCommand cmd = new SQLiteCommand(query, connectionOffine); // cmd.ExecuteNonQuery(); // //close Connection // this.CloseOffineConnection(); // } //} } catch (Exception ex) { logger.Error(ex.InnerException); //System.Windows.Forms.MessageBox.Show(ex.Message); return(false); } return(true); }
//Select statement public List <ModelUserLogs> Select(String cri) { string query = "SELECT * FROM tb_users_log " + cri; //Create a list to store the result List <ModelUserLogs> lists = new List <ModelUserLogs>(); //Open connection //if (this.OpenConnection() == true) //{ using (MySqlConnection connection = new MySqlConnection(Configurations.MysqlStr)) { connection.Open(); //Create Command MySqlCommand cmd = new MySqlCommand(query, connection); //Create a data reader and Execute the command MySqlDataReader dr = cmd.ExecuteReader(); //Read the data and store them in the list while (dr.Read()) { ModelUserLogs transaction = new ModelUserLogs(); transaction.id = (DBNull.Value == dr["id"]) ? -1 : Convert.ToInt16(dr["id"]); transaction.user_id = (DBNull.Value == dr["user_id"]) ? -1 : Convert.ToInt16(dr["user_id"]); transaction.event_id = (DBNull.Value == dr["event_id"]) ? -1 : Convert.ToInt16(dr["event_id"]); transaction.log_description = (DBNull.Value == dr["log_description"]) ? "" : Convert.ToString(dr["log_description"]); transaction.log_date = Convert.ToDateTime(dr["log_date"]); lists.Add(transaction); } //close Data Reader dr.Close(); } //close Connection //this.CloseConnection(); //return list to be displayed return(lists); //} //else //{ // this.CloseConnection(); // if (this.OpenOffineConnection() == true) // { // //Create Command // SQLiteCommand cmd = new SQLiteCommand(query, connectionOffine); // //Create a data reader and Execute the command // SQLiteDataReader dr = cmd.ExecuteReader(); // //Read the data and store them in the list // while (dr.Read()) // { // ModelUserLogs model = new ModelUserLogs(); // model.id = (DBNull.Value == dr["id"]) ? -1 : Convert.ToInt16(dr["id"]); // model.user_id = (DBNull.Value == dr["user_id"]) ? -1 : Convert.ToInt16(dr["user_id"]); // model.event_id = (DBNull.Value == dr["event_id"]) ? -1 : Convert.ToInt16(dr["event_id"]); // model.log_description = (DBNull.Value == dr["log_description"]) ? "" : Convert.ToString(dr["log_description"]); // model.log_date = Convert.ToDateTime(dr["log_date"]); // lists.Add(model); // } // //close Data Reader // dr.Close(); // //close Connection // this.CloseOffineConnection(); // } // else // { // System.Windows.Forms.MessageBox.Show("Can't Connect to Offine DB!! Please contact Developer"); // } // return lists; //} }