Exemple #1
0
 private void CheckExchangesStatus(int code)
 {
     if (code.Equals(EXCHANGE_STATUS))
     {
         // провірити чи є товар в даний момент на складі
         try
         {
             GoodsShops goodsShop = (db.GoodsShops as IEnumerable <GoodsShops>)
                                    .Where(x => x.Good_ID.Equals(GoodsComboBox.SelectedValue) &&
                                           x.Shop_ID.Equals(employee.Shop_ID))
                                    .FirstOrDefault();
             if (goodsShop.Count > 0)
             {
                 db.GoodsShops.Attach(goodsShop);
                 goodsShop.Count -= 1;
                 db.SaveChanges();
                 createService(code);
                 this.Close();
             }
             else
             {
                 MessageBox.Show("В даний момент у магазині немає цього товару", "Повідомлення", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
         catch (NullReferenceException)
         {
             MessageBox.Show("В даний момент у магазині немає цього товару", "Повідомлення", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     else
     {
         createService(code);
         this.Close();
     }
 }
Exemple #2
0
        private void NewShipmentForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.OK)
            {
                Delivery delivery = (db.Delivery as IEnumerable <Delivery>)
                                    .Where(x => x.Deliver_ID.Equals(DeliveryComboBox.SelectedValue))
                                    .FirstOrDefault();
                GoodsShops gs = (db.GoodsShops as IEnumerable <GoodsShops>)
                                .Where(x => x.Shop_ID.Equals(ShopComboBox.SelectedValue ?? 0) &&
                                       x.Good_ID.Equals(delivery.Good_ID))
                                .FirstOrDefault();
                if (gs != null)
                {
                    db.GoodsShops.Attach(gs);
                    gs.Count += delivery.Count;
                }
                else
                {
                    gs = new GoodsShops()
                    {
                        Code    = CodeGenerator.GenerateCode("GoodsShops", "gs"),
                        Good_ID = delivery.Good_ID,
                        Shop_ID = (int)ShopComboBox.SelectedValue,
                        Count   = delivery.Count
                    };
                    db.GoodsShops.Add(gs);
                    db.SaveChanges();
                    gs = (db.GoodsShops as IEnumerable <GoodsShops>)
                         .Where(x => x.Shop_ID.Equals(ShopComboBox.SelectedValue ?? 0) &&
                                x.Good_ID.Equals(delivery.Good_ID))
                         .FirstOrDefault();
                }

                Shipment shipment = new Shipment()
                {
                    Deliver_ID    = delivery.Deliver_ID,
                    GoodsShops_ID = gs.GoodsShops_ID,
                    Employee_ID   = (int)EmployeeComboBox.SelectedValue,
                    Date          = DateTime.Now
                };
                db.Shipment.Add(shipment);
                db.SaveChanges();
            }
            e.Cancel = false;
        }
Exemple #3
0
 public GoodsShopsIEF(GoodsShops obj, my_db_for_db_2Entities _db)
 {
     InitializeComponent();
     db = _db;
     goodsBindingSource.DataSource      = db.Goods.ToList();
     shopsBindingSource.DataSource      = db.Shops.ToList();
     goodsShopsBindingSource.DataSource = db.GoodsShops.ToList();
     if (obj == null)
     {
         goodsShopsBindingSource.DataSource = new GoodsShops();
         db.GoodsShops.Add(goodsShopsBindingSource.Current as GoodsShops);
     }
     else
     {
         goodsShopsBindingSource.DataSource = obj;
         db.GoodsShops.Attach(goodsShopsBindingSource.Current as GoodsShops);
     }
 }
Exemple #4
0
        private void NewTransportationForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.OK)
            {
                if (!ShopFromComboBox.SelectedValue.Equals(ShopToComboBox.SelectedValue))
                {
                    if (countNUD.Value < 1)
                    {
                        MessageBox.Show("Оберіть кількість", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        e.Cancel = true;
                        return;
                    }
                    else
                    {
                        int        goodID = (int)(goodsComboBox.SelectedValue ?? 0);
                        int        shopTo = (int)(ShopToComboBox.SelectedValue ?? 0);
                        GoodsShops GS_To  = (db.GoodsShops as IEnumerable <GoodsShops>)
                                            .Where(x => x.Good_ID.Equals(goodID) &&
                                                   x.Shop_ID.Equals(shopTo))
                                            .Select(x => x)
                                            .FirstOrDefault();
                        if (GS_To == null)
                        {
                            GS_To = new GoodsShops()
                            {
                                Code    = CodeGenerator.GenerateCode("GoodsShops", "gs"),
                                Good_ID = goodID,
                                Shop_ID = shopTo,
                                Count   = 0
                            };
                            db.GoodsShops.Add(GS_To);
                            db.SaveChanges();
                            GS_To = (db.GoodsShops as IEnumerable <GoodsShops>)
                                    .Where(x => x.Good_ID.Equals(goodID) &&
                                           x.Shop_ID.Equals(shopTo))
                                    .Select(x => x)
                                    .FirstOrDefault();
                        }
                        GoodsShops GS_From = (db.GoodsShops as IEnumerable <GoodsShops>)
                                             .Where(x => x.Good_ID.Equals(goodID) &&
                                                    x.Shop_ID.Equals(ShopFromComboBox.SelectedValue ?? 0))
                                             .Select(x => x)
                                             .FirstOrDefault();
                        int            count          = (int)countNUD.Value;
                        Transportation transportation = new Transportation()
                        {
                            GS_from_ID  = GS_From.GoodsShops_ID,
                            GS_in_ID    = GS_To.GoodsShops_ID,
                            Employee_ID = employee.Employee_ID,
                            Date        = DateTime.Now,
                            Count       = count
                        };

                        db.Transportation.Add(transportation);
                        db.GoodsShops.Attach(GS_From);
                        GS_From.Count -= count;
                        db.GoodsShops.Attach(GS_To);
                        GS_To.Count += count;
                        db.SaveChanges();
                        //this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Оберіть різні магазини", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;
                    return;
                }
            }
            e.Cancel = false;
        }