コード例 #1
0
        private string CreateSheetDataSql(DataTableInfo tInfo, DataTable dtt, bool isTarget, bool isIdInsert)
        {
            TableLayoutInfo tinfo = GetTableLayoutInfo(tInfo.TableName, isTarget);

            StringBuilder sbSql = new StringBuilder();

            sbSql.AppendFormat("/****【{0}】({1}) ****/", tInfo.DisplayName, tInfo.TableName);
            sbSql.AppendLine();
            bool hasIdColumn = tinfo.Columns.Any(col => col.IsIdentity);

            if (isIdInsert && hasIdColumn)
            {
                sbSql.AppendFormat("SET IDENTITY_INSERT [{0}] ON", tinfo.TableName);
                sbSql.AppendLine("GO");
            }
            foreach (DataRow row in dtt.Rows)
            {
                sbSql.AppendLine(tinfo.GetInsertScript(row, true));
                sbSql.AppendLine("GO");
            }
            if (isIdInsert && hasIdColumn)
            {
                sbSql.AppendFormat("SET IDENTITY_INSERT [{0}] OFF", tinfo.TableName);
                sbSql.AppendLine("GO");
            }
            return(sbSql.ToString());
        }
コード例 #2
0
        /// <summary>
        /// テーブル列の書式を設定する
        /// </summary>
        /// <param name="info"></param>
        /// <param name="sheet"></param>
        private void SetColumnFormat(TableLayoutInfo info, Excel.Worksheet sheet)
        {
            string rangeName;

            foreach (ColumnInfo column in info.Columns)
            {
                switch (column.DataType)
                {
                case "datetime":
                    rangeName = string.Format("{0}[{1}]", info.TableName, column.ColumnName);
                    sheet.Range[rangeName].NumberFormat = "yyyy/MM/dd HH:mm:ss";
                    break;

                case "nvarchar":
                case "varchar":
                case "char":
                    rangeName = string.Format("{0}[{1}]", info.TableName, column.ColumnName);
                    sheet.Range[rangeName].NumberFormat = "@";
                    break;

                default:
                    break;
                }
            }
        }
コード例 #3
0
ファイル: TableCreator.cs プロジェクト: Maxiaozhe/CodeBank
 /// <summary>
 /// SQL Scriptを出力する
 /// </summary>
 /// <param name="opt"></param>
 /// <param name="tableInfo"></param>
 private void CreateSqlScript(ScriptOptions opt, TableLayoutInfo tableInfo)
 {
     //OutPut Start
     Logging.WriteLine(Resource.StringTable.Messages.SqlScriptStart, tableInfo.TableName, tableInfo.DisplayName);
     //Drop Description
     if ((opt & ScriptOptions.DropDropDescriptions) == ScriptOptions.DropDropDescriptions)
     {
         Logging.Write(tableInfo.GetDropDescriptionScript());
     }
     //Drop
     if ((opt & ScriptOptions.DropTables) == ScriptOptions.DropTables)
     {
         Logging.Write(tableInfo.GetDropScript());
     }
     //Create
     if ((opt & ScriptOptions.CreateTables) == ScriptOptions.CreateTables)
     {
         Logging.Write(tableInfo.GetCreateScript());
     }
     //Create Description
     if ((opt & ScriptOptions.CreateDropDescriptions) == ScriptOptions.CreateDropDescriptions)
     {
         Logging.Write(tableInfo.GetCreateDescriptionScript());
     }
 }
コード例 #4
0
ファイル: TableCreator.cs プロジェクト: Maxiaozhe/CodeBank
 public void CreateDBScript(LayoutType layout, string tableLayoutFile, ScriptOptions opt)
 {
     base.Report(Resource.StringTable.Messages.OpenDesignFile);
     using (ExcelHelp xls = new ExcelHelp(tableLayoutFile))
     {
         //int sheectCount = xls.WorkBook.Sheets.Count;
         base.Report(Resource.StringTable.Messages.ReadingTableList);
         System.Data.DataTable dttList = GetTableList(layout);
         //System.Data.DataTable dttList = GetTableList(xls,layout );
         base.SetStep(dttList.Rows.Count, Resource.StringTable.Messages.CreatingSqlScript);
         foreach (System.Data.DataRow row in dttList.Rows)
         {
             string sheetName = Utility.DBToString(row["DisplayName"]);
             string tabName   = Utility.DBToString(row["TableName"]);
             try
             {
                 TableLayoutInfo tableInfo = ReadTableLayout(xls, sheetName, layout);
                 //Script出力
                 CreateSqlScript(opt, tableInfo);
                 ReportStep(Resource.StringTable.Messages.CreatedTableSqlScript, tableInfo.DisplayName, tableInfo.TableName);
             }
             catch (Exception ex)
             {
                 Logging.WriteLine("/*");
                 Logging.WriteLine(Resource.StringTable.Messages.ScriptCreateFailed, sheetName, tabName);
                 Logging.Exception("", ex);
                 Logging.WriteLine("*/");
             }
         }
         Report(Resource.StringTable.Messages.ProcessFinished);
         xls.Close();
     }
 }
