Ejemplo n.º 1
0
        /// <summary>
        /// 編輯Program資料
        /// </summary>
        /// <param name="Program">ProgramModel</param>
        /// <returns></returns>
        public bool ProgramEdit(ProgramModel Program)
        {
            DbTransaction objTrans = DbAccess.CreateDbTransaction();


            try
            {
                DbAccess.ExecuteNonQuery("UPDATE tbProgram SET ProgID=@ProgID,ProgName=@ProgName,Power=@Power,Url=@Url,FlagType=@FlagType WHERE ProgID = @EditPK ", objTrans,
                                         new DbParameter[] {
                    DataAccess.CreateParameter("EditPK", DbType.String, Program.EditPK.ToString()),
                    DataAccess.CreateParameter("ProgID", DbType.String, Program.ProgID.ToString()),
                    DataAccess.CreateParameter("ProgName", DbType.String, Program.ProgName.ToString()),
                    DataAccess.CreateParameter("Power", DbType.Int64, Program.Power.ToString()),
                    DataAccess.CreateParameter("Url", DbType.String, Program.Url.ToString()),
                    DataAccess.CreateParameter("FlagType", DbType.String, Program.FlagType.ToString())
                });

                objTrans.Commit();

                return(true);
            }
            catch
            {
                objTrans.Rollback();
                return(false);
            }
            finally
            {
                if (objTrans != null)
                {
                    objTrans.Dispose();
                }
            }
        }
