?? ormremover.cs
字號:
//using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Text;
//using System.Data;
//using System.Data.SqlClient;
//using System.Reflection;
//using System.Transactions;
//namespace MiniORM.BAK
//{
// /// <summary>
// /// Orm刪除器,負責刪除指定的Model對應的數據庫記錄
// /// </summary>
// public class OrmRemover
// {
// /// <summary>
// /// 刪除指定的單據,如果有子單據存在那么先刪除子單據
// /// </summary>
// /// <param name="ModelObject">記錄Model</param>
// /// <param name="id">記錄ID</param>
// /// <returns>True - 刪除成功,false - 刪除錯誤</returns>
// public bool Remove(object ModelObject, int id)
// {
// //刪除操作,首先應該先刪除子單據表,再刪除主表
// string strTablename = PubFuncs.GetTableName(ModelObject.GetType());
// string strKeyName = PubFuncs.GetKey(ModelObject.GetType());
// string strDeleteSQL = "DELETE FROM {0} WHERE {1}";
// MiniORMAttribute.SubDataObjectAttribute SubDataAttr = null;
// PropertyInfo[] props = ModelObject.GetType().GetProperties();
// object[] CustomerAttributes;
// using (TransactionScope scope = new TransactionScope())
// {
// //先判斷此單據是否存在子單據,如果存在那么先刪除子單據,刪除子單句之前必須先讀取所有此單據信息,然后做刪除
// foreach (PropertyInfo prop in props)
// {
// CustomerAttributes = prop.GetCustomAttributes(typeof(MiniORMAttribute.SubDataObjectAttribute), false);
// if (CustomerAttributes.Length > 0)
// {
// SubDataAttr = CustomerAttributes[0] as MiniORMAttribute.SubDataObjectAttribute;
// if (SubDataAttr != null)
// {
// Type type = PubFuncs.GetObjectType(SubDataAttr.AssemblyName, SubDataAttr.NamespaceName, SubDataAttr.ClassName);
// //如果有子表存在,那么刪除之
// RemoveSubObject(type, id);
// }
// }
// }
// //刪除本單據
// using (SqlConnection conn = new SqlConnection(INS.DBUtility.SqlHelper.INSClient_Trade_ConnectionString))
// {
// conn.Open();
// SqlCommand cmd = new SqlCommand();
// cmd.Connection = conn;
// cmd.CommandType = CommandType.Text;
// cmd.Parameters.Add(new SqlParameter("@" + strKeyName, id));
// cmd.CommandText = string.Format(strDeleteSQL, new object[] { strTablename, strKeyName + " = @" + strKeyName });
// //刪除
// cmd.ExecuteNonQuery();
// }
// //提交事務
// scope.Complete();
// }
// return true;
// }
// /// <summary>
// /// 刪除子單據
// /// </summary>
// /// <param name="SubObjectType">要刪除的子單據類型</param>
// /// <param name="foreignkey">子單據的外鍵</param>
// private void RemoveSubObject(Type SubObjectType, object ForeignKeyValue)
// {
// string strTablename = PubFuncs.GetTableName(SubObjectType);
// string strKeyName = PubFuncs.GetKey(SubObjectType);
// string strForeignKey = PubFuncs.GetForeignKey(SubObjectType);
// string strSeleteSQL = "SELECT {0} FROM {1} WHERE {2}";
// string strDeleteSQL = "DELETE FROM {0} WHERE {1}";
// MiniORMAttribute.SubDataObjectAttribute SubDataAttr = null;
// PropertyInfo[] props = SubObjectType.GetProperties();
// object[] CustomerAttributes;
// using (TransactionScope scope = new TransactionScope())
// {
// //先判斷此單據是否存在子單據,如果存在那么先刪除子單據,刪除子單句之前必須先讀取所有此單據信息,然后做刪除
// foreach (PropertyInfo prop in props)
// {
// CustomerAttributes = prop.GetCustomAttributes(typeof(MiniORMAttribute.SubDataObjectAttribute), false);
// if (CustomerAttributes.Length > 0)
// {
// SubDataAttr = CustomerAttributes[0] as MiniORMAttribute.SubDataObjectAttribute;
// if (SubDataAttr != null)
// {
// Type type = PubFuncs.GetObjectType(SubDataAttr.AssemblyName, SubDataAttr.NamespaceName, SubDataAttr.ClassName);
// using (SqlConnection conn = new SqlConnection(INS.DBUtility.SqlHelper.INSClient_Trade_ConnectionString))
// {
// conn.Open();
// SqlCommand cmd = new SqlCommand();
// cmd.Connection = conn;
// cmd.CommandType = CommandType.Text;
// cmd.Parameters.Add(new SqlParameter("@" + strForeignKey, ForeignKeyValue));
// cmd.CommandText = string.Format(strSeleteSQL, new object[] { strKeyName, strTablename, strForeignKey + " = @" + strForeignKey });
// using (SqlDataReader rd = cmd.ExecuteReader(CommandBehavior.CloseConnection))
// {
// while (rd.Read())
// {
// //如果有子表存在,那么刪除之
// RemoveSubObject(type, rd[0]);
// }
// }
// } // --using (SqlConnection conn ...
// }
// } // --if (CustomerAttributes.Length > 0)
// }
// //刪除本單據
// using (SqlConnection conn = new SqlConnection(INS.DBUtility.SqlHelper.INSClient_Trade_ConnectionString))
// {
// conn.Open();
// SqlCommand cmd = new SqlCommand();
// cmd.Connection = conn;
// cmd.CommandType = CommandType.Text;
// cmd.Parameters.Add(new SqlParameter("@" + strForeignKey, ForeignKeyValue));
// cmd.CommandText = string.Format(strDeleteSQL, new object[] { strTablename, strForeignKey + " = @" + strForeignKey });
// //刪除
// cmd.ExecuteNonQuery();
// }
// //提交事務
// scope.Complete();
// }
// }
// }
//}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -