Ejemplo n.º 1
0
        /// <summary>
        ///Save,保存方法,先删除,再增加
        /// </summary>
        public void Save(t_server model, SqlTransaction tran = null, params string[] str)
        {
            string        tran_flag = "1";
            SqlConnection conn      = new SqlConnection(Dal.DataHelper.constr);

            conn.Open();
            if (tran == null)
            {
                tran_flag = "0";
                tran      = conn.BeginTransaction();
            }
            try
            {
                Delete(model, tran, str);
                Add(model, tran);

                //如果传入事物,提交否则外层提交
                if (tran_flag == "0")
                {
                    tran.Commit();
                    conn.Close();
                }
            }
            catch (Exception e)
            {
                if (tran_flag == "0")
                {
                    tran.Rollback();
                    conn.Close();
                }
                throw e;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public override void Add(dynamic obj, SqlTransaction tran = null)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into t_server(");
            strSql.Append("cdef2,cdef3,cdef4,cdef5,cdef6,cdef7,cdef8,cdef9,cdef10,ip,accout,username,pwd,memo,zdr,zdrq,cdef1");
            strSql.Append(") values (");
            strSql.Append("@cdef2,@cdef3,@cdef4,@cdef5,@cdef6,@cdef7,@cdef8,@cdef9,@cdef10,@ip,@accout,@username,@pwd,@memo,@zdr,@zdrq,@cdef1");
            strSql.Append(") ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@cdef2",    SqlDbType.VarChar,   50),
                new SqlParameter("@cdef3",    SqlDbType.VarChar,   50),
                new SqlParameter("@cdef4",    SqlDbType.VarChar,   50),
                new SqlParameter("@cdef5",    SqlDbType.VarChar,   50),
                new SqlParameter("@cdef6",    SqlDbType.VarChar,  100),
                new SqlParameter("@cdef7",    SqlDbType.VarChar,  100),
                new SqlParameter("@cdef8",    SqlDbType.VarChar,  100),
                new SqlParameter("@cdef9",    SqlDbType.VarChar,  100),
                new SqlParameter("@cdef10",   SqlDbType.VarChar,  100),
                new SqlParameter("@ip",       SqlDbType.VarChar,  100),
                new SqlParameter("@accout",   SqlDbType.VarChar,  100),
                new SqlParameter("@username", SqlDbType.VarChar,  100),
                new SqlParameter("@pwd",      SqlDbType.VarChar,  100),
                new SqlParameter("@memo",     SqlDbType.VarChar, 1000),
                new SqlParameter("@zdr",      SqlDbType.VarChar,  100),
                new SqlParameter("@zdrq",     SqlDbType.VarChar,  100),
                new SqlParameter("@cdef1",    SqlDbType.VarChar, 50)
            };
            t_server model = (t_server)obj;

            parameters[0].Value  = SqlNull(model.cdef2);
            parameters[1].Value  = SqlNull(model.cdef3);
            parameters[2].Value  = SqlNull(model.cdef4);
            parameters[3].Value  = SqlNull(model.cdef5);
            parameters[4].Value  = SqlNull(model.cdef6);
            parameters[5].Value  = SqlNull(model.cdef7);
            parameters[6].Value  = SqlNull(model.cdef8);
            parameters[7].Value  = SqlNull(model.cdef9);
            parameters[8].Value  = SqlNull(model.cdef10);
            parameters[9].Value  = SqlNull(model.ip);
            parameters[10].Value = SqlNull(model.accout);
            parameters[11].Value = SqlNull(model.username);
            parameters[12].Value = SqlNull(model.pwd);
            parameters[13].Value = SqlNull(model.memo);
            parameters[14].Value = SqlNull(model.zdr);
            parameters[15].Value = SqlNull(model.zdrq);
            parameters[16].Value = SqlNull(model.cdef1);
            if (tran == null)
            {
                DataHelper.ExcuteNonQuery(strSql.ToString(), parameters, false);
            }
            else
            {
                DataHelper.ExcuteNonQuery(strSql.ToString(), tran, parameters, false);
            }
        }