public async Task dCoinsShow(params String[] UserL) { string output = ""; for (int i = 0; i < UserL.Length; i++) { output += UserL.ElementAt(i); if (i != UserL.Length - 1) { output += " "; } } if (output != "") { if (output.IndexOf('@') == 1) { try { output = output.Remove(0, 2); output = output.Remove(output.Length - 1, 1); if (output.IndexOf('!') == 0) { output = output.Remove(0, 1); } SocketGuildUser j = null; var n = Initialization._client.Guilds.GetEnumerator(); n.MoveNext(); var g = n.Current; for (int i = 0; i < Initialization._client.Guilds.Count; i++) { g = n.Current; n.MoveNext(); if (j == null) { j = g.Users.FirstOrDefault(x => x.Id == ulong.Parse(output)); } } if (j == null) { throw new Exception(); } EmbedBuilder eb = new EmbedBuilder(); eb.WithAuthor($"Succesfull", Context.User.GetAvatarUrl()); eb.WithColor(40, 200, 150); eb.WithDescription($"**{j.Username}'s balance is: **" + DBData.getCoins(j.Id)); eb.WithThumbnailUrl(j.GetAvatarUrl()); await Context.Channel.SendMessageAsync("", false, eb.Build()); return; } catch (Exception) { EmbedBuilder eb = new EmbedBuilder(); eb.WithAuthor($"Error", Context.User.GetAvatarUrl()); eb.WithColor(40, 200, 150); eb.WithDescription($"**Can't find user with id {output} in all connected to the bot servers.**"); eb.WithThumbnailUrl(Settings.MainThumbnailUrl); await Context.Channel.SendMessageAsync("", false, eb.Build()); return; } } else { try { var n = Initialization._client.Guilds.GetEnumerator(); n.MoveNext(); var g = n.Current; SocketGuildUser j = null; for (int i = 0; i < Initialization._client.Guilds.Count; i++) { g = n.Current; n.MoveNext(); if (j == null) { j = g.Users.FirstOrDefault(x => x.Username == output); } } if (j == null) { throw new Exception(); } EmbedBuilder eb = new EmbedBuilder(); eb.WithAuthor($"Succesfull", Context.User.GetAvatarUrl()); eb.WithColor(40, 200, 150); eb.WithDescription($"**{j.Username}'s balance is: **" + DBData.getCoins(j.Id)); eb.WithThumbnailUrl(j.GetAvatarUrl()); await Context.Channel.SendMessageAsync("", false, eb.Build()); return; } catch (Exception) { EmbedBuilder eb = new EmbedBuilder(); eb.WithAuthor($"Error", Context.User.GetAvatarUrl()); eb.WithColor(40, 200, 150); eb.WithDescription($"**Can't find user with username \"{output}\" in all connected to the bot servers.**"); eb.WithThumbnailUrl(Settings.MainThumbnailUrl); await Context.Channel.SendMessageAsync("", false, eb.Build()); return; } } } else { EmbedBuilder eb = new EmbedBuilder(); eb.WithAuthor($"Succesfull", Context.User.GetAvatarUrl()); eb.WithColor(40, 200, 150); eb.WithDescription("**Your balance is:** " + DBData.getCoins(Context.User.Id)); eb.WithThumbnailUrl(Context.User.GetAvatarUrl()); await Context.Channel.SendMessageAsync("", false, eb.Build()); } }
/// <summary> /// Write out this query to its output file. /// </summary> /// <returns>A Problem if one was encountered</returns> /// <exception cref="QueryException">Throws QueryExceptions for any exceptions encountered.</exception> public void Write() { List <string> lines = new List <string>(); DBData data = null; using (MSAccessConnection conn = new MSAccessConnection(Database)) { try { conn.Open(); } catch (ThreadAbortException) { throw; } catch (Exception e) { throw new QueryException(this, "Exception encountered when attempting to connect to database at " + Database + ": " + e.Message, e); } try { if (QueryStatement.Length > 0) { data = new DBData(conn.Query(QueryStatement)); } else { data = new DBData(conn.Select(DataView.Length > 0 ? DataView : Name)); } } catch (ThreadAbortException) { throw; } catch (Exception e) { throw new QueryException(this, "Exception encountered when attempting to access query " + Name + " in " + Database + ": " + e.Message, e); } } try { if (Transpose) { for (int i = 0; i < data.Headers.Length; i++) { StringBuilder line = new StringBuilder(); if (PrintHeaders) { line.Append(data.Headers[i]); } for (int j = 0; j < data.Data.Count; j++) { if (PrintHeaders || j > 0) { line.Append(Delimiter); } line.Append(data.Data[j][data.Headers[i]]); } lines.Add(line.ToString()); } } else { if (PrintHeaders) { lines.Add(data.Headers.Join()); } for (int i = 0; i < data.Data.Count; i++) { StringBuilder line = new StringBuilder(); for (int j = 0; j < data.Headers.Length; j++) { if (j > 0) { line.Append(Delimiter); } line.Append(data.Data[i][data.Headers[j]]); } lines.Add(line.ToString()); } } } catch (ThreadAbortException) { throw; } catch (Exception e) { throw new QueryException(this, "Exception encountered when attempting to parse data from query " + Name + " in " + Database + ": " + e.Message, e); } try { Output.Output(lines.Join(Environment.NewLine)); } catch (ThreadAbortException) { throw; } catch (Exception e) { throw new QueryException(this, "Exception encountered when attempting to output data from query " + Name + " in " + Database + ": " + e.Message, e); } }
public async Task DailyCoins() { if (Context.Message.Timestamp.UtcDateTime.Day.ToString() != await DBData.getDailyTimestamp(Context.User.Id)) { await DBData.saveCoins(Context.User.Id, 1000); await DBData.saveTimeStamp(Context.User.Id); EmbedBuilder eb = new EmbedBuilder(); eb.WithColor(40, 200, 150); eb.WithThumbnailUrl(Context.User.GetAvatarUrl()); eb.WithAuthor("Successful"); eb.WithDescription("1000 daily coins had successfully given!" + Environment.NewLine + $"Your balance is now: {DBData.getCoins(Context.User.Id)} Ducky Coins"); await Context.Channel.SendMessageAsync("", false, eb.Build()); } else { EmbedBuilder eb = new EmbedBuilder(); eb.WithColor(40, 200, 150); eb.WithThumbnailUrl(Context.User.GetAvatarUrl()); eb.WithAuthor("Error"); eb.WithDescription("You must wait 1 day to use that command next time!"); await Context.Channel.SendMessageAsync("", false, eb.Build()); } }
public async Task giveDCoins(int amount = 0, params String[] UserL) { string output = ""; for (int i = 0; i < UserL.Length; i++) { output += UserL.ElementAt(i); if (i != UserL.Length - 1) { output += " "; } } if (output != "") { if (output.IndexOf('@') == 1) { try { output = output.Remove(0, 2); output = output.Remove(output.Length - 1, 1); if (output.IndexOf('!') == 0) { output = output.Remove(0, 1); } SocketGuildUser j = null; var n = Initialization._client.Guilds.GetEnumerator(); n.MoveNext(); var g = n.Current; for (int i = 0; i < Initialization._client.Guilds.Count; i++) { g = n.Current; n.MoveNext(); if (j == null) { j = g.Users.FirstOrDefault(x => x.Id == ulong.Parse(output)); } } if (j == null) { throw new Exception(); } if (j.IsBot) { EmbedBuilder eb1 = new EmbedBuilder(); eb1.WithAuthor($"Error", Context.User.GetAvatarUrl()); eb1.WithColor(40, 200, 150); eb1.WithDescription($"**Can't give {amount} Ducky Coins to {j.Username}, cause it's a bot!**"); eb1.WithThumbnailUrl(j.GetAvatarUrl()); await Context.Channel.SendMessageAsync("", false, eb1.Build()); return; } if (DBData.getCoins(Context.User.Id) < amount) { EmbedBuilder eb2 = new EmbedBuilder(); eb2.WithAuthor($"Error", Context.User.GetAvatarUrl()); eb2.WithColor(40, 200, 150); eb2.WithDescription($"**You don't have {amount} Ducky Coins to give them**"); eb2.WithThumbnailUrl(j.GetAvatarUrl()); await Context.Channel.SendMessageAsync("", false, eb2.Build()); return; } await DBData.saveCoins(j.Id, amount); await DBData.removeCoins(Context.User.Id, amount); EmbedBuilder eb = new EmbedBuilder(); eb.WithAuthor($"Succesfull", Context.User.GetAvatarUrl()); eb.WithColor(40, 200, 150); eb.WithDescription($"**Succesfully gave {amount} Ducky Coins to {j.Username}**"); eb.WithThumbnailUrl(j.GetAvatarUrl()); await Context.Channel.SendMessageAsync("", false, eb.Build()); return; } catch (Exception) { if (amount >= 0) { EmbedBuilder eb1 = new EmbedBuilder(); eb1.WithAuthor($"Error", Context.User.GetAvatarUrl()); eb1.WithColor(40, 200, 150); eb1.WithDescription($"**Can't find user with id {output} in all connected to the bot servers.**"); eb1.WithThumbnailUrl(Settings.MainThumbnailUrl); await Context.Channel.SendMessageAsync("", false, eb1.Build()); } else { EmbedBuilder eb1 = new EmbedBuilder(); eb1.WithAuthor($"Error", Context.User.GetAvatarUrl()); eb1.WithColor(40, 200, 150); eb1.WithDescription($"**Please type right amount of Ducky Coins to give them.**"); eb1.WithThumbnailUrl(Settings.MainThumbnailUrl); await Context.Channel.SendMessageAsync("", false, eb1.Build()); } return; } } else { try { var n = Initialization._client.Guilds.GetEnumerator(); n.MoveNext(); var g = n.Current; SocketGuildUser j = null; for (int i = 0; i < Initialization._client.Guilds.Count; i++) { g = n.Current; n.MoveNext(); if (j == null) { j = g.Users.FirstOrDefault(x => x.Username == output); } } if (j == null) { throw new Exception(); } if (j.IsBot) { EmbedBuilder eb1 = new EmbedBuilder(); eb1.WithAuthor($"Error", Context.User.GetAvatarUrl()); eb1.WithColor(40, 200, 150); eb1.WithDescription($"**Can't give {amount} Ducky Coins to {j.Username}, cause it is a bot!**"); eb1.WithThumbnailUrl(j.GetAvatarUrl()); await Context.Channel.SendMessageAsync("", false, eb1.Build()); return; } if (DBData.getCoins(Context.User.Id) < amount) { EmbedBuilder eb1 = new EmbedBuilder(); eb1.WithAuthor($"Error", Context.User.GetAvatarUrl()); eb1.WithColor(40, 200, 150); eb1.WithDescription($"**You don't have {amount} Ducky Coins to give them**"); eb1.WithThumbnailUrl(j.GetAvatarUrl()); await Context.Channel.SendMessageAsync("", false, eb1.Build()); return; } await DBData.saveCoins(j.Id, amount); await DBData.removeCoins(Context.User.Id, amount); EmbedBuilder eb = new EmbedBuilder(); eb.WithAuthor($"Succesfull", Context.User.GetAvatarUrl()); eb.WithColor(40, 200, 150); eb.WithDescription($"**Succesfully gave {amount} Ducky Coins to {j.Username}**"); eb.WithThumbnailUrl(j.GetAvatarUrl()); await Context.Channel.SendMessageAsync("", false, eb.Build()); return; } catch (Exception) { if (amount >= 0) { EmbedBuilder eb1 = new EmbedBuilder(); eb1.WithAuthor($"Error", Context.User.GetAvatarUrl()); eb1.WithColor(40, 200, 150); eb1.WithDescription($"**Can't find user with id {output} in all connected to the bot servers.**"); eb1.WithThumbnailUrl(Settings.MainThumbnailUrl); await Context.Channel.SendMessageAsync("", false, eb1.Build()); } else { EmbedBuilder eb1 = new EmbedBuilder(); eb1.WithAuthor($"Error", Context.User.GetAvatarUrl()); eb1.WithColor(40, 200, 150); eb1.WithDescription($"**Please type right amount of Ducky Coins to give them.**"); eb1.WithThumbnailUrl(Settings.MainThumbnailUrl); await Context.Channel.SendMessageAsync("", false, eb1.Build()); } return; } } } }
//マイナスになってはいけないデータの確認など public virtual void DataUpdateAction(DBData data) { }
public void UpdateData(DBData data) { _data = data; UpdateMember(); }
public BaseController() { db = DBData.Instance; }
public static bool TryLoad(string pswd, out List <DBData> result, out string eMessage) { eMessage = ""; result = new List <DBData>(); try { using (var client = new SQLiteConnection(GetConnectionString(pswd, false))) { client.Open(); Create(client); var query = string.Format("SELECT * FROM DATA;"); using (var command = new SQLiteCommand(query, client)) { using (var reader = command.ExecuteReader()) { while (reader.Read()) { var newData = new DBData { Id = reader.GetInt32(0), Url = reader.GetString(1), Description = reader.GetString(2), Icon = reader.GetString(3) }; result.Add(newData); // Загружаем список записей query = string.Format("SELECT * FROM DATA_RECORD WHERE DataId={0};", newData.Id); using (var command2 = new SQLiteCommand(query, client)) { using (var reader2 = command2.ExecuteReader()) { while (reader2.Read()) { // "Id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, " + //"DataId INTEGER, " + //"Name TEXT, " + //"Value TEXT, " + //"Description TEXT, " + newData.Records.Add( new DataRecord { Id = reader2.GetInt32(0), DataId = reader2.GetInt32(1), Name = reader2.GetString(2), Value = reader2.GetString(3), Description = reader2.GetString(4), }); } } } } } } } return(true); } catch (Exception ex) { eMessage = string.Format("Ошибка Загрузки данных: {0}", ex.Message); return(false); } }
/// <summary> /// Returns the data from local file by desirialization /// </summary> /// <returns>Desirializated data</returns> public ItemsCollection GetBLData() { var data = DBData.DeSerialize <ItemsCollection>(); return(data); }
/// <summary> /// Saves entire Library to the local file by Serialization /// </summary> /// <param name="data">Data to save</param> public void SaveData(ItemsCollection data) { DBData.Serialize(data); }
public void SetFlashData(string key, DBData data) { _flashDBData.Add(key, data); }
private void CalSalary() //Calculate Salary { //Assuming 25th is the Salary paying Day int Date = Convert.ToInt32(DateTime.Now.Date.ToString("dd")); if (Date == 25) { String sql = ""; DBData db = new DBData(); List <SqlCommand> sqlCmd = new List <SqlCommand>(); int Year = Convert.ToInt32(DateTime.Now.Date.ToString("yyyy")); int Month = Convert.ToInt32(DateTime.Now.Date.ToString("MM")); String date = DateTime.Now.Date.ToString("yyyy-MM"); sql = "SELECT * FROM StaffView"; SqlCommand cmd = new SqlCommand(sql, db.Con()); try { db.Connect(); SqlDataReader rdr1 = cmd.ExecuteReader(); while (rdr1.Read()) { int FullDay = 0, HalfDay = 0, OTH = 0, OTP = 0, BS = 0, Tot = 0; String staffId = rdr1.GetString(0); sql = "SELECT StaffID FROM SalView WHERE StaffID='" + staffId + "' AND Year='" + Year + "' AND Month='" + Month + "'"; cmd = new SqlCommand(sql, db.Con()); SqlDataReader rdr2 = cmd.ExecuteReader(); if (!rdr2.Read()) //If Not Available. Mean Not yet Salary Calculated { sql = "SELECT * FROM Attendance WHERE RegID = '" + staffId + "' AND ADate LIKE '" + date + "%'"; cmd = new SqlCommand(sql, db.Con()); SqlDataReader rdr3 = cmd.ExecuteReader(); while (rdr3.Read()) { TimeSpan t1 = rdr3.GetTimeSpan(4) - rdr3.GetTimeSpan(3); if (t1.Hours > 8) { FullDay += 1; OTH += (t1.Hours - 8); } else if (t1.Hours == 8) { FullDay += 1; } else if (t1.Hours >= 4) { HalfDay += 1; } } rdr3.Close(); rdr3.Dispose(); sql = "SELECT BSalary,OTP FROM JobRole WHERE RoleID = (SELECT RoleID FROM EmpRole WHERE StaffID='" + staffId + "')"; cmd = new SqlCommand(sql, db.Con()); rdr3 = cmd.ExecuteReader(); if (rdr3.Read()) { BS = rdr3.GetInt32(0); OTP = rdr3.GetInt32(0); //OT Payment per Hour } rdr3.Close(); rdr3.Dispose(); OTP = OTP * OTH; //This is Total OT Payment Per Month Tot = BS + OTP; cmd = new SqlCommand(); cmd.CommandText = "MonthlySal"; //Salary Procedure Name RegPara(cmd, staffId, Year, Month, OTP, BS, Tot); sqlCmd.Add(cmd); //Add To SqlCommand List } rdr2.Close(); rdr2.Dispose(); } rdr1.Close(); rdr1.Dispose(); } catch (Exception ex) { } finally { cmd.Dispose(); db.DisConnect(); } if (sqlCmd != null) { foreach (SqlCommand cmdInsert in sqlCmd) { db.Execute(cmdInsert); } } } }
public zwtpController(DBData context) { _context = context; }