コード例 #1
0
ファイル: SQLCodeManager.cs プロジェクト: 396000787/csaa
        /// <summary>
        /// 添加SQLXML文件
        /// </summary>
        /// <param name="parameters">页面传递的参数</param>
        /// <returns>true:成功,false:失败</returns>
        public object AddSql(Dictionary <String, String> parameters)
        {
            try
            {
                ////XML存储路径
                //string _XmlOutPath = Path.Combine(WorkDir, SQLPath);
                //if (!Directory.Exists(_XmlOutPath))//如果路径不存在
                //{
                //    //创建路径
                //    Directory.CreateDirectory(_XmlOutPath);
                //}

                //检查SQLXML路径是否存在
                CheckPath();
                JsonOperate _JsonOperate = new JsonOperate();
                //获取SQL序号
                string _SqlNum = parameters.ContainsKey("SqlNum") ? _JsonOperate.FromJsonString <string>(parameters["SqlNum"]) : "";
                //获取SQL说明
                string _SqlDescription = parameters.ContainsKey("SqlDescription") ? _JsonOperate.FromJsonString <string>(parameters["SqlDescription"]) : "";
                //获取SQL语句
                string _SQLString = parameters.ContainsKey("SQLString") ? _JsonOperate.FromJsonString <string>(parameters["SQLString"]) : "";

                //SQL语句所在xml文件路径
                string xmlPath = Path.Combine(SQLPath, _SqlNum + ".xml");
                if (File.Exists(xmlPath))//如果存在文件,返回false
                {
                    return(new { Methods = false });
                }
                if (string.IsNullOrEmpty(_SqlNum) || string.IsNullOrEmpty(_SqlDescription) || string.IsNullOrEmpty(_SQLString))
                {
                    return(new { Methods = false });
                }
                //实例化XML文件操作类
                XmlOperate _XmlOperate = new XmlOperate();
                //实例化SQL实体类
                SQLCodeEntity _SQLCodeEntity = new SQLCodeEntity();
                _SQLCodeEntity.SqlNum         = _SqlNum;
                _SQLCodeEntity.SqlDescription = _SqlDescription;
                _SQLCodeEntity.SQLString      = _SQLString;

                //转换成xml字符串
                string _XmlString = _XmlOperate.ObjectToSimpleXml(_SQLCodeEntity);
                //生成SQLXML文件
                File.WriteAllText(xmlPath, _XmlString);
                return(new { Methods = true });
            }
            catch
            {
                return(new { Methods = false });
            }
        }
コード例 #2
0
ファイル: SQLCodeManager.cs プロジェクト: 396000787/csaa
        /// <summary>
        /// 根据SQL序号删除SQLXML文件
        /// </summary>
        /// <param name="parameters">页面传递的参数</param>
        /// <returns>true:成功,false:失败</returns>
        public object DeleteSql(Dictionary <String, String> parameters)
        {
            try
            {
                JsonOperate _JsonOperate = new JsonOperate();
                //获取SQL序号
                string _SqlNum = parameters.ContainsKey("SqlNum") ? _JsonOperate.FromJsonString <string>(parameters["SqlNum"]) : "";

                //SQL语句所在xml文件路径
                string xmlPath = Path.Combine(SQLPath, _SqlNum + ".xml");
                //判断是否存在文件
                if (!File.Exists(xmlPath))
                {
                    return(new { Methods = false });
                }
                //判断配置文件是否只读
                FileInfo fi = new FileInfo(xmlPath);
                //如果只读则修改为普通
                //if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
                //{
                fi.Attributes = FileAttributes.Normal;
                //}

                //删除SQLXML文件
                File.Delete(xmlPath);

                return(new { Methods = true });
            }
            catch
            {
                return(new { Methods = false });
            }
        }
コード例 #3
0
ファイル: SQLCodeManager.cs プロジェクト: 396000787/csaa
        /// <summary>
        /// 根据SQL序号获得SQL信息
        /// </summary>
        /// <param name="parameters">页面传递的参数</param>
        /// <returns>SQL信息</returns>
        public object GetSqlByNum(Dictionary <String, String> parameters)
        {
            try
            {
                JsonOperate _JsonOperate = new JsonOperate();
                //获取SQL序号
                string _SqlNum = parameters.ContainsKey("SqlNum") ? _JsonOperate.FromJsonString <string>(parameters["SqlNum"]) : "";

                //SQLCodeEntity _SQLCodeEntity;
                if (_SQLCodeEntityList != null && SQLCodeManager._SQLCodeEntityList.FirstOrDefault(S => S.SqlNum == _SqlNum) != null)
                {
                    //从缓存中获得SQL实体
                    SQLCodeEntity _SQLCodeEntity = SQLCodeManager._SQLCodeEntityList.FirstOrDefault(S => S.SqlNum == _SqlNum);

                    return(new { Methods = _SQLCodeEntity });
                }
                else
                {
                    //SQL语句所在xml文件路径
                    string xmlPath = Path.Combine(SQLPath, _SqlNum + ".xml");
                    //判断是否存在文件
                    if (!File.Exists(xmlPath))
                    {
                        return(new { Methods = "" });
                    }
                    //实例化XML文件操作类
                    //XmlOperate _XmlOperate = new XmlOperate();
                    //判断配置文件是否只读
                    //FileInfo fi = new FileInfo(xmlPath);
                    ////如果只读则修改为普通
                    //if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
                    //{
                    //    fi.Attributes = FileAttributes.Normal;
                    //}
                    ////实例化文件操作类
                    //DirectoryFileOperate _DirectoryFileOperate = new DirectoryFileOperate();
                    ////根据指定路径读取文件
                    //string _XmlContent = _DirectoryFileOperate.ShareReadFile(xmlPath);
                    ////把xml转换成对象
                    //SQLCodeEntity _SQLCodeEntity = _XmlOperate.SimpleXmlToObject<SQLCodeEntity>(_XmlContent);
                    SQLCodeEntity _SQLCodeEntity = SQLCodeHelp.GetSQLCodeEntityByPath(xmlPath);

                    return(new { Methods = _SQLCodeEntity });
                }
            }
            catch
            {
                return(new { Methods = "" });
            }
        }
コード例 #4
0
ファイル: SQLCodeManager.cs プロジェクト: 396000787/csaa
        /// <summary>
        /// 根据SQL序号修改SQL文件
        /// </summary>
        /// <param name="parameters">页面传递的参数</param>
        /// <returns>true:成功,false:失败</returns>
        public object EditSql(Dictionary <String, String> parameters)
        {
            try
            {
                JsonOperate _JsonOperate = new JsonOperate();
                //获取SQL序号
                string _SqlNum = parameters.ContainsKey("SqlNum") ? _JsonOperate.FromJsonString <string>(parameters["SqlNum"]) : "";
                //获取SQL说明
                string _SqlDescription = parameters.ContainsKey("SqlDescription") ? _JsonOperate.FromJsonString <string>(parameters["SqlDescription"]) : "";
                //获取SQL语句
                string _SQLString = parameters.ContainsKey("SQLString") ? _JsonOperate.FromJsonString <string>(parameters["SQLString"]) : "";

                //SQL语句所在xml文件路径
                string xmlPath = Path.Combine(SQLPath, _SqlNum + ".xml");
                if (!File.Exists(xmlPath))
                {
                    return(new { Methods = false });
                }
                //实例化XML文件操作类
                XmlOperate _XmlOperate = new XmlOperate();
                //实例化SQL实体类
                SQLCodeEntity _SQLCodeEntity = new SQLCodeEntity();
                _SQLCodeEntity.SqlNum         = _SqlNum;
                _SQLCodeEntity.SqlDescription = _SqlDescription;
                _SQLCodeEntity.SQLString      = _SQLString;

                //转换成xml字符串
                string _Xmlstring = _XmlOperate.ObjectToSimpleXml(_SQLCodeEntity);
                bool   _IsSuccess = SaveXml(_Xmlstring, xmlPath);
                return(new { Methods = _IsSuccess });
            }
            catch
            {
                return(new { Methods = false });
            }
        }
コード例 #5
0
ファイル: SQLCodeManager.cs プロジェクト: 396000787/csaa
        /// <summary>
        /// 根据SQL序号、SQL说明和SQL语句获得SQL语句列表
        /// </summary>
        /// <param name="parameters">页面传递的参数</param>
        /// <returns>SQL对象列表</returns>
        public object GetSqlList(Dictionary <String, String> parameters)
        {
            try
            {
                //检查SQLXML路径是否存在
                CheckPath();
                //SQL语句所在xml文件路径
                string xmlPath = SQLPath;
                //if (!Directory.Exists(xmlPath))//如果路径不存在
                //{
                //    return null;
                //}

                if (_SQLCodeEntityList == null || _SQLCodeEntityList.Count == 0)
                {
                    //将指定路径下所有SQLXML转换成SQLCodeEntity对象列表
                    _SQLCodeEntityList = ConvertXmlToEntity(xmlPath);
                }
                List <SQLCodeEntity> _TempSQLCodeEntityList = _SQLCodeEntityList.ToList();
                //将指定路径下所有SQLXML转换成SQLCodeEntity对象列表
                //List<SQLCodeEntity> _SQLCodeEntityList = ConvertXmlToEntity(xmlPath);

                JsonOperate _JsonOperate = new JsonOperate();
                //获取SQL序号
                string _SqlNum = parameters.ContainsKey("SqlNum") ? _JsonOperate.FromJsonString <string>(parameters["SqlNum"]) : "";
                //获取SQL说明
                string _SqlDescription = parameters.ContainsKey("SqlDescription") ? _JsonOperate.FromJsonString <string>(parameters["SqlDescription"]) : "";
                //获取SQL语句
                string _SQLString = parameters.ContainsKey("SQLString") ? _JsonOperate.FromJsonString <string>(parameters["SQLString"]) : "";
                //获取每页显示条数
                int _pageSize = parameters.ContainsKey("pageSize") ? Convert.ToInt32(parameters["pageSize"]) : 0;
                //获取当前页码
                int _pageIndex = parameters.ContainsKey("pageIndex") ? Convert.ToInt32(parameters["pageIndex"]) - 1 : 0;

                //判断是否根据SQL序号查询
                if (!string.IsNullOrEmpty(_SqlNum))
                {
                    _TempSQLCodeEntityList = _TempSQLCodeEntityList.Where(S => S.SqlNum.Contains(_SqlNum)).ToList();
                }
                //判断是否根据SQL说明查询
                if (!string.IsNullOrEmpty(_SqlDescription))
                {
                    _TempSQLCodeEntityList = _TempSQLCodeEntityList.Where(S => S.SqlDescription.ToLower().Contains(_SqlDescription.ToLower())).ToList();
                }
                //判断是否根据SQL语句查询
                if (!string.IsNullOrEmpty(_SQLString))
                {
                    _TempSQLCodeEntityList = _TempSQLCodeEntityList.Where(S => S.SQLString.ToLower().Contains(_SQLString.ToLower())).ToList();
                }
                //按序号排序
                var _SQLList = from S in _TempSQLCodeEntityList
                               orderby S.SqlNum
                               select
                               new
                {
                    SqlNum         = S.SqlNum,
                    SqlDescription = S.SqlDescription
                };

                IEnumerable <object> result = _SQLList;
                //定义总页数
                int _pageCount;
                //分页
                result = result.TakePage(_pageSize, _pageIndex, out _pageCount);

                return(new { PageSize = _pageSize, PageIndex = _pageIndex + 1, PageCount = _pageCount, Methods = result });
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
コード例 #6
0
ファイル: iCommandEntity.cs プロジェクト: 396000787/csaa
        /// <summary>
        /// 获取返回结果的反序列化结果
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public T GetResponseData <T>()
        {
            JsonOperate _JsonOperate = new JsonOperate();

            return(_JsonOperate.FromJsonString <T>(responseData));
        }