コード例 #1
0
        /// <summary>
        /// 添加数据到数据库
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Insert(Model.SystemProfile model)
        {
            if (model == null)
            {
                return(-1);
            }

            //判断当前记录是否存在,如果存在则返回;
            if (IsExist(model.Title, ""))
            {
                return(110);
            }

            string cmdText = "insert into [SystemProfile] (NumberID,Title,ContentText,LastUpdatedDate) values (@NumberID,@Title,@ContentText,@LastUpdatedDate)";

            //创建查询命令参数集
            SqlParameter[] parms =
            {
                new SqlParameter("@NumberID",        SqlDbType.VarChar,  40),
                new SqlParameter("@Title",           SqlDbType.NVarChar, 50),
                new SqlParameter("@ContentText",     SqlDbType.NText),
                new SqlParameter("@LastUpdatedDate", SqlDbType.DateTime)
            };
            parms[0].Value = NumberID.GetNumberID();
            parms[1].Value = model.Title;
            parms[2].Value = model.ContentText;
            parms[3].Value = model.LastUpdatedDate;

            //执行数据库操作
            return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parms));
        }
コード例 #2
0
        public int Insert(Model.Category model)
        {
            if (model == null)
            {
                return(-1);
            }

            if (IsExist(model.CategoryName, model.ParentID, ""))
            {
                return(110);
            }

            //定义查询命令
            string cmdText = "insert into Category (NumberID,CategoryName,ParentID,Sort,Remark,Title,CreateDate) values (@NumberID,@CategoryName,@ParentID,@Sort,@Remark,@Title,@CreateDate)";

            //创建查询命令参数集
            SqlParameter[] parms =
            {
                new SqlParameter("@NumberID",     SqlDbType.VarChar,    50),
                new SqlParameter("@CategoryName", SqlDbType.NVarChar,  256),
                new SqlParameter("@ParentID",     SqlDbType.VarChar,    50),
                new SqlParameter("@Sort",         SqlDbType.Int),
                new SqlParameter("@Remark",       SqlDbType.NVarChar,  300),
                new SqlParameter("@CreateDate",   SqlDbType.DateTime),
                new SqlParameter("@Title",        SqlDbType.NVarChar,   20),
            };
            parms[0].Value = NumberID.GetNumberID("c");
            parms[1].Value = model.CategoryName;
            parms[2].Value = model.ParentID;
            parms[3].Value = model.Sort;
            parms[4].Value = model.Remark;
            parms[5].Value = model.CreateDate;
            parms[6].Value = model.Title;

            return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parms));
        }
