Ejemplo n.º 1
0
        public void RefreshResource()
        {
            string v = CCommon.GetValue(CCommon.key_tableP);

            if (Directory.Exists(v))
            {
                #region 1.file ext
                List <string> p       = new List <string>();
                bool          isExcel = CCommon.GetValue(CCommon.key_fileExcel) == "1";
                bool          isTxt   = CCommon.GetValue(CCommon.key_fileTxt) == "1";
                bool          isCode  = CCommon.GetValue(CCommon.key_fileCode) == "1";
                if (isExcel)
                {
                    p.Add(".xlsm");
                }
                if (isTxt)
                {
                    p.Add(".txt");
                }
                if (isCode)
                {
                    p.Add(".cs");
                }
                #endregion

                #region 2. filter is change the root path
                if (m_ResItems.Count > 0)
                {
                    if (m_ResItems.First().Path != v)
                    {
                        m_ResItems.Clear();
                    }
                }
                CResourceItem resItemRoot;
                if (m_ResItems.Count > 0)
                {
                    resItemRoot = m_ResItems[0];
                }
                else
                {
                    resItemRoot = new CResourceItem();
                    string curName = System.IO.Path.GetFileName(v);
                    resItemRoot.Icon        = CCommon.StrFolderIconPath;
                    resItemRoot.DisplayName = curName;
                    resItemRoot.Path        = v;
                    m_ResItems.Add(resItemRoot);
                }
                m_ResManager.GetResources(v, resItemRoot, p.ToArray());
                tw_item.ItemsSource = m_ResItems;
                if (tw_item.ItemContainerGenerator.Items.Count > 0)
                {
                    TreeViewItem ti = (TreeViewItem)(tw_item.ItemContainerGenerator.ContainerFromIndex(0));
                    if (ti != null)
                    {
                        ti.IsExpanded = true;
                    }
                }
                #endregion
            }
        }
Ejemplo n.º 2
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     tb_code_path.Text               = CCommon.GetValue(CCommon.key_codeEP);
     tb_table_path.Text              = CCommon.GetValue(CCommon.key_tableP);
     tb_table_exopt_path.Text        = CCommon.GetValue(CCommon.key_tableEP);
     tb_table_exopt_binary_path.Text = CCommon.GetValue(CCommon.key_tableEBP);
     cb_excel.IsChecked              = CCommon.GetValue(CCommon.key_fileExcel) == "1";
     cb_txt.IsChecked  = CCommon.GetValue(CCommon.key_fileTxt) == "1";
     cb_code.IsChecked = CCommon.GetValue(CCommon.key_fileCode) == "1";
 }
Ejemplo n.º 3
0
 private void MenuItem_ExportTableBinary_Click(object sender, RoutedEventArgs e)
 {
     ThreadPool.QueueUserWorkItem((o) =>
     {
         string s = @"Build\SHLib\SHLib\SHLib.csproj";
         string t = CCommon.GetValue(CCommon.key_codeEP);
         string l = @"Build\Link\ToolLinkCode.exe";
         string b = @"Build\Build\AutoBuild.bat";
         m_BuildManager.AutoLink(s, t, l);
         int buildBack = m_BuildManager.AutoBuild(b);
         if (buildBack > 0)
         {
             Clog.Instance.LogError("编译失败 错误代码:" + buildBack);
         }
     });
 }
Ejemplo n.º 4
0
        private void cb_fileType_UnChecked(object sender, RoutedEventArgs e)
        {
            CheckBox c = sender as CheckBox;

            switch (c.Name)
            {
            case "cb_excel": CCommon.SetValue(CCommon.key_fileExcel, "0"); break;

            case "cb_txt": CCommon.SetValue(CCommon.key_fileTxt, "0"); break;

            case "cb_code": CCommon.SetValue(CCommon.key_fileCode, "0"); break;

            default:
                break;
            }
        }
Ejemplo n.º 5
0
        private void bt_table_setting_Click(object sender, RoutedEventArgs e)
        {
            string lastSelect = CCommon.GetValue(CCommon.key_tableP);

            System.Windows.Forms.FolderBrowserDialog folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
            if (Directory.Exists(lastSelect))
            {
                lastSelect = System.IO.Path.GetFullPath(lastSelect);
                folderBrowserDialog.SelectedPath = lastSelect;
            }
            System.Windows.Forms.DialogResult result = folderBrowserDialog.ShowDialog();
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                string path     = folderBrowserDialog.SelectedPath;
                string relative = ChangeToRelativePath(path);
                CCommon.SetValue(CCommon.key_tableP, relative);
                tb_table_path.Text = relative;
            }
        }
