protected void departmentdelete_Click(object sender, EventArgs e) { int dno = Int32.Parse((sender as Button).CommandArgument.ToString()); string sql = "delete from tb_department where dno ='" + dno + "'"; try { if (DBControl.delete(sql) > 0) { DepartmentListView.DataSource = null; DepartmentListView.DataBind(); ScriptManager.RegisterStartupScript(this.department_panel, this.GetType(), "updateScript", "alert('删除成功')", true); } else { DepartmentListView.DataSource = null; DepartmentListView.DataBind(); ScriptManager.RegisterStartupScript(this.department_panel, this.GetType(), "updateScript", "alert('该系不存在')", true); } } catch (Exception ex) { ScriptManager.RegisterStartupScript(this.department_panel, this.GetType(), "updateScript", "alert('系统异常')", true); } }
public async Task AcceptEmote(params string[] emoteIDs) { List <string> SuccessfulEmotes = new List <string>(); string dir = FinalEmoteLocation.Substring(0, FinalEmoteLocation.Length - 1); EmoteRequest er = new EmoteRequest(null, "", false, "", false); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } foreach (string s in emoteIDs) { if (GlobalVars.EmoteRequests.TryGetValue(s, out er)) { SuccessfulEmotes.Add(er.RequestID); if (GlobalVars.RequestMessage.TryGetValue(er.RequestID, out var msg)) { await msg.DeleteAsync(); GlobalVars.RequestMessage.Remove(er.RequestID); } string sql = $"INSERT INTO Emotes (EmoteID, RequestedBy, EmoteTrigger, fExt, RequireTarget, OutputText, Nsfw) VALUES ('{er.RequestID}', {er.RequestedBy.Id}, '{er.Trigger}', '{er.FileExtension}', {(er.RequiresTarget ? 1 : 0)}, '{er.OutputText}', {(er.Nsfw ? 1 : 0)});"; DBControl.UpdateDB(sql); File.Move(RequestLocation + er.FileName, FinalEmoteLocation + er.FileName); GlobalVars.EmoteList.Add(er.RequestID, new ApprovedEmote(er.RequestID, er.FileExtension, er.Trigger, er.RequiresTarget, er.OutputText, er.Nsfw)); GlobalVars.EmoteRequests.Remove(er.RequestID); } } await Context.Channel.SendMessageAsync($"Emote(s) ID(s) accepted: ({string.Join(", ", SuccessfulEmotes)})"); }
word[] words;//对象数组暂存需要背的单词之后会传递给Recite页面 public Recite_StarPage() { this.InitializeComponent(); DBControl db = new DBControl(); words = db.read("frq != 0 order by rand() limit 20", 20); }
protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { String sql = null; if (Convert.ToInt32(usertype.SelectedValue) == 1) { sql = "SELECT * FROM tb_student WHERE xh = '" + username.Text.Trim() + "' and pass ='******'"; if (Convert.ToInt32(DBControl.findOne(sql)) > 0) { Session["student"] = username.Text.Trim(); Response.Redirect("STU.aspx"); } } else if (Convert.ToInt32(usertype.SelectedValue) == 2) { sql = "SELECT * FROM tb_teacher WHERE gh = '" + username.Text.Trim() + "' and pass ='******'"; if (Convert.ToInt32(DBControl.findOne(sql)) > 0) { Session["teacher"] = username.Text.Trim(); Response.Redirect("TEA.aspx"); } } else { sql = "SELECT * FROM tb_adminuser WHERE username = '******' and password ='******'"; if (Convert.ToInt32(DBControl.findOne(sql)) > 0) { Session["admin"] = username.Text.Trim(); Response.Redirect("Default.aspx"); } } Response.Write("<script>alert('用户名或密码错误,请重新输入!');location.href='Login.aspx';</script>"); }
/// <summary> /// Ищет устройство в базе, если есть заполняет переменные класса. Если нет, создаёт добавляет в базу устройство /// </summary> private bool loadOrCreateFromDB() { string query = String.Format(TeraSettings.Default.selectDeviceBySerial, this.SerialNumber); DataSet data_set = new DataSet(); DBControl dc = new DBControl(DBSettings.Default.DBName); MySqlDataAdapter da = new MySqlDataAdapter(query, dc.MyConn); da.Fill(data_set); if (data_set.Tables[0].Rows.Count > 0) { this.deviceDataRow = data_set.Tables[0].Rows[0]; return(true); } else { query = String.Format(TeraSettings.Default.insertDevice, this.SerialNumber); MySqlCommand cmd = new MySqlCommand(query, dc.MyConn); dc.MyConn.Open(); cmd.ExecuteNonQuery(); dc.MyConn.Close(); this.checkSumFromDB = this.checkSumFromDevice; this.isLoadedFromDB = true; return(false); } }
private void FillUsers() { if (!DBControl.Connected) { MessageBox.Show("No Connection!"); return; } userList.Items.Clear(); users = new object[][] { new object[] { 0, "admin", Properties.Settings.Default.AdminPass, 1 }, new object[] { 1, "user", Properties.Settings.Default.UserPass, 0 } }; int len = 2; DataTable t = DBControl.Select("select * from users"); if (t != null && t.Columns.Count == 4) { len = t.Rows.Count; users = new object[len][]; for (int i = 0; i < len; i++) { users[i] = t.Rows[i].ItemArray; } } for (int i = 0; i < len; i++) { userList.Items.Add(users[i][1]); } }
protected void btnCreate_Click(object sender, EventArgs e) { Users users = new Users(); users.username = txUser.Text; users.name = txName.Text; users.email = txEmail.Text; users.status = (switchToggle2.Value == "true") ? "ACTIVE" : "INACTIVE"; users.userType = (userType.SelectedValue == "admin") ? "1" : "2"; MessageResult messageResult = DBControl.insertUser(users); switch (messageResult.ErrorCode) { case ErrorCode.E: SuccessMessage_ins.Visible = false; ErrorMessage_ins.Visible = true; FailureText_ins.Text = messageResult.Message; FailBtn.Visible = true; break; case ErrorCode.S: ErrorMessage_ins.Visible = false; SuccessMessage_ins.Visible = true; SuccessText_ins.Text = messageResult.Message; FailBtn.Visible = false; break; } ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModalInsert();", true); }
private void Vlist_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Return) { string sql = Vlist.Text, name = "expression" + ++counter; DataTableView dtv = FindView(sql); if (dtv != null) { dtv.Exit(); } if (sql.StartsWith("#")) { dtv = new DataTableView(sql, DBControl.Schema(sql.Substring(1))); } else { dtv = new DataTableView(sql, DBControl.Adapter(sql), access); } if (dtv.IsDisposed) { return; } dtv.Disposed += dtv_Disposed; tabFormControl1.AddTab(sql, -1, dtv); } }
protected void teacherdelete_Click(object sender, EventArgs e) { int gh = Int32.Parse((sender as Button).CommandArgument.ToString()); string sql = "delete from tb_teacher where gh ='" + gh + "'"; try { if (DBControl.delete(sql) > 0) { TeacherListView.DataSource = null; TeacherListView.DataBind(); ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('删除成功')", true); } else { TeacherListView.DataSource = null; TeacherListView.DataBind(); ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('该教师不存在')", true); } } catch (Exception ex) { ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('系统异常')", true); } }
/// <summary> /// 刷新加载数据 /// </summary> private void Refresh() { try { //获取当前时间 SelectTime = Convert.ToDateTime(this.dateTimePicker_Select.Value.ToString("yyyy-MM-dd ") + cboTime.Text); this.txtbedno.Text = TemperatureMethod.GetBedNo(pid_ids, pageindex, Convert.ToDateTime(startDate), Convert.ToDateTime(endDate)); this.txtDiagnose.Text = TemperatureMethod.GetDiagnose(pid_ids, pageindex, Convert.ToDateTime(startDate), Convert.ToDateTime(endDate)); this.tw.IsHowTime = currentHour;//时间点 this.tw.CurDateTime = SelectTime.Date; GetPageIndex(); ClearInfo(); if (CompareTime(SelectTime, Convert.ToDateTime(this.inTime))) { string dateTime = SelectTime.ToString("yyyy-MM-dd"); if (!DBControl.SelectGreaterZero(dateTime, this.pid_ids)) { lists = DBControl.GetTemper(dateTime, this.pid_ids); LoadAll(lists); lists.Clear(); } } //inRooms(); } catch (System.Exception ex) { } }
private async Task Client_JoinedGuild(SocketGuild arg) { Console.WriteLine($"{DateTime.Now} -> Joined guild: {arg.Id}"); GuildOption go = new GuildOption(); Options o = new Options(); go.GuildID = arg.Id; go.GuildName = arg.Name; go.OwnerID = arg.Owner.Id; go.Prefix = "]"; o.LogChannelID = 0; o.LogEmbeds = false; o.LogAttachments = false; go.Options = o; if (!GlobalVars.GuildOptions.Any(x => x.GuildID == go.GuildID)) { GlobalVars.GuildOptions.Add(go); } DBControl.UpdateDB($"INSERT INTO Guilds (GuildID,GuildName,OwnerID,Prefix,LogChannelID,LogEmbeds,LogAttachments) VALUES ({go.GuildID.ToString()}, '{go.GuildName.Replace(@"'","")}',{go.OwnerID.ToString()},'{go.Prefix}',{go.Options.LogChannelID.ToString()}, {(go.Options.LogEmbeds ? 1:0)}, {(go.Options.LogAttachments ? 1:0)});"); await UpdateActivity(); await Task.Delay(100); }
private void BtnSubmit_Click(object sender, EventArgs e) { bool submit = true; //save current question answer test.Questions[questionIndex].StudentAnswer = rbnAnswerA.Checked ? 'a' : rbnAnswerB.Checked ? 'b' : rbnAnswerC.Checked ? 'c' : default(char); foreach (Question question in test.Questions) { if (question.StudentAnswer == default(char)) { DialogResult res = MessageBox.Show( "You have not completed all the answers \nAre you sure you want to submit?", "Incomplete Test", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (res == DialogResult.No || res == DialogResult.Cancel) { submit = false; break; } } } if (submit) { try { int mark = 0, percentage; foreach (Question question in test.Questions) { if (question.CorrectAnswer == question.StudentAnswer) { mark++; } } percentage = (int)((double)mark / (double)test.Questions.Count * 100.0); test.Mark = mark; test.Percentage = percentage; test.AttemptsMade++; bool subit = new DBControl().SubmitTest(currentUser, test); if (subit) { MessageBox.Show("Test saved successfully", "Success"); } new S_ViewMemoForm(currentUser, test).Show(); this.Hide(); } catch (Exception ex) { StackLog.GetInstance().Log(ex.Message + "\n" + ex.StackTrace); MessageBox.Show("Failed to submit test", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private async void ShowVideo_Loaded(object sender, RoutedEventArgs e) { DBControl dBControl = new DBControl(); videos = dBControl.readvideo(); StorageFolder folder = await(Windows.Storage.KnownFolders.VideosLibrary).GetFolderAsync("uwpVideo"); try { var file = await folder.GetFileAsync("1.mp4"); if (file != null) { Windows.Storage.Streams.IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read); this.meVoideo.SetSource(stream, ""); this.meVoideo.Play(); } } catch (Exception ex) { return; } }
protected void outcoursesub_Click(object sender, EventArgs e) { int kcdh = Int32.Parse((sender as Button).CommandArgument.ToString()); string sql = "delete from tb_study where xh='" + Session["student"] + "' and kcdh ='" + kcdh + "' and cj is null "; try { if (DBControl.delete(sql) > 0) { StudyListView.DataSource = null; StudyListView.DataBind(); ScriptManager.RegisterStartupScript(this.outcourse_panel, this.GetType(), "updateScript", "alert('退选成功')", true); } else { StudyListView.DataSource = null; StudyListView.DataBind(); ScriptManager.RegisterStartupScript(this.outcourse_panel, this.GetType(), "updateScript", "alert('该课程已有成绩,不能退选')", true); } } catch (Exception ex) { ScriptManager.RegisterStartupScript(this.outcourse_panel, this.GetType(), "updateScript", "alert('系统异常')", true); } }
protected void adminuseraddsub_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(adminuseraddname.Text.Trim())) { ScriptManager.RegisterStartupScript(this.adminuser_panel, this.GetType(), "updateScript", "alert('用户名不能为空!')", true); } if (string.IsNullOrEmpty(adminuseraddpass.Text.Trim())) { ScriptManager.RegisterStartupScript(this.adminuser_panel, this.GetType(), "updateScript", "alert('密码不能为空!')", true); } string check = "SELECT * FROM tb_adminuser WHERE username = '******'"; if (Convert.ToInt32(DBControl.findOne(check)) > 0) { ScriptManager.RegisterStartupScript(this.adminuser_panel, this.GetType(), "updateScript", "alert('该用户名已经被使用!')", true); return; } string sql = "insert into tb_adminuser (username,password) values('" + adminuseraddname.Text.Trim() + "','" + adminuseraddpass.Text.Trim() + "')"; try { DBControl.Insert(sql); ScriptManager.RegisterStartupScript(this.adminuser_panel, this.GetType(), "updateScript", "alert('插入成功')", true); } catch (Exception ex) { ScriptManager.RegisterStartupScript(this.adminuser_panel, this.GetType(), "updateScript", "alert('插入失败')", true); } }
protected void teachereditsub_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(teachereditage.Text.Trim())) { ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('工龄不能为空!')", true); } if (string.IsNullOrEmpty(teachereditsalary.Text.Trim())) { ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('基本工资不能为空!')", true); } if (Convert.ToInt32(teachereditdept.SelectedValue) == 0) { ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('请选择院系!')", true); } int gh = 0; string xb = null; string xm = null; string zc = null; DateTime csrq = System.DateTime.Now; int gl = 0; int jbgz = 0; int dno = 0; try { gh = Convert.ToInt32(teacheredituser.Text.Trim()); xm = teachereditname.Text.Trim(); xb = "男"; if (teachereditsex2.Checked) { xb = "女"; } zc = teacheredittitles.Text.Trim(); gl = Convert.ToInt32(teachereditage.Text.Trim()); csrq = Convert.ToDateTime(teachereditbirth.Text.Trim()); jbgz = Convert.ToInt32(teachereditsalary.Text.Trim()); dno = Convert.ToInt32(teachereditdept.SelectedValue); } catch (Exception) { ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('请在工龄、基本工资中输入数字')", true); } string sql = "update tb_teacher set xm='" + xm + "',xb='" + xb + "',zc='" + zc + "',gl='" + gl + "',csrq='" + csrq + "',jbgz='" + jbgz + "',dno='" + dno + "' where gh ='" + gh + "'"; try { DBControl.update(sql); ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('编辑成功')", true); TeacherListView.DataSource = null; TeacherListView.DataBind(); manageteacher_panel.Visible = true; editteacher_panel.Visible = false; } catch (Exception ex) { ScriptManager.RegisterStartupScript(this.teacher_panel, this.GetType(), "updateScript", "alert('编辑失败')", true); } }
protected void courseaddsub_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(courseaddnum.Text.Trim())) { ScriptManager.RegisterStartupScript(this.course_panel, this.GetType(), "updateScript", "alert('课程代号不能为空!')", true); } if (string.IsNullOrEmpty(courseaddname.Text.Trim())) { ScriptManager.RegisterStartupScript(this.course_panel, this.GetType(), "updateScript", "alert('课程名不能为空!')", true); } if (string.IsNullOrEmpty(courseaddcount.Text.Trim())) { ScriptManager.RegisterStartupScript(this.course_panel, this.GetType(), "updateScript", "alert('课时数不能为空!')", true); } if (Convert.ToInt32(courseaddteacher.SelectedValue) == 0) { ScriptManager.RegisterStartupScript(this.course_panel, this.GetType(), "updateScript", "alert('请选择授课老师!')", true); } int kcdh = 0; string kcm = null; int kss = 0; int bxk = 0; int xf = 0; int gh = 0; try { kcdh = Convert.ToInt32(courseaddnum.Text.Trim()); kcm = courseaddname.Text.Trim(); kss = Convert.ToInt32(courseaddcount.Text.Trim()); bxk = Convert.ToInt32(courseaddisneed.SelectedValue); xf = Convert.ToInt32(courseaddcredit.SelectedValue); gh = Convert.ToInt32(courseaddteacher.SelectedValue); } catch (Exception) { ScriptManager.RegisterStartupScript(this.course_panel, this.GetType(), "updateScript", "alert('请在学号和年龄中输入数字!')", true); } string check = "SELECT * FROM tb_course WHERE kcdh = '" + courseaddnum.Text.Trim() + "'"; if (Convert.ToInt32(DBControl.findOne(check)) > 0) { ScriptManager.RegisterStartupScript(this.course_panel, this.GetType(), "updateScript", "alert('该课程代号已经被使用!')", true); return; } string sql = "insert into tb_course (kcdh,kcm,kss,bxk,xf,gh) values('" + kcdh + "','" + kcm + "','" + kss + "','" + bxk + "','" + xf + "','" + gh + "')"; try { DBControl.Insert(sql); ScriptManager.RegisterStartupScript(this.course_panel, this.GetType(), "updateScript", "alert('插入成功')", true); } catch (Exception ex) { ScriptManager.RegisterStartupScript(this.course_panel, this.GetType(), "updateScript", "alert('插入失败')", true); } }
protected void studentaddsub_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(studentadduser.Text.Trim())) { ScriptManager.RegisterStartupScript(this.student_panel, this.GetType(), "updateScript", "alert('学号不能为空!')", true); } if (string.IsNullOrEmpty(studentaddname.Text.Trim())) { ScriptManager.RegisterStartupScript(this.student_panel, this.GetType(), "updateScript", "alert('姓名不能为空!')", true); } if (string.IsNullOrEmpty(studentaddage.Text.Trim())) { ScriptManager.RegisterStartupScript(this.student_panel, this.GetType(), "updateScript", "alert('年龄不能为空!')", true); } if (Convert.ToInt32(studentadddept.SelectedValue) == 0) { ScriptManager.RegisterStartupScript(this.student_panel, this.GetType(), "updateScript", "alert('请选择院系!')", true); } int xh = 0; int nl = 0; string xb = null; string xm = null; int dno = 0; try { xh = Convert.ToInt32(studentadduser.Text.Trim()); xm = studentaddname.Text.Trim(); xb = "男"; if (studentaddsex2.Checked) { xb = "女"; } nl = Convert.ToInt32(studentaddage.Text.Trim()); dno = Convert.ToInt32(studentadddept.SelectedValue); } catch (Exception) { ScriptManager.RegisterStartupScript(this.student_panel, this.GetType(), "updateScript", "alert('请在学号和年龄中输入数字!')", true); } string check = "SELECT * FROM tb_student WHERE xh = '" + xh + "'"; if (Convert.ToInt32(DBControl.findOne(check)) > 0) { ScriptManager.RegisterStartupScript(this.student_panel, this.GetType(), "updateScript", "alert('该学号已经被使用!')", true); } string sql = "insert into tb_student (xh,xm,xb,nl,dno) values('" + xh + "','" + xm + "','" + xb + "','" + nl + "','" + dno + "')"; try { DBControl.Insert(sql); ScriptManager.RegisterStartupScript(this.student_panel, this.GetType(), "updateScript", "alert('插入成功')", true); } catch (Exception ex) { ScriptManager.RegisterStartupScript(this.student_panel, this.GetType(), "updateScript", "alert('插入失败')", true); } }
private void tsbtnDeleteTab_Click(object sender, System.EventArgs e) { if (tctrlFrames.SelectedTab != null) { tctrlFrames.Controls.Remove(tctrlFrames.SelectedTab); Control = null; } }
private void BtnLogin_Click(object sender, EventArgs e) { Refresh(); bool isUsername = false; bool isPassword = false; if (tbxUsername.Text == "") { lblErrMsgUsername.Visible = true; } else { isUsername = true; } if (tbxPassword.Text == "") { lblErrMsgPassword.Visible = true; } else { isPassword = true; } if (isUsername && isPassword) { try { UserSession currentUser = new DBControl().LoginUser(tbxUsername.Text, tbxPassword.Text); if (currentUser == null) { MessageBox.Show("Username or/and password is incorrect.", "Invalid Credentials"); } else { switch (currentUser.UserType) { case 's': new S_StudentHome(currentUser).Show(); this.Hide(); break; case 'l': new L_ClassListForm(currentUser).Show(); this.Hide(); break; case 'r': new R_RegisterForm(currentUser).Show(); this.Hide(); break; } } } catch (Exception ex) { StackLog.GetInstance().Log(ex.StackTrace); MessageBox.Show(ex.Message, "Error"); } } }
private void tctrlFrames_Selecting(object sender, TabControlCancelEventArgs e) { if (sender is TabControl ctrl) { if (ctrl.SelectedIndex > -1) { Control = ctrl.TabPages[ctrl.SelectedIndex].Tag as DBControl; } } }
public async Task AddOwner(ulong id) { string sql = $"INSERT INTO BotOwners (OwnerID) VALUES ({id})"; var l = Constants._BOTOWNERS_.ToList(); l.Add(id); Constants._BOTOWNERS_ = l.ToArray(); DBControl.UpdateDB(sql); var m = await Context.Channel.SendMessageAsync($"User {CustomUserTypereader.GetUserFromID(id, Context.Client.Guilds).Result.Username} added as one of my Owners."); GlobalVars.AddRandomTracker(m, 5); }
/// <summary> /// 保存体温信息 /// </summary> /// <returns></returns> public bool Excute() { list.Add(this.tw3am.GetTempers(this.pid, this.bed_no, SelectTime.ToString("yyyy-MM-dd 02:00"), this.pid_ids)); list.Add(this.tw7am.GetTempers(this.pid, this.bed_no, SelectTime.ToString("yyyy-MM-dd 06:00"), this.pid_ids)); list.Add(this.tw11am.GetTempers(this.pid, this.bed_no, SelectTime.ToString("yyyy-MM-dd 10:00"), this.pid_ids)); list.Add(this.tw3pm.GetTempers(this.pid, this.bed_no, SelectTime.ToString("yyyy-MM-dd 14:00"), this.pid_ids)); list.Add(this.tw7pm.GetTempers(this.pid, this.bed_no, SelectTime.ToString("yyyy-MM-dd 18:00"), this.pid_ids)); list.Add(this.tw11pm.GetTempers(this.pid, this.bed_no, SelectTime.ToString("yyyy-MM-dd 22:00"), this.pid_ids)); return(DBControl.InsertTempers(list)); }
public async Task SetPrefix(string newPrefix) { if (newPrefix != null && newPrefix != "") { GlobalVars.GuildOptions.Single(x => x.GuildID == Context.Guild.Id).Prefix = newPrefix; DBControl.UpdateDB($"UPDATE SBGuilds SET Prefix = '{newPrefix}' WHERE GuildID = {Context.Guild.Id};"); await Context.Channel.SendMessageAsync($"{Context.User.Mention}, I have updated your server's prefix to {newPrefix}"); } }
public async Task RequestShip(string shipName, int amount, string coord1, string coord2) { //int amount = -1; //int.TryParse(amt, out amount); //if (amount == -1) //{ // await Context.Channel.SendMessageAsync($"Can not parse the value you entered for `Amount`. Please try again.\nYour input: {amt}"); // return; //} List <string> idList = new List <string>(); string datestamp = DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year; SqlConnectionStringBuilder sBuilder = new SqlConnectionStringBuilder(); sBuilder.InitialCatalog = GlobalVars.dbSettings.db; sBuilder.UserID = GlobalVars.dbSettings.username; sBuilder.Password = GlobalVars.dbSettings.password; sBuilder.DataSource = GlobalVars.dbSettings.host + @"\" + GlobalVars.dbSettings.instance + "," + GlobalVars.dbSettings.port; SqlConnection conn = new SqlConnection { ConnectionString = sBuilder.ConnectionString }; using (conn) { conn.Open(); SqlCommand cmd = new SqlCommand($"SELECT ReqID, ShipName, Amount, coord1, coord2 FROM ShipRequests WHERE GuildID = {Context.Guild.Id} AND Completed = 0;", conn); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { if (dr.GetValue(3).ToString() == coord1 && dr.GetValue(4).ToString() == coord2) { var m = await Context.Channel.SendMessageAsync($"{Context.User.Mention}; this location already has a pending ship request."); GlobalVars.AddRandomTracker(m); return; } idList.Add(dr.GetValue(0).ToString()); } dr.Close(); conn.Close(); conn.Dispose(); } string ReqID = GenerateID(idList); string sql = $"INSERT INTO ShipRequests VALUES ('{ReqID}', {Context.Guild.Id}, {Context.User.Id}, '{shipName}', '{coord1}', '{coord2}', {amount}, '{datestamp}', 0);"; DBControl.UpdateDB(sql); await Context.Channel.SendMessageAsync($"Ship request ID {ReqID} added."); }
public async Task RemoveReservation(int coord1, int coord2) { SqlConnectionStringBuilder sBuilder = new SqlConnectionStringBuilder(); sBuilder.InitialCatalog = GlobalVars.dbSettings.db; sBuilder.UserID = GlobalVars.dbSettings.username; sBuilder.Password = GlobalVars.dbSettings.password; sBuilder.DataSource = GlobalVars.dbSettings.host + @"\" + GlobalVars.dbSettings.instance + "," + GlobalVars.dbSettings.port; SqlConnection conn = new SqlConnection { ConnectionString = sBuilder.ConnectionString }; bool success = false; using (conn) { conn.Open(); #region Get Reservation SqlCommand cmd = new SqlCommand($"SELECT UserID FROM Reservations WHERE GuildID = {Context.Guild.Id} AND Coord1 = '{coord1}' AND Coord2 = '{coord2}';", conn); SqlDataReader dr = cmd.ExecuteReader(); if (dr.HasRows) { ulong uID = 0; while (dr.Read()) { uID = Convert.ToUInt64(dr.GetValue(0)); } if (uID == Context.User.Id) { DBControl.UpdateDB($"DELETE FROM Reservations WHERE GuildID = {Context.Guild.Id} AND UserID = {Context.User.Id} AND Coord1 = '{coord1}' AND Coord2 = '{coord2}';"); success = true; } else { success = false; } } #endregion conn.Close(); conn.Dispose(); } if (success) { await Context.Channel.SendMessageAsync($"{Context.User.Mention}, your station reservation at /goto {coord1} {coord2} has been removed."); } else { await Context.Channel.SendMessageAsync($"{Context.User.Mention}, you don't have a reservation at this location.\n*Keep in mind, you can't remove other users' reservations.*"); } }
private void Save(object sender, EventArgs e) { if (!DBControl.Connect()) { MessageBox.Show(DBControl.LastError, "Не подключено!"); return; } RewriteProviders(); settings.Save(); DialogResult = DialogResult.OK; }
public SavedSearchManager(string connectionString, DataProvider provider) { _connectionString = connectionString; _provider = provider; DBControl control = new DBControl(connectionString, provider); if (!control.CheckDataAccess()) { control.CreateTables(); } }
public async Task SetMaxReserves(ushort amount) { GlobalVars.GuildOptions.Single(go => go.GuildID == Context.Guild.Id).MaxReserves = amount; var sql = $"UPDATE SBGuilds SET MaxReserves = {amount} WHERE GuildID = {Context.Guild.Id};"; DBControl.UpdateDB(sql); var m = await Context.Channel.SendMessageAsync($"Updated max location reservations to {amount}."); GlobalVars.AddRandomTracker(m); }
private async Task Client_LeftGuild(SocketGuild arg) { Console.WriteLine($"{DateTime.Now} -> Left guild: {arg.Id}"); GlobalVars.GuildOptions.Remove(GlobalVars.GuildOptions.Single(x => x.GuildID == arg.Id)); DBControl.UpdateDB($"DELETE FROM Guilds WHERE GuildID = {arg.Id};"); await UpdateActivity(); await Task.Delay(100); }