Exemple #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            SkladDBEntities context         = new SkladDBEntities();
            int             currentCustomer = Convert.ToInt32(
                dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells[1].Value);

            Customer c = context.Customer.Find(currentCustomer);

            List <Invoice> invoidce = context.Invoice
                                      .Where(o => o.ID_customer == currentCustomer).ToList();

            List <Product_customer> pc = context.Product_customer
                                         .Where(o => o.ID_customer == currentCustomer).ToList();

            for (int i = 0; i < invoidce.Count; i++)
            {
                context.Invoice.Remove(invoidce[i]);
            }
            for (int i = 0; i < pc.Count; i++)
            {
                context.Product_customer.Remove(pc[i]);
            }
            context.Customer.Remove(c);
            context.SaveChanges();

            RefreshCustomer();
            RefreshCustProducts();
        }
Exemple #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            SkladDBEntities context        = new SkladDBEntities();
            int             currentProduct = Convert.ToInt32(
                dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[2].Value);

            Product c = context.Product.Find(currentProduct);

            List <Product_Storage_place> invoidce = context.Product_Storage_place
                                                    .Where(o => o.ID_product == currentProduct).ToList();

            List <Product_customer> pc = context.Product_customer
                                         .Where(o => o.ID_product == currentProduct).ToList();

            for (int i = 0; i < invoidce.Count; i++)
            {
                context.Product_Storage_place.Remove(invoidce[i]);
            }
            for (int i = 0; i < pc.Count; i++)
            {
                context.Product_customer.Remove(pc[i]);
            }
            context.Product.Remove(c);
            context.SaveChanges();

            //RefreshCustomer();
            RefreshCustProducts();
            RefreshProduct();
        }
Exemple #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string           date    = textBox1.Text;
                SkladDBEntities  context = new SkladDBEntities();
                Product_customer p_c     = context.Product_customer
                                           .Where(o => o.ID_customer == currentCust &&
                                                  o.ID_product == currentProd).First();
                if (date == "")
                {
                    MessageBox.Show("Заполните поле дата");
                    return;
                }
                p_c.Order_date = date;
                context.Product_customer.Attach(p_c);
                context.Entry(p_c).Property(o => o.Order_date).IsModified = true;
                context.SaveChanges();

                DialogResult = DialogResult.OK;
            }
            catch (FormatException)
            {
                MessageBox.Show("Заполните поле дата");
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                SkladDBEntities context = new SkladDBEntities();
                int             id      = context.Product.Max(o => o.ID_product);
                string          name    = textBox1.Text;
                string          manuf   = textBox2.Text;

                List <Manufacturer> m = context.Manufacturer
                                        .Where(o => o.C_Name == name).ToList();

                if (m.Count == 0)
                {
                    int          idM = context.Manufacturer.Max(o => o.ID_manufacturer);
                    Manufacturer man = new Manufacturer
                    {
                        ID_manufacturer = idM + 1,
                        C_Name          = manuf
                    };
                    Product p = new Product
                    {
                        C_Name          = name,
                        ID_product      = id + 1,
                        C_Count         = 0,
                        ID_manufacturer = man.ID_manufacturer
                    };

                    context.Manufacturer.Add(man);
                    context.Product.Add(p);
                }
                else
                {
                    Product p = new Product
                    {
                        C_Name          = name,
                        ID_product      = id + 1,
                        C_Count         = 0,
                        ID_manufacturer = m[0].ID_manufacturer
                    };

                    context.Product.Add(p);
                }

                context.SaveChanges();
                DialogResult = DialogResult.OK;
            }
            catch (Exception)
            {
                MessageBox.Show("Заполните пустые поля");
            }
        }
Exemple #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                int    count = Convert.ToInt32(textBox2.Text);
                string adr   = textBox1.Text;

                if (count < 0)
                {
                    MessageBox.Show("Введите корректное число в поле \"Count\"");
                    return;
                }
                SkladDBEntities context = new SkladDBEntities();

                List <Storage_place> p = context.Storage_place
                                         .Where(o => o.Adress == adr).ToList();
                if (p.Count == 0)
                {
                    int idStor = context.Storage_place.Count() != 0 ?
                                 context.Storage_place.Max(o => o.ID_storage_place) + 1 : 1;

                    Storage_place s = new Storage_place
                    {
                        ID_storage_place = idStor,
                        Adress           = adr
                    };
                    Product_Storage_place n = new Product_Storage_place
                    {
                        ID_storage_place = s.ID_storage_place,
                        ID_product       = currentProd,
                        C_Count          = count
                    };
                    context.Storage_place.Add(s);
                    context.Product_Storage_place.Add(n);
                }
                else
                {
                    Product_Storage_place n = new Product_Storage_place
                    {
                        ID_storage_place = p[0].ID_storage_place,
                        ID_product       = currentProd,
                        C_Count          = count
                    };
                    context.Product_Storage_place.Add(n);
                }

                context.SaveChanges();
                DialogResult = DialogResult.OK;
            }
            catch (FormatException) { MessageBox.Show("Заполните поля"); }
            catch (Exception) { }
        }
Exemple #6
0
        void RefreshCustomer()
        {
            SkladDBEntities context = new SkladDBEntities();
            var             trans   = from cust in context.Customer
                                      select new
            {
                name   = cust.C_Name,
                custID = cust.ID_customer
            };

            dataGridView2.DataSource         = trans.ToList();
            dataGridView2.Columns[1].Visible = false;
        }
Exemple #7
0
        private void button9_Click(object sender, EventArgs e)
        {
            int             currentProd = (int)dataGridView3.CurrentRow.Cells[2].Value;
            int             currentCust = (int)dataGridView2.CurrentRow.Cells[1].Value;
            SkladDBEntities context     = new SkladDBEntities();

            Product_customer p_c = context.Product_customer
                                   .Where(o => o.ID_customer == currentCust &&
                                          o.ID_product == currentProd).First();

            context.Product_customer.Remove(p_c);
            context.SaveChanges();
            RefreshCustProducts();
        }
Exemple #8
0
        private void AddCustomerProdForm_Load(object sender, EventArgs e)
        {
            SkladDBEntities context = new SkladDBEntities();
            var             trans   = from prod in context.Product
                                      join manuf in context.Manufacturer on prod.ID_manufacturer equals manuf.ID_manufacturer
                                      select new
            {
                name         = prod.C_Name,
                manufacturer = manuf.C_Name,
                prodID       = prod.ID_product
            };

            dataGridView1.DataSource         = trans.ToList();
            dataGridView1.Columns[2].Visible = false;
        }
Exemple #9
0
        void RefreshProduct()
        {
            SkladDBEntities context = new SkladDBEntities();
            var             trans   = from prod in context.Product
                                      join manuf in context.Manufacturer on prod.ID_manufacturer equals manuf.ID_manufacturer
                                      select new
            {
                name         = prod.C_Name,
                manufacturer = manuf.C_Name,
                prodID       = prod.ID_product
            };

            dataGridView1.DataSource         = trans.ToList();
            dataGridView1.Columns[2].Visible = false;
        }
Exemple #10
0
        private void button6_Click(object sender, EventArgs e)
        {
            string          currentRow = dataGridView4.Rows[dataGridView4.CurrentRow.Index].Cells[0].Value.ToString();
            SkladDBEntities context    = new SkladDBEntities();
            Storage_place   stor       = context.Storage_place
                                         .Where(o => o.Adress == currentRow).First();

            Product_Storage_place p_s = context.Product_Storage_place
                                        .Where(o => o.ID_product == currentProduct &&
                                               o.ID_storage_place == stor.ID_storage_place).First();

            context.Product_Storage_place.Remove(p_s);
            context.SaveChanges();
            RefreshProdInfo();
        }