Ejemplo n.º 6
0
        public bool ExportTable(string path)
        {
            if (m_bIsExporting)
            {
                Clog.Instance.LogError("请等待上一次导出完成");
                return(false);
            }
            m_bIsExporting = true;
            if (!CExcelManager.Instance.Open(path))
            {
                m_bIsExporting = false;
                Clog.Instance.LogError("Excel打开失败");
                return(false);
            }
            Sheets sheets = CExcelManager.Instance.GetSheets();

            if (sheets == null)
            {
                m_bIsExporting = false;
                Clog.Instance.LogError("Excel找不到有效页签供导出");
                return(false);
            }
            int sheetsCount = sheets.Count;

            for (int i = 2; i <= sheetsCount; i++)
            {
                Worksheet sheet = sheets[i];
                if (sheet.Name.Contains("~"))
                {
                    continue;
                }
                string exportPath = CCommon.GetValue(CCommon.key_tableEP);
                if (!CFileManager.DirectorExist(exportPath))
                {
                    Clog.Instance.LogError("导出路径不存在:" + exportPath);
                    continue;
                }
                CTableTemplate tableTemplate = new CTableTemplate(sheet);
                if (tableTemplate == null)
                {
                    Clog.Instance.LogError(sheet.Name + "导出失败");
                    continue;
                }
                string        excelFilePath = Path.Combine(exportPath, sheet.Name + ".txt");
                FileStream    fs            = CFileManager.Open(excelFilePath, FileMode.Create);
                StreamWriter  st            = new StreamWriter(fs);
                StringBuilder s             = new StringBuilder();
                CCell         sheetBound    = tableTemplate.RangeBound;

                string strEnd = _GetColumnChar(sheetBound.Column) + sheetBound.Row;
                Range  cells  = sheet.Range["A1", strEnd].Cells;
                object[,] realCells = cells.Value;
                for (int r = 1; r <= sheetBound.Row; r++)
                {
                    s.Clear();
                    string cellValue = string.Empty;
                    object o         = realCells[r, 1];
                    if (o != null)
                    {
                        cellValue = o.ToString();
                    }
                    if (cellValue == CCommon.StrSkipRows)
                    {
                        continue;
                    }
                    for (int c = 1; c <= sheetBound.Column; c++)
                    {
                        cellValue = string.Empty;
                        o         = realCells[r, c];
                        if (o != null)
                        {
                            cellValue = o.ToString();
                        }
                        s.Append(cellValue);
                        s.Append(",");
                    }
                    st.WriteLine(s.ToString());
                }
                st.Close();
                fs.Close();
                st.Dispose();
                fs.Dispose();
                Clog.Instance.Log(sheet.Name + "导出成功");
            }
            m_bIsExporting = false;
            return(true);
        }
