コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                AddressBookDatabaseEntities db = new AddressBookDatabaseEntities();

                User user = db.Users.SingleOrDefault(us => us.UserId.Equals(this.id));
                user.Name       = textBox1.Text;
                user.Address    = textBox2.Text;
                user.Gender     = comboBox1.SelectedItem.ToString();
                user.Email      = textBox3.Text;
                user.Phone      = textBox4.Text;
                user.Birthdate  = dateTimePicker1.Value;
                user.NationalId = textBox5.Text;
                user.Username   = textBox6.Text;
                user.Password   = textBox7.Text;

                db.SaveChanges();

                MessageBox.Show("Updated");
                showData(user.UserId);
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to update.");
            }
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                AddressBookDatabaseEntities db = new AddressBookDatabaseEntities();

                Contact c = db.Contacts.SingleOrDefault(us => us.Contact_Id.Equals(this.id));
                c.Contact_Name       = textBox1.Text;
                c.Contact_Address    = textBox2.Text;
                c.Contact_Gender     = comboBox1.SelectedItem.ToString();
                c.Contact_Email      = textBox3.Text;
                c.Contact_Phone      = textBox4.Text;
                c.Contact_Birthdate  = dateTimePicker1.Value;
                c.Contact_NationalId = textBox5.Text;
                c.Contact_Category   = comboBox2.SelectedItem.ToString();
                db.SaveChanges();

                MessageBox.Show("Updated");
                f7.LoadDataFromDatabase();
                this.Dispose();
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to update.");
            }
        }
コード例 #3
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (contactId != 0)
            {
                try
                {
                    AddressBookDatabaseEntities db = new AddressBookDatabaseEntities();

                    Contact c = db.Contacts.SingleOrDefault(p => p.Contact_Id.Equals(this.contactId));

                    db.Contacts.Remove(c);
                    db.SaveChanges();

                    MessageBox.Show("Successfully Deleted.");

                    LoadDataFromDatabase();
                }
                catch (Exception)
                {
                    MessageBox.Show("Failed to Delete.");
                }
            }
            else
            {
                MessageBox.Show("Select Any Row First.");
            }
        }
コード例 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            AddressBookDatabaseEntities db = new AddressBookDatabaseEntities();

            try
            {
                User u =
                    db.Users.SingleOrDefault(
                        user => user.Username == textBox1.Text && user.Password == textBox2.Text);
                if (u != null)
                {
                    this.Hide();
                    Form3 f3 = new Form3(u);
                    f3.Show();
                }
                else
                {
                    MessageBox.Show("Invalid Username or Password.");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Invalid Username or Password.");
            }
        }
コード例 #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                AddressBookDatabaseEntities db = new AddressBookDatabaseEntities();

                User u = new User();
                u.Name       = textBox1.Text;
                u.Address    = textBox2.Text;
                u.Gender     = comboBox1.SelectedItem.ToString();
                u.Email      = textBox3.Text;
                u.Phone      = textBox4.Text;
                u.Birthdate  = dateTimePicker1.Value;
                u.NationalId = textBox5.Text;
                u.Username   = textBox6.Text;
                u.Password   = textBox7.Text;

                db.Users.Add(u);
                db.SaveChanges();

                MessageBox.Show("Registration Done.Now you can login!");

                this.Dispose();
                f1.Show();
            }
            catch (Exception)
            {
                MessageBox.Show("Somethings Wrong. Please try again.");
            }
        }
コード例 #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                AddressBookDatabaseEntities db = new AddressBookDatabaseEntities();

                Contact u = new Contact();
                u.Contact_Name       = textBox1.Text;
                u.Contact_Address    = textBox2.Text;
                u.Contact_Gender     = comboBox1.SelectedItem.ToString();
                u.Contact_Email      = textBox3.Text;
                u.Contact_Phone      = textBox4.Text;
                u.Contact_Birthdate  = dateTimePicker1.Value;
                u.Contact_NationalId = textBox5.Text;
                u.Contact_Category   = comboBox2.SelectedItem.ToString();
                u.Contact_UserId     = this.id;
                db.Contacts.Add(u);
                db.SaveChanges();

                MessageBox.Show("Saved.");

                this.Dispose();
                f1.LoadDataFromDatabase();
                f1.Show();
            }
            catch (Exception)
            {
                MessageBox.Show("Somethings Wrong. Please try again.");
            }
        }