Exemple #11
0
        private void EditCustomerProdForm_Load(object sender, EventArgs e)
        {
            SkladDBEntities context = new SkladDBEntities();

            var trans = from prod in context.Product
                        join prod_cust in context.Product_customer on prod.ID_product equals prod_cust.ID_product
                        where prod_cust.ID_customer == currentCust
                        select new
            {
                Product    = prod.C_Name,
                Order_date = prod_cust.Order_date
            };

            textBox1.Text            = trans.ToList()[0].Order_date;
            dataGridView1.DataSource = trans.ToList();
        }
Exemple #12
0
        void RefreshProdInfo()
        {
            SkladDBEntities context = new SkladDBEntities();
            int             prodID  = (int)dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[2].Value;

            currentProduct = prodID;

            var trans = from prod_stor in context.Product_Storage_place
                        join stor in context.Storage_place on prod_stor.ID_storage_place equals stor.ID_storage_place
                        where prod_stor.ID_product == prodID
                        select new
            {
                Adress = stor.Adress,
                Count  = prod_stor.C_Count
            };

            dataGridView4.DataSource = trans.ToList();
        }
Exemple #13
0
        void RefreshCustProducts()
        {
            SkladDBEntities context = new SkladDBEntities();
            int             custID  = (int)dataGridView2.CurrentRow.Cells[1].Value;

            var trans = from prod_cust in context.Product_customer
                        join prod in context.Product on prod_cust.ID_product equals prod.ID_product
                        where prod_cust.ID_customer == custID
                        select new
            {
                Product    = prod.C_Name,
                Order_Date = prod_cust.Order_date,
                prodId     = prod_cust.ID_product
            };

            dataGridView3.DataSource         = trans.ToList();
            dataGridView3.Columns[2].Visible = false;
        }
Exemple #14
0
        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                int    nCount = Convert.ToInt32(textBox2.Text);
                string adr    = textBox1.Text;

                if (nCount < 0)
                {
                    MessageBox.Show("Введите корректное число в поле \"Count\"");
                    return;
                }
                SkladDBEntities context = new SkladDBEntities();
                Storage_place   stor    = context.Storage_place
                                          .Where(o => o.Adress == addr)
                                          .First();

                Product_Storage_place p_s = context.Product_Storage_place
                                            .Where(o => o.ID_product == currentProd &&
                                                   o.ID_storage_place == stor.ID_storage_place).First();
                //.Find(currentProd, stor.ID_storage_place);

                stor.Adress = adr;
                p_s.C_Count = nCount;

                context.Storage_place.Attach(stor);
                context.Entry(stor).Property(o => o.Adress).IsModified = true;
                context.Product_Storage_place.Attach(p_s);
                context.Entry(p_s).Property(o => o.C_Count).IsModified = true;
                context.SaveChanges();
                DialogResult = DialogResult.OK;
            }
            catch (FormatException)
            {
                MessageBox.Show("Заполните поля");
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #15
0
        private void dataGridView1_Click(object sender, EventArgs e)
        {
            try
            {
                SkladDBEntities context     = new SkladDBEntities();
                int             currentProd = (int)dataGridView1.CurrentRow.Cells[2].Value;

                Product_customer p_c = new Product_customer
                {
                    ID_product  = currentProd,
                    ID_customer = currentCust,
                    Order_date  = DateTime.Now.Date.ToString()
                };

                context.Product_customer.Add(p_c);
                context.SaveChanges();
                MessageBox.Show("Товар добавлен");
            }
            catch (Exception)
            {
                MessageBox.Show("Товар уже добавлен");
            }
        }
Exemple #16
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                SkladDBEntities context = new SkladDBEntities();
                int             ID      = context.Customer.Max(o => o.ID_customer);
                string          name    = textBox1.Text;

                Customer c = new Customer
                {
                    C_Name      = name,
                    ID_customer = ID + 1
                };

                context.Customer.Add(c);
                context.SaveChanges();
                DialogResult = DialogResult.OK;
            }
            catch (Exception)
            {
                MessageBox.Show("Заполните поле \"Name\"");
                //throw;
            }
        }