예제 #1
0
        public MainWindow()
        {
            Application.Current.DispatcherUnhandledException += DispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException       += CurrentDomainOnUnhandledException;

            try
            {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(Settings.Default.Localization);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Localization error");
            }

            InitializeComponent();

            CreateDeviceColumns();
            KeyPreview();
            Connection = CreateConnection();

            //чтобы скрыть пустые DataGrid сразу после запуска приложения
            DataViewModel vm = new DataViewModel();

            this.DataContext = vm;

            dgDevices.BuildData = BuildData;

            //применяем стили для раскраски DataGrid
            dgRTData.RTStyle();
            dgTMData.TMStyle();
        }
예제 #2
0
        private void BuildData()
        {
            DataRowView row = dgDevices.SelectedItem as DataRowView;

            if (row != null)
            {
                object[] itemArray = row.Row.ItemArray;

                int    selDevID   = DevID(itemArray);
                string selDevType = DeviceType(itemArray);
                TemperatureCondition selTemperatureCondition = TemperatureConditionByProfileName(ProfileName(itemArray));

                string pairProfileName;
                int    pairDevID;
                TemperatureCondition pairTemperatureCondition;

                bool foundedPair = CalcPairData(ProfileName(itemArray), GroupName(itemArray), Code(itemArray), out pairProfileName, out pairDevID, out pairTemperatureCondition);

                DataViewModel vm = null;
                switch (selTemperatureCondition)
                {
                case TemperatureCondition.RT:
                    lbRTProfileName.Content = ProfileName(itemArray);
                    vm = new DataViewModel(selDevID, selDevType, selTemperatureCondition, pairDevID, selDevType, pairTemperatureCondition);
                    lbTMProfileName.Content = foundedPair ? pairProfileName : string.Empty;
                    break;

                case TemperatureCondition.TM:
                    lbTMProfileName.Content = ProfileName(itemArray);
                    vm = new DataViewModel(pairDevID, selDevType, pairTemperatureCondition, selDevID, selDevType, selTemperatureCondition);
                    lbRTProfileName.Content = foundedPair ? pairProfileName : string.Empty;
                    break;

                case TemperatureCondition.None:
                    vm = new DataViewModel();
                    break;
                }

                this.DataContext = vm;

                //вычисляем сколько записей стоит ниже текущей выбранной
                int selectedRowNum = dgDevices.Items.IndexOf(dgDevices.SelectedItem) + 1;
                int bottomRecords  = dgDevices.Items.Count - selectedRowNum;
                lbBottomRecordCount.Content = string.Format("({0})", bottomRecords.ToString());
            }
        }