예제 #1
0
        public override bool SaveAddNew()
        {
            TablesInfo info = new TablesInfo();

            SetInfo(info);

            try
            {
                #region 新增数据

                XmlHelper xmltableshelper = new XmlHelper(@"XML\entity.xml");
                // <name>{0}</name><chineseName>{1}</chineseName><functionId>{2}</functionId><path>{3}</path>
                xmltableshelper.InsertElement("datatype/dataitem", "item", "gid", info.Gid, string.Format(tablesModel, info.Name, info.ChineseName, info.FunctionId, info.BasicdataPath));

                xmltableshelper.Save();

                // 新增表名.entity文件
                FileUtil.AppendText(string.Format(@"XML\{0}.entity", info.Name), string.Format(tablesDetailModel, System.Guid.NewGuid(), info.FunctionId, info.Name, info.ChineseName, string.Empty, "1.0.0.0", string.Empty, string.Empty, DateTimeHelper.GetServerDateTime(), string.Empty), Encoding.UTF8);

                strItemName    = info.Name;
                intFunction    = info.FunctionId;
                strChineseName = info.ChineseName;
                // TODO
                //Id = info.GUID;
                return(true);

                #endregion
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(FrmEditItemName));
                MessageDxUtil.ShowError(ex.Message);
            }
            return(false);
        }
예제 #2
0
파일: Form1.cs 프로젝트: yyan/winform
        private void btnFileUtil_Click(object sender, EventArgs e)
        {
            string filePath = "DB\\Test.txt";

            //创建一个文件并添加文本
            FileUtil.AppendText(filePath, "测试内容", Encoding.Default);

            //获取文件编码
            Encoding encode     = FileUtil.GetEncoding(filePath);
            string   encodename = encode.EncodingName;

            //读取文件内容
            string content = FileUtil.FileToString(filePath);

            //读取文件到内存流
            Stream stream = FileUtil.FileToStream(filePath);

            stream.Close();

            //获取文件创建时间
            DateTime dtCreate = FileUtil.GetFileCreateTime(filePath);

            //设置文件只读
            FileUtil.SetFileReadonly(filePath, true);
        }
        public override bool SaveAddNew()
        {
            TablesInfo info = new TablesInfo();

            SetInfo(info);

            try
            {
                #region 新增数据
                XmlHelper xmltableshelper = new XmlHelper(@"XML\tables.xml");
                xmltableshelper.Replace(string.Format("datatype/dataitem/item[@gid=\"{0}\"]/basicdatapath", info.Gid), info.BasicdataPath);
                xmltableshelper.Save();

                if (FileUtil.FileIsExist(info.BasicdataPath))
                {
                    FileUtil.DeleteFile(info.BasicdataPath);
                }

                string tablesdataDetailModel = "<?xml version=\"1.0\" encoding=\"utf-8\"?><datatype><dataitem></dataitem></datatype>";
                FileUtil.AppendText(info.BasicdataPath, tablesdataDetailModel, System.Text.Encoding.UTF8);

                //ID = info.GUID;
                strItemName = cbbItemName.SelectedText;
                return(true);

                #endregion
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(FrmEditBasicDataItemName));
                MessageDxUtil.ShowError(ex.Message);
            }
            return(false);
        }
예제 #4
0
        /// <summary>
        /// 查找不适用文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnFindNotSetFile_Click(object sender, EventArgs e)
        {
            string path = txtPath.Text.Trim();

            if (string.IsNullOrEmpty(path))
            {
                path = FileDialogHelper.OpenDir();
            }

            if (!DirectoryUtil.IsExistDirectory(path))
            {
                MessageDxUtil.ShowTips("文件路径不可用");
                return;
            }

            string recordFileName = "\\" + "不适用文件.txt";

            if (FileUtil.FileIsExist(path + recordFileName))
            {
                FileUtil.DeleteFile(path + recordFileName);
            }
            FileUtil.CreateFile(path + recordFileName);

            string[] allFiles = DirectoryUtil.GetAllFileNames(path);
            foreach (var file in allFiles)
            {
                FileInfo fileInfo = new FileInfo(file);
                if (fileInfo.Name.Contains("不适用"))
                {
                    FileUtil.AppendText(path + recordFileName, string.Format("{0}\t\t\t{1}\r\n", fileInfo.Name, fileInfo.FullName), Encoding.UTF8);
                }
            }

            MessageDxUtil.ShowTips("操作完成");
        }
예제 #5
0
        protected virtual void CreateDSNFile()
        {
            string dsnFile = Path.Combine(GlobalSetting.Config.TempDirectory, "Demo.dsn");

            FileUtil.CreateFile(dsnFile);
            FileUtil.AppendText(dsnFile, "124", true);
            FileUtil.AppendText(dsnFile, "222", true);
            FileUtil.AppendText(dsnFile, "2234", true);
        }