コード例 #5
0
        private void CreateDataSheet(ExcelHelp xls, DataTableInfo tableInfo, bool isTarget)
        {
            DatabaseAcsesser dba = new DatabaseAcsesser();

            DatabaseAcsesser.DbConnections connType = isTarget ? DatabaseAcsesser.DbConnections.TargetDbConnection
                                                               : DatabaseAcsesser.DbConnections.SourceDbConnection;
            TableLayoutInfo info = dba.GetTableLayout(connType, tableInfo.TableName);

            Excel.Worksheet templateSheet = xls.WorkBook.Sheets["Template"];
            Excel.Worksheet sheet         = xls.CreateSheet(tableInfo.SheetName, templateSheet);
            int             colIndex      = 0;

            xls.WriteValue(sheet, 1, 2, info.TableName);
            foreach (ColumnInfo column in info.Columns)
            {
                colIndex++;
                xls.WriteValue(sheet, STRAT_ROW, colIndex, column.ColumnName);
                if (!string.IsNullOrEmpty(column.DisplayName))
                {
                    string comment = column.DisplayName + "\n" + column.GetSqlType();
                    sheet.Range[xls.GetColumnName(colIndex, STRAT_ROW)].AddComment(comment);
                }
                if (column.IsPrimaryKey)
                {
                    Excel.Range cell = sheet.Range[xls.GetColumnName(colIndex, STRAT_ROW)];
                    cell.Font.Color = Excel.XlRgbColor.rgbRed;
                }
            }
            xls.AddListObject(sheet, STRAT_ROW, STRAT_ROW + 1, colIndex, tableInfo.TableName);
            SetColumnFormat(info, sheet);
            sheet.Columns.AutoFit();
            sheet.Tab.Color = isTarget ? Excel.XlRgbColor.rgbBlue : Excel.XlRgbColor.rgbRed;
        }
コード例 #6
0
        private TableLayoutInfo GetTableLayoutInfo(string tableName, bool isTarget)
        {
            DatabaseAcsesser dba = new DatabaseAcsesser();

            DatabaseAcsesser.DbConnections connType = isTarget ? DatabaseAcsesser.DbConnections.TargetDbConnection
                                                               : DatabaseAcsesser.DbConnections.SourceDbConnection;
            TableLayoutInfo info = dba.GetTableLayout(connType, tableName);

            return(info);
        }
コード例 #7
0
 public TableLayoutInfo GetTableLayout(DbConnections conn, string tableName)
 {
     using (DaoBase dao = GetDao(conn))
     {
         using (SqlCommand cmd = dao.CreateCommand())
         {
             cmd.CommandText = Properties.Resources.GetTableLayout;
             cmd.AddParameter("@tableName", tableName);
             DataTable       dtt       = dao.ExecuteResultSet(cmd, tableName, false);
             TableLayoutInfo tableInfo = new TableLayoutInfo(tableName, dtt);
             return(tableInfo);
         }
     }
 }
コード例 #8
0
        private static bool IsMatch(string keyword, TableList t, TableLayoutInfo c, SearchModes mode, SearchOptions opts)
        {
            bool result = false;

            if ((opts & SearchOptions.TableName) == SearchOptions.TableName)
            {
                result = Match(t.TableName, keyword, mode) || Match(t.TableDisplayName, keyword, mode);
            }

            if ((opts & SearchOptions.ColumnName) == SearchOptions.ColumnName)
            {
                result = result || Match(c.ColumnName, keyword, mode) || Match(c.ColumnDisplayName, keyword, mode);
            }
            if ((opts & SearchOptions.CommentName) == SearchOptions.CommentName)
            {
                result = result || Match(t.Comment, keyword, SearchModes.Contain) || Match(c.Comment, keyword, SearchModes.Contain);
            }
            return(result);
        }
コード例 #9
0
ファイル: TableCreator.cs プロジェクト: Maxiaozhe/CodeBank
        public void CreateDBScript(TableCreateInfo info)
        {
            string outPutPath = System.IO.Path.ChangeExtension(info.LayoutFileName, "sql");

            Logging.OutputFileName = outPutPath;
            try
            {
                base.Report(Resource.StringTable.Messages.OpenDesignFile);
                using (ExcelHelp xls = new ExcelHelp(info.LayoutFileName))
                {
                    //int sheectCount = xls.WorkBook.Sheets.Count;
                    base.Report(Resource.StringTable.Messages.ReadingTableList);
                    System.Data.DataTable dttList = GetTableList(info.TableListSheetName);
                    base.SetStep(dttList.Rows.Count, Resource.StringTable.Messages.CreatingSqlScript);
                    foreach (System.Data.DataRow row in dttList.Rows)
                    {
                        DataTableInfo tbInfo = new DataTableInfo(row);
                        try
                        {
                            TableLayoutInfo tableInfo = ReadTableLayout(xls, tbInfo.SheetName, info.LayoutKind);
                            //Script出力
                            CreateSqlScript(info.Options, tableInfo);
                            ReportStep(Resource.StringTable.Messages.CreatedTableSqlScript, tableInfo.DisplayName, tableInfo.TableName);
                        }
                        catch (Exception ex)
                        {
                            Logging.WriteLine("/*");
                            Logging.WriteLine(Resource.StringTable.Messages.ScriptCreateFailed, tbInfo.SheetName, tbInfo.TableName);
                            Logging.Exception("", ex);
                            Logging.WriteLine("*/");
                        }
                    }
                    Report(Resource.StringTable.Messages.ProcessFinished);
                    xls.Close();
                }
            }
            finally
            {
                Logging.OutputFileName = "";
            }
        }
