Exemplo n.º 1
0
        public int BantchOnce(List <IEntity> tlist, DBtransaction dbtran)
        {
            StringBuilder      stringBuilder = new StringBuilder();
            List <DbParameter> list          = new List <DbParameter>();
            string             str           = " IF EXIST (SELECT  " + PrimaryKey + " FROM " + TableName + " WHERE " + PrimaryKey + "=@" + PrimaryKey + ")";

            str += " BEGIN ";
            str += IEntity.GetUpdatePlate();
            str += " END ELSE BEGIN ";
            str += IEntity.GetInsertPlate();
            str += " END ";
            int count = tlist.Count;

            for (int i = 0; i < count; i++)
            {
                string             text          = str;
                List <DbParameter> fullParmeters = tlist[i].GetFullParameters(); //获取所有的Parameters
                int count2 = fullParmeters.Count;
                //把每一个ParameterName加上序号
                for (int j = 0; j < count2; j++)
                {
                    text = text.Replace(fullParmeters[j].ParameterName, fullParmeters[j].ParameterName + j);
                    fullParmeters[j].ParameterName = fullParmeters[j].ParameterName + i;
                }
                stringBuilder.Append(text.ToString());
                list.AddRange(fullParmeters);
            }
            if (dbtran != null)
            {
                return(excuteImport.ExcuteNotQuery(stringBuilder.ToString(), list, dbtran));
            }
            return(excuteImport.ExcuteNotQuery(stringBuilder.ToString(), list));
        }
Exemplo n.º 2
0
        public int DeleteModel(object primaryKey, DBtransaction dbtran)
        {
            List <DbParameter> parameters = new List <DbParameter>();
            string             sqlStr     = "";

            parameters.Add(excuteImport.CreateDbParameter("@" + PrimaryKey, primaryKey));
            sqlStr = " DELETE " + TableName + " WHERE " + PrimaryKey + "=@PrimaryKey";
            return(excuteImport.ExcuteNotQuery(sqlStr, parameters, dbtran));
        }
Exemplo n.º 3
0
        public int Insert(InsertClip insertClip, DBtransaction dbtran)
        {
            List <DbParameter> parameters = new List <DbParameter>();
            string             sqlInsert  = "";

            insertClip.GetParameterString(excuteImport, ref sqlInsert, ref parameters);
            string sqlStr = "INSERT " + TableName + sqlInsert;

            return(excuteImport.ExcuteNotQuery(sqlStr, parameters, dbtran));
        }
Exemplo n.º 4
0
        public int Delete(WhereClip whereClip, DBtransaction dbtran)
        {
            List <DbParameter> parameters   = new List <DbParameter>();
            string             sqlWhereClip = "";

            whereClip.GetPartmerStrings(excuteImport, ref sqlWhereClip, ref parameters);
            string sqlStr = "DELETE " + TableName + " " + "WHERE " + sqlWhereClip;

            return(excuteImport.ExcuteNotQuery(sqlStr, parameters, dbtran));
        }
Exemplo n.º 5
0
        public int Update(UpdateClip updateClip, WhereClip whereClip, DBtransaction dbtran)
        {
            List <DbParameter> parameters = new List <DbParameter>();
            string             updateSql  = "";
            string             whereSql   = "";

            updateClip.GetParamString(excuteImport, ref updateSql, ref parameters);
            whereClip.GetPartmerStrings(excuteImport, ref whereSql, ref parameters);
            string sqlStr = "UPDATE " + TableName + " " + updateSql + " WHERE " + whereSql;

            return(excuteImport.ExcuteNotQuery(sqlStr, parameters, dbtran));
        }
Exemplo n.º 6
0
        public int BantchUpdate(List <IEntity> tlist, DBtransaction dbtran)
        {
            IList <List <DbParameter> > parameterList = new List <List <DbParameter> >();

            foreach (IEntity t in tlist)
            {
                parameterList.Add(t.GetFullParameters());
            }
            if (dbtran != null)
            {
                return(excuteImport.ExcuteNotQuery(IEntity.GetUpdatePlate(), parameterList, dbtran));
            }
            return(excuteImport.ExcuteNotQuery(IEntity.GetUpdatePlate(), parameterList));
        }
Exemplo n.º 7
0
        public int DeleteModel(Collection <object> primaryKeyList, DBtransaction dbtran)
        {
            string             text = "";
            List <DbParameter> list = new List <DbParameter>();
            int count = primaryKeyList.Count;

            for (int i = 0; i < count; i++)
            {
                //将所有primaryKey添加到集合中,如果是第一个,直接添加,如果不是第一个,则加入逗号后添加
                text = ((text.Length != 0) ? (text + "," + excuteImport.sqlSetting.Flag + i.ToString()) : (text + excuteImport.sqlSetting.Flag + i.ToString()));
                list.Add(excuteImport.CreateDbParameter(excuteImport.sqlSetting.Flag + PrimaryKey + i.ToString(), primaryKeyList[i]));
            }
            string sqlStr = string.Format(excuteImport.sqlSetting.DeleteModel_sql_In, TableName, PrimaryKey, text);

            return(excuteImport.ExcuteNotQuery(sqlStr, list, dbtran));
        }
Exemplo n.º 8
0
        public int BantchDelete(List <IEntity> tlist, DBtransaction dbtran)
        {
            IList <List <DbParameter> > parameterlist = new List <List <DbParameter> >();

            //由于此处没有定义虚函数,所以在此编写sql语句
            foreach (IEntity t in tlist)
            {
                List <DbParameter> list2 = new List <DbParameter>();
                list2.Add(excuteImport.CreateDbParameter("@" + PrimaryKey, t.PrimaryKeyValue));
                parameterlist.Add(list2);
            }
            string sql = " DELETE " + TableName + " WHERE " + IEntity.PrimaryKey + "=@" + PrimaryKey;

            if (dbtran != null)
            {
                return(excuteImport.ExcuteNotQuery(sql, parameterlist, dbtran));
            }
            return(excuteImport.ExcuteNotQuery(sql, parameterlist));
        }
Exemplo n.º 9
0
        public int ExcuteNotQuery(string sqlStr, List <DbParameter> Parmeters, DBtransaction dbtran)
        {
            int       result    = 0;
            DbCommand dbCommand = providerFactory.CreateCommand();

            try
            {
                dbCommand.CommandText    = sqlStr;
                dbCommand.CommandType    = CommandType.Text;
                dbCommand.Connection     = dbtran.DbConnection;
                dbCommand.Transaction    = dbtran.DbTransaction;
                dbCommand.CommandTimeout = commandTimeOut;

                if (Parmeters != null && Parmeters.Count > 0)
                {
                    dbCommand.Parameters.AddRange(Parmeters.ToArray());
                }
                result = dbCommand.ExecuteNonQuery();
                dbCommand.Parameters.Clear();  // 清空参数
                dbCommand.Connection.Close();  //关闭Command
            }
            catch (Exception ex)
            {
                if (dbCommand != null && dbCommand.Connection.State == ConnectionState.Open)
                {
                    dbtran.RollBack();
                    dbCommand.Transaction.Dispose();
                    dbCommand.Connection.Close();
                }
                throw ex;
            }
            finally
            {
            }
            return(result);
        }
Exemplo n.º 10
0
        public int BantchSave(List <IEntity> tlist, DBtransaction dbtran)
        {
            //使用stringbulider,生成存储过程语句
            StringBuilder stringbulider = new StringBuilder();

            stringbulider.Append(" IF EXISTS(SELECT " + PrimaryKey + " FROM " + TableName + " WHERE " + PrimaryKey + "=@" + PrimaryKey + ")");
            stringbulider.Append(" BEGIN ");
            stringbulider.Append(IEntity.GetUpdatePlate());
            stringbulider.Append(" END ELSE BEGIN ");
            stringbulider.Append(" END ");

            IList <List <DbParameter> > list = new List <List <DbParameter> >();

            foreach (IEntity T in tlist)
            {
                //写入参数
                list.Add(T.GetFullParameters());
            }
            if (dbtran != null)
            {
                return(excuteImport.ExcuteNotQuery(stringbulider.ToString(), list, dbtran));
            }
            return(excuteImport.ExcuteNotQuery(stringbulider.ToString(), list));
        }
Exemplo n.º 11
0
        public string BantchInsert(List <T> tList, ref DBtransaction dbTran)
        {
            int num = EntityGenerics <DB, T> .Instance.BanthInsert(tList, dbTran);

            return((num > 0) ? "" : "批量添加失败");
        }
