コード例 #1
0
        private void AddOrderDetailsButton_OnClick(object sender, RoutedEventArgs e)
        {
            List <Material> materials  = new List <Material>();
            List <Operatie> operations = new List <Operatie>();
            List <Mecanic>  mechanics  = new List <Mecanic>();
            List <Imagine>  images     = new List <Imagine>();

            DataRowView selectedRow = (DataRowView)DisplayOrderOrdersDataGrid.SelectedItem;
            string      autoIdText  = selectedRow["Id"].ToString();
            int         orderId     = Convert.ToInt32(autoIdText);

            IList selectedMaterials = DisplayOrderMaterialsDataGrid.SelectedItems;
            int   materialsSize     = selectedMaterials.Count;

            for (var i = 0; i < materialsSize; i++)
            {
                DataRowView row    = (DataRowView)DisplayOrderMaterialsDataGrid.SelectedItems[i];
                string      textId = row["Id"].ToString();

                Console.WriteLine(textId); // a luat bine

                int id = Convert.ToInt32(textId);

                Material material = _client.FindMaterialById(id);
                _totalCost += material.Pret;

                material.Cantitate -= 1;
                _client.UpdateMaterial(material);

                materials.Add(material);

                // merge bine
                foreach (var item in materials)
                {
                    Console.WriteLine(item.Denumire, material.Id);
                }
            }

            IList selectedOperations = DisplayOrderOperationsDataGrid.SelectedItems;
            int   operationsSize     = selectedOperations.Count;

            for (var i = 0; i < operationsSize; i++)
            {
                DataRowView row    = (DataRowView)DisplayOrderOperationsDataGrid.SelectedItems[i];
                string      textId = row["Id"].ToString();
                int         id     = Convert.ToInt32(textId);

                Operatie operation = _client.FindOperationById(id);
                operations.Add(operation);
            }

            IList selectedMechanics = DisplayOrderMechanicsDataGrid.SelectedItems;
            int   mechanicsSize     = selectedMechanics.Count;

            for (var i = 0; i < mechanicsSize; i++)
            {
                DataRowView row    = (DataRowView)DisplayOrderMechanicsDataGrid.SelectedItems[i];
                string      textId = row["Id"].ToString();
                int         id     = Convert.ToInt32(textId);

                Mecanic mecanic = _client.FindMecanicById(id);
                mechanics.Add(mecanic);
            }

            IList selectedImages = DisplayOrderImagesDataGrid.SelectedItems;
            int   imagesSize     = selectedImages.Count;

            for (var i = 0; i < imagesSize; i++)
            {
                DataRowView row    = (DataRowView)DisplayOrderImagesDataGrid.SelectedItems[i];
                string      textId = row["Id"].ToString();
                int         id     = Convert.ToInt32(textId);

                Imagine image = _client.FindImageById(id);
                images.Add(image);
            }

            DetaliuComanda orderDetails = new DetaliuComanda()
            {
                ComandaId = orderId,
                Imagini   = images.ToArray(),
                Mecanici  = mechanics.ToArray(),
                Materiale = materials.ToArray(),
                Operatii  = operations.ToArray()
            };

            _client.AddOrderDetails(orderDetails);

            Comanda order = _client.FindOrderById(orderId);

            order.ValoarePiese = _totalCost + _serviceFee;
            _client.UpdateOrder(order);
        }