Exemplo n.º 1
0
        private void InitializeCommand()
        {
            #region CommandBinding : IDEdit
            CommandBinding cbIDEdit = new CommandBinding(cmdIDEdit, (sender, e) =>
            {
                txtProjectID.IsReadOnly  = false;
                bnIDEditOk.IsEnabled     = true;
                bnIDEditCancel.IsEnabled = true;
                bnIDEdit.IsEnabled       = false;
                IsSuspend = true;
            }, (sender, e) => { e.CanExecute = true; e.Handled = true; });
            CommandBinding cbIDEditOk = new CommandBinding(cmdIDEditOk, (sender, e) =>
            {
                if (System.Text.RegularExpressions.Regex.IsMatch(txtProjectID.Text, @"^BIM\d{10}[C|W]$"))
                {
                    Global.UpdateAppConfig("CurrentProjectID", txtProjectID.Text);

                    txtProjectID.IsReadOnly  = true;
                    bnIDEditCancel.IsEnabled = false;
                    bnIDEdit.IsEnabled       = true;
                    bnIDEditOk.IsEnabled     = false;
                    IsSuspend = false;

                    lblApplied.Visibility = Visibility.Collapsed;
                    isModified            = true;
                }
                else
                {
                    txtProjectID.Focus();
                    txtProjectID.SelectAll();
                    return;
                }
            }, (sender, e) => { e.CanExecute = true; e.Handled = true; });
            CommandBinding cbIDEditCancel = new CommandBinding(cmdIDEditCancel, (sender, e) =>
            {
                txtProjectID.IsReadOnly  = true;
                bnIDEditCancel.IsEnabled = false;
                bnIDEdit.IsEnabled       = true;
                bnIDEditOk.IsEnabled     = false;
                IsSuspend = false;
            }, (sender, e) => { e.CanExecute = true; e.Handled = true; });
            #endregion

            #region CommandBinding : PNEdit
            CommandBinding cbPNEdit = new CommandBinding(cmdPNEdit, (sender, e) =>
            {
                txtProjectName.IsReadOnly = false;
                bnPNEditOk.IsEnabled      = true;
                bnPNEditCancel.IsEnabled  = true;
                bnPNEdit.IsEnabled        = false;
                IsSuspend = true;
            }, (sender, e) => { e.CanExecute = true; e.Handled = true; });
            CommandBinding cbPNEditOk = new CommandBinding(cmdPNEditOk, (sender, e) =>
            {
                if (System.Text.RegularExpressions.Regex.IsMatch(txtProjectName.Text, @"^\S.*?\S$"))
                {
                    Global.UpdateAppConfig("CurrentProjectName", txtProjectName.Text);

                    txtProjectName.IsReadOnly = true;
                    bnPNEditCancel.IsEnabled  = false;
                    bnPNEdit.IsEnabled        = true;
                    bnPNEditOk.IsEnabled      = false;
                    IsSuspend = false;

                    lblApplied.Visibility = Visibility.Collapsed;
                    isModified            = true;
                }
                else
                {
                    txtProjectName.Focus();
                    txtProjectName.SelectAll();
                    return;
                }
            }, (sender, e) => { e.CanExecute = true; e.Handled = true; });
            CommandBinding cbPNEditCancel = new CommandBinding(cmdPNEditCancel, (sender, e) =>
            {
                txtProjectName.IsReadOnly = true;
                bnPNEditCancel.IsEnabled  = false;
                bnPNEdit.IsEnabled        = true;
                bnPNEditOk.IsEnabled      = false;
                IsSuspend = false;
            }, (sender, e) => { e.CanExecute = true; e.Handled = true; });
            #endregion

            #region BrowseZoneData
            CommandBinding cbBrowseZoneData = new CommandBinding(cmdBrowseZoneData, (sender, e) =>
            {
                Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog()
                {
                    DefaultExt = "*.zone",
                    Filter     = "Zone Data Files(*.zone)|*.zone|All(*.*)|*.*"
                };
                if (ofd.ShowDialog() == false)
                {
                    return;
                }
                if (Global.GetAppConfig("CurrentProjectID") is null)
                {
                    MessageBox.Show("导入分区数据之前必须先设置当前项目的项目编号。");
                    return;
                }
                var pzfile = ZoneHelper.FnZoneDataSerialize(ofd.FileName);
                listInformation.SelectedIndex = listInformation.Items.Add($"{DateTime.Now:HH:mm:ss} - L: ZONEDATA/{ofd.FileName}.");
                listInformation.SelectedIndex = listInformation.Items.Add($"{DateTime.Now:HH:mm:ss} - S: ZONEDATA/{pzfile}.");
                txtProjectZoneFile.Text       = pzfile;
            }, (sender, e) => { e.CanExecute = true; e.Handled = true; });