예제 #6
0
        private void btnGetMachineCode_Click(object sender, EventArgs e)
        {
            // 不自动更新排除的文件 license.lic 序列号
            // log              日志文件
            // AutoUpdater      自动更新
            string startupPath = Application.StartupPath;

            if (FileUtil.IsExistFile(startupPath + "\\" + txtFileName.Text.Trim()))
            {
                FileUtil.DeleteFile(startupPath + "\\" + txtFileName.Text.Trim());
            }

            // 写入前面的模板
            FileUtil.AppendText(txtFileName.Text.Trim(), "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n", Encoding.UTF8);
            FileUtil.AppendText(txtFileName.Text.Trim(), "<manifest>\r\n", Encoding.UTF8);
            FileUtil.AppendText(txtFileName.Text.Trim(), "\t<version>" + txtVersion.Text.Trim() + "</version>\r\n", Encoding.UTF8);
            FileUtil.AppendText(txtFileName.Text.Trim(), "\t<description>" + txtUpdateInfo.Text.Trim() + "</description>\r\n", Encoding.UTF8);
            FileUtil.AppendText(txtFileName.Text.Trim(), "\t<!--applicationId运用程序ID,需要与客户端配置一样,否则不会进行更新-->\r\n", Encoding.UTF8);
            FileUtil.AppendText(txtFileName.Text.Trim(), "\t<myapplication applicationId=\"" + txtApplicationId.Text.Trim() + "\">\r\n", Encoding.UTF8);
            FileUtil.AppendText(txtFileName.Text.Trim(), "\t\t<!--暂时没有使用,重新启动exe名称,parameters启动时传入的参数-->\r\n", Encoding.UTF8);
            FileUtil.AppendText(txtFileName.Text.Trim(), "\t\t<entryPoint file=\"" + txtMain.Text.Trim() + "\" parameters=\"" + txtparam.Text.Trim() + "\" />\r\n", Encoding.UTF8);
            FileUtil.AppendText(txtFileName.Text.Trim(), "\t</myapplication>\r\n", Encoding.UTF8);
            FileUtil.AppendText(txtFileName.Text.Trim(), "\t<!--base表示存放该文件的url-->\r\n", Encoding.UTF8);
            FileUtil.AppendText(txtFileName.Text.Trim(), "\t<files base=\"http://www.jcodes.cn/update/Pack/\">\r\n", Encoding.UTF8);
            FileUtil.AppendText(txtFileName.Text.Trim(), "\t\t<!--文件名称-->\r\n", Encoding.UTF8);

            string[] files = DirectoryUtil.GetAllFileNames(startupPath);
            for (Int32 i = 0; i < files.Length; i++)
            {
                // 日志路径
                if (files[i].Contains("log\\"))
                {
                    continue;
                }
                if (files[i].Contains("license.lic"))
                {
                    continue;
                }
                if (files[i].Contains("AutoUpdater"))
                {
                    continue;
                }

                FileStream fsread  = new FileStream(files[i], FileMode.Open, FileAccess.Read, FileShare.Read);
                byte[]     md5File = new byte[fsread.Length];
                fsread.Read(md5File, 0, (int)fsread.Length);                               // 将文件流读取到Buffer中
                fsread.Close();
                string result = MD5Util.MD5Buffer(md5File, 0, md5File.Length);             // 对Buffer中的字节内容算MD5
                string tmp    = files[i].Replace(startupPath + "\\", "");
                FileUtil.AppendText(txtFileName.Text.Trim(), "\t\t<file source=\"" + tmp + "\" md5=\"" + result + "\" checkmd5=\"true\" />\r\n", Encoding.UTF8);
            }
            FileUtil.AppendText(txtFileName.Text.Trim(), "\t</files>\r\n", Encoding.UTF8);
            FileUtil.AppendText(txtFileName.Text.Trim(), "</manifest>\r\n", Encoding.UTF8);

            MessageDxUtil.ShowTips("操作完成");
        }
예제 #7
0
        private void sbtnOk_Click(object sender, EventArgs e)
        {
            string str = txtDSPath.Text.Trim();

            if (string.IsNullOrEmpty(str))
            {
                MessageUtil.ShowTips("请选择导出权限文件存放位置位置!");
            }
            else
            {
                try
                {
                    string filePath = str + "DoorPower.txt";     // "C:\\Test.txt";

                    if (FileUtil.IsExistFile(filePath))
                    {
                        FileUtil.ClearFile(filePath);
                    }
                    else
                    {
                        FileUtil.AppendText(filePath, "");
                    }

                    string    strSql = "select ID,tvParent,tvChildId,IsGroup,GroupName,UserName,IcNo,IsPower from tb_DoorUser  ";
                    DataTable dt     = datalogic.GetDataTable(strSql);
                    foreach (DataRow datarow in dt.Rows)
                    {
                        string strTxt = "";
                        strTxt  = datarow["ID"].ToString();
                        strTxt += ",";
                        strTxt += datarow["tvParent"].ToString();
                        strTxt += ",";
                        strTxt += datarow["tvChildId"].ToString();
                        strTxt += ",";
                        strTxt += datarow["IsGroup"].ToString();
                        strTxt += ",";
                        strTxt += datarow["GroupName"].ToString();
                        strTxt += ",";
                        strTxt += datarow["IcNo"].ToString();
                        strTxt += ",";
                        strTxt += datarow["IsPower"].ToString();
                        strTxt += "\r\n";

                        FileUtil.AppendText(filePath, strTxt);
                    }
                    MessageUtil.ShowTips("导出权限成功!");
                }
                catch (Exception ex)
                {
                    MessageUtil.ShowTips(ex.Message);
                }
            }
        }
예제 #8
0
        private void simpleButton3_Click(object sender, EventArgs e)
        {
            string path = txtPath.Text.Trim();

            if (string.IsNullOrEmpty(path))
            {
                path = FileDialogHelper.OpenDir();
            }

            string fileRecord    = "F:\\oldfile.txt";
            string fileNewReocrd = "F:\\newfile.txt";

            if (FileUtil.IsExistFile(fileRecord))
            {
                FileUtil.DeleteFile(fileRecord);
            }
            FileUtil.CreateFile(fileRecord);

            if (FileUtil.IsExistFile(fileNewReocrd))
            {
                FileUtil.DeleteFile(fileNewReocrd);
            }
            FileUtil.CreateFile(fileNewReocrd);

            Int32 copyCount = 0;

            if (!string.IsNullOrEmpty(path))
            {
                string[] files = DirectoryUtil.GetFileNames(path, "*", true);

                foreach (var file in files)
                {
                    FileUtil.AppendText(fileRecord, file + "\r\n", Encoding.UTF8);

                    string oldfilerelatefile = file.Replace(path + "\\", "");
                    string newfllerelatefile = oldfilerelatefile.Replace("\\", "_");
                    if (FileUtil.IsExistFile(file) && oldfilerelatefile != newfllerelatefile)
                    {
                        File.Move(file, path + "\\" + newfllerelatefile);
                        copyCount++;
                    }
                }

                files = DirectoryUtil.GetFileNames(path, "*", true);
                foreach (var file in files)
                {
                    FileUtil.AppendText(fileNewReocrd, file + "\r\n", Encoding.UTF8);
                }
            }

            MessageDxUtil.ShowTips("操作完成, 一共成功复制" + copyCount + "个文件");
        }
