Beispiel #1
0
        public bool MarkDelete(string id)
        {
            var batchStates = new DBState[]
            {
                new DBState()
                {
                    Name  = "DeleteTargetByMark",
                    Param = new { MarkTabID = id },
                    Type  = ESqlType.DELETE
                },
                new DBState()
                {
                    Name  = "DeleteReferByMark",
                    Param = new { MarkTabID = id },
                    Type  = ESqlType.DELETE
                },
                new DBState()
                {
                    Name  = new NursingMark().MAP_DELETE,
                    Param = new { ID = id },
                    Type  = ESqlType.DELETE
                }
            };

            return(DB.ExecuteWithTransaction(batchStates) > 0);
        }
Beispiel #2
0
 public int InsertOrUpdate(IDictionary <string, object> dict)
 {
     //insert
     if (!dict.ContainsKey("ID") || string.IsNullOrEmpty(dict["ID"].ToString()))
     {
         dict["ID"] = Utils.getGUID();
         DBState state = null;
         state = new DBState
         {
             Name  = "INSERT_TreeDefinition",
             Param = dict,
             Type  = ESqlType.INSERT
         };
         return(DB.Execute(state));
     }
     //update
     else
     {
         DBState state = null;
         dict["Invalidtime"] = DateTime.Now;
         state = new DBState
         {
             Name  = "UPDATE_TreeDefinition",
             Param = dict,
             Type  = ESqlType.UPDATE
         };
         return(DB.Execute(state));
     }
 }
Beispiel #3
0
        /// <summary>
        /// Загрузить БД
        /// </summary>
        /// <param name="dbName">Имя загружаемой БД</param>
        public void LoadDB(string dbName)
        {
            if (slim.TryEnterWriteLock(500))
            {
                string old_name_db = string.Empty;

                try
                {
                    if (IsSrvValid)
                    {
                        old_name_db = adapter.InitialCatalog;
                        if (state == DBState.Default)
                        {
                            adapter.InitialCatalog          = dbName;
                            provider.Adapter.InitialCatalog = dbName;

                            DataBase.LoadDB(provider);
                            state = DBState.Loaded;
                        }
                    }
                }
                catch (Exception ex)
                {
                    adapter.InitialCatalog          = old_name_db;
                    provider.Adapter.InitialCatalog = old_name_db;

                    throw new Exception(ex.Message, ex);
                }
                finally
                {
                    slim.ExitWriteLock();
                }
            }
        }
Beispiel #4
0
        public virtual int InsertOrUpdateBatchs <T>(IList <T> list) where T : BaseModel, new()
        {
            IList <DBState> states = new List <DBState>();
            T t = System.Activator.CreateInstance <T>();

            foreach (var item in list)
            {
                DBState state = null;
                if (string.IsNullOrEmpty(t.ID))
                {
                    if (string.IsNullOrEmpty(t.ID))
                    {
                        t.ID = Utils.getGUID();
                    }
                    state = new DBState
                    {
                        Name  = t.MAP_INSERT,
                        Param = item.ToDict(),
                        Type  = ESqlType.INSERT
                    };
                }
                else
                {
                    state = new DBState
                    {
                        Name  = t.MAP_UPDATE,
                        Param = item.ToDict(),
                        Type  = ESqlType.UPDATE
                    };
                }
                states.Add(state);
            }

            return(DB.ExecuteWithTransaction(states));
        }
Beispiel #5
0
        public bool TargetDelete(StrObjectDict obj)
        {
            var id = obj.GetString("ID");

            var batchStates = new DBState[]
            {
                new DBState()
                {
                    Name  = new NursingPlanTarget().MAP_DELETE,
                    Param = new{ ID = id },
                    Type  = ESqlType.DELETE
                },
                new DBState()
                {
                    Name  = new NursingPlanDetails().MAP_DELETE,
                    Param = new{ PlanTargetID = id },
                    Type  = ESqlType.DELETE
                },
                new DBState()
                {
                    Name  = new QuestionRelation().MAP_DELETE,
                    Param = new{ FunID = id },
                    Type  = ESqlType.DELETE
                }
            };

            return(DB.ExecuteWithTransaction(batchStates) > 0);
        }
Beispiel #6
0
 /// <summary>
 /// Закрыть загруженную БД
 /// </summary>
 public void CloseDB()
 {
     if (slim.TryEnterWriteLock(1000))
     {
         try
         {
             if (state == DBState.Loaded || state == DBState.Saving)
             {
                 DataBase.CloseDB();
                 state = DBState.Default;
             }
             else
             {
                 throw new InvalidOperationException("База данных не загружена.");
             }
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message, ex);
         }
         finally
         {
             slim.ExitWriteLock();
         }
     }
 }
