/// <summary> /// 店選択リストで選択が変更されアタ時の処理を行う。 /// </summary> /// <param name="sender">送信元オブジェクト</param> /// <param name="e">イベントオブジェクト</param> private void OnDataGridViewShopsSelectionChanged(object sender, EventArgs e) { DataShop shop = GetSelectedShop(); if (shop == null) { textBoxShopName.Text = string.Empty; numericUpDownShopLevel.Value = 1; numericUpDownBuyingPriceRate.Value = 100; numericUpDownSellingPriceRate.Value = 50; ((DataTable)(dataGridViewShops.DataSource)).Rows.Clear(); } else { textBoxShopName.Text = shop.Name; int level = shop.Level; numericUpDownShopLevel.Value = Math.Max(1, Math.Min(99, level)); int buyingPriceRate = (int)(shop.BuyingPriceRate * 100); numericUpDownBuyingPriceRate.Value = Math.Max(1, Math.Min(10000, buyingPriceRate)); int sellingPriceRate = (int)(shop.SellingPriceRate * 100); numericUpDownSellingPriceRate.Value = Math.Max(1, Math.Min(10000, sellingPriceRate)); UpdateDataGridViewItems(); } textBoxShopName.Enabled = (shop != null); numericUpDownShopLevel.Enabled = (shop != null); numericUpDownBuyingPriceRate.Enabled = (shop != null); numericUpDownSellingPriceRate.Enabled = (shop != null); dataGridViewShops.Enabled = (shop != null); buttonAddItem.Enabled = (shop != null); }
/// <summary> /// レベル入力欄の数値が変更されたときに通知を受け取る。 /// </summary> /// <param name="sender">送信元オブジェクト</param> /// <param name="e">イベントオブジェクト</param> private void OnNumericUpDownShopLevelValueChanged(object sender, EventArgs e) { DataShop shop = GetSelectedShop(); if (shop == null) { return; } int level = (int)(numericUpDownShopLevel.Value); shop.Level = Math.Max(1, Math.Min(99, level)); }
/// <summary> /// アイテム一覧データグリッドビューのコンテンツを更新する。 /// </summary> private void UpdateDataGridViewItems() { DataShop shop = GetSelectedShop(); DataTable dt = (DataTable)(dataGridViewItems.DataSource); dt.Rows.Clear(); if (shop != null) { for (int i = 0; i < shop.ItemList.Count; i++) { var itemEntry = shop.ItemList[i]; var row = dt.NewRow(); SetRowData(row, itemEntry); dt.Rows.Add(row); } } }
/// <summary> /// ショップ名テキストボックスの内容が変更されたときに通知を受け取る。 /// </summary> /// <param name="sender">送信元オブジェクト</param> /// <param name="e">イベントオブジェクト</param> private void OnTextBoxShopNameTextChanged(object sender, EventArgs e) { DataShop shop = GetSelectedShop(); if (shop == null) { return; } shop.Name = textBoxShopName.Text; var rows = dataGridViewShops.SelectedRows; int index = rows[0].Index; DataTable dt = (DataTable)(dataGridViewShops.DataSource); var row = dt.Rows[index]; row.SetField(0, string.Format("{0,4:D}:{1}", shop.Id, shop.Name)); }
/// <summary> /// 販売レートが変更されたときに通知を受け取る。 /// </summary> /// <param name="sender">送信元オブジェクト</param> /// <param name="e">イベントオブジェクト</param> private void OnNumericUpDownPriceRateChanged(object sender, EventArgs e) { DataShop shop = GetSelectedShop(); if (shop == null) { return; } double rate = (int)(((NumericUpDown)(sender)).Value) * 0.01; if (sender == numericUpDownBuyingPriceRate) { shop.BuyingPriceRate = rate; } else if (sender == numericUpDownSellingPriceRate) { shop.SellingPriceRate = rate; } }
/// <summary> /// アイテムが選択された時に通知を受け取る。 /// </summary> /// <param name="sender">送信元オブジェクト</param> /// <param name="e">イベントオブジェクト</param> private void OnItemListItemSelected(object sender, EventArgs e) { IItem item = itemListForm.SelectedItem; DataShop shop = GetSelectedShop(); if (shop == null) { return; } ItemEntry itemEntry = new ItemEntry(); itemEntry.Id = item.Id; itemEntry.Kind = GetItemKind(item); itemEntry.MinCount = 0; itemEntry.MaxCount = 1; shop.ItemList.Add(itemEntry); DataTable dt = (DataTable)(dataGridViewItems.DataSource); var row = dt.NewRow(); SetRowData(row, itemEntry); dt.Rows.Add(row); }
/// <summary> /// セルの値が変更されたときの処理を行う。 /// </summary> /// <param name="sender">送信元オブジェクト</param> /// <param name="e">イベントオブジェクト</param> private void OnDataGridViewCellValueChanged(object sender, DataGridViewCellEventArgs e) { try { DataShop shop = GetSelectedShop(); if (shop == null) { return; } DataTable dt = (DataTable)(dataGridViewItems.DataSource); ItemEntry entry = shop.ItemList[e.RowIndex]; DataRow row = dt.Rows[e.RowIndex]; switch (e.ColumnIndex) { case 1: if (DBNull.Value.Equals(row[1])) { row[1] = entry.MinCount; } else { entry.MinCount = (int)(row[1]); } break; case 2: if (DBNull.Value.Equals(row[2])) { row[2] = entry.MaxCount; } else { entry.MaxCount = (int)(row[2]); } break; case 3: if (DBNull.Value.Equals(row[3])) { row[3] = entry.BuyingPrice; } else { entry.BuyingPrice = (int)(row[3]); } break; case 4: if (DBNull.Value.Equals(row[4])) { row[4] = entry.SellingPrice; } else { entry.SellingPrice = (int)(row[4]); } break; case 5: entry.Condition = row.Field <string>(5) ?? string.Empty; break; } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error"); } }