예제 #9
0
        public override bool SaveAddNew()
        {
            TablesInfo info = new TablesInfo();

            SetInfo(info);

            try
            {
                #region 新增数据
                // 获取数据库数据类型
                XmlHelper   xmlprojhelper     = new XmlHelper(@"XML\project.xml");
                XmlNodeList xmlprejectNodeLst = xmlprojhelper.Read("datatype");

                if (xmlprejectNodeLst.Count == 0)
                {
                    return(false);
                }

                XmlNode xn1project = xmlprejectNodeLst[0];
                // 将节点转换为元素,便于得到节点的属性值
                XmlElement xeproject = (XmlElement)xn1project;

                // 得到DataTypeInfo节点的所有子节点
                XmlNodeList xnl0project = xeproject.ChildNodes;

                string DbType = xnl0project.Item(4).InnerText;

                XmlHelper xmltableshelper = new XmlHelper(@"XML\tables.xml");
                xmltableshelper.InsertElement("datatype/dataitem", "item", "guid", info.GUID, string.Format(tablesModel, info.Name, info.ChineseName, info.FunctionId, info.TypeGuid, info.Path));

                xmltableshelper.Save();

                // 新增表名.table文件
                FileUtil.AppendText(string.Format(@"XML\{0}.table", info.Name), string.Format(tablesDetailModel, System.Guid.NewGuid(), info.FunctionId, info.Name, info.ChineseName, Const.Zero, DbType, "1.0.0.0", DateTimeHelper.GetServerDateTime(), string.Empty), Encoding.UTF8);

                strItemName    = info.Name;
                strFunction    = info.FunctionId;
                strChineseName = info.ChineseName;
                ID             = info.GUID;
                return(true);

                #endregion
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(FrmEditItemName));
                MessageDxUtil.ShowError(ex.Message);
            }
            return(false);
        }
예제 #10
0
        /// <summary>
        /// 根据配置导出SQL
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGenerateSQL_Click(object sender, EventArgs e)
        {
            if (projectInfo != null)
            {
                if (string.IsNullOrEmpty(projectInfo.OutputPath))
                {
                    MessageDxUtil.ShowError("请在项目菜单中配置导出脚本路径");
                    return;
                }

                if (!DirectoryUtil.IsExistDirectory(projectInfo.OutputPath))
                {
                    MessageDxUtil.ShowError(string.Format("配置的路径{0}在系统中不存在,请在项目菜单中配置导出脚本路径", projectInfo.OutputPath));
                    return;
                }

                // 操控进度条
                var           progressBar = (this.MdiParent as MainForm).progressBar;
                string        fileName    = "Dict.Sql";
                string        sqlfile     = projectInfo.OutputPath + "\\" + fileName;
                StringBuilder sb          = new StringBuilder();

                switch (projectInfo.DbType)
                {
                case "Oracle": break;

                case "Mysql": break;

                case "DB2": break;

                case "SqlServer":
                {
                    #region 对于SqlServer 脚本的处理
                    if (FileUtil.IsExistFile(sqlfile))
                    {
                        FileUtil.DeleteFile(sqlfile);
                    }
                    List <ModRecordInfo> lst = new List <ModRecordInfo>();
                    lst.Add(new ModRecordInfo()
                        {
                            ModDate = DateTimeHelper.GetServerDateTime2(), ModVersion = new Version("1.0.0.0").ToString(), ModOrderId = "M1234567890", Proposer = "测试递申人", Programmer = "测试修改人", ModContent = "这里是修改内容", ModReason = "修改原因", Remark = "备注信息"
                        });

                    // 创建文件
                    FileUtil.CreateFile(sqlfile);
                    // 添加文本信息
                    //FileUtil.AppendText(sqlfile, SqlServerGenerate.printHeaderInfo(fileName, "V1.3.2.1111", "Jimmy", "2017-09-01 13:22:11", "备注信息", "2017-07-01", lst), Encoding.Default);
                    FileUtil.AppendText(sqlfile, SqlOperate.printHeaderInfo(projectInfo.DbType, fileName, "V1.3.2.1111", "Jimmy", "2017-09-01 13:22:11", "备注信息", "2017-07-01", lst), Encoding.Default);

                    //FileUtil.AppendText(sqlfile, SqlServerGenerate.printInitInfo("T_Basic_DictType"), Encoding.Default);

                    //FileUtil.AppendText(sqlfile, SqlServerGenerate.printInitInfo("T_Basic_DictData"), Encoding.Default);

                    // TODO 这里需要等表结果完成在做


                    break;
                    #endregion
                }

                case "Sqlite": break;

                case "Access": break;
                }
            }
        }
