Пример #1
0
        private void insertButton(object sender, EventArgs e)
        {
            using (var db = new SoftwareEntities())
            {
                db.Product.Add(new Product {
                    product_name = textBox2.Text, product_cost = Convert.ToInt32(textBox1.Text)
                });
                db.SaveChanges();
            }



            if (textBox1.Text == "")
            {
                MessageBox.Show("Please fill all fields!!", "Alert", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
            }
            else if (textBox2.Text == "")
            {
                MessageBox.Show("Please fill all fields!!", "Alert", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
            }
            else if (textBox3.Text == "")
            {
                MessageBox.Show("Please fill all fields!!", "Alert", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
            }
            else
            {
                connection.Open();
                SqlCommand command  = new SqlCommand("Insert into Softwares(software_name,employee_id) values('" + textBox2.Text.ToString() + "','" + textBox3.Text.ToString() + "') ", connection);
                SqlCommand command2 = new SqlCommand("Insert into Product(product_name,product_cost) values('" + textBox2.Text.ToString() + "','" + textBox1.Text.ToString() + "') ", connection);
                command.ExecuteNonQuery();
                command2.ExecuteNonQuery();
                connection.Close();
                showDatas();
            }
        }
Пример #2
0
        private void insertButton(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("Please fill all fields!!", "Alert", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
            }
            else if (textBox2.Text == "")
            {
                MessageBox.Show("Please fill all fields!!", "Alert", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
            }
            else if (textBox3.Text == "")
            {
                MessageBox.Show("Please fill all fields!!", "Alert", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
            }
            if (textBox4.Text == "")
            {
                MessageBox.Show("Please fill all fields!!", "Alert", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
            }
            else if (comboBox1.Text == "")
            {
                MessageBox.Show("Please fill all fields!!", "Alert", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
            }
            else if (comboBox2.Text == "")
            {
                MessageBox.Show("Please fill all fields!!", "Alert", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
            }
            else
            {
                using (var db = new SoftwareEntities())
                {
                    db.Customer.Add(new Customer {
                        customer_name = textBox1.Text, customer_surname = textBox2.Text, customer_gender = (int)Convert.ToInt32(comboBox1.SelectedValue), customer_adress = textBox3.Text, customer_job = textBox4.Text, customer_soft = (int)Convert.ToInt32(comboBox2.SelectedValue)
                    });
                    db.SaveChanges();
                }
                showDatas();

                //alternatif yol entitiy framework kullanma yukarda

                //connection.Open();
                //SqlCommand command = new SqlCommand("Insert into Customer(customer_name,customer_surname,customer_gender,customer_adress,customer_job,customer_soft) values('" + textBox1.Text.ToString() + "','" + textBox2.Text.ToString() + "','" + comboBox1.SelectedValue + "','" + textBox3.Text.ToString() + "','" + textBox4.Text.ToString() + "','" + comboBox2.SelectedValue + "') select Customer.customer_gender from Customer inner join Gender ON Customer.customer_gender = Gender.gender_id", connection);
                //command.ExecuteNonQuery();
                //connection.Close();
                //showDatas();
            }
        }
Пример #3
0
        private void deleteButton(object sender, EventArgs e)
        {
            using (var db = new SoftwareEntities())
            {
                int      id       = int.Parse(listView1.SelectedItems[0].SubItems[0].Text);
                Customer customer = new Customer {
                    customer_id = id
                };
                db.Entry(customer).State = EntityState.Deleted;
                db.SaveChanges();
            }
            showDatas();

            //connection.Open();
            //int id = int.Parse(listView1.SelectedItems[0].SubItems[0].Text);
            //SqlCommand command = new SqlCommand("Delete from Customer where customer_id=(" + id + ")", connection);
            //command.ExecuteNonQuery();
            //connection.Close();
        }