コード例 #10
0
ファイル: TableResult.cs プロジェクト: yung-chu/FastReport
        private TableLayoutInfo GeneratePagesDownThenAcross()
        {
            ReportEngine  engine        = Report.Engine;
            PreparedPages preparedPages = Report.PreparedPages;

            preparedPages.CanUploadToCache = false;

            TableLayoutInfo info = new TableLayoutInfo();

            info.startPage = engine.CurPage;
            List <Rectangle> spans = GetSpanList();
            int   startColumn      = 0;
            bool  addNewPage       = false;
            float saveCurY         = engine.CurY;
            float lastCurY         = 0;
            int   lastPage         = 0;

            Top = 0;

            while (startColumn < Columns.Count)
            {
                if (addNewPage)
                {
                    engine.StartNewPage();
                }

                int startRow   = 0;
                int columnsFit = GetColumnsFit(startColumn, engine.PageWidth - Left);
                // avoid the infinite loop if there is not enough space for one column
                if (startColumn > 0 && columnsFit == 0)
                {
                    columnsFit = 1;
                }

                engine.CurY = saveCurY;
                info.tableSize.Width++;
                info.tableSize.Height = 0;

                if (columnsFit > 0)
                {
                    while (startRow < Rows.Count)
                    {
                        int rowsFit = GetRowsFit(startRow, engine.FreeSpace);
                        if (startRow == 0 && engine.IsKeeping && rowsFit < RowCount && isFirstRow && engine.KeepCurY > 0)
                        {
                            engine.EndColumn();

                            rowsFit = GetRowsFit(startRow, engine.FreeSpace);
                        }
                        // avoid the infinite loop if there is not enough space for one row
                        if (startRow > 0 && rowsFit == 0)
                        {
                            rowsFit = 1;
                        }

                        engine.CurY += GeneratePage(startColumn, startRow, columnsFit, rowsFit,
                                                    new RectangleF(0, 0, engine.PageWidth, engine.FreeSpace), spans);
                        info.tableSize.Height++;

                        startRow += rowsFit;
                        if (startRow < Rows.Count)
                        {
                            // if we have something to print, start a new page
                            engine.StartNewPage();
                        }
                        else if (startColumn > 0)
                        {
                            // finish the last printed page in case it is not a start page
                            engine.EndPage(false);
                        }

                        if (Report.Aborted)
                        {
                            break;
                        }
                    }
                }

                info.startX  = Left + GetColumnsWidth(startColumn, columnsFit);
                startColumn += columnsFit;
                Left         = 0;
                preparedPages.AddPageAction = AddPageAction.Add;
                addNewPage = true;

                if (lastPage == 0)
                {
                    lastPage = engine.CurPage;
                    lastCurY = engine.CurY;
                }

                if (Report.Aborted)
                {
                    break;
                }
            }

            engine.CurPage = lastPage;
            engine.CurY    = lastCurY;
            return(info);
        }
コード例 #11
0
ファイル: TableResult.cs プロジェクト: yung-chu/FastReport
        internal void GeneratePages(object sender, EventArgs e)
        {
            isFirstRow = false;
            if (Skip)
            {
                Skip = false;
                return;
            }


            // check if band contains several tables
            if (sender is BandBase)
            {
                BandBase senderBand = sender as BandBase;
                isFirstRow = senderBand.IsFirstRow;
                SortedList <float, TableBase> tables = new SortedList <float, TableBase>();
                foreach (Base obj in senderBand.Objects)
                {
                    TableBase table = obj as TableBase;
                    if (table != null && table.ResultTable != null)
                    {
                        tables.Add(table.Left, table);
                    }
                }

                // render tables side-by-side
                if (tables.Count > 1)
                {
                    ReportEngine    engine = Report.Engine;
                    TableLayoutInfo info   = new TableLayoutInfo();
                    info.startPage = engine.CurPage;
                    info.tableSize = new Size(1, 1);
                    info.startX    = tables.Values[0].Left;

                    int   firstTableHeight = 0;
                    int   startPage        = info.startPage;
                    float firstTableCurY   = 0;
                    float saveCurY         = engine.CurY;

                    for (int i = 0; i < tables.Count; i++)
                    {
                        TableBase table = tables.Values[i];

                        // do not allow table to render itself in the band.AfterPrint event
                        table.ResultTable.Skip = true;
                        // render using the down-then-across mode
                        table.Layout = TableLayout.DownThenAcross;

                        engine.CurPage = info.startPage + (info.tableSize.Width - 1) * info.tableSize.Height;
                        engine.CurY    = saveCurY;
                        float addLeft = 0;
                        if (i > 0)
                        {
                            addLeft = table.Left - tables.Values[i - 1].Right;
                        }
                        table.ResultTable.Left = info.startX + addLeft;

                        // calculate cells' bounds
                        table.ResultTable.CalcBounds();
                        // generate pages
                        Report.PreparedPages.AddPageAction = AddPageAction.WriteOver;
                        info = table.ResultTable.GeneratePagesDownThenAcross();

                        if (i == 0)
                        {
                            firstTableHeight = info.tableSize.Height;
                            firstTableCurY   = engine.CurY;
                        }
                    }

                    engine.CurPage = startPage + firstTableHeight - 1;
                    engine.CurY    = firstTableCurY;

                    Skip = false;
                    return;
                }
            }

            // calculate cells' bounds
            CalcBounds();

            if (Report.Engine.UnlimitedHeight || Report.Engine.UnlimitedWidth)
            {
                if (!Report.Engine.UnlimitedWidth)
                {
                    GeneratePagesWrapped();
                }
                else if (!Report.Engine.UnlimitedHeight)
                {
                    GeneratePagesDownThenAcross();
                }
                else
                {
                    GeneratePagesAcrossThenDown();
                }
            }
            else if (Layout == TableLayout.AcrossThenDown)
            {
                GeneratePagesAcrossThenDown();
            }
            else if (Layout == TableLayout.DownThenAcross)
            {
                GeneratePagesDownThenAcross();
            }
            else
            {
                GeneratePagesWrapped();
            }
        }
コード例 #12
0
ファイル: EditorTable.cs プロジェクト: ikvm/webmatrix
 public void DeleteTableRow()
 {
     BatchedUndoUnit unit = this._editor.OpenBatchUndo("DeleteTableRow");
     try
     {
         Interop.IHTMLTableCell cell = null;
         if (string.Compare(this._element.GetTagName(), "td", true) == 0)
         {
             cell = (Interop.IHTMLTableCell) this._element;
         }
         else if (string.Compare(this._element.GetTagName(), "tr", true) == 0)
         {
             Interop.IHTMLTableRow row = this._element as Interop.IHTMLTableRow;
             cell = (Interop.IHTMLTableCell) row.GetCells().Item(0, 0);
         }
         if (cell != null)
         {
             int num;
             int num2;
             this.TableInfo.GetCellPoint(cell, out num, out num2);
             num += cell.GetRowSpan() - 1;
             Interop.IHTMLTable table = this.TableInfo.Table;
             Interop.IHTMLTableRow row2 = table.GetRows().Item(num, num) as Interop.IHTMLTableRow;
             int num3 = 0;
             for (Interop.IHTMLTableCell cell2 = this.TableInfo[num, num3]; cell2 != null; cell2 = this.TableInfo[num, num3])
             {
                 Interop.IHTMLTableRow parentElement = ((Interop.IHTMLElement) cell2).GetParentElement() as Interop.IHTMLTableRow;
                 if (parentElement != row2)
                 {
                     cell2.SetRowSpan(cell2.GetRowSpan() - 1);
                 }
                 num3 += cell2.GetColSpan();
             }
             table.DeleteRow(num);
             this._tableInfo = null;
         }
     }
     finally
     {
         unit.Close();
     }
 }
コード例 #13
0
ファイル: EditorTable.cs プロジェクト: ikvm/webmatrix
 public void InsertTableColumn()
 {
     BatchedUndoUnit unit = this._editor.OpenBatchUndo("InsertTableColumn");
     try
     {
         Interop.IHTMLTableCell cell = null;
         bool flag = false;
         if (string.Compare(this._element.GetTagName(), "td", true) == 0)
         {
             cell = (Interop.IHTMLTableCell) this._element;
         }
         else if (string.Compare(this._element.GetTagName(), "tr", true) == 0)
         {
             Interop.IHTMLTableRow row = this._element as Interop.IHTMLTableRow;
             int name = row.GetCells().GetLength() - 1;
             cell = (Interop.IHTMLTableCell) row.GetCells().Item(name, name);
             flag = true;
         }
         else if (string.Compare(this._element.GetTagName(), "tbody", true) == 0)
         {
             Interop.IHTMLElementCollection rows = (this._element.GetParentElement() as Interop.IHTMLTable).GetRows();
             int num2 = rows.GetLength() - 1;
             Interop.IHTMLTableRow row2 = (Interop.IHTMLTableRow) rows.Item(0, 0);
             num2 = row2.GetCells().GetLength() - 1;
             cell = (Interop.IHTMLTableCell) row2.GetCells().Item(num2, num2);
             flag = true;
         }
         else if (string.Compare(this._element.GetTagName(), "table", true) == 0)
         {
             Interop.IHTMLElementCollection elements4 = (this._element as Interop.IHTMLTable).GetRows();
             int num3 = elements4.GetLength() - 1;
             Interop.IHTMLTableRow row3 = (Interop.IHTMLTableRow) elements4.Item(num3, num3);
             num3 = row3.GetCells().GetLength() - 1;
             cell = (Interop.IHTMLTableCell) row3.GetCells().Item(num3, num3);
             flag = true;
         }
         if (cell != null)
         {
             int num4;
             int num5;
             this.TableInfo.GetCellPoint(cell, out num4, out num5);
             int num6 = 0;
             for (Interop.IHTMLTableCell cell2 = this.TableInfo[num6, num5]; cell2 != null; cell2 = this.TableInfo[num6, num5])
             {
                 int num7;
                 int num8;
                 Interop.IHTMLTableRow parentElement = ((Interop.IHTMLElement) cell2).GetParentElement() as Interop.IHTMLTableRow;
                 this.TableInfo.GetCellPoint(cell2, out num7, out num8);
                 if (flag || (num5 == num8))
                 {
                     int index = num5;
                     if (flag)
                     {
                         index = -1;
                     }
                     parentElement.InsertCell(index).SetRowSpan(cell2.GetRowSpan());
                 }
                 else
                 {
                     cell2.SetColSpan(cell2.GetColSpan() + 1);
                 }
                 num6 += cell2.GetRowSpan();
             }
             this._tableInfo = null;
         }
     }
     finally
     {
         unit.Close();
     }
 }
