private void BuliderModel() { StringBuilder str_Model = new StringBuilder(Environment.NewLine); ClassCreator ClassCreator = new ClassCreator(); // CSBaseClass CSBaseClass = new CSBaseClass(); foreach (TreeNode node in Home.form_Database.GetTreeView1Selected()) { foreach (var item in node.Nodes) { Column column = new Model.Column(); string data = item.ToString();//TreeNode: AdminID(uniqueidentifier,not null) data = data.Contains("TreeNode:") ? data.Replace("TreeNode:", "") : data; var str = data.Split('('); column.Name = str[0].ToString().Trim(); column.Type = StaticTool.GetColumnsType(str[1].ToString().Trim().Split(',')[0].ToString().Trim()); str_Model.Append("\t\t" + string.Format(CSBaseClass.baseAttributeTemplate, column.Type, "_" + column.Name)); str_Model.Append(string.Format(CSBaseClass.basePropertyTemplate, column.Name, column.Type, "_" + column.Name)); } } Form_Code_Area fca_business = new Form_Code_Area(str_Model.ToString(), "Model生成"); fca_business.Show(Home.Instance.dockPanel1); }
private void 生成构造函数ToolStripMenuItem_Click(object sender, EventArgs e) { StringBuilder strb1 = new StringBuilder(Environment.NewLine); StringBuilder strb2 = new StringBuilder(Environment.NewLine); StringBuilder strb3 = new StringBuilder(Environment.NewLine); string t = "public {0}(){{}};" + Environment.NewLine; string q = "public {0}({1}){{}};"; string c = string.Empty; foreach (TreeNode node in Home.form_Database.GetTreeView1Selected()) { strb1.Append(string.Format(t, node.Text.ToString()) + Environment.NewLine); c = ""; foreach (var item in node.Nodes) { Column column = new Model.Column(); string data = item.ToString(); data = data.Contains("TreeNode:") ? data.Replace("TreeNode:", "") : data; var str = data.Split('('); column.Name = str[0].ToString().Trim(); column.Type = StaticTool.GetColumnsType(str[1].ToString().Trim().Split(',')[0].ToString().Trim()); c += column.Type + " " + column.Name + ","; } strb2.Append(string.Format(q, node.Text.ToString(), c.Length > 0? c.Substring(0, c.Length - 1):c) + Environment.NewLine); strb3.Append(strb1.ToString() + Environment.NewLine); strb3.Append(strb2.ToString() + Environment.NewLine); strb1.Length = 0; strb2.Length = 0; } Form_Code_Area fca_business = new Form_Code_Area(strb3.ToString(), "构造函数生成"); fca_business.Show(Home.Instance.dockPanel1); }
private Table ReadSheet(Worksheet sheet, Range SchemaRange) { Table table = new Table(); table.Name = ((Range)(sheet.Cells[1, 2])).Value2.ToString(); table.Description = ((Range)(sheet.Cells[2, 2])).Value2.ToString(); for (int rowIndex = sheet.UsedRange.Row + 4; rowIndex <= sheet.UsedRange.Row + sheet.UsedRange.Rows.Count - 1; rowIndex++) { Column column = new Column(); column.Name = GetValue(sheet, rowIndex, 1); column.Type = GetValue(sheet, rowIndex, 2); //column.Length = GetValue(sheet, rowIndex, 3); //column.Decimals = GetValue(sheet, rowIndex, 4); column.IsCanNull = GetValue(sheet, rowIndex, 3) == "Y"; column.IsPrimaryKey = GetValue(sheet, rowIndex, 4) == "Y"; column.DefaultValue = GetValue(sheet, rowIndex, 5); column.IsIdentity = GetValue(sheet, rowIndex, 6) == "Y"; column.Description = GetValue(sheet, rowIndex, 7); table.Columns.Add(column); } string errmsg = ""; textBox1.Text = JsonHelperClass.ObjectToJson<Table>(table, ref errmsg); return table; }
// Generates content of Sheet. private void GenerateWorksheetPartContent(WorksheetPart worksheetPart, DataTable data, bool isPrimaryTab = false) { Worksheet worksheet1 = new Worksheet() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "x14ac" } }; worksheet1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships"); worksheet1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006"); worksheet1.AddNamespaceDeclaration("x14ac", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"); SheetViews sheetViews = new SheetViews(); SheetView sheetView = new SheetView() { TabSelected = isPrimaryTab, WorkbookViewId = (UInt32Value)0U }; sheetViews.Append(sheetView); SheetFormatProperties sheetFormatProperties1 = new SheetFormatProperties() { DefaultRowHeight = 15D, DyDescent = 0.25D }; //If you want to default select a cell //Selection selection1 = new Selection() { ActiveCell = "A3", SequenceOfReferences = new ListValue<StringValue>() { InnerText = "A3" } }; //sheetView1.Append(selection1); //Column Creation Column tempCol; Columns columns = new Columns(); for (int ii = 0; ii < data.Columns.Count; ii++) { tempCol = new Column() { Min = (UInt32Value)Convert.ToUInt32(ii + 1), Max = (UInt32Value)Convert.ToUInt32(ii + 1), Width = 10.28515625D, CustomWidth = true, BestFit = true }; columns.Append(tempCol); } SheetData sheetData = new SheetData(); //Creating cells and adding them to rows Row row; Cell cell; CellValue cellVal; int rowIndex = 1; string cellName = ""; List<string> cellsWithHyperLinks = new List<string>(); //Insert Header Row row = new Row() { RowIndex = (UInt32Value)Convert.ToUInt32(rowIndex), Spans = new ListValue<StringValue>() { InnerText = "1:" + data.Columns.Count } };//, DyDescent = 0.25D }; for (int jj = 0; jj < data.Columns.Count; jj++) { cellName = GetExcelCellName(jj + 1, rowIndex); cell = new Cell() { CellReference = cellName, StyleIndex = (UInt32Value)1U, DataType = CellValues.String }; cellVal = new CellValue() { Text = data.Columns[jj].ColumnName }; cell.Append(cellVal); row.Append(cell); } sheetData.Append(row); rowIndex++; //Insert Data foreach (DataRow datarow in data.Rows) { row = new Row() { RowIndex = (UInt32Value)Convert.ToUInt32(rowIndex), Spans = new ListValue<StringValue>() { InnerText = "1:" + data.Columns.Count } };//, DyDescent = 0.25D }; for (int jj = 0; jj < data.Columns.Count; jj++) { cellName = GetExcelCellName(jj + 1, rowIndex); cell = new Cell() { CellReference = cellName, StyleIndex = (UInt32Value)0U }; if (data.Columns[jj].DataType == typeof(int) || data.Columns[jj].DataType == typeof(double)) { cell.DataType = CellValues.Number; } else if (data.Columns[jj].DataType == typeof(DateTime)) { cell.DataType = CellValues.Date; } else { cell.DataType = CellValues.String; } cellVal = new CellValue() { Text = datarow[jj].ToString() }; if (cellVal.Text.ToLower().Contains("http")) { cell.StyleIndex = (UInt32Value)2U; cellsWithHyperLinks.Add(cellName); } cell.Append(cellVal); row.Append(cell); } //Add the row to the sheetdata object sheetData.Append(row); rowIndex++; } //Adding hyperlinks Hyperlink hyperlink; Hyperlinks hyperlinks = null; if (cellsWithHyperLinks.Count > 0) { hyperlinks = new Hyperlinks(); for (int ii = 0; ii < cellsWithHyperLinks.Count; ii++) { hyperlink = new Hyperlink() { Reference = cellsWithHyperLinks[ii], Id = "rId" + (ii + 1) }; hyperlinks.Append(hyperlink); } } //PageMargins pageMargins1 = new PageMargins() { Left = 0.7D, Right = 0.7D, Top = 0.75D, Bottom = 0.75D, Header = 0.3D, Footer = 0.3D }; //PageSetup pageSetup1 = new PageSetup() { Orientation = OrientationValues.Portrait, VerticalDpi = (UInt32Value)0U, Id = "rId2" }; worksheet1.Append(sheetViews); worksheet1.Append(sheetFormatProperties1); worksheet1.Append(columns); worksheet1.Append(sheetData); if (hyperlinks != null) { worksheet1.Append(hyperlinks); } //worksheet1.Append(pageMargins1); //worksheet1.Append(pageSetup1); worksheetPart.Worksheet = worksheet1; }