Ejemplo n.º 1
0
            /// <summary>
            /// Очистить содержание представления (например, перед )
            /// </summary>
            public override void ClearValues()
            {
                CellValueChanged -= onCellValueChanged;

                foreach (DataGridViewRow r in Rows)
                {
                    foreach (DataGridViewCell c in r.Cells)
                    {
                        if (((TepCommon.HandlerDbTaskCalculate.TECComponent)Columns[r.Cells.IndexOf(c)].Tag).m_Id > 0)
                        {
                            // только для реальных компонетов - нельзя удалять идентификатор параметра
                            c.Value           = string.Empty;
                            c.Style.BackColor = s_arCellColors[(int)INDEX_COLOR.EMPTY];
                        }
                        else
                        {
                            ;
                        }
                    }
                }
                //??? если установить 'true' - редактирование невозможно
                ReadOnly = false;

                CellValueChanged += new DataGridViewCellEventHandler(onCellValueChanged);
            }
Ejemplo n.º 2
0
        public MainForm()
        {
            m_usb      = new HIDDevice();
            m_cmds     = new List <Command>();
            m_connList = new List <HIDInfoSet>();

            try
            {
                m_settings = LoadFromFile(typeof(AppSettings), m_confName) as AppSettings;
            }
            catch
            {
                m_settings = new AppSettings();
            }

            InitializeComponent();

            m_usb.OnDeviceRemoved += usb_OnDeviceRemoved;
            m_usb.OnDeviceArrived += usb_OnDeviceArrived;
            m_usb.OnDataRecieved  += usb_OnDataReceived;

            LogDataGridView.Enabled       = false;
            EditToolStripButton.Enabled   = false;
            RemoveToolStripButton.Enabled = false;
            SaveToolStripButton.Enabled   = false;

            m_tclk = new DataGridViewCellEventHandler(TxDataGridView_CellClick);
        }
        public void LoadCheckBox()
        {
            bool designMode = (LicenseManager.UsageMode == LicenseUsageMode.Designtime);

            if (designMode)
            {
                return;
            }

            DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();

            checkBoxColumn.HeaderText = "";
            checkBoxColumn.Width      = 30;
            checkBoxColumn.Name       = COLUMN_NAME_CHECKBOX;
            Columns.Insert(0, checkBoxColumn);

            _headerCheckBox.BackColor = Color.White;
            _headerCheckBox.Size      = new Size(18, 18);

            var headerCell = GetCellDisplayRectangle(0, -1, false);
            int x          = Math.Abs((checkBoxColumn.Width / 2) - (_headerCheckBox.Width / 2)) + 4;
            int y          = Math.Abs((headerCell.Height / 2) - (_headerCheckBox.Height / 2)) + 2;

            _headerCheckBox.Location = new Point(x, y);
            _headerCheckBox.Click   += new EventHandler(HeaderCheckBox_Clicked);
            Controls.Add(_headerCheckBox);

            CellContentClick += new DataGridViewCellEventHandler(DataGridView_CellClick);
        }
Ejemplo n.º 4
0
        //#region Properties

        //public FormDataEntryLogic DataEntryController { get; set; }

        //public bool ViewLoading { get { return _viewLoading; } }

        //public ICollection<Tree> Trees
        //{
        //    get
        //    {
        //        return DataService.NonPlotTrees;
        //    }
        //}

        //#region DataService

        //IDataEntryDataService _dataService;

        //IDataEntryDataService DataService
        //{
        //    get { return _dataService; }
        //    set
        //    {
        //        OnDataServiceChanging();
        //        _dataService = value;
        //        OnDataServiceChanged();
        //    }
        //}

        //void OnDataServiceChanged()
        //{
        //    if (_dataService != null)
        //    {
        //        _dataService.EnableLogGradingChanged += HandleEnableLogGradingChanged;
        //    }
        //}

        //void OnDataServiceChanging()
        //{
        //    if (_dataService != null)
        //    {
        //        _dataService.EnableLogGradingChanged -= HandleEnableLogGradingChanged;
        //    }
        //}

        //void HandleEnableLogGradingChanged(object sender, EventArgs e)
        //{
        //    if (_logsColumn != null)
        //    {
        //        var logGradingEnabled = DataService.EnableLogGrading;
        //        _logsColumn.Visible = logGradingEnabled;

        //        _logToolStripMenuItem.Text = logGradingEnabled ?
        //        "Disable Log Grading" : "Enable Log Grading";
        //    }
        //}

        //#endregion DataService

        //#region AppSettings

        //private ApplicationSettings _appSettings;

        //public ApplicationSettings AppSettings
        //{
        //    get { return _appSettings; }
        //    set
        //    {
        //        OnAppSettingsChanging();
        //        _appSettings = value;
        //        OnAppSettingsChanged();
        //    }
        //}

        //private void OnAppSettingsChanging()
        //{
        //    if (_appSettings != null)
        //    {
        //        _appSettings.CruisersChanged -= Settings_CruisersChanged;
        //    }
        //}

        //private void OnAppSettingsChanged()
        //{
        //    if (_appSettings != null)
        //    {
        //        _appSettings.CruisersChanged += Settings_CruisersChanged;
        //    }
        //}

        //#endregion AppSettings

        //#endregion Properties

        ControlTreeDataGrid()
        {
            UpdatePageText();

            EditMode              = DataGridViewEditMode.EditOnEnter;
            AutoGenerateColumns   = false;
            AllowUserToDeleteRows = false;
            AllowUserToAddRows    = false;

            CellClick += new DataGridViewCellEventHandler(ControlTreeDataGrid_CellClick);

            _BS_trees = new BindingSource();
            ((System.ComponentModel.ISupportInitialize)_BS_trees).BeginInit();
            _BS_trees.DataSource = typeof(Tree);
            DataSource           = _BS_trees;
            ((System.ComponentModel.ISupportInitialize)_BS_trees).EndInit();

            ColumnHeaderMouseClick += new DataGridViewCellMouseEventHandler(ControlTreeDataGrid_ColumnHeaderMouseClick);

            _logToolStripMenuItem        = new ToolStripMenuItem();
            _logToolStripMenuItem.Name   = "logToolStripMenuItem";
            _logToolStripMenuItem.Size   = new System.Drawing.Size(180, 22);
            _logToolStripMenuItem.Click += logToolStripMenuItem_Click;

            _contexMenu = new ContextMenuStrip(new System.ComponentModel.Container());
            _contexMenu.SuspendLayout();
            _contexMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { _logToolStripMenuItem });
            _contexMenu.Name = "_contexMenu";
            _contexMenu.Size = new System.Drawing.Size(181, 26);

            _contexMenu.ResumeLayout(false);
        }
Ejemplo n.º 5
0
        public TicTacToeGUI()
        {
            InitializeComponent();
            CenterToParent();
            //BringToFront();
            Width = 150;
            Height = 150;

            for (int i = 0; i < 3; i++)
            {
                DataGridViewColumn c = new DataGridViewTextBoxColumn();
                c.Name = "" + i;
                c.HeaderText = "" + i;
                c.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                c.FillWeight = 33;
                grid.Columns.Add(c);
            }
            for (int i = 0; i < 3; i++)
            {
                grid.Rows.Add("");
                grid.Rows[i].HeaderCell.Value = "" + i;
            }

            gridClicker = new DataGridViewCellEventHandler(grid_Click);

        }
Ejemplo n.º 6
0
        public SpreadsheetView()
            : base()
        {
            SpreadsheetModel = new SpreadsheetModel(new CellCollection());            
            Dock = DockStyle.Fill;
            CellMouseDoubleClick += new DataGridViewCellMouseEventHandler(SpreadsheetView_CellMouseDoubleClick);
            CellMouseClick += new DataGridViewCellMouseEventHandler(SpreadsheetView_CellMouseClick);
            RowHeaderMouseClick += new DataGridViewCellMouseEventHandler(SpreadsheetView_RowHeaderMouseClick);
            RowHeightChanged += new DataGridViewRowEventHandler(SpreadsheetView_RowHeightChanged);
            ColumnWidthChanged += new DataGridViewColumnEventHandler(SpreadsheetView_ColumnWidthChanged);
            KeyDown += new KeyEventHandler(SpreadsheetView_KeyDown);
            KeyUp += new KeyEventHandler(SpreadsheetView_KeyUp);
            ParentChanged += delegate
            {
                Columns.Clear();

                for (int k = 0; k < ColumnCount; k++)
                {
                    Columns.Add(MakeColumnLabel(k), MakeColumnLabel(k));
                    Columns[k].SortMode = DataGridViewColumnSortMode.NotSortable;
                }

                Rows.Add(RowCount);

                AllowUserToOrderColumns = false;
                SelectionMode = DataGridViewSelectionMode.ColumnHeaderSelect;
            };

            CellEndEdit += new DataGridViewCellEventHandler(SpreadsheetView_CellEndEdit);
            CellBeginEdit += new DataGridViewCellCancelEventHandler(SpreadsheetView_CellBeginEdit);
            RowsRemoved += new DataGridViewRowsRemovedEventHandler(SpreadsheetView_RowsRemoved);

            this.DefaultCellStyle.Font = new Font("Times", 12);
        }