예제 #11
0
        //第二步:定义执行线程主体事件
        //线程主体方法
        public void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            List <object> args = e.Argument as List <object>;

            #region 根据项目属性获取数据类型
            XmlHelper   xmlprojectthelper = new XmlHelper(@"XML\project.xml");
            XmlNodeList xmlprejectNodeLst = xmlprojectthelper.Read("datatype");

            if (xmlprejectNodeLst.Count == 0)
            {
                return;
            }

            XmlNode xn1project = xmlprejectNodeLst[0];

            // 将节点转换为元素,便于得到节点的属性值
            XmlElement xeproject = (XmlElement)xn1project;

            // 得到DataTypeInfo节点的所有子节点
            XmlNodeList xnl0project = xeproject.ChildNodes;

            string dbType   = xnl0project.Item(4).InnerText;
            string filePath = xnl0project.Item(9).InnerText;
            #endregion

            switch (args[0].ToString())
            {
            case "GenerTableSql":
                string[] filenames = args[1] as string[];
                Dictionary <string, string> constrainttypelst = new Dictionary <string, string>();
                constrainttypelst.Add("0", "主键");
                constrainttypelst.Add("1", "索引");
                constrainttypelst.Add("2", "唯一索引");

                //在线程中更新UI(通过ReportProgress方法)
                //...执行线程任务

                #region 先读取datatype.xml 在读取defaulttype.xml 然后Linq 查询保存到数据字典dic中
                XmlHelper           xmldatatypehelper  = new XmlHelper(@"XML\datatype.xml");
                XmlNodeList         xmldatatypeNodeLst = xmldatatypehelper.Read("datatype");
                List <DataTypeInfo> dataTypeInfoList   = new List <DataTypeInfo>();
                foreach (XmlNode xn1 in xmldatatypeNodeLst)
                {
                    DataTypeInfo dataTypeInfo = new DataTypeInfo();
                    // 将节点转换为元素,便于得到节点的属性值
                    XmlElement xe = (XmlElement)xn1;
                    // 得到Type和ISBN两个属性的属性值
                    dataTypeInfo.Gid = xe.GetAttribute("gid").ToString();

                    // 得到DataTypeInfo节点的所有子节点
                    XmlNodeList xnl0 = xe.ChildNodes;
                    dataTypeInfo.Name      = xnl0.Item(0).InnerText;
                    dataTypeInfo.StdType   = xnl0.Item(2).InnerText;
                    dataTypeInfo.Length    = xnl0.Item(3).InnerText;
                    dataTypeInfo.Precision = xnl0.Item(4).InnerText;

                    dataTypeInfoList.Add(dataTypeInfo);
                }

                XmlHelper   defaulttypexmlHelper  = new XmlHelper(@"XML\defaulttype.xml");
                XmlNodeList defaulttypexmlNodeLst = defaulttypexmlHelper.Read("datatype");
                Dictionary <string, string> dict  = new Dictionary <string, string>();
                foreach (var dataTypeInfo in dataTypeInfoList)
                {
                    foreach (XmlNode xn1 in defaulttypexmlNodeLst)
                    {
                        // 将节点转换为元素,便于得到节点的属性值
                        XmlElement xe = (XmlElement)xn1;
                        // 得到DataTypeInfo节点的所有子节点
                        XmlNodeList xnl0  = xe.ChildNodes;
                        string      value = string.Empty;
                        if (dbType == "Oracle")
                        {
                            value = xnl0.Item(2).InnerText;
                        }
                        else if (dbType == "Mysql")
                        {
                            value = xnl0.Item(3).InnerText;
                        }
                        else if (dbType == "DB2")
                        {
                            value = xnl0.Item(4).InnerText;
                        }
                        else if (dbType == "SqlServer")
                        {
                            value = xnl0.Item(5).InnerText;
                        }
                        else if (dbType == "Sqlite")
                        {
                            value = xnl0.Item(6).InnerText;
                        }
                        else if (dbType == "Access")
                        {
                            value = xnl0.Item(7).InnerText;
                        }

                        // 找到匹配记录
                        if (dataTypeInfo.StdType == xnl0.Item(0).InnerText)
                        {
                            if (value.Contains("$L"))
                            {
                                if (String.Empty == dataTypeInfo.Length)
                                {
                                    value = value.Replace("$L", "0");
                                }
                                else
                                {
                                    value = value.Replace("$L", dataTypeInfo.Length);
                                }
                            }
                            if (value.Contains("$P"))
                            {
                                if (String.Empty == dataTypeInfo.Precision)
                                {
                                    value = value.Replace("$P", "0");
                                }
                                else
                                {
                                    value = value.Replace("$P", dataTypeInfo.Precision);
                                }
                            }
                            dict.Add(dataTypeInfo.Name, value);
                        }
                    }
                }

                XmlHelper   stdfieldxmlHelper  = new XmlHelper(@"XML\stdfield.xml");
                XmlNodeList stdfieldxmlNodeLst = stdfieldxmlHelper.Read("datatype/dataitem");

                List <StdFieldComboBox> stdFieldInfoList = new List <StdFieldComboBox>();
                foreach (XmlNode xn1 in stdfieldxmlNodeLst)
                {
                    // 将节点转换为元素,便于得到节点的属性值
                    XmlElement xe = (XmlElement)xn1;
                    // 得到DataTypeInfo节点的所有子节点
                    XmlNodeList      xnl0     = xe.ChildNodes;
                    StdFieldComboBox listItem = new StdFieldComboBox();
                    listItem.Name        = xnl0.Item(0).InnerText;
                    listItem.ChineseName = xnl0.Item(1).InnerText;
                    listItem.DataType    = xnl0.Item(2).InnerText;
                    listItem.DictNo      = xnl0.Item(3).InnerText.ToInt32();
                    if (dictTypeInfoList != null)
                    {
                        var dictType = dictTypeInfoList.Find(new Predicate <DictInfo>(dictinfo => dictinfo.Id == xnl0.Item(3).InnerText.ToInt32()));
                        if (dictType != null)
                        {
                            listItem.DictNameLst = dictType.Remark;
                        }
                    }

                    stdFieldInfoList.Add(listItem);
                }
                #endregion

                if (FileUtil.IsExistFile(filePath + "\\TableInit.sql"))
                {
                    FileUtil.DeleteFile(filePath + "\\TableInit.sql");
                }

                FileUtil.CreateFile(filePath + "\\TableInit.sql");

                #region 处理每个Table脚本
                for (Int32 ii = 0; ii < filenames.Length; ii++)
                {
                    // 20190925 没有做好的不生成
                    if (filenames[ii].Contains("_TODO"))
                    {
                        Console.WriteLine(string.Format("{0} [{1})]无需处理.\r\n", LogLevel.LOG_LEVEL_INFO, filenames[ii]));
                        backgroundWorker1.ReportProgress((Int32)(progressBar.Position + 1) / progressBar.Properties.Maximum, string.Format("{0} [{1})]无需处理.\r\n", LogLevel.LOG_LEVEL_INFO, filenames[ii]));
                        continue;
                    }

                    XmlHelper xmltablesinfohelper = new XmlHelper(filenames[ii]);

                    XmlNodeList xmlbasicsLst = xmltablesinfohelper.Read(string.Format("datatype/basicinfo"));
                    XmlNodeList xmlbasicsOne = ((XmlElement)xmlbasicsLst[0]).ChildNodes;
                    string      functionStr  = xmlbasicsOne.Item(0).InnerText;
                    string      englishName  = xmlbasicsOne.Item(1).InnerText;
                    string      chineseName  = xmlbasicsOne.Item(2).InnerText;
                    Boolean     checkHis     = Convert.ToInt32(xmlbasicsOne.Item(3).InnerText) == 0 ? false : true;

                    XmlNodeList            xmlfieldsLst  = xmltablesinfohelper.Read(string.Format("datatype/fieldsinfo"));
                    List <TableFieldsInfo> FieldsInfoLst = new List <TableFieldsInfo>();
                    foreach (XmlNode xn1 in xmlfieldsLst)
                    {
                        TableFieldsInfo tablefieldInfo = new TableFieldsInfo();

                        // 将节点转换为元素,便于得到节点的属性值
                        XmlElement xe = (XmlElement)xn1;

                        tablefieldInfo.Gid = xe.GetAttribute("gid").ToString();

                        // 得到DataTypeInfo节点的所有子节点
                        XmlNodeList xnl0 = xe.ChildNodes;

                        for (Int32 i = 0; i < stdFieldInfoList.Count; i++)
                        {
                            if (string.Equals(stdFieldInfoList[i].Name, xnl0.Item(0).InnerText))
                            {
                                tablefieldInfo.FieldName   = stdFieldInfoList[i].Name;
                                tablefieldInfo.ChineseName = stdFieldInfoList[i].ChineseName;
                                tablefieldInfo.DataType    = stdFieldInfoList[i].DataType;
                                tablefieldInfo.FieldInfo   = stdFieldInfoList[i].DictNameLst;
                                break;
                            }
                        }

                        tablefieldInfo.IsNull  = (short)(xnl0.Item(1).InnerText == "0" ? 0 : 1);
                        tablefieldInfo.Remark  = xnl0.Item(2).InnerText;
                        tablefieldInfo.lstInfo = new Dictionary <string, DevExpress.XtraEditors.DXErrorProvider.ErrorInfo>();
                        FieldsInfoLst.Add(tablefieldInfo);
                    }

                    // 如果没有字段则写日志继续
                    if (FieldsInfoLst.Count == 0)
                    {
                        backgroundWorker1.ReportProgress((Int32)(progressBar.Position + 1) / progressBar.Properties.Maximum, string.Format("{0} 表[{1}({2})]不存在字段,请检查,处理完成.\r\n", LogLevel.LOG_LEVEL_ERR, chineseName, englishName));
                        continue;
                    }

                    XmlNodeList xmlindexLst = xmltablesinfohelper.Read(string.Format("datatype/indexsinfo"));

                    List <TableIndexsInfo> IndexsInfoLst = new List <TableIndexsInfo>();

                    foreach (XmlNode xn1 in xmlindexLst)
                    {
                        TableIndexsInfo tableindexsInfo = new TableIndexsInfo();

                        // 将节点转换为元素,便于得到节点的属性值
                        XmlElement xe = (XmlElement)xn1;
                        tableindexsInfo.Gid = xe.GetAttribute("gid").ToString();

                        // 得到DataTypeInfo节点的所有子节点
                        XmlNodeList xnl0 = xe.ChildNodes;
                        tableindexsInfo.IndexName      = xnl0.Item(0).InnerText;
                        tableindexsInfo.IndexFieldLst  = xnl0.Item(1).InnerText;
                        tableindexsInfo.ConstraintType = string.IsNullOrEmpty(xnl0.Item(2).InnerText) ? (short)-1 : Convert.ToInt16(xnl0.Item(2).InnerText);
                        tableindexsInfo.lstInfo        = new Dictionary <string, DevExpress.XtraEditors.DXErrorProvider.ErrorInfo>();
                        IndexsInfoLst.Add(tableindexsInfo);
                    }

                    FileUtil.AppendText(filePath + "\\TableInit.sql", JCodes.Framework.Common.Proj.SqlOperate.initTableInfo(dbType, tableGroup[englishName] + englishName, string.Format("{0}({1})", chineseName, functionStr), checkHis, FieldsInfoLst, IndexsInfoLst, dict), Encoding.UTF8);

                    Console.WriteLine(string.Format("{0} [{1}({2})]处理完成.\r\n", LogLevel.LOG_LEVEL_INFO, chineseName, englishName));
                    backgroundWorker1.ReportProgress((Int32)(progressBar.Position + 1) / progressBar.Properties.Maximum, string.Format("{0} [{1}({2})]处理完成.\r\n", LogLevel.LOG_LEVEL_INFO, chineseName, englishName));
                }
                #endregion
                break;

            case "TableDataSql":
                string[] filenames2 = args[1] as string[];

                //在线程中更新UI(通过ReportProgress方法)
                if (FileUtil.IsExistFile(filePath + "\\TableDataSql.sql"))
                {
                    FileUtil.DeleteFile(filePath + "\\TableDataSql.sql");
                }

                FileUtil.CreateFile(filePath + "\\TableDataSql.sql");

                #region 处理每个Table脚本
                for (Int32 ii = 0; ii < filenames2.Length; ii++)
                {
                    DataTable dt = new DataTable();
                    // 先读取表结构信息
                    XmlHelper xmltablefieldhelper = new XmlHelper(filenames2[ii].Replace("basicdata", "table"));

                    XmlNodeList xmlfieldsbasicLst = xmltablefieldhelper.Read(string.Format("datatype/basicinfo"));

                    XmlNodeList xnl0basic   = ((XmlElement)xmlfieldsbasicLst[0]).ChildNodes;
                    string      englishName = xnl0basic.Item(1).InnerText;
                    string      chineseName = xnl0basic.Item(2).InnerText;

                    XmlNodeList xmlfieldsLst = xmltablefieldhelper.Read(string.Format("datatype/fieldsinfo"));

                    foreach (XmlNode xn1 in xmlfieldsLst)
                    {
                        // 将节点转换为元素,便于得到节点的属性值
                        XmlElement xe = (XmlElement)xn1;
                        // 得到DataTypeInfo节点的所有子节点
                        XmlNodeList xnl0 = xe.ChildNodes;

                        dt.Columns.Add(xnl0.Item(0).InnerText);
                    }

                    // 读取数据信息
                    XmlHelper   xmltabledatahelper = new XmlHelper(filenames2[ii]);
                    XmlNodeList xmlNodeLst         = xmltabledatahelper.Read("datatype/dataitem");

                    foreach (XmlNode xn1 in xmlNodeLst)
                    {
                        DataRow dr = dt.NewRow();
                        // 将节点转换为元素,便于得到节点的属性值
                        XmlElement xe = (XmlElement)xn1;

                        for (int i = 0; i < dt.Columns.Count; i++)
                        {
                            if (xe.Attributes[dt.Columns[i].ColumnName.ToLower()] != null)
                            {
                                dr[dt.Columns[i].ColumnName] = xe.GetAttribute(dt.Columns[i].ColumnName.ToLower()).ToString();
                            }
                            else
                            {
                                xe.SetAttribute(dt.Columns[i].ColumnName.ToLower(), string.Empty);
                            }
                        }
                        xmltabledatahelper.Save(false);
                        dt.Rows.Add(dr);

                        // 根据属性去反查是否存在不存在则删除
                        List <String> tmp = new List <string>();
                        foreach (XmlAttribute a in xe.Attributes)
                        {
                            if (dt.Columns[a.Name] == null && !string.Equals(a.Name, "gid"))
                            {
                                tmp.Add(a.Name);
                            }
                        }
                        foreach (var s in tmp)
                        {
                            xe.RemoveAttribute(s);
                        }
                        xmltabledatahelper.Save(false);
                    }

                    FileUtil.AppendText(filePath + "\\TableDataSql.sql", JCodes.Framework.Common.Proj.SqlOperate.initTableDataInfo(dbType, tableGroup[englishName] + englishName, chineseName, dt), Encoding.Default);

                    backgroundWorker1.ReportProgress((Int32)(progressBar.Position + 1) / progressBar.Properties.Maximum, string.Format("{0} [{1}({2})]处理完成.\r\n", LogLevel.LOG_LEVEL_INFO, chineseName, englishName));
                }
                #endregion
                break;

            case "DictionarySql":
                //在线程中更新UI(通过ReportProgress方法)
                if (FileUtil.IsExistFile(filePath + "\\Dict.sql"))
                {
                    FileUtil.DeleteFile(filePath + "\\Dict.sql");
                }

                FileUtil.CreateFile(filePath + "\\Dict.sql");

                #region 处理每个Table脚本
                XmlHelper           xmldicthelper      = new XmlHelper(@"XML\dict.xml");
                XmlNodeList         xmlNodeLst2        = xmldicthelper.Read("datatype/dataitem");
                List <DictInfo>     dictTypeInfoList2  = new List <DictInfo>();
                List <DictDataInfo> dictDetailInfoList = new List <DictDataInfo>();
                foreach (XmlNode xn1 in xmlNodeLst2)
                {
                    DictInfo dictInfo = new DictInfo();
                    // 将节点转换为元素,便于得到节点的属性值
                    XmlElement xe = (XmlElement)xn1;

                    // 得到DataTypeInfo节点的所有子节点
                    XmlNodeList xnl0 = xe.ChildNodes;
                    dictInfo.Id     = Convert.ToInt32(xnl0.Item(0).InnerText);
                    dictInfo.Pid    = Convert.ToInt32(xnl0.Item(1).InnerText);
                    dictInfo.Name   = xnl0.Item(2).InnerText;
                    dictInfo.Remark = xnl0.Item(3).InnerText;

                    if (!string.IsNullOrEmpty(xnl0.Item(4).InnerXml))
                    {
                        System.Xml.XmlDocument doc = new System.Xml.XmlDocument();  //新建对象
                        doc.LoadXml("<tmp>" + xnl0.Item(4).InnerXml + "</tmp>");    //符合xml格式的字符串
                        var nodes = doc.DocumentElement.ChildNodes;
                        foreach (var node in nodes)
                        {
                            DictDataInfo dicdetailInfo = new DictDataInfo();
                            var          dNode         = ((XmlElement)node).ChildNodes;
                            dicdetailInfo.DicttypeValue = dNode.Item(0).InnerText.ToInt32();
                            dicdetailInfo.Name          = dNode.Item(1).InnerText;
                            dicdetailInfo.Seq           = dNode.Item(2).InnerText;
                            dicdetailInfo.Remark        = dNode.Item(3).InnerText;
                            dicdetailInfo.DicttypeId    = dictInfo.Id;

                            dictDetailInfoList.Add(dicdetailInfo);
                        }
                    }

                    dictTypeInfoList2.Add(dictInfo);
                }

                // T_Basic_DictType
                // T_Basic_DictData
                FileUtil.AppendText(filePath + "\\Dict.sql", JCodes.Framework.Common.Proj.SqlOperate.initDictTypeInfo(dbType, tableGroup["DictType"] + "DictType", "数据字典类型", dictTypeInfoList2), Encoding.Default);

                backgroundWorker1.ReportProgress((Int32)(progressBar.Position + 1) / progressBar.Properties.Maximum, string.Format("{0} [{1}({2})]处理完成.\r\n", LogLevel.LOG_LEVEL_INFO, "数据字典类型", "DictType"));

                FileUtil.AppendText(filePath + "\\Dict.sql", JCodes.Framework.Common.Proj.SqlOperate.initDictDataInfo(dbType, tableGroup["DictData"] + "DictData", "数据字典明细", dictDetailInfoList), Encoding.Default);

                backgroundWorker1.ReportProgress((Int32)(progressBar.Position + 1) / progressBar.Properties.Maximum, string.Format("{0} [{1}({2})]处理完成.\r\n", LogLevel.LOG_LEVEL_INFO, "数据字典明细", "DictData"));

                #endregion

                break;

            case "MenuSql":
                //在线程中更新UI(通过ReportProgress方法)
                if (FileUtil.IsExistFile(filePath + "\\Menu.sql"))
                {
                    FileUtil.DeleteFile(filePath + "\\Menu.sql");
                }

                FileUtil.CreateFile(filePath + "\\Menu.sql");

                #region 处理每个Table脚本
                XmlHelper       xmlmenuhelper = new XmlHelper(@"XML\menu.xml");
                XmlNodeList     xmlNodeLst3   = xmlmenuhelper.Read("datatype/dataitem");
                List <MenuInfo> menuInfolst   = new List <MenuInfo>();
                foreach (XmlNode xn1 in xmlNodeLst3)
                {
                    MenuInfo menuinfo = new MenuInfo();
                    // 将节点转换为元素,便于得到节点的属性值
                    XmlElement xe = (XmlElement)xn1;

                    // 得到DataTypeInfo节点的所有子节点
                    XmlNodeList xnl0 = xe.ChildNodes;
                    menuinfo.Gid            = xnl0.Item(0).InnerText;
                    menuinfo.Pgid           = xnl0.Item(1).InnerText;
                    menuinfo.Name           = xnl0.Item(2).InnerText;
                    menuinfo.Icon           = xnl0.Item(3).InnerText;
                    menuinfo.Seq            = xnl0.Item(4).InnerText;
                    menuinfo.AuthGid        = xnl0.Item(5).InnerText;
                    menuinfo.IsVisable      = Convert.ToInt16(xnl0.Item(6).InnerText);
                    menuinfo.WinformClass   = xnl0.Item(7).InnerText;
                    menuinfo.Url            = xnl0.Item(8).InnerText;
                    menuinfo.WebIcon        = xnl0.Item(9).InnerText;
                    menuinfo.SystemtypeId   = xnl0.Item(10).InnerText;
                    menuinfo.CreatorId      = Convert.ToInt32(xnl0.Item(11).InnerText);
                    menuinfo.CreatorTime    = Convert.ToDateTime(xnl0.Item(12).InnerText);
                    menuinfo.EditorId       = Convert.ToInt32(xnl0.Item(13).InnerText);
                    menuinfo.LastUpdateTime = Convert.ToDateTime(xnl0.Item(14).InnerText);
                    menuinfo.IsDelete       = Convert.ToInt16(xnl0.Item(15).InnerText);
                    menuInfolst.Add(menuinfo);
                }

                FileUtil.AppendText(filePath + "\\Menu.sql", JCodes.Framework.Common.Proj.SqlOperate.initMenuInfo(dbType, tableGroup["Menu"] + "Menu", "系统菜单", menuInfolst), Encoding.Default);

                backgroundWorker1.ReportProgress((Int32)(progressBar.Position + 1) / progressBar.Properties.Maximum, string.Format("{0} [{1}({2})]处理完成.\r\n", LogLevel.LOG_LEVEL_INFO, "系统菜单", "Menu"));
                #endregion
                break;

            case "FunctionSql":
                //在线程中更新UI(通过ReportProgress方法)
                if (FileUtil.IsExistFile(filePath + "\\Function.sql"))
                {
                    FileUtil.DeleteFile(filePath + "\\Function.sql");
                }

                FileUtil.CreateFile(filePath + "\\Function.sql");

                #region 处理每个Table脚本
                XmlHelper   xmlfunctionhelper = new XmlHelper(@"XML\function.xml");
                XmlNodeList xmlNodeLst4       = xmlfunctionhelper.Read("datatype/dataitem");
                List <JCodes.Framework.Entity.FunctionInfo> functionInfolst = new List <JCodes.Framework.Entity.FunctionInfo>();
                foreach (XmlNode xn1 in xmlNodeLst4)
                {
                    JCodes.Framework.Entity.FunctionInfo functioninfo = new JCodes.Framework.Entity.FunctionInfo();
                    // 将节点转换为元素,便于得到节点的属性值
                    XmlElement xe = (XmlElement)xn1;

                    // 得到DataTypeInfo节点的所有子节点
                    XmlNodeList xnl0 = xe.ChildNodes;
                    functioninfo.Gid          = xnl0.Item(0).InnerText;
                    functioninfo.Pgid         = xnl0.Item(1).InnerText;
                    functioninfo.Name         = xnl0.Item(2).InnerText;
                    functioninfo.DllPath      = xnl0.Item(3).InnerText;
                    functioninfo.SystemtypeId = xnl0.Item(4).InnerText;
                    functioninfo.Seq          = xnl0.Item(5).InnerText;
                    functionInfolst.Add(functioninfo);
                }

                FileUtil.AppendText(filePath + "\\Function.sql", JCodes.Framework.Common.Proj.SqlOperate.initFunctionInfo(dbType, tableGroup["Function"] + "Function", "系统功能", functionInfolst), Encoding.Default);

                #endregion
                break;
            }
            //...执行线程其他任务

            backgroundWorker1.ReportProgress(100, string.Format("{0} 已全部生成完毕.\r\n", LogLevel.LOG_LEVEL_INFO));
        }
