|
|
using System;
|
|
|
using System.IO;
|
|
|
using System.Windows.Forms;
|
|
|
using BO;
|
|
|
using Forks.Utils.IO;
|
|
|
|
|
|
namespace B3ButcherWeightClient {
|
|
|
public partial class Setting : Form {
|
|
|
public Setting() {
|
|
|
InitializeComponent();
|
|
|
typeComboBox.Items.Add("");
|
|
|
typeComboBox.Items.Add("IND560");
|
|
|
typeComboBox.Items.Add("Xk3124");
|
|
|
typeComboBox.Items.Add("XK3130");
|
|
|
typeComboBox.Items.Add("Xk3190A9");
|
|
|
|
|
|
SetConfigControl();
|
|
|
}
|
|
|
|
|
|
// 取得设置的值
|
|
|
private void SetConfigControl() {
|
|
|
|
|
|
using (var reader = FS.OpenReader(ConfigUtil.ConfigFilePath, true)) {
|
|
|
var nutFile = NutFile.Parse(reader);
|
|
|
var ctype = nutFile.AsString(ConfigItem.CType, "");
|
|
|
typeComboBox.SelectedItem = ctype;
|
|
|
txtBComName.Text = nutFile.AsString(ConfigItem.ComName, "COM1");
|
|
|
txtBaudRate.Text = nutFile.AsString(ConfigItem.BaundRate, "9600");
|
|
|
txtDataBits.Text = nutFile.AsString(ConfigItem.DataBits, "8");
|
|
|
txtBServerName.Text = nutFile.AsString(ConfigItem.Server, "");
|
|
|
txtBoxDataBase.Text = nutFile.AsString(ConfigItem.Database, "");
|
|
|
txtBoxUserName.Text = nutFile.AsString(ConfigItem.UserName, "");
|
|
|
textBoxPassword.Text = EncodeString.Encode(nutFile.AsString(ConfigItem.Password, ""));
|
|
|
cbxAllowChangeLevel.Checked = nutFile.AsBool(ConfigItem.AllowChangeLevel, false);
|
|
|
txtPerDayStartHour.Text = nutFile.AsInt32(ConfigItem.PerDayStartHour, 0).ToString();
|
|
|
textBox1.Text = nutFile.AsString(ConfigItem.RemoteServer, "");
|
|
|
textBox3.Text = nutFile.AsString(ConfigItem.RemoteDatabase, "");
|
|
|
textBox2.Text = nutFile.AsString(ConfigItem.RemoteUserName, "");
|
|
|
textBox4.Text = EncodeString.Encode(nutFile.AsString(ConfigItem.RemotePassword, ""));
|
|
|
minTextBox.Text = nutFile.AsString(ConfigItem.MinWeight, "25");
|
|
|
maxTextBox.Text = nutFile.AsString(ConfigItem.MaxWeight, "300");
|
|
|
var readType = nutFile.AsString(ConfigItem.ReadType, "");
|
|
|
if (readType == "0") {
|
|
|
radioButton1.Checked = true;
|
|
|
} else if (readType == "1") {
|
|
|
radioButton2.Checked = true;
|
|
|
}
|
|
|
urlTextBox.Text = nutFile.AsString(ConfigItem.Url, "http://");
|
|
|
subWeightSettingTextBox.Text = nutFile.AsString(ConfigItem.SubWeight, "0");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void button1_Click(object sender, EventArgs e) {
|
|
|
var database = txtBoxDataBase.Text.Trim();
|
|
|
string conStr;
|
|
|
if (!TryGetConnectStr(database, out conStr))
|
|
|
return;
|
|
|
try {
|
|
|
conStr = UpdateDb.CreateTables(conStr, database);
|
|
|
UpdateDb.UpdateTables(conStr);
|
|
|
MessageBox.Show(@"升级成功!");
|
|
|
} catch (Exception ex) {
|
|
|
MessageBox.Show(string.Format("升级失败!{0}", ex.Message));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private bool TryGetConnectStr(string database, out string conStr) {
|
|
|
var server = txtBServerName.Text.Trim();
|
|
|
var user = txtBoxUserName.Text.Trim();
|
|
|
var password = textBoxPassword.Text.Trim();
|
|
|
conStr = string.Format("Server={0};Database={1};User ID={2};Password={3};", server, "master", user, password);
|
|
|
if (string.IsNullOrEmpty(server) || string.IsNullOrEmpty(database) || string.IsNullOrEmpty(user) || string.IsNullOrEmpty(password)) {
|
|
|
MessageBox.Show(@"请输入服务器名,数据库名,用户名,密码");
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
private void btnClose_Click(object sender, EventArgs e) {
|
|
|
Dispose();
|
|
|
}
|
|
|
|
|
|
private void button2_Click(object sender, EventArgs e) {
|
|
|
var database = textBox3.Text.Trim();
|
|
|
string conStr;
|
|
|
if (!TryGetConnectStrSvr(database, out conStr))
|
|
|
return;
|
|
|
try {
|
|
|
conStr = UpdateDb.CreateTables(conStr, database);
|
|
|
UpdateDb.UpdateTables(conStr);
|
|
|
MessageBox.Show(@"升级成功!");
|
|
|
} catch (Exception ex) {
|
|
|
MessageBox.Show(string.Format("升级失败!{0}", ex.Message));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private bool TryGetConnectStrSvr(string database, out string conStr) {
|
|
|
var server = textBox1.Text.Trim();
|
|
|
var user = textBox2.Text.Trim();
|
|
|
var password = textBox4.Text.Trim();
|
|
|
conStr = string.Format("Server={0};Database={1};User ID={2};Password={3};", server, "master", user, password);
|
|
|
if (string.IsNullOrEmpty(server) || string.IsNullOrEmpty(database) || string.IsNullOrEmpty(user) || string.IsNullOrEmpty(password)) {
|
|
|
MessageBox.Show(@"请输入服务器名,数据库名,用户名,密码");
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
private void btnSave_Click(object sender, EventArgs e) {
|
|
|
using (TextReader reader = FS.OpenReader(ConfigUtil.ConfigFilePath, true)) {
|
|
|
var nutFile = NutFile.Parse(reader);
|
|
|
nutFile.SetValue(ConfigItem.CType, (string)typeComboBox.SelectedItem);
|
|
|
nutFile.SetValue(ConfigItem.ComName, txtBComName.Text.Trim());
|
|
|
nutFile.SetValue(ConfigItem.BaundRate, txtBaudRate.Text.Trim());
|
|
|
nutFile.SetValue(ConfigItem.DataBits, txtDataBits.Text.Trim());
|
|
|
nutFile.SetValue(ConfigItem.Server, txtBServerName.Text.Trim());
|
|
|
nutFile.SetValue(ConfigItem.Database, txtBoxDataBase.Text.Trim());
|
|
|
nutFile.SetValue(ConfigItem.UserName, txtBoxUserName.Text.Trim());
|
|
|
nutFile.SetValue(ConfigItem.Password, EncodeString.Encode(textBoxPassword.Text.Trim()));
|
|
|
nutFile.SetValue(ConfigItem.AllowChangeLevel, cbxAllowChangeLevel.Checked);
|
|
|
nutFile.SetValue(ConfigItem.PerDayStartHour, Convert.ToInt32(txtPerDayStartHour.Text.Trim()));
|
|
|
nutFile.SetValue(ConfigItem.RemoteServer, textBox1.Text.Trim());
|
|
|
nutFile.SetValue(ConfigItem.RemoteDatabase, textBox3.Text.Trim());
|
|
|
nutFile.SetValue(ConfigItem.RemoteUserName, textBox2.Text.Trim());
|
|
|
nutFile.SetValue(ConfigItem.RemotePassword, EncodeString.Encode(textBox4.Text.Trim()));
|
|
|
nutFile.SetValue(ConfigItem.MinWeight, minTextBox.Text.Trim());
|
|
|
nutFile.SetValue(ConfigItem.MaxWeight, maxTextBox.Text.Trim());
|
|
|
string readType = "0";
|
|
|
if (radioButton2.Checked) {
|
|
|
readType = "1";
|
|
|
}
|
|
|
nutFile.SetValue(ConfigItem.ReadType, readType);
|
|
|
|
|
|
nutFile.SetValue(ConfigItem.SubWeight, subWeightSettingTextBox.Text.Trim());
|
|
|
nutFile.SetValue(ConfigItem.Url, urlTextBox.Text.Trim());
|
|
|
using (TextWriter writer = FS.OpenWriter(ConfigUtil.ConfigFilePath, createDirsIfNotExist: true)) {
|
|
|
nutFile.Write(writer);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
MessageBox.Show("设置保存成功!");
|
|
|
}
|
|
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
var form = new Livestock();
|
|
|
form.Show();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|