I'm a beginner with dhtmlx scheduler, I use dbfirst with mvc4 razor syntax. So please can anybody help me to set the start time and endtime values I'm getting from the database: here is my code:

controller:

sched.Config.first_hour = 8;
sched.Config.last_hour = 19;
 public string GetDbValues()
            {
                string strState = "";
               List<tblSettings> settings = new List<tblSettings>();
                settings = _config.GetSettings();
                var defaultState = from setting in settings
                  where (setting.Desc == "start time"
                  || setting.Desc == "end time")  
// starttime as 08 and end time as 20 from database
                select setting.Settings;
                foreach (var oState in defaultState)
                {strState += oState + "|";
                }
               strState = strState.Remove(strState.Length - 1);

                return strState;
            }

I get the values for first_hour and last_hour as string from the output. How to assign this string value to the first_hour and last_hour?

//I use linq to get the db values because of the table structure: ID(int), Settings(nvarchar) ,Desc (nvarchar)

enter image description here

有帮助吗?

解决方案

why do you concatenate the settings into string? More comprehensive data format will simplify the task. You could return List as it is and then just iterate it with foreach, applying needed settings. If for some reason you don't want to pass tblSettings objects, you can select data into Dictionary and then again, apply the values

var data = _config.GetSettings().ToDictionary(
                s => s.Desc, 
                s => s.Setting, 
                StringComparer.Ordinal);


if(data.ContainsKey("start time"))
    scheduler.Config.first_hour = int.Parse(data["start time"]);

if (data.ContainsKey("end time"))
    scheduler.Config.first_hour = int.Parse(data["end time"]);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top