예제 #12
0
        /// <summary>
        /// 根据配置导出SQL
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGenerateSQL_Click(object sender, EventArgs e)
        {
            if (projectInfo != null)
            {
                if (string.IsNullOrEmpty(projectInfo.OutputPath))
                {
                    MessageDxUtil.ShowError("请在项目菜单中配置导出脚本路径");
                    return;
                }

                if (!DirectoryUtil.IsExistDirectory(projectInfo.OutputPath))
                {
                    MessageDxUtil.ShowError(string.Format("配置的路径{0}在系统中不存在,请在项目菜单中配置导出脚本路径", projectInfo.OutputPath));
                    return;
                }

                // 操控进度条
                //var progressBar = (this.MdiParent as MainForm).progressBar;
                //progressBar.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;

                if (FileUtil.IsExistFile(projectInfo.OutputPath + "\\Dict.sql"))
                {
                    FileUtil.DeleteFile(projectInfo.OutputPath + "\\Dict.sql");
                }

                FileUtil.CreateFile(projectInfo.OutputPath + "\\Dict.sql");

                #region 处理每个Table脚本
                XmlHelper           xmldicthelper      = new XmlHelper(@"XML\dict.xml");
                XmlNodeList         xmlNodeLst2        = xmldicthelper.Read("datatype/dataitem");
                List <DictInfo>     dictTypeInfoList2  = new List <DictInfo>();
                List <DictDataInfo> dictDetailInfoList = new List <DictDataInfo>();
                foreach (XmlNode xn1 in xmlNodeLst2)
                {
                    DictInfo dictInfo = new DictInfo();
                    // 将节点转换为元素,便于得到节点的属性值
                    XmlElement xe = (XmlElement)xn1;

                    // 得到DataTypeInfo节点的所有子节点
                    XmlNodeList xnl0 = xe.ChildNodes;
                    dictInfo.Id     = Convert.ToInt32(xnl0.Item(0).InnerText);
                    dictInfo.Pid    = Convert.ToInt32(xnl0.Item(1).InnerText);
                    dictInfo.Name   = xnl0.Item(2).InnerText;
                    dictInfo.Remark = xnl0.Item(3).InnerText;

                    if (!string.IsNullOrEmpty(xnl0.Item(4).InnerXml))
                    {
                        System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); //新建对象
                        doc.LoadXml("<tmp>" + xnl0.Item(4).InnerXml + "</tmp>");   //符合xml格式的字符串
                        var nodes = doc.DocumentElement.ChildNodes;
                        foreach (var node in nodes)
                        {
                            DictDataInfo dicdetailInfo = new DictDataInfo();
                            var          dNode         = ((XmlElement)node).ChildNodes;
                            dicdetailInfo.DicttypeValue = dNode.Item(0).InnerText.ToInt32();
                            dicdetailInfo.Name          = dNode.Item(1).InnerText;
                            dicdetailInfo.Seq           = dNode.Item(2).InnerText;
                            dicdetailInfo.Remark        = dNode.Item(3).InnerText;
                            dicdetailInfo.DicttypeId    = dictInfo.Id;

                            dictDetailInfoList.Add(dicdetailInfo);
                        }
                    }

                    dictTypeInfoList2.Add(dictInfo);
                }

                // T_Basic_DictType
                // T_Basic_DictData
                FileUtil.AppendText(projectInfo.OutputPath + "\\Dict.sql", JCodes.Framework.Common.Proj.SqlOperate.initDictTypeInfo(projectInfo.DbType, tableGroup["DictType"] + "DictType", "数据字典类型", dictTypeInfoList2), Encoding.Default);

                //progressBar.EditValue = 50;

                FileUtil.AppendText(projectInfo.OutputPath + "\\Dict.sql", JCodes.Framework.Common.Proj.SqlOperate.initDictDataInfo(projectInfo.DbType, tableGroup["DictData"] + "DictData", "数据字典明细", dictDetailInfoList), Encoding.Default);

                //progressBar.EditValue = 100;
                #endregion

                MessageDxUtil.ShowTips("生成脚本成功");
                //progressBar.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
            }
        }
