Example #1
0
        private void ParseServerMessage(Operatie op)
        {
            switch (op.Denumire)
            {
            case Operatie.DenumireOperatie.OP_SERVER:
            {
                OperatieServer os = op as OperatieServer;
                if (os.OperatiuneServer == OperatieServer.Operatii.SERV_SYNC)
                {
                    string data = os.opData as string;
                    SafeUpdateControl(tbContent, data);
                }
            }
            break;

            case Operatie.DenumireOperatie.OP_INSERARE:
            {
                OperatieInserare oi = op as OperatieInserare;
                int i = oi.InsertPoint.PozitieStart;
                int j = i + oi.InsertPoint.LungimeSelectie;
                SafeInsertContent(oi);
                //string data = tbContent.Text.Substring(0, i) + oi.InsertedText + tbContent.Text.Substring(j);
                //SafeUpdateControl(tbContent, data);
                SafeUpdateControl(tbLog, tbLog.Text + "INSERT recived from " + oi.Token + "\n");
            }
            break;

            default:
                break;
            }
        }
        public static void AplicaOperatie(int[] vector, int x, Operatie op)
        {
            for (int i = 0; i < vector.Length; ++i)
            {
                switch (op)
                {
                case Operatie.Adunare:
                    vector[i] += x;
                    break;

                case Operatie.Scadere:
                    vector[i] -= x;
                    break;

                case Operatie.Inmultire:
                    vector[i] *= x;
                    break;

                case Operatie.Impartire:
                    if (x == 0)
                    {
                        throw new DivideByZeroException("Impartirea la zero strict interzisa!");
                    }
                    vector[i] /= x;
                    break;
                }
            }
        }
Example #3
0
        private bool BuildOperatie()
        {
            var operatie = new Operatie()
            {
                Denumire     = addOperatieTextBox.Text,
                TimpExecutie = decimal.Parse(timpExecutieTextBox.Text)
            };

            DialogResult userResponse;

            do
            {
                var response = _serviceApi.AddOperatie(operatie, _detaliuComanda);

                if (response)
                {
                    break;
                }

                userResponse =
                    MessageBox.Show(@"Ups.. change could not be done.  Try again ?", @"Something went wrong",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Error);

                if (userResponse == DialogResult.No)
                {
                    break;
                }
            } while (userResponse == DialogResult.Yes);


            operatiiListView.Items.Add($"{operatie.Denumire}");

            return(true);
        }
Example #4
0
        private void AddOperationButton_OnClick(object sender, RoutedEventArgs e)
        {
            string name          = AddOperationNameTextBox.Text;
            string executionTime = AddOperationExecutionTimeTextBox.Text;

            if (!FieldsCompleted(name, executionTime))
            {
                AddOperationDisplayInfoTextBlock.Text = @"Must complete mandatory fields.";
            }
            else
            {
                AddOperationButton.IsEnabled = true;
                Operatie operation = new Operatie()
                {
                    Denumire     = name,
                    TimpExecutie = Convert.ToDecimal(executionTime)
                };

                _client.AddOperation(operation);

                AddOperationDisplayInfoTextBlock.Text       = @"Operation added.";
                AddOperationDisplayInfoTextBlock.Visibility = Visibility.Visible;

                OperationsTabItem_OnLoaded(sender, e);
            }
        }
Example #5
0
        public static OperationModel FromEntityToModel(Operatie operationEntity)
        {
            OperationModel operationModel = new OperationModel();

            operationModel.OperationId   = operationEntity.OperatieId;
            operationModel.Name          = operationEntity.Denumire;
            operationModel.ExecutionTime = operationEntity.TimpExecutie;
            return(operationModel);
        }
Example #6
0
 public void Delete(Operatie operatie)
 {
     if (operatie == null)
     {
         return;
     }
     Context.Operaties.Remove(operatie);
     Context.SaveChanges();
 }
Example #7
0
 public void Add(Operatie operatie)
 {
     if (operatie == null)
     {
         return;
     }
     Context.Operaties.Add(operatie);
     Context.SaveChanges();
 }
Example #8
0
        public bool OperationExists(Operatie operation)
        {
            if (operation == null)
            {
                return(false);
            }
            var foundOperation = _applicationContext.Operaties.FirstOrDefault(o => o.OperatieId == operation.OperatieId);

            return(foundOperation != null);
        }
        public void AddOperation(Operatie operation)
        {
            if (operation == null)
            {
                throw new ArgumentException("Operation must not be null.");
            }

            _context.Operatii.Add(operation);
            _context.SaveChanges();
        }
Example #10
0
        public void Create(Operatie operatie)
        {
            if (operatie != null)
            {
                throw new System.ArgumentNullException();
            }

            operatieRepository.Add(operatie);
            operatieRepository.Save();
        }
Example #11
0
 public void AddOperation(Operatie operation)
 {
     if (operation == null)
     {
         return;
     }
     if (OperationExists(operation))
     {
         return;
     }
     _applicationContext.Operaties.Add(operation);
 }
Example #12
0
        public Operatie Add(Operatie operatie)
        {
            if (GetById(operatie.OperatieId) != null)
            {
                return(null);
            }

            db.Operaties.Add(operatie);
            db.SaveChanges();

            return(operatie);
        }
Example #13
0
        public Boolean Delete(int id)
        {
            Operatie operatie = GetById(id);

            if (operatie == null)
            {
                return(false);
            }

            db.Operaties.Remove(operatie);
            db.SaveChanges();
            return(true);
        }
Example #14
0
        public static Operatie FromModelToEntity(OperationModel operationModel)
        {
            Operatie operationEntity = new Operatie();

            if (operationModel != null)
            {
                operationEntity.OperatieId   = operationModel.OperationId;
                operationEntity.Denumire     = operationModel.Name;
                operationEntity.TimpExecutie = operationModel.ExecutionTime;
            }

            return(operationEntity);
        }
Example #15
0
        public void UpdateOperation(Operatie operation)
        {
            if (operation == null)
            {
                return;
            }
            if (OperationExists(operation))
            {
                var clonedOperation = operation;
                OperationsTransformer.MergeOperationEntities(clonedOperation, operation);
            }

            _applicationContext.SaveChanges();
        }
Example #16
0
        public void EvaluateTest()
        {
            // arrange
            string           expresie = "1 ? 2";
            CalculatorParser cp       = new CalculatorParser(expresie);

            Operatie operatie = null;


            /// instructiune switch care foloseste type pattern
            /// valabil doar in C# v7.0 sau mai mare.
            switch (cp.Operatie)
            {
            case Add op:
                operatie = Operatii.Add;
                break;

            case Subtract op:
                operatie = Operatii.Subtract;
                break;

            case Multiply op:
                operatie = Operatii.Multiply;
                break;

            case Divide op:
                operatie = Operatii.Divide;
                break;

            default:
                break;
            }

            if (operatie == null)
            {
                return;
            }
            Calculator3 c3 = new Calculator3(cp.Op1, cp.Op2, operatie);


            // act
            c3.Evaluate();

            int expected = -1;
            int actual   = c3.Value;


            // assert
            Assert.AreEqual(expected, actual);
        }
        static void ExecutaOperatie(Operatie op)
        {
            Console.Write("a = ");
            int a = int.Parse(Console.ReadLine());

            Console.Write("b = ");
            int b = int.Parse(Console.ReadLine());

            foreach (Operatie opindv in op.GetInvocationList())
            {
                int rezultat = op(a, b);
                Console.WriteLine("Rezultatul este: {0}", rezultat);
            }
        }
Example #18
0
        static void Main(string[] args)
        {
            douaNumere no = new douaNumere();

            no.x = 5.213;
            no.y = 8442.121111;
            Operatie plus  = () => { return(no.x + no.y); };
            Operatie minus = () => { return(no.x - no.y); };

            no.Operatie(plus);
            no.Operatie(minus);

            Console.ReadLine();
        }
Example #19
0
        public void Update(Operatie operatie)
        {
            if (operatie == null)
            {
                throw new System.ArgumentNullException();
            }

            var operatieU = operatieRepository.Where(a => a.Id == operatie.Id).FirstOrDefault();

            operatieU.Denumire       = operatie.Denumire == null ? operatieU.Denumire : operatie.Denumire;
            operatieU.DetaliuComanda = operatie.DetaliuComanda == null ? operatieU.DetaliuComanda : operatie.DetaliuComanda;
            operatieU.TimpExecutie   = operatie.TimpExecutie == default(decimal) ? operatieU.TimpExecutie : operatie.TimpExecutie;

            operatieRepository.Save();
        }
Example #20
0
        /// <inheritdoc />
        /// <summary>
        /// Creates the operatie.
        /// </summary>
        /// <param name="operatie">The operatie.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        public bool CreateOperatie(Operatie operatie)
        {
            try
            {
                _operatieWrite = new WriteOperatieRepository(_context);

                _operatieWrite.Create(operatie);
                _context.SaveChanges();
                return(true);
            }
            catch (Exception e)
            {
                var message = DbEntityCustomException.BuildMessageExceptions(e);
                throw new DbEntityCustomException(message);
            }
        }
Example #21
0
        private void buttonUpdateOperation_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dataGridViewDisplayOperations.SelectedRows)
            {
                int      id        = Convert.ToInt32(row.Cells[0].Value);
                Operatie operation = _carService.FindOperationById(id);

                operation.Denumire     = row.Cells[1].Value.ToString();
                operation.TimpExecutie = Convert.ToDecimal(row.Cells[2].Value);

                _carService.UpdateOperation(operation);
            }

            // reload to view changes
            FormDisplayDetails_Load(sender, e);
        }
        static void Main(string[] args)
        {
            Operatie lista = Suma_static;

            lista += Produs_static;

            lista += (i, j) =>
            {
                Console.Write("Diferenta ->");
                return(i - j);
            };

            lista += (i, j) =>
            {
                Console.Write("Restul impartirii ->");
                if (j == 0)
                {
                    Console.Write(" Impartire la 0! ");
                    return(-1);
                }
                else
                {
                    return(i / j);
                }
            };

            Console.WriteLine("\nValori pt x, y: ");
            int x = int.Parse(Console.ReadLine());
            int y = int.Parse(Console.ReadLine());

            foreach (Operatie op_individuala in lista.GetInvocationList())
            {
                int rezultat = op_individuala(x, y);
                Console.WriteLine("Rezultatul obtinut: {0}", rezultat);
            }

            Console.Write("\n\n----------------\n");
            Operatie lista2 = new Operatie(Matematica.Suma_clasa);

            lista2 += new Operatie(Matematica.Produs_clasa);

            foreach (Operatie op_indv2 in lista2.GetInvocationList())
            {
                int rez = op_indv2(x, y);
                Console.WriteLine("Rez: {0}", rez);
            }
        }
Example #23
0
        public void CreateNew(OperatieDto operatieDto)
        {
            if (operatieDto == null)
            {
                throw new ArgumentNullException(nameof(operatieDto));
            }

            var operatie = new Operatie
            {
                Denumire = operatieDto.Denumire,
                //DetaliuComanda = operatieDto.DetaliuComanda,
                TimpExecutie = operatieDto.TimpExecutie
            };

            operatieRepository.Add(operatie);
            unitOfWork.Commit();
        }
        public void UpdateOperation(Operatie operation)
        {
            if (operation == null)
            {
                throw new ArgumentException("Operation must not be null.");
            }

            var toUpdate = _context.Operatii.Find(operation.Id);

            if (toUpdate == null)
            {
                return;
            }

            _context.Entry(toUpdate).CurrentValues.SetValues(operation);
            _context.SaveChanges();
        }
