private void __pView_AddNewSensor(object sender, EventArgs e)
        {
            AddEditSensorDialog pDialog = new AddEditSensorDialog();

            pDialog.SetData(null, __pParamModels.ToList());

            bool?bResult = pDialog.ShowDialog();

            if (bResult.HasValue && bResult.Value)
            {
                try {
                    FullSensorViewModel pData = pDialog.Data;
                    Sensor pSensor            = new Sensor(pData.MaterialNumber, pData.Name, pData.TestParam == null ? null : (long?)pData.TestParam.ID);
                    //bool bSuccess =__pServiceProxy.AddSensor(pSensor);
                    __pServiceProxy.AddSensor(pSensor);

                    if (true)
                    {
                        __pSensorModels.Add(pData);
                    }
                }
                catch (Exception ex) {
                    //todo: Add logging
                }
            }
        }
        private void btn_Accept_Click(object sender, RoutedEventArgs e)
        {
            string sMessage = string.Empty;

            Data = null;

            if (ssc_NewSensor.ValidateInput(out sMessage))
            {
                if (ckb_AddTestParameter.IsChecked.HasValue && ckb_AddTestParameter.IsChecked.Value && lst_TestParams.SelectedItem == null)
                {
                    sMessage += string.Format("{0} No Test selected", string.IsNullOrWhiteSpace(sMessage) ? string.Empty : sMessage + " | ");
                }
                else
                {
                    FullSensorViewModel pSensorData = ssc_NewSensor.GetData();

                    if (ckb_AddTestParameter.IsChecked.HasValue && ckb_AddTestParameter.IsChecked.Value)
                    {
                        pSensorData.TestParam = tpc_TestParam.GetData();
                    }

                    Data = pSensorData;

                    DialogResult = true;
                }
            }
        }
        private void __pView_EditSensor(object sender, SensorArgs e)
        {
            AddEditSensorDialog pDialog = new AddEditSensorDialog();

            pDialog.SetData(e.Sensor, __pParamModels.ToList());

            bool?bResult = pDialog.ShowDialog();

            if (bResult.HasValue && bResult.Value)
            {
                FullSensorViewModel pData = pDialog.Data;
                Sensor pSensor            = new Sensor(pData.MaterialNumber, pData.Name, pData.TestParam == null ? null : (long?)pData.TestParam.ID);

                bool bSuccess = __pServiceProxy.UpdateSensor(pSensor);

                if (bSuccess)
                {
                    FullSensorViewModel pListSensor = __pSensorModels.FirstOrDefault(p => p.MaterialNumber == e.Sensor.MaterialNumber);
                    if (pListSensor != null)
                    {
                        //This sucks, must be a better way to do this
                        List <FullSensorViewModel> pNewSensorList = __pSensorModels.Except(new List <FullSensorViewModel> {
                            pListSensor
                        }).ToList();
                        pNewSensorList.Add(pData);
                        __pSensorModels = new ObservableCollection <FullSensorViewModel>(pNewSensorList.OrderBy(p => p.MaterialNumber));
                        __pView.LoadSensorsPageData(__pSensorModels);
                    }
                }
            }
        }
        private void lst_Sensors_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                FullSensorViewModel pSensor = e.AddedItems[0] as FullSensorViewModel;

                ssc_Sensor.SetData(pSensor);
                if (pSensor != null && pSensor.TestParam != null)
                {
                    tpc_TestParams.SetData(new TestParameterViewModel(pSensor.TestParam));
                }
                else
                {
                    tpc_TestParams.SetData(null);
                }
            }
        }
        private void btn_EditSensor_Click(object sender, RoutedEventArgs e)
        {
            FullSensorViewModel pCurrentSelection = lst_Sensors.SelectedItem as FullSensorViewModel;

            if (pCurrentSelection == null)
            {
                MessageBox.Show("Please select a Sensor from the list for editing", "No selection", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                if (EditSensor != null)
                {
                    EditSensor(this, new SensorArgs {
                        Sensor = pCurrentSelection
                    });
                }
            }
        }
        public void SetData(FullSensorViewModel pSensorModel, List <TestParameterViewModel> pTestParams)
        {
            if (pSensorModel == null)
            {
                btn_Accept.Content = "Add";
                Title = "Add new Sensor";
                ssc_NewSensor.ReadOnly = false;
            }
            else
            {
                btn_Accept.Content = "Save";
                Title = "Edit Sensor";
                ssc_NewSensor.ReadOnly = true;
            }

            ssc_NewSensor.SetData(pSensorModel);

            TestParams = pTestParams;

            if (pSensorModel != null && pSensorModel.TestParam != null)
            {
                TestParameterViewModel pFittingParam = TestParams.FirstOrDefault(p => p.ID == pSensorModel.TestParam.ID);

                if (pFittingParam != null)
                {
                    ckb_AddTestParameter.IsChecked = true;
                    lst_TestParams.SelectedItem    = pFittingParam;
                }
                else
                {
                    tpc_TestParam.SetData(new TestParameterViewModel(pSensorModel.TestParam));
                    ckb_AddTestParameter.IsChecked = false;
                }
            }
            else
            {
                tpc_TestParam.SetData(null);
            }
        }
示例#7
0
 public void Update(FullSensorViewModel pFrom)
 {
     MaterialNumber = pFrom.MaterialNumber;
     Name           = pFrom.Name;
     TestParam      = pFrom.TestParam;
 }