コード例 #3
0
ファイル: Product.cs プロジェクト: qq283335746/TygaShop-Old
        /// <summary>
        /// 添加数据到数据库
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Insert(Model.Product model)
        {
            if (model == null)
            {
                return(-1);
            }

            //判断当前记录是否存在,如果存在则返回;
            if (IsExist(model.ProductName, model.CategoryId, ""))
            {
                return(110);
            }

            string productId = NumberID.GetNumberID();

            string cmdText1 = "insert into Product (ProductId,CategoryId,ProductName,Subtitle,ProductPrice,ImagesUrl,CreateDate,UserId) values (@ProductId,@CategoryId,@ProductName,@Subtitle,@ProductPrice,@ImagesUrl,@CreateDate,@UserId)";

            SqlParameter[] parms1 =
            {
                new SqlParameter("@ProductId",    SqlDbType.VarChar,    40),
                new SqlParameter("@CategoryId",   SqlDbType.VarChar,    40),
                new SqlParameter("@ProductName",  SqlDbType.NVarChar,  256),
                new SqlParameter("@Subtitle",     SqlDbType.NVarChar,  256),
                new SqlParameter("@ProductPrice", SqlDbType.Decimal),
                new SqlParameter("@ImagesUrl",    SqlDbType.NVarChar,  300),
                new SqlParameter("@CreateDate",   SqlDbType.DateTime),
                new SqlParameter("@UserId",       SqlDbType.UniqueIdentifier)
            };
            parms1[0].Value = productId;
            parms1[1].Value = model.CategoryId;
            parms1[2].Value = model.ProductName;
            parms1[3].Value = model.Subtitle;
            parms1[4].Value = model.ProductPrice;
            parms1[5].Value = model.ImagesUrl;
            parms1[6].Value = model.CreateDate;
            parms1[7].Value = Guid.Parse(model.UserId.ToString());

            string cmdText2 = "insert into ProductItem (ProductId,PNum,StockNum,ImagesAppend,MainImage,LImagesUrl,MImagesUrl,SImagesUrl,MarketPrice,PayOptions,ViewCount,CreateDate) values (@ProductId,@PNum,@StockNum,@ImagesAppend,@MainImage,@LImagesUrl,@MImagesUrl,@SImagesUrl,@MarketPrice,@PayOptions,@ViewCount,@CreateDate)";

            SqlParameter[] parms2 =
            {
                new SqlParameter("@ProductId",    SqlDbType.VarChar,    40),
                new SqlParameter("@PNum",         SqlDbType.VarChar,    30),
                new SqlParameter("@StockNum",     SqlDbType.Int),
                new SqlParameter("@LImagesUrl",   SqlDbType.NVarChar),
                new SqlParameter("@MImagesUrl",   SqlDbType.NVarChar),
                new SqlParameter("@SImagesUrl",   SqlDbType.NVarChar),
                new SqlParameter("@MarketPrice",  SqlDbType.Decimal),
                new SqlParameter("@PayOptions",   SqlDbType.NVarChar,  300),
                new SqlParameter("@ViewCount",    SqlDbType.Int),
                new SqlParameter("@CreateDate",   SqlDbType.DateTime),
                new SqlParameter("@ImagesAppend", SqlDbType.NVarChar),
                new SqlParameter("@MainImage",    SqlDbType.NVarChar),
            };
            parms2[0].Value  = productId;
            parms2[1].Value  = model.PNum;
            parms2[2].Value  = model.StockNum;
            parms2[3].Value  = model.LImagesUrl;
            parms2[4].Value  = model.MImagesUrl;
            parms2[5].Value  = model.SImagesUrl;
            parms2[6].Value  = model.MarketPrice;
            parms2[7].Value  = model.PayOptions;
            parms2[8].Value  = model.ViewCount;
            parms2[9].Value  = model.CreateDate;
            parms2[10].Value = model.ImagesAppend;
            parms2[11].Value = model.MainImage;

            string cmdText3 = "insert into ProductAttr (ProductId,CustomAttrs,Descr,CreateDate) values (@ProductId,@CustomAttrs,@Descr,@CreateDate)";

            SqlParameter[] parms3 =
            {
                new SqlParameter("@ProductId",   SqlDbType.VarChar,   40),
                new SqlParameter("@CustomAttrs", SqlDbType.NVarChar),
                new SqlParameter("@Descr",       SqlDbType.NText),
                new SqlParameter("@CreateDate",  SqlDbType.DateTime)
            };
            parms3[0].Value = productId;
            parms3[1].Value = model.CustomAttrs;
            parms3[2].Value = model.Descr;
            parms3[3].Value = model.CreateDate;

            using (SqlConnection conn = new SqlConnection(SqlHelper.SqlProviderConnString))
            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                using (SqlTransaction tran = conn.BeginTransaction())
                {
                    try
                    {
                        SqlHelper.ExecuteNonQuery(tran, CommandType.Text, cmdText1, parms1);
                        SqlHelper.ExecuteScalar(tran, CommandType.Text, cmdText2, parms2);
                        SqlHelper.ExecuteScalar(tran, CommandType.Text, cmdText3, parms3);

                        tran.Commit();
                        return(1);
                    }
                    catch
                    {
                        tran.Rollback();
                    }
                }
            }

            return(0);
        }