Ejemplo n.º 7
0
        public TicTacToeGUI()
        {
            InitializeComponent();
            CenterToParent();
            //BringToFront();
            Width  = 150;
            Height = 150;

            for (int i = 0; i < 3; i++)
            {
                DataGridViewColumn c = new DataGridViewTextBoxColumn();
                c.Name         = "" + i;
                c.HeaderText   = "" + i;
                c.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                c.FillWeight   = 33;
                grid.Columns.Add(c);
            }
            for (int i = 0; i < 3; i++)
            {
                grid.Rows.Add("");
                grid.Rows[i].HeaderCell.Value = "" + i;
            }

            gridClicker = new DataGridViewCellEventHandler(grid_Click);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed.
        /// <example>
        /// datagridviewcelleventhandler.BeginInvoke(sender, e, callback);
        /// </example>
        /// </summary>
        public static IAsyncResult BeginInvoke(this DataGridViewCellEventHandler datagridviewcelleventhandler, Object sender, DataGridViewCellEventArgs e, AsyncCallback callback)
        {
            if (datagridviewcelleventhandler == null)
            {
                throw new ArgumentNullException("datagridviewcelleventhandler");
            }

            return(datagridviewcelleventhandler.BeginInvoke(sender, e, callback, null));
        }
Ejemplo n.º 9
0
        protected virtual void OnCellDoubleClick(DataGridViewCellEventArgs e)
        {
            DataGridViewCellEventHandler handler = CellDoubleClick;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Ejemplo n.º 10
0
        public MusicInjector()
        {
            /*Text = "Music Injector";
             * Icon = Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetExecutingAssembly().Location);
             * Visible = false;
             * Width = 720;
             * Height = 540;
             * CenterToScreen();*/

            CellClick += new DataGridViewCellEventHandler(TableCellClicked);

            Columns.Add("name", "Name");
            Columns.Add("filename", "Filename");

            // Create Extract button column
            DataGridViewButtonColumn play_col = new DataGridViewButtonColumn();

            play_col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            play_col.HeaderText   = "Play";
            play_col.Text         = "Play";
            play_col.Name         = "play";
            play_col.UseColumnTextForButtonValue = true;
            Columns.Add(play_col);

            // Create Extract button column
            DataGridViewButtonColumn extract_col = new DataGridViewButtonColumn();

            extract_col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            extract_col.HeaderText   = "Extract";
            extract_col.Text         = "Extract";
            extract_col.Name         = "extract";
            extract_col.UseColumnTextForButtonValue = true;
            Columns.Add(extract_col);

            // Create Replace button column
            DataGridViewButtonColumn replace_col = new DataGridViewButtonColumn();

            replace_col.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            replace_col.HeaderText   = "Replace";
            replace_col.Text         = "Replace";
            replace_col.Name         = "replace";
            replace_col.UseColumnTextForButtonValue = true;
            Columns.Add(replace_col);

            foreach (DataGridViewColumn col in Columns)
            {
                col.SortMode = DataGridViewColumnSortMode.NotSortable;
            }

            Dock = DockStyle.Fill;

            ReadOnly              = true;
            RowHeadersVisible     = false;
            AutoSizeColumnsMode   = DataGridViewAutoSizeColumnsMode.Fill;
            AllowUserToResizeRows = false;
        }
Ejemplo n.º 11
0
 protected override void OnCellValueChanged(DataGridViewCellEventArgs e)
 {
     switch (e.ColumnIndex)
     {
     case DataGridViewMarketStatics.Column_Value:
         DataGridViewCellEventHandler handler = ValueChanged;
         handler?.Invoke(this, e);
         break;
     }
 }
Ejemplo n.º 12
0
 public ZSummaryGridView()
 {
     ShowSummary         = true;
     RowsAdded          += new DataGridViewRowsAddedEventHandler(SummaryGridView_RowsAdded);
     RowsRemoved        += new DataGridViewRowsRemovedEventHandler(SummaryGridView_RowsRemoved);
     ColumnWidthChanged += new DataGridViewColumnEventHandler(SummaryGridView_ColumnWidthChanged);
     CellValueChanged   += new DataGridViewCellEventHandler(SummaryGridView_CellValueChanged);
     ColumnStateChanged += new DataGridViewColumnStateChangedEventHandler(SummaryGridView_ColumnStateChanged);
     MouseClick         += new MouseEventHandler(SummaryGridView_MouseClick);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Конструктор - основной (без параметров)
 /// </summary>
 public DataGridViewTaskTepValues()
     : base()
 {
     //Разместить ячейки, установить свойства объекта
     InitializeComponents();
     //Назначить (внутренний) обработчик события - изменение значения ячейки
     // для дальнейшей ретрансляции родительскому объекту
     CellValueChanged += new DataGridViewCellEventHandler(onCellValueChanged);
     //RowsRemoved += new DataGridViewRowsRemovedEventHandler (onRowsRemoved);
 }
Ejemplo n.º 14
0
 public static bool DataGridViewPaste(DataGridView dgv, DataGridViewCellEventHandler dgv_CellValueChanged)
 {
     //粘贴赋值
     dgv.CellValueChanged -= dgv_CellValueChanged;
     //string errMessage = MyMethod.PasterToDataGridView(dgv, dgv.AllowUserToAddRows, ref rowsCount, ref columnsCount);
     //string errMessage = MyMethod.PasterToDataGridView(dgv, false, ref rowsCount, ref columnsCount);
     DataGridViewBehaviors.PasterToDataGridView(dgv, true);
     //再绑定单元格值改变事件
     dgv.CellValueChanged += dgv_CellValueChanged;
     return(true);
 }
Ejemplo n.º 15
0
 private void setUpHandlers()
 {
     DefaultValuesNeeded   += new DataGridViewRowEventHandler(FormattedGridView_DefaultValuesNeeded);
     CellValidating        += new DataGridViewCellValidatingEventHandler(FormattedGridView_CellValidating);
     this.RowEnter         += new DataGridViewCellEventHandler(FormattedGridView_RowEnter);
     this.CausesValidation  = true;
     UserAddedRow          += new DataGridViewRowEventHandler(displayArrayGrid_DoubleClick2);
     CellEnter             += new DataGridViewCellEventHandler(FormattedGridView_CellEnter);
     CellFormatting        += new DataGridViewCellFormattingEventHandler(FormattedGridView_CellFormatting);
     EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(FormattedGridView_EditingControlShowing);
     this.RowsRemoved      += new DataGridViewRowsRemovedEventHandler(FormattedGridView_RowsRemoved);
     CellBeginEdit         += new DataGridViewCellCancelEventHandler(FormattedGridView_CellBeginEdit);
 }
Ejemplo n.º 16
0
        /// <summary>
        /// セルクリック時に_testColの値を表示する
        /// </summary>
        /// <param name="grid">グリッド</param>
        static void CellContentClickEvent(DataGridView grid)
        {
            DataGridViewCellEventHandler handler = null;

            handler = delegate(object sender, DataGridViewCellEventArgs e)
            {
                _testCol = e.ColumnIndex;
                grid.BeginInvoke((MethodInvoker) delegate
                {
                    grid.CellContentClick -= handler;
                });
            };
            grid.CellContentClick += handler;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 編集終了時にメッセージボックスを表示する
        /// </summary>
        /// <param name="grid">グリッド</param>
        static void CellEndEditEvent(DataGridView grid)
        {
            DataGridViewCellEventHandler handler = null;

            handler = delegate
            {
                MessageBox.Show("");
                grid.BeginInvoke((MethodInvoker) delegate
                {
                    grid.CellEndEdit -= handler;
                });
            };
            grid.CellEndEdit += handler;
        }
        // create a datagridview into a panel
        private void loadDatagrid(ref DataGridView dgv, ref BindingSource bs, ref Panel panel,
                                  ref List <ProfileViewData> lp, DataGridViewCellEventHandler cellMouseClick)
        {
            bs.DataSource = lp;
            // Initialize the DataGridView.
            dgv.AutoGenerateColumns      = false;
            dgv.AllowUserToResizeRows    = false;
            dgv.AllowUserToResizeColumns = false;
            dgv.AllowUserToResizeColumns = false;
            dgv.AllowUserToAddRows       = false;
            dgv.ColumnHeadersVisible     = false;
            dgv.AutoSize   = true;
            dgv.DataSource = bs;
            dgv.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
            dgv.RowHeadersVisible       = false;
            dgv.CellContentClick       += new DataGridViewCellEventHandler(cellMouseClick);
            dgv.AutoSizeRowsMode        = DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders;
            dgv.GridColor       = SystemColors.Control;
            dgv.BorderStyle     = BorderStyle.None;
            dgv.BackgroundColor = SystemColors.Control;

            // Initialize and add a check box column.
            DataGridViewColumn column = new DataGridViewTextBoxColumn();

            column = new DataGridViewCheckBoxColumn();
            column.DataPropertyName = "isChecked";
            column.Name             = "isProfileChecked";
            column.Width            = 40;
            dgv.Columns.Add(column);

            // Initialize and add a text box column.
            column = new DataGridViewTextBoxColumn();
            column = new DataGridViewTextBoxColumn();
            column.DataPropertyName = "name";
            column.Name             = "NAME";
            column.AutoSizeMode     = DataGridViewAutoSizeColumnMode.Fill;
            column.ReadOnly         = true;
            dgv.Columns.Add(column);

            // Initialize the DataGridView.
            dgv.AutoGenerateColumns = false;
            dgv.ScrollBars          = ScrollBars.Both;
            dgv.AutoSize            = true;

            panel.Controls.Add(dgv);
            this.AutoSize = true;
            dgv.Update();
            dgv.Refresh();
        }
Ejemplo n.º 19
0
        }   // End event

        /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         *  Event:       SS_CellPropertyChanged                              *
         *  Input:       object, PropertyChangedEventArgs                    *
         *  Output:      void                                                *
         *  Description: An event that triggers when a Cell property is      *
         *               changed.                                            *
         * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
        private void OnCellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewCellEventHandler handler = OnCellEndEdit;

            if (handler != null)
            {
                ss.getCell(infoDataGridView.CurrentCell.RowIndex,
                           infoDataGridView.CurrentCell.ColumnIndex).Text =
                    infoDataGridView.CurrentCell.Value.ToString();

                infoDataGridView.CurrentCell.Value =
                    ss.getCell(infoDataGridView.CurrentCell.RowIndex,
                               infoDataGridView.CurrentCell.ColumnIndex).Value;
            }
        }   // End event
 public ucCheckBoxGridView()
 {
     AddHeaderCheckBox();
     HeaderCheckBox.KeyUp += new KeyEventHandler(HeaderCheckBox_KeyUp);
     HeaderCheckBox.MouseClick += new MouseEventHandler(HeaderCheckBox_MouseClick);
     CellValueChanged += new DataGridViewCellEventHandler(dataGridView_CellValueChanged);
     CurrentCellDirtyStateChanged += new EventHandler(dataGridView_CurrentCellDirtyStateChanged);
     CellPainting += new DataGridViewCellPaintingEventHandler(dataGridView_CellPainting);
     CellBeginEdit += new DataGridViewCellCancelEventHandler(dataGridView_CellBeginEdit);
     DataBindingComplete += new DataGridViewBindingCompleteEventHandler(dataGridView_DataBindingComplete);
     CheckBoxCollumn = new DataGridViewCheckBoxColumn();
     CheckBoxCollumn.Name = CheckBoxCollumnName;
     CheckBoxCollumn.HeaderText = "";
     Columns.Add(CheckBoxCollumn);
     AllowUserToAddRows = false;
 }
Ejemplo n.º 21
0
        public void SubmitCellChange()
        {
            OnRowLeave(new DataGridViewCellEventArgs(SelectedCells[0].ColumnIndex, SelectedCells[0].RowIndex));
            OnRowEnter(null);
            DataGridViewCellEventHandler handler = new DataGridViewCellEventHandler((sender, e) => { });

            handler = (sender, e) =>
            {
                if (SubmitCellChange_Completed != null)
                {
                    this.Submit_Completed -= handler;
                    SubmitCellChange_Completed(this, null);
                }
            };
            this.Submit_Completed += handler;
        }
Ejemplo n.º 22
0
 public static bool DataGridViewPaste(DataGridView dgv, DataGridViewCellEventHandler dgv_CellValueChanged, out int rowsCount, out int columnsCount)
 {
     rowsCount = columnsCount = 0;
     //粘贴赋值
     dgv.CellValueChanged -= dgv_CellValueChanged;
     //string errMessage = MyMethod.PasterToDataGridView(dgv, dgv.AllowUserToAddRows, ref rowsCount, ref columnsCount);
     //string errMessage = MyMethod.PasterToDataGridView(dgv, false, ref rowsCount, ref columnsCount);
     MyMethod.PasterToDataGridView(dgv, true);
     //再绑定单元格值改变事件
     dgv.CellValueChanged += dgv_CellValueChanged;
     if (string.IsNullOrEmpty(errMessage) == false)
     {
         WinPublicMethods.WarnMessageBox(errMessage);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 23
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventHandler e)
        {
            Order order = (Order)dataGridView1.CurrentRow.DataBoundItem;

            selectedOrderID = order.ID;

            decimal.TryParse(MatCostLbl.Text.ToString(), out decimal cost);
            decimal.TryParse(OrderPriceLbl.Text.ToString(), out decimal quant);
            decimal revenue = cost * quant;

            RevenueLbl.Text = revenue.ToString();

            RevenueLbl.Refresh();

            dataGridView2.DataSource = DataLib.GetOrderDetails(selectedOrderID);
            dataGridView2.Refresh();
        }
Ejemplo n.º 24
0
        private void InitializeApp()
        {
            m_usb = new HIDDevice();
            m_usb.OnDeviceRemoved += usb_OnDeviceRemoved;
            m_usb.OnDeviceArrived += usb_OnDeviceArrived;
            m_usb.OnDataRecieved  += usb_OnDataReceived;

            m_connList = new List <HIDInfoSet>();
            m_cmds     = new List <Command>();

            m_settings = new AppSettings();

            ScanConnection();

            LogDataGridView.Enabled       = false;
            EditToolStripButton.Enabled   = false;
            RemoveToolStripButton.Enabled = false;
            SaveToolStripButton.Enabled   = false;
            m_tclk = new DataGridViewCellEventHandler(TxDataGridView_CellClick);
        }
Ejemplo n.º 25
0
        private void Initialize()
        {
            grdFiles.DataSource = Project.Files;

            SetTagsComboDatasource();

            var defaultTag = new Tag();

            colTag.ValueMember   = nameof(defaultTag.Name);
            colTag.DisplayMember = nameof(defaultTag.Name);

            _selectedFileChangedObservable = Observable
                                             .FromEvent <DataGridViewCellEventHandler, DataGridViewCellEventArgs>(
                genericGridHandler =>
            {
                DataGridViewCellEventHandler specificHandler = (sender, e) => { genericGridHandler(e); };
                return(specificHandler);
            },
                handler => grdFiles.CellEnter += handler,
                handler => grdFiles.CellEnter -= handler)
                                             .Select(GetMusicFileFromGridCell)
                                             .Where(musicFile => musicFile != null);

            _newTagAddedObservable =
                Observable.FromEventPattern(ev => btnAddTag.Click += ev, ev => btnAddTag.Click -= ev)
                .Select(e => CreateTag())
                .Where(tag => tag != null);

            var tagsLoader = _selectedFileChangedObservable.Subscribe(GetTagsForFile);

            _disposables.Add(tagsLoader);

            var linkingFiles = _selectedFileChangedObservable.Subscribe(GetLinkingFiles);

            _disposables.Add(linkingFiles);

            var updateTags = _newTagAddedObservable.Subscribe(UpdateProjectTags);

            _disposables.Add(updateTags);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Constructor
        /// </summary>
        public EnhancedGrid()
        {
            InitializeComponent();
            CellDoubleClick       += new DataGridViewCellEventHandler(OnCellDoubleClick);
            CellClick             += new DataGridViewCellEventHandler(OnCellClick);
            CellValidating        += new DataGridViewCellValidatingEventHandler(OnCellValidating);
            DataError             += new DataGridViewDataErrorEventHandler(OnDataError);
            EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(OnEditingControlShowing);
            RowHeadersVisible      = false;

            // Populate the context menu.
            ToolStripMenuItem CopyItem = (ToolStripMenuItem)PopupMenu.Items.Add("Copy");

            CopyItem.ShortcutKeys = Keys.Control | Keys.C;
            CopyItem.Click       += new EventHandler(OnCopy);

            ToolStripMenuItem PasteItem = (ToolStripMenuItem)PopupMenu.Items.Add("Paste");

            PasteItem.ShortcutKeys = Keys.Control | Keys.V;
            PasteItem.Click       += new EventHandler(OnPaste);

            ToolStripMenuItem DeleteItem = (ToolStripMenuItem)PopupMenu.Items.Add("Delete");

            DeleteItem.ShortcutKeys = Keys.Delete;
            DeleteItem.Click       += new EventHandler(OnDelete);

            PopupMenu.Items.Add(new ToolStripSeparator());

            ToolStripMenuItem MoveDownItem = (ToolStripMenuItem)PopupMenu.Items.Add("Move down");

            MoveDownItem.ShortcutKeys = Keys.Control | Keys.Down;
            MoveDownItem.Click       += new EventHandler(OnMoveDown);

            ToolStripMenuItem MoveUpItem = (ToolStripMenuItem)PopupMenu.Items.Add("Move up");

            MoveUpItem.ShortcutKeys = Keys.Control | Keys.Up;
            MoveUpItem.Click       += new EventHandler(OnMoveUp);
            ContextMenuStrip        = PopupMenu;
        }
Ejemplo n.º 27
0
        public static void DataGridViewCut(DataGridView dgv, DataGridViewCellEventHandler dgv_CellValueChanged)
        {
            if (dgv_CellValueChanged != null)
            {
                dgv.CellValueChanged -= dgv_CellValueChanged;
            }
            MyMethod.CopyFromDataGridView(dgv);
            foreach (DataGridViewCell item in dgv.SelectedCells)
            {
                if (dgv.Columns[item.ColumnIndex].ReadOnly)
                {
                    continue;
                }

                item.Value = DBNull.Value;
            }
            //再绑定单元格值改变事件
            if (dgv_CellValueChanged != null)
            {
                dgv.CellValueChanged += dgv_CellValueChanged;
            }
        }
Ejemplo n.º 28
0
 public void AdicioneEvent(DataGridViewCellEventHandler eventoDeSelecao)
 {
     dgv.CellDoubleClick += eventoDeSelecao;
 }
Ejemplo n.º 29
0
 public void dataMember_CellContentClick(DataGridViewCellEventHandler e)
 {
     this.dataMember.CellClick += e;
 }
        public ControlTreeDataGrid(IApplicationController controller, FormDataEntryLogic dataEntryController)
        {
            EditMode = DataGridViewEditMode.EditOnEnter;
            AutoGenerateColumns = false;
            AllowUserToDeleteRows = false;
            AllowUserToAddRows = false;
            Controller = controller;
            DataEntryController = dataEntryController;

            CellClick += new DataGridViewCellEventHandler(ControlTreeDataGrid_CellClick);

            _BS_trees = new BindingSource();
            ((System.ComponentModel.ISupportInitialize)_BS_trees).BeginInit();
            _BS_trees.DataSource = typeof(TreeVM);
            DataSource = _BS_trees;
            ((System.ComponentModel.ISupportInitialize)_BS_trees).EndInit();

            //_BS_TreeSpecies = new BindingSource();
            //((System.ComponentModel.ISupportInitialize)_BS_TreeSpecies).BeginInit();
            //_BS_TreeSpecies.DataSource = typeof(TreeDefaultValueDO);
            //((System.ComponentModel.ISupportInitialize)_BS_TreeSpecies).EndInit();

            //_BS_TreeSampleGroups = new BindingSource();
            //((System.ComponentModel.ISupportInitialize)_BS_TreeSampleGroups).BeginInit();
            //_BS_TreeSampleGroups.DataSource = typeof(SampleGroupDO);
            //((System.ComponentModel.ISupportInitialize)_BS_TreeSampleGroups).EndInit();

            var columns = DataEntryController.Unit.MakeTreeColumns();
            base.Columns.AddRange(columns.ToArray());

            _speciesColumn = base.Columns["TreeDefaultValue"] as DataGridViewComboBoxColumn;
            _sgColumn = base.Columns["SampleGroup"] as DataGridViewComboBoxColumn;
            _stratumColumn = base.Columns["Stratum"] as DataGridViewComboBoxColumn;
            _treeNumberColumn = base.Columns["TreeNumber"] as DataGridViewTextBoxColumn;
            _initialsColoumn = base.Columns["Initials"] as DataGridViewComboBoxColumn;
            _errorMessageColumn = base.Columns["Error"] as DataGridViewTextBoxColumn;
            _logsColumn = base.Columns["Logs"] as DataGridViewButtonColumn;

            if (_speciesColumn != null)
            {
                _speciesColumn.DataSource = Controller._cDal.From<TreeDefaultValueDO>().Read().ToList();
            }
            if (_sgColumn != null)
            {
                _sgColumn.DataSource = DataEntryController.Unit.TreeSampleGroups.ToList();
            }
            if (_stratumColumn != null)
            {
                _stratumColumn.DataSource = DataEntryController.Unit.TreeStrata;
            }
            if (_initialsColoumn != null)
            {
                _initialsColoumn.DataSource = Controller.Settings.Cruisers.ToArray();
            }
            if (_logsColumn != null)
            {
                _logsColumn.Visible = Controller.ViewController.EnableLogGrading;
            }

            _contexMenu = new ContextMenuStrip(new System.ComponentModel.Container());
            logToolStripMenuItem = new ToolStripMenuItem();
            _contexMenu.SuspendLayout();

            this.ColumnHeaderMouseClick += new DataGridViewCellMouseEventHandler(ControlTreeDataGrid_ColumnHeaderMouseClick);

            _contexMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { logToolStripMenuItem });
            _contexMenu.Name = "_contexMenu";
            _contexMenu.Size = new System.Drawing.Size(181, 26);
            logToolStripMenuItem.Name = "logToolStripMenuItem";
            logToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
            logToolStripMenuItem.Text = Controller.ViewController.EnableLogGrading ?
                "Disable Log Grading" : "Enable Log Grading";
            logToolStripMenuItem.Click += logToolStripMenuItem_Click;
            _contexMenu.ResumeLayout(false);
        }
Ejemplo n.º 31
0
 internal void AtribuaEvento(DataGridViewCellEventHandler eventoDeSelecao)
 {
     ctlPesquisaDeServico1.AdicioneEvento(eventoDeSelecao);
 }
Ejemplo n.º 32
0
 public void dataTimeDeposit_CellContentClick(DataGridViewCellEventHandler e)
 {
     this.dataTimeDeposit.CellClick += e;
 }
Ejemplo n.º 33
0
        private void Board_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewCellEventHandler handler = BoardCellContentClick;

            handler(sender, e);
        }
Ejemplo n.º 34
0
 public void AdicioneEvento(DataGridViewCellEventHandler eventoDeSelecao)
 {
     this.dgvProdutos.AdicioneEvent(eventoDeSelecao);
 }
Ejemplo n.º 35
0
 public void dataAmortization_CellValueChanged(DataGridViewCellEventHandler e)
 {
     this.dataAmortization.CellValueChanged += e;
 }
Ejemplo n.º 36
0
        /// <summary>
        /// Subscribing to any changes of the controls by type
        /// </summary>
        /// <param name="type"></param>
        /// <param name="control">where to look</param>
        /// <param name="callback"></param>
        /// <param name="except">Optional the exception list with names what should be ignored</param>
        public static void noticeAboutChanges(Type type, Form control, EventHandler callback, string[] except = null)
        {
            foreach (Control ctrl in getControls(control,
                                                 c =>
                                                 c.GetType() == type
                                                 &&
                                                 (
                                                     (except != null && !except.Contains(c.Name))
                                                     ||
                                                     except == null
                                                 )
                                                 ))
            {
                if (type == typeof(CheckBox))
                {
                    ((CheckBox)ctrl).CheckedChanged -= callback;
                    ((CheckBox)ctrl).CheckedChanged += callback;
                    continue;
                }

                if (type == typeof(RadioButton))
                {
                    ((RadioButton)ctrl).CheckedChanged -= callback;
                    ((RadioButton)ctrl).CheckedChanged += callback;
                    continue;
                }

                if (type == typeof(TextBox))
                {
                    ((TextBox)ctrl).TextChanged -= callback;
                    ((TextBox)ctrl).TextChanged += callback;
                    continue;
                }

                if (type == typeof(ListBox))
                {
                    ((ListBox)ctrl).SelectedIndexChanged -= callback;
                    ((ListBox)ctrl).SelectedIndexChanged += callback;
                    continue;
                }

                if (type == typeof(ComboBox))
                {
                    ((ComboBox)ctrl).TextChanged -= callback;
                    ((ComboBox)ctrl).TextChanged += callback;
                    continue;
                }

                if (type == typeof(RichTextBox))
                {
                    ((RichTextBox)ctrl).TextChanged -= callback;
                    ((RichTextBox)ctrl).TextChanged += callback;
                    continue;
                }

                if (type == typeof(CheckedListBox))
                {
                    ItemCheckEventHandler call = (sender, e) => { callback(sender, (EventArgs)e); };
                    ((CheckedListBox)ctrl).ItemCheck -= call;
                    ((CheckedListBox)ctrl).ItemCheck += call;
                    continue;
                }

                if (type == typeof(DataGridView) || type == typeof(DataGridViewExt))
                {
                    DataGridViewCellEventHandler call = (sender, e) => { callback(sender, (EventArgs)e); };
                    ((DataGridView)ctrl).CellValueChanged -= call;
                    ((DataGridView)ctrl).CellValueChanged += call;
                    continue;
                }

                if (type == typeof(PropertyGrid))
                {
                    PropertyValueChangedEventHandler call = (sender, e) => { callback(sender, (EventArgs)e); };
                    ((PropertyGrid)ctrl).PropertyValueChanged -= call;
                    ((PropertyGrid)ctrl).PropertyValueChanged += call;
                    continue;
                }
            }
        }
Ejemplo n.º 37
0
        public Form1()
        {
            InitializeComponent();
            var ShowList      = new List <List <LogInfo> >();
            var ShowDic       = new List <Dictionary <int, int> >();
            var CusTomList    = new List <SaveInfo>();
            var ShowListIndex = 0;
            var StartTree     = 0;
            var SavePath      = "";
            var LogPath       = "";
            var Custompath    = new FileInfo(GetType().Assembly.Location).DirectoryName + @"\" + "custom.xml";
            Action <List <LogInfo> > ShowToDataGridView = (TempInfo) =>
            {
                if (TempInfo.Count != 0)
                {
                    var table = new DataTable();
                    table.Columns.Add("序号");      //0
                    table.Columns.Add("时间");      //1
                    table.Columns.Add("模式");      //2
                    table.Columns.Add("时间间隔");    //3
                    table.Columns.Add("Trace间隔"); //4
                    table.Columns.Add("操作");      //5
                    table.Columns.Add("备注");      //5
                    foreach (var Tempinfo in TempInfo)
                    {
                        table.Rows.Add(Tempinfo.Index, Tempinfo.time, Tempinfo.Mode, Tempinfo.TimeSpan + "ms", Tempinfo.TraceSpan == 0 ? "" : Tempinfo.TraceSpan + "ms", Tempinfo.OperaInfo, Tempinfo.remark);
                    }
                    BeginInvoke(new MethodInvoker(() =>
                    {
                        LogData.DataSource = table;
                        //LogData.Rows[0].DefaultCellStyle.BackColor = Color.Red;
                        LogData.Columns[0].Width    = 50;
                        LogData.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
                        LogData.Columns[0].ReadOnly = true;
                        LogData.Columns[1].Width    = 100;
                        LogData.Columns[1].ReadOnly = true;
                        LogData.Columns[2].Width    = 60;
                        LogData.Columns[2].ReadOnly = true;
                        LogData.Columns[3].Width    = 60;
                        LogData.Columns[3].ReadOnly = true;
                        LogData.Columns[3].SortMode = DataGridViewColumnSortMode.NotSortable;
                        LogData.Columns[4].Width    = 50;
                        LogData.Columns[4].ReadOnly = true;
                        LogData.Columns[4].SortMode = DataGridViewColumnSortMode.NotSortable;
                        LogData.Columns[5].Width    = 280;
                        LogData.Columns[5].ReadOnly = true;
                        LogData.Columns[5].SortMode = DataGridViewColumnSortMode.NotSortable;
                        LogData.Columns[6].Width    = 180;
                        LogData.Columns[6].SortMode = DataGridViewColumnSortMode.NotSortable;
                    }));
                }
            };
            Action CheckColorMsecStatus = () =>
            {
                var      redindex   = int.Parse(LogData.Rows[0].Cells[0].Value.ToString());
                var      greenindex = -1;
                TimeSpan spantime;
                for (int i = 1; i < LogData.Rows.Count; i++)
                {
                    LogData.Rows[i].Cells[7].Value = "";
                    LogData.Rows[i].Cells[8].Value = "";
                    if (LogData.Rows[i].Cells[7].Style.BackColor == Color.Red)
                    {
                        var tempindex = int.Parse(LogData.Rows[i].Cells[0].Value.ToString());
                        spantime = Convert.ToDateTime(ShowList[ShowListIndex][tempindex].time) - Convert.ToDateTime(ShowList[ShowListIndex][redindex].time);
                        LogData.Rows[i].Cells[7].Value = spantime.TotalMilliseconds + "ms";

                        if (greenindex != -1)
                        {
                            spantime = Convert.ToDateTime(ShowList[ShowListIndex][tempindex].time) - Convert.ToDateTime(ShowList[ShowListIndex][greenindex].time);
                            LogData.Rows[i].Cells[8].Value = spantime.TotalMilliseconds + "ms";
                        }
                        greenindex = -1;
                        redindex   = tempindex;
                    }
                    if (LogData.Rows[i].Cells[8].Style.BackColor == Color.MediumSpringGreen)
                    {
                        var tempindex = int.Parse(LogData.Rows[i].Cells[0].Value.ToString());
                        if (greenindex == -1)
                        {
                            spantime = Convert.ToDateTime(ShowList[ShowListIndex][tempindex].time) - Convert.ToDateTime(ShowList[ShowListIndex][redindex].time);
                        }
                        else
                        {
                            spantime = Convert.ToDateTime(ShowList[ShowListIndex][tempindex].time) - Convert.ToDateTime(ShowList[ShowListIndex][greenindex].time);
                        }
                        LogData.Rows[i].Cells[8].Value = spantime.TotalMilliseconds + "ms";
                        greenindex = tempindex;
                    }
                }
                LogData.Update();
            };
            Action LoadCustomSetToData = () =>
            {
                if (LogData.Rows.Count == 0)
                {
                    return;
                }
                var RowIndex = 0;
                foreach (var item in CusTomList)
                {
                    for (int i = RowIndex; i < LogData.Rows.Count; i++)
                    {
                        var String = new StringCompute();
                        String.SpeedyCompute(item.OperaInfo, LogData.Rows[i].Cells[5].Value.ToString());
                        var res = (float)String.ComputeResult.Rate;
                        if (res >= 0.8)
                        {
                            var color = Color.FromName(item.Color);
                            if (color == Color.Red)
                            {
                                LogData.Rows[i].Cells[7].Style.BackColor = color;
                            }
                            else
                            {
                                LogData.Rows[i].Cells[8].Style.BackColor = color;
                            }
                            LogData.Rows[i].Cells[6].Value = item.remark;
                            RowIndex = i + 1;
                            break;
                        }
                    }
                }
                CheckColorMsecStatus();
            };
            Action <int, int> SingleShowToDataGridView = (startindex, endindex) =>
            {
                var table = new DataTable();
                table.Columns.Add("序号");      //0
                table.Columns.Add("时间");      //1
                table.Columns.Add("模式");      //2
                table.Columns.Add("时间间隔");    //3
                table.Columns.Add("Trace间隔"); //4
                table.Columns.Add("操作");      //5
                table.Columns.Add("备注");      //5
                if (AnalysisCheck.Checked)
                {
                    table.Columns.Add("检查工序");
                    table.Columns.Add("检查工作");
                }
                for (; startindex <= endindex; startindex++)
                {
                    var Tempinfo = ShowList[ShowListIndex][startindex];
                    table.Rows.Add(Tempinfo.Index, Tempinfo.time, Tempinfo.Mode, Tempinfo.TimeSpan + "ms", Tempinfo.TraceSpan == 0 ? "" : Tempinfo.TraceSpan + "ms", Tempinfo.OperaInfo, Tempinfo.remark);
                }
                BeginInvoke(new MethodInvoker(() =>
                {
                    LogData.DataSource          = table;
                    LogData.Columns[0].Width    = 50;
                    LogData.Columns[0].SortMode = DataGridViewColumnSortMode.NotSortable;
                    LogData.Columns[0].ReadOnly = true;
                    LogData.Columns[1].Width    = 100;
                    LogData.Columns[1].ReadOnly = true;
                    LogData.Columns[2].Width    = 60;
                    LogData.Columns[2].ReadOnly = true;
                    LogData.Columns[3].Width    = 60;
                    LogData.Columns[3].ReadOnly = true;
                    LogData.Columns[3].SortMode = DataGridViewColumnSortMode.NotSortable;
                    LogData.Columns[4].Width    = 50;
                    LogData.Columns[4].ReadOnly = true;
                    LogData.Columns[4].SortMode = DataGridViewColumnSortMode.NotSortable;
                    LogData.Columns[5].Width    = 280;
                    LogData.Columns[5].ReadOnly = true;
                    LogData.Columns[5].SortMode = DataGridViewColumnSortMode.NotSortable;
                    LogData.Columns[6].Width    = 180;
                    LogData.Columns[6].SortMode = DataGridViewColumnSortMode.NotSortable;
                    if (AnalysisCheck.Checked)
                    {
                        LogData.Columns[7].ReadOnly = true;
                        LogData.Columns[7].Width    = 60;
                        LogData.Columns[7].SortMode = DataGridViewColumnSortMode.NotSortable;
                        LogData.Columns[8].ReadOnly = true;
                        LogData.Columns[8].Width    = 60;
                        LogData.Columns[8].SortMode = DataGridViewColumnSortMode.NotSortable;
                        LogData.Rows[0].Cells[7].Style.BackColor = Color.Red;
                        LogData.Rows[LogData.Rows.Count - 1].Cells[7].Style.BackColor = Color.Red;
                        if (CusTomList.Count != 0)
                        {
                            LoadCustomSetToData();
                        }
                    }
                }));
            };
            Action <List <LogInfo> > ShowToTree = (GetInfo) =>
            {
                if (GetInfo.Count != 0)
                {
                    var      StartDic       = new Dictionary <int, int>();//记录的是这次开始和上次开始之间的序列,
                    var      laststartindex = -1;
                    TreeNode Root           = new TreeNode();
                    TreeNode DepthStart     = new TreeNode();
                    TreeNode DepthTrace     = new TreeNode();
                    Root.Text = ShowList.IndexOf(GetInfo) + ":" + GetInfo[0].Data;
                    foreach (var item in GetInfo)
                    {
                        if (item.Mode == "Trace" && item.OperaInfo.StartsWith("Start Inspection"))
                        {
                            if (item.OperaInfo == "Start Inspection")
                            {
                                DepthStart      = new TreeNode();
                                DepthStart.Text = item.Index + ":开始检测";
                                Root.Nodes.Add(DepthStart);
                                laststartindex = item.Index;
                                continue;
                            }
                            else if (item.OperaInfo.EndsWith("[msec]"))
                            {
                                StartDic.Add(laststartindex, item.Index);
                            }
                        }
                        if (DepthStart.Text != "")
                        {
                            if (item.Mode == "Trace")
                            {
                                DepthTrace      = new TreeNode();
                                DepthTrace.Text = string.IsNullOrWhiteSpace(item.remark) ? item.Index + ":" + item.OperaInfo : item.Index + ":" + item.remark;
                                DepthStart.Nodes.Add(DepthTrace);
                                continue;
                            }
                            else
                            {
                                if (DepthTrace.Text != "")
                                {
                                    if (item.Mode != "")
                                    {
                                        DepthTrace.Nodes.Add(string.IsNullOrWhiteSpace(item.remark) ? item.Index + ":" + item.Mode : item.Index + ":" + item.remark);
                                    }
                                    else
                                    {
                                        DepthTrace.Nodes.Add(string.IsNullOrWhiteSpace(item.remark) ? item.Index + ":" + item.OperaInfo : item.Index + ":" + item.remark);
                                    }
                                }
                            }
                        }
                    }
                    ShowDic.Add(StartDic);
                    BeginInvoke(new MethodInvoker(() =>
                    {
                        Logtree.Nodes.Add(Root);
                    }));
                }
            };
            Action <Stream> StartRead = (File) =>
            {
                using (TextReader sr = new StreamReader(File))
                {
                    int ProgressBar = 0;
                    new Task(() =>
                    {
                        BeginInvoke(new MethodInvoker(() =>
                        {
                            progressBar.Value   = 0;
                            progressBar.Maximum = (int)File.Length;
                        }));
                        do
                        {
                            BeginInvoke(new MethodInvoker(() =>
                            {
                                progressBar.Value = (int)File.Position;
                            }));
                            Thread.Sleep(10);
                        } while (progressBar.Value != progressBar.Maximum);
                    }).Start();
                    var     GetInfo   = new List <LogInfo>();
                    var     Regex     = new Regex(@"(?<key>\d{4}-\d{2}-\d{2}).(?<key2>\d{2}:\d{2}:\d{2},\d{3})..(?<key3>(?<=\[).*?(?=\]))..(?<key4>.*)", RegexOptions.Compiled);
                    var     Regex2    = new Regex(@"(?<key>\d{4}-\d{2}-\d{2}).(?<key2>\d{2}:\d{2}:\d{2},\d{3})..(?<key4>.*)", RegexOptions.Compiled);
                    LogInfo LastTrace = null;
                    LogInfo LastOpera = null;
                    while (sr.Peek() != -1)
                    {
                        var             Text       = sr.ReadLine();
                        GroupCollection MatchGroup = Regex.Match(Text).Groups;
                        if (MatchGroup.Count == 1)
                        {
                            MatchGroup = Regex2.Match(Text).Groups;
                            if (MatchGroup.Count == 1)
                            {
                                continue;
                            }
                        }
                        var TempInfo = new LogInfo();
                        TempInfo.Index     = ProgressBar;
                        TempInfo.Data      = MatchGroup["key"].Value;
                        TempInfo.time      = MatchGroup["key2"].Value.Replace(",", ".");
                        TempInfo.Mode      = MatchGroup["key3"].Value;
                        TempInfo.OperaInfo = MatchGroup["key4"].Value;
                        if (TempInfo.Mode == "Trace")
                        {
                            if (LastTrace != null)
                            {
                                TempInfo.TraceSpan = (uint)(Convert.ToDateTime(TempInfo.time) - Convert.ToDateTime(LastTrace.time)).TotalMilliseconds;
                                TempInfo.TimeSpan  = (uint)(Convert.ToDateTime(TempInfo.time) - Convert.ToDateTime(LastOpera.time)).TotalMilliseconds;
                                LastTrace          = TempInfo;
                            }
                            else
                            {
                                LastTrace = TempInfo;
                            }
                        }
                        else
                        {
                            if (LastOpera != null)
                            {
                                TempInfo.TimeSpan = (uint)(Convert.ToDateTime(TempInfo.time) - Convert.ToDateTime(LastOpera.time)).TotalMilliseconds;
                                LastOpera         = TempInfo;
                            }
                        }
                        LastOpera = TempInfo;
                        GetInfo.Add(TempInfo);
                        Interlocked.Increment(ref ProgressBar);
                    }
                    Thread.Sleep(100);
                    ShowList.Add(GetInfo);
                    var Mission = new Task(() => ShowToTree(GetInfo));
                    Mission.ContinueWith((obj) =>
                    {
                        if (AnalysisCheck.Checked)
                        {
                            StartTree = ShowDic[ShowListIndex].Keys.First();
                            SingleShowToDataGridView(StartTree, ShowDic[ShowListIndex][StartTree]);
                        }
                    });
                    Mission.Start();
                    if (!AnalysisCheck.Checked)
                    {
                        new Task(() => ShowToDataGridView(GetInfo)).Start();
                    }
                    ShowListIndex = ShowList.Count - 1;
                }
            };
            Action Save = () =>
            {
                using (var SaveDialog = new SaveFileDialog())
                {
                    SaveDialog.Title        = "保存列表";
                    SaveDialog.Filter       = "dat文件(*.dat)|*.dat";
                    SaveDialog.AddExtension = true;
                    if (SavePath == "" || !new FileInfo(SavePath).Exists)
                    {
                        if (LogPath != "")
                        {
                            var FileInfo = new FileInfo(LogPath);
                            SaveDialog.FileName = FileInfo.Name.Split('.')[0];
                        }
                        SaveDialog.ShowDialog();
                        if (SaveDialog.FileName == "")
                        {
                            return;
                        }
                        SavePath = SaveDialog.FileName;
                    }
                    if (SavePath == "")
                    {
                        return;
                    }
                    new Task(() =>
                    {
                        using (Stream Filestream = new FileStream(SavePath, FileMode.Create, FileAccess.Write, FileShare.None))
                        {
                            XmlSerializer ser = new XmlSerializer(typeof(List <List <LogInfo> >));
                            ser.Serialize(Filestream, ShowList);
                        }
                    }).Start();
                }
            };
            Action <List <SaveInfo> > Savecustom = (list) =>
            {
                new Task(() =>
                {
                    XmlSerializer ser = new XmlSerializer(typeof(List <SaveInfo>));
                    using (Stream Filestream = new FileStream(Custompath, FileMode.Create, FileAccess.Write, FileShare.None))
                    {
                        ser.Serialize(Filestream, list);
                    }
                }).Start();
            };
            Action StartChangeShow = () =>
            {
                ShowToDataGridView(ShowList[ShowListIndex]);
                BeginInvoke(new MethodInvoker(() => { LogData.CurrentCell = LogData.Rows[StartTree].Cells[0]; }));
            };
            Func <TreeNode, int> FindStartTree = Tree =>
            {
                var index = 0;
                if (Tree.Parent != null)
                {
                    while (true)
                    {
                        if (Tree.Text.EndsWith("开始检测"))
                        {
                            int.TryParse(Tree.Text.Split(':')[0], out index);
                            break;
                        }
                        else if (Tree == null)
                        {
                            break;
                        }
                        else
                        {
                            Tree = Tree.Parent;
                        }
                    }
                }
                return(index);
            };
            Func <TreeNode, int> FindRootTree = Tree =>
            {
                var index = 0;
                if (Tree.Parent != null)
                {
                    while (true)
                    {
                        if (Tree.Parent == null)
                        {
                            int.TryParse(Tree.Text.Split(':')[0], out index);
                            break;
                        }
                        else
                        {
                            Tree = Tree.Parent;
                        }
                    }
                }
                else
                {
                    int.TryParse(Tree.Text.Split(':')[0], out index);
                }
                return(index);
            };
            DataGridViewCellEventHandler setcustommouseopera = (s, o) =>
            {
                if (LogData.CurrentCell.ColumnIndex == 7 || LogData.CurrentCell.ColumnIndex == 8)
                {
                    if (LogData.CurrentCell.RowIndex != 0 && LogData.CurrentCell.RowIndex != LogData.Rows.Count - 1)
                    {
                        if (LogData.CurrentCell.ColumnIndex == 7)
                        {
                            if (LogData.CurrentCell.Style.BackColor == Color.Red)
                            {
                                LogData.CurrentCell.Style.BackColor = Color.Empty;
                            }
                            else
                            {
                                LogData.CurrentCell.Style.BackColor = Color.Red;
                                LogData.Rows[LogData.CurrentCell.RowIndex].Cells[8].Style.BackColor = Color.Empty;
                            }
                        }
                        else if (LogData.Rows[LogData.CurrentCell.RowIndex].Cells[7].Style.BackColor != Color.Red)
                        {
                            if (LogData.CurrentCell.Style.BackColor == Color.MediumSpringGreen)
                            {
                                LogData.CurrentCell.Style.BackColor = Color.Empty;
                            }
                            else
                            {
                                LogData.CurrentCell.Style.BackColor = Color.MediumSpringGreen;
                            }
                        }
                        CheckColorMsecStatus();
                        LogData.CurrentCell = LogData.Rows[LogData.CurrentCell.RowIndex].Cells[6];
                    }
                }
            };

            LoadLogfile.Click += delegate
            {
                using (OpenFileDialog open = new OpenFileDialog())
                {
                    open.Title  = "载入Log日志";
                    open.Filter = "所有文件(*.*)|*.*|Log文件(*.Log)|*.log|文本文档(*.txt)|*.txt";
                    open.ShowDialog();
                    if (open.FileName != "")
                    {
                        LogPath            = open.FileName;
                        SaveButton.Enabled = true;
                        new Task(() => { StartRead(open.OpenFile()); }).Start();
                    }
                }
            };
            Logtree.AfterSelect += (s, e) =>
            {
                try
                {
                    var RootTree  = FindRootTree(Logtree.SelectedNode);
                    var startTree = FindStartTree(Logtree.SelectedNode);
                    if (!AnalysisCheck.Checked)
                    {
                        if (RootTree != ShowListIndex)
                        {
                            ShowListIndex = RootTree;
                            StartTree     = startTree;
                            new Task(() => StartChangeShow()).Start();
                            return;
                        }
                        else if (StartTree != startTree)
                        {
                            int.TryParse(Logtree.SelectedNode.Text.Split(':')[0], out int selectindex);
                            LogData.CurrentCell = LogData.Rows[selectindex].Cells[0];
                        }
                        {
                            int.TryParse(Logtree.SelectedNode.Text.Split(':')[0], out int selectindex);
                            LogData.CurrentCell = LogData.Rows[selectindex].Cells[0];
                        }
                    }
                    else
                    {
                        if (RootTree != ShowListIndex || StartTree != startTree)
                        {
                            ShowListIndex = RootTree;
                            StartTree     = startTree;
                            SingleShowToDataGridView(StartTree, (from T in ShowDic[ShowListIndex] where T.Key == StartTree select T.Value).FirstOrDefault());
                        }
                        {
                            int.TryParse(Logtree.SelectedNode.Text.Split(':')[0], out int selectindex);
                            if (AnalysisCheck.Checked)
                            {
                                for (int i = 0; i < LogData.Rows.Count; i++)
                                {
                                    if (LogData.Rows[i].Cells[0].Value.ToString() == selectindex.ToString())
                                    {
                                        LogData.CurrentCell = LogData.Rows[i].Cells[0];
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                }
            };
            LogData.CellEndEdit += (s, e) =>
            {
                SaveButton.Enabled = true;
                int.TryParse(LogData.Rows[e.RowIndex].Cells[0].Value.ToString(), out int Index);
                if (AnalysisCheck.Checked)
                {
                    for (int i = 0; i < LogData.Rows.Count; i++)
                    {
                        if (LogData.Rows[i].Cells[0].Value.ToString() == Index.ToString())
                        {
                            Index = i;
                        }
                    }
                }
                ShowList[ShowListIndex][Index].remark = LogData.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
            };
            SaveButton.Click += delegate
            {
                Save();
                SaveButton.Enabled = false;
            };
            LoadListButton.Click += delegate
            {
                using (OpenFileDialog open = new OpenFileDialog())
                {
                    open.Title        = "载入列表";
                    open.Filter       = "dat文件(*.dat)|*.dat";
                    open.AddExtension = true;
                    open.ShowDialog();
                    if (open.FileName == "")
                    {
                        return;
                    }
                    Logtree.Nodes.Clear();
                    LoadListButton.Text    = "载入中";
                    LoadLogfile.Enabled    = false;
                    LoadListButton.Enabled = false;
                    SaveButton.Enabled     = false;
                    SavePath = open.FileName;
                    new Task(() =>
                    {
                        using (Stream stream = new FileStream(SavePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            XmlSerializer ser = new XmlSerializer(typeof(List <List <LogInfo> >));
                            ShowList          = new List <List <LogInfo> >((List <List <LogInfo> >)ser.Deserialize(stream));
                            if (ShowList.Count != 0)
                            {
                                foreach (var GetInfo in ShowList)
                                {
                                    ShowToTree(GetInfo);
                                }
                                if (!AnalysisCheck.Checked)
                                {
                                    new Task(() => ShowToDataGridView(ShowList[0])).Start();
                                }
                                else
                                {
                                    StartTree = ShowDic[ShowListIndex].Keys.First();
                                    SingleShowToDataGridView(StartTree, ShowDic[ShowListIndex][StartTree]);
                                }
                                BeginInvoke(new MethodInvoker(() =>
                                {
                                    LoadListButton.Text    = "载入列表";
                                    LoadLogfile.Enabled    = true;
                                    LoadListButton.Enabled = true;
                                }));
                            }
                        }
                    }).Start();
                }
            };
            FormClosed += delegate
            {
                if (SaveButton.Enabled)
                {
                    if (MessageBox.Show("列表已经修改,是否保存?", "是否保存列表", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    {
                        Save();
                    }
                }
            };
            AnalysisCheck.CheckedChanged += delegate
            {
                try
                {
                    if (AnalysisCheck.Checked)
                    {
                        if (ShowList.Count != 0)
                        {
                            StartTree = ShowDic[ShowListIndex].Keys.First();
                            SingleShowToDataGridView(StartTree, ShowDic[ShowListIndex][StartTree]);
                        }
                        LoadCustomSet.Visible = true;
                        SetCustom.Visible     = true;
                        SaveCustom.Visible    = true;
                    }
                    else
                    {
                        LoadCustomSet.Visible = false;
                        SetCustom.Visible     = false;
                        SaveCustom.Visible    = false;
                        if (LogData.Columns.Count < 6)
                        {
                            return;
                        }
                        new Task(() => StartChangeShow()).Start();
                        LogData.Columns.Remove("检查工序");
                        LogData.Columns.Remove("检查工作");
                    }
                }
                catch (Exception)
                { }
            };
            SetCustom.Click += delegate
            {
                if (SetCustom.Text == "设定自定义")
                {
                    LogData.CellClick     += setcustommouseopera;
                    SetCustom.Text         = "正在设定";
                    LoadLogfile.Enabled    = false;
                    LoadListButton.Enabled = false;
                    LoadCustomSet.Enabled  = false;
                    SaveCustom.Enabled     = false;
                    AnalysisCheck.Enabled  = false;
                }
                else
                {
                    LogData.CellClick     -= setcustommouseopera;
                    SetCustom.Text         = "设定自定义";
                    LoadLogfile.Enabled    = true;
                    LoadListButton.Enabled = true;
                    LoadCustomSet.Enabled  = true;
                    SaveCustom.Enabled     = true;
                    AnalysisCheck.Enabled  = true;
                    ThreadPool.QueueUserWorkItem((object state) =>
                    {
                        List <SaveInfo> cusTomList = new List <SaveInfo>();
                        foreach (DataGridViewRow item in LogData.Rows)
                        {
                            var Color7 = item.Cells[7].Style.BackColor;
                            var Color8 = item.Cells[8].Style.BackColor;
                            if (Color7 != Color.Empty || Color8 != Color.Empty)
                            {
                                var TempInfo       = new SaveInfo();
                                TempInfo.Color     = Color7.IsEmpty ? Color8.Name : Color7.Name;
                                TempInfo.OperaInfo = item.Cells[5].Value.ToString();
                                TempInfo.remark    = item.Cells[6].Value.ToString();
                                cusTomList.Add(TempInfo);
                            }
                        }
                        if (CusTomList.Count == cusTomList.Count)
                        {
                            for (int i = 0; i < CusTomList.Count; i++)
                            {
                                if (CusTomList[i] != cusTomList[i])
                                {
                                    if (MessageBox.Show("自定义已经修改,是否保存?", "是否保存自定义", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                                    {
                                        BeginInvoke(new MethodInvoker(() => { Savecustom(cusTomList); }));
                                    }
                                    break;
                                }
                            }
                        }
                        else
                        {
                            if (MessageBox.Show("自定义已经修改,是否保存?", "是否保存自定义", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                            {
                                Savecustom(cusTomList);
                            }
                        }
                        CusTomList = new List <SaveInfo>(cusTomList);
                    });
                    //增加询问是否保存
                }
            };
            LoadCustomSet.Click += delegate
            {
                using (OpenFileDialog open = new OpenFileDialog())
                {
                    open.Title        = "载入自定义";
                    open.Filter       = "Xml文件(*.Xml)|*.xml";
                    open.AddExtension = true;
                    open.ShowDialog();
                    if (open.FileName == "")
                    {
                        return;
                    }
                    SavePath = open.FileName;
                    new Task(() =>
                    {
                        XmlSerializer ser = new XmlSerializer(typeof(List <SaveInfo>));
                        using (Stream stream = new FileStream(open.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            CusTomList = new List <SaveInfo>((List <SaveInfo>)ser.Deserialize(stream));
                            BeginInvoke(new MethodInvoker(() =>
                            {
                                LoadCustomSetToData();
                            }));
                        }
                    }).Start();
                }
            };
            SaveCustom.Click += delegate
            {
                using (var SaveDialog = new SaveFileDialog())
                {
                    SaveDialog.Title            = "保存自定义";
                    SaveDialog.Filter           = "Xml文件(*.Xml)|*.xml";
                    SaveDialog.InitialDirectory = new FileInfo(Custompath).DirectoryName;
                    SaveDialog.FileName         = new FileInfo(Custompath).Name;
                    SaveDialog.AddExtension     = true;
                    SaveDialog.ShowDialog();
                    if (SaveDialog.FileName == "")
                    {
                        return;
                    }
                    Custompath = SaveDialog.FileName;
                    Savecustom(CusTomList);
                }
            };
            new Task(() =>
            {
                if (File.Exists(Custompath))
                {
                    XmlSerializer ser = new XmlSerializer(typeof(List <SaveInfo>));
                    using (Stream stream = new FileStream(new FileInfo(GetType().Assembly.Location).DirectoryName + @"\" + "custom.xml", FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        CusTomList = new List <SaveInfo>((List <SaveInfo>)ser.Deserialize(stream));
                    }
                }
            }).Start();
        }
Ejemplo n.º 38
0
 public void setDataSearchEventHandler(DataGridViewCellEventHandler e)
 {
     this.dataSearch.CellClick += e;
 }