コード例 #1
0
ファイル: CWebTreeView.cs プロジェクト: doctorgu/MadeIn9
        public static void AddHierarchical(TreeView tvw, DataTable dt,
                                           string ColumnNameId, string ColumnNameParentId, string ColumnNameText,
                                           string ValueToSelect, EventHandler SelectedNodeChanged)
        {
            tvw.Nodes.Clear();

            if (dt.Rows.Count > 0)
            {
                dt = CDataTable.GetHierarchicalDataTable(dt, ColumnNameId, ColumnNameParentId, "R");

                int    Seq   = Convert.ToInt32(dt.Rows[0][ColumnNameId]);
                string Title = dt.Rows[0][ColumnNameText].ToString();

                TreeNode tnRoot = new TreeNode(Title, Seq.ToString());
                if (tnRoot.Value == ValueToSelect)
                {
                    tnRoot.Selected = true;

                    if (SelectedNodeChanged != null)
                    {
                        SelectedNodeChanged(tvw, new EventArgs());
                    }
                }

                tnRoot.Expanded = true;
                tvw.Nodes.Add(tnRoot);
                AddChild(dt.Rows[0], tvw.Nodes[0], ColumnNameId, ColumnNameText, ValueToSelect, SelectedNodeChanged);
            }
        }
コード例 #2
0
        public static bool MoveRow(DataGridView dtg, int IndexFrom, int IndexTo)
        {
            if ((IndexFrom == IndexTo) || ((IndexFrom + 1) == IndexTo))
            {
                return(false);
            }

            DataTable dt = GetDataTable(dtg);

            DataRow dr = CDataTable.CopyRow(dt, IndexFrom, false);

            dt.Rows.RemoveAt(IndexFrom);

            int IndexNew = (IndexFrom < IndexTo) ? IndexTo - 1 : IndexTo;

            if ((IndexNew + 1) <= dt.Rows.Count)
            {
                dt.Rows.InsertAt(dr, IndexNew);
            }
            else
            {
                dt.Rows.Add(dr);
            }

            SelectNewRow(dtg, IndexNew);

            return(true);
        }
コード例 #3
0
        public static bool UpDownSelectedRowOfDataTable(DataGridView dtg, bool IsUp)
        {
            DataTable dt = GetDataTable(dtg);

            //dtg.CurrentCell.RowIndex를 읽으면 * 표시된 추가 행을 선택했을 때에도 마지막 행 값이 읽혀지므로 SelectedCells 사용.
            int IndexCur = dtg.SelectedCells[0].RowIndex;
            int IndexNew = CDataTable.UpDownRow(dt, IndexCur, IsUp);

            if (IndexCur == IndexNew)
            {
                return(false);
            }

            SelectNewRow(dtg, IndexNew);

            return(true);
        }
コード例 #4
0
        public static void CopyRow(DataGridView dtg, int IndexFrom, int IndexTo)
        {
            DataTable dt = GetDataTable(dtg);

            DataRow dr = CDataTable.CopyRow(dt, IndexFrom, true);

            int IndexNew = IndexTo;

            if ((IndexNew + 1) <= dt.Rows.Count)
            {
                dt.Rows.InsertAt(dr, IndexTo);
            }
            else
            {
                dt.Rows.Add(dr);
            }

            SelectNewRow(dtg, IndexNew);
        }
コード例 #5
0
        public static DataSet Merge(params DataSet[] aDs)
        {
            DataSet dsNew = new DataSet();


            for (int cl = 0; cl < aDs[0].Tables.Count; cl++)
            {
                DataTable[] dtToMerge = new DataTable[aDs.Length];
                for (int rw = 0; rw < aDs.Length; rw++)
                {
                    DataSet dsCur = aDs[rw];
                    dtToMerge[rw] = dsCur.Tables[cl];
                }

                DataTable dtMerged = CDataTable.Merge(dtToMerge);
                dsNew.Tables.Add(dtMerged);
            }

            return(dsNew);
        }
コード例 #6
0
        public static void SortByRelation(DataTable dt, string ColumnNameId, string ColumnNameParentId)
        {
            DataRow[] adr = dt.Select(string.Format("{0} > ''", ColumnNameParentId));
            if (adr.Length == 0)
            {
                return;
            }

            object ParentId = adr[0][ColumnNameParentId];
            SqlColumnTypeSimple ColumnType = CSql.GetColumnTypeSimple(ParentId);

            if ((ColumnType == SqlColumnTypeSimple.DateTime) || (ColumnType == SqlColumnTypeSimple.Boolean))
            {
                throw new Exception(string.Format("ColumnType: '{0}' is not allowed.", ColumnType));
            }

            string Parenthesis = (ColumnType == SqlColumnTypeSimple.String) ? "'" : "";

            //하위 행을 추가할 때 원래의 순서를 유지하기 위해 거꾸로 루핑을 함
            for (int rw = (adr.Length - 1); rw >= 0; rw--)
            {
                DataRow dr          = adr[rw];
                object  ParentIdCur = dr[ColumnNameParentId];

                string    Filter    = string.Format("{0} = {1}{2}{1}", ColumnNameId, Parenthesis, ParentIdCur);
                DataRow[] adrParent = dt.Select(Filter);
                if (adrParent.Length == 0)
                {
                    continue;
                }
                else if (adrParent.Length >= 2)
                {
                    throw new Exception(string.Format("{0} is not unique. Duplicated value: {1}", ColumnNameId, ParentIdCur));
                }

                DataRow drParent = adrParent[0];
                CDataTable.MoveRow(dt, dt.Rows.IndexOf(dr), dt.Rows.IndexOf(drParent) + 1);
            }
        }