Exemplo n.º 1
0
        public string path_to_lxd;                                                          // Storing path after user has selected file in path_lxd_Click

        private void tbl_create_Click(object sender, EventArgs e)
        {
            Table table = new Table();                                                      // Creating a table object

            if (!MgBox.editState)
            {
                if (!validate(tbl_name.Text, tbl_num.Text, tbl_id.Text))   //, path_to_lxd        // This validator is dumb but, oh well..
                {                                                          //
                    return;
                }

                MgBox.positionY = tableList.Any() ? MgBox.positionY += 30 : MgBox.positionY = 10;

                table.Create(tbl_name.Text, tbl_num.Text, tbl_id.Text, path_to_lxd, tbl_ip.Text, MgBox.positionY);

                Panel tblPanel = table.GetPanel();                              // Creating new table object and returning list of elements which has to be rendered

                tableList.Add(table);                                           // Adding created table to table list

                Read_write_xml.Write(tableList, table.Number + " added", true); // Writi with backup

                table_list_form.readAndAdd();

                MessageBox.Show("Table is added: " + table.Name + " : " + table.Number);

                // Emty the textboxes
                tbl_name.Text = "";
                tbl_num.Text  = "";
                tbl_id.Text   = "";
                tbl_ip.Text   = "";
                path_to_lxd   = "";
            }
            else
            {
                if (!validate(tbl_name.Text, tbl_num.Text, tbl_id.Text))   //, path_to_lxd        // This validator is dumb but, oh well..
                {                                                          //
                    return;
                }

                int tableToEditIndex = tableList.FindIndex(i => i.Name == MgBox.tableToEdit);

                Table tableObj = tableList[tableToEditIndex];

                tableObj.Name     = tbl_name.Text.Trim();
                tableObj.Number   = tbl_num.Text.Trim();
                tableObj.Id       = tbl_id.Text.Trim();
                tableObj.Path_lxd = path_to_lxd;
                tableObj.Tbl_ip   = tbl_ip.Text.Trim();

                tableList[tableToEditIndex] = tableObj;

                Read_write_xml.Write(tableList, tbl_num.Text.Trim() + " edited", true); // W

                this.Close();
                table_list_form.readAndAdd();
            }
        }
Exemplo n.º 2
0
        protected void context_edit_clic(object sender, EventArgs e)
        {
            List <Table> tableList = MgBox.tableList;

            MenuItem item = (sender as MenuItem);

            ContextMenu owner = item.Parent as ContextMenu;

            switch (item.Text)
            {
            case "delete":
                var confirmDelete = MessageBox.Show("Are you sure to delete this table?", "Confirm Delete!!", MessageBoxButtons.OKCancel);
                if (confirmDelete == DialogResult.OK)
                {
                    int itemToRemove = tableList.FindIndex(i => i.Name == owner.SourceControl.Text);
                    tableList.RemoveAt(itemToRemove);
                    Read_write_xml.Write(tableList, "table removed", true);     // Write with backup
                    if (pnl_search_overlay.Visible == true)
                    {
                        List <Table> result = MgBox.tableList.FindAll(i => i.Number.Contains(search_bar.Text));
                        readAndAdd(result, pnl_search_overlay);
                    }

                    readAndAdd();
                }
                else
                {
                    return;
                }

                break;

            case "edit":
                string num = tableList.Find(i => i.Name == owner.SourceControl.Text).Number;

                var confirmEdit = MessageBox.Show("Are you sure to edit this table?", "Edit: " + num, MessageBoxButtons.OKCancel);
                if (confirmEdit == DialogResult.OK)
                {
                    MgBox.editState   = true;
                    MgBox.tableToEdit = tableList.Find(i => i.Name == owner.SourceControl.Text).Name;

                    Create_table create_table = new Create_table(this);         // Initializing Create_table form and passing this form "designer?!?" as a parameter
                    create_table.ShowDialog();
                }
                else
                {
                    return;
                }

                break;
            }
        }
Exemplo n.º 3
0
        // Reading from XML onProgramStart and rendering existing tables in UI
        public void readAndAdd(List <Table> list = null, Panel overlay = null)
        {
            Table table = new Table();

            Read_write_xml.Read();                              // Getting list of tables and store it in Mgbox
            MgBox.positionY = 10;
            List <Table> tableList     = list ?? MgBox.tableList;
            Panel        placeToRender = overlay ?? tbl_list_panel;

            if (placeToRender == overlay)
            {
                tbl_list_panel.Visible = false;
                overlay.Visible        = true;
            }

            placeToRender.Controls.Clear();

            if (tableList.Any())
            {
                for (int i = 0; i < tableList.Count; i++)       // If list is not emty - loop trough list and render each table in UI
                {
                    table = tableList[i];
                    table.Create(
                        table.Name,
                        table.Number,
                        table.Id,
                        table.Path_lxd,
                        table.Tbl_ip,
                        MgBox.positionY);

                    placeToRender.Controls.Add(table.GetPanel());

                    MgBox.positionY += 30;
                }
            }
        }