public static string getRealNameTableAttribute(this ComboBox cmbItems1, MetaDataDBContainer metaDbContainer) { string Result = metaDbContainer.TableSet.Where(y => y.Name == cmbItems1.Text.ToString().Substring(0, cmbItems1.Text.ToString().IndexOf("."))).Select(z => z.RealName).FirstOrDefault() + "." + metaDbContainer.AttributeSet.Where(y => y.Name == cmbItems1.Text.ToString().Substring(cmbItems1.Text.ToString().IndexOf(".") + 1)).Select(z => z.RealName).FirstOrDefault(); return(Result); }
public TableInfoForm(string realTableName, MetaDataDBContainer metaDataDbContainer, SqlConnection dbConnection) { InitializeComponent(); this.metaDbContainer = metaDataDbContainer; this.dbConnection = dbConnection; currentTable = metaDbContainer.TableSet.Where(t => t.RealName == realTableName).First(); Text = $"Просмотр таблицы {currentTable.Name}"; var allAttrs = currentTable.Attributes.ToList(); int allAttrsCount = allAttrs.Count; if (allAttrsCount > 0) { dataGridView1.Rows.Add(allAttrsCount); for (int i = 0; i < allAttrsCount; i++) { var cells = dataGridView1.Rows[i].Cells; cells[0].Value = allAttrs[i].Name; cells[0].Tag = allAttrs[i]; cells[1].Value = (allAttrs[i].Type.StartsWith("t")) ? "Ссылка на таблицу" : allAttrs[i].Type; cells[2].Value = allAttrs[i].IsPKey; cells[3].Value = allAttrs[i].IsNullable; cells[4].Value = allAttrs[i].IsIndexed; } } }
/// <summary> /// /// </summary> /// <param name="Name">*table.attr*</param> /// <param name="metaDbContainer"></param> /// <returns></returns> public static string getRealNameTableAttribute(this string Name, MetaDataDBContainer metaDbContainer) { string table = Name.Split('.')[0]; string attr = Name.Split('.')[1]; return(table.getRealNameTable(metaDbContainer) + "." + attr.getRealNameAttribute(metaDbContainer)); }
public static string getRealNamesAttributes(this ListBox listBoxSelected, MetaDataDBContainer metaDbContainer) { var elementsForQuery = listBoxSelected.Items.Cast <string>().ToArray(); var distinctElementsForQUery = elementsForQuery.Select(x => x.Substring(x.IndexOf('.') + 1)).Distinct().ToArray(); //Convert TableNames to TableRealNames as String string Elements = String.Join(",", elementsForQuery.Distinct().ToList().Select(c => { c = metaDbContainer.TableSet.Where(y => y.Name == c.Substring(0, c.IndexOf("."))).Select(z => z.RealName).FirstOrDefault() + "." + metaDbContainer.AttributeSet.Where(y => y.Name == c.Substring(c.IndexOf(".") + 1)).Select(z => z.RealName + " as '" + z.Name.ToString()).FirstOrDefault() + "'"; return(c); }).ToList()); if (distinctElementsForQUery.Count() != elementsForQuery.Count()) { Regex r = new Regex(Regex.Escape("'") + "(.*?)" + Regex.Escape("'")); MatchCollection matches = r.Matches(Elements); string ElementsNew = ""; foreach (string str in Elements.Split(',')) { var ss = elementsForQuery.Except(distinctElementsForQUery).ToArray(); //попробовать реплейснуть после точки var a = r.Match(str).ToString().Replace("'", ""); //if (elementsForQuery.Except(distinctElementsForQUery).Contains(a)) { string tmp_substr = str.Split('.')[0]; string tmp = metaDbContainer.TableSet.Where(x => x.RealName == tmp_substr).FirstOrDefault().Name + "." + a; ElementsNew += str.Replace(a, tmp) + ","; } } ElementsNew = ElementsNew.Substring(0, ElementsNew.Length - 1); return(ElementsNew); } return(Elements); }
public static string[] getJoinsWithPar(this ListBox listBoxJoins, MetaDataDBContainer metaDbContainer) { var a = listBoxJoins.Items.Cast <string>().ToArray(); string[] Result = listBoxJoins.Items.Cast <string>().Select(x => String.Join("", x.Split(' ')[3].TakeWhile(sep => sep != '.')).getRealNameTable(metaDbContainer) + " " + x.Split(' ')[0] + " " + x.Split(' ')[1] + " " + String.Join("", x.Split(' ')[5].TakeWhile(sep => sep != '.')).getRealNameTable(metaDbContainer) + " ON (" + x.Split(' ')[3].getRealNameTableAttribute(metaDbContainer) + " " + x.Split(' ')[4] + " " + x.Split(' ')[5].getRealNameTableAttribute(metaDbContainer) + ")").ToArray(); return(Result); }
public static string getRealNamesTables(this ListBox listBoxSelected, MetaDataDBContainer metaDbContainer) { var elementsForQuery = listBoxSelected.Items.Cast <string>().ToArray(); //Convert TableNames to TableRealNames as String string Tables = String.Join(",", elementsForQuery.Select(x => x.Substring(0, x.IndexOf("."))).Distinct().ToList().Select(c => { c = metaDbContainer.TableSet.Where(y => y.Name == c).Select(z => z.RealName).FirstOrDefault(); return(c); }).ToList()); return(Tables); }
public static string getRealNamesTables(this string[] listBoxSelected, MetaDataDBContainer metaDbContainer) { var elementsForQuery = listBoxSelected; //Convert TableNames to TableRealNames as String string Tables = String.Join(",", elementsForQuery.Distinct().ToList().Select(c => { c = metaDbContainer.TableSet.Where(y => y.Name == c).Select(z => z.RealName).FirstOrDefault(); return(c); }).ToList()); return(Tables); }
/* * Давать возможность изменять структуру данных целевого приложения, с которым будет работать конечный пользователь. * Как минимум - создавать новые таблицы, добавлять в таблицы новые атрибуты, индексировать по ним, а также создавать связи между таблицами - на положительную оценку. * На хорошую оценку - задавать ограничения на значения атрибутов, начальные значения и пр. * На отличную - давать возможность и удалять поля в таблицах и сами таблицы, связи (или изменять, но это можно сделать и через удаление-добавление). * Схема БД фиксируется в метаданных. Операции над структурой БД должны выполняться с учётом поддержания целостности метаданных, * т.е. метаданные также нормализуются, как и данные в обычных БД, но описывают они не состояние объекта предметной области, а состояние БД, её структуру. */ public NewTableForm(MetaDataDBContainer metaDataDbContainer, SqlConnection dbConnection) { InitializeComponent(); log.Debug("NewTableForm opened"); this.metaDbContainer = metaDataDbContainer; this.dbConnection = dbConnection; sqlExecutor = new SqlExecutor(dbConnection); tableRealName2Name = GetTableNames(); ((DataGridViewComboBoxColumn)fkDataGridView.Columns[0]).Items.AddRange(tableRealName2Name.Keys.Select(x => x.ToString()).ToArray()); }
public NewAttributeForm(MetaDataDBContainer metaDataDbContainer, SqlConnection dbConnection, Table currentTable) { InitializeComponent(); this.metaDbContainer = metaDataDbContainer; this.dbConnection = dbConnection; this.currentTable = currentTable; tableRealName2Name = metaDbContainer.TableSet .Where(t => t.Attributes.Any(a => a.IsPKey)).ToList().Where(t => !currentTable.ParentTables.Contains(t) && t.RealName != currentTable.RealName) .Aggregate(new Dictionary <string, string>(), (d, t) => { d.Add("Ссылка на " + t.Name, t.RealName); return(d); }); }
public QueriesForm(MetaDataDBContainer metaDataDbContainer, SqlConnection dbConnection, string QueryName) { InitializeComponent(); // cmbTables.SelectedIndex = 0; log.Debug("QueriesForm opened"); this.metaDbContainer = metaDataDbContainer; this.dbConnection = dbConnection; sqlExecutor = new SqlExecutor(dbConnection); cmbTables.DataSource = metaDataDbContainer.TableSet.Select(x => x.Name).ToList(); cmbTables.SelectedIndex = 0; this.QueryName = QueryName; needToAdd = true; btnAddJoin.Enabled = false; CreateQuery.Enabled = false; }
public JoinForm(MetaDataDBContainer metaDataDbContainer, SqlConnection dbConnection, string tablesFrom) { try { selectedTables = tablesFrom.Split(',').ToList(); InitializeComponent(); this.metaDbContainer = metaDataDbContainer; this.dbConnection = dbConnection; cmbT1.DataSource = new BindingSource(selectedTables, string.Empty); cmbT1.SelectedIndex = 0; cmbT2.DataSource = new BindingSource(selectedTables, string.Empty); cmbT2.SelectedIndex = 1; cmbT1.DataSource = new BindingSource(selectedTables, string.Empty); cmbOn.SelectedIndex = 0; cmbJoinTypes.SelectedIndex = 0; } catch { } }
public ViewForm(MetaDataDBContainer Container, SqlConnection dbConnection, Model.View View) { InitializeComponent(); try { _dbConnection = dbConnection; _cont = Container; view = View; LoadViewForm(); //InitializeAttributePage(); } catch (Exception e) { MessageBox.Show("Возникла ошибка"); _log.Error(e); //SaveError(e); } }
public ViewForm() { InitializeComponent(); try { _cont = new MetaDataDBContainer(); view = new Model.View("NewView"); _cont.ViewSet.Add(view); _cont.SaveChanges(); InitializeAttributePage(); } catch (Exception e) { MessageBox.Show("Возникла ошибка"); _log.Error(e); //SaveError(e); } }
public ViewForm(MetaDataDBContainer Container, SqlConnection dbConnection, string ViewName) { InitializeComponent(); try { _dbConnection = dbConnection; _cont = Container; view = new Model.View(ViewName); _cont.ViewSet.Add(view); _cont.SaveChanges(); InitializeAttributePage(); } catch (Exception e) { MessageBox.Show("Возникла ошибка"); _log.Error(e); //SaveError(e); } }
public static string getRealNameAttribute(this string Name, MetaDataDBContainer metaDbContainer) { return(metaDbContainer.AttributeSet.Where(x => x.Name == Name).Select(y => y.RealName).FirstOrDefault()); }
public NewValueForm(MetaDataDBContainer Container, SqlConnection dbConnection) { InitializeComponent(); _container = Container; _dbConnection = dbConnection; }