Beispiel #7
0
        /// <summary>
        /// Delete 表单信息
        /// </summary>
        /// <param name="id">表单ID</param>
        /// <returns></returns>
        public int NursingFormInsertDelete(string id)
        {
            DBState         state  = null;
            IList <DBState> dblist = new List <DBState>();

            dblist.Add(new DBState
            {
                Name  = "DELETE_Form",
                Param = new
                {
                    ID = id
                }.toStrObjDict(),
                Type = ESqlType.DELETE
            });
            dblist.Add(new DBState
            {
                Name  = "DELETE_FormFile",
                Param = new
                {
                    ID = id
                }.toStrObjDict(),
                Type = ESqlType.DELETE
            });
            return(DB.Execute(dblist));
        }
Beispiel #8
0
 /// <summary>
 /// 保存护理要素分类
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public int Hns_SavePType(IDictionary <string, object> obj)
 {
     if (!obj.ContainsKey("ID"))
     {
         obj["ID"] = Utils.getGUID();
         DBState state = null;
         state = new DBState
         {
             Name  = "INSERT_ElementPartGroup",
             Param = obj.toStrObjDict(),
             Type  = ESqlType.INSERT
         };
         return(DB.Execute(state));
     }
     else
     {
         DBState state = null;
         state = new DBState
         {
             Name  = "UPDATE_ElementPartGroup",
             Param = obj.toStrObjDict(),
             Type  = ESqlType.UPDATE
         };
         return(DB.Execute(state));
     }
 }
Beispiel #9
0
        public override int InsertOrUpdate <T>(ZLSoft.Pub.StrObjectDict dict)
        {
            DBState state = null;
            T       t     = System.Activator.CreateInstance <T>();

            if (!dict.ContainsKey("ID") || string.IsNullOrEmpty(dict["ID"].ToString()))
            {
                dict["ID"]      = Utils.getGUID();
                dict["RelatID"] = dict["ID"];
                state           = new DBState
                {
                    Name  = t.MAP_INSERT,
                    Param = dict,
                    Type  = ESqlType.INSERT
                };
            }
            else
            {
                state = new DBState
                {
                    Name  = t.MAP_UPDATE,
                    Param = dict,
                    Type  = ESqlType.UPDATE
                };
            }
            return(DB.Execute(state));
        }
Beispiel #10
0
 /// <summary>
 /// 保存报表分类
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public int TypeInsertOrUpdate(IDictionary <string, object> obj)
 {
     if (!obj.ContainsKey("ID"))
     {
         obj["ID"] = Utils.getGUID();
         DBState state = null;
         state = new DBState
         {
             Name  = "INSERT_ReportFormType",
             Param = obj.toStrObjDict(),
             Type  = ESqlType.INSERT
         };
         return(DB.Execute(state));
     }
     else
     {
         DBState state = null;
         state = new DBState
         {
             Name  = "UPDATE_ReportFormType",
             Param = obj.toStrObjDict(),
             Type  = ESqlType.UPDATE
         };
         return(DB.Execute(state));
     }
 }
Beispiel #11
0
        /// <summary>
        /// 插入或者更新表
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dict"></param>
        /// <returns></returns>
        public virtual int InsertOrUpdate <T>(StrObjectDict dict) where T : BaseModel, new()
        {
            DBState state = null;
            T       t     = System.Activator.CreateInstance <T>();

            if (!dict.ContainsKey("ID") || dict["ID"] == null)
            {
                dict["ID"] = Utils.getGUID();
                state      = new DBState
                {
                    Name  = t.MAP_INSERT,
                    Param = dict,
                    Type  = ESqlType.INSERT
                };
            }
            else
            {
                state = new DBState
                {
                    Name  = t.MAP_UPDATE,
                    Param = dict,
                    Type  = ESqlType.UPDATE
                };
            }
            return(DB.Execute(state));
        }
Beispiel #12
0
        /// <summary>
        /// 插入或者更新表
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public virtual int InsertOrUpdate <T>(T t) where T : BaseModel, new()
        {
            DBState state = null;

            if (string.IsNullOrEmpty(t.ID))
            {
                if (string.IsNullOrEmpty(t.ID))
                {
                    t.ID = Utils.getGUID();
                }
                state = new DBState
                {
                    Name  = t.MAP_INSERT,
                    Param = t.ToDict(),
                    Type  = ESqlType.INSERT
                };
            }
            else
            {
                state = new DBState
                {
                    Name  = t.MAP_UPDATE,
                    Param = t.ToDict(),
                    Type  = ESqlType.UPDATE
                };
            }
            return(DB.Execute(state));
        }
		public GenericNotificationInfo (int laneID, int hostID, int revisionID, string message, DBState state)
		{
			this.laneID = laneID;
			this.hostID = hostID;
			this.revisionID = revisionID;
			this.message = message;
			this.state = state;
		}
        public StateStruct GetState(string stateGuid, string MachineGuid)
        {
            DBState dbState = new DBState(dataProvider);
            dbState.Connection = connection;

            dbState.Load(stateGuid, MachineGuid);
            return dbState.BusinessObject;
        }
Beispiel #15
0
 public GenericNotificationInfo(int laneID, int hostID, int revisionID, string message, DBState state)
 {
     this.laneID     = laneID;
     this.hostID     = hostID;
     this.revisionID = revisionID;
     this.message    = message;
     this.state      = state;
 }
Beispiel #16
0
 private static void SaveState(DB db, int id, DBState state, bool completed)
 {
     using (IDbCommand cmd = db.CreateCommand()) {
         cmd.CommandText = "UPDATE RevisionWork SET state = @state, completed = @completed WHERE id = @id;";
         DB.CreateParameter(cmd, "state", (int)state);
         DB.CreateParameter(cmd, "completed", completed);
         DB.CreateParameter(cmd, "id", id);
         cmd.ExecuteNonQuery();
     }
 }
Beispiel #17
0
		public static void SetState (DB db, int id, DBState old_state, DBState new_state)
		{
			using (IDbCommand cmd = db.CreateCommand ()) {
				cmd.CommandText = "UPDATE Work SET state = @new_state WHERE state = @old_state AND id = @id;";
				DB.CreateParameter (cmd, "id", id);
				DB.CreateParameter (cmd, "old_state", (int) old_state);
				DB.CreateParameter (cmd, "new_state", (int) new_state);
				cmd.ExecuteNonQuery ();
			}
		}
Beispiel #18
0
        public static DbCommand Command <TCon>(DBState <TCon> dbState, string query, params System.Data.Common.DbParameter[] ps)
            where TCon : DbConnection
        {
            var cmd = dbState.Connection.CreateCommand();

            cmd.CommandText = query;
            dbState.Transaction.MatchSome(t => cmd.Transaction = t);
            cmd.Parameters.AddRange(ps);
            return(cmd);
        }
Beispiel #19
0
        /// <summary>
        /// Create DBCommand based on embedded resource query file
        /// that will be searched in dbState.AssemblyWithEmbResourcesQueries
        /// based on fileName.[sql|hana] pattern - extension will be chosed based on dbState.Connection Type
        /// </summary>
        /// <param name="fileName">the query file name(without extensions)</param>
        /// <param name="replaceInQueryStringList">will be used as a String.Format parameters to replace the query string.
        /// NOTE: this should not be used unless the source for this list is secured in order to avoid SQL injections</param>
        /// <param name="ps"> DBMonad DBParameters which will be mapped to the correct DB Data provider Parameter</param>
        /// <returns></returns>
        public static DbCommand CommandFromFile <TCon>(DBState <TCon> dbState, string fileName, string[] replaceInQueryStringList, params System.Data.Common.DbParameter[] ps)
            where TCon : DbConnection
        {
            var fileExtension = dbState.Connection.GetType().Name.Replace("Connection", "").ToLower();

            var query = string.Format(QueryFromFile(
                                          dbState.AssemblyWithEmbResourcesQueries,
                                          fileName, fileExtension
                                          ), replaceInQueryStringList);

            return(Command(dbState, query, ps));
        }
Beispiel #20
0
        public int SetDesktopStyle(IDictionary <string, object> obj)
        {
            DBState state = null;

            state = new DBState
            {
                Name  = "SetDesktopStyle_Form",
                Param = obj.toStrObjDict(),
                Type  = ESqlType.UPDATE
            };
            return(DB.Execute(state));
        }
Beispiel #21
0
        public virtual int Delete <T>(StrObjectDict obj) where T : BaseModel, new()
        {
            T       t     = System.Activator.CreateInstance <T>();
            DBState state = new DBState
            {
                Name  = t.MAP_DELETE,
                Param = obj,
                Type  = ESqlType.DELETE
            };

            return(DB.Execute(state));
        }
Beispiel #22
0
        public int DeletePowers(IDictionary <string, object> obj)
        {
            DBState db = new DBState();

            db = new DBState
            {
                Name  = "DELALL_RolePower",
                Param = obj,
                Type  = ESqlType.DELETE
            };
            return(DB.Execute(db));
        }
Beispiel #23
0
        /// <summary>
        /// 删除报表文件
        /// </summary>
        /// <returns></returns>
        public int FileDel(IDictionary <string, object> obj)
        {
            DBState state = null;

            state = new DBState
            {
                Name  = "DELETE_ReportFormFile",
                Param = obj.toStrObjDict(),
                Type  = ESqlType.DELETE
            };
            return(DB.Execute(state));
        }
Beispiel #24
0
        /// <summary>
        /// 删除护理要素分类
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int Hns_DelPType(IDictionary <string, object> obj)
        {
            DBState state = null;

            state = new DBState
            {
                Name  = "DELETE_ElementPartGroup",
                Param = obj.toStrObjDict(),
                Type  = ESqlType.DELETE
            };
            return(DB.Execute(state));
        }
        public async Task <IDialogFlowOutput> ExecuteAsync(IDialogFlowInput flowPostModel)
        {
            // Save the email with the session Id for later use
            var sessionId = flowPostModel.SessionId;
            // Save the session state
            await DBState.SaveSessionState(sessionId, flowPostModel);

            // Save the session and email to the store
            var response = new DialogFlowOutput();

            // Return a blank response
            return(response);
        }
Beispiel #26
0
        public int Delete(IDictionary <string, object> dict)
        {
            DBState state = null;

            state = new DBState
            {
                Name  = "DELETE_TreeDefinition",
                Param = new
                {
                    ID = dict["ID"]
                }.toStrObjDict(),
                Type = ESqlType.DELETE
            };
            return(DB.Execute(state));
        }
Beispiel #27
0
        /// <summary>
        /// 通过ID删除表的一条数据
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public virtual int Delete <T>(string ID) where T : BaseModel, new()
        {
            T t = new T
            {
                ID = ID
            };
            DBState state = new DBState
            {
                Name  = t.MAP_DELETE,
                Param = t.ToDict(),
                Type  = ESqlType.DELETE
            };

            return(DB.Execute(state));
        }
Beispiel #28
0
        /// <summary>
        /// 保存对应宣教单
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int Hns_setFormMap(IDictionary <string, object> obj)
        {
            DBState state = null;

            state = new DBState
            {
                Name  = "SaveFormMap_Form",
                Param = new
                {
                    FormAgainst = obj["FormAgainst"],
                    ID          = obj["ID"]
                }.toStrObjDict(),
                Type = ESqlType.UPDATE
            };
            return(DB.Execute(state));
        }
Beispiel #29
0
    public DBState AddNewState(string name)
    {
        DBState newState;

        if (!_states.ContainsKey(name))
        {
            newState = new DBState();
            _states.Add(name, newState);
        }
        else
        {
            newState = GetState(name);
        }

        return(newState);
    }
Beispiel #30
0
        /// <summary>
        /// 保存适用科室
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int Hns_setFormDepts(IDictionary <string, object> obj)
        {
            DBState state = null;

            state = new DBState
            {
                Name  = "SaveDeptList_Form",
                Param = new
                {
                    DeptRange = obj["DeptRange"],
                    ID        = obj["ID"]
                }.toStrObjDict(),
                Type = ESqlType.UPDATE
            };
            return(DB.Execute(state));
        }
Beispiel #31
0
        protected ReaderWriterLockSlim t_slim; // синхронизатор таймера

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Инициализирует новый экземпляр класса
        /// </summary>
        public DataBaseManager()
        {
            state = DBState.Default;

            adapter = new DataBaseAdapter(".", "", "sa", "");
            provider = new DataBaseProvider(adapter);

            saver = new DataBaseSaver();

            is_valid = false;
            timer = new Timer(TimerCallback, null, 0, 5000);

            slim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
            t_slim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);

            DataBase.Initialize();
        }
Beispiel #32
0
        /// <summary>
        /// Инициализирует новый экземпляр класса
        /// </summary>
        public DataBaseManager()
        {
            state = DBState.Default;

            adapter  = new DataBaseAdapter(".", "", "sa", "");
            provider = new DataBaseProvider(adapter);

            saver = new DataBaseSaver();

            is_valid = false;
            timer    = new Timer(TimerCallback, null, 0, 5000);

            slim   = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
            t_slim = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);

            DataBase.Initialize();
        }
