Esempio n. 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddM_StockInfo(M_StockInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tb_M_StockInfo(");
            strSql.Append("m_ConfigInfoID,ProductsID,m_Num,m_UpdateTime,StorageID)");
            strSql.Append(" values (");
            strSql.Append("@m_ConfigInfoID,@ProductsID,@m_Num,@m_UpdateTime,@StorageID)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@m_ConfigInfoID", SqlDbType.Int,       4),
                new SqlParameter("@ProductsID",     SqlDbType.Int,       4),
                new SqlParameter("@m_Num",          SqlDbType.Int,       4),
                new SqlParameter("@m_UpdateTime",   SqlDbType.DateTime),
                new SqlParameter("@StorageID",      SqlDbType.Int,       4),
            };
            parameters[0].Value = model.m_ConfigInfoID;
            parameters[1].Value = model.ProductsID;
            parameters[2].Value = model.m_Num;
            parameters[3].Value = model.m_UpdateTime;
            parameters[4].Value = model.StorageID;

            object obj = DbHelper.ExecuteScalar(CommandType.Text, strSql.ToString(), parameters);

            if (obj == null)
            {
                return(-1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void UpdateM_StockInfo(M_StockInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tb_M_StockInfo set ");
            strSql.Append("m_ConfigInfoID=@m_ConfigInfoID,");
            strSql.Append("ProductsID=@ProductsID,");
            strSql.Append("m_Num=@m_Num,");
            strSql.Append("m_UpdateTime=@m_UpdateTime,");
            strSql.Append("StorageID=@StorageID");
            strSql.Append(" where m_StockInfoID=@m_StockInfoID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@m_StockInfoID",  SqlDbType.Int,       4),
                new SqlParameter("@m_ConfigInfoID", SqlDbType.Int,       4),
                new SqlParameter("@ProductsID",     SqlDbType.Int,       4),
                new SqlParameter("@m_Num",          SqlDbType.Int,       4),
                new SqlParameter("@m_UpdateTime",   SqlDbType.DateTime),
                new SqlParameter("@StorageID",      SqlDbType.Int,       4),
            };
            parameters[0].Value = model.m_StockInfoID;
            parameters[1].Value = model.m_ConfigInfoID;
            parameters[2].Value = model.ProductsID;
            parameters[3].Value = model.m_Num;
            parameters[4].Value = model.m_UpdateTime;
            parameters[5].Value = model.StorageID;

            DbHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters);
        }
Esempio n. 3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public M_StockInfo GetM_StockInfoModel(int m_StockInfoID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 m_StockInfoID,m_ConfigInfoID,ProductsID,m_Num,m_UpdateTime,StorageID,(select sname from tbStorageInfo where StorageID=tb_M_StockInfo.StorageID) as StorageName from tb_M_StockInfo ");
            strSql.Append(" where m_StockInfoID=@m_StockInfoID ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@m_StockInfoID", SqlDbType.Int, 4)
            };
            parameters[0].Value = m_StockInfoID;

            M_StockInfo model = new M_StockInfo();
            DataSet     ds    = DbHelper.ExecuteDataset(CommandType.Text, strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["m_StockInfoID"].ToString() != "")
                {
                    model.m_StockInfoID = int.Parse(ds.Tables[0].Rows[0]["m_StockInfoID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["m_ConfigInfoID"].ToString() != "")
                {
                    model.m_ConfigInfoID = int.Parse(ds.Tables[0].Rows[0]["m_ConfigInfoID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["ProductsID"].ToString() != "")
                {
                    model.ProductsID = int.Parse(ds.Tables[0].Rows[0]["ProductsID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["m_Num"].ToString() != "")
                {
                    model.m_Num = int.Parse(ds.Tables[0].Rows[0]["m_Num"].ToString());
                }
                if (ds.Tables[0].Rows[0]["m_UpdateTime"].ToString() != "")
                {
                    model.m_UpdateTime = DateTime.Parse(ds.Tables[0].Rows[0]["m_UpdateTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["StorageID"].ToString() != "")
                {
                    model.StorageID = int.Parse(ds.Tables[0].Rows[0]["StorageID"].ToString());
                }
                model.StorageName = ds.Tables[0].Rows[0]["StorageName"].ToString();
                return(model);
            }
            else
            {
                return(null);
            }
        }