Ejemplo n.º 2
0
        public ActionResult Program()
        {
            try
            {
                sSQL = " SELECT * FROM mainpath";
                MySqlDataReader dr = conn1.ExecuteReader(sSQL);

                if (dr.Read())
                {
                    ProgramModel rec = new ProgramModel
                    {
                        txtCoName     = dr["CONAME"].ToString(),
                        txtAdd1       = dr["ADD1"].ToString(),
                        txtLengthMenu = dr["LENGTHMENU"].ToString(),
                    };

                    ViewBag.FieldValue = rec;
                    return(View());
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }

            return(View());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 新增Program資料
        /// </summary>
        /// <param name="Program">ProgramModel</param>
        /// <returns></returns>
        public bool ProgramAdd(ProgramModel Program)
        {
            DbTransaction objTrans = DbAccess.CreateDbTransaction();


            try
            {
                DbAccess.ExecuteNonQuery("INSERT INTO tbProgram(ProgID,ProgName,Power,Url,FlagType) VALUES (@ProgID,@ProgName,@Power,@Url,@FlagType) ", objTrans,
                                         new DbParameter[] {
                    DataAccess.CreateParameter("ProgID", DbType.String, Program.ProgID.ToString()),
                    DataAccess.CreateParameter("ProgName", DbType.String, Program.ProgName.ToString()),
                    DataAccess.CreateParameter("Power", DbType.Int64, Program.Power.ToString()),
                    DataAccess.CreateParameter("Url", DbType.String, Program.Url.ToString()),
                    DataAccess.CreateParameter("FlagType", DbType.String, Program.FlagType.ToString())
                });

                objTrans.Commit();

                return(true);
            }
            catch
            {
                objTrans.Rollback();
                return(false);
            }
            finally
            {
                if (objTrans != null)
                {
                    objTrans.Dispose();
                }
            }
        }
Ejemplo n.º 4
0
        public CircularPB()
        {
            maxValue                 = 100;
            value                    = maxValue;
            minValue                 = 0;
            progressColor            = Color.LightBlue;
            innerRadius              = 30;
            outerRadius              = 50;
            stroke                   = 10;
            MinimumSize              = new System.Drawing.Size(60, 60);
            automaticFontCalculation = true;
            allowText                = true;
            transparency             = true;
            brush                    = new SolidBrush(progressColor);
            SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
            Location       = new Point(100, 100);
            BackColor      = Color.Transparent;
            timer.Tick    += timer_Tick;
            timer.Interval = 1;
            timer.Enabled  = true;

            var result = string.Empty;

            using (var webClient = new System.Net.WebClient())
            {
                result = webClient.DownloadString(programJsonFile);
            }
            JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();

            model = jsonSerializer.Deserialize <ProgramModel>(result);
        }
Ejemplo n.º 5
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            //If this is 0 then there is nothing to show. The model is blank
            if (selectedProgram.id == 0)
            {
                return;
            }

            //Don't let them delete it by accident
            DialogResult result = MessageBox.Show(
                "Wow!! Wait...are you sure?",
                "Important Question",
                MessageBoxButtons.YesNo);

            //Abort!!
            if (result == DialogResult.No)
            {
                return;
            }

            //Delete the reord from the table and update the ListView
            try
            {
                new ProgramTable().delete(selectedProgram.id);

                //reset everything
                ClearInputs();
                RefreshList();
                selectedProgram = new ProgramModel();
            }
            catch (Exception ex)
            {
                new ExceptionMessageGenerator().generateMessage(ex.Message);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        ///		Procesa la generación de documentación de un programa
        /// </summary>
        internal DocumentFileModelCollection Process(ProgramModel objProgram)
        {
            NameSpaceGroupModelCollection objColGroups    = new Prepare.NameSpaceGroupGenerator().Generate(objProgram);
            DocumentFileModelCollection   objColDocuments = new DocumentFileModelCollection();

            // Carga las plantillas
            Templates = new Repository.Templates.TemplateRepository().Load(DocumentationProcessor.Parameters.TemplateFileName);
            // Crea los documentos
            foreach (NameSpaceGroupModel objGroup in objColGroups)
            {
                if (Templates.MustGenerateFile(objGroup, DocumentationProcessor.Parameters))
                {
                    DocumentFileModel objDocument = new DocumentFileModel(null, objGroup.NameSpace, 0);

                    // Procesa la estructura del lenguaje
                    if (objGroup.NameSpace != null)
                    {
                        Generate(objGroup.NameSpace, objDocument);
                    }
                    else
                    {
                        objDocument.Name = objGroup.Name;
                    }
                    // Añade el documento a la colección
                    objColDocuments.Add(objDocument);
                }
            }
            // Graba los documentos
            ProcessDocuments(objColDocuments);
            // Devuelve los documentos
            return(objColDocuments);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 番組表取得処理
        /// </summary>
        /// <param name="stationId"></param>
        /// <returns></returns>
        private List <Entities.Program> RefreshPrograms(string stationId)
        {
            using (SqliteConnection)
            {
                var sModel   = new StationModel(SqliteConnection);
                var station  = sModel.GetById(stationId);
                var programs = new List <Entities.Program>();
                if (station == null)
                {
                    return(programs);
                }

                switch (station.Type)
                {
                case Define.Radiko.TypeName:

                    programs = Radiko.GetPrograms(station).Result;
                    break;

                case Define.Nhk.TypeName:
                    programs = Nhk.GetPrograms(station, DateTime.Now, DateTime.Now.AddDays(1)).Result;
                    break;
                }


                var pModel = new ProgramModel(SqliteConnection);
                pModel.Refresh(programs);

                return(programs);
            }
        }
Ejemplo n.º 8
0
        public IActionResult AddProgram(ProgramModel programModel)
        {
            string[] pathParts = programModel.ImageFile.FileName.Split("\\");

            var fileName = pathParts.Last();

            var imagePath = _env.WebRootPath + "\\images\\" + fileName;

            //var fileInfo = new FileInfo(programModel.ImagePath);

            using (var stream = new FileStream(imagePath, FileMode.Create))
            {
                programModel.ImageFile.CopyTo(stream);
            }

            var optionsBuilder = new DbContextOptionsBuilder <PowerContext>();

            optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=PowerDB;Trusted_Connection=True;ConnectRetryCount=0");

            var trainingItemImage = new TrainingItemImage();

            trainingItemImage.FilePath = "~/images/" + fileName;

            var imageRepo = new TrainingItemImageDbo(optionsBuilder);

            programModel.Program.Image = trainingItemImage;

            var programRepo = new ProgramDbo(optionsBuilder);

            programRepo.Add(programModel.Program);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 9
0
        public ActionResult GroupForm()
        {
            ViewData["LoginUserInfo"] = LoginUserInfo;



            string       ProgramID  = "G001";
            ProgramModel SysProgram = null;

            if (!GeneralObj.CheckProgID(LoginUserInfo.ProgramList, ProgramID))
            {
                return(View("../SysMsg/NoAccess"));
            }
            else
            {
                SysProgram             = GeneralObj.GetProgram(LoginUserInfo.ProgramList, ProgramID);
                ViewData["SysProgram"] = SysProgram;
            }



            UserFreeStyleModel UserFreeStyle;

            UserFreeStyle = JsonConvert.DeserializeObject <UserFreeStyleModel>(Session[UserFreeStyle_id].ToString());



            try
            {
                if (UserFreeStyle.SignId == "")
                {
                    GroupModel Group = new GroupModel();
                    Group.Mode      = "ADD"; //新增模式
                    Group.ViewLevel = "C";


                    ProgramModelFactory ProgramModelFactorys = new ProgramModelFactory();
                    Group.GroupProgramList = ProgramModelFactorys.GetGroupProgramList();


                    ViewData["Group"] = Group;
                }
                else
                {
                    GroupModel Group = ModelFactory.GetGroupData(UserFreeStyle.SignId);
                    Group.Mode        = "EDIT"; //修改模式
                    ViewData["Group"] = Group;
                }
            }
            catch (Exception ex)
            {
            }
            catch
            {
            }



            return(View());
        }
Ejemplo n.º 10
0
        public List <ProgramModel> getProgram()
        {
            List <ProgramModel> listStudent = new List <ProgramModel>();

            try
            {
                string          Query = "Select code,name,description from college_db.program";
                MySqlConnection con   = new MySqlConnection(DBConnection.ConnectionString);

                MySqlCommand    cmd = new MySqlCommand(Query, con);
                MySqlDataReader myReader;
                con.Open();
                myReader = cmd.ExecuteReader();

                while (myReader.Read())
                {
                    ProgramModel objStudent = new ProgramModel();
                    objStudent.ProgramCode        = myReader["code"].ToString();
                    objStudent.ProgramName        = myReader["name"].ToString();
                    objStudent.ProgramDescription = myReader["description"].ToString();
                    listStudent.Add(objStudent);
                }
            }
            catch (Exception ex)
            {
            }

            return(listStudent);
        }
Ejemplo n.º 11
0
        public JsonResult ProgramFormAdd(string ProgramJson)
        {
            ProgramModel Program = null;

            try
            {
                Program = JsonConvert.DeserializeObject <ProgramModel>(ProgramJson);


                if (ModelFactory.ProgramAdd(Program))
                {
                    return(Json("1"));//代表已經處裡完
                }
                else
                {
                    return(Json(""));//失敗
                }
            }
            catch (Exception ex)
            {
                return(Json(ex.Message));
            }
            catch
            {
                return(Json("系統發生錯誤"));
            }
        }
Ejemplo n.º 12
0
        public void Setup()
        {
            new DataStoreTableHelper().clearAllTables();

            ProgramVarietyModel programeVarietyModel = new ProgramVarietyModel();

            programeVarietyModel.depositAmount = 20.0;
            programeVarietyModel.sessionCost   = 20.0;
            programeVarietyModel.fullPaymentPercentageDiscount = 20;
            programeVarietyModel.name             = "Regular";
            programeVarietyModel.dogSpacesMaximum = 50;
            programeVarietyModel.noOfClasses      = 50;

            ProgramVarietyTable programVarietyTable = new ProgramVarietyTable();

            programeCostId = programVarietyTable.create(programeVarietyModel);

            ProgramModel programModel = new ProgramModel();

            programModel.programVarietyId = programeCostId;

            ProgramTable programTable = new ProgramTable();

            programId = programTable.create(programModel);

            StaffModel staffModel = new StaffModel();

            staffModel.name = "Bob";

            StaffTable staffTable = new StaffTable();

            staffId = staffTable.create(staffModel);
        }
Ejemplo n.º 13
0
        public async Task <ApiResponse> Timefree(string programId)
        {
            return(await Execute(() =>
            {
                _timefreeProgress = 0;
                using (SqliteConnection)
                {
                    var pModel = new ProgramModel(SqliteConnection);
                    var program = pModel.Get(programId);

                    var cModel = new ConfigModel(SqliteConnection);
                    var config = cModel.Get();

                    if (program != null)
                    {
                        var rr = new RadikoRecorder(config)
                        {
                            ChangeProgress = (progress) =>
                            {
                                _timefreeProgress = progress;
                            }
                        };
                        rr.TimeFree(program);
                    }
                    Result.Result = true;
                }
            }));
        }
Ejemplo n.º 14
0
        public async Task <int> DeleteProgram(ProgramModel programModel)
        {
            List <ProgramModel> programs = await GetPrograms();

            var newlist = programs.Where(p => p.SeriesId != programModel.SeriesId &&
                                         p.Date != programModel.Date &&
                                         p.Screen != programModel.Screen &&
                                         p.Views != programModel.Views).Select(p => p).ToList();

            if (programs.Count == newlist.Count)
            {
                return(0);
            }
            else
            {
                StringBuilder sb = new StringBuilder("seriesId,date,screen,views" + Environment.NewLine);

                foreach (ProgramModel item in newlist)
                {
                    sb.Append($@"{item.SeriesId},{item.Date.ToString("yyyyMMdd")},{item.Screen},{item.Views}" + Environment.NewLine);
                }

                await File.WriteAllTextAsync(inputFile, sb.ToString());

                return(programs.Count - newlist.Count);
            }
        }
Ejemplo n.º 15
0
        public ProgrammingViewModel(ProgramModel model, LogicDeviceProvider logicDeviceProvider,
                                    LogicElementsFactory elementsFactory, IApplicationGlobalCommands globalCommands, ISerializerService serializerService)
        {
            this._programModel = model;
            this._applicationGlobalCommands = globalCommands;
            this._elementsFactory           = elementsFactory;

            this._serializerService   = serializerService;
            this._logicDeviceProvider = logicDeviceProvider;

            this.SchemesCollection    = new ObservableCollection <SchemeTabViewModel>();
            this.ElementsLibrary      = new ObservableCollection <LogicElementViewModel>();
            this.ConnectionCollection = new ObservableCollection <ConnectionViewModel>();

            this.NewSchemeCommand     = new RelayCommand(this.CreateNewScheme);
            this.SaveProjectCommand   = new RelayCommand(this.SaveProject, this.CanSaveProject);
            this.LoadProjectCommand   = new RelayCommand(this.LoadProject);
            this.DeleteCommand        = new RelayCommand(this.DeleteSelectedElements, this.CanDelete);
            this.ZoomIncrementCommand = new RelayCommand(this.ZoomIncrement, this.CanZooming);
            this.ZoomDecrementCommand = new RelayCommand(this.ZoomDecrement, this.CanZooming);

            this.WriteLogicCommand  = new RelayCommand(this.OnWriteCommand, this.CanWriteLogic);
            this.ReadLogicCommand   = new RelayCommand(this.OnReadCommand, this.CanReadLogic);
            this.StopEmulationLogic = new RelayCommand(this.OnStopEmulation);
        }
Ejemplo n.º 16
0
        public void GivenValidViewModelHasSelectedProviders_WhenEdit_ThenProviderAssociationsChange()
        {
            try
            {
                EducationContext.Database.ExecuteSqlCommand("Update SSD.StudentAssignedOffering Set IsActive = 0");
                var          expected  = new int[] { 1, 2 };
                ProgramModel viewModel = new ProgramModel {
                    Id = 2, Name = "something valid", SelectedProviders = expected, SelectedServiceTypes = new List <int> {
                        2
                    }
                };

                Target.Edit(viewModel);

                using (EducationDataContext assertContext = new EducationDataContext())
                {
                    var actual = assertContext.Programs.Include("ServiceOfferings.Provider").Single(p => p.Id == viewModel.Id).ServiceOfferings.Where(s => s.IsActive).Select(s => s.Provider).Distinct();
                    CollectionAssert.AreEquivalent(expected, actual.Select(p => p.Id).ToList());
                }
            }
            finally
            {
                AssemblySetup.ForceDeleteEducationDatabase("SSD");
            }
        }
Ejemplo n.º 17
0
        public IActionResult AddProgram(int programId, string operationType)
        {
            var model = new ProgramModel(programId, operationType, _programService);

            _session.SetString("OperationType", operationType);
            return(PartialView("_AddProgram", model));
        }
Ejemplo n.º 18
0
        /// <summary>
        ///		Interpreta un programa o un archivo
        /// </summary>
        private ProgramModel ParseProgram(string strFileName)
        {
            SolutionVisualStudioModel objSolution = new SolutionVisualStudioModel(strFileName);
            ProgramModel objProgram = new ProgramModel(strFileName);

            // Carga la solución
            objSolution.Load();
            // Interpreta los proyectos
            foreach (ProjectVisualStudioModel objProject in objSolution.Projects)
            {
                foreach (FileVisualStudioModel objFile in objProject.Files)
                {
                    if (!System.IO.File.Exists(objFile.FullFileName))
                    {
                        objProgram.Errors.Add("No se encuentra el archivo " + objFile.FullFileName);
                    }
                    else
                    {
                        CompilationUnitModel objUnit = ParseFile(objFile.FullFileName);

                        if (objUnit != null)
                        {
                            objProgram.CompilationUnits.Add(objUnit);
                        }
                    }
                }
            }
            // Devuelve el programa interpretado
            return(objProgram);
        }
Ejemplo n.º 19
0
        public void Update_CreatedUpdateAndRead1Record_UpdatedValues()
        {
            //Assemble
            ProgramModel programModel = new ProgramModel();

            programModel.programTypeId    = programTypeId;
            programModel.programCostId    = programCostId;
            programModel.dogSpacesMaximum = 10;
            programModel.noOfClasses      = 6;
            ProgramTable programTable = new ProgramTable();
            int          programID    = programTable.create(programModel);

            programModel.id               = programID;
            programModel.programTypeId    = programTypeId;
            programModel.programCostId    = programCostId;
            programModel.dogSpacesMaximum = 12;
            programModel.noOfClasses      = 7;

            //Act
            programTable.update(programModel);
            ProgramModel actual = programTable.read(programID);

            //Assert
            Assert.AreEqual(programModel.programTypeId, actual.programTypeId);
            Assert.AreEqual(programModel.programCostId, actual.programCostId);
            Assert.AreEqual(programModel.dogSpacesMaximum, actual.dogSpacesMaximum);
            Assert.AreEqual(programModel.noOfClasses, actual.noOfClasses);
        }
Ejemplo n.º 20
0
        protected string IsValid(ProgramModel model)
        {
            var listProgramModels = new List <ProgramModel>();

            listProgramModels = _service.GetProgramModels();

            if (model == null)
            {
                return("Não foi possivel encontrar o programa de aquecimento");
            }

            if (model.Name.IsNull() && !model.Potency.HasPositiveValue() || model.Potency < 1 || model.Potency > 10)
            {
                return("Por favor informe uma potência entre 1 e 10");
            }
            else if (model.Name.IsNull() && model.Time < 1 || model.Time > 120)
            {
                return("Por favor informe um intervalo de tempo entre 1 segundo e 2 minutos");
            }
            else if (!model.Potency.HasPositiveValue() && !model.Time.HasPositiveValue() && !listProgramModels.Select(p => p.Name.ToLower()).Contains(model.Name.ToLower()))
            {
                return("Programa de aquecimento não encontrado");
            }

            return("");
        }
Ejemplo n.º 21
0
        public ActionResult ManageOutMan()
        {
            ViewData["LoginUserInfo"] = LoginUserInfo;



            string       ProgramID  = "W004";
            ProgramModel SysProgram = null;

            if (!GeneralObj.CheckProgID(LoginUserInfo.ProgramList, ProgramID))
            {
                return(View("../SysMsg/NoAccess"));
            }
            else
            {
                SysProgram             = GeneralObj.GetProgram(LoginUserInfo.ProgramList, ProgramID);
                ViewData["SysProgram"] = SysProgram;
            }

            UserFreeStyleModel UserFreeStyle;

            UserFreeStyle = JsonConvert.DeserializeObject <UserFreeStyleModel>(Session[UserFreeStyle_id].ToString());



            EmpModel Emp = ModelFactory.GetOutMan(UserFreeStyle.SignId);


            ViewData["Emp"] = Emp;


            return(View());
        }
Ejemplo n.º 22
0
        public ActionResult HolidayForm()
        {
            ViewData["LoginUserInfo"] = LoginUserInfo;



            string       ProgramID  = "Z001";
            ProgramModel SysProgram = null;

            if (!GeneralObj.CheckProgID(LoginUserInfo.ProgramList, ProgramID))
            {
                return(View("../SysMsg/NoAccess"));
            }
            else
            {
                SysProgram             = GeneralObj.GetProgram(LoginUserInfo.ProgramList, ProgramID);
                ViewData["SysProgram"] = SysProgram;
            }

            UserFreeStyleModel UserFreeStyle;

            UserFreeStyle = JsonConvert.DeserializeObject <UserFreeStyleModel>(Session[UserFreeStyle_id].ToString());


            HolidayModel Holiday = ModelFactory.GetHolidayData(UserFreeStyle.SignId);

            ViewData["Holiday"] = Holiday;

            return(View());
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 全番組表再取得
        /// </summary>
        private void RefreshTimeTable()
        {
            using (var con = new SqliteConnection($"Data Source={Define.File.DbFile}"))
            {
                var sw = new Stopwatch();
                sw.Start();
                con.Open();
                var sModel = new StationModel(con);
                var pModel = new ProgramModel(con);
                foreach (var station in sModel.Get(Define.Radiko.TypeName))
                {
                    try
                    {
                        var programs = Radiko.GetPrograms(station).Result;
                        pModel.Refresh(programs);
                    }
                    catch (Exception e)
                    {
                        Global.Logger.Error($"{e.Message}¥r¥n{e.StackTrace}");
                    }
                }

                _refreshTimetableDate = DateTime.Now;
                _timetableLock        = false;
                sw.Stop();
                Global.Logger.Info($"番組表全更新:{sw.Elapsed}");
            }
        }
Ejemplo n.º 24
0
        public ActionResult Index()
        {
            ViewData["LoginUserInfo"] = LoginUserInfo;

            string       ProgramID  = "Z001";
            ProgramModel SysProgram = null;

            if (!GeneralObj.CheckProgID(LoginUserInfo.ProgramList, ProgramID))
            {
                return(View("../SysMsg/NoAccess"));
            }
            else
            {
                SysProgram             = GeneralObj.GetProgram(LoginUserInfo.ProgramList, ProgramID);
                ViewData["SysProgram"] = SysProgram;
            }


            UserFreeStyleModel UserFreeStyle;

            try
            {
                if (Request["action"] == "BACK" && Session[UserFreeStyle_id] != null)
                {
                    UserFreeStyle = JsonConvert.DeserializeObject <UserFreeStyleModel>(Session[UserFreeStyle_id].ToString());
                }
                else
                {
                    UserFreeStyle = new UserFreeStyleModel()
                    {
                        Name          = UserFreeStyle_id,
                        OrderField    = "YearId",
                        OrderType     = "DESC",
                        PageNum       = "0",
                        SearchCompany = GeneralObj.SearchCompanyDefault(LoginUserInfo, SysProgram),
                        SearchText    = "", //搜尋狀態
                    };
                }
            }
            catch
            {
                UserFreeStyle = new UserFreeStyleModel()
                {
                    Name          = UserFreeStyle_id,
                    OrderField    = "YearId",
                    OrderType     = "DESC",
                    PageNum       = "0",
                    SearchCompany = GeneralObj.SearchCompanyDefault(LoginUserInfo, SysProgram),
                    SearchText    = "", //搜尋狀態
                };
            }


            Session[UserFreeStyle_id] = JsonConvert.SerializeObject(UserFreeStyle);
            ViewData["UserFreeStyle"] = UserFreeStyle;



            return(View());
        }
Ejemplo n.º 25
0
        public void GivenViewModel_WhenEdit_ThenStateCopiedToEntityToUpdate()
        {
            int          id        = 2;
            ProgramModel viewModel = new ProgramModel
            {
                Id           = id,
                Name         = "Mortal Combat",
                StartDate    = new DateTime(2001, 4, 6),
                EndDate      = new DateTime(2001, 10, 11),
                Purpose      = "Don't worry, it is just a video game.  It teaches important life lessons....really.",
                ContactEmail = "*****@*****.**",
                ContactName  = "Bob",
                ContactPhone = "123-456-7890"
            };
            Program toUpdate = Data.Programs.Single(p => p.Id == id);

            Target.Edit(viewModel);

            Assert.AreEqual(viewModel.Name, toUpdate.Name);
            Assert.AreEqual(viewModel.StartDate, toUpdate.StartDate);
            Assert.AreEqual(viewModel.EndDate, toUpdate.EndDate);
            Assert.AreEqual(viewModel.Purpose, toUpdate.Purpose);
            Assert.AreEqual(viewModel.ContactEmail, toUpdate.ContactInfo.Email);
            Assert.AreEqual(viewModel.ContactName, toUpdate.ContactInfo.Name);
            Assert.AreEqual(viewModel.ContactPhone, toUpdate.ContactInfo.Phone);
        }
Ejemplo n.º 26
0
        public void ReadAll_Create3Records_CountIs3()
        {
            //Assemble
            ProgramModel programModel1 = new ProgramModel();

            programModel1.programVarietyId = programVarietyId;


            ProgramModel programModel2 = new ProgramModel();

            programModel2.programVarietyId = programVarietyId;


            ProgramModel programModel3 = new ProgramModel();

            programModel3.programVarietyId = programVarietyId;


            ProgramTable programTable = new ProgramTable();
            int          expected     = 3;

            //Act
            int programID1             = programTable.create(programModel1);
            int programID2             = programTable.create(programModel2);
            int programID3             = programTable.create(programModel3);
            List <ProgramModel> actual = programTable.readAll();

            //Assert
            Assert.AreEqual(expected, actual.Count);
        }
Ejemplo n.º 27
0
        /// <summary>
        /// RG01 外出異常表
        /// </summary>
        /// <returns></returns>
        public ActionResult RG01()
        {
            ViewData["LoginUserInfo"] = LoginUserInfo;


            string       ProgramID  = "RG01";//員工外出異常表
            ProgramModel SysProgram = null;

            if (!GeneralObj.CheckProgID(LoginUserInfo.ProgramList, ProgramID))
            {
                return(View("../SysMsg/NoAccess"));
            }
            else
            {
                SysProgram             = GeneralObj.GetProgram(LoginUserInfo.ProgramList, ProgramID);
                ViewData["SysProgram"] = SysProgram;
            }



            ReportFormModel ReportForm = new ReportFormModel();

            ReportForm.Company      = LoginUserInfo.Company;
            ReportForm.DepartMentNo = GeneralObj.SearchDepartMentDefault(LoginUserInfo, SysProgram);
            ReportForm.EmpNo        = "";
            ReportForm.StartDate    = DateTime.Now.ToString("yyyy-MM-dd");
            ReportForm.EndDate      = DateTime.Now.ToString("yyyy-MM-dd");

            ViewData["ReportForm"] = ReportForm;

            return(View());
        }
Ejemplo n.º 28
0
        public ProgramModel GetProgramData(string ProgID)
        {
            DataTable dt = DbAccess.ExecuteDataTable("SELECT * FROM tbProgram Where ProgID = @ProgID ",
                                                     new DbParameter[] {
                DataAccess.CreateParameter("ProgID", DbType.String, ProgID.ToString())
            }
                                                     );

            ProgramModel Program = null;


            if (dt.Rows.Count == 0)
            {
                throw new Exception("查無資料");
            }
            else if (dt.Rows.Count >= 2)
            {
                throw new Exception("有多筆資料");
            }
            else
            {
                Program = new ProgramModel();

                Program.ProgID   = dt.Rows[0]["ProgID"].ToString();
                Program.ProgName = dt.Rows[0]["ProgName"].ToString();
                Program.Power    = int.Parse(dt.Rows[0]["Power"].ToString());
                Program.Url      = dt.Rows[0]["Url"].ToString();
                Program.FlagType = dt.Rows[0]["FlagType"].ToString();
                Program.EditPK   = Program.ProgID.ToString();//修改專用PK值
            }

            return(Program);
        }
Ejemplo n.º 29
0
        public List <ProgramModel> GetProgramModels(string SearchContent = "")
        {
            List <ProgramModel> listProgramModels = new List <ProgramModel>();

            JavaScriptSerializer serializer = new JavaScriptSerializer();

            var programodel = new ProgramModel();
            var file        = @"C:\Users\Pedro\source\repos\Microondas\programs.txt";

            if (File.Exists(file))
            {
                var listPrograms = File.ReadAllLines(file);

                foreach (string program in listPrograms)
                {
                    programodel = serializer.Deserialize <ProgramModel>(program);
                    listProgramModels.Add(programodel);
                }

                if (!SearchContent.IsNull())
                {
                    var program = listProgramModels.Where(p => p.Name.ToLower().Contains(SearchContent.ToLower())).FirstOrDefault();
                    listProgramModels.Clear();
                    if (program != null)
                    {
                        listProgramModels.Add(program);
                    }
                }
            }
            return(listProgramModels);
        }
Ejemplo n.º 30
0
 /// <summary>
 ///		Añade los errores del analizador léxico
 /// </summary>
 private void AddErrorsLexer(ProgramModel program)
 {
     foreach (ParseErrorModel error in program.Errors)
     {
         AddError($"Lexical error. Line {error.Line}. {error.Message}");
     }
 }
        public void GivenInvalidViewModel_WhenEdit_ThenLogicManagerDoesNotEditEntity()
        {
            ProgramModel viewModel = new ProgramModel();
            Target.ModelState.AddModelError("whatever", "this is an invalid view model");

            PartialViewResult actual = Target.Edit(viewModel) as PartialViewResult;

            MockLogicManager.AssertWasNotCalled(m => m.Create(viewModel));
        }
        public void GivenInvalidViewModel_WhenCreate_ThenReturnViewWithViewModel()
        {
            ProgramModel viewModel = new ProgramModel();
            Target.ModelState.AddModelError("whatever", "this is an invalid view model");

            PartialViewResult actual = Target.Create(viewModel) as PartialViewResult;

            actual.AssertGetViewModel(viewModel);
        }
        public void GivenInvalidViewModel_WhenEdit_ThenPopulateViewModelListsCalled()
        {
            ProgramModel viewModel = new ProgramModel();
            Target.ModelState.AddModelError("whatever", "this is an invalid view model");

            PartialViewResult actual = Target.Edit(viewModel) as PartialViewResult;

            MockLogicManager.AssertWasCalled(m => m.PopulateViewModelLists(viewModel));
        }
 public ActionResult Create(ProgramModel viewModel)
 {
     ValidateModelState(viewModel);
     if (ModelState.IsValid)
     {
         LogicManager.Create(viewModel);
         return Json(true);
     }
     LogicManager.PopulateViewModelLists(viewModel);
     return PartialView(viewModel);
 }
 public ActionResult Create(ProgramModel pm)
 {
     if (Session["LoggedUserName"] == null || Session["IsAdmin"] == "0")
         return RedirectToAction("Login","Bh");
     if (ModelState.IsValid && programFlag == 1)
     {
         BugBusinessLayer.OperationsBusinessLayerControl obc = new OperationsBusinessLayerControl();
         obc.AddProgram(pm);
         return RedirectToAction("Index");
     }
     return View(pm);
 }
 private void UpdateSchools(ProgramModel model, Program toUpdate)
 {
     var selectedSchools = (model.SelectedSchools == null || !model.SelectedSchools.Any()) ?
         new List<School>() :
         SchoolRepository.Items.Where(s => model.SelectedSchools.Contains(s.Id)).ToList();
     toUpdate.Schools = selectedSchools;
 }
 public ProgramModel GenerateCreateViewModel()
 {
     ProgramModel viewModel = new ProgramModel();
     return viewModel;
 }
        public void GivenModelHasSelectedSchools_WhenPopulateViewModelLists_ThenSchoolSelectListSelectionsMade()
        {
            var expected = new List<int> { 1, 4 };
            ProgramModel viewModel = new ProgramModel { SelectedSchools = expected };

            Target.PopulateViewModelLists(viewModel);

            CollectionAssert.AreEqual(expected, viewModel.Schools.SelectedValues.Cast<int>().ToList());
        }
        public void GivenViewModel_WhenCreate_ThenProgramAddedToRepository()
        {
            ProgramModel viewModel = new ProgramModel();

            Target.Create(viewModel);

            Repositories.MockProgramRepository.AssertWasCalled(m => m.Add(Arg<Program>.Is.NotNull));
        }
        public void WhenPopulateViewModelLists_ThenViewModelHasServiceTypeSelectListPopulated()
        {
            var expected = Data.ServiceTypes.Where(s => s.IsActive).OrderBy(s => s.Name);
            ProgramModel viewModel = new ProgramModel();

            Target.PopulateViewModelLists(viewModel);

            CollectionAssert.AreEqual(expected.ToList(), viewModel.ServiceTypes.Items.Cast<ServiceType>().ToList());
        }
 private static bool AssertPropertiesMatch(ProgramModel expectedState, Program actualState)
 {
     Assert.IsNotNull(actualState);
     Assert.AreEqual(expectedState.Name, actualState.Name);
     Assert.AreEqual(expectedState.StartDate, actualState.StartDate);
     Assert.AreEqual(expectedState.EndDate, actualState.EndDate);
     Assert.AreEqual(expectedState.Purpose, actualState.Purpose);
     Assert.AreEqual(expectedState.ContactEmail, actualState.ContactInfo.Email);
     Assert.AreEqual(expectedState.ContactName, actualState.ContactInfo.Name);
     Assert.AreEqual(expectedState.ContactPhone, actualState.ContactInfo.Phone);
     return true;
 }
        public void WhenPopulateViewModelLists_ThenViewModelHasSchoolSelectListPopulated()
        {
            var expected = Data.Schools.OrderBy(s => s.Name);
            ProgramModel viewModel = new ProgramModel();

            Target.PopulateViewModelLists(viewModel);

            CollectionAssert.AreEqual(expected.ToList(), viewModel.Schools.Items.Cast<School>().ToList());
        }
        public void WhenPopulateViewModelLists_ThenViewModelHasProviderSelectListPopulated()
        {
            var expected = Data.Providers.Where(p => p.IsActive).OrderBy(p => p.Name).ToList();
            ProgramModel viewModel = new ProgramModel();

            Target.PopulateViewModelLists(viewModel);

            CollectionAssert.AreEqual(expected, viewModel.Providers.Items.Cast<Provider>().ToList());
        }
        public void WhenPopulateViewModelLists_ThenServiceTypeSelectListTextAndValueMembersSet()
        {
            ProgramModel viewModel = new ProgramModel();

            Target.PopulateViewModelLists(viewModel);

            Assert.AreEqual("Name", viewModel.ServiceTypes.DataTextField);
            Assert.AreEqual("Id", viewModel.ServiceTypes.DataValueField);
        }
        public void GivenViewModel_WhenEdit_ThenStateCopiedToEntityToUpdate()
        {
            int id = 2;
            ProgramModel viewModel = new ProgramModel
            {
                Id = id,
                Name = "Mortal Combat",
                StartDate = new DateTime(2001, 4, 6),
                EndDate = new DateTime(2001, 10, 11),
                Purpose = "Don't worry, it is just a video game.  It teaches important life lessons....really.",
                ContactEmail = "*****@*****.**",
                ContactName = "Bob",
                ContactPhone = "123-456-7890"
            };
            Program toUpdate = Data.Programs.Single(p => p.Id == id);

            Target.Edit(viewModel);

            Assert.AreEqual(viewModel.Name, toUpdate.Name);
            Assert.AreEqual(viewModel.StartDate, toUpdate.StartDate);
            Assert.AreEqual(viewModel.EndDate, toUpdate.EndDate);
            Assert.AreEqual(viewModel.Purpose, toUpdate.Purpose);
            Assert.AreEqual(viewModel.ContactEmail, toUpdate.ContactInfo.Email);
            Assert.AreEqual(viewModel.ContactName, toUpdate.ContactInfo.Name);
            Assert.AreEqual(viewModel.ContactPhone, toUpdate.ContactInfo.Phone);
        }
        public void GivenViewModel_WhenCreate_ThenStateCopiedToEntityToCreate()
        {
            ProgramModel viewModel = new ProgramModel
            {
                Name = "Mortal Kombat",
                StartDate = new DateTime(2001, 4, 6),
                EndDate = new DateTime(2001, 10, 11),
                Purpose = "Don't worry, it is just a video game.  It teaches important life lessons....really.",
                ContactEmail = "*****@*****.**",
                ContactName = "Bob",
                ContactPhone = "123-456-7890"
            };

            Target.Create(viewModel);

            Repositories.MockProgramRepository.AssertWasCalled(m => m.Add(Arg<Program>.Matches(p => AssertPropertiesMatch(viewModel, p))));
        }
 public void InitializeTest()
 {
     Target = new ProgramModel();
 }
 public ProgramModel GenerateEditViewModel(int id)
 {
     Program program = ProgramRepository.Items.Include(p => p.ServiceOfferings).Include(p => p.Schools).SingleOrDefault(p => p.Id == id);
     if (program == null || !program.IsActive)
     {
         throw new EntityNotFoundException("Could not find Program with specified Id.");
     }
     ProgramModel viewModel = new ProgramModel();
     viewModel.CopyFrom(program);
     viewModel.SelectedProviders = program.ServiceOfferings.Where(s => s.IsActive).Select(s => s.ProviderId);
     viewModel.SelectedServiceTypes = program.ServiceOfferings.Where(s => s.IsActive).Select(s => s.ServiceTypeId);
     viewModel.SelectedSchools = program.Schools.Select(s => s.Id);
     return viewModel;
 }
 public void Edit(ProgramModel viewModel)
 {
     if (viewModel == null)
     {
         throw new ArgumentNullException("viewModel");
     }
     Program toUpdate = ProgramRepository.Items.Include(s => s.ServiceOfferings).Include(s => s.Schools).SingleOrDefault(p => p.Id == viewModel.Id);
     if (toUpdate == null || !toUpdate.IsActive)
     {
         throw new EntityNotFoundException("Could not find Program with specified Id.");
     }
     var currentMappings = ServiceOfferingRepository.Items.
         Include(c => c.ServiceType).
         Include(c => c.Provider).
         Include("StudentAssignedOfferings").
         Where(s => s.ProgramId == viewModel.Id).ToList();
     var newMappings = GenerateServiceOfferingMappings(viewModel, toUpdate);
     UpdateSchools(viewModel, toUpdate);
     DeactivateServiceOfferings(currentMappings, newMappings);
     ActivateServiceOfferings(currentMappings, newMappings);
     viewModel.CopyTo(toUpdate);
     ProgramRepository.Update(toUpdate);
     RepositoryContainer.Save();
 }
 public void Validate(ProgramModel viewModel)
 {
     if (ProgramRepository.Items.Any(p => p.IsActive && p.Name == viewModel.Name && p.Id != viewModel.Id))
     {
         throw new ValidationException(new ValidationResult("Name already exists", new string[] { "Name" }), null, viewModel.Name);
     }
 }
 public ProgramModel GenerateDeleteViewModel(int id)
 {
     Program program = ProgramRepository.Items.SingleOrDefault(p => p.Id == id);
     if (program == null)
     {
         throw new EntityNotFoundException("Could not find Program with specified Id.");
     }
     ProgramModel viewModel = new ProgramModel();
     viewModel.CopyFrom(program);
     return viewModel;
 }
 private IEnumerable<Provider> LoadSelectedProviders(ProgramModel viewModel)
 {
     if (viewModel.SelectedProviders == null)
     {
         return Enumerable.Empty<Provider>();
     }
     return ProviderRepository.Items.Where(p => viewModel.SelectedProviders.Contains(p.Id)).ToList();
 }
 public void PopulateViewModelLists(ProgramModel viewModel)
 {
     viewModel.Providers = new MultiSelectList(ProviderRepository.Items.Where(p => p.IsActive).OrderBy(p => p.Name), "Id", "Name", viewModel.SelectedProviders);
     viewModel.ServiceTypes = new MultiSelectList(ServiceTypeRepository.Items.Where(s => s.IsActive).OrderBy(s => s.Name), "Id", "Name", viewModel.SelectedServiceTypes);
     viewModel.Schools = new MultiSelectList(SchoolRepository.Items.OrderBy(s => s.Name), "Id", "Name", viewModel.SelectedSchools);
 }
        public void GivenViewModelServiceTypeAssociationsWereMade_WhenEdit_ThenProgramHasServiceOfferingsWithSelectedServiceTypes()
        {
            int id = 2;
            Program toUpdate = Data.Programs.Single(p => p.Id == id);
            var expected = new int[] { 1, 4 };
            ProgramModel viewModel = new ProgramModel { Id = id, SelectedServiceTypes = expected, SelectedProviders = new [] { 1 } };

            Target.Edit(viewModel);

            var actual = toUpdate.ServiceOfferings.Select(s => s.ServiceTypeId).Distinct();
            CollectionAssert.AreEquivalent(expected, actual.ToList());
        }
 private List<ServiceOffering> GenerateServiceOfferingMappings(ProgramModel viewModel, Program item)
 {
     List<ServiceOffering> newMappings = new List<ServiceOffering>();
     if (viewModel.SelectedServiceTypes != null && viewModel.SelectedProviders != null)
     {
         foreach (var serviceTypeId in viewModel.SelectedServiceTypes)
         {
             foreach (var providerId in viewModel.SelectedProviders)
             {
                 ServiceOffering newOffering = ServiceOfferingRepository.Items.SingleOrDefault(s => s.ServiceTypeId == serviceTypeId && s.ProviderId == providerId && s.ProgramId == item.Id && !s.IsActive);
                 if (newOffering == null)
                 {
                     newOffering = new ServiceOffering { ProviderId = providerId, ServiceTypeId = serviceTypeId, Program = item, ProgramId = item.Id, IsActive = true };
                 }
                 else
                 {
                     newOffering.IsActive = true;
                 }
                 newMappings.Add(newOffering);
             }
         }
     }
     return newMappings;
 }
        public void GivenViewModelWithEditedSchools_WhenEdit_ThenSchoolsListUpdated()
        {
            var expected = new int[] { 1, 2 };
            ProgramModel viewModel = new ProgramModel { Id = 1, SelectedSchools = expected, SelectedProviders = new int[] { 1 }, SelectedServiceTypes = new int[] { 1 } };
            Program toUpdate = Data.Programs.Single(p => p.Id == 1);

            Target.Edit(viewModel);

            CollectionAssert.AreEqual(expected, toUpdate.Schools.Select(s => s.Id).ToArray());
        }
 private IEnumerable<ServiceType> LoadSelectedServiceTypes(ProgramModel viewModel)
 {
     if (viewModel.SelectedServiceTypes == null)
     {
         return Enumerable.Empty<ServiceType>();
     }
     return ServiceTypeRepository.Items.Where(t => viewModel.SelectedServiceTypes.Contains(t.Id)).ToList();
 }
        public void GivenViewModelWithSelectedSchools_WhenCreate_ThenSchoolsListUpdated()
        {
            var expected = new int[] { 1, 2 };
            ProgramModel viewModel = new ProgramModel { SelectedSchools = expected, SelectedProviders = new int[] { 1 }, SelectedServiceTypes = new int[] { 1 } };

            Target.Create(viewModel);

            Repositories.MockProgramRepository.AssertWasCalled(m => m.Add(Arg<Program>.Matches(p => p.Schools.Select(s => s.Id).SequenceEqual(expected))));
        }
 public void Create(ProgramModel viewModel)
 {
     if (viewModel == null)
     {
         throw new ArgumentNullException("viewModel");
     }
     Program item = ProgramRepository.Items.SingleOrDefault(p => p.Name == viewModel.Name && !p.IsActive);
     if (item == null)
     {
        item = new Program();
        ProgramRepository.Add(item);
     }
     viewModel.Id = item.Id;
     item.IsActive = true;
     viewModel.CopyTo(item);
     UpdateSchools(viewModel, item);
     var mappings = GenerateServiceOfferingMappings(viewModel, item);
     foreach (var mapping in mappings)
     {
         if (!ServiceOfferingRepository.Items.Where(s => s.ProgramId == mapping.ProgramId && s.ProviderId == mapping.ProviderId && s.ServiceTypeId == mapping.ServiceTypeId).Any())
         {
             item.ServiceOfferings.Add(mapping);
             ServiceOfferingRepository.Add(mapping);
         }
     }
     RepositoryContainer.Save();
 }
        public void GivenViewModel_WhenCreate_ThenChangesSaved()
        {
            ProgramModel viewModel = new ProgramModel();

            Target.Create(viewModel);

            Repositories.MockRepositoryContainer.AssertWasCalled(m => m.Save());
        }