private void loadFromXml() { XmlDocument document = new XmlDocument(); document.Load("configuration.xml"); var xmlNodeList = document.SelectNodes("root/oneToN"); foreach (XmlNode node in xmlNodeList) { OneToNQueries oneToNQueries = new OneToNQueries(); oneToNQueries.connectionString = node.SelectSingleNode("connection").InnerText; oneToNQueries.masterName = node.SelectSingleNode("master/name").InnerText; oneToNQueries.name = node.SelectSingleNode("name").InnerText; oneToNQueries.masterName = node.SelectSingleNode("master/name").InnerText; oneToNQueries.masterFriendlyName = Int32.Parse(node .SelectSingleNode("master/friendlyName").InnerText); oneToNQueries.selectMaster = node.SelectSingleNode("master/select/query") .InnerText; oneToNQueries.slaveName = node.SelectSingleNode("slave/name").InnerText; oneToNQueries.selectSlave = node.SelectSingleNode("slave/select/query").InnerText; oneToNQueries.maxSlaveId = node.SelectSingleNode("slave/maxId/query").InnerText; oneToNQueries.getSlaveByMasterId = node .SelectSingleNode("slave/getByMaster/query").InnerText; oneToNQueries.getSlaveByMasterIdParams = Int32.Parse(node .SelectSingleNode("slave/getByMaster/parameters").InnerText); oneToNQueries.insertSlave = node.SelectSingleNode("slave/insert/query").InnerText; oneToNQueries.insertSlaveParams = Int32.Parse(node .SelectSingleNode("slave/insert/parameters").InnerText); oneToNQueries.updateSlave = node.SelectSingleNode("slave/update/query").InnerText; oneToNQueries.updateSlaveParams = Int32.Parse(node .SelectSingleNode("slave/update/parameters").InnerText); oneToNQueries.deleteSlave = node.SelectSingleNode("slave/delete/query").InnerText; oneToNQueries.deleteSlaveParams = Int32.Parse(node .SelectSingleNode("slave/delete/parameters").InnerText); OneToNTab oneToNTab = new OneToNTab(oneToNQueries); this.tabs.TabPages.Add(oneToNTab); } }
public OneToNTab(OneToNQueries oneToNQueries) { this.connectionString = oneToNQueries.connectionString; this.sqlConnection = new SqlConnection(connectionString); this.Text = oneToNQueries.name; this.oneToNQueries = oneToNQueries; masterLabel.Text = oneToNQueries.masterName; slaveLabel.Text = oneToNQueries.slaveName; masterLabel.Top = 25; masterLabel.Left = 50; masterLabel.Height = 25; masterLabel.Width = 150; masterGridView.Top = 90; masterGridView.Left = 50; masterGridView.Height = 400; masterGridView.Width = 800; masterGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; masterGridView.ReadOnly = true; masterGridView.SelectionChanged += (sender, args) => fillSlaveTable(); slaveLabel.Top = 25; slaveLabel.Left = 975; slaveLabel.Height = 25; slaveLabel.Width = 150; slaveGridView.Top = 90; slaveGridView.Left = 975; slaveGridView.Height = 400; slaveGridView.Width = 700; slaveGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; slaveGridView.ReadOnly = true; addToMaster.Top = 550; addToMaster.Left = 50; addToMaster.Height = 30; addToMaster.Width = 150; addToMaster.Text = "Add"; addToMaster.Click += addToMasterMethod; updateSlave.Top = 550; updateSlave.Left = 975; updateSlave.Height = 30; updateSlave.Width = 150; updateSlave.Text = "Update"; updateSlave.Click += updateSlaveMethod; removeSlave.Top = 550; removeSlave.Left = 1150; removeSlave.Height = 30; removeSlave.Width = 150; removeSlave.Text = "Remove"; removeSlave.Click += removeSlaveMethod; SqlDataAdapter sqlData = new SqlDataAdapter(oneToNQueries.selectMaster, sqlConnection); DataTable dataTable = new DataTable(); sqlData.Fill(dataTable); this.masterGridView.DataSource = dataTable; this.friendlyMaster = dataTable.AsEnumerable() .Select(property => new StringStringObject(property[0].ToString(), property[oneToNQueries.masterFriendlyName].ToString())).ToList(); sqlConnection.Open(); SqlCommand comm = new SqlCommand(oneToNQueries.maxSlaveId, sqlConnection); object result = comm.ExecuteScalar(); Int32 count; try { count = (Int32)result; } catch { count = 0; } this.nextId = count + 1; this.Controls.Add(masterLabel); this.Controls.Add(slaveLabel); this.Controls.Add(masterGridView); this.Controls.Add(slaveGridView); this.Controls.Add(addToMaster); this.Controls.Add(updateSlave); this.Controls.Add(removeSlave); }