Ejemplo n.º 7
0
        public bool CreateCode(string path)
        {
            if (m_bIsGenerate)
            {
                Clog.Instance.LogError("请等待上一次生成代码完成");
                return(false);
            }
            m_bIsGenerate = true;
            if (!CExcelManager.Instance.Open(path))
            {
                m_bIsGenerate = false;
                Clog.Instance.LogError("Excel打开失败");
                return(false);
            }
            Sheets sheets = CExcelManager.Instance.GetSheets();

            if (sheets == null)
            {
                m_bIsGenerate = false;
                Clog.Instance.LogError("Excel找不到有效页签供生成代码");
                return(false);
            }
            int sheetsCount = sheets.Count;

            for (int i = 2; i <= sheetsCount; i++)
            {
                Worksheet sheet = sheets[i];
                if (sheet.Name.Contains("~"))
                {
                    continue;
                }
                string exportPath = CCommon.GetValue(CCommon.key_codeEP);
                if (!CFileManager.DirectorExist(exportPath))
                {
                    Clog.Instance.LogError("导出路径不存在:" + exportPath);
                    continue;
                }
                CTableTemplate tableTemplate = new CTableTemplate(sheet);
                if (tableTemplate == null)
                {
                    Clog.Instance.LogError(sheet.Name + "生成失败");
                    continue;
                }
                #region 1.write table

                FileStream    fs;
                StreamWriter  st;
                bool          isOverride = true;
                List <string> dataName   = tableTemplate.GetRowContent(CTableTemplate.KeyColumn);
                List <string> dataType   = tableTemplate.GetRowContent(CTableTemplate.KeyDataType);
                if (dataName == null || dataType == null)
                {
                    Clog.Instance.LogError("列名和列类型获取失败");
                    return(false);
                }
                string fileName      = "C" + sheet.Name + "Table.cs";
                string excelFilePath = Path.Combine(exportPath, fileName);
                if (File.Exists(excelFilePath))
                {
                    DialogResult r = MessageBox.Show("是否覆盖文件 " + fileName, "", MessageBoxButtons.YesNo);
                    isOverride = r == DialogResult.Yes;
                }
                if (isOverride)
                {
                    string tableScript = CFileManager.ReadAllText("Template/TableTemplate.cs");
                    tableScript = tableScript.Replace("#author#", "TM");
                    tableScript = tableScript.Replace("#datetime#", DateTime.Now.ToString("yyyy-MM-dd"));
                    tableScript = tableScript.Replace("#tablename#", sheet.Name);
                    tableScript = tableScript.Replace("#tableinforow_fields#", GetTableRowInfoFields(dataName, dataType));
                    tableScript = tableScript.Replace("#tableinforow_init#", GetTableRowInfoInit(dataName, dataType));

                    fs = CFileManager.Open(excelFilePath, FileMode.Create);
                    st = new StreamWriter(fs);
                    st.Write(tableScript);
                    st.Close();
                    fs.Close();
                    st.Dispose();
                    fs.Dispose();
                }
                #endregion

                #region 2.write tableinfo

                isOverride    = true;
                fileName      = "C" + sheet.Name + "TableInfo.cs";
                excelFilePath = Path.Combine(exportPath, fileName);
                string matchInit = string.Empty;
                string matchPro  = string.Empty;
                if (File.Exists(excelFilePath))
                {
                    DialogResult r = MessageBox.Show("是否覆盖文件 " + fileName, "", MessageBoxButtons.YesNo);
                    isOverride = r == DialogResult.Yes;
                    string input = File.ReadAllText(excelFilePath);

                    Match match = Regex.Match(input, @"#region Init([\s\S]*)#endregion Init");
                    if (match.Groups.Count >= 2)
                    {
                        matchInit = match.Groups[1].ToString();
                        matchInit = matchInit.Replace("\r\n\r\n", "");
                        int idx = matchInit.IndexOf("public");
                        matchInit = matchInit.Substring(idx);
                    }
                    match = Regex.Match(input, @"#region Properties([\s\S]*)#endregion Properties");
                    if (match.Groups.Count >= 2)
                    {
                        matchPro = match.Groups[1].ToString();
                        matchPro = matchPro.Replace("\r\n\r\n", "");
                        int idx = matchPro.IndexOf("public");
                        matchPro = matchPro.Substring(idx);
                    }
                }
                if (isOverride)
                {
                    string tableInfoScript = CFileManager.ReadAllText("Template/TableInfoTemplate.cs");
                    tableInfoScript = tableInfoScript.Replace("#author#", "TM");
                    tableInfoScript = tableInfoScript.Replace("#datetime#", DateTime.Now.ToString("yyyy-MM-dd"));
                    tableInfoScript = tableInfoScript.Replace("#tablename#", sheet.Name);
                    tableInfoScript = tableInfoScript.Replace("#tableinfo_fields#", GetFields(dataName, dataType));
                    tableInfoScript = tableInfoScript.Replace("#tableinfo_serialize#", GetSerialize(dataName));
                    tableInfoScript = tableInfoScript.Replace("#tableinfo_unserialize#", GetUnSerialize(dataName));
                    tableInfoScript = tableInfoScript.Replace("#tableinfo_assign#", GetAssign(dataName));

                    if (string.IsNullOrEmpty(matchPro))
                    {
                        tableInfoScript = tableInfoScript.Replace("#tableinfo_properties#", GetPropertiess(dataName, dataType));
                    }
                    else
                    {
                        tableInfoScript = tableInfoScript.Replace("#tableinfo_properties#", matchPro);
                    }

                    if (string.IsNullOrEmpty(matchInit))
                    {
                        tableInfoScript = tableInfoScript.Replace("#tableinfo_init#", GetInit());
                    }
                    else
                    {
                        tableInfoScript = tableInfoScript.Replace("#tableinfo_init#", matchInit);
                    }

                    fs = CFileManager.Open(excelFilePath, FileMode.Create);
                    st = new StreamWriter(fs);
                    st.Write(tableInfoScript);
                    st.Close();
                    fs.Close();
                    st.Dispose();
                    fs.Dispose();
                }
                #endregion
                Clog.Instance.Log(sheet.Name + "生成成功");
            }
            m_bIsGenerate = false;
            return(true);
        }