public static MasterList LoadList(string filename) { MasterList list = new MasterList(); if (!File.Exists(filename)) { return(list); } XmlSerializer xs = null; FileStream fs = null; try { //xs = new XmlSerializer(typeof(MasterList)); xs = Utils.CreateDefaultXmlSerializer(typeof(MasterList)); fs = new FileStream(filename, FileMode.Open); list = (MasterList)xs.Deserialize(fs); return(list); } catch (Exception) { //LogError(e.Message); list = new MasterList(); return(list); } finally { if (fs != null) { fs.Close(); } } }
private KlonsData() { _KlonsData = this; CurrentDBTag = null; LoadSettings(); LoadMasterList(); ColorThemeHelper.MyToolStripRenderer.SetColorTheme(Settings.ColorTheme); if (Settings.MasterEntry.Name != "") { var me = MasterList.GetMasterEntryByName(Settings.MasterEntry.Name); if (me != null) { Settings.MasterEntry.CopyFrom(me); } } _Params = new KlonsParams(); ReportHelper = new ReportHelperP(); _klonsDataSetHelper = new DataSetHelper( typeof(KlonsPDataSet), typeof(KlonsAdapters.TableAdapterManager), typeof(KlonsAdapters.QueriesTableAdapter), "ConnectionString1", KlonsP.Properties.Settings.Default); _dataSetHelpers["KlonsData"] = _klonsDataSetHelper; _klonsRepDataSetHelper = new DataSetHelper( typeof(KlonsPRepDataSet), typeof(KlonsRepAdapters.TableAdapterManager), null, "ConnectionString1", KlonsP.Properties.Settings.Default); _dataSetHelpers["KlonsRep"] = _klonsRepDataSetHelper; }
public bool ConnectTo(MasterEntry me, string username, string userpsw) { string filename = GetFileName(me); if (!File.Exists(filename)) { throw new Exception($"Nav faila: [{filename}]"); } if (CurrentDBTag != null) { try { Params.Save(); if (KlonsTableAdapterManager?.TUSERSTableAdapter?.Connection != null) { KlonsTableAdapterManager.TUSERSTableAdapter.Connection.StateChange -= Connection_StateChange; } } catch (Exception) { } } _klonsDataSetHelper = new DataSetHelper( typeof(KlonsPDataSet), typeof(KlonsAdapters.TableAdapterManager), typeof(KlonsAdapters.QueriesTableAdapter), "ConnectionString1", KlonsP.Properties.Settings.Default); _dataSetHelpers["KlonsData"] = _klonsDataSetHelper; _klonsRepDataSetHelper = new DataSetHelper( typeof(KlonsPRepDataSet), typeof(KlonsRepAdapters.TableAdapterManager), null, "ConnectionString1", KlonsP.Properties.Settings.Default); _dataSetHelpers["KlonsRep"] = _klonsRepDataSetHelper; string newconnstr = MasterList.GetTemplateByName(me.ConnStr); if (string.IsNullOrEmpty(newconnstr)) { newconnstr = "character set=UTF8;" + "data source=localhost;" + @"initial catalog={0};" + "user id=aivars;" + "password=parole"; } newconnstr = string.Format(newconnstr, filename, username); var s1 = CheckConnectionString(newconnstr); if (s1 == null) { throw new Exception($"Nekorekti pieslēguma dati:\n{newconnstr}"); } newconnstr = s1; _currentUserName = username; _klonsDataSetHelper.ConnectTo(newconnstr); _klonsRepDataSetHelper.ConnectTo(newconnstr); KlonsTableAdapterManager.TUSERSTableAdapter.Connection.StateChange += Connection_StateChange; KlonsTableAdapterManager.TUSERSTableAdapter.Connection.Open(); CurrentDBTag = new MasterEntry(me); return(true); }
public void SaveMasterList() { MasterList.SaveList(MasterListFileName); }