private void btnView_Click(object sender, EventArgs e) { string sErr = ""; _processStatus = "V"; frmQDADDView frm = new frmQDADDView(_db, _user); //frm.Connect = _db; if (frm.ShowDialog() == DialogResult.OK) { if (frm.ReturnCode != "") { BUS.LIST_QD_SCHEMAControl ctr = new BUS.LIST_QD_SCHEMAControl(); DTO.LIST_QD_SCHEMAInfo inf = ctr.Get(_db, frm.ReturnCode, ref sErr); SetDataToForm(inf); } } if (sErr == "") { EnableForm(false); _processStatus = "V"; } dgvFrom.AutoSizeColumns(); dgvField.AutoSizeColumns(); }
private void btnRelation_Click(object sender, EventArgs e) { string sErr = ""; frmQDADDView frmview = new frmQDADDView(_db, _user); frmview.Conn_ID = ddlQD.Text; if (frmview.ShowDialog() == DialogResult.OK && frmview.ReturnCode != "") { frmRelation frm = new frmRelation(); frm.DTOriginal = _data.Tables["_TableName"]; BUS.LIST_QD_SCHEMAControl ctr = new BUS.LIST_QD_SCHEMAControl(); DTO.LIST_QD_SCHEMAInfo inf = ctr.Get(_db, frmview.ReturnCode, ref sErr); if (inf.SCHEMA_ID != "") { try { ////string result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><SUN_SCHEMA></SUN_SCHEMA>"; //XmlDocument doc = new XmlDocument(); //doc.LoadXml(inf.FIELD_TEXT); //XmlElement docele = doc.DocumentElement; ////<row table="M5" node="Lookup" name="Lookup" type=""/> //string schema = inf.FROM_TEXT; DataSet dset = ReadScheme(inf); //dset = ReadScheme(inf); //DataTable dtfrom = new DataTable("fromcode"); //DataColumn[] colfrom = new DataColumn[] { new DataColumn("fromcode"), new DataColumn("lookup") }; //dtfrom.Columns.AddRange(colfrom); // DataTable dtfield = new DataTable("_TableName"); // DataColumn[] colfield = new DataColumn[] { new DataColumn("node") //, new DataColumn("table") //, new DataColumn("name") //, new DataColumn("nodeDesc") //, new DataColumn("type")}; // dtfield.Columns.AddRange(colfield); // //dset.Tables.Add(dtfrom); // dset.Tables.Add(dtfield); // //DataRelation relation = new DataRelation("R_field", dtfrom.Columns["fromcode"], dtfield.Columns["table"], true); // //dset.Relations.Add(relation); // StringReader strR = new StringReader(schema); // dset.ReadXml(strR); frm.DTLooup = dset.Tables["_TableName"]; if (frm.ShowDialog() == DialogResult.OK) { DataTable dtR = frm.Relation; DataRow fromRow = _data.Tables["fromcode"].NewRow(); DataRow fieldRow = _data.Tables["_TableName"].NewRow(); fieldRow["node"] = frmview.ReturnCode; fieldRow["name"] = frmview.ReturnCode + "Record"; fieldRow["type"] = "S"; fieldRow["table"] = txtCode.Text.Trim(); fromRow["fromcode"] = String.Format("{0}\\{1}", txtCode.Text.Trim(), frmview.ReturnCode); string lookup = ""; foreach (DataRow row in dtR.Rows) { if (row["Original"].ToString().Contains(" ")) { row["Original"] = String.Format("[{0}]", row["Original"]); } if (row["lookup"].ToString().Contains(" ")) { row["lookup"] = String.Format("[{0}]", row["lookup"]); } lookup += String.Format(" and {0}.{1} = {2}.{3}", txtCode.Text.Trim(), row["Original"], frmview.ReturnCode, row["lookup"]); } fromRow["lookup"] = lookup.Substring(5); _data.Tables["fromcode"].Rows.Add(fromRow); if (dgvField.CurrentRow != null && dgvField.CurrentRow.RowIndex >= 0) { _data.Tables["_TableName"].Rows.InsertAt(fieldRow, dgvField.CurrentRow.RowIndex); } else { _data.Tables["_TableName"].Rows.Add(fieldRow); } } } catch (Exception ex) { lbErr.Text = ex.Message; } } } }