示例#1
0
        private void NewDeliveryForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.OK)
            {
                //TODO провірки
                ProvideOrder provideOrder = new ProvideOrder()
                {
                    Code       = CodeGenerator.GenerateCode("ProvideOrder", "po"),
                    Date       = DateTime.Now,
                    TotalCost  = (int)TotalPrice(),
                    Provide_ID = (int)ProviderComboBox.SelectedValue
                };

                db.ProvideOrder.Add(provideOrder);
                db.SaveChanges();
                provideOrder = (db.ProvideOrder as IEnumerable <ProvideOrder>)
                               .Where(x => x.Code.Equals(provideOrder.Code))
                               .First();

                foreach (Delivery delivery in deliveryContain.Values)
                {
                    // записуємо вмістиме корзини в бд
                    delivery.Code            = CodeGenerator.GenerateCode("Delivery", "d");
                    delivery.ProvideOrder_ID = provideOrder.ProvideOrder_ID;
                    delivery.Date            = DateTime.Now;
                    db.Delivery.Add(delivery);
                    db.SaveChanges();
                }
                //db.SaveChanges();
                MessageBox.Show(totalPriceLabel.Text, "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            e.Cancel = false;
        }
示例#2
0
        private void NewSalesForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.OK)
            {
                if (basketsContain.Count == 0)
                {
                    MessageBox.Show("Для здійснення замовлення оберіть товар", "Повідомлення", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;
                    return;
                }
                else
                {
                    //генеруємо продажу
                    Sales sales = new Sales()
                    {
                        SalesCode   = CodeGenerator.GenerateCode("Sales", "sl"),
                        Employee_ID = employee.Employee_ID,
                        Customer_ID = (int)customerComboBox.SelectedValue,
                        Date        = DateTime.Now,
                        Guarante    = guaranteeCB.Checked,
                        Total       = TotalPrice()
                    };

                    db.Sales.Add(sales);
                    db.SaveChanges();
                    sales = (db.Sales as IEnumerable <Sales>)
                            .Where(x => x.SalesCode.Equals(sales.SalesCode))
                            .First();

                    GoodsShops gs;
                    foreach (Basket basket in basketsContain.Values)
                    {
                        // записуємо вмістиме корзини в бд
                        basket.Sales_ID = sales.Sales_ID;
                        db.Basket.Add(basket);
                        gs = db.GoodsShops
                             .Where(x => x.GoodsShops_ID.Equals(basket.GoodsShops_ID))
                             .First();
                        // зменшити кількість товарів
                        db.GoodsShops.Attach(gs);
                        gs.Count -= basket.Count;
                        db.SaveChanges();
                    }
                    //db.SaveChanges();
                    MessageBox.Show(totalPriceLabel.Text, "Повідомлення", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            e.Cancel = false;
        }
示例#3
0
 private void EmployeeIEF_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (DialogResult == DialogResult.OK)
     {
         if (string.IsNullOrEmpty(phoneTB.Text))
         {
             MessageBox.Show("Please ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
             firstNameTB.Focus();
             e.Cancel = true;
             return;
         }
         if (string.IsNullOrEmpty(phoneTB.Text))
         {
             MessageBox.Show("Please ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
             firstNameTB.Focus();
             e.Cancel = true;
             return;
         }
         if (string.IsNullOrEmpty(phoneTB.Text))
         {
             MessageBox.Show("Please ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
             phoneTB.Focus();
             e.Cancel = true;
             return;
         }
         db.SaveChanges();
         e.Cancel = false;
     }
     e.Cancel = false;
 }
示例#4
0
 private void GoodsIEF_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (DialogResult == DialogResult.OK)
     {
         if (string.IsNullOrEmpty(modelTB.Text))
         {
             MessageBox.Show("Please ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
             modelTB.Focus();
             e.Cancel = true;
             return;
         }
         if (string.IsNullOrEmpty(codeTB.Text))
         {
             MessageBox.Show("Please ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
             codeTB.Focus();
             e.Cancel = true;
             return;
         }
         if (string.IsNullOrEmpty(descriptionTB.Text))
         {
             MessageBox.Show("Please ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
             descriptionTB.Focus();
             e.Cancel = true;
             return;
         }
         db.SaveChanges();
         e.Cancel = false;
     }
     e.Cancel = false;
 }
示例#5
0
        private void Add_Click(object sender, EventArgs e)
        {
            Repair repair = new Repair()
            {
                ServiceTransportation_ID = (int)STComboBox.SelectedValue,
                Comment = CommentTextBox.Text,
                Date    = DateTime.Now
            };

            try
            {
                int serviceID = (db.ServiceTransportation as IEnumerable <ServiceTransportation>)
                                .Where(x => x.ServiceTransportation_ID.Equals((int)STComboBox.SelectedValue))
                                .Select(x => x.Service_ID)
                                .FirstOrDefault();
                Service service = (db.Service as IEnumerable <Service>)
                                  .Where(x => x.Service_ID.Equals(serviceID))
                                  .FirstOrDefault();
                if (!service.Status_ID.Equals(StatusComboBox.SelectedValue))
                {
                    db.Service.Attach(service);
                    service.Status_ID = (int)StatusComboBox.SelectedValue;
                }
                db.Repair.Add(repair);
                db.SaveChanges();
                updateTableContent();
            }
            catch (Exception)// переробити
            { }
        }
示例#6
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;
        }
示例#7
0
 private void ServiceIEF_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (DialogResult == DialogResult.OK)
     {
         db.SaveChanges();
         e.Cancel = false;
     }
     e.Cancel = false;
 }
示例#8
0
        private void createService(int status)
        {
            List <int> goodsShop = (db.GoodsShops as IEnumerable <GoodsShops>)
                                   .Where(x => x.Good_ID.Equals(GoodsComboBox.SelectedValue))
                                   .Select(x => x.GoodsShops_ID)
                                   .ToList();
            int basket = (db.Basket as IEnumerable <Basket>)
                         .Where(x => x.Sales_ID.Equals(SalesComboBox.SelectedValue) && goodsShop.Contains(x.GoodsShops_ID))
                         .Select(x => x.Basket_ID)
                         .FirstOrDefault();
            //TODO
            Service service = new Service()
            {
                Code        = CodeGenerator.GenerateCode("Service", "se"),
                Breakage_ID = (int)BreakageComboBox.SelectedValue,
                Status_ID   = status,
                Basket_ID   = basket,
                Date        = DateTime.Now
            };

            db.Service.Add(service);
            db.SaveChanges();
            MessageBox.Show(service.Code, "Повідомлення", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
示例#9
0
 private void Delete_Click(object sender, EventArgs e)
 {
     if (breakageBindingSource.Current != null)
     {
         if (MessageBox.Show("Ви впевнені ?", "Увага", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             try
             {
                 db.Breakage.Remove(breakageBindingSource.Current as Breakage);
                 db.SaveChanges();
                 breakageBindingSource.RemoveCurrent();
             }
             catch (Exception exc)
             {
                 MessageBox.Show("Дані не можливо видалити, оскільки це порушить цілісність бази даних", "Помилка", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
 }
        private void NewServiceTransportationForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.OK)
            {
                if (ServiceComboBox.SelectedValue != null)
                {
                    if (SCComboBox.SelectedValue != null)
                    {
                        ServiceTransportation serviceTransportation = new ServiceTransportation()
                        {
                            Code       = CodeGenerator.GenerateCode("ServiceTransportation", "st"),
                            Service_ID = (int)ServiceComboBox.SelectedValue,
                            SC_ID      = (int)SCComboBox.SelectedValue,
                            Date       = DateTime.Now
                        };

                        Service service = db.Service
                                          .Where(x => x.Service_ID.Equals((int)ServiceComboBox.SelectedValue))
                                          .FirstOrDefault();
                        db.Service.Attach(service);
                        service.Status_ID = 4;//у перевезені
                        db.ServiceTransportation.Add(serviceTransportation);
                        db.SaveChanges();
                    }
                    else
                    {
                        MessageBox.Show("Оберіть сервісний центр", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        e.Cancel = true;
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("оберіть заявку на ремонт", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    e.Cancel = true;
                    return;
                }
            }
            e.Cancel = false;
        }
示例#11
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;
        }