Example #1
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="childTableName">从表名称如是多个从表,以逗号隔开</param>
        /// <param name="primaryKeyName">主健字段名称</param>
        /// <returns></returns>

        public EntityResult Delete(string childTableName, string primaryKeyName)
        {
            List <string> sqllist = new List <string>();

            if (childTableName.IndexOf(',') > 0)
            {
                string[] sqls = childTableName.Split(',');
                for (int i = 0; i < sqls.Length; i++)
                {
                    string childsql = "DELETE FROM " + sqls[i] + " WHERE " + primaryKeyName.ToUpper() + "='" + PrimaryKeyValue + "'";
                    sqllist.Add(childsql);
                }
            }
            else
            {
                string childsql = "DELETE FROM " + childTableName + " WHERE " + primaryKeyName.ToUpper() + "='" + PrimaryKeyValue + "'";
                sqllist.Add(childsql);
            }
            string mainsql = "DELETE FROM " + this.GetType().Name + " WHERE " + PrimaryKeyName.ToUpper() + "='" + PrimaryKeyValue + "'";

            sqllist.Add(mainsql);
            EntityResult result = GetEntityResult(SMT.DataProvider.ExecuteByTransaction(sqllist));
            int          n      = result.RecordCount;

            if (n > 0)
            {
                eb = null;
                result.RecordCount = n;
            }
            else
            {
                result.RecordCount = 0;
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// 删除(通过事务,必须在BeginTransaction()和 CommitTransaction()二个方法中间)
        /// </summary>

        public EntityResult DeleteByTransaction(IDbCommand idbconn)
        {
            string sql = "DELETE FROM " + this.GetType().Name + " WHERE " + PrimaryKeyName.ToUpper() + "='" + PrimaryKeyValue + "'";
            //SMT.DataProvider.ExecuteSQLByTransaction(idbconn, sql);
            EntityResult result = GetEntityResult(SMT.DataProvider.ExecuteSQLByTransaction(idbconn, sql));

            result.Sql = sql;
            return(result);
        }
Example #3
0
        /// <summary>
        /// 删除
        /// </summary>
        /// <returns></returns>

        public EntityResult Delete()
        {
            string sql = "DELETE FROM " + this.GetType().Name + " WHERE " + PrimaryKeyName.ToUpper() + "='" + PrimaryKeyValue + "'";

            EntityResult result = GetEntityResult(SMT.DataProvider.ExecuteSQL(sql));
            int          n      = result.RecordCount;

            if (n > 0)
            {
                eb = null;
                result.RecordCount = n;
            }
            else
            {
                result.RecordCount = 0;
            }
            return(result);
        }
Example #4
0
        /// <summary>
        /// 更改(通过事务,必须在BeginTransaction()和 CommitTransaction()二个方法中间)
        /// </summary>

        public EntityResult UpdateByTransaction(IDbCommand idbconn)
        {
            #region 参数化
            eb = this;
            string sql  = "";
            Type   type = this.GetType();
            string name = "";
            if (has == null)
            {
                has = DataBaseType.GetTableColumn(this.GetType().Name);
            }
            SMT.DataProvider.CreateParameters(has.Count);
            int i = 0;
            foreach (PropertyInfo p in this.GetType().GetProperties())
            {
                //Console.WriteLine(p.Name + "=" + p.GetValue(eb, null));
                //this.GetType().GetProperties()[3].Name
                if (has.Contains(p.Name.ToUpper()))
                {
                    if (PrimaryKeyName.ToUpper() != p.Name.ToUpper())
                    {
                        SMT.DataProvider.AddParameters(i, p.Name.ToUpper(), p.GetValue(eb, null));
                        sql  += p.Name.ToUpper() + "='" + p.GetValue(eb, null) + "',";
                        name += p.Name.ToUpper() + "=:" + p.Name.ToUpper() + ",";
                        i++;
                    }
                }
            }
            sql = "UPDATE " + this.GetType().Name + " SET " + sql.TrimEnd(',') + " WHERE  " + PrimaryKeyName.ToUpper() + "='" + PrimaryKeyValue + "'";
            SMT.DataProvider.AddParameters(i, PrimaryKeyName.ToUpper(), PrimaryKeyValue);
            string exeSql = "UPDATE " + this.GetType().Name + " SET " + name.TrimEnd(',') + " WHERE  " + PrimaryKeyName.ToUpper() + "=:" + PrimaryKeyName.ToUpper() + "";

            EntityResult result = GetEntityResult(SMT.DataProvider.ExecuteSQLByTransaction(idbconn, exeSql));
            result.Sql = sql;
            return(result);

            #endregion
        }
Example #5
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <returns></returns>

        public EntityResult Update()
        {
            #region sql语句
            //Result result = new Result();
            //eb = this;
            //string sql="";
            //Type type=this.GetType();
            //foreach (PropertyInfo p in this.GetType().GetProperties())
            //     {
            //         //Console.WriteLine(p.Name + "=" + p.GetValue(eb, null));
            //         //this.GetType().GetProperties()[3].Name
            //         if (has.Contains(p.Name.ToUpper()))
            //         {
            //             if (PrimaryKeyName.ToUpper() != p.Name.ToUpper())
            //             {
            //                 sql += p.Name.ToUpper() + "='" + p.GetValue(eb, null) + "',";
            //             }
            //         }
            //     }
            //string exeSql="UPDATE "+this.GetType().Name+" SET "+sql.TrimEnd(',')+" WHERE  "+ PrimaryKeyName.ToUpper() + "='" + PrimaryKey + "'";
            //result.Sql = exeSql;
            //int n = SMT.DataProvider.ExecuteSQL(exeSql);
            //if (n > 0)
            //{
            //    result.RecordCount = n;
            //}
            //else
            //{
            //    result.RecordCount = 0;
            //}
            //return result;
            #endregion
            #region 参数化

            eb = this;
            string sql  = "";
            Type   type = this.GetType();
            string name = "";
            if (has == null)
            {
                has = DataBaseType.GetTableColumn(this.GetType().Name);
            }
            SMT.DataProvider.CreateParameters(has.Count);
            int i = 0;
            foreach (PropertyInfo p in this.GetType().GetProperties())
            {
                //Console.WriteLine(p.Name + "=" + p.GetValue(eb, null));
                //this.GetType().GetProperties()[3].Name
                if (has.Contains(p.Name.ToUpper()))
                {
                    if (PrimaryKeyName.ToUpper() != p.Name.ToUpper())
                    {
                        SMT.DataProvider.AddParameters(i, p.Name.ToUpper(), p.GetValue(eb, null));
                        sql  += p.Name.ToUpper() + "='" + p.GetValue(eb, null) + "',";
                        name += p.Name.ToUpper() + "=:" + p.Name.ToUpper() + ",";
                        i++;
                    }
                }
            }
            sql = "UPDATE " + this.GetType().Name + " SET " + sql.TrimEnd(',') + " WHERE  " + PrimaryKeyName.ToUpper() + "='" + PrimaryKeyValue + "'";
            SMT.DataProvider.AddParameters(i, PrimaryKeyName.ToUpper(), PrimaryKeyValue);
            string exeSql = "UPDATE " + this.GetType().Name + " SET " + name.TrimEnd(',') + " WHERE  " + PrimaryKeyName.ToUpper() + "=:" + PrimaryKeyName.ToUpper() + "";

            EntityResult result = GetEntityResult(SMT.DataProvider.ExecuteSQL(exeSql));
            result.Sql = sql;
            int n = result.RecordCount;
            if (n > 0)
            {
                result.RecordCount = n;
            }
            else
            {
                result.RecordCount = 0;
            }
            return(result);

            #endregion
        }