public addIntoOrder()
 {
     InitializeComponent();
     db = new STOContext();
     db.goods.Load();
     GoodsGrid.ItemsSource = db.goods.Local.ToBindingList();
     this.Closing         += Window_Closing;
 }
예제 #2
0
        private void comCar_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            STOContext strContext = new STOContext();
            //auto select customer
            int CarOwnerID = strContext.car.Where(
                a => a.carModel.Name + " " + a.carNumber == this.comCar.SelectedItem.ToString()
                ).Single().customerId;

            this.comCustomer.SelectedItem = (sc.customers.Where(a => a.ID == CarOwnerID).Single().LastName + " "
                                             + sc.customers.Where(a => a.ID == CarOwnerID).Single().Name);
            this.comCustomer.IsEnabled = false;
        }
예제 #3
0
        private void comboFillCars()
        {
            //function what selected and filling combo box car
            string     model;
            STOContext strContext = new STOContext();

            foreach (var item in sc.car)
            {
                //find model name for displayed in combo box model name + car number
                model = strContext.carModel.Where(a => a.ID == item.carmodelId).Single().Name;
                //added finding result into combo box
                this.selCar.Items.Add(model + " " + item.carNumber);
            }
        }
예제 #4
0
        private void fillingHeader()
        {
            //filling some visual elements
            this.comCar.Items.Clear();
            this.comCustomer.Items.Clear();
            string model;

            //filling car of customer's
            foreach (var item in sc.car)
            {
                STOContext strContext = new STOContext();
                model = strContext.carModel.Where(a => a.ID == item.carmodelId).Single().Name;
                this.comCar.Items.Add(model + " " + item.carNumber);
            }
            //filling fild customers
            foreach (var item in sc.customers)
            {
                this.comCustomer.Items.Add(item.LastName + " " + item.Name);
            }
        }
예제 #5
0
        //method determines what user add want, this method call new form with some parameters, which describe UI in AddForm
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            //work with STO context
            if (rbValue == "rbtnOrder")
            {
                //create new window for added new Order
                NewOrder insOrder = new NewOrder(false);
                insOrder.Owner = this;

                STOContext strContext = new STOContext();
                #region order
                if (insOrder.ShowDialog() == true)
                {
                    //find car id from add order dialog
                    int CarID = strContext.car.Where(
                        a => a.carModel.Name + " " + a.carNumber == insOrder.comCar.SelectedItem.ToString()
                        ).Single().ID;

                    //add new order into db
                    Orders ord = new Orders()
                    {
                        carId = CarID, Date = DateTime.Parse(insOrder.txtDateTime.Text)
                    };
                    sc.orders.Add(ord);
                    sc.SaveChanges();
                    //add order context into db table
                    foreach (OrderDescr item in insOrder.listOrders.ItemsSource)
                    {
                        OrderCotnext orderTable = new OrderCotnext()
                        {
                            OrderId = ord.ID,
                            goodsID = item.GoodsId,
                            Count   = item.Count,
                            Price   = item.Price,
                            Suma    = item.Summa
                        };
                        sc.ordersContext.Add(orderTable);
                        sc.SaveChanges();
                    }
                    //add last added order into listOrders - this described above
                    int    iCustID      = sto.car.Where(n => n.ID == ord.carId).Single().customerId;
                    string strCarNumber = sto.car.Where(n => n.ID == ord.carId).Single().carNumber;
                    int    iCarModel    = sto.car.Where(n => n.ID == ord.carId).Single().carmodelId;
                    string strCarModel  = sto.carModel.Where(m => m.ID == iCarModel).Single().Name;
                    string strCustName  = sto.customers.Where(n => n.ID == iCustID).Single().LastName +
                                          " " + sto.customers.Where(n => n.ID == iCustID).Single().Name;
                    string strPhone = sto.customers.Where(n => n.ID == iCustID).Single().Phone;

                    OrderItems.Add(new OrdersDescr(ord.Date, ord.ID, strCustName, strPhone, strCarModel, strCarNumber, 0));

                    this.listOrders.Items.Refresh();
                    this.listOrders.ItemsSource = OrderItems;
                }
                #endregion
            }
            else
            {
                //add new customer
                AddWindow addWnd = new AddWindow(rbValue);
                if (addWnd.ShowDialog() == true)
                {
                    #region customer
                    if (rbValue == "rbtnCustomer")
                    {
                        Customers cust = new Customers()
                        {
                            Name = addWnd.txtBox1.Text, LastName = addWnd.txtBox2.Text, Phone = addWnd.txtBox3.Text
                        };
                        sc.customers.Add(cust);
                        sc.SaveChanges();
                        this.selCustomers.Items.Add(cust.LastName + " " + cust.Name);
                    }
                    #endregion
                    //add new car
                    #region car
                    if (rbValue == "rbtnCar")
                    {
                        Car car = new Car();
                        car.carNumber   = addWnd.txtBox1.Text;
                        car.carmodelId  = sc.carModel.Where(a => a.Name == addWnd.txtBox2.Text).Single().ID;
                        car.customerId  = sc.customers.Where(a => a.LastName + " " + a.Name == addWnd.txtBox3.Text).Single().ID;
                        car.YearProduce = Int32.Parse(addWnd.txtBox4.Text);
                        sc.car.Add(car);
                        sc.SaveChanges();
                    }
                    #endregion
                    //add new car model
                    #region carmodel
                    if (rbValue == "rbtnCarModel")
                    {
                        CarModel carM = new CarModel()
                        {
                            Name = addWnd.txtBox1.Text
                        };
                        sc.carModel.Add(carM);
                        sc.SaveChanges();
                        this.selCar.Items.Add(carM.Name);
                    }
                    #endregion
                    //add new godds type
                    #region GoddsType
                    if (rbValue == "rbtnGoodsType")
                    {
                        GoodsType gt = new GoodsType()
                        {
                            Name = addWnd.txtBox1.Text
                        };
                        sc.goodsType.Add(gt);
                        sc.SaveChanges();
                    }
                    #endregion
                    //add new goods
                    #region goods
                    if (rbValue == "rbtnGoods")
                    {
                        Goods goods = new Goods()
                        {
                            Name        = addWnd.txtBox1.Text,
                            GoodsTypeID = sc.goodsType.Where(a => a.Name == addWnd.txtBox4.Text).Single().ID,
                            Price       = Int32.Parse(addWnd.txtBox3.Text),
                            CarModelID  = sc.carModel.Where(a => a.Name == addWnd.txtBox2.Text).Single().ID
                        };

                        sc.goods.Add(goods);
                        sc.SaveChanges();
                    }
                    #endregion
                }
            }
        }