示例#1
0
        /// <summary>
        /// Вставить новый элемент в представление
        /// </summary>
        private void InsertItem(TableView.Item item)
        {
            // получение индекса для вставки
            int newInd;

            if (dgvItems.SelectedRows.Count > 0)
            {
                newInd = -1;
                foreach (DataGridViewRow row in dgvItems.SelectedRows)
                {
                    if (newInd < row.Index)
                    {
                        newInd = row.Index;
                    }
                }
                newInd++;
            }
            else if (dgvItems.CurrentRow != null)
            {
                newInd = dgvItems.CurrentRow.Index + 1;
            }
            else
            {
                newInd = dgvItems.Rows.Count;
            }

            // вставка элемента
            tableView.Items.Insert(newInd, item);
            bsItems.ResetBindings(false);
            SelectItem(newInd, !dgvCnls.Focused);
            SetModified(true);
        }
示例#2
0
        /// <summary>
        /// Inserts the item in the table.
        /// </summary>
        private void InsertTableItem(TableView.Item item)
        {
            // get insert index
            int newInd;

            if (dgvTable.SelectedRows.Count > 0)
            {
                newInd = -1;
                foreach (DataGridViewRow row in dgvTable.SelectedRows)
                {
                    if (newInd < row.Index)
                    {
                        newInd = row.Index;
                    }
                }
                newInd++;
            }
            else if (dgvTable.CurrentRow != null)
            {
                newInd = dgvTable.CurrentRow.Index + 1;
            }
            else
            {
                newInd = dgvTable.Rows.Count;
            }

            // insert the item
            tableView.Items.Insert(newInd, item);
            bsTable.ResetBindings(false);
            SelectTableItem(newInd, !tvCnl.Focused);
            Modified = true;
        }
示例#3
0
        /// <summary>
        /// Добавить элемент на основе канала из базы конфигурации
        /// </summary>
        private void AddItem()
        {
            if (dgvCnls.SelectedRows.Count > 0)
            {
                DataGridViewRow cnlRow = dgvCnls.SelectedRows[0];
                TableView.Item  item   = new TableView.Item();
                int             cnlNum = (int)cnlRow.Cells["colCnlNum"].Value;
                item.Caption = (string)cnlRow.Cells["colCnlName"].Value;

                if (bsCnls.DataSource == tblInCnl)
                {
                    item.CnlNum = cnlNum;
                }
                else
                {
                    item.CtrlCnlNum = cnlNum;
                }

                InsertItem(item);
            }
        }
示例#4
0
        private void btnMoveUpDownItem_Click(object sender, EventArgs e)
        {
            // move selected table item up or down
            if (GetSelectedRow(out DataGridViewRow row))
            {
                int curInd = row.Index;
                List <TableView.Item> items = tableView.Items;

                if (sender == btnMoveUpItem && curInd > 0 ||
                    sender == btnMoveDownItem && curInd < items.Count - 1)
                {
                    int            newInd = sender == btnMoveUpItem ? curInd - 1 : curInd + 1;
                    TableView.Item item   = items[curInd];
                    items.RemoveAt(curInd);
                    items.Insert(newInd, item);

                    bsTable.ResetBindings(false);
                    SelectTableItem(newInd);
                    Modified = true;
                }
            }
        }
示例#5
0
        private void btnMoveUpDownItem_Click(object sender, EventArgs e)
        {
            // перемещение выбранного элемента вверх или вниз
            DataGridViewSelectedRowCollection selRows = dgvItems.SelectedRows;

            if (selRows.Count == 1 || dgvItems.CurrentRow != null)
            {
                int  curInd  = selRows.Count > 0 ? selRows[0].Index : dgvItems.CurrentRow.Index;
                bool canMove = sender == btnMoveUpItem && curInd > 0 ||
                               sender == btnMoveDownItem && curInd < items.Count - 1;

                if (canMove)
                {
                    int            newInd = sender == btnMoveUpItem ? curInd - 1 : curInd + 1;
                    TableView.Item item   = items[curInd];
                    items.RemoveAt(curInd);
                    items.Insert(newInd, item);

                    bsItems.ResetBindings(false);
                    SelectItem(newInd);
                    SetModified(true);
                }
            }
        }
