Exemple #1
0
 private void FillOrders()
 {
     using (var db = new ShopContext()){
     }
 }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            int    cat;
            double price;
            int    vat;
            int    availble;

            try
            {
                cat = (int)dataGridView1.SelectedCells[0].Value;
            }
            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry(ex.Source, ex.StackTrace, System.Diagnostics.EventLogEntryType.Warning);
                MessageBox.Show("Niepoprawna kategoria");
                return;
            }
            try
            {
                price = Convert.ToDouble(textBox2.Text);
            }
            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry(ex.Source, ex.StackTrace, System.Diagnostics.EventLogEntryType.Warning);
                MessageBox.Show(textBox2.Text + " nie jest poprawną ceną");
                return;
            }
            try
            {
                vat = Convert.ToInt32(textBox3.Text);
            }
            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry(ex.Source, ex.StackTrace, System.Diagnostics.EventLogEntryType.Warning);
                MessageBox.Show(textBox3.Text + " nie jest poprawną stawką vat");
                return;
            }
            try
            {
                availble = Convert.ToInt32(textBox4.Text);
            }
            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry(ex.Source, ex.StackTrace, System.Diagnostics.EventLogEntryType.Warning);
                MessageBox.Show(textBox4.Text + " nie jest poprawną liczbą");
                return;
            }
            if (availble < (int)row.Cells[6].Value)
            {
                MessageBox.Show(textBox4.Text + " to mniej niż w tym momencie jest zamówionych");
                return;
            }
            try
            {
                database = new ShopContext();
                if (
                    EditProduct((int)row.Cells[0].Value, cat, textBox1.Text) &&
                    EditPrice((int)row.Cells[8].Value, (int)row.Cells[0].Value, DateTime.Now, price) &&
                    EditVat((int)row.Cells[9].Value, (int)row.Cells[0].Value, DateTime.Now, vat) &&
                    EditAvail((int)row.Cells[0].Value, availble))
                {
                    database.SaveChanges();
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Wystąpił problem z edytowaniem produktu");
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry(ex.Source, ex.StackTrace, System.Diagnostics.EventLogEntryType.Warning);
                MessageBox.Show("Błąd zapisu do bazy");
                return;
            }
            finally
            {
                database.Dispose();
            }
        }
Exemple #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            int    prodId;
            double price;
            int    vat;
            int    count;

            try
            {
                prodId = (int)dataGridView1.SelectedCells[0].Value;
            }
            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry(ex.Source, ex.StackTrace, System.Diagnostics.EventLogEntryType.Warning);
                MessageBox.Show("Niepoprawny produkt");
                return;
            }
            try
            {
                price = Convert.ToDouble(textBox1.Text);
            }
            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry(ex.Source, ex.StackTrace, System.Diagnostics.EventLogEntryType.Warning);
                MessageBox.Show(textBox1.Text + " nie jest poprawną ceną");
                return;
            }
            try
            {
                vat = Convert.ToInt32(textBox2.Text);
            }
            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry(ex.Source, ex.StackTrace, System.Diagnostics.EventLogEntryType.Warning);
                MessageBox.Show(textBox2.Text + " nie jest poprawną stawką vat");
                return;
            }
            try
            {
                count = Convert.ToInt32(textBox3.Text);
            }
            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry(ex.Source, ex.StackTrace, System.Diagnostics.EventLogEntryType.Warning);
                MessageBox.Show(textBox3.Text + " nie jest poprawną liczbą");
                return;
            }
            if (count < 0)
            {
                MessageBox.Show(textBox3.Text + " nie jest poprawną wartością");
                return;
            }
            if (price < 0)
            {
                MessageBox.Show("Cena powinna być dodatnia");
                return;
            }
            try
            {
                database = new ShopContext();
                if (InsertNewDetail(delivId, prodId, price, vat, count))
                {
                    database.SaveChanges();
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Wystąpił problem z dodawaniem produktu");
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry(ex.Source, ex.StackTrace, System.Diagnostics.EventLogEntryType.Warning);
                MessageBox.Show("Błąd zapisu do bazy");
                return;
            }
            finally
            {
                database.Dispose();
            }
        }