private void buttonBringDown_Click(object sender, EventArgs e) { if (listBox1.SelectedItems.Count > 0) { List <itemObjOrdered> lllist = new List <itemObjOrdered>(); int max = 0; foreach (itemObjOrdered sel in listBox1.SelectedItems) { if (listBox1.Items.IndexOf(sel) > max) { max = listBox1.Items.IndexOf(sel); } lllist.Add(sel); } if (max < listBox1.Items.Count - 1) { listBox1.ClearSelected(); for (int i = lllist.Count - 1; i >= 0; i--) { itemObjOrdered sel = lllist[i]; int k = listBox1.Items.IndexOf(sel); listBox1.Items.Remove(sel); listBox1.Items.Insert(k + 1, sel); listBox1.SelectedItems.Add(sel); } } } }
public void reloadGroups() { itemObjOrdered selectedItem = comboBox1.SelectedItem as itemObjOrdered; comboBox1.Items.Clear(); List <itemObjOrdered> list_groups = gf.LoadGroups(); itemObjOrdered[] arr_group = new itemObjOrdered[list_groups.Count]; list_groups.CopyTo(arr_group); comboBox1.Items.AddRange(arr_group); label8.Text = changeTextOfCount2(comboBox1.Items.Count); if (selectedItem != null) { for (int i = 0; i < comboBox1.Items.Count; i++) { if ((comboBox1.Items[i] as itemObjOrdered).Id_o == selectedItem.Id_o) { comboBox1.SelectedItem = (comboBox1.Items[i] as itemObjOrdered); break; } } } if (comboBox1.SelectedItem == null) { panel1.Visible = false; } }
/// <summary> /// Метод загружает из базы все группы в List /// </summary> public List <itemObjOrdered> LoadGroups() { List <itemObjOrdered> list_groups = new List <itemObjOrdered>(); SqlWork sqlCmd = new SqlWork(); sqlCmd.sql = "SELECT id,name_group,descript,order_num FROM " + Program.scheme + ".table_groups ORDER BY order_num"; try { sqlCmd.Execute(false); } catch (Exception ex) { MessageBox.Show(ex.Message); sqlCmd.Close(); return(null); } while (sqlCmd.CanRead()) { int id_gr = sqlCmd.GetInt32(0); string name_gr = sqlCmd.GetString(1); string desc_gr = sqlCmd.GetString(2); int order_num = sqlCmd.GetInt32(3); itemObjOrdered io = new itemObjOrdered(id_gr, name_gr, desc_gr, order_num);//использую уже готовую структуру, вместо Layer там будет храниться описание list_groups.Add(io); } sqlCmd.Close(); return(list_groups); }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedItem != null) { panel1.Visible = true; listBox1.Items.Clear(); listt = gf.GetListTablesInOrOutGroup((comboBox1.SelectedItem as itemObj).Id_o, true); itemObjOrdered[] it = new itemObjOrdered[listt.Count]; listt.CopyTo(it); listBox1.Items.AddRange(it); listBox2.Items.Clear(); List <itemObjOrdered> listt2 = gf.GetListTablesInOrOutGroup((comboBox1.SelectedItem as itemObj).Id_o, false); itemObjOrdered[] it2 = new itemObjOrdered[listt2.Count]; listt2.CopyTo(it2); listBox2.Items.AddRange(it2); itemObj gr = gf.GetGroup((comboBox1.SelectedItem as itemObj).Id_o); textBox2.Text = gr.Layer; label6.Text = changeTextOfCount(listBox1.Items.Count); label7.Text = changeTextOfCount(listBox2.Items.Count); } else { panel1.Visible = false; } }
public void reloadTables() { listBox1.Items.Clear(); listBox2.Items.Clear(); List <itemObjOrdered> list_of_tables = new List <itemObjOrdered>(); List <itemObjOrdered> list_of_tables_visible = new List <itemObjOrdered>(); SqlWork sqlCmd = new SqlWork(); sqlCmd.sql = "SELECT id,name_map,order_num,default_visibl FROM " + Program.scheme + ".table_info WHERE type=1 ORDER BY order_num"; sqlCmd.Execute(false); while (sqlCmd.CanRead()) { itemObjOrdered item = new itemObjOrdered(sqlCmd.GetInt32(0), sqlCmd.GetString(1), sqlCmd.GetBoolean(3).ToString(), sqlCmd.GetInt32(2)); list_of_tables.Add(item); if (item.Layer.Contains("True")) { list_of_tables_visible.Add(item); } } sqlCmd.Close(); listBox1.Items.AddRange(list_of_tables_visible.ToArray()); listBox2.Items.AddRange(list_of_tables.ToArray()); label6.Text = changeTextOfCount(listBox1.Items.Count); label7.Text = changeTextOfCount(listBox2.Items.Count); }
/// <summary> /// Конструктор /// </summary> /// <param name="id_group">ID группы, если же создаеться новая то должно быть отрицательным</param> /// <param name="par">Форма на которой создаеться этот контрол</param> /// <param name="p_group">Контрол из которого создаеться</param> public AddEditGroup(itemObjOrdered itemObjOrd, EditGroupsOrder parent) { InitializeComponent(); _parent = parent; _id = itemObjOrd.Id_o; gf = new GroupFunct(); textBox1.Text = itemObjOrd.Name_o; textBox2.Text = itemObjOrd.Layer; }
private void reloadGroups() { listBox1.Items.Clear(); List <itemObjOrdered> listGroups = _groupFunct.LoadGroups(); itemObjOrdered[] arr_group = new itemObjOrdered[listGroups.Count]; listGroups.CopyTo(arr_group); listBox1.Items.AddRange(arr_group); labelCount.Text = listBox1.Items.Count.ToString() + " " + Rekod.Properties.Resources.EGO_groups; }
/// <summary> /// Возвращает список таблиц в(вне) группе /// </summary> /// <param name="id">ID группы</param> /// <param name="in_group">Если TRUE, то то список будет таблиц в группе, FALSE- список вне группы</param> /// <returns></returns> public List <itemObjOrdered> GetListTablesInOrOutGroup(int id, bool in_group) { List <itemObjOrdered> list_of_tables = new List <itemObjOrdered>(); SqlWork sqlCmd = new SqlWork(); if (in_group) { sqlCmd.sql = "SELECT t.id,t.name_db,t.name_map,g.order_num FROM " + Program.scheme + ".table_groups_table AS g," + Program.scheme + ".table_info AS t WHERE g.id_group=" + id.ToString() + " AND g.id_table=t.id AND t.type=1 and hidden = false ORDER BY g.order_num"; try { sqlCmd.Execute(false); } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } } else { sqlCmd.sql = "SELECT * FROM " + "(SELECT t.id,t.name_db,t.name_map FROM " + Program.scheme + ".table_info AS t WHERE t.type=1 and hidden=false" + " EXCEPT " + "SELECT DISTINCT t.id,t.name_db,t.name_map FROM " + Program.scheme + ".table_groups_table AS g," + Program.scheme + ".table_info AS t WHERE g.id_group=" + id.ToString() + " AND g.id_table=t.id and hidden = false " + ")AS al ORDER BY al.name_map"; try { sqlCmd.Execute(false); } catch (Exception ex) { MessageBox.Show(ex.Message); return(null); } } while (sqlCmd.CanRead()) { int id_table = sqlCmd.GetInt32(0); string db_name_table = sqlCmd.GetString(1); string map_name_table = sqlCmd.GetString(2); int ord = 0; if (in_group) { ord = sqlCmd.GetInt32(3); } itemObjOrdered io = new itemObjOrdered(id_table, map_name_table, db_name_table, ord); list_of_tables.Add(io); } sqlCmd.Close(); return(list_of_tables); }
private void button3_Click(object sender, EventArgs e) { for (int i = 0; i < listBox2.Items.Count; i++) { itemObjOrdered item = (listBox2.Items[i] as itemObjOrdered); if (item.Layer.Contains("True") != listBox1.Items.Contains(item) || i != item.order) { saveTable(item.Id_o, listBox1.Items.Contains(item), i); } } reloadTables(); }
private void editNameDescription() { itemObjOrdered itemObjOrd = listBox1.SelectedItem as itemObjOrdered; if (itemObjOrd != null) { AddEditGroup aeg = new AddEditGroup(itemObjOrd, this); aeg.Location = new Point((this.Width - aeg.Width) / 2, (this.Height - aeg.Height) / 2); groupBox1.Enabled = false; this.Controls.Add(aeg); aeg.BringToFront(); } }
public void save_data() { for (int k = 0; k < listBox1.Items.Count; k++) { itemObjOrdered obj = listBox1.Items[k] as itemObjOrdered; if (obj.order != k) {//сохраняем SqlWork sqlCmd = new SqlWork(); sqlCmd.sql = "UPDATE " + Program.scheme + ".table_field_info SET num_order=" + k.ToString() + " WHERE id=" + obj.Id_o; sqlCmd.Execute(true); sqlCmd.Close(); } } }
public void loadFields(int idT) { listBox1.Items.Clear(); SqlWork sqlCmd = new SqlWork(); sqlCmd.sql = "SELECT id,name_db,type_field,name_map,num_order FROM " + Program.scheme + ".table_field_info WHERE id_table=" + idT.ToString() + " ORDER BY num_order"; sqlCmd.Execute(false); while (sqlCmd.CanRead()) { itemObjOrdered item = new itemObjOrdered(sqlCmd.GetInt32(0), sqlCmd.GetString(1) + " (" + classesOfMetods.getTipField(sqlCmd.GetInt32(2)).nameTipData + ") - " + sqlCmd.GetString(3), sqlCmd.GetString(1), sqlCmd.GetInt32(4)); listBox1.Items.Add(item); } sqlCmd.Close(); label2.Text = changeTextOfCount(listBox1.Items.Count); }
private List <itemObjOrdered> getRecalcedGroupsOrderList() { SqlWork sqlCmd = new SqlWork(); sqlCmd.sql = String.Format("SELECT id, name_group, descript FROM {0}.{1} ORDER BY order_num", Program.scheme, "table_groups"); sqlCmd.Execute(false); List <itemObjOrdered> newGroupsOrder = new List <itemObjOrdered>(); int orderObj = 1; while (sqlCmd.CanRead()) { int idObj = sqlCmd.GetInt32(0); String nameObj = sqlCmd.GetValue <string>(1); String descObj = sqlCmd.GetValue <string>(2); itemObjOrdered itObjOrd = new itemObjOrdered(idObj, nameObj, descObj, orderObj); orderObj++; } return(newGroupsOrder); }
public void SetGroupsOrder(List <itemObjOrdered> newGroupsOrder) { try { SqlWork sqlCmd = new SqlWork(); sqlCmd.BeginTransaction(); for (int i = 0; i < newGroupsOrder.Count; i++) { itemObjOrdered itemObjOrd = newGroupsOrder[i]; int objId = itemObjOrd.Id_o; int orderNum = i + 1; sqlCmd.sql = String.Format("UPDATE {0}.{1} SET order_num={2} WHERE id={3}", Program.scheme, "table_groups", orderNum, objId); sqlCmd.ExecuteNonQuery(); } sqlCmd.EndTransaction(); } catch (Exception ex) { Rekod.Classes.workLogFile.writeLogFile(Rekod.Properties.Resources.GF_OrderGroup + " \n" + ex.Message, false, true); } }