private void button2_Click(object sender, EventArgs e) { if (i == 0) { ClanWork db = new ClanWork(); db.NewMembTabs.Load(); NewMembTab nm = new NewMembTab(); try { nm.FirstName = textBox1.Text; nm.LastName = textBox2.Text; nm.Log = textBox3.Text; nm.Pass = textBox4.Text; nm.WantedPosition = comboBox1.SelectedItem.ToString(); db.NewMembTabs.Add(nm); db.SaveChanges(); label6.Visible = true; i++; } catch (Exception ex) { label7.Visible = true; } } }
private void button1_Click(object sender, EventArgs e) { string connectionString = @"Data Source=.\MSSQLSERVER,1433;Initial Catalog=ClanWork;Integrated Security=True"; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand cmd = new SqlCommand("UPDATE Members SET Position = @SUM WHERE ID=@ID", connection); cmd.Parameters.AddWithValue("@SUM", comboBox2.Text); cmd.Parameters.AddWithValue("@ID", lastID); cmd.ExecuteNonQuery(); connection.Close(); } using (ClanWork db = new ClanWork()) { comboBox1.DataSource = db.Members.ToList(); } comboBox1.Focus(); using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand c = new SqlCommand("Insert into History VALUES(@1,@2)", connection); c.Parameters.AddWithValue("@1", ActionForm.Pos + " " + LoginForm.Namez + " changed position of " + comboBox1.SelectedIndex + " from " + textBox1.Text + " to " + comboBox2.Text); c.Parameters.AddWithValue("@2", DateTime.Now); c.ExecuteNonQuery(); connection.Close(); } }
public NewMembForm() { InitializeComponent(); BackgroundImage = Image.FromFile("E:\\war3\\Projects\\ClanWork\\Mafia.png"); BackgroundImageLayout = ImageLayout.Stretch; ClanWork db = new ClanWork(); db.NewMembTabs.Load(); dataGridView1.DataSource = db.NewMembTabs.Local.ToBindingList(); }
private void ActionForm_Load(object sender, EventArgs e) { using (ClanWork db = new ClanWork()) { var pos = from p in db.Members where p.id == LoginForm.ID select p; foreach (Member p in pos) { Pos = p.Position; } } }
public ChangePosForm() { InitializeComponent(); BackgroundImage = Image.FromFile("E:\\war3\\Projects\\ClanWork\\Mafia.png"); BackgroundImageLayout = ImageLayout.Stretch; using (ClanWork db = new ClanWork()) { comboBox1.DataSource = db.Members.ToList(); } comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged; }
private void BankForm_Load(object sender, EventArgs e) { using (ClanWork db = new ClanWork()) { var money = from m in db.Banks where m.id == 1 select m; foreach (Bank m in money) { textBox2.Text = m.Money.ToString(); } } }
private void button2_Click(object sender, EventArgs e) { if (ActionForm.Pos == "King" | ActionForm.Pos == "Queen" | ActionForm.Pos == "Rook") { if (dataGridView1.SelectedRows.Count > 0) { int index = dataGridView1.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id); if (converted == false) { return; } ClanWork db = new ClanWork(); Member memb = db.Members.Find(id); db.Members.Remove(memb); db.SaveChanges(); dataGridView1.Update(); dataGridView1.RefreshEdit(); string connectionString = @"Data Source=.\MSSQLSERVER,1433;Initial Catalog=ClanWork;Integrated Security=True"; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand c = new SqlCommand("Insert into History VALUES(@1,@2)", connection); c.Parameters.AddWithValue("@1", ActionForm.Pos + " " + LoginForm.Namez + " " + "kicked " + memb.Position + " " + memb.FirstName); c.Parameters.AddWithValue("@2", DateTime.Now); c.ExecuteNonQuery(); connection.Close(); } } } else { MessageBox.Show("You don't have rights to do given action!"); } }
private void button1_Click(object sender, EventArgs e) { if (ActionForm.Pos == "Pawn") { MessageBox.Show("You don't have rights to do given action!"); } else { SqlConnection con = new SqlConnection("Data Source=DESKTOP-J8I3ABH,1433;Initial Catalog=ClanWork;Integrated Security=True"); con.Open(); SqlCommand cmd = new SqlCommand("SELECT TOP 1 * FROM Members ORDER BY ID DESC", con); int i = cmd.ExecuteNonQuery(); con.Close(); if (dataGridView1.SelectedRows.Count > 0) { int index = dataGridView1.SelectedRows[0].Index; int id = 0; bool converted = Int32.TryParse(dataGridView1[0, index].Value.ToString(), out id); if (converted == false) { return; } ClanWork db = new ClanWork(); NewMembTab nm = db.NewMembTabs.Find(id); Login lg = new Login { Log = nm.Log, Pass = nm.Pass, Memberid = i + 1 }; Member mb = new Member { FirstName = nm.FirstName, LastName = nm.LastName, Position = nm.WantedPosition, Job = "Not yet", id = i + 1 }; db.Logins.Add(lg); db.Members.Add(mb); db.NewMembTabs.Remove(nm); try { db.SaveChanges(); dataGridView1.Update(); dataGridView1.RefreshEdit(); } catch (DbEntityValidationException ex) { foreach (DbEntityValidationResult validationError in ex.EntityValidationErrors) { MessageBox.Show("Object: " + validationError.Entry.Entity.ToString()); foreach (DbValidationError err in validationError.ValidationErrors) { MessageBox.Show(err.ErrorMessage + ""); } } } string connectionString = @"Data Source=.\MSSQLSERVER,1433;Initial Catalog=ClanWork;Integrated Security=True"; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand c = new SqlCommand("Insert into History VALUES(@1,@2)", connection); c.Parameters.AddWithValue("@1", ActionForm.Pos + " " + LoginForm.Namez + " " + "invited " + mb.Position + " " + mb.FirstName); c.Parameters.AddWithValue("@2", DateTime.Now); c.ExecuteNonQuery(); connection.Close(); } } } }