Esempio n. 1
0
 static public DialogResult ShowDialog(string caption_, string message_, string check_message_, Icon icon)
 {
     // Call the private constructor so the users only need to call this
     // function, which is similar to MessageBox.Show.
     // Returns a standard DialogResult.
     using (QuestionDelete dialog = new QuestionDelete(caption_, message_, check_message_, icon))
     {
         DialogResult result = dialog.ShowDialog();
         return(result);
     }
 }
Esempio n. 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                int idTable   = -1;
                int typetable = -1;
                foreach (tablesInfo ti in Program.tables_info)
                {
                    if (ti.idTable == ((itemObj)listBox1.SelectedItem).Id_o)
                    {
                        idTable   = ti.idTable;
                        typetable = ti.type;
                        break;
                    }
                }
                List <itemObj> list_tables = new List <itemObj>();
                if (typetable == 3) // если интервал
                {
                    SqlWork sqlCmd = new SqlWork();
                    sqlCmd.sql = "SELECT id_table,name_db FROM " + Program.scheme + ".table_field_info WHERE ref_table=" + idTable;
                    sqlCmd.Execute(false);
                    while (sqlCmd.CanRead())
                    {
                        list_tables.Add(new itemObj(sqlCmd.GetInt32(0), sqlCmd.GetString(1), sqlCmd.GetString(1)));
                    }
                    sqlCmd.Close();
                }

                DialogResult dr = DialogResult.Cancel;
                switch (typetable)
                {
                case 1:
                    dr = QuestionDelete.ShowDialog(Rekod.Properties.Resources.TLE_DeletingLayer,
                                                   Rekod.Properties.Resources.TLE_DeletingLayerAsk,
                                                   Rekod.Properties.Resources.FELC_Forever);
                    break;

                case 2:
                    dr = QuestionDelete.ShowDialog(Rekod.Properties.Resources.TLE_DeletingCatalog,
                                                   Rekod.Properties.Resources.TLE_Attention + "\n" + Rekod.Properties.Resources.TLE_DeletingCatalogAsk,
                                                   Rekod.Properties.Resources.FELC_Forever);
                    break;

                case 3:
                    dr = QuestionDelete.ShowDialog(Rekod.Properties.Resources.TLE_DeletingInterval,
                                                   Rekod.Properties.Resources.TLE_Attention + "\n" + Rekod.Properties.Resources.TLE_DeletingIntervalAsk,
                                                   Rekod.Properties.Resources.FELC_Forever, SystemIcons.Warning);
                    break;

                case 4:
                    dr = QuestionDelete.ShowDialog(Rekod.Properties.Resources.TLE_DeletingTable,
                                                   Rekod.Properties.Resources.TLE_Attention + "\n" + Rekod.Properties.Resources.TLE_DeletingTableAsk,
                                                   Rekod.Properties.Resources.FELC_Forever);
                    break;
                }
                if (dr != DialogResult.Cancel)
                {
                    SqlWork sqlCmd = new SqlWork();
                    foreach (itemObj io in list_tables)
                    {
                        sqlCmd     = new SqlWork();
                        sqlCmd.sql = "UPDATE " + Program.scheme + ".table_info SET default_style=true,style_field='style' WHERE id=" + io.Id_o + " AND style_field='" + io.Name_o + "'";
                        sqlCmd.Execute(true);
                        sqlCmd.Close();
                    }
                    // удалить все ссылки на связанные таблицы
                    sqlCmd     = new SqlWork();
                    sqlCmd.sql = String.Format("UPDATE {0}.table_field_info SET ref_table=null, ref_field=null, ref_field_name=null, is_reference=false, is_interval = FALSE WHERE ref_table={1};", Program.scheme, idTable);
                    sqlCmd.Execute(true);
                    sqlCmd.Close();
                    sqlCmd     = new SqlWork();
                    sqlCmd.sql = "SELECT " + Program.scheme + ".delete_table(" + ((itemObj)listBox1.SelectedItem).Id_o + "," + (dr == DialogResult.Yes).ToString() + ")";
                    sqlCmd.Execute(true);
                    sqlCmd.Close();
                    classesOfMetods.DeleteLayerInMap(((itemObj)listBox1.SelectedItem).Id_o);
                    try
                    {
                        SyncController.DeleteTable(((itemObj)listBox1.SelectedItem).Id_o, false);
                    }
                    catch (Exception ex)
                    {
                        Classes.workLogFile.writeLogFile(ex, false, true);
                    }
                    classesOfMetods cls = new classesOfMetods();

                    cls.reloadInfo();
                    loadTables();

                    MessageBox.Show(((dr == DialogResult.Yes) ? Rekod.Properties.Resources.TLE_DeleteForever : Rekod.Properties.Resources.TLE_DeleteNoForever));
                    Control[] cntrs = parent.Controls.Find("CloseButton", true);
                    if (cntrs.Length == 1)
                    {
                        ((CloseButton)cntrs[0]).CloseBox(e);
                    }
                }
            }
        }
        private void button2_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                string dependantTables = "";
                using (SqlWork sqlCmd = new SqlWork())
                {
                    sqlCmd.sql = String.Format("SELECT DISTINCT ti.name_map as name FROM {0}.table_field_info tfi, {0}.table_info ti WHERE (ref_field = {1} OR ref_field_end = {1} OR ref_field_name = {1}) AND ti.id = tfi.id_table;", Program.scheme, idF);
                    sqlCmd.ExecuteReader();
                    while (sqlCmd.CanRead())
                    {
                        dependantTables += sqlCmd.GetString("name") + Environment.NewLine;
                    }
                }

                if (dependantTables != "")
                {
                    MessageBox.Show(String.Format(@Rekod.Properties.Resources.FELC_CannotDeleteField, dependantTables.Remove(dependantTables.Length - 2)),
                                    Rekod.Properties.Resources.FELC_DeletingFields, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                else
                {
                    var          fi         = classesOfMetods.getFieldInfo(idF);
                    var          ti         = classesOfMetods.getTableInfo(fi.idTable);
                    bool         styleField = !ti.Style.DefaultStyle && ti.style_field == fi.nameDB || ti.Style.DefaultStyle && ti.Style.Range.RangeColumn == fi.nameDB;
                    bool         labelField = ti.label_showlabel && ti.lableFieldName.Contains("((" + fi.nameDB + ")::text)");
                    DialogResult dr         = QuestionDelete.ShowDialog(
                        Rekod.Properties.Resources.FELC_DeletingFields,
                        (styleField ? Rekod.Properties.Resources.FELC_DeletingFieldStyle + Environment.NewLine : "") +
                        (labelField ? Rekod.Properties.Resources.FELC_DeletingFieldLabel + Environment.NewLine : "") +
                        Rekod.Properties.Resources.FELC_DeletingFieldAsk,
                        Rekod.Properties.Resources.FELC_Forever);
                    if (dr != DialogResult.Cancel)
                    {
                        List <string> dep_table_list = new List <string>();
                        SqlWork       sqlCmd         = new SqlWork();
                        sqlCmd.sql = String.Format("SELECT sys_scheme.get_dependent_by_field('{0}', '{1}') as table_name;", ti.nameDB, fi.nameDB);
                        sqlCmd.ExecuteReader();
                        while (sqlCmd.CanRead())
                        {
                            String table_name = sqlCmd.GetValue <string>("table_name");
                            if (table_name != ti.view_name)
                            {
                                dep_table_list.Add(table_name);
                                if (dep_table_list.Count >= 7)
                                {
                                    dep_table_list.Add("...");
                                    break;
                                }
                            }
                        }
                        sqlCmd.Close();

                        if (dep_table_list.Count > 0)
                        {
                            MessageBox.Show("Безвозвратное удаление атрибута невозможно! Имеются следующие зависимые объекты:" + Environment.NewLine +
                                            String.Join("," + Environment.NewLine, dep_table_list.ToArray()), "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                            return;
                        }

                        sqlCmd     = new SqlWork();
                        sqlCmd.sql = "SELECT " + Program.scheme + ".delete_field(" + ((itemObjOrdered)listBox1.SelectedItem).Id_o.ToString() + "," + (dr == DialogResult.Yes).ToString() + ")";
                        sqlCmd.Execute(true);
                        sqlCmd.Close();

                        classesOfMetods.reloadLayer(ti.idTable);
                        loadFields(id);

                        DBTablesEdit.SyncController.ReloadTable(ti.idTable);
                    }
                }
            }
        }