using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using Forks.Utils.IO;
|
|
|
|
namespace B3ButcherWeightClient {
|
|
public partial class Livestock : Form {
|
|
public class Info {
|
|
public long ID { get; set; }
|
|
public string 名称 { get; set; }
|
|
}
|
|
|
|
readonly IList<Info> _dTable = new List<Info>();
|
|
|
|
public Livestock() {
|
|
InitializeComponent();
|
|
ConfigUtil.SetLivestock(_dTable);
|
|
dataGridView1.DataSource = _dTable;
|
|
}
|
|
|
|
private void textBox2_TextChanged(object sender, EventArgs e) {
|
|
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e) {
|
|
var item = new Info();
|
|
var id = long.Parse(textBox1.Text);
|
|
item.ID = id;
|
|
item.名称 = textBox2.Text;
|
|
_dTable.Add(item);
|
|
dataGridView1.DataSource = null;
|
|
dataGridView1.DataSource = _dTable;
|
|
}
|
|
|
|
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) {
|
|
var data = (IList<Info>)dataGridView1.DataSource;
|
|
|
|
if (Column3.Index == e.ColumnIndex) {
|
|
DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
|
|
var info = row.DataBoundItem as Info;
|
|
if (info != null)
|
|
data.Remove(info);
|
|
dataGridView1.DataSource = null;
|
|
dataGridView1.DataSource = data;
|
|
}
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e) {
|
|
var str = new StringBuilder();
|
|
foreach (DataGridViewRow row in dataGridView1.Rows) {
|
|
var info = row.DataBoundItem as Info;
|
|
if (info != null) {
|
|
str.AppendFormat("{0}|{1},", info.ID, info.名称);
|
|
}
|
|
}
|
|
using (TextReader reader = FS.OpenReader(ConfigUtil.LivestockFilePath, true)) {
|
|
var nutFile = NutFile.Parse(reader);
|
|
nutFile.SetValue("ITEM", str.ToString());
|
|
|
|
using (TextWriter writer = FS.OpenWriter(ConfigUtil.LivestockFilePath, createDirsIfNotExist: true)) {
|
|
nutFile.Write(writer);
|
|
}
|
|
}
|
|
Dispose();
|
|
}
|
|
}
|
|
}
|