コード例 #14
0
ファイル: TableCreator.cs プロジェクト: Maxiaozhe/CodeBank
        private TableLayoutInfo ReadLiveTableLayout(ExcelHelp xls, string sheetName)
        {
            Excel.Worksheet sheet     = xls.WorkBook.Sheets[sheetName];
            string          tableName = Utility.DBToString(sheet.Range[LiveLayoutInfo.TABLE_NAME].Value);
            TableLayoutInfo tableInfo = new TableLayoutInfo(tableName)
            {
                DisplayName = sheet.Range[LiveLayoutInfo.TABLE_DISPLAY_NAME].Value
            };
            //列作成
            int    rowIndex = LiveLayoutInfo.START_ROW;
            string No       = Utility.DBToString(sheet.Range[LiveLayoutInfo.COLUMN_NO + rowIndex].Value);
            int    columnId = 0;

            while (!string.IsNullOrEmpty(No) && int.TryParse(No, out columnId))
            {
                //ColumnName
                ColumnInfo column = new ColumnInfo();
                column.ColumnId    = columnId;
                column.ColumnName  = Utility.DBToString(sheet.Range[LiveLayoutInfo.COLUMN_NAME + rowIndex].Value).Trim();
                column.DisplayName = Utility.DBToString(sheet.Range[LiveLayoutInfo.COLUMN_DISPLAY + rowIndex].Value).Trim();
                column.DataType    = Utility.DBToString(sheet.Range[LiveLayoutInfo.COLUMN_TYPE + rowIndex].Value).Trim();
                //Length
                string lenVal = Utility.DBToString(sheet.Range[LiveLayoutInfo.COLUMN_LENGTH + rowIndex].Value).Trim();
                if (!string.IsNullOrWhiteSpace(lenVal))
                {
                    int length = 0;
                    if (int.TryParse(lenVal, out length))
                    {
                        column.Length = length;
                    }
                    else if (lenVal.Contains(","))
                    {
                        int      num  = 0;
                        string[] sect = lenVal.Split(',');
                        if (int.TryParse(sect[0], out num))
                        {
                            column.NumericPrecision = num;
                        }
                        if (int.TryParse(sect[1], out num))
                        {
                            column.NumericScale = num;
                        }
                    }
                    else
                    {
                        if (lenVal.ToLower().Equals("max"))
                        {
                            column.Length = -1;
                        }
                    }
                }
                //Nullable
                string nullable = Utility.DBToString(sheet.Range[LiveLayoutInfo.COLUMN_NULLABLE + rowIndex].Value);
                column.Nullable = (!string.IsNullOrWhiteSpace(nullable));
                //InPrimary
                string InPrimary = Utility.DBToString(sheet.Range[LiveLayoutInfo.COLUMN_ISPRIMARY + rowIndex].Value);
                column.IsPrimaryKey = (!string.IsNullOrWhiteSpace(InPrimary));
                //Index Key
                string indexNo = Utility.DBToString(sheet.Range[LiveLayoutInfo.COLUMN_INDEX + rowIndex].Value);
                int    indexId = 0;
                if (!string.IsNullOrWhiteSpace(indexNo) && int.TryParse(indexNo, out indexId))
                {
                    column.IndexColumnId = indexId;
                }
                if (!string.IsNullOrWhiteSpace(column.ColumnName) && !string.IsNullOrWhiteSpace(column.DataType))
                {
                    tableInfo.Columns.Add(column);
                }
                else
                {
                    Logging.WriteLine("-- ERROR:: {0}-{1} 行:{2} {3}",
                                      sheetName, tableInfo.TableName, No,
                                      string.IsNullOrWhiteSpace(column.ColumnName) ? "列名なし" : "型なし");
                }
                //Comment
                column.Comment = Utility.DBToString(sheet.Range[LiveLayoutInfo.COLUMN_COMMENT + rowIndex].Value).Trim();
                rowIndex++;
                No = Utility.DBToString(sheet.Range[LiveLayoutInfo.COLUMN_NO + rowIndex].Value);
            }

            return(tableInfo);
        }
コード例 #15
0
ファイル: TableCreator.cs プロジェクト: Maxiaozhe/CodeBank
        private TableLayoutInfo ReadSeedTableLayout(ExcelHelp xls, string sheetName)
        {
            Excel.Worksheet sheet     = xls.WorkBook.Sheets[sheetName];
            string          tableName = Utility.DBToString(sheet.Range[SeedLayoutInfo.TABLE_NAME].Value);
            TableLayoutInfo tableInfo = new TableLayoutInfo(tableName)
            {
                DisplayName = sheetName
            };

            //列作成
            int    rowIndex   = SeedLayoutInfo.START_ROW;
            int    columnId   = 0;
            string no         = Utility.DBToString(sheet.Range[SeedLayoutInfo.COLUMN_NO + rowIndex].Value);
            string columnName = Utility.DBToString(sheet.Range[SeedLayoutInfo.COLUMN_NAME + rowIndex].Value).Trim();

            while (!string.IsNullOrEmpty(columnName) || !string.IsNullOrEmpty(no))
            {
                //ColumnName
                ColumnInfo column = new ColumnInfo();

                if (int.TryParse(no, out columnId))
                {
                    column.ColumnId = columnId;
                }
                column.ColumnName = columnName;
                string displayName = Utility.DBToString(sheet.Range[SeedLayoutInfo.COLUMN_DISPLAY + rowIndex].Value).Trim();
                if (sheet.Range[SeedLayoutInfo.COLUMN_DISPLAY + rowIndex].MergeCells == true)
                {
                    displayName = Utility.DBToString(sheet.Range[SeedLayoutInfo.COLUMN_DISPLAY + rowIndex].MergeArea[1, 1].Value);
                    string displayName2 = Utility.DBToString(sheet.Range[SeedLayoutInfo.COLUMN_DISPLAY2 + rowIndex].Value).Trim();
                    displayName = displayName + " " + displayName2;
                    displayName = displayName.Replace("\n", "");
                }
                column.DisplayName = displayName;
                column.DataType    = Utility.DBToString(sheet.Range[SeedLayoutInfo.COLUMN_TYPE + rowIndex].Value).Trim();
                //Length
                string lenVal = Utility.DBToString(sheet.Range[SeedLayoutInfo.COLUMN_LENGTH + rowIndex].Value).Trim();
                if (!string.IsNullOrWhiteSpace(lenVal))
                {
                    int length = 0;
                    if (int.TryParse(lenVal, out length))
                    {
                        column.Length = length;
                    }
                    else
                    {
                        if (lenVal.ToLower().Equals("max"))
                        {
                            column.Length = -1;
                        }
                    }
                }
                //Scale
                string scaleVal = Utility.DBToString(sheet.Range[SeedLayoutInfo.COLUMN_SCALE + rowIndex].Value).Trim();
                if (!string.IsNullOrWhiteSpace(scaleVal))
                {
                    int scale = 0;
                    if (int.TryParse(lenVal, out scale))
                    {
                        column.NumericPrecision = column.Length;
                        column.NumericScale     = scale;
                    }
                }
                //Nullable
                string nullable = Utility.DBToString(sheet.Range[SeedLayoutInfo.COLUMN_NULLABLE + rowIndex].Value);
                if (!string.IsNullOrWhiteSpace(nullable) && nullable.Equals("N"))
                {
                    column.Nullable = false;
                }
                else
                {
                    column.Nullable = true;
                }

                //Primary Key
                string indexNo = Utility.DBToString(sheet.Range[SeedLayoutInfo.COLUMN_PRIMARYINDEX + rowIndex].Value);
                int    indexId = 0;
                if (!string.IsNullOrWhiteSpace(indexNo) && int.TryParse(indexNo, out indexId))
                {
                    column.IndexColumnId = indexId;
                }
                //InPrimary
                if (column.IndexColumnId > 0)
                {
                    column.IsPrimaryKey = true;
                }

                if (!string.IsNullOrWhiteSpace(column.ColumnName) && !string.IsNullOrWhiteSpace(column.DataType))
                {
                    tableInfo.Columns.Add(column);
                }
                //Comment
                column.Comment = Utility.DBToString(sheet.Range[SeedLayoutInfo.COLUMN_COMMENT + rowIndex].Value).Trim();
                rowIndex++;
                no         = Utility.DBToString(sheet.Range[SeedLayoutInfo.COLUMN_NO + rowIndex].Value);
                columnName = Utility.DBToString(sheet.Range[SeedLayoutInfo.COLUMN_NAME + rowIndex].Value).Trim();
            }

            return(tableInfo);
        }
コード例 #16
0
ファイル: EditorTable.cs プロジェクト: ikvm/webmatrix
 public void InsertTableRow()
 {
     BatchedUndoUnit unit = this._editor.OpenBatchUndo("InsertTableRow");
     try
     {
         Interop.IHTMLTableCell cell = null;
         bool flag = false;
         if (string.Compare(this._element.GetTagName(), "td", true) == 0)
         {
             cell = (Interop.IHTMLTableCell) this._element;
         }
         else if (string.Compare(this._element.GetTagName(), "tr", true) == 0)
         {
             Interop.IHTMLTableRow row = this._element as Interop.IHTMLTableRow;
             cell = (Interop.IHTMLTableCell) row.GetCells().Item(0, 0);
         }
         else if (string.Compare(this._element.GetTagName(), "tbody", true) == 0)
         {
             Interop.IHTMLElementCollection rows = (this._element.GetParentElement() as Interop.IHTMLTable).GetRows();
             int name = rows.GetLength() - 1;
             Interop.IHTMLTableRow row2 = (Interop.IHTMLTableRow) rows.Item(name, name);
             cell = (Interop.IHTMLTableCell) row2.GetCells().Item(0, 0);
             flag = true;
         }
         else if (string.Compare(this._element.GetTagName(), "table", true) == 0)
         {
             Interop.IHTMLElementCollection elements2 = (this._element as Interop.IHTMLTable).GetRows();
             int num2 = elements2.GetLength() - 1;
             Interop.IHTMLTableRow row3 = (Interop.IHTMLTableRow) elements2.Item(num2, num2);
             cell = (Interop.IHTMLTableCell) row3.GetCells().Item(0, 0);
             flag = true;
         }
         if (cell != null)
         {
             int num3;
             int num4;
             this.TableInfo.GetCellPoint(cell, out num3, out num4);
             Interop.IHTMLTableRow parentElement = ((Interop.IHTMLElement) cell).GetParentElement() as Interop.IHTMLTableRow;
             int rowIndex = parentElement.GetRowIndex();
             Interop.IHTMLTable table = this.TableInfo.Table;
             if (flag)
             {
                 rowIndex = -1;
             }
             Interop.IHTMLTableRow row5 = table.InsertRow(rowIndex);
             int num6 = 0;
             for (Interop.IHTMLTableCell cell2 = this.TableInfo[num3, num6]; cell2 != null; cell2 = this.TableInfo[num3, num6])
             {
                 Interop.IHTMLTableRow row6 = ((Interop.IHTMLElement) cell2).GetParentElement() as Interop.IHTMLTableRow;
                 if (flag || (row6 == parentElement))
                 {
                     row5.InsertCell(-1).SetColSpan(cell2.GetColSpan());
                 }
                 else
                 {
                     cell2.SetRowSpan(cell2.GetRowSpan() + 1);
                 }
                 num6 += cell2.GetColSpan();
             }
             this._tableInfo = null;
         }
     }
     finally
     {
         unit.Close();
     }
 }
コード例 #17
0
ファイル: EditorTable.cs プロジェクト: ikvm/webmatrix
 public void DeleteTableColumn()
 {
     BatchedUndoUnit unit = this._editor.OpenBatchUndo("DeleteTableColumn");
     try
     {
         Interop.IHTMLTableCell cell = null;
         if (string.Compare(this._element.GetTagName(), "td", true) == 0)
         {
             cell = (Interop.IHTMLTableCell) this._element;
         }
         if (cell != null)
         {
             int num;
             int num2;
             this.TableInfo.GetCellPoint(cell, out num, out num2);
             num2 += cell.GetColSpan() - 1;
             int num3 = 0;
             for (Interop.IHTMLTableCell cell2 = this.TableInfo[num3, num2]; cell2 != null; cell2 = this.TableInfo[num3, num2])
             {
                 int num4;
                 int num5;
                 Interop.IHTMLTableRow parentElement = ((Interop.IHTMLElement) cell2).GetParentElement() as Interop.IHTMLTableRow;
                 this.TableInfo.GetCellPoint(cell2, out num4, out num5);
                 if (num2 == num5)
                 {
                     int index = num2;
                     parentElement.DeleteCell(index);
                 }
                 else
                 {
                     cell2.SetColSpan(cell2.GetColSpan() - 1);
                 }
                 num3 += cell2.GetRowSpan();
             }
             this._tableInfo = null;
         }
     }
     finally
     {
         unit.Close();
     }
 }
コード例 #18
0
ファイル: EditorTable.cs プロジェクト: ikvm/webmatrix
 public void MergeUp()
 {
     BatchedUndoUnit unit = this._editor.OpenBatchUndo("MergeUp");
     try
     {
         Interop.IHTMLTableCell cell = this._element as Interop.IHTMLTableCell;
         if (cell != null)
         {
             int num;
             int num2;
             this.TableInfo.GetCellPoint(cell, out num, out num2);
             Interop.IHTMLTableCell cell2 = this.TableInfo[num - 1, num2];
             Interop.IHTMLElement o = (Interop.IHTMLElement) cell2;
             string innerHTML = this._element.GetInnerHTML();
             int rowSpan = cell.GetRowSpan();
             Interop.IHTMLTableRow parentElement = this._element.GetParentElement() as Interop.IHTMLTableRow;
             int cellIndex = cell.GetCellIndex();
             parentElement.DeleteCell(cellIndex);
             cell2.SetRowSpan(cell2.GetRowSpan() + rowSpan);
             o.InsertAdjacentHTML("beforeEnd", innerHTML);
             this._selection.SelectElement(o);
             this._tableInfo = null;
         }
     }
     finally
     {
         unit.Close();
     }
 }
コード例 #19
0
ファイル: EditorTable.cs プロジェクト: ikvm/webmatrix
 public void SplitHorizontal()
 {
     BatchedUndoUnit unit = this._editor.OpenBatchUndo("SplitHorizontal");
     try
     {
         Interop.IHTMLTableCell cell = this._element as Interop.IHTMLTableCell;
         if (cell != null)
         {
             int num;
             int num2;
             this.TableInfo.GetCellPoint(cell, out num, out num2);
             int colSpan = cell.GetColSpan();
             if (colSpan > 1)
             {
                 cell.SetColSpan(colSpan - 1);
             }
             else
             {
                 int num4 = 0;
                 for (Interop.IHTMLTableCell cell2 = this.TableInfo[num4, num2]; cell2 != null; cell2 = this.TableInfo[num4, num2])
                 {
                     if (cell2 != cell)
                     {
                         cell2.SetColSpan(cell2.GetColSpan() + 1);
                     }
                     num4 += cell2.GetRowSpan();
                 }
             }
             Interop.IHTMLTableCell o = (((Interop.IHTMLElement) cell).GetParentElement() as Interop.IHTMLTableRow).InsertCell(cell.GetCellIndex() + 1);
             o.SetRowSpan(cell.GetRowSpan());
             Interop.IHTMLTxtRange mSHTMLSelection = this._selection.MSHTMLSelection as Interop.IHTMLTxtRange;
             if (mSHTMLSelection != null)
             {
                 for (int i = 1; i > 0; i = mSHTMLSelection.MoveEnd("character", 1))
                 {
                 }
                 string innerHTML = this._element.GetInnerHTML();
                 string text = mSHTMLSelection.GetText();
                 if ((text != null) && (text.Length > 0))
                 {
                     int length = innerHTML.LastIndexOf(text);
                     if (length != -1)
                     {
                         this._element.SetInnerHTML(innerHTML.Substring(0, length));
                         ((Interop.IHTMLElement) o).SetInnerHTML(text);
                     }
                 }
             }
             this._selection.SelectElement(o);
             this._tableInfo = null;
         }
     }
     finally
     {
         unit.Close();
     }
 }
コード例 #20
0
ファイル: EditorTable.cs プロジェクト: ikvm/webmatrix
 public void SplitVertical()
 {
     BatchedUndoUnit unit = this._editor.OpenBatchUndo("SplitVertical");
     try
     {
         Interop.IHTMLTableCell cell = this._element as Interop.IHTMLTableCell;
         if (cell != null)
         {
             int num;
             int num2;
             this.TableInfo.GetCellPoint(cell, out num, out num2);
             int rowSpan = cell.GetRowSpan();
             if (rowSpan > 1)
             {
                 cell.SetRowSpan(rowSpan - 1);
             }
             else
             {
                 int num4 = 0;
                 for (Interop.IHTMLTableCell cell2 = this.TableInfo[num, num4]; cell2 != null; cell2 = this.TableInfo[num, num4])
                 {
                     if (cell2 != cell)
                     {
                         cell2.SetRowSpan(cell2.GetRowSpan() + 1);
                     }
                     num4 += cell2.GetColSpan();
                 }
             }
             Interop.IHTMLTableRow parentElement = ((Interop.IHTMLElement) cell).GetParentElement() as Interop.IHTMLTableRow;
             Interop.IHTMLTable table = this.TableInfo.Table;
             int name = parentElement.GetRowIndex() + cell.GetRowSpan();
             Interop.IHTMLTableRow row2 = table.GetRows().Item(name, name) as Interop.IHTMLTableRow;
             Interop.IHTMLTableCell o = null;
             bool flag = false;
             if ((row2 != null) && (rowSpan > 1))
             {
                 int num6 = num2;
                 while (num6 >= 0)
                 {
                     Interop.IHTMLTableCell cell4 = this.TableInfo[name, num6];
                     Interop.IHTMLTableRow row3 = ((Interop.IHTMLElement) cell4).GetParentElement() as Interop.IHTMLTableRow;
                     if (row3 == row2)
                     {
                         break;
                     }
                     num6--;
                 }
                 if (parentElement.GetCells().GetLength() > row2.GetCells().GetLength())
                 {
                     int index = 0;
                     if (num6 >= 0)
                     {
                         Interop.IHTMLTableCell cell5 = this.TableInfo[name, num6];
                         index = cell5.GetCellIndex() + 1;
                     }
                     o = row2.InsertCell(index);
                     flag = true;
                 }
             }
             if (!flag)
             {
                 o = table.InsertRow(name).InsertCell(-1);
             }
             o.SetColSpan(cell.GetColSpan());
             Interop.IHTMLTxtRange mSHTMLSelection = this._selection.MSHTMLSelection as Interop.IHTMLTxtRange;
             if (mSHTMLSelection != null)
             {
                 for (int i = 1; i > 0; i = mSHTMLSelection.MoveEnd("character", 1))
                 {
                 }
                 string innerHTML = this._element.GetInnerHTML();
                 string text = mSHTMLSelection.GetText();
                 if ((text != null) && (text.Length > 0))
                 {
                     int length = innerHTML.LastIndexOf(text);
                     if (length != -1)
                     {
                         this._element.SetInnerHTML(innerHTML.Substring(0, length));
                         ((Interop.IHTMLElement) o).SetInnerHTML(text);
                     }
                 }
             }
             this._selection.SelectElement(o);
             this._tableInfo = null;
         }
     }
     finally
     {
         unit.Close();
     }
 }