屠宰场客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.3 KiB

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BO.Utils;
using Forks.EnterpriseServices.DomainObjects2;
using Forks.JsonRpc.Client;
using Forks.Utils;
using Forks.Utils.Data;
using TSingSoft.WebPluginFramework;
namespace ButcherManageClient
{
public partial class SettingForm : Form
{
bool mInited;
public SettingForm(bool rpcFacadeInited)
{
InitializeComponent();
uTextBoxWithPad1.Text = ButcherAppContext.Context.UrlConfig.ServerUrl;
mInited = rpcFacadeInited;
}
private void cancelBtn_Click(object sender, EventArgs e)
{
this.Close();
}
private void saveBtn_Click(object sender, EventArgs e)
{
string uri = this.uTextBoxWithPad1.Text.Trim();
if (string.IsNullOrEmpty(uri))
throw new Exception("请先设置服务器地址");
ButcherAppContext.Context.UrlConfig.ServerUrl = uri;
ButcherAppContext.Context.UrlConfig.OfflineSqlConnection = (string)dbSelect.SelectedValue;
ButcherAppContext.Context.Save();
if (mInited)
RpcFacade.ReInit(ButcherAppContext.Context.UrlConfig.ServerUrl);
MessageBox.Show("设置保存成功!");
}
private void btnUpdate_Click(object sender, EventArgs e)
{
using (ISqlUtil sqlUtil = new SqlUtil(ButcherAppContext.Context.UrlConfig.OfflineSqlConnection))
{
var boTypes = GetTypes();
Dmo.UpdateTables(sqlUtil, boTypes);
}
MessageBox.Show("升级成功");
}
List<string> NeedUpdateDbDll()
{
var list=new List<string>();
//list.Add("SegmentationWeight.dll");
//list.Add("TrunksIousOutInStore.dll");
//list.Add("SegmentationInStore.dll");
list.Add("BO.dll");
return list;
}
private IEnumerable<Type> GetTypes()
{
var startuppath = Application.StartupPath;
DirectoryInfo fdir = new DirectoryInfo(startuppath);
var needList = NeedUpdateDbDll();
foreach (FileInfo file in fdir.GetFiles("*.dll"))
{
if (!needList.Contains(file.Name))
{
continue;
}
var asm = Assembly.LoadFile(file.FullName);
foreach (var t in asm.GetExportedTypes())
{
if (t.IsAbstract)
{
continue;
}
if (t.IsClass && IsMapTable(t))
{
yield return t;
}
}
}
}
public static bool IsMapTable(Type t)
{
var attr = ReflectionUtil.GetAttribute<MapToTableAttribute>(t);
if (attr == null)
{
return false;
}
return true;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!File.Exists("DBSelectTemplate.xml"))
{
var list = new List<DBSelectTemplate>();
list.Add(new DBSelectTemplate() { Name = "我的机器", Value = SELFDB });
list.Add(new DBSelectTemplate() { Name = "主机", Value = REMOTEDB.Replace("{IP}", "172.28.21.5").Replace("{PWD}", "123") });
list.Add(new DBSelectTemplate() { Name = "线路01", Value = REMOTEDB.Replace("{IP}", "172.28.1.194").Replace("{PWD}", "Wanfu2014") });
list.Add(new DBSelectTemplate() { Name = "线路02", Value = REMOTEDB.Replace("{IP}", "172.28.1.99").Replace("{PWD}", "Wanfu2014") });
BO.Utils.XmlUtil.SerializerObjToFile(list, "DBSelectTemplate.xml");
}
var db = BO.Utils.XmlUtil.DeserializeFromFile<List<DBSelectTemplate>>("DBSelectTemplate.xml");
dbSelect.DisplayMember = "Name";
dbSelect.ValueMember = "Value";
dbSelect.DataSource = db;
if (!string.IsNullOrEmpty(ButcherAppContext.Context.UrlConfig.OfflineSqlConnection))
{
var idx = db.FindIndex(x => x.Value == ButcherAppContext.Context.UrlConfig.OfflineSqlConnection);
if (idx > 0)
dbSelect.SelectedIndex = idx;
}
}
const string SELFDB = "Server=.;Database=LocalClientService;Integrated Security=true;Language=Simplified Chinese;";
const string REMOTEDB = "Server={IP};Database=LocalClientService;User ID=sa;Password={PWD};Language=Simplified Chinese;";
}
public class DBSelectTemplate
{
public string Name { get; set; }
public string Value { get; set; }
}
}