示例#1
0
        private void Btn_Save_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (TBox_Name.Text == string.Empty ||
                    TB_OpenFileGame.Text == string.Empty ||
                    TBox_NameProcess.Text == string.Empty ||
                    TB_OpenFileMoution.Text == string.Empty
                    )
                {
                    throw new Exception();
                }

                ModelGame newGame = new ModelGame
                {
                    Name              = TBox_Name.Text,
                    PathIcon          = TB_OpenFileIcon.Text,
                    ItemPath          = TB_OpenFileGame.Text,
                    StartUpParams     = TBox_Params.Text,
                    NameProcess       = TBox_NameProcess.Text,
                    FileMotion        = TB_OpenFileMoution.Text,
                    AdditionalKey     = _additionalKeyPressed,
                    StartTime         = Convert.ToInt32(TBox_TimeShift.Text),
                    MouseClickCordX   = Convert.ToInt32(TB_xMousClick.Text),
                    MouseClickCordY   = Convert.ToInt32(TB_yMousClick.Text),
                    TypeStartFocus    = (TypeStartFocus)CB_TypeStart.SelectedIndex,
                    PathToBannerVideo = TB_OpenFileVideoBanner.Text
                };

                IconType?iconType = null;

                if (RBtn_Image.IsChecked == true)
                {
                    iconType = IconType.Image;
                }
                else if (RBtn_Video.IsChecked == true)
                {
                    iconType = IconType.Video;
                }
                newGame.IconType = (IconType)iconType;

                Key?startUpButtpn = null;

                if (RBEnter.IsChecked == true)
                {
                    startUpButtpn = Key.Enter;
                }
                else if (RBSpace.IsChecked == true)
                {
                    startUpButtpn = Key.Space;
                }
                newGame.RunKey = (Key)startUpButtpn;

                if (TP_TimeOut.SelectedTime != null)
                {
                    DateTime?nowDate = new DateTime(2000, 12, 12, 0, 0, 0);
                    nowDate        += TP_TimeOut.SelectedTime;
                    newGame.TimeOut = nowDate;
                }

                if (TS_ShiftClick.IsChecked.Value)
                {
                    newGame.ShiftPressTime = int.Parse(TB_ShiftClick.Text);
                }
                else
                {
                    newGame.ShiftPressTime = null;
                }


                if (isAddOrEdit)
                {
                    _rep.ChangeGame(_oldGame, newGame);
                }
                else
                {
                    _rep.AddGame(newGame);
                }



                App.Frame.Navigate(new TablesPage(_typeItem));
            }
            catch (FormatException)
            {
                ValidationMessage.Text = "Время в сек.нажатия клавиши Shift или Моусклика введенно некоректно";
            }
            catch (Exception ex)
            {
                ValidationMessage.Text = "Вы не заполнили всех полей!";
            }
        }