private void deleteBtn_Click(object sender, EventArgs e) { int row = dataGridView1.CurrentCell.RowIndex; int id = Convert.ToInt32(dataGridView1[0, row].Value); try { var user = DirectoryDB.UsersInfoSet.Find(id); if (user.Access_level == "Owner") { MessageBox.Show("You can`t delete yourself", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { DirectoryDB.UsersInfoSet.Remove(user); DirectoryDB.SaveChanges(); MessageBox.Show("Done", "Action", MessageBoxButtons.OK, MessageBoxIcon.Information); DirectoryDB.UsersInfoSet.Load(); dataGridView1.DataSource = DirectoryDB.UsersInfoSet.Local.ToList(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void addBtn_Click(object sender, EventArgs e) { try { switch (activetable) { case "Subscribers": { SubscribersInfo subscriber = new SubscribersInfo { PassportData = propTextBox1.Text, FullName = propTextBox2.Text, Address = propTextBox3.Text }; DirectoryDB.SubscribersInfoSet.Add(subscriber); DirectoryDB.SaveChanges(); break; } case "Operators": { OperatorsInfo operators = new OperatorsInfo { Name = propTextBox1.Text, Code = propTextBox2.Text, AmountOfUsers = Convert.ToInt32(propTextBox3.Text) }; DirectoryDB.OperatorsInfoSet.Add(operators); DirectoryDB.SaveChanges(); break; } case "Connections": { int id = Convert.ToInt32(propComboBox5.Text); var sub = DirectoryDB.SubscribersInfoSet.Where(subscriber => subscriber.Id == id).First(); var ops = DirectoryDB.OperatorsInfoSet.Where(oper => oper.Id == id).First(); ConnectionsInfo connection = new ConnectionsInfo { PhoneNumber = propTextBox1.Text, Arrear = Convert.ToDecimal(propTextBox2.Text), Tariff = propTextBox3.Text, InstallationDate = Convert.ToDateTime(propTextBox4.Text), SubscribersInfo = sub, OperatorsInfo = ops }; DirectoryDB.ConnectionsInfoSet.Add(connection); DirectoryDB.SaveChanges(); break; } } MessageBox.Show("Done", "Action", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void addBtn_Click(object sender, EventArgs e) { try { switch (activetable) { case "Subscribers": { var sub = DirectoryDB.SubscribersInfoSet.Find(currentId); sub.PassportData = propTextBox1.Text; sub.FullName = propTextBox2.Text; sub.Address = propTextBox3.Text; DirectoryDB.Entry(sub).State = EntityState.Modified; break; } case "Operators": { var ops = DirectoryDB.OperatorsInfoSet.Find(currentId); ops.Name = propTextBox1.Text; ops.Code = propTextBox2.Text; ops.AmountOfUsers = Convert.ToInt32(propTextBox3.Text); DirectoryDB.Entry(ops).State = EntityState.Modified; break; } case "Connections": { var con = DirectoryDB.ConnectionsInfoSet.Find(currentId); con.PhoneNumber = propTextBox1.Text; con.Arrear = Convert.ToInt32(propTextBox2.Text); con.Tariff = propTextBox3.Text; con.InstallationDate = Convert.ToDateTime(propTextBox4.Text); DirectoryDB.Entry(con).State = EntityState.Modified; break; } } DirectoryDB.SaveChanges(); MessageBox.Show("Done", "Action", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//Регистрация private void signUpBtn_Click(object sender, EventArgs e) { var count = (from registered in DirectoryDB.UsersInfoSet where registered.Login == loginTextBox.Text select registered).Count(); if (count == 0) { UsersInfo user = new UsersInfo { Login = loginTextBox.Text, Password = passwordTextBox.Text, Access_level = "User" }; DirectoryDB.UsersInfoSet.Add(user); DirectoryDB.SaveChanges(); MessageBox.Show("You have successfully registered", "Welcome!", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearBoxes(); } else { MessageBox.Show("This user is already registered.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }