Exemplo n.º 1
0
        public WindowExportExcelSettings(UIControls.ActionBuilder.ActionExportExcel.ExportExcelSettings settings)
        {
            _activeSettings = settings;
            InitializeComponent();

            Sheets = new ObservableCollection <Sheet>();
            Fields = new ObservableCollection <CheckedListItem <PropertyItem> >();

            FileName = settings.FileName;
            foreach (var s in settings.Sheets)
            {
                var ns = new Excel.Sheet();
                ns.Name = s.Name;
                foreach (var item in s.SelectedItems)
                {
                    ns.SelectedItems.Add(item);
                }
                Sheets.Add(ns);
            }

            foreach (var fi in PropertyItem.PropertyItems.OrderBy(x => x.ToString()))
            {
                CheckedListItem <PropertyItem> cli = new CheckedListItem <PropertyItem>(fi, false);
                Fields.Add(cli);
                cli.PropertyChanged += cli_PropertyChanged;
            }

            FileName = settings.FileName;
            if (Sheets.Count > 0)
            {
                ActiveSheet = Sheets[0];
            }

            DataContext = this;
        }
Exemplo n.º 2
0
        private ExportExcelSettings GetSettingsFromValue(string v)
        {
            var result = new ExportExcelSettings();

            if (!string.IsNullOrEmpty(v))
            {
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(v);

                    XmlNodeList nl = doc.SelectNodes("/settings/setting");
                    foreach (XmlNode n in nl)
                    {
                        switch (n.Attributes["name"].Value)
                        {
                        case "FileName":
                            result.FileName = n.Attributes["value"].Value;
                            break;
                        }
                    }
                    nl = doc.SelectNodes("/settings/sheet");
                    foreach (XmlNode n in nl)
                    {
                        var sheet = new Excel.Sheet();
                        sheet.Name = n.Attributes["name"].Value;
                        var parts = n.Attributes["items"].Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var p in parts)
                        {
                            var pi = (from a in Excel.PropertyItem.PropertyItems where a.GetType().ToString() == p select a).FirstOrDefault();
                            if (pi != null)
                            {
                                sheet.SelectedItems.Add(pi);
                            }
                        }
                        result.Sheets.Add(sheet);
                    }
                }
                catch
                {
                    result = null;
                }
            }
            return(result);
        }
 public SheetAdapter(Excel.Sheet sheet)
 {
     _sheet = sheet;
 }
        private static void GenerateDAOScript(string projectCode, string destPath, string assetDestPath, string baseName, string keyType, Excel.Sheet sheet)
        {
            var path    = DAOScriptPath(destPath, baseName, sheet.name);
            var content = kDaoTemplate
                          .Replace("${BASE_NAMESPACE}", BaseNamespace(projectCode, destPath))
                          .Replace("${BASE_NAME}", baseName)
                          .Replace("${NAME}", sheet.name)
                          .Replace("${KEY_TYPE}", keyType)
                          .Replace("${ASSET_DEST_BASE_PATH}", assetDestPath)
                          .ReplaceEOL("\n");

            GenerateScript(path, content);
        }
        private static void GenerateVOScript(string projectCode, string destPath, string baseName, Excel.Sheet sheet)
        {
            var defineBuilder = new StringBuilder();
            var fieldBuilder  = new StringBuilder();
            var nameCells     = sheet.GetRowCells((int)RowSettings.KeyName);
            var defineCells   = sheet.GetRowCells((int)RowSettings.EnumDefine);
            var typeCells     = sheet.GetRowCells((int)RowSettings.Type);

            for (int i = 0; i < nameCells.Length; i++)
            {
                if (string.IsNullOrEmpty(defineCells[i].value))
                {
                    continue;
                }
                defineBuilder.AppendLine("public enum " + typeCells[i].value + " {");
                defineBuilder.AppendLine(defineCells[i].value.Indent(4));
                defineBuilder.AppendLine("}");
            }
            for (int i = 0; i < nameCells.Length; i++)
            {
                fieldBuilder.AppendLine(string.Format("public {0} {1};", typeCells[i].value, nameCells[i].value));
            }
            var path    = VOScriptPath(destPath, baseName, sheet.name);
            var content = kVoTemplate
                          .Replace("${BASE_NAMESPACE}", BaseNamespace(projectCode, destPath))
                          .Replace("${BASE_NAME}", baseName)
                          .Replace("${NAME}", sheet.name)
                          .Replace("${FIELDS}", fieldBuilder.ToString().Indent(8))
                          .Replace("${KEY_TYPE}", typeCells[(int)ColumnSettings.Key].value)
                          .Replace("${KEY_NAME}", nameCells[(int)ColumnSettings.Key].value)
                          .ReplaceEOL("\n");

            GenerateScript(path, content);
        }