private TVChannel GetSelected() { try { DataGridView dgv = dgvTV; if (dgv != null && dgv.SelectedRows.Count > 0 && dgv.SelectedRows[0].Index > -1) { TVChannel tvc = null; if (dgv.SelectedRows[0].DataBoundItem is TVChannel) { tvc = dgv.SelectedRows[0].DataBoundItem as TVChannel; } if (tvc != null) { return(tvc); } } return(null); } catch (Exception ex) { Debug.Print("Ошибка выполнения GetSelected()\n" + ex.Message); return(null); } }
private void CreateTVChannelMerge(TVChannel item) { NewChannels.Add(new TVChannelMerge( _tvgName: item.TvgName, _tvglogo: item.Tvglogo, _groupTitle: item.GroupTitle, _udp: item.UDP, _Name: item.Name, _check: false)); }
private bool TVchannelExist(TVChannel tvc) { foreach (TVChannel _tvc in channels) // проверка наличия канала в листе { if (_tvc.Equals(tvc)) { return(true); } } return(false); }
private void Selected(DataGridView dgv, TVChannel tvc) { dgv.ClearSelection(); foreach (DataGridViewRow row in dgv.Rows) { if ((row.DataBoundItem as TVChannel).Name == tvc.Name && (row.DataBoundItem as TVChannel).GroupTitle == tvc.GroupTitle) { row.Selected = true; // dgv.FirstDisplayedScrollingRowIndex = row.Index; // прокрутка таблицы до выбранной строки break; } } }
private void Apply() { for (int i = 0; i < dgvMerge.RowCount; i++) { TVChannel tvc = null; if (dgvMerge.Rows[i].DataBoundItem is TVChannel) { tvc = dgvMerge.Rows[i].DataBoundItem as TVChannel; } if (tvc != null) { ModChannels.Add(tvc); } } }
public bool Equals(TVChannel tvc) { if (tvc != null) { if (tvc.UDP == this.UDP) { return(true); } else { return(false); } } return(false); }
/// <summary>Получение выбранной записи</summary> private TVChannel GetSelectedRow() { DataGridView dgv = dgvTV; if (dgv != null && dgv.SelectedRows.Count > 0 && dgv.SelectedRows[0].Index > -1) { TVChannel tvc = null; if (dgv.SelectedRows[0].DataBoundItem is TVChannel) { tvc = dgv.SelectedRows[0].DataBoundItem as TVChannel; } if (tvc != null) { return(tvc); } } return(null); }
private void dgvTV_SelectionChanged(object sender, EventArgs e) { if (dgvTV.SelectedRows.Count == 0) { return; } TVChannel tvc = GetSelectedRow(); if (tvc != null) { tvgNameBox.Text = tvc.TvgName; tvglogoBox.Text = tvc.Tvglogo; groupTitleComboBox.Text = tvc.GroupTitle; UDPbox.Text = tvc.UDP; NameBox.Text = tvc.Name; } }
private void Up() { if (dgvTV.RowCount > 1 && dgvTV.SelectedRows.Count != 0) { int selectedRow = dgvTV.SelectedRows[0].Index; if (selectedRow == 0) { return; } TVChannel current = channels[selectedRow]; TVChannel previous = channels[selectedRow - 1]; channels.RemoveAt(selectedRow); channels.Insert(selectedRow -= 1, current); dgvTV.Rows[selectedRow].Selected = true; } }
private void tree_DragDrop(object sender, DragEventArgs e)// здесь функционал DragDrop { Point pt = tree.PointToClient(new Point(e.X, e.Y)); TreeNode destinationNode = tree.GetNodeAt(pt); TVChannel tvc = GetSelected(); if (tvc != null) { try { if (destinationNode != tree.TopNode) { tvc.GroupTitle = destinationNode.Text; TableRefresh(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btnChangeApprove_Click(object sender, EventArgs e) // Кнопка Применить { if (dgvTV.SelectedRows.Count == 0) { return; } TVChannel tvc = GetSelected(); if (tvc != null) { if (ValidatorText(tvgNameBox.Text)) { tvc.TvgName = tvgNameBox.Text; } if (ValidatorText(tvglogoBox.Text)) { tvc.Tvglogo = tvglogoBox.Text; } if (ValidatorText(groupTitleComboBox.Text)) { tvc.GroupTitle = groupTitleComboBox.Text; } if (ValidatorUDP(UDPbox.Text)) { tvc.UDP = UDPbox.Text; } if (ValidatorText(NameBox.Text)) { tvc.Name = NameBox.Text; } } dgvTVtreeEnabled(true); TableRefresh(); Changed(); }
private void Down() { if (dgvTV.RowCount > 1 && dgvTV.SelectedRows.Count != 0) { int selectedRow = dgvTV.SelectedRows[0].Index; if (selectedRow == dgvTV.RowCount - 1) { return; } TVChannel current = channels[selectedRow]; TVChannel next = channels[selectedRow + 1]; channels.RemoveAt(selectedRow); channels.Insert(selectedRow += 1, current); dgvTV.Rows[selectedRow].Selected = true; } }
void TableRefresh(string node = "", bool refresh = false) { TVChannel tvc = GetSelected(); if (refresh) { // SortableBindingList<TVChannel> filteredList = new SortableBindingList<TVChannel>(channels.Where(m => m.GroupTitle == node).ToList()); // dgvTV.DataSource = filteredList; //tssLabel2.Text = "В составе группы: " + filteredList.Count; dgvTV.DataSource = channels.Where(m => m.GroupTitle == node).ToList(); tssLabel2.Text = "В составе группы: " + channels.Where(m => m.GroupTitle == node).ToList().Count; } else { dgvTV.DataSource = channels; tssLabel2.Text = ""; } if (tvc != null) { Selected(dgvTV, tvc); } }
void packetReceive() { byte[] data = new byte[65535]; // max udp size datagram int recv = 0; bool foundchannel = false; bool timedout = false; bool searchforward = Ethernet.searchForward(IPstart, IPstop); uint progressfull = Ethernet.calculateNumOfIpAddr(IPstart, IPstop); bool stopcondition = false; byte[] oct = IPstart.GetAddressBytes(); multiep = new IPEndPoint(new IPAddress(oct), Port); EndPoint ep = (EndPoint)multiep; IPEndPoint iep = new IPEndPoint(IPAddress.Parse(localhost), Port); int i = 0; int dir, tst; byte str; if (searchforward) { dir = 1; tst = 256; str = (byte)0; } else { dir = -1; tst = -1; str = (byte)255; } while (true) { i++; Thread.Sleep(300); // 300 ms between requests foundchannel = false; sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); try { sock.Bind(iep); } catch (SocketException ex) { if (ex.SocketErrorCode == SocketError.AddressAlreadyInUse) { break; } } sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, Timeout); sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastInterface, IPAddress.Parse(localhost).GetAddressBytes()); try { // Must be valid multicast address, else exception 10049 sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(new IPAddress(oct), IPAddress.Parse(localhost))); } catch (SocketException) { break; } CurrentIP_label.Invoke(new UpdateTextCallback(UpdateipLabel), curip.ToString()); FoundIP_label.Invoke(new UpdateTextCallback(UpdatefoundLabel), found.ToString()); try { recv = sock.ReceiveFrom(data, ref ep); } catch (SocketException ex1) { if (ex1.SocketErrorCode == SocketError.TimedOut) { timedout = true; recv = 0; foundchannel = false; } } if (recv > 0) { foundchannel = true; found++; }//We found a channel if (!timedout) { Thread.Sleep(300); // we are receiving for 300 ms } string tvgName = "Chan " + lastchan; string tvglogo = "New Logo"; string groupTitle = "New Group"; string Name = lastchan.ToString(); string udp = "udp://@" + curip.ToString() + ":" + Port; TVChannel tvc = new TVChannel( _tvgName: tvgName.Trim(), _tvglogo: tvglogo.Trim(), _groupTitle: groupTitle.Trim(), _udp: udp.Trim(), _Name: Name.Trim() ); bool isTVC = false; for (int count = 0; count < FindCH.Count; count++) { if (FindCH[count].Equals(tvc)) { isTVC = true; break; } } //Check if entry allready exists if (foundchannel && !isTVC) { CurrentIP_label.Invoke(new RefreshDatatableViewCallback(TableAdd), tvc); newchan++; lastchan++; CurrentIP_label.Invoke(new UpdateTextCallback(UpdateipLabel), curip.ToString()); FoundIP_label.Invoke(new UpdateTextCallback(UpdatefoundLabel), found.ToString()); } sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.DropMembership, new MulticastOption(new IPAddress(oct), IPAddress.Parse(localhost))); if (stopcondition) { break; } int test1 = oct[3] + dir; if (test1 == tst) { oct[3] = str; int test2 = oct[2] + dir; if (test2 == tst) { oct[2] = str; int test3 = oct[1] + dir; if (test3 == tst) { oct[1] = str; int test4 = oct[0] + dir; if (test4 == tst) { oct[0] = str; } } else { oct[1] = (byte)(oct[1] + dir); } } else { oct[2] = (byte)(oct[2] + dir); } } else { oct[3] = (byte)(oct[3] + dir); } curip = new IPAddress(oct); progress_Bar.Invoke(new ProgressbarCallback(UpdateprogressBar), (int)Math.Round(100 * (float)i / (float)progressfull)); if (curip.Equals(IPstop)) { stopcondition = true; } sock.Close(); } sock.Close(); CurrentIP_label.Invoke(new UpdateTextCallback(UpdateipLabel), curip.ToString()); FoundIP_label.Invoke(new UpdateTextCallback(UpdatefoundLabel), found.ToString()); start_bt.Invoke(new UpdateButtonsCallback(UpdatestartButton)); stop_bt.Invoke(new UpdateButtonsCallback(UpdatestopButton)); progress_Bar.Invoke(new ProgressbarCallback(UpdateprogressBar), 100); //Abort thread ThreadReceiver.Abort(); }
public void TableAdd(TVChannel tvc) { FindCH.Add(tvc); }