public IQueryable<SystemSettingViewModel> GetSystemSetting(String EventClass)
        {
            List<SystemSettingViewModel> ret = new List<SystemSettingViewModel>();

            var qry = db.SystemSetting.Where(x => x.Seq != 0);
            if(EventClass != "" && db.SystemSetting.Where(x => x.EventClass == EventClass).Count()!=0)
                qry = db.SystemSetting.Where(x => x.EventClass == EventClass);
            else
                qry = db.SystemSetting.Where(x => x.EventClass == null);
            foreach (SystemSetting o in qry)
            {
                SystemSettingViewModel s = new SystemSettingViewModel();

                s.AlertTimes = o.AlertTimes;
                s.EventClass = o.EventClass;
                s.isSysDefault = o.isSysDefault;
                s.Seq =o.Seq;
                s.SugArriveMin = o.SugArriveMin;
                s.SugFinishMin = o.SugFinishMin;
                s.AnnexNeed = o.AnnexNeed;
                s.AutoAssign = o.AutoAssign;
                s.AutoAssignUserType = o.AutoAssignUserType;
                s.AssignUserType = o.AssignUserType;
                s.ScheduleStartDTNeed = o.ScheduleStartDTNeed;
                s.Alert43Day = o.Alert43Day;
                s.ExamineNeed = o.ExamineNeed;

                ret.Add(s);
            }

            return ret.AsQueryable();
        }
        public String SaveSystemSetting(SystemSettingViewModel Setting)
        {
            String ret = "false";
            try
            {
                if (Setting.EventClass == null)
                {                
                    SystemSetting setting = db.SystemSetting.Find(db.SystemSetting.Where(x => x.EventClass == null).Select(x => x.Seq).First());

                    setting.SugArriveMin = Setting.SugArriveMin;
                    setting.SugFinishMin = Setting.SugFinishMin;
                    setting.AnnexNeed = Setting.AnnexNeed;
                    //setting.AutoAssign = Setting.AutoAssign;
                    setting.AutoAssign = false;
                    //setting.AutoAssignUserType = Setting.AutoAssignUserType;
                    setting.AutoAssignUserType = 1;
                    setting.ScheduleStartDTNeed = Setting.ScheduleStartDTNeed;
                    setting.AssignUserType = Setting.AssignUserType;
                    setting.Alert43Day = Setting.Alert43Day;
                    setting.ExamineNeed = Setting.ExamineNeed;

                    db.SaveChanges();
                    ret = "true";
                }
                else
                {
                    if (Setting.isSysDefault)
                    {
                        SystemSetting setting = new SystemSetting();

                        setting.EventClass = Setting.EventClass;
                        setting.AlertTimes = db.SystemSetting.Where(x => x.EventClass == null).Select(x => x.AlertTimes).First();
                        setting.SugArriveMin = Setting.SugArriveMin;
                        setting.SugFinishMin = Setting.SugFinishMin;
                        setting.isSysDefault = false;
                        setting.AnnexNeed = Setting.AnnexNeed;
                        //setting.AutoAssign = Setting.AutoAssign;
                        setting.AutoAssign = false;
                        //setting.AutoAssignUserType = Setting.AutoAssignUserType;
                        setting.AutoAssignUserType = 1;
                        setting.ScheduleStartDTNeed = Setting.ScheduleStartDTNeed;
                        setting.AssignUserType = Setting.AssignUserType;
                        setting.Alert43Day = Setting.Alert43Day;
                        setting.ExamineNeed = Setting.ExamineNeed;


                        db.SystemSetting.Add(setting);
                        db.SaveChanges();

                        ret = "true";
                    }
                    else
                    {
                        SystemSetting setting = db.SystemSetting.Find(db.SystemSetting.Where(x => x.EventClass==Setting.EventClass).Select(x => x.Seq).First());

                        setting.SugArriveMin = Setting.SugArriveMin;
                        setting.SugFinishMin = Setting.SugFinishMin;
                        setting.AnnexNeed = Setting.AnnexNeed;
                        //setting.AutoAssign = Setting.AutoAssign;
                        setting.AutoAssign = false;
                        //setting.AutoAssignUserType = Setting.AutoAssignUserType;
                        setting.AutoAssignUserType = 1;
                        setting.ScheduleStartDTNeed = Setting.ScheduleStartDTNeed;
                        setting.AssignUserType = Setting.AssignUserType;
                        setting.Alert43Day = Setting.Alert43Day;
                        setting.ExamineNeed = Setting.ExamineNeed;

                        db.SaveChanges();
                        ret = "true";
                    }

                }
            }
            catch
            {
                ret = "false";
            }
            return ret;
        }