Esempio n. 1
0
 /// <summary>
 /// 根据功能标识返回该功能标识下的所有DataTable的DefineField信息
 /// 第一层List的顺序是功能下的DataTable顺序,第二层是某个DataTable下的各个DefineField信息
 /// </summary>
 /// <param name="progId">功能标识</param>
 /// <param name="errorMsg">错误信息。如果成功则为string.Empty</param>
 /// <returns></returns>
 public static List <List <DefineField> > GetBcfDefineFields(string progId, out string errorMsg)
 {
     errorMsg = string.Empty;
     try
     {
         List <List <DefineField> > listResult = null;
         if (ProgIdHost.Instance.ProgIdRef.ContainsKey(progId))
         {
             BcfServerInfo info     = ProgIdHost.Instance.ProgIdRef[progId];
             string        path     = Path.Combine(EnvProvider.Default.MainPath, "Bcf", info.DllName);
             Assembly      assembly = Assembly.LoadFrom(path);
             Type          t        = assembly.GetType(info.ClassName);
             LibBcfBase    destObj  = (LibBcfBase)t.InvokeMember(null, BindingFlags.CreateInstance, null, null, null);
             if (destObj == null)
             {
                 errorMsg = string.Format("异常信息:未能构造Bcf实例对象。");
                 return(null);
             }
             if (destObj.DataSet == null || destObj.DataSet.Tables == null || destObj.DataSet.Tables.Count == 0 ||
                 destObj.DataSet.Tables[0].Columns == null || destObj.DataSet.Tables[0].Columns.Count == 0)
             {
                 errorMsg = string.Format("异常信息:Bcf实例对象DataSet的Column列为空。");
                 return(null);
             }
             listResult = new List <List <DefineField> >();
             foreach (DataTable table in destObj.DataSet.Tables)
             {
                 listResult.Add(new List <DefineField>());
                 foreach (DataColumn column in table.Columns)
                 {
                     listResult.Last().Add(DataSourceHelper.ConvertToDefineField(column));
                 }
             }
         }
         else
         {
             errorMsg = string.Format("异常信息:不可识别的功能标识号:{0}", progId);
             return(null);
         }
         return(listResult);
     }
     catch (Exception exp)
     {
         string message = exp.InnerException == null ? exp.Message : exp.InnerException.Message;
         errorMsg = string.Format("异常信息:{0}{1}异常堆栈:{2}", message, Environment.NewLine, exp.StackTrace);
         return(null);
     }
 }
Esempio n. 2
0
 protected override void CheckFieldReturn(int tableIndex, string fieldName, object[] curPk, Dictionary <string, object> fieldKeyAndValue, Dictionary <string, object> returnValue)
 {
     base.CheckFieldReturn(tableIndex, fieldName, curPk, fieldKeyAndValue, returnValue);
     if (tableIndex == 1 && fieldName == "PROGID" && curPk != null && curPk.Length == 1)
     {
         LibBcfBase bcfBase = LibBcfSystem.Default.GetBcfInstance(LibSysUtils.ToString(curPk[0]));
         if (bcfBase != null)
         {
             bcfBase.Template.GetViewTemplate(bcfBase.DataSet);
             returnValue.Add("OperatePowerData", BuildPowerInfo(bcfBase.Template.FuncPermission.Permission));
             string sql = string.Format("select distinct BUTTONID,BUTTONNAME from AXPFUNCBUTTON where PROGID={0}", LibStringBuilder.GetQuotObject(curPk[0]));
             Dictionary <string, string> dic = new Dictionary <string, string>();
             using (IDataReader reader = this.DataAccess.ExecuteDataReader(sql, false))
             {
                 while (reader.Read())
                 {
                     dic.Add(LibSysUtils.ToString(reader["BUTTONID"]), LibSysUtils.ToString(reader["BUTTONNAME"]));
                 }
             }
             returnValue.Add("ButtonPowerData", dic);
         }
     }
 }
Esempio n. 3
0
        public DataSet GetRpt_Ws(ExecuteWsMethodParam_Ws param)
        {
            if (string.IsNullOrEmpty(param.ProgId))
            {
                throw new ArgumentNullException("ProgId", "ProgId is empty.");
            }
            DataSet ds = null;

            if (ProgIdHost.Instance.ProgIdRef.ContainsKey(param.ProgId))
            {
                BcfServerInfo info     = ProgIdHost.Instance.ProgIdRef[param.ProgId];
                string        path     = Path.Combine(EnvProvider.Default.MainPath, "Bcf", info.DllName);
                Assembly      assembly = Assembly.LoadFrom(path);
                Type          t        = assembly.GetType(info.ClassName);
                LibBcfBase    destObj  = t.InvokeMember(null, BindingFlags.CreateInstance, null, null, null) as LibBcfBase;
                if (destObj != null)
                {
                    destObj.Handle = LibHandleCache.Default.GetSystemHandle();
                    ds             = t.InvokeMember(param.MethodName, BindingFlags.InvokeMethod, null, destObj, param.MethodParam) as DataSet;
                }
            }
            return(ds);
        }
Esempio n. 4
0
        public void SystemUpgrade1()
        {
            LibSqlModelCache.Default.RemoveAll();//升级数据库时需要将SqlModel的缓存清空

            //重新生成ProgId

            #region 1.	从实体文件夹中获取dll文件,转到程序集,构建实体列表
            Dictionary <string, Assembly> assemblyDic = new Dictionary <string, Assembly>();
            ProgIdConfigListingManager.BuildListing(EnvProvider.Default.MainPath, EnvProvider.Default.ExtendPath, assemblyDic);
            #endregion

            //在本地构建SqlModel文件,升级数据库表、创建单据存储过程
            ProgIdHost.Instance.Run();
            List <string> updateBusinessTaskList = new List <string>()
            {
                "DELETE FROM AXPBUSINESSTASK"
            };
            foreach (var item in ProgIdHost.Instance.ProgIdRef)
            {
                BcfServerInfo info = item.Value;
                if (!assemblyDic.ContainsKey(info.DllName))
                {
                    continue;
                }
                Assembly assembly = assemblyDic[info.DllName];
                Type     destType = assembly.GetType(info.ClassName);
                if (destType == null)
                {
                    continue;
                }
                try
                {
                    LibBcfBase destObj = destType.InvokeMember(null, BindingFlags.CreateInstance, null, null, null) as LibBcfBase;
                    if (destObj != null)
                    {
                        SaveSqlModel(item.Key, destObj.DataSet);
                    }
                }
                catch (Exception exp)
                {
                    throw new Exception(string.Format("UpdateError(SaveSqlModel):\r\n{0}  {1}  {2}  {3}。", item.Key, item.Value.ClassName, item.Value.DllName, exp.ToString()));
                }
            }
            ILibDbSchema    schemaHelper = null;
            LibDataAccess   dataAccess   = new LibDataAccess();
            LibDatabaseType databaseType = dataAccess.DatabaseType;
            if (LibDatabaseType.Oracle == databaseType)
            {
                schemaHelper = new LibOracleDbSchema();
            }
            else
            {
                schemaHelper = new LibSqlServerDbSchema();
            }
            List <string> updateFunList = new List <string>()
            {
                "DELETE FROM AXPFUNCLIST"
            };
            List <string> updateFunButtonList = new List <string>()
            {
                "DELETE FROM AXPFUNCBUTTON"
            };
            List <string> updateBrowseStoreProcedureList = new List <string>();
            foreach (var item in ProgIdHost.Instance.ProgIdRef)
            {
                BcfServerInfo info = item.Value;
                if (!assemblyDic.ContainsKey(info.DllName))
                {
                    continue;
                }
                Assembly assembly = assemblyDic[info.DllName];
                try
                {
                    Type       destType = assembly.GetType(info.ClassName);
                    LibBcfBase destObj  = destType.InvokeMember(null, BindingFlags.CreateInstance, null, null, null) as LibBcfBase;
                    if (destObj != null)
                    {
                        LibFuncPermission funcPermission = destObj.Template.FuncPermission;
                        updateFunList.Add(GetSqlForFunList(destObj.ProgId, destObj.Template.DisplayText, funcPermission.ConfigPack, funcPermission.CanMenu, funcPermission.KeyCode, funcPermission.Permission, destObj.Template.BillType, LibSysUtils.ToString(funcPermission.ProgTag)));
                        //Dictionary<string, string> dic = destObj.Template.GetViewTemplate(destObj.DataSet).Layout.GetButtonList();
                        //if (dic != null)
                        //{
                        //    foreach (var button in dic)
                        //    {
                        //        updateFunButtonList.Add(string.Format("insert into AXPFUNCBUTTON(PROGID,BUTTONID,BUTTONNAME) values('{0}','{1}','{2}')", destObj.ProgId, button.Key, button.Value));
                        //    }
                        //}

                        if (!destType.IsSubclassOf(typeof(LibBcfData)) && !destType.IsSubclassOf(typeof(LibBcfGrid)))
                        {
                            continue;
                        }
                        schemaHelper.DicUniqueDataSql = destObj.GetUniqueDataSqlForUpdate(dataAccess.DatabaseType);//添加对于唯一性字段数据的提前处理Sql
                        schemaHelper.UpdateTables(destObj.DataSet, false);
                        //schemaHelper.CreateTables(destObj.DataSet);
                        SqlBuilder sqlBuilder = new SqlBuilder(item.Key);
                        string     sql;
                        if (LibDatabaseType.Oracle == databaseType)
                        {
                            sql = sqlBuilder.BuildBrowseStoreProcedureByOracle(destObj.Template.BillType);
                        }
                        else
                        {
                            sql = sqlBuilder.BuildBrowseStoreProcedure(destObj.Template.BillType);
                        }
                        if (!string.IsNullOrEmpty(sql))
                        {
                            string name = destObj.Template.ProgId.Replace('.', '_');
                            if (LibDatabaseType.SqlServer == databaseType)
                            {
                                updateBrowseStoreProcedureList.Add(string.Format("IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID({0}) AND type in (N'P', N'PC')) DROP PROCEDURE {1}", LibStringBuilder.GetQuotString(name), name));
                            }
                            updateBrowseStoreProcedureList.Add(sql);
                        }
                    }
                }
                catch (Exception exp)
                {
                    throw new Exception(string.Format("UpdateError(UpdateTable):\r\n{0}  {1}  {2}  {3}\r\n。", item.Key, item.Value.ClassName, item.Value.DllName, exp.ToString()));
                }
            }

            //创建浏览存储过程
            foreach (string sql in updateBrowseStoreProcedureList)
            {
                try
                {
                    dataAccess.ExecuteNonQuery(sql, false);
                }
                catch (Exception exp)
                {
                    throw new Exception(string.Format("UpdateError(updateBrowseStoreProcedureList):\r\n{0} \r\n{1}。", sql, exp.ToString()));
                }
            }

            //更新功能清单
            dataAccess.ExecuteNonQuery(updateFunList, false);
            //dataAccess.ExecuteNonQuery(updateFunButtonList, false);
            //更新业务任务表
            //dataAccess.ExecuteNonQuery(updateBusinessTaskList, false);
            //创建存储过程
            //CreateStoredProcedure(Path.Combine(EnvProvider.Default.MainPath, "StoredProcedure"), dataAccess);
            //CreateStoredProcedure(Path.Combine(EnvProvider.Default.ExtendPath, "StoredProcedure"), dataAccess);
            //this.InitData();
        }
Esempio n. 5
0
        private void ExecBusinessTask(object obj)
        {
            LibTaskParam    param      = (LibTaskParam)obj;
            LibBusinessTask taskDefine = param.TaskDefine;

            //系统当天是否可以执行
            if (IsExecOfDay(taskDefine))
            {
                try
                {
                    param.Task.TaskState = TaskRunState.Running;
                    LibBcfBase bcf = LibBcfSystem.Default.GetBcfInstance(taskDefine.ProgId);
                    bcf.Handle = LibHandleCache.Default.GetSystemHandle();
                    Type     type      = bcf.GetType();
                    object[] destParam = RestoreParamFormat(type, taskDefine.BusinessTaskId, new string[] { taskDefine.ExecCondition });
                    object   result    = bcf.GetType().InvokeMember(taskDefine.BusinessTaskId, BindingFlags.InvokeMethod, null, bcf, destParam);
                    switch (bcf.Template.BillType)
                    {
                    case AxCRL.Template.BillType.Master:
                    case AxCRL.Template.BillType.Bill:
                        break;

                    case AxCRL.Template.BillType.Grid:
                        break;

                    case AxCRL.Template.BillType.DataFunc:
                        break;

                    case AxCRL.Template.BillType.Rpt:
                    case AxCRL.Template.BillType.DailyRpt:
                        DataSet dataSet = result as DataSet;
                        if (dataSet != null)
                        {
                            LibSysNews news = new LibSysNews();
                            news.Content  = taskDefine.MainContent;
                            news.Data     = LibBillDataSerializeHelper.Serialize(dataSet);
                            news.PersonId = "SYSTEM";
                            news.ProgId   = taskDefine.ProgId;
                            news.Title    = taskDefine.Title;
                            foreach (LibBusinessTaskLiaison item in taskDefine.Liaison)
                            {
                                news.UserList.Add(item.UserId);
                            }
                            LibSysNewsHelper.SendNews(news, false);
                        }
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    //将错误输出
                    string path = System.IO.Path.Combine(AxCRL.Comm.Runtime.EnvProvider.Default.MainPath, "Output", "Error", "ScheduleTask", string.Format("{0}.txt", DateTime.Now.Ticks));
                    OutputInfo(path, ex.ToString());
                }
                finally
                {
                    param.Task.TaskState = TaskRunState.Wait;
                }
            }
            bool canNextExec = true;

            if (taskDefine.ExecDate != 0)
            {
                int curDate = LibDateUtils.GetCurrentDate();
                if (taskDefine.ExecDate > curDate)
                {
                    param.Task.Timer.Dispose();
                    canNextExec          = false;
                    param.Task.TaskState = TaskRunState.Stop;
                }
                else if (taskDefine.ExecDate == curDate && taskDefine.ExecTime.Count > 0)
                {
                    int curTime = LibDateUtils.GetLibTimePart(LibDateUtils.GetCurrentDateTime(), LibDateTimePartEnum.Time);
                    if (taskDefine.ExecTime[taskDefine.ExecTime.Count - 1] < curTime)
                    {
                        param.Task.Timer.Dispose();
                        canNextExec          = false;
                        param.Task.TaskState = TaskRunState.Stop;
                    }
                }
            }
            if (canNextExec)
            {
                param.Task.Timer.Change(param.GetTaskDueTime(), Timeout.InfiniteTimeSpan);
            }
            else if (taskDefine.TaskType == LibTaskType.TempTask)
            {
                //删除临时任务
                LibDataAccess dataAccess = new LibDataAccess();
                dataAccess.ExecuteNonQuery(string.Format("delete AXPBUSINESSTEMPTASK where TASKID={0}", LibStringBuilder.GetQuotString(taskDefine.TaskId)), false);
            }
        }