private ListModel GetListModel(string listName, string laboratoryBookName)
        {
            var connectionString = ConfigurationManager.ConnectionStrings["cs_login"].ConnectionString;
            var connection       = new MySqlConnection(connectionString);

            var sqlCommand = new MySqlCommand()
            {
                Connection  = connection,
                CommandText = $"SELECT `{listName}` FROM `{listName}s_{laboratoryBookName}`;"
            };

            connection.Open();

            var dbReader  = sqlCommand.ExecuteReader();
            var dataTable = new DataTable();

            dataTable.Load(dbReader);

            var listModel = new ListModel();

            foreach (DataRow row in dataTable.Rows)
            {
                var value = new ListValueModel()
                {
                    ListValue    = (string)row[$"{listName}"],
                    OldListValue = (string)row[$"{listName}"]
                };

                listModel.Values.Add(value);
            }
            listModel.ListName = listName;

            if (listModel.Values.Any())
            {
                listModel.SelectedValue = listModel.Values.First();
            }

            connection.Close();
            sqlCommand?.Dispose();

            return(listModel);
        }
Пример #2
0
 public ListModel()
 {
     this.Values        = new ObservableCollection <ListValueModel>();
     this.ListName      = String.Empty;
     this.SelectedValue = new ListValueModel();
 }