public static void Initialize() { if (Categories == null) { Categories = new Dictionary<int, string>(); Database db = new Database(); var cat = db.getAllCategories(); foreach (var c in cat) { Categories.Add(c.ID, c.Name); } } isInitialized = true; }
protected override void OnLoad(EventArgs e) { //Get from login if (Session["user_id"] == null) { Response.Redirect("Login.aspx"); } db = new Database(); DateTime from = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0)); DateTime to = DateTime.Now; if (Request.QueryString.HasKeys()) { from = Convert.ToDateTime(Request.QueryString["start"]); to = Convert.ToDateTime(Request.QueryString["end"]); } ShowData(from, to); }
public static string AJAX_DailyStats(string type) { Database db = new Database(); List<Transaction> transactions = null; switch (type) { case "1": break; case "2": break; case "3": break; } transactions = db.getFromToTransactions(int.Parse(HttpContext.Current.Session["user_id"].ToString()), DateTime.Now.Subtract(new TimeSpan(7, 0, 0, 0, 0)), DateTime.Now, int.Parse(type)); //return chart data return HelperTools.FormatToChartData(transactions); }
private static Transaction ValidateAndAdd(TransactionType type, string name, int amount, int category_id, string comment) { Database db = new Database(); var user = int.Parse(HttpContext.Current.Session["user_id"].ToString()); int comment_id = -1; if (!string.IsNullOrWhiteSpace(comment)) { comment_id = (int)db.addComment(comment); db.addTransaction(category_id, user, (int)comment_id, amount, DateTime.Now, name, type == TransactionType.Wishlist); } else { db.addTransactionBezKomentar(category_id, user, amount, DateTime.Now, name, type == TransactionType.Wishlist); } return new Transaction() { Category = new Category(category_id, HelperTools.Categories[category_id]), Date = DateTime.Now, Type = (int)type, Amount = amount, Comment_ID = comment_id, ID = -1, Name = name }; }
public static string AJAX_TransactionData(string from, string to, string type) { DateTime dateFrom = Convert.ToDateTime(from); DateTime dateTo = Convert.ToDateTime(to); Database db = new Database(); var transactions = db.getFromToTransactions(int.Parse(HttpContext.Current.Session["user_id"].ToString()), dateFrom, dateTo, int.Parse(type)); //return chart data return HelperTools.FormatTransactions(transactions); }
public static string AJAX_GetCurrentFunds() { Database db = new Database(); int user_id = (int)HttpContext.Current.Session["user_id"]; int saved_funds = db.getSavedFunds(user_id); int curr_funds = db.currentFunds(user_id); StringBuilder sb = new StringBuilder(); sb.Append("{"); sb.Append("\"funds\": "); sb.Append(curr_funds); sb.Append(", "); sb.Append("\"saved_funds\": "); sb.Append(saved_funds); sb.Append("}"); return sb.ToString(); }
//brisenje na daden element od transakcii void removeTransaction(int transaction_id) { Database db = new Database(); db.removeTransaction(transaction_id); }
public static string AJAX_removeTransaction(int transaction_id) { Database db = new Database(); return db.removeTransaction(transaction_id).ToString(); }
public static string AJAX_RemoveWishlist(string id) { int _id = int.Parse(id); Database db = new Database(); return db.removeTransaction(_id).ToString(); }
public static string AJAX_BuyWishlist(string id) { int _id = int.Parse(id); Database db = new Database(); return db.buyItemFromWishlist(_id); }
internal static User authenticateUser(string username, string password) { //da se naprave funkcija za avtentikacija na korisnikot i da vrakja User so site parametri so gi ima za user Database db = new Database(); MySqlConnection konekcija = db.getConnection(); string sqlString = "SELECT * FROM user WHERE username=@username " + "AND password=AES_ENCRYPT(@password, SHA1(@username))";// AND is_active = 1"; // neznam so e is_active zatoa e iskomentirano :D nema takvo nesto vo bazata zacuvano :) MySqlCommand komanda = new MySqlCommand(sqlString, konekcija); komanda.Parameters.AddWithValue("@username", username); komanda.Parameters.AddWithValue("@password", password); try { konekcija.Open(); MySqlDataReader citac = komanda.ExecuteReader(); if (citac.Read()) { // mozi da se zemi i datumot koga e kreiran userot... // dokolku se dodade pole vo User klasata za datum // u.datum = citac["datum"] User u = new User(); u.username = citac["username"] as string; u.name = citac["name"] as string; u.user_id = int.Parse(citac["user_id"].ToString()); ; u.funds = int.Parse(citac["funds"].ToString()); ; u.email = citac["e_mail"] as string; // u.user_id = int.Parse(citac["user_id"].ToString()); // u.name = citac["first_name"].ToString(); // u.last_name = citac["last_name"].ToString(); // u.organization_id = int.Parse(citac["organization_id"].ToString()); return u; } else return null; } catch (Exception err) { Console.Write(err.ToString()); } finally { konekcija.Close(); } return null; }