Exemplo n.º 12
0
        public int ExcuteNotQuery(IList <string> lstSqls, IList <List <DbParameter> > lstParmeters, DBtransaction dbtran)
        {
            int    num    = 0;
            string sqlstr = "";

            try
            {
                int counts = lstSqls.Count;
                for (int i = 0; i < counts; i++)
                {
                    DbCommand dbCommand = providerFactory.CreateCommand();
                    dbCommand.CommandText    = lstSqls[i];
                    dbCommand.CommandType    = CommandType.Text;
                    dbCommand.CommandTimeout = commandTimeOut;
                    dbCommand.Connection     = dbtran.DbConnection;
                    dbCommand.Transaction    = dbtran.DbTransaction;
                    sqlstr = lstSqls[i];
                    if (lstParmeters[i] != null && lstParmeters[i].Count > 0)
                    {
                        dbCommand.Parameters.AddRange(lstParmeters[i].ToArray());
                    }
                    num += dbCommand.ExecuteNonQuery();
                    dbCommand.Parameters.Clear();
                }
            }
            catch (Exception ex)
            {
                if (dbtran != null)
                {
                    throw new Exception(sqlstr + "执行错误!" + ex);
                }
            }
            finally
            {
                if (dbtran != null)
                {
                    dbtran.DbTransaction.Dispose();
                    dbtran.DbConnection.Dispose();
                }
            }
            return(num);
        }
Exemplo n.º 13
0
 public void EndTransaction(DBtransaction dbtran)
 {
     dbtran.Dispose();
 }
Exemplo n.º 14
0
        public string BantchUpdate(List <T> tList, ref DBtransaction dbTran)
        {
            int num = EntityGenerics <DB, T> .Instance.BanthUpdate(tList);

            return((num > 0) ? "" : "批量更新失败");
        }
Exemplo n.º 15
0
        public string BantchUpdate(List <T> oldtList, List <T> tList, string userName, string changeBanth, ref DBtransaction dbTran)
        {
            int num = EntityGenerics <DB, T> .Instance.BanthUpdate(tList, dbTran);

            return((num > 0) ? "" : "批量更新失败");
        }
Exemplo n.º 16
0
 public int UpdateModel(IEntity iEntity, DBtransaction dbtran)
 {
     return(excuteImport.ExcuteNotQuery(iEntity.GetUpdatePlate(), iEntity.GetFullParameters(), dbtran));
 }
Exemplo n.º 17
0
        public string BantchDelete(List <T> tList, ref DBtransaction dbtran)
        {
            int num = EntityGenerics <DB, T> .Instance.BanthDelete(tList, dbtran);

            return((num > 0) ? "" : "批量删除失败");
        }
Exemplo n.º 18
0
 public int BantchSave(List <string> strList, List <List <DbParameter> > lstDbParmeter, DBtransaction dbtran)
 {
     return(excuteImport.ExcuteNotQuery(strList, lstDbParmeter, dbtran));
 }
Exemplo n.º 19
0
        public string DeleteModel(object primaryValue, ref DBtransaction dbtran)
        {
            int num = EntityGenerics <DB, T> .Instance.DeleteModel(primaryValue, dbtran);

            return((num > 0) ? "" : "删除失败");
        }
Exemplo n.º 20
0
        public string Delete(Collection <object> keys, ref DBtransaction dbtran)
        {
            int num = EntityGenerics <DB, T> .Instance.DeleteModel(keys, dbtran);

            return((num > 0) ? "" : "删除失败");
        }
Exemplo n.º 21
0
        public int ExcuteNotQuery(string sqlStr, IList <List <DbParameter> > lstParmeters, DBtransaction dbtran)
        {
            int num   = 0;
            int count = lstParmeters.Count;

            try
            {
                for (int i = 0; i < count; i++)
                {
                    DbCommand dbCommand = providerFactory.CreateCommand();
                    dbCommand.CommandText = sqlStr;
                    dbCommand.Connection  = dbtran.DbConnection;
                    dbCommand.CommandType = CommandType.Text;
                    dbCommand.Transaction = dbtran.DbTransaction;
                    if (lstParmeters[i] != null && lstParmeters[i].Count > 0)
                    {
                        dbCommand.Parameters.AddRange(lstParmeters[i].ToArray());
                    }
                    num += dbCommand.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("'" + sqlStr + "'" + "执行错误!" + ex);
            }
            finally {
                if (dbtran != null)
                {
                    dbtran.RollBack();
                }
            }
            return(num);
        }
Exemplo n.º 22
0
        public string UpdateModel(T newModel, ref DBtransaction dbtran)
        {
            int num = EntityGenerics <DB, T> .Instance.UpdateModel(newModel, dbtran);

            return((num > 0) ? "" : "更新失败");
        }
Exemplo n.º 23
0
        public string UpdateModel(T oldModel, T newModel, string userName, string changeBanth, ref DBtransaction dbtran)
        {
            int num = EntityGenerics <DB, T> .Instance.UpdateModel(newModel, dbtran);

            return((num > 0) ? "" : "更新失败");
        }
Exemplo n.º 24
0
        public string InsertModel(T model, ref DBtransaction dbtran)
        {
            int num = EntityGenerics <DB, T> .Instance.InsertModel(model, dbtran);

            return((num > 0) ? "" : "添加失败");
        }