public Form_filter(TableSettings tableSettings)
 {
     InitializeComponent();
     settings = tableSettings;
     if (settings.IconSettings.Count == 0)
     {
         button1.Enabled = false;
     }
 }
Beispiel #2
0
        public Form_filter(TableSettings tableSettings)
        {
            InitializeComponent();
            settings = tableSettings;
            if (settings.IconSettings.Count == 0)
            {
                button1.Enabled = false;
            }

            SetColorScheme();
            Program.ColorManager.SchemeChanded += ColorManager_SchemeChanded;
        }
Beispiel #3
0
        public void LoadTableByText(string text)
        {
            SQLiteTableReader reader = new SQLiteTableReader(Application.StartupPath, Program.DbPath);

            reader.Connect();
            var data = reader.GetDataTableByText(text, Program.TableDisplaySettings);

            reader.Disconnect();
            listBox1.ClearSelected();
            if (data.table == null)
            {
                dataGridView1.DataSource = null;
                currentTableSettings     = null;
                currentTable             = null;
            }
            else
            {
                CheckBeforeReload();
                SetDataTable(data.settings, data.table);
            }
        }
Beispiel #4
0
        public void LoadTableByIds(string tableName, List <Int64> ids)
        {
            var tableSetting = Program.TableDisplaySettings.Find(a => a.TableName.Equals(tableName));

            SQLiteTableReader reader = new SQLiteTableReader(Application.StartupPath, Program.DbPath);

            reader.Connect();
            var table = reader.GetDataTable(tableSetting, ids);

            reader.Disconnect();
            listBox1.ClearSelected();
            if (table == null)
            {
                dataGridView1.DataSource = null;
                currentTableSettings     = null;
                currentTable             = null;
            }
            else
            {
                CheckBeforeReload();
                SetDataTable(tableSetting, table);
            }
        }
Beispiel #5
0
        public List <TableSettings> LoadSettings()
        {
            List <TableSettings> settings = new List <TableSettings>();
            StreamReader         reader   = new StreamReader(IniFile);

            while (!reader.EndOfStream)
            {
                if (reader.Peek() == '#')
                {
                    reader.ReadLine();
                    continue;
                }
                if (reader.Peek() != '[')
                {
                    throw new Exception("Формат файла нарушен!");
                }
                TableSettings ts = new TableSettings();
                ts.TableName = reader.ReadLine();
                ts.TableName = ts.TableName.Substring(1, ts.TableName.Length - 2);
                while (!reader.EndOfStream && reader.Peek() != '[')
                {
                    string line = reader.ReadLine();
                    if (string.IsNullOrWhiteSpace(line) || line.StartsWith("#"))
                    {
                        continue;
                    }
                    int splitIndex = line.IndexOf("=");
                    if (splitIndex == -1)
                    {
                        throw new Exception("Ошибка разбора строки ключ=параметр");
                    }
                    string[] subItems = new string[2];
                    subItems[0] = line.Substring(0, splitIndex).Trim();
                    subItems[1] = line.Substring(splitIndex + 1).Trim();
                    switch (subItems[0].Trim())
                    {
                    case "TextIndexColumn":
                    {
                        ts.TextIndexColumn = subItems[1];
                        break;
                    }

                    case "DisplayColumms":
                    {
                        string[] listColumn = subItems[1].Split(new char[] { ',' });
                        foreach (var item in listColumn)
                        {
                            ts.DisplayColumms.Add(item.Trim());
                        }
                        break;
                    }

                    case "IconSettings":
                    {
                        string[] listParam = subItems[1].Split(new char[] { ',' });
                        if (listParam.Length < 2)
                        {
                            throw new Exception("В секции IconSettings должно быть два параметра и более.");
                        }
                        List <string> dirs = new List <string>();
                        for (int i = 1; i < listParam.Length; i++)
                        {
                            dirs.Add(listParam[i]);
                        }
                        ts.IconSettings.Add(new KeyValuePair <string, List <string> >(listParam[0], dirs));
                        break;
                    }

                    case "TextTypeAndName":
                    {
                        string[] listParam = subItems[1].Split(new char[] { ',' });
                        if (listParam.Length != 2)
                        {
                            throw new Exception("В секции TextTypeAndName должно быть два параметра.");
                        }
                        ts.TextTypeAndName.Add(new KeyValuePair <int, string>(Convert.ToInt32(listParam[0].Trim()), listParam[1].Trim()));
                        break;
                    }

                    case "CustomQueryMainTable":
                    {
                        ts.CustomQueryMainTable = subItems[1];
                        break;
                    }

                    case "RowHeight":
                    {
                        ts.RowHeight = Convert.ToInt32(subItems[1]);
                        break;
                    }

                    case "ColumnWidth":
                    {
                        string[] listParam = subItems[1].Split(new char[] { ',' });
                        if (listParam.Length != 2)
                        {
                            throw new Exception("В секции ColumnWidth должно быть два параметра.");
                        }
                        ts.ColumnWidth.Add(new KeyValuePair <string, int>(listParam[0].Trim(), Convert.ToInt32(listParam[1].Trim())));
                        break;
                    }
                    }
                }
                settings.Add(ts);
            }

            return(settings);
        }
