private void buttonDown_Click(object sender, EventArgs e)
        {
            ColumnsListView colList = CurrentList;

            if (colList == null)
            {
                return;
            }

            ColParams colParams = ColumnsLists[colList];

            if (colParams == null)
            {
                return;
            }

            if (colList.SelectedRows.Count == 1)
            {
                colList.SuspendLayout();
                int row = colList.SelectedRows[0].Index;
                if (row < colList.Rows.Count - 1)
                {
                    int    col = colList.Columns["OrderIndex"].Index;
                    object a   = colList[col, row].Value;
                    object b   = colList[col, row + 1].Value;

                    colList[col, row].Value     = b;
                    colList[col, row + 1].Value = a;
                }
                colList.Sort(colList.Columns["OrderIndex"], ListSortDirection.Ascending);
                colList.ResumeLayout();
            }
            UpdateButtons(colList, e);
        }
        private void SettingsColumnsDialog_Load(object sender, EventArgs e)
        {
            foreach (ColumnsListView colList in ColumnsLists.Keys)
            {
                ColParams colParams = ColumnsLists[colList];
                //if (ColumnsLists.Count > 1)
                //{
                TabPage page = new TabPage(colParams.FriendlyName)
                {
                    Name = colParams.FriendlyName
                };
                page.Controls.Add(colList);
                colList.Visible = true;
                tabControl.TabPages.Add(page);
                //}

                colList.SuspendLayout();
                foreach (ColParam col in colParams.Values.Where(col => col != null && !col.IsSystemField))
                {
                    colList.Rows.Add();
                    int i = colList.Rows.Count - 1;
                    colList[colList.Columns["Visibility"].Index, i].Value    = col.Visible;
                    colList[colList.Columns["SortIndex"].Index, i].Value     = string.Empty;
                    colList[colList.Columns["SortDirection"].Index, i].Value = SortOrder.None;
                    colList[colList.Columns["FriendlyName"].Index, i].Value  = col.HeaderName;
                    colList[colList.Columns["Name"].Index, i].Value          = col.Name;
                    colList[colList.Columns["IsKeyField"].Index, i].Value    = col.IsKeyField;
                    colList[colList.Columns["OrderIndex"].Index, i].Value    = col.Index;
                }
                string[] _s = colParams.SortOrder.ToLower().Replace("[", "").Replace("]", "").Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);

                int sortIndex = 1;
                for (int i = 0; i < _s.Length && sortIndex < 6; i++)
                {
                    for (int row = 0; row < colList.Rows.Count && sortIndex < 6; row++)
                    {
                        if (
                            colList[colList.Columns["Name"].Index, row].Value.ToString().ToLower().Equals(_s[i].ToLower()))
                        {
                            i++;
                            colList[colList.Columns["SortIndex"].Index, row].Value     = sortIndex.ToString();
                            colList[colList.Columns["SortDirection"].Index, row].Value = _s[i].ToLower().Equals("asc") ? SortOrder.Ascending : SortOrder.Descending;
                            sortIndex++;
                        }
                    }
                }

                colList.SelectionChanged += UpdateButtons;
                colList.ResumeLayout();
                UpdateButtons(colList, null);
            }
            LoadReg();

            if (m_style != null && tabControl.TabPages.Count > 0 && tabControl.TabPages.ContainsKey(m_style.FriendlyName))
            {
                tabControl.SelectTab(tabControl.TabPages[m_style.FriendlyName]);
            }
        }
        public SettingsColumnsDialog(Style style, Folder optionFolder, Style finalStyle)
        {
            try
            {
                this.finalStyle = finalStyle;
                InitializeComponent();
                ComponentResourceManager resources = new ComponentResourceManager(typeof(Forms.MainFormDialog));
                this.Text         = resources.GetObject("menuItem8.Text").ToString() + "->" + resources.GetObject("mIColumns.Text").ToString().TrimEnd('.');
                this.optionFolder = optionFolder;
                FolderCollection savedStyles = optionFolder.GetSavedFolders();
                m_style = style;

                if (/*style == null &&*/ savedStyles.Count > 0)
                {
                    panelColumns.Controls.Remove(list);
                    list.Visible = false;

                    int countAvailableStyles = 0;

                    foreach (Folder folder in savedStyles)
                    {
                        string    name    = folder.Name;
                        ColParams colsNew = new ColParams(folder, false);
                        if (colsNew.WasInited && colsNew.NotEmpty(true))
                        {
                            ColumnsListView listNew = (ColumnsListView)list.Clone();
                            ColumnsLists.Add(listNew, colsNew);

                            countAvailableStyles++;
                        }
                    }

                    if (countAvailableStyles == 1)
                    {
                        ColumnsLists.Clear();
                        TheOnlyStyleToEdit(finalStyle);
                    }
                    else
                    {
                        subLayout = Environment.Layout.Folders.Add("SettingsColumns");
                        Closed   += SettingsColumnsDialog_Closed;
                    }
                }
                //else
                //    TheOnlyStyleToEdit(style);
            }
            catch (Exception ex)
            {
                Environment.CmdManager.Commands["ResetColumns"].Execute();
            }
        }
        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (ColumnsListView colList in ColumnsLists.Keys)
                {
                    ColParams colParams = ColumnsLists[colList];
                    string[]  sortOrder = new string[5];
                    colParams.SortOrder = string.Empty;

                    for (int i = 0; i < colList.Rows.Count; i++)
                    {
                        string colName = colList[colList.Columns["Name"].Index, i].Value.ToString();
                        colParams.GetParam(colName).Visible    = (bool)colList[colList.Columns["Visibility"].Index, i].Value;
                        colParams.GetParam(colName).HeaderName = colList[colList.Columns["FriendlyName"].Index, i].Value.ToString();
                        colParams.GetParam(colName).IsKeyField = (bool)colList[colList.Columns["IsKeyField"].Index, i].Value;
                        colParams.GetParam(colName).Index      = int.Parse(colList[colList.Columns["OrderIndex"].Index, i].Value.ToString());

                        if (!string.IsNullOrEmpty(colList[colList.Columns["SortIndex"].Index, i].Value.ToString()))
                        {
                            int       _sortIndex = int.Parse(colList[colList.Columns["SortIndex"].Index, i].Value.ToString());
                            SortOrder _sortOrder = (SortOrder)colList[colList.Columns["SortDirection"].Index, i].Value;
                            sortOrder[_sortIndex - 1] = colName + (_sortOrder == SortOrder.Ascending ? " asc" : " desc");
                        }
                    }

                    StringBuilder sb = new StringBuilder();
                    foreach (string t in sortOrder.Where(t => !string.IsNullOrEmpty(t)))
                    {
                        sb.Append(t);
                        sb.Append(",");
                    }
                    colParams.SortOrder = sb.ToString().TrimEnd(new[] { ',', ' ' }).TrimStart(new[] { ',', ' ' });
                    colParams.Save();
                }
            }
            catch (Exception ex)
            {
                Lib.Win.Data.Env.WriteToLog(ex);
            }
            finalStyle.ReloadData();

            End(DialogResult.OK);
        }