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; offlineSqlConInput.Text = ButcherAppContext.Context.UrlConfig.OfflineSqlConnection; txtOutAddress.Text = ButcherAppContext.Context.UrlConfig.OutAddress; if (string.IsNullOrEmpty(offlineSqlConInput.Text)) offlineSqlConInput.Text = "Server=localhost;Database=LocalClientService;Integrated Security=true;Language=Simplified Chinese;"; 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 = offlineSqlConInput.Text.Trim(); ButcherAppContext.Context.UrlConfig.OutAddress = txtOutAddress.Text.Trim(); 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(offlineSqlConInput.Text.Trim())) { var boTypes = GetTypes(); Dmo.UpdateTables(sqlUtil, boTypes); } MessageBox.Show("升级成功"); } List NeedUpdateDbDll() { var list=new List(); list.Add("SegmentationWeight.dll"); list.Add("TrunksIousOutInStore.dll"); list.Add("SegmentationInStore.dll"); return list; } private IEnumerable 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(t); if (attr == null) { return false; } return true; } } }