Beispiel #6
0
        private void SetDataTable(TableSettings settings, DataTable preloadedTable = null)
        {
            DataTable table = null;

            if (preloadedTable == null)
            {
                SQLiteTableReader reader = new SQLiteTableReader(Application.StartupPath, Program.DbPath);
                reader.Connect();
                table = reader.GetDataTable(settings);
                reader.Disconnect();
            }
            else
            {
                table = preloadedTable;
            }

            currentDictonary = Program.TransDict.LoadDictonary(Path.Combine(Program.DictonariesDir, settings.TableName + "_" + toolStripComboBox1.SelectedItem + ".txt"));
            if (currentDictonary.Count > 0)
            {
                foreach (var item in settings.TextTypeAndName)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        string original = (string)table.Rows[i][item.Value];
                        if (!string.IsNullOrWhiteSpace(original))
                        {
                            string trans = Program.TransDict.GetTranslation(currentDictonary, original);
                            if (!string.IsNullOrWhiteSpace(trans))
                            {
                                table.Rows[i][item.Value + "_trans"] = trans;
                            }
                        }
                    }
                }
            }
            table.AcceptChanges();
            dataGridView1.RowTemplate.Height = settings.RowHeight;
            dataGridView1.DataSource         = table;
            //dataGridView1.RowTemplate.Height = 50;
            for (int i = 0; i < dataGridView1.ColumnCount; i++)
            {
                if (dataGridView1.Columns[i].ValueType == typeof(Image))
                {
                    ((DataGridViewImageColumn)dataGridView1.Columns[i]).ImageLayout = DataGridViewImageCellLayout.Zoom;
                    dataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                }
                else if (dataGridView1.Columns[i].Name.EndsWith("_imagePath"))
                {
                    dataGridView1.Columns[i].Visible = false;
                }
                else
                {
                    dataGridView1.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                    dataGridView1.Columns[i].ReadOnly     = true;
                }
            }
            foreach (var item in settings.TextTypeAndName)
            {
                dataGridView1.Columns[item.Value].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                dataGridView1.Columns[item.Value].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
                dataGridView1.Columns[item.Value].ReadOnly = false;

                dataGridView1.Columns[item.Value + "_trans"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
                dataGridView1.Columns[item.Value + "_trans"].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
                dataGridView1.Columns[item.Value + "_trans"].ReadOnly = false;
            }
            foreach (var item in settings.ColumnWidth)
            {
                dataGridView1.Columns[item.Key].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
                dataGridView1.Columns[item.Key].Width        = item.Value;
                dataGridView1.Columns[item.Key].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            }

            currentTableSettings = settings;
            currentTable         = table;
            if (filter != null)
            {
                filter.Close();
                filter = null;
            }

            // var test = table.DefaultView.RowFilter = "LEN(SkillName)=5";
        }