Example #25
0
        private void BuildOperatie()
        {
            DialogResult userResponse;

            var operatie = new Operatie()
            {
                Id           = Guid.NewGuid(),
                Denumire     = _addOperationTextBox.Text,
                TimpExecutie = decimal.Parse(_addTimeTextBox.Text)
            };

            if (!CommonItem.DemoApp)
            {
                do
                {
                    using (var autoApi = new AutoServiceClient())
                    {
                        var response = autoApi.AddOperatie(operatie, _detaliuComanda);
                        if (response)
                        {
                            break;
                        }

                        userResponse = MessageBox.Show(
                            @"Ups.. change could not be done.  Try again ?",
                            @"Something went wrong",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Error);

                        if (userResponse == DialogResult.No)
                        {
                            break;
                        }
                    }
                }while (userResponse == DialogResult.Yes);
            }

            Operations.Add(
                new SelectableViewModel <Operatie>
            {
                Item = new Operatie()
                {
                    Denumire = operatie.Denumire, TimpExecutie = operatie.TimpExecutie
                }
            });
        }
Example #26
0
        public void Update(Operatie operatie1, Operatie operatie2)
        {
            if (operatie1 == null || operatie2 == null)
            {
                return;
            }

            var foundOperatie = Context.Operaties.FirstOrDefault(m => m.OperatieId == operatie1.OperatieId);

            if (foundOperatie != null)
            {
                foundOperatie.Denumire     = operatie2.Denumire;
                foundOperatie.TimpExecutie = operatie2.TimpExecutie;
            }

            Context.Operaties.AddOrUpdate(foundOperatie);
            Context.SaveChanges();
        }
Example #27
0
        public Operatie Update(Operatie operatie)
        {
            if (GetById(operatie.OperatieId) == null)
            {
                return(null);
            }

            Operatie operatie1 = GetById(operatie.OperatieId);

            operatie1.Denumire     = operatie.Denumire;
            operatie1.TimpExecutie = operatie.TimpExecutie;
            operatie1.Mecanic      = operatie.Mecanic;
            operatie1.Materials    = operatie.Materials;


            db.SaveChanges();

            return(operatie);
        }
Example #28
0
        private void UpdateOperationsButton_OnClick(object sender, RoutedEventArgs e)
        {
            IList selectedOperations = OperationsDataGrid.SelectedItems;
            int   operationsSize     = selectedOperations.Count;

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

                Operatie operation = _client.FindOperationById(id);
                operation.Denumire     = row["Denumire"].ToString();
                operation.TimpExecutie = Convert.ToDecimal(row["TimpExecutie"].ToString());

                _client.UpdateOperation(operation);
            }

            OperationsTabItem_OnLoaded(sender, e);
        }
Example #29
0
        private void buttonAddNewOperation_Click(object sender, EventArgs e)
        {
            string name          = textBoxAddOperationName.Text;
            string executionTime = textBoxAddOperationExecutionTime.Text;

            if (!FieldsCompleted(name, executionTime))
            {
                labelAddOperation.Text = @"Must complete mandatory fields.";
            }
            else
            {
                buttonAddNewOperation.Enabled = true;
                Operatie operation = new Operatie()
                {
                    Denumire     = name,
                    TimpExecutie = Convert.ToDecimal(executionTime)
                };

                _carService.AddOperation(operation);

                labelAddOperation.Text    = @"Operation added.";
                labelAddOperation.Visible = true;
            }
        }
Example #30
0
        private bool BuildOperatie()
        {
            var selectedComanda = _listaDetaliuComandas[comenziiListBox.FocusedItem.Index];

            var operatie = new Operatie()
            {
                Denumire     = addOperatieTextBox.Text,
                TimpExecutie = decimal.Parse(timpExecutieTextBox.Text)
            };

            DialogResult userResponse;

            do
            {
                var response = _serviceApi.AddOperatie(operatie, selectedComanda);
                if (response)
                {
                    addOperatieTextBox.Text  = "";
                    timpExecutieTextBox.Text = "";

                    MessageBox.Show($"Operatia \"{operatie.Denumire}\" adaugata comenzii cu numar auto: {selectedComanda.Comanda.Auto.NumarAuto}", @"Succcesful",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                }
                userResponse =
                    MessageBox.Show(@"Ups.. change could not be done.  Try again ?", @"Something went wrong",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                if (userResponse == DialogResult.No)
                {
                    break;
                }
            } while (userResponse == DialogResult.Yes);

            operatiiListView.Items.Add($"{operatie.Denumire} : {operatie.TimpExecutie}");
            return(true);
        }