예제 #13
0
        private void simpleButton4_Click(object sender, EventArgs e)
        {
            string path = FileDialogHelper.OpenDir();

            string recordFileName = "\\" + "缺少文件.txt";

            if (FileUtil.FileIsExist(path + recordFileName))
            {
                FileUtil.DeleteFile(path + recordFileName);
            }
            FileUtil.CreateFile(path + recordFileName);


            if (!string.IsNullOrEmpty(path))
            {
                string[] dirs = DirectoryUtil.GetDirectories(path);

                Dictionary <string, bool> a = new Dictionary <string, bool>();
                // 判断是否是子目录
                foreach (var d in dirs)
                {
                    string[] subdirs = DirectoryUtil.GetDirectories(d, "*", true);

                    string[] tmpdsname = d.Split('\\');
                    string   dsname    = tmpdsname[tmpdsname.Length - 1].Split('$')[0];

                    foreach (var dir in subdirs)
                    {
                        string[] tmpdirsname = dir.Split('\\');
                        string   dirname     = tmpdirsname[tmpdirsname.Length - 1].Split('$')[0];

                        a[dsname + dirname] = false;

                        if (dirname.Substring(0, 1) == "第" && dirname.Substring(dirname.Length - 1, 1) == "章")
                        {
                            continue;
                        }

                        Int32 readCount = 0;
                        foreach (var dir2 in subdirs)
                        {
                            string[] tmpdir2sname = dir2.Split('\\');
                            string   dir2name     = tmpdir2sname[tmpdir2sname.Length - 1].Split('$')[0];

                            if (dir2name != dirname && dirname.Contains(dir2name) && dirname.IndexOf(dir2name) == 0)
                            {
                                a[dsname + dirname] = true;
                                break;
                            }

                            if (dir2name != dirname && dir2name.Contains(dirname) && dir2name.IndexOf(dirname) == 0)
                            {
                                a[dsname + dirname] = false;
                                break;
                            }

                            // 已经遍历玩了,则还没有找到就是没有子目录
                            readCount++;
                            if (subdirs.Length == readCount)
                            {
                                a[dsname + dirname] = true;
                                break;
                            }
                        }
                    }
                }

                foreach (var d in dirs)
                {
                    string[] subdirs = DirectoryUtil.GetDirectories(d, "*", true);

                    string[] tmpdsname = d.Split('\\');
                    string   dsname    = tmpdsname[tmpdsname.Length - 1].Split('$')[0];

                    foreach (var dir in subdirs)
                    {
                        string[] tmpdirsname = dir.Split('\\');
                        string   dirname     = tmpdirsname[tmpdirsname.Length - 1].Split('$')[0];

                        if (dirname.Substring(0, 1) == "第" && dirname.Substring(dirname.Length - 1, 1) == "章")
                        {
                            continue;
                        }
                        // 是子目录
                        if (a[dsname + dirname])
                        {
                            if (dir.Length > 250)
                            {
                                MessageDxUtil.ShowTips("目录超过限制长度[" + dir + "]");
                                continue;
                            }

                            if (DirectoryUtil.IsEmptyDirectory(dir))
                            {
                                FileUtil.AppendText(path + recordFileName, string.Format("{0}\r\n", dir), Encoding.UTF8);
                            }
                        }
                    }
                }

                MessageDxUtil.ShowTips("操作完成");
            }
        }