Beispiel #7
0
        public DataTable GetDataTable(TableSettings settings, List <Int64> filterByTextIds = null)
        {
            var command = connection.CreateCommand();

            if (!string.IsNullOrWhiteSpace(settings.TextIndexColumn) && settings.TextTypeAndName.Count > 0)
            {
                List <string> textQueries = new List <string>();
                string        mainQuery   = "";
                if (string.IsNullOrWhiteSpace(settings.CustomQueryMainTable))
                {
                    mainQuery = "(SELECT " + settings.TextIndexColumn + ", " + string.Join(", ", settings.DisplayColumms) +
                                " FROM " + settings.TableName + ") as tm";
                }
                else
                {
                    mainQuery = "(" + settings.CustomQueryMainTable + ") as tm";
                }
                textQueries.Add(mainQuery);
                int a = 0;
                foreach (var item in settings.TextTypeAndName)
                {
                    string query = "(SELECT \"index\", text FROM text_data WHERE category=" + item.Key + ") as t" + a++;
                    textQueries.Add(query);
                }

                StringBuilder sb = new StringBuilder();
                sb.Append("SELECT ");
                for (int i = 0; i < settings.DisplayColumms.Count; i++)
                {
                    sb.Append("tm." + settings.DisplayColumms[i]);
                    if (i != settings.DisplayColumms.Count - 1)
                    {
                        sb.Append(", ");
                    }
                }
                for (int i = 0; i < settings.TextTypeAndName.Count; i++)
                {
                    sb.Append(", t" + i + ".text as " + settings.TextTypeAndName[i].Value);
                    sb.Append(", \"\" as " + settings.TextTypeAndName[i].Value + "_trans");
                }
                sb.Append(" FROM ");
                sb.Append(string.Join(", ", textQueries));
                sb.Append(" WHERE ");
                for (int i = 0; i < settings.TextTypeAndName.Count; i++)
                {
                    sb.Append("tm." + settings.TextIndexColumn + " = " + "t" + i + ".\"index\"");
                    if (i != settings.TextTypeAndName.Count - 1)
                    {
                        sb.Append(" AND ");
                    }
                }

                if (filterByTextIds != null)
                {
                    sb.Append(" AND (");
                    for (int i = 0; i < filterByTextIds.Count; i++)
                    {
                        sb.Append("tm." + settings.TextIndexColumn + " = " + filterByTextIds[i]);
                        if (i < filterByTextIds.Count - 1)
                        {
                            sb.Append(" OR ");
                        }
                    }
                    sb.Append(")");
                }
                command.CommandText = sb.ToString();
            }
            else
            {
                if (string.IsNullOrWhiteSpace(settings.CustomQueryMainTable))
                {
                    command.CommandText = "SELECT " + string.Join(", ", settings.DisplayColumms) +
                                          " FROM " + settings.TableName;
                }
                else
                {
                    command.CommandText = settings.CustomQueryMainTable;
                }
            }
            DataTable table = new DataTable(settings.TableName);

            using (var reader = command.ExecuteReader())
            {
                bool      useImage = false;
                DataTable metadata = reader.GetSchemaTable();
                for (int i = 0; i < metadata.Rows.Count; i++)
                {
                    string cName = metadata.Rows[i][SchemaTableColumn.ColumnName].ToString();
                    Type   cType = (Type)metadata.Rows[i][SchemaTableColumn.DataType];
                    table.Columns.Add(cName, cType);

                    if (settings.IconSettings.Count > 0)
                    {
                        int iconIndex = settings.IconSettings.FindIndex(a => a.Key.Equals(cName));
                        if (iconIndex != -1)
                        {
                            useImage = true;
                            table.Columns.Add(cName + "_image", typeof(Image));
                            table.Columns.Add(cName + "_imagePath", typeof(string));
                        }
                    }
                }
                while (reader.Read())
                {
                    var row = table.NewRow();
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        string cName     = reader.GetName(i);
                        int    iconIndex = -1;
                        if (useImage && (iconIndex = settings.IconSettings.FindIndex(a => a.Key.Equals(cName))) != -1)
                        {
                            object icon = reader[i];
                            row[cName] = icon;
                            var iconPath = FindFile(appPath, settings.IconSettings[iconIndex].Value, icon + ".png");
                            if (iconPath.fullPath != null)
                            {
                                //Image img = Image.FromFile(iconPath);

                                row[cName + "_image"]     = Program.IconDB.GetImageByKey(iconPath.PathOnRoot, icon.ToString());
                                row[cName + "_imagePath"] = iconPath.fullPath;
                            }
                        }
                        else
                        {
                            if (settings.TextTypeAndName.FindIndex(b => b.Value.Equals(cName)) != -1)
                            {
                                row[cName] = ((string)reader[i]).Replace("\\n", "");
                            }
                            else
                            {
                                row[cName] = reader[i];
                            }
                        }
                    }
                    table.Rows.Add(row);
                }
            }

            TableModifier.ModifyTable(ref table);
            return(table);
        }