public static void LoadFromXML() { try { Workplaces.LoadFromXML(); Offices.LoadFromXML(); Workers DB = new Workers(); DatabaseControlService.SQL.SQLDS = new DataSet(); DatabaseControlService.SQL.SQLDS.ReadXml("XML\\Workers.XML"); DataSet Base = new DataSet(); Base.ReadXml("XML\\Workers.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][5]); DatabaseControlService.SQL.SQLDS = new DataSet(); DatabaseControlService.SQL.SQLDS.ReadXml("XML\\Workplaces.XML"); string OLD_Name = DatabaseControlService.SQL.GetValueByID(OLD_ValueID, 1, 0); Base.Tables["Table"].Rows[i][5] = DatabaseControlService.DBECS.GetWorkplaceIDByWorkplaceName(OLD_Name); OLD_ValueID = Convert.ToInt32(Base.Tables["Table"].Rows[i][6]); DatabaseControlService.SQL.SQLDS = new DataSet(); DatabaseControlService.SQL.SQLDS.ReadXml("XML\\Offices.XML"); OLD_Name = DatabaseControlService.SQL.GetValueByID(OLD_ValueID, 1, 0); Base.Tables["Table"].Rows[i][6] = DatabaseControlService.DBECS.GetOfficeIDByOfficeName(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.Telephone, 4, 0); DB.Worker_ID = ID; DatabaseControlService.SQL.SqlProcduceTransactionCommand(DB.Update()); } } DatabaseControlService.SQL.SQLDS = new DataSet(); DatabaseControlService.SQL.SQLDS.ReadXml("XML\\Workers.XML"); } } catch (System.Exception ex) { MessageBox.Show("XML ERROR: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public static void SaveToXML() { try { Workplaces.SaveToXML(); Offices.SaveToXML(); DatabaseControlService.SQL.SqlProcduceCommand(SelectAll()); DatabaseControlService.SQL.SQLDS.WriteXml("XML\\Workers.XML"); } catch (System.Exception ex) { MessageBox.Show("XML ERROR: " + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }