Exemplo n.º 1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Hownet.Model.BAS_PackUnit GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 CnName,EnName,JnName,EnNamePlural,EnShortName,EnShortNamePlural,IsValid,ID,IsEnd from BAS_PackUnit ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

            Hownet.Model.BAS_PackUnit model = new Hownet.Model.BAS_PackUnit();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                model.CnName            = ds.Tables[0].Rows[0]["CnName"].ToString();
                model.EnName            = ds.Tables[0].Rows[0]["EnName"].ToString();
                model.JnName            = ds.Tables[0].Rows[0]["JnName"].ToString();
                model.EnNamePlural      = ds.Tables[0].Rows[0]["EnNamePlural"].ToString();
                model.EnShortName       = ds.Tables[0].Rows[0]["EnShortName"].ToString();
                model.EnShortNamePlural = ds.Tables[0].Rows[0]["EnShortNamePlural"].ToString();
                if (ds.Tables[0].Rows[0]["IsValid"] != null && ds.Tables[0].Rows[0]["IsValid"].ToString() != "")
                {
                    if ((ds.Tables[0].Rows[0]["IsValid"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsValid"].ToString().ToLower() == "true"))
                    {
                        model.IsValid = true;
                    }
                    else
                    {
                        model.IsValid = false;
                    }
                }
                if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "")
                {
                    model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["IsEnd"] != null && ds.Tables[0].Rows[0]["IsEnd"].ToString() != "")
                {
                    model.IsEnd = int.Parse(ds.Tables[0].Rows[0]["IsEnd"].ToString());
                }
                model.A = 1;
                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Hownet.Model.BAS_PackUnit model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update BAS_PackUnit set ");
            strSql.Append("CnName=@CnName,");
            strSql.Append("EnName=@EnName,");
            strSql.Append("JnName=@JnName,");
            strSql.Append("EnNamePlural=@EnNamePlural,");
            strSql.Append("EnShortName=@EnShortName,");
            strSql.Append("EnShortNamePlural=@EnShortNamePlural,");
            strSql.Append("IsValid=@IsValid,");
            strSql.Append("IsEnd=@IsEnd");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CnName",            SqlDbType.VarChar, 100),
                new SqlParameter("@EnName",            SqlDbType.VarChar, 100),
                new SqlParameter("@JnName",            SqlDbType.VarChar, 100),
                new SqlParameter("@EnNamePlural",      SqlDbType.VarChar,  50),
                new SqlParameter("@EnShortName",       SqlDbType.VarChar,  50),
                new SqlParameter("@EnShortNamePlural", SqlDbType.VarChar,  50),
                new SqlParameter("@IsValid",           SqlDbType.Bit,       1),
                new SqlParameter("@IsEnd",             SqlDbType.Int,       4),
                new SqlParameter("@ID",                SqlDbType.Int, 4)
            };
            parameters[0].Value = model.CnName;
            parameters[1].Value = model.EnName;
            parameters[2].Value = model.JnName;
            parameters[3].Value = model.EnNamePlural;
            parameters[4].Value = model.EnShortName;
            parameters[5].Value = model.EnShortNamePlural;
            parameters[6].Value = model.IsValid;
            parameters[7].Value = model.IsEnd;
            parameters[8].Value = model.ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Hownet.Model.BAS_PackUnit model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into BAS_PackUnit(");
            strSql.Append("CnName,EnName,JnName,EnNamePlural,EnShortName,EnShortNamePlural,IsValid,IsEnd)");
            strSql.Append(" values (");
            strSql.Append("@CnName,@EnName,@JnName,@EnNamePlural,@EnShortName,@EnShortNamePlural,@IsValid,@IsEnd)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CnName",            SqlDbType.VarChar, 100),
                new SqlParameter("@EnName",            SqlDbType.VarChar, 100),
                new SqlParameter("@JnName",            SqlDbType.VarChar, 100),
                new SqlParameter("@EnNamePlural",      SqlDbType.VarChar,  50),
                new SqlParameter("@EnShortName",       SqlDbType.VarChar,  50),
                new SqlParameter("@EnShortNamePlural", SqlDbType.VarChar,  50),
                new SqlParameter("@IsValid",           SqlDbType.Bit,       1),
                new SqlParameter("@IsEnd",             SqlDbType.Int, 4)
            };
            parameters[0].Value = model.CnName;
            parameters[1].Value = model.EnName;
            parameters[2].Value = model.JnName;
            parameters[3].Value = model.EnNamePlural;
            parameters[4].Value = model.EnShortName;
            parameters[5].Value = model.EnShortNamePlural;
            parameters[6].Value = model.IsValid;
            parameters[7].Value = model.IsEnd;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }