private void btnDatabase_Click(object sender, RoutedEventArgs e) { DbConnection conn = SystemUtility.GetDbConnection(cmbDatabase.Text); conn.ConnectionString = txtConnectionString.Text; conn.Open(); GetTable(conn); conn.Close(); }
private void btnGenClient_Click(object sender, RoutedEventArgs e) { string path = SystemUtility.m_project.OutputPath.TrimEnd('/', '\\'); path += "\\Client\\"; if (Directory.Exists(path)) { MessageBox.Show("项目已存在,是否删除?", "是否删除", MessageBoxButton.YesNo, MessageBoxImage.Question); Directory.Delete(path, true); } SystemUtility.BuildClientPorject(Guid.NewGuid()); MessageBox.Show("生成完成!"); }
private void Window_Loaded(object sender, RoutedEventArgs e) { conn = SystemUtility.GetDbConnection(SystemUtility.m_project.DatabaseType); conn.ConnectionString = SystemUtility.m_project.ConnectionString; conn.Open(); dgvTables.DataSource = conn.GetSchema("Tables"); conn.Close(); dgvTables.ReadOnly = true; dgvTables.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dgvTables.SelectionChanged += new EventHandler(dgvTables_SelectionChanged); wfhTables.Child = dgvTables; wfhColumns.Child = dgvColumns; }
private void btnGenModel_Click(object sender, RoutedEventArgs e) { string path = SystemUtility.m_project.OutputPath.TrimEnd('/', '\\'); path += "\\Server\\"; if (Directory.Exists(path)) { MessageBox.Show("项目已存在,是否删除?", "是否删除", MessageBoxButton.YesNo, MessageBoxImage.Question); Directory.Delete(path, true); } Guid guid1 = Guid.NewGuid(); Guid guid2 = Guid.NewGuid(); SystemUtility.BuildServerPorject(guid1); //SystemUtility.BuildServerSln(guid2, guid1); MessageBox.Show("生成完成!"); }
public void BuildServerFile() { if (m_tableInfo.IsGenerateCode && !m_tableInfo.HasError) { string path = SystemUtility.GetServerPath(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string file = path + m_tableInfo.ClassName + ".cs"; FileStream stream = new FileStream(file, FileMode.Create); StreamWriter sw = new StreamWriter(stream); foreach (ColumnInfo info in m_tableInfo.Columns) { if (info.ColumnName.ToLower() == "rid") { continue; } if (info.IsRealTime) { m_realTimeList.Add(info); } if (info.IsAltKey) { m_altKeyList.Add(info); } } #region using sw.WriteLine("using System;"); sw.WriteLine("using System.Collections.Generic;"); sw.WriteLine("using System.Linq;"); sw.WriteLine("using System.Text;"); sw.WriteLine("using System.Runtime.Serialization;"); sw.WriteLine("using SuperControl.ServiceModel;"); #endregion #region ClassAttribute sw.WriteLine(); sw.WriteLine("namespace {0}", SystemUtility.m_project.ServerNameSpace); sw.WriteLine("{"); sw.WriteLine(" [Serializable, DataContract]"); sw.WriteLine(" [DbTable(HasAlternateKey = {0},CacheMode = CacheMode.{1},TableName = \"{2}\",Realtime = {3})]", (m_altKeyList.Count > 0).ToString().ToLower(), m_tableInfo.CacheMode, m_tableInfo.TableName, (m_realTimeList.Count > 0).ToString().ToLower()); #endregion #region Class string baseclass = SystemUtility.m_project.RootClassName; if (m_tableInfo.ParentTable != null && m_tableInfo.ParentTable.IsGenerateCode && !m_tableInfo.ParentTable.HasError) { baseclass = m_tableInfo.ParentTable.ClassName; } sw.WriteLine(" public class {0} : {1}", m_tableInfo.ClassName, baseclass); sw.WriteLine(" {"); #region Property foreach (ColumnInfo info in m_tableInfo.Columns) { if (info.ColumnName.ToLower() == "rid") { continue; } GetPropertyCode(info, sw); } #endregion #region altkey if (m_altKeyList.Count > 0) { sw.WriteLine(" public override string AlternateKey"); sw.WriteLine(" {"); sw.WriteLine(" get"); sw.WriteLine(" {"); sw.WriteLine(" string altkey = string.Empty;"); for (int i = 0; i < m_altKeyList.Count; i++) { sw.WriteLine(" altkey += {0} == null ? string.Empty : {0}.ToString();", m_altKeyList[i].PropertyName); if (i < m_altKeyList.Count - 1) { sw.WriteLine(" altkey += '|';"); } } sw.WriteLine(" return altkey;"); sw.WriteLine(" }"); sw.WriteLine(" }"); sw.WriteLine(); } #endregion #region realtime if (m_realTimeList.Count > 0) { sw.WriteLine(" protected override void GetRealtimeData(RealtimeData data)"); sw.WriteLine(" {"); sw.WriteLine(" base.GetRealtimeData(data);"); sw.Write(" data.AddData("); for (int i = 0; i < m_realTimeList.Count; i++) { sw.Write(m_realTimeList[i].PropertyName); if (i < m_realTimeList.Count - 1) { sw.Write(','); } } sw.Write(");"); sw.WriteLine(); sw.WriteLine(" }"); sw.WriteLine(); } #endregion #region set value sw.WriteLine(" public override void SetValueWithTableName(string fieldName, object value, out bool sendImmediately)"); sw.WriteLine(" {"); sw.WriteLine(" base.SetValueWithTableName(fieldName, value, out sendImmediately);"); sw.WriteLine(" switch (fieldName)"); sw.WriteLine(" {"); //先设置realtime部分的属性 foreach (ColumnInfo info in m_tableInfo.Columns) { if (!info.IsGenerateCode || info.HasError) { continue; } if (info.ColumnName.ToLower() == "rid") { continue; } if (!info.IsRealTime) { continue; } sw.WriteLine(" case \"{0}\":", info.ColumnName); sw.WriteLine(" if (!m_{0}.Equals(value))", info.PropertyName); sw.WriteLine(" {"); sw.WriteLine(" m_{0} = ({1})ModelDatabaseEnumerator.ChangeType(value, typeof({1}));", info.PropertyName, info.PropertyType); sw.WriteLine(" sendImmediately = false;"); sw.WriteLine(" OnPropertyChanged(\"{0}\");", info.PropertyName); sw.WriteLine(" }"); sw.WriteLine(" break;"); } //其他非实时属性后设置 foreach (ColumnInfo info in m_tableInfo.Columns) { if (!info.IsGenerateCode || info.HasError) { continue; } if (info.ColumnName.ToLower() == "rid") { continue; } if (info.IsRealTime) { continue; } sw.WriteLine(" case \"{0}\":", info.ColumnName); sw.WriteLine(" if (!m_{0}.Equals(value))", info.PropertyName); sw.WriteLine(" {"); sw.WriteLine(" m_{0} = ({1})ModelDatabaseEnumerator.ChangeType(value, typeof({1}));", info.PropertyName, info.PropertyType); sw.WriteLine(" sendImmediately = true;"); sw.WriteLine(" OnPropertyChanged(\"{0}\");", info.PropertyName); sw.WriteLine(" }"); sw.WriteLine(" break;"); } sw.WriteLine(" default:"); sw.WriteLine(" sendImmediately = false;"); sw.WriteLine(" break;"); sw.WriteLine(" }"); sw.WriteLine(" }"); #endregion sw.WriteLine(" }"); sw.WriteLine("}"); sw.WriteLine(); #endregion sw.Flush(); stream.Close(); } }
public void BuildClientFile() { foreach (ColumnInfo info in m_tableInfo.Columns) { if (info.IsGenerateCode && !info.HasError) { if (info.IsRealTime) { m_realTimeList.Add(info); } if (info.IsAltKey) { m_altKeyList.Add(info); } } } if (!m_tableInfo.IsGenerateCode) { return; } //if (m_altKeyList.Count == 0 && m_realTimeList.Count == 0) // return; string path = SystemUtility.GetClientProxyPath(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string file = path + m_tableInfo.ClassName + ".cs"; FileStream stream = new FileStream(file, FileMode.Create); StreamWriter sw = new StreamWriter(stream); #region using sw.WriteLine("using System;"); sw.WriteLine("using System.Net;"); sw.WriteLine("using SuperControl.ServiceModel;"); sw.WriteLine("using System.Collections.ObjectModel;"); #endregion #region ClassAttribute sw.WriteLine(); sw.WriteLine("namespace {0}", SystemUtility.m_project.ClientNameSpace + ".Proxy"); sw.WriteLine("{"); sw.WriteLine(" [DbTable(HasAlternateKey = {0},Realtime = {1})]", (m_altKeyList.Count > 0).ToString().ToLower(), (m_realTimeList.Count > 0).ToString().ToLower()); sw.WriteLine(" public partial class {0}", m_tableInfo.ClassName); sw.WriteLine(" {"); #endregion #region GetClientParentPropertyCode(m_tableInfo.ParentRelation, sw); sw.WriteLine(); GetClientChildrenPropertyCode(m_tableInfo.ChidrenRelation, sw); #endregion #region altkey if (m_altKeyList.Count > 0) { sw.WriteLine(" public override string AlternateKey"); sw.WriteLine(" {"); sw.WriteLine(" get"); sw.WriteLine(" {"); sw.WriteLine(" string altkey = string.Empty;"); for (int i = 0; i < m_altKeyList.Count; i++) { sw.WriteLine(" altkey += {0} == null ? string.Empty : {0}.ToString();", m_altKeyList[i].PropertyName); if (i < m_altKeyList.Count - 1) { sw.WriteLine(" altkey += '|';"); } } sw.WriteLine(" return altkey;"); sw.WriteLine(" }"); sw.WriteLine(" }"); } #endregion #region realtime if (m_realTimeList.Count > 0) { sw.WriteLine(" internal override void SetRealtimeData(RealtimeData data)"); sw.WriteLine(" {"); for (int i = 0; i < m_realTimeList.Count; i++) { sw.WriteLine(" this.{0} = ({1})data.Data[{2}];", m_realTimeList[i].PropertyName, m_realTimeList[i].PropertyType.Name, i); } sw.WriteLine(" }"); } #endregion sw.WriteLine(" }"); sw.WriteLine("}"); sw.Flush(); stream.Close(); }