Пример #1
0
        private string ToXML(ITableAdaptor dataTableAdaptor, int id,string tab)
        {
            var sb = new StringBuilder();
            DataTable dataTable =  dataTableAdaptor.GetTable();
            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                if (id > -1)
                {
                    int currentId;
                    int.TryParse(dataTable.Rows[i].ItemArray[0].ToString(), out currentId);
                    if (currentId != id)
                    {
                        continue;
                    }
                }
                for (int j = 0; j < dataTable.Columns.Count; j++)
                {
                    if (j>0 && dataTable.Columns[j].DataType == typeof (decimal))
                    {
                        sb.Append(tab+"<" + dataTable.Columns[j].ColumnName + ">\n");
                
                        object objo =
                            dataTableAdaptor.GetItem().UnderlyingSystemType.GetProperty(
                                dataTable.Columns[j].ColumnName);
                        if (objo != null)
                        {
                            ITableAdaptor dataTableAdaptorChild =
                                new MySqlTableAdaptor(((PropertyInfo) objo).PropertyType);
                            int idToFind;
                            int.TryParse(dataTable.Rows[i].ItemArray[j].ToString(), out idToFind);
                            string childXml = ToXML(dataTableAdaptorChild, idToFind,tab+"\t");
                            sb.Append(childXml);

                        }
                        sb.Append(tab+"</" + dataTable.Columns[j].ColumnName + ">\n");
                    }
                    else
                    {
                        sb.Append(tab+"<" + dataTable.Columns[j].ColumnName + ">" + dataTable.Rows[i].ItemArray[j] + "</" + dataTable.Columns[j].ColumnName + ">\n");
                
                    }
                }
            }

            string result = sb.ToString();
            return result;
        }
Пример #2
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var console = new Console();
            console.Show();

            //CatModel cats = new CatModel();
            ITableAdaptor cta = new MySqlTableAdaptor();

            if (DialogResult.Yes == MessageBox.Show("DropTables ?", "?", MessageBoxButtons.YesNo))
            {
                var tt = GetTypesInNamespace(Assembly.GetExecutingAssembly(), "WindowsFormsApplication1.Model");
                foreach (Type t in tt)
                {
                    cta.DropTable(t.Name);
                }
            }

            CreateForm(typeof(Cat));
            Application.Run();
        }