Esempio n. 1
0
 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();
     }
 }
Esempio n. 2
0
        private KlonsData()
        {
            _KlonsData   = this;
            CurrentDBTag = null;

            LoadSettings();
            LoadMasterList();

            if (Settings.MasterEntry.Name != "")
            {
                var me = MasterList.GetMasterEntryByName(Settings.MasterEntry.Name);
                if (me != null)
                {
                    Settings.MasterEntry.CopyFrom(me);
                }
            }

            _Params = new KlonsParams();

            ReportHelper = new ReportHelperF();

            _klonsDataSetHelper = new DataSetHelper(
                typeof(klonsDataSet),
                typeof(KlonsAdapters.TableAdapterManager),
                typeof(KlonsAdapters.QueriesTableAdapter),
                "ConnectionString1",
                KlonsF.Properties.Settings.Default);

            _dataSetHelpers["KlonsData"] = _klonsDataSetHelper;

            _klonsRepDataSetHelper = new DataSetHelper(
                typeof(klonsRepDataSet),
                typeof(KlonsRepAdapters.TableAdapterManager),
                null,
                "ConnectionString1",
                KlonsF.Properties.Settings.Default);

            _dataSetHelpers["KlonsRep"] = _klonsRepDataSetHelper;
        }
Esempio n. 3
0
        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)
            {
                Params.Save();
            }

            _klonsDataSetHelper = new DataSetHelper(
                typeof(klonsDataSet),
                typeof(KlonsAdapters.TableAdapterManager),
                typeof(KlonsAdapters.QueriesTableAdapter),
                "ConnectionString1",
                KlonsF.Properties.Settings.Default);

            _dataSetHelpers["KlonsData"] = _klonsDataSetHelper;

            _klonsRepDataSetHelper = new DataSetHelper(
                typeof(klonsRepDataSet),
                typeof(KlonsRepAdapters.TableAdapterManager),
                null,
                "ConnectionString1",
                KlonsF.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);
        }
Esempio n. 4
0
 public void SaveMasterList()
 {
     MasterList.SaveList(MasterListFileName);
 }