private void showDiagram() { try { if (provider == null) { return; } IDataSetDesktop desktop = provider.Desktop; IDataSetFactory factory = DataSetFactoryChooser.Chooser[provider.FactoryName]; DataSetService.Forms.FormDataSet form = new FormDataSet(desktop, new DataSetSerializable.DataDesktopSerializable(), factory, provider.ConnecionString); form.ShowDialog(this); desktop = form.Desktop; if (desktop != null) { provider.Desktop = desktop; string st = factory.GenerateStatement(desktop); textBoxStatement.Text = st; } } catch (Exception ex) { ex.ShowError(10); } }
/// <summary> /// Constructor /// </summary> /// <param name="desktop">Desktop</param> /// <param name="factory">Desktop facr\tory</param> /// <param name="dataFactory">Data set factorty</param> /// <param name="connectionString">Connection string</param> public FormDataSet(IDataSetDesktop desktop, IDataSetDesktopFactory factory, IDataSetFactory dataFactory, string connectionString) { InitializeComponent(); this.connectionString = connectionString; this.dataFactory = dataFactory; ResourceService.Resources.LoadControlResources(this, DataSetService.Forms.Utils.ControlUtilites.Resources); this.factory = factory; if (desktop == null) { createDesktop(); } else { this.desktop = desktop; } try { createPanel(); } catch (Exception) { } }
/// <summary> /// Sets data to desktop /// </summary> /// <param name="dataSet">Data set</param> /// <param name="desktop">Desktop</param> public static void Set(DataSet dataSet, IDataSetDesktop desktop) { foreach (DataTable t in dataSet.Tables) { string name = t.TableName; ITable table = desktop.Tables[name]; } }
internal static PanelDataSet Load(IDataSetDesktop desktop) { PanelDataFactory f = PanelDataFactory.Object; PanelDataSet p = f.Copy(desktop) as PanelDataSet; p.Init(); p.Set(); return(p); }
private void createDesktop() { DbConnection connection = dataFactory.Connection; connection.ConnectionString = connectionString + ""; DataSet dataSet = dataFactory.GetData(connection); DataSetSerializable.DataDesktopSerializable desk = new DataSetSerializable.DataDesktopSerializable(); desktop = desk.Create(dataSet); }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { if (saveFileDialogDgm.ShowDialog(this) != DialogResult.OK) { return; } Stream stream = File.OpenWrite(saveFileDialogDgm.FileName); BinaryFormatter bf = new BinaryFormatter(); desktop = factory.Copy(panel); bf.Serialize(stream, desktop); }
/// <summary> /// Creates desktop from prototype /// </summary> /// <param name="dataSet">Prototype</param> /// <param name="factory">Factory</param> /// <returns>Desktop</returns> public static IDataSetDesktop Create(DataSet dataSet, IDataSetDesktopFactory factory) { IDataSetDesktop d = factory.Desktop; foreach (DataTable table in dataSet.Tables) { ITable t = Create(table, factory); d.Tables[t.Name] = t; t.Desktop = d; } return(d); }
/// <summary> /// Sets parameters of link /// </summary> /// <param name="link">The link</param> /// <param name="sourceTable">Name of source table</param> /// <param name="targetTable">Name of target table</param> /// <param name="sourceColumn">Name of source column</param> /// <param name="targetColumn">Name of target column</param> static public void Set(ILink link, string sourceTable, string targetTable, string sourceColumn, string targetColumn) { IDataSetDesktop d = link.Desktop; ITable tt = d.Tables[targetTable]; IColumn tc = tt.Columns[targetColumn]; link.Target = tc; ITable st = d.Tables[sourceTable]; IColumn sc = st.Columns[sourceColumn]; link.Source = sc; }
/// <summary> /// Gets selected links from desktop /// </summary> /// <param name="desktop">The desktop</param> /// <returns>List of selected links</returns> static public List <ILink> GetSelectedLinks(IDataSetDesktop desktop) { List <ILink> list = new List <ILink>(); foreach (ILink l in desktop.Links) { if (l.IsMarked) { list.Add(l); } } return(list); }
/// <summary> /// Gets list of pairs of selected columns of desktop /// </summary> /// <param name="desktop">Desktop</param> /// <returns>List of pairs of selected columns</returns> static public List <IColumn[]> GetLinkColumns(IDataSetDesktop desktop) { List <ILink> list = GetSelectedLinks(desktop); List <IColumn[]> l = new List <IColumn[]>(); foreach (ILink link in list) { IColumn[] c = new IColumn[2]; c[0] = link.Source; c[1] = link.Target; l.Add(c); } return(l); }
/// <summary> /// Gets links from column /// </summary> /// <param name="column">The column</param> /// <returns>List of links</returns> static public List <ILink> GetLinks(IColumn column) { ITable t = column.Table; IDataSetDesktop d = t.Desktop; List <ILink> list = new List <ILink>(); List <ILink> l = d.Links; foreach (ILink link in l) { if (link.Source == column | link.Target == column) { list.Add(link); } } return(list); }
/// <summary> /// Gets selected columns from desktop /// </summary> /// <param name="desktop">The desktop</param> /// <returns>List of selected columns</returns> static public List <IColumn> GetSelectedColumns(IDataSetDesktop desktop) { List <IColumn> list = new List <IColumn>(); foreach (ITable t in desktop.Tables.Values) { foreach (IColumn c in t.Columns.Values) { if (c.IsMarked) { list.Add(c); } } } return(list); }
/// <summary> /// Checks target of link /// </summary> /// <param name="link">The link</param> /// <param name="target">The target</param> static public void Check(ILink link, IColumn target) { if (link.Source == target) { throw new Exception("Cannot link to itself"); } IDataSetDesktop d = link.Source.Table.Desktop; List <ILink> links = d.Links; foreach (ILink l in links) { if (l.Source == link.Source && target == l.Target) { throw new Exception("Link already exists"); } } if (!link.Source.Type.Equals(target.Type)) { throw new Exception("Different types of columns"); } }
/// <summary> /// Deserialization constructor /// </summary> /// <param name="info">Serialization info</param> /// <param name="context">Streaming context</param> public AbstractDataProvider(SerializationInfo info, StreamingContext context) { connectionString = info.GetValue("ConnectionString", typeof(string)) + ""; statement = info.GetValue("Statement", typeof(string)) + ""; try { desktop = info.GetValue("Desktop", typeof(object)) as IDataSetDesktop; } catch (Exception ex) { ex.ShowError(-1); } try { parameters = info.GetValue("Parameters", typeof(Dictionary <string, string>)) as Dictionary <string, string>; } catch (Exception exc) { exc.ShowError(10); } }
/// <summary> /// Removes table /// </summary> /// <param name="table">Table for removing</param> static public void RemoveTable(ITable table) { IDataSetDesktop d = table.Desktop; List <ILink> l = new List <ILink>(); List <ILink> lp = d.Links; foreach (ILink link in lp) { if (link.Source == table && link.Target == table) { if (!l.Contains(link)) { l.Add(link); } } } foreach (ILink link in l) { d.Remove(link); } d.Remove(table); }
/// <summary> /// Copies desktop with help of factory /// </summary> /// <param name="desktop">The desktop</param> /// <param name="factory">The factory</param> /// <returns>Desktop copy</returns> public static IDataSetDesktop Copy(IDataSetDesktop desktop, IDataSetDesktopFactory factory) { IDataSetDesktop d = factory.Desktop; Dictionary <string, Dictionary <string, IColumn> > dictionary = new Dictionary <string, Dictionary <string, IColumn> >(); foreach (string name in desktop.Tables.Keys) { ITable t = Copy(desktop.Tables[name], factory); d.Tables[name] = t; t.Desktop = d; } foreach (ITable t in d.Tables.Values) { Dictionary <string, IColumn> dic = new Dictionary <string, IColumn>(); dictionary[t.Name] = dic; foreach (IColumn c in t.Columns.Values) { dic[c.Name] = c; } } foreach (ILink link in desktop.Links) { ILink l = factory.Link; l.Desktop = d; l.IsMarked = link.IsMarked; l.SourceTable = link.SourceTable; l.TargetTable = link.TargetTable; l.SourceColumn = link.SourceColumn; l.TargetColumn = link.TargetColumn; l.Source = dictionary[l.SourceTable][l.SourceColumn]; l.Target = dictionary[l.TargetTable][l.TargetColumn]; if (!d.Links.Contains(l)) { d.Links.Add(l); } } return(d); }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { if (openFileDialogDgm.ShowDialog(this) != DialogResult.OK) { return; } Stream stream = File.OpenRead(openFileDialogDgm.FileName); BinaryFormatter bf = new BinaryFormatter(); try { object o = bf.Deserialize(stream); if (!(o is IDataSetDesktop)) { return; } desktop = o as IDataSetDesktop; panelCenter.Controls.Clear(); createPanel(); } catch (Exception) { } }
private void buttonOK_Click(object sender, EventArgs e) { desktop = factory.Copy(panel); Close(); }
/// <summary> /// Copies sesktop /// </summary> /// <param name="desktop">Prototype</param> /// <returns>A copy</returns> public IDataSetDesktop Copy(IDataSetDesktop desktop) { return(DataSetFactoryPerformer.Copy(desktop, this)); }
/// <summary> /// Generates statement from desktop /// </summary> /// <param name="desktop">The desktop</param> /// <returns>The statement</returns> public string GenerateStatement(IDataSetDesktop desktop) { return(AbstractDataSetDesktop.GenerateStandardStatement(desktop)); }
/// <summary> /// Sets data set to desktop /// </summary> /// <param name="desktop">The desktop</param> /// <param name="dataSet">The data set</param> public void Set(IDataSetDesktop desktop, DataSet dataSet) { DataSetFactoryPerformer.Set(dataSet, desktop); }
/// <summary> /// Removes link /// </summary> /// <param name="link">Link for removing</param> static public void RemoveLink(ILink link) { IDataSetDesktop d = link.Desktop; d.Remove(link); }
/// <summary> /// Generates standard statement of desktop /// </summary> /// <param name="desktop">The desktop</param> /// <returns>The statement</returns> static public string GenerateStandardStatement(IDataSetDesktop desktop) { List <IColumn> cols = GetSelectedColumns(desktop); List <IColumn[]> links = GetLinkColumns(desktop); List <ITable> tables = new List <ITable>(); foreach (IColumn c in cols) { ITable t = c.Table; if (!tables.Contains(t)) { tables.Add(t); } } List <IColumn[]> linksn = new List <IColumn[]>(links); foreach (IColumn[] c in linksn) { if (!tables.Contains(c[0].Table) | !tables.Contains(c[1].Table)) { if (links.Contains(c)) { links.Remove(c); } } } string s = "SELECT "; bool bg = false; foreach (IColumn c in cols) { if (bg) { s += ", "; } bg = true; s += c.Table.Name + "." + c.Name; } s += " FROM "; bg = false; foreach (ITable t in tables) { if (bg) { s += ", "; } bg = true; s += t.Name; } string wh = ""; bg = false; foreach (IColumn[] c in links) { if (bg) { wh += " AND "; } bg = true; wh += c[0].Table.Name + "." + c[0].Name + " = " + c[1].Table.Name + "." + c[1].Name; } foreach (IColumn c in cols) { if (c.IsNullable) { if (!c.IsNull) { if (bg) { wh += " AND "; } bg = true; wh += c.Table.Name + "." + c.Name + " IS NOT NULL"; } } } foreach (ITable table in desktop.Tables.Values) { foreach (IColumn c in table.Columns.Values) { string mod = c.Modifier; string val = c.Value; if (mod.Length > 0 & val.Length > 0) { if (bg) { wh += " AND "; } wh += c.Table.Name + "." + c.Name + " " + mod + " "; if (c.Type.Equals("System.Char[]")) { wh += "\'"; } wh += val; if (c.Type.Equals("System.Char[]")) { wh += "\'"; } bg = true; } } } if (wh.Length > 0) { s += " WHERE " + wh; } return(s); }