コード例 #7
0
        private void Form6_Load(object sender, EventArgs e)
        {
            AddressBookDatabaseEntities db = new AddressBookDatabaseEntities();

            comboBox2.DataSource = db.Categories.Select(c => c.CategoryName).ToList();

            showData(this.id);
        }
コード例 #8
0
        private void LoadDataFromDatabase()
        {
            AddressBookDatabaseEntities db = new AddressBookDatabaseEntities();

            dataGridView1.DataSource = db.Categories.ToList();
            if (dataGridView1.CurrentRow != null)
            {
                dataGridView1.CurrentRow.Selected = false;
            }
        }
コード例 #9
0
        private void button4_Click(object sender, EventArgs e)
        {
            AddressBookDatabaseEntities db = new AddressBookDatabaseEntities();

            dataGridView1.DataSource = db.Contacts.Where(c => c.Contact_UserId == this.id && (c.Contact_Name.Contains(textBox1.Text) || c.Contact_Email.Contains(textBox1.Text) || c.Contact_Phone.Contains(textBox1.Text))).ToList();
            if (dataGridView1.CurrentRow != null)
            {
                dataGridView1.CurrentRow.Selected = false;
            }
            dataGridView1.Columns[10].Visible = false;
        }
コード例 #10
0
        public void LoadDataFromDatabase()
        {
            AddressBookDatabaseEntities db = new AddressBookDatabaseEntities();

            dataGridView1.DataSource = db.Contacts.Where(c => c.Contact_UserId.Equals(this.id)).ToList();
            if (dataGridView1.CurrentRow != null)
            {
                dataGridView1.CurrentRow.Selected = false;
            }
            dataGridView1.Columns[10].Visible = false;
        }
コード例 #11
0
        private void showData(int id)
        {
            AddressBookDatabaseEntities db = new AddressBookDatabaseEntities();
            Contact u = db.Contacts.SingleOrDefault(us => us.Contact_Id.Equals(this.id));

            textBox1.Text           = u.Contact_Name;
            textBox2.Text           = u.Contact_Address;
            comboBox1.SelectedIndex = u.Contact_Gender == "Male" ? 0 : 1;
            textBox3.Text           = u.Contact_Email;
            textBox4.Text           = u.Contact_Phone;
            dateTimePicker1.Value   = u.Contact_Birthdate;
            textBox5.Text           = u.Contact_NationalId;
            comboBox2.SelectedIndex = comboBox2.Items.IndexOf(u.Contact_Category);
        }
コード例 #12
0
        private void showData(int id)
        {
            AddressBookDatabaseEntities db = new AddressBookDatabaseEntities();
            User u = db.Users.SingleOrDefault(us => us.UserId.Equals(this.id));

            textBox1.Text           = u.Name;
            textBox2.Text           = u.Address;
            comboBox1.SelectedIndex = u.Gender == "Male" ? 0 : 1;
            textBox3.Text           = u.Email;
            textBox4.Text           = u.Phone;
            dateTimePicker1.Value   = u.Birthdate;
            textBox5.Text           = u.NationalId;
            textBox6.Text           = u.Username;
            textBox7.Text           = u.Password;
        }
コード例 #13
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                AddressBookDatabaseEntities db = new AddressBookDatabaseEntities();

                Category c = db.Categories.SingleOrDefault(p => p.CategoryId.Equals(this.id));
                c.CategoryName = textBox2.Text;
                db.SaveChanges();

                MessageBox.Show("Successfully Updated.");
                ClearInputField();
                LoadDataFromDatabase();
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to Update.");
            }
        }
コード例 #14
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                AddressBookDatabaseEntities db = new AddressBookDatabaseEntities();

                Category c = new Category();
                c.CategoryName = textBox2.Text;

                db.Categories.Add(c);
                db.SaveChanges();

                MessageBox.Show("Category Saved!");
                ClearInputField();
                LoadDataFromDatabase();
            }
            catch (Exception)
            {
                MessageBox.Show("Somethings Wrong. Please try again.");
            }
        }