Beispiel #33
0
        public int InsertPowers(IList <RolePower> list)
        {
            IList <DBState> states = new List <DBState>();

            foreach (RolePower item in list)
            {
                DBState state = null;
                state = new DBState
                {
                    Name  = "INSERT_RolePower",
                    Param = item.ToDict(),
                    Type  = ESqlType.INSERT
                };
                states.Add(state);
            }

            return(DB.ExecuteWithTransaction(states));
        }
		/// <summary>
		/// Calculates a new state if the current state is NotDone.
		/// </summary>
		/// <param name="db"></param>
		/// <param name="id"></param>
		/// <param name="current"></param>
		/// <returns></returns>
		public static DBState EnsureState (DB db, int id, DBState current)
		{
			DBState actual;
			bool completed;

			if (current != DBState.NotDone)
				return current;

			actual = CalculateState (db, id, out completed);

			if (actual != current)
				SaveState (db, id, actual, completed);

			return actual;
		}
		private static void SaveState (DB db, int id, DBState state, bool completed)
		{
			using (IDbCommand cmd = db.CreateCommand ()) {
				cmd.CommandText = "UPDATE RevisionWork SET state = @state, completed = @completed WHERE id = @id;";
				DB.CreateParameter (cmd, "state", (int) state);
				DB.CreateParameter (cmd, "completed", completed);
				DB.CreateParameter (cmd, "id", id);
				cmd.ExecuteNonQuery ();
			}
		}
Beispiel #36
0
        /// <summary>
        /// Загрузить БД
        /// </summary>
        /// <param name="dbName">Имя загружаемой БД</param>
        public void LoadDB(string dbName)
        {
            if (slim.TryEnterWriteLock(500))
            {
                string old_name_db = string.Empty;

                try
                {
                    if (IsSrvValid)
                    {
                        old_name_db = adapter.InitialCatalog;
                        if (state == DBState.Default)
                        {
                            adapter.InitialCatalog = dbName;
                            provider.Adapter.InitialCatalog = dbName;

                            DataBase.LoadDB(provider);
                            state = DBState.Loaded;
                        }
                    }
                }
                catch (Exception ex)
                {
                    adapter.InitialCatalog = old_name_db;
                    provider.Adapter.InitialCatalog = old_name_db;

                    throw new Exception(ex.Message, ex);
                }
                finally
                {
                    slim.ExitWriteLock();
                }
            }
        }
		public static void SetState (DB db, int id, DBState old_state, DBState new_state)
		{
			using (IDbCommand cmd = db.CreateCommand ()) {
				cmd.CommandText = "UPDATE Work SET state = @new_state WHERE state = @old_state AND id = @id;";
				DB.CreateParameter (cmd, "id", id);
				DB.CreateParameter (cmd, "old_state", (int) old_state);
				DB.CreateParameter (cmd, "new_state", (int) new_state);
				cmd.ExecuteNonQuery ();
			}
		}
 public bool UpdateState(string stateGuid, string xmlInfo, string machine)
 {
     DBState dbState = new DBState(dataProvider);
     dbState.Connection = connection;
     StateStruct state = new StateStruct();
     state.Guid = stateGuid;
     state.XmlInfo = xmlInfo;
     state.Machine = machine;
     return dbState.Save(state);
 }
Beispiel #39
0
 /// <summary>
 /// Закрыть загруженную БД
 /// </summary>
 public void CloseDB()
 {
     if (slim.TryEnterWriteLock(1000))
     {
         try
         {
             if (state == DBState.Loaded || state == DBState.Saving)
             {
                 DataBase.CloseDB();
                 state = DBState.Default;
             }
             else
                 throw new InvalidOperationException("База данных не загружена.");
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message, ex);
         }
         finally
         {
             slim.ExitWriteLock();
         }
     }
 }
Beispiel #40
0
 /// <summary>
 /// Начать сохранение параметров в базу данных
 /// </summary>
 public void TurnOnSave()
 {
     if (slim.TryEnterWriteLock(500))
     {
         try
         {
             if (state == DBState.Loaded)
             {
                 saver.Start();
                 if (saver.State == DataBaseSaver.DataBaseSaverStates.Started)
                 {
                     state = DBState.Saving;
                 }
             }
         }
         finally
         {
             slim.ExitWriteLock();
         }
     }
 }