示例#6
0
        /// <summary>
        /// Отобразить форму настроек приложения
        /// </summary>
        public static void Show(TableView.Item item, DataTable tblInCnl, DataTable tblCtrlCnl,
                                DataTable tblObj, DataTable tblKP)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            if (tblInCnl == null)
            {
                throw new ArgumentNullException("tblInCnl");
            }
            if (tblCtrlCnl == null)
            {
                throw new ArgumentNullException("tblCtrlCnl");
            }
            if (tblObj == null)
            {
                throw new ArgumentNullException("tblObj");
            }
            if (tblKP == null)
            {
                throw new ArgumentNullException("tblKP");
            }

            // создание и перевод формы
            FrmItemInfo frmItemInfo = new FrmItemInfo();

            Localization.TranslateForm(frmItemInfo, "ScadaTableEditor.FrmItemInfo");

            // получение информации о входном канале
            if (item.CnlNum > 0)
            {
                string cnlNumStr = item.CnlNum.ToString();
                frmItemInfo.txtInCnlNum.Text = cnlNumStr;

                try
                {
                    DataView view = new DataView(tblInCnl);
                    view.RowFilter = "CnlNum = " + cnlNumStr;

                    if (view.Count > 0)
                    {
                        DataRowView rowView = view[0];
                        frmItemInfo.txtInCnlName.Text = (string)rowView["Name"];

                        int objNum = (int)rowView["ObjNum"];
                        if (objNum > 0)
                        {
                            frmItemInfo.txtInCnlObjNum.Text  = objNum.ToString();
                            frmItemInfo.txtInCnlObjName.Text = GetObjName(objNum, tblObj);
                        }

                        int kpNum = (int)rowView["KPNum"];
                        if (kpNum > 0)
                        {
                            frmItemInfo.txtInCnlKPNum.Text  = kpNum.ToString();
                            frmItemInfo.txtInCnlKPName.Text = GetKPName(kpNum, tblKP);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ScadaUtils.ShowError(AppPhrases.GetInCnlError + ":\n" + ex.Message);
                }
            }

            // получение информации о канале управления
            if (item.CtrlCnlNum > 0)
            {
                string ctrlCnlNumStr = item.CtrlCnlNum.ToString();
                frmItemInfo.txtCtrlCnlNum.Text = ctrlCnlNumStr;

                try
                {
                    DataView view = new DataView(tblCtrlCnl);
                    view.RowFilter = "CtrlCnlNum = " + ctrlCnlNumStr;

                    if (view.Count > 0)
                    {
                        DataRowView rowView = view[0];
                        frmItemInfo.txtCtrlCnlName.Text = (string)rowView["Name"];

                        int objNum = (int)rowView["ObjNum"];
                        if (objNum > 0)
                        {
                            frmItemInfo.txtCtrlCnlObjNum.Text  = objNum.ToString();
                            frmItemInfo.txtCtrlCnlObjName.Text = GetObjName(objNum, tblObj);
                        }

                        int kpNum = (int)rowView["KPNum"];
                        if (kpNum > 0)
                        {
                            frmItemInfo.txtCtrlCnlKPNum.Text  = kpNum.ToString();
                            frmItemInfo.txtCtrlCnlKPName.Text = GetKPName(kpNum, tblKP);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ScadaUtils.ShowError(AppPhrases.GetCtrlCnlError + ":\n" + ex.Message);
                }
            }

            // отображение формы
            frmItemInfo.ShowDialog();
        }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the class.
 /// </summary>
 public FrmItemInfo(TableView.Item item, BaseTables baseTables)
     : this()
 {
     this.item       = item ?? throw new ArgumentNullException("item");
     this.baseTables = baseTables ?? throw new ArgumentNullException("baseTables");
 }