Example #1
0
        public AddStocks(ItemsDto item)
        {
            //初期化
            InitializeComponent();

            this.item = item;
        }
Example #2
0
        public List <ItemsDto> SearchItemsList(string searchItemName)
        {
            access.DbConnect();


            SqlCommand command = new SqlCommand();



            //パラメータ設定
            command.Parameters.Add("@itemName", SqlDbType.NVarChar, 50);
            command.Parameters["@itemName"].Value = "%" + searchItemName + "%";


            command.CommandText = $"SELECT * FROM Items " +
                                  $"INNER JOIN Stocks ON Items.itemId = Stocks.itemId " +
                                  $"WHERE itemName LIKE @itemName ";


            command.Connection = access.Connection;


            //クエリの実行
            SqlDataReader reader;

            reader = command.ExecuteReader();
            List <ItemsDto> list = new List <ItemsDto>();

            //値の取得
            while (reader.Read())
            {
                string itemIdStr = reader["itemId"].ToString();
                string itemName  = reader["itemName"].ToString();
                string priceStr  = reader["price"].ToString();
                string stockStr  = reader["stock"].ToString();

                int      itemId   = Convert.ToInt32(itemIdStr);
                int      price    = Convert.ToInt32(priceStr);
                int      stock    = Convert.ToInt32(stockStr);
                ItemsDto itemsDto = new ItemsDto(itemId, itemName, price, stock);
                list.Add(itemsDto);
            }

            access.DbClose();

            return(list);
        }
Example #3
0
        private void orderButton_Click(object sender, EventArgs e)
        {
            //注文を押したとき
            //選択されたインデックス

            int num = searchResult.SelectedIndex;



            //選択されている場合
            if (num != -1)
            {
                if (itemsList[num].Stock == 0)
                {
                    resultText.Visible = true;
                    resultText.Text    = MessageHolder.EM3;
                    return;
                }
                item = new ItemsDto(itemsList[num].ItemId, itemsList[num].ItemName,
                                    itemsList[num].Price, itemsList[num].Stock);
                //フォーム呼び出す
                Order order = new Order(item);


                //OKで返ってきたら
                if (order.ShowDialog(this) == DialogResult.OK)
                {
                    searchResult.Items.Clear();
                    resultText.Visible = true;
                    resultText.Text    = MessageHolder.PM1;
                    ItemsDao items = new ItemsDao();
                    itemsList = items.query();
                    for (int i = 0; i < itemsList.Count; i++)
                    {
                        //リストに追加
                        searchResult.Items.Add("商品名:" + itemsList[i].ItemName + " 価格:" + itemsList[i].Price + " 在庫:" + itemsList[i].Stock);
                    }
                }
            }
            else//選択されていない場合
            {
                resultText.Visible = true;
                resultText.Text    = MessageHolder.PM4;
            }
        }
Example #4
0
        public List <ItemsDto> query()
        {
            access.DbConnect();


            SqlCommand command = new SqlCommand();


            command.CommandText = $"SELECT * FROM Items " +
                                  $"INNER JOIN Stocks ON Items.itemId = Stocks.itemId ";


            command.Connection = access.Connection;


            //クエリの実行
            SqlDataReader reader;

            reader = command.ExecuteReader();
            List <ItemsDto> list = new List <ItemsDto>();

            //値の取得
            while (reader.Read())
            {
                string itemIdStr = reader["itemId"].ToString();
                string itemName  = reader["itemName"].ToString();
                string priceStr  = reader["price"].ToString();
                string stockStr  = reader["stock"].ToString();

                int      itemId   = Convert.ToInt32(itemIdStr);
                int      price    = Convert.ToInt32(priceStr);
                int      stock    = Convert.ToInt32(stockStr);
                ItemsDto itemsDto = new ItemsDto(itemId, itemName, price, stock);
                list.Add(itemsDto);
            }

            access.DbClose();

            return(list);
        }
Example #5
0
        private void addStockButton_Click(object sender, EventArgs e)
        {
            //在庫追加を押したとき
            //選択されたインデックス
            int num = searchResult.SelectedIndex;


            if (num != -1)
            {
                item = new ItemsDto(itemsList[num].ItemId, itemsList[num].ItemName,
                                    itemsList[num].Price, itemsList[num].Stock);
                //フォーム呼び出す
                AddStocks addStocks = new AddStocks(item);


                //OKで返ってきたら
                if (addStocks.ShowDialog(this) == DialogResult.OK)
                {
                    searchResult.Items.Clear();
                    resultText.Visible = true;
                    resultText.Text    = MessageHolder.PM2;
                    ItemsDao items = new ItemsDao();
                    itemsList = items.query();
                    for (int i = 0; i < itemsList.Count; i++)
                    {
                        //リストに追加
                        searchResult.Items.Add("商品名:" + itemsList[i].ItemName + " 価格:" + itemsList[i].Price + " 在庫:" + itemsList[i].Stock);
                    }
                }
                else
                {
                    resultText.Visible = true;
                    resultText.Text    = MessageHolder.PM4;
                }
            }
        }
Example #6
0
 public Order(ItemsDto item)
 {
     //初期化
     InitializeComponent();
     this.item = item;
 }