private void button2_Click(object sender, EventArgs e) { if (Instance == null) { Instance = new OracleInstance("Mortal"); } //var list = Instance.Query<MortalLog>("SELECT T1.ID \"Id\", T1.CONTENT \"Content\", T1.CREATION_DATE \"CreationDate\" FROM MORTAL_LOG T1"); //var list = Instance.Query<MortalLog>("SELECT * FROM MORTAL_LOG"); var list = Instance.Query <PatientInfo>("SELECT * FROM CIS_PATIENT_INFO"); }
public BaseHelper(IDBInstance db, char quoting) : this(db) { m_QuotingStart = quoting; switch (quoting) { case '"': m_QuotingEnd = '"'; break; case '[': m_QuotingEnd = ']'; break; } }
static void Main(string[] args) { // Can not create an object because of private constructor // Singleton obj = new Singleton(); //// Get an instance of the Singleton class Singleton obj = Singleton.Instance; //// Instance is already available, return the already created instance Singleton obj2 = Singleton.Instance; //Is it going to work on multithreaded enviornment Parallel.For(0, 5, i => { ProcessData(i); }); //// without using a sealed class //Singleton.SingletonNested nestedObj1 = new Singleton.SingletonNested(); //Singleton.SingletonNested nestedObj2 = new Singleton.SingletonNested(); ////Get SQL instance IDBInstance obj3 = SQLInstance.Instance; //// Get Flat file instance IDBInstance obj4 = new FlatFileInstance(); ////Get SQL instance IDBInstance obj5 = SQLInstance.Instance; //// Get Flat file instance IDBInstance obj6 = new FlatFileInstance(); ////Calling client method ProcessData(obj3); ProcessData(obj4); ProcessData(obj5); ProcessData(obj6); }
public BaseHelper(IDBInstance db) { m_Db = db; }
public LoginBusiness() { Instance = new OracleInstance(); }
private static void ProcessData(IDBInstance dbInstance) { Console.Write(dbInstance.ToString() + " started processing: "); dbInstance.Process(); }
/// <summary> /// 改变树节点序号 /// </summary> /// <typeparam name="T">树节点类</typeparam> /// <param name="dbInstance">数据库操作对象</param> /// <param name="dbHelper">数据库操作帮助对象</param> /// <param name="idProperty">主键属性名</param> /// <param name="pIdProperty">父节点主键属性名</param> /// <param name="orderProperty">序号属性名</param> /// <param name="id">主键</param> /// <param name="sourcePID">源父节点主键</param> /// <param name="sourceIndex">源序号</param> /// <param name="newPID">新父节点主键</param> /// <param name="newIndex">新序号</param> /// <returns></returns> public static bool ChangeOrder<T>(IDBInstance dbInstance, MSSQLHelper dbHelper, string idProperty, string pIdProperty, string orderProperty, long? id, long? sourcePID, long? sourceIndex, long? newPID, long? newIndex) where T : class { PropertyInfo orderProp = typeof(T).GetProperty(orderProperty); if (newPID == null || newPID == sourcePID) { // 在同一父节点下改变序号 long dVal = newIndex.Value - sourceIndex.Value; List<T> tObjs = null; if (dVal > 0) { // 新序号在旧序号之后 tObjs = dbHelper.Query<T>(string.Format(" [{0}] > {1} and [{0}] <= {2} and [{3}] " + (sourcePID == 0 ? "IS NULL" : "=" + sourcePID) + " ", orderProperty, sourceIndex, newIndex, pIdProperty), null, null); for (int i = 0, len = tObjs.Count; i < len; ++i) { orderProp.SetValue(tObjs[i], CalcOrder(orderProp.PropertyType, orderProp.GetValue(tObjs[i], null), -1), null); } } else if (dVal < 0) { // 新序号在旧序号之前 tObjs = dbHelper.Query<T>(string.Format(" [{0}] >= {1} and [{0}] < {2} and [{3}] " + (sourcePID == 0 ? "IS NULL" : "=" + sourcePID) + " ", orderProperty, newIndex, sourceIndex, pIdProperty), null, null); for (int i = 0, len = tObjs.Count; i < len; ++i) { orderProp.SetValue(tObjs[i], CalcOrder(orderProp.PropertyType, orderProp.GetValue(tObjs[i], null), 1), null); } } T targetTObj = typeof(T).GetConstructor(new List<Type>().ToArray()).Invoke(new List<object>().ToArray()) as T; targetTObj.GetType().GetProperty(idProperty).SetValue(targetTObj, id, null); orderProp.SetValue(targetTObj, newIndex, null); tObjs.Add(targetTObj); tObjs.ForEach(tInfo => { dbHelper.Update<T>(tInfo); }); return true; } else { // 在不同父节点间下改变序号 List<T> sourceParentChildInfos = dbHelper.Query<T>(string.Format(" [{0}] > {1} and [{2}] " + (sourcePID == 0 ? "IS NULL" : "=" + sourcePID) + " ", orderProperty, sourceIndex, pIdProperty), null, null); List<T> targetParentChildInfos = dbHelper.Query<T>(string.Format(" [{0}] >= {1} and [{2}] " + (newPID == 0 ? "IS NULL" : "=" + newPID) + " ", orderProperty, newIndex, pIdProperty), null, null); for (int i = 0, len = sourceParentChildInfos.Count; i < len; ++i) { orderProp.SetValue(sourceParentChildInfos[i], CalcOrder(orderProp.PropertyType, orderProp.GetValue(sourceParentChildInfos[i], null), -1), null); } for (int i = 0, len = targetParentChildInfos.Count; i < len; ++i) { orderProp.SetValue(targetParentChildInfos[i], CalcOrder(orderProp.PropertyType, orderProp.GetValue(targetParentChildInfos[i], null), 1), null); } List<T> totalTInfos = new List<T>(); totalTInfos.AddRange(sourceParentChildInfos); totalTInfos.AddRange(targetParentChildInfos); totalTInfos.ForEach(tInfo => { dbHelper.Update<T>(tInfo); }); TblAttr tblAttr = typeof(T).GetCustomAttributes(typeof(TblAttr), false)[0] as TblAttr; int count = dbInstance.ExecNonQuery(string.Format("UPDATE {0} SET [{1}]=" + (newPID == 0 ? "NULL" : newPID.Value.ToString()) + ",[{2}]=" + newIndex + " WHERE [{3}]=" + id.Value, tblAttr.Name, pIdProperty, orderProperty, idProperty), null); return count > 0; } }