コード例 #1
0
ファイル: AutomobilesData.cs プロジェクト: GTVolk/DBAutoShop
        public static void LoadFromXML()
        {
            try
            {
                Manafacturers.LoadFromXML();
                Classes.LoadFromXML();
                Countries.LoadFromXML();
                BodyTypes.LoadFromXML();
                GearTypes.LoadFromXML();

                AutomobilesData DB = new AutomobilesData();
                DatabaseControlService.SQL.SQLDS = new DataSet();
                DatabaseControlService.SQL.SQLDS.ReadXml("XML\\AutomobilesData.XML");
                DataSet Base = new DataSet();
                Base.ReadXml("XML\\AutomobilesData.XML");
                if (Base.Tables.Count == 0)
                {
                    return;
                }
                if (DatabaseControlService.SQL.DataTableHasValues())
                {
                    for (int i = 0; i < Base.Tables["Table"].Rows.Count; i++)
                    {
                        int OLD_ValueID = Convert.ToInt32(Base.Tables["Table"].Rows[i][2]);
                        DatabaseControlService.SQL.SQLDS = new DataSet();
                        DatabaseControlService.SQL.SQLDS.ReadXml("XML\\Manafacturers.XML");
                        string OLD_Name = DatabaseControlService.SQL.GetValueByID(OLD_ValueID, 1, 0);
                        Base.Tables["Table"].Rows[i][2] = DatabaseControlService.DBECS.GetManafacturerIDByManafacturerName(OLD_Name);

                        OLD_ValueID = Convert.ToInt32(Base.Tables["Table"].Rows[i][4]);
                        DatabaseControlService.SQL.SQLDS = new DataSet();
                        DatabaseControlService.SQL.SQLDS.ReadXml("XML\\Classes.XML");
                        OLD_Name = DatabaseControlService.SQL.GetValueByID(OLD_ValueID, 1, 0);
                        Base.Tables["Table"].Rows[i][4] = DatabaseControlService.DBECS.GetClassIDByClassName(OLD_Name);

                        OLD_ValueID = Convert.ToInt32(Base.Tables["Table"].Rows[i][5]);
                        DatabaseControlService.SQL.SQLDS = new DataSet();
                        DatabaseControlService.SQL.SQLDS.ReadXml("XML\\Countries.XML");
                        OLD_Name = DatabaseControlService.SQL.GetValueByID(OLD_ValueID, 1, 0);
                        Base.Tables["Table"].Rows[i][5] = DatabaseControlService.DBECS.GetCountryIDByCountryName(OLD_Name);

                        OLD_ValueID = Convert.ToInt32(Base.Tables["Table"].Rows[i][7]);
                        DatabaseControlService.SQL.SQLDS = new DataSet();
                        DatabaseControlService.SQL.SQLDS.ReadXml("XML\\BodyTypes.XML");
                        OLD_Name = DatabaseControlService.SQL.GetValueByID(OLD_ValueID, 1, 0);
                        Base.Tables["Table"].Rows[i][7] = DatabaseControlService.DBECS.GetBodyIDByBodyName(OLD_Name);

                        OLD_ValueID = Convert.ToInt32(Base.Tables["Table"].Rows[i][23]);
                        DatabaseControlService.SQL.SQLDS = new DataSet();
                        DatabaseControlService.SQL.SQLDS.ReadXml("XML\\GearTypes.XML");
                        OLD_Name = DatabaseControlService.SQL.GetValueByID(OLD_ValueID, 1, 0);
                        Base.Tables["Table"].Rows[i][22] = DatabaseControlService.DBECS.GetGearIDByGearName(OLD_Name);

                        DB.Reset();
                        DB.LoadData(Base, i);
                        if (!DB.CheckAll())
                        {
                            DatabaseControlService.SQL.SqlProcduceTransactionCommand(DB.Insert());
                        }
                        else
                        {
                            DatabaseControlService.SQL.SqlProcduceCommand(SelectAll());
                            int ID = DatabaseControlService.SQL.GetIDByValue(DB.Model, 3, 0);
                            DB.Auto_ID = ID;
                            DatabaseControlService.SQL.SqlProcduceTransactionCommand(DB.Update());
                        }
                    }
                    DatabaseControlService.SQL.SQLDS = new DataSet();
                    DatabaseControlService.SQL.SQLDS.ReadXml("XML\\AutomobilesData.XML");
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("XML ERROR: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }