コード例 #1
0
        public static void Remove(ProductItem ProductItem)
        {
            //更新資料庫
            ProductItemAccessor.Delete(ProductItem);

            //更新記憶体
            ProductItemCache.Remove(ProductItem);
        }
コード例 #2
0
        internal static void UpdateInsert(ProductItem ProductItem)
        {
            using (SqlConnection SqlConnection = ConnectionManager.GetConnection())
            {
                using (SqlCommand SqlCommand = SqlConnection.CreateCommand())
                {
                    SqlCommand.CommandText = "UPDATE "
                                             + " Product_ProductItem "
                                             + "SET "
                                             + " Name = @Name "
                                             + " ,Tags = @Tags "
                                             + " ,OriginalPrice = @OriginalPrice "
                                             + " ,Discount = @Discount "
                                             + " ,SalePrice = @SalePrice "
                                             + " ,Inventory = @Inventory "
                                             + " ,Sort = @Sort "
                                             + " ,UpdateTime = @UpdateTime "
                                             + " ,CreateTime = @CreateTime "
                                             + "WHERE "
                                             + " Id = @Id "

                                             + "IF @@ROWCOUNT = 0 "
                                             + "BEGIN "

                                             + "INSERT INTO "
                                             + " Product_ProductItem "
                                             + "( Id, Name, Tags, OriginalPrice, Discount, SalePrice, Inventory, Sort, UpdateTime, CreateTime ) "
                                             + "VALUES "
                                             + "( @Id, @Name, @Tags, @OriginalPrice, @Discount, @SalePrice, @Inventory, @Sort, @UpdateTime, @CreateTime ) "
                                             + "END ";

                    SqlCommand.Parameters.AddWithValue("Id", ProductItem.Id);
                    SqlCommand.Parameters.AddWithValue("Name", ProductItem.Name);
                    SqlCommand.Parameters.AddWithValue("Tags", string.Join(",", ProductItem.Tags.Select(t => t.Replace(",", "�A"))));
                    SqlCommand.Parameters.AddWithValue("OriginalPrice", ProductItem.OriginalPrice);
                    SqlCommand.Parameters.AddWithValue("Discount", ProductItem.Discount);
                    SqlCommand.Parameters.AddWithValue("SalePrice", ProductItem.SalePrice);
                    SqlCommand.Parameters.AddWithValue("Inventory", ProductItem.Inventory);
                    SqlCommand.Parameters.AddWithValue("Sort", ProductItem.Sort);
                    SqlCommand.Parameters.AddWithValue("UpdateTime", ProductItem.UpdateTime);
                    SqlCommand.Parameters.AddWithValue("CreateTime", ProductItem.CreateTime);

                    SqlConnection.Open();
                    SqlCommand.ExecuteNonQuery();
                }
            }
        }
コード例 #3
0
        internal static void Delete(ProductItem ProductItem)
        {
            using (SqlConnection SqlConnection = ConnectionManager.GetConnection())
            {
                using (SqlCommand SqlCommand = SqlConnection.CreateCommand())
                {
                    SqlCommand.CommandText = "Delete "
                                           + " Product_ProductItem "
                                           + "WHERE "
                                           + " Id = @Id ";

                    SqlCommand.Parameters.AddWithValue("Id", ProductItem.Id);

                    SqlConnection.Open();
                    SqlCommand.ExecuteNonQuery();
                }
            }
        }
コード例 #4
0
 public static void Save(ProductItem ProductItem)
 {
     Save(new List<ProductItem>() { ProductItem });
 }
コード例 #5
0
        private static List<ProductItem> Get(SqlCommand SqlCommand)
        {
            List<ProductItem> ProductItems = new List<ProductItem>();

            using (SqlConnection SqlConnection = ConnectionManager.GetConnection())
            {
                using (SqlCommand.Connection = SqlConnection)
                {
                    SqlConnection.Open();

                    SqlDataReader SqlDataReader = SqlCommand.ExecuteReader();

                    while (SqlDataReader.Read())
                    {
                        string Id = (string)SqlDataReader["Id"];
                        string Name = (string)SqlDataReader["Name"];
                        List<string> Tags = SqlDataReader["Tags"].ToString().Split(',').ToList();
                        string OriginalPrice = (string)SqlDataReader["OriginalPrice"];
                        string Discount = (string)SqlDataReader["Discount"];
                        decimal SalePrice = (decimal)SqlDataReader["SalePrice"];
                        int Inventory = (int)SqlDataReader["Inventory"];
                        int Sort = (int)SqlDataReader["Sort"];
                        DateTime UpdateTime = (DateTime)SqlDataReader["UpdateTime"];
                        DateTime CreateTime = (DateTime)SqlDataReader["CreateTime"];

                        ProductItem ProductItem = new ProductItem(Id, Name, Tags, OriginalPrice, Discount, SalePrice, Inventory, Sort, UpdateTime, CreateTime);
                        ProductItems.Add(ProductItem);
                    }
                }
            }

            return ProductItems;
        }