public Boolean SaveCertificationFile(CertificationType cType, Boolean withEmptyPlaceHolders, Int32 idCommunity, Int32 idUser, String cName, String cDescription, long idPath, long idSubActivity, Guid uniqueID, String extension, Boolean restore = false) { Certification cert = null; SubActivity s = Service.GetSubActivity(idSubActivity); if (s != null) { dtoCertification dto = dtoCertification.Create(cType); dto.Name = cName; if (!String.IsNullOrEmpty(cDescription) && cDescription.Contains("{0}")) { cDescription = string.Format(cDescription, Service.GetPathName(idPath)); } dto.Description = cDescription; dto.IdCommunity = idCommunity; dto.IdContainer = idPath; dto.IdOwner = idUser; dto.UniqueIdGeneratedFile = uniqueID; dto.FileExtension = extension; dto.IdTemplate = s.IdCertificate; dto.IdTemplateVersion = s.IdCertificateVersion; dto.WithEmptyPlaceHolders = withEmptyPlaceHolders; dto.SourceItem = ModuleObject.CreateLongObject(idSubActivity, s, (int)COL_BusinessLogic_v2.UCServices.Services_EduPath.ObjectType.SubActivity, idCommunity, COL_BusinessLogic_v2.UCServices.Services_EduPath.Codex, Service.ServiceModuleID()); cert = ServiceCertifications.SaveUserCertification(dto); } return(cert != null); }
public async Task <ActionResult> DeleteConfirmed(int id) { SubActivity subActivity = await db.SubActivities.FindAsync(id); db.SubActivities.Remove(subActivity); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit([Bind(Include = "ID,SubActivity1,IDMA")] SubActivity subActivity) { if (ModelState.IsValid) { db.Entry(subActivity).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.IDMA = new SelectList(db.MainActivities, "ID", "MainActivity1", subActivity.IDMA); return(View(subActivity)); }
public lm.Comol.Core.DomainModel.DocTemplateVers.Domain.DTO.ServiceExport.DTO_Template FillDataIntoTemplate(Int32 idCommunity, Int32 idUser, long idPath, long idSubActivity, String basePath, String istanceName, ref CertificationError cError) { lm.Comol.Core.DomainModel.DocTemplateVers.Domain.DTO.ServiceExport.DTO_Template template = null; SubActivity subActivity = Service.GetSubActivity(idSubActivity); if (subActivity != null) { template = ServiceTemplates.TemplateGet(subActivity.IdCertificate, subActivity.IdCertificateVersion, basePath); if (template != null) { //litePerson person = CurrentManager.GetLitePerson(idUser); Person person = CurrentManager.GetPerson(idUser); liteCommunity community = CurrentManager.GetLiteCommunity(idCommunity); liteSubscriptionInfo subscription = CurrentManager.GetLiteSubscriptionInfo(idUser, idCommunity); String organization = ""; if (community != null) { organization = CurrentManager.GetOrganizationName(community.IdOrganization); } List <String> pHolders = TemplateEduPathPlaceHolders.PlaceHolders().Values.Select(v => v).ToList(); pHolders.AddRange(lm.Comol.Core.DomainModel.Helpers.TemplateCommonPlaceHolders.PlaceHolders().Values.Select(v => v).ToList()); if (template.Modules != null && template.Modules.Where(m => m.IdModule == Service.ServiceModuleID()).Any() && subActivity != null) { // DEVO RIEmPIRE I PLACE HOLDERS ! List <lm.Comol.Modules.EduPath.Domain.DTO.dtoSubActivityLink> links = Service.GetDtoSubactivityActiveLinks(idSubActivity); if (links == null || links.Count == 0) { template.Body.Text = TemplateEduPathPlaceHolders.Translate(template.Body.Text, AppContext, idPath, idUser, subActivity); } else { template.Body.Text = TemplateEduPathPlaceHolders.Translate(template.Body.Text, AppContext, idPath, idUser, subActivity, View.GetQuizInfos(links.Where(l => l.Visible).Select(l => l.IdObject).ToList(), idUser, IsEvaluablePath(idPath))); } } Int32 idLanguage = (person == null) ? UserContext.Language.Id : person.LanguageID; template.Body.Text = lm.Comol.Core.DomainModel.Helpers.TemplateCommonPlaceHolders.Translate(template.Body.Text, person, community, (subscription == null) ? null : subscription.SubscribedOn, organization, CurrentManager.GetTranslatedRole(subscription.IdRole, idLanguage), CurrentManager.GetTranslatedProfileType((person == null) ? (int)UserTypeStandard.Guest : person.TypeID, idLanguage), istanceName); Int32 missingPlaceHolders = pHolders.Where(p => template.Body.Text.Contains(p)).Count(); cError = (missingPlaceHolders == 0) ? CertificationError.None : ((missingPlaceHolders == 1) ? CertificationError.EmptyTemplateItem : CertificationError.EmptyTemplateItems); } } else { cError = CertificationError.ExternalItemUnknown; } return(template); }
// GET: SubActivity/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SubActivity subActivity = await db.SubActivities.FindAsync(id); if (subActivity == null) { return(HttpNotFound()); } return(View(subActivity)); }
// GET: SubActivity/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SubActivity subActivity = await db.SubActivities.FindAsync(id); if (subActivity == null) { return(HttpNotFound()); } ViewBag.IDMA = new SelectList(db.MainActivities, "ID", "MainActivity1", subActivity.IDMA); return(View(subActivity)); }
public async Task <bool> CreateSubActivityAsync(string userId, SubActivityCreateDto model) { var subActivity = new SubActivity(model.Name, userId); subActivity.SubActivityItems = await _context.Items .Where(i => model.ItemIds.Contains(i.Id)) .Select(item => new SubActivityItemJoin() { Item = item, SubActivity = subActivity }) .ToListAsync(); await _context.SubActivities.AddAsync(subActivity); return(await _context.SaveChangesAsync() == model.ItemIds.Count() + 1); }
public bool Create(SubActivityCreate model) { var entity = new SubActivity() { OwnerId = _userId, Name = model.Name, Nombre = model.Nombre, Items = model.Items, }; using (var ctx = new ApplicationDbContext()) { ctx.SubActivities.Add(entity); return(ctx.SaveChanges() >= 1); } }
private void AddCommunityFilesToItem(Activity activity, RepositoryIdentifier identifier, List <ModuleActionLink> links) { if (links != null && links.Count > 0 && activity != null) { Person person = CurrentManager.GetPerson(UserContext.CurrentUserID); List <SubActivity> inserted = new List <SubActivity>(); DateTime createdOn = DateTime.Now; foreach (ModuleActionLink l in links) { SubActivity subActivity = new SubActivity(); subActivity.ParentActivity = activity; subActivity.CreateMetaInfo(UserContext.CurrentUserID, UserContext.IpAddress, UserContext.ProxyIpAddress, createdOn); subActivity.IdObjectLong = l.ModuleObject.ObjectLongID; subActivity.IdObjectVersion = 0; subActivity.IdModuleAction = l.Action; subActivity.Description = ""; subActivity.Link = l.Link; subActivity.ContentPermission = l.Permission; subActivity.Name = ""; subActivity.IdModule = l.ModuleObject.ServiceID; subActivity.CodeModule = l.ModuleObject.ServiceCode; subActivity.ContentType = SubActivityType.File; SubActivity added = Service.SaveOrUpdateSubActivity(subActivity, l, CurrentIdModule, ModuleEduPath.UniqueCode, identifier.IdCommunity, person, UserContext.IpAddress, UserContext.ProxyIpAddress); if (added != null) { inserted.Add(added); } } if (inserted.Any()) { View.DisplayItemsAdded(); } else { View.DisplayItemsNotAdded(); } } else { View.DisplayNoFilesToAdd(); } }
public ActionResult subActivity(int id) { SingleApartmentEntities entity = new SingleApartmentEntities(); CMember member = Session[CDictionary.welcome] as CMember; if (member == null) { return(RedirectToAction("Login", "Member")); } int memberID = member.fMemberId; SubActivity subActivity = new SubActivity(); subActivity.ActivityID = id; subActivity.MemberID = memberID; entity.SubActivity.Add(subActivity); entity.SaveChanges(); return(RedirectToAction("List")); }
public List <StandardActionType> GetAllowedStandardAction(ModuleObject source, ModuleObject destination, int idUser, int idRole, int idCommunity, Dictionary <string, long> moduleUserLong = null, Dictionary <string, string> moduleUserString = null) { List <StandardActionType> actions = new List <StandardActionType>(); if (source.ServiceCode == "SRVEDUP") { PermissionEP permission = new PermissionEP(RoleEP.None); switch (source.ObjectTypeID) { case (int)ItemType.Path: permission = GetUserPermission_ByPath(source.ObjectLongID, idUser, idRole); break; case (int)ItemType.Unit: permission = GetUserPermission_ByUnit(source.ObjectLongID, idUser, idRole); break; case (int)ItemType.Activity: permission = GetUserPermission_ByActivity(source.ObjectLongID, idUser, idRole); break; case (int)ItemType.SubActivity: SubActivity sub = GetSubActivity(source.ObjectLongID); if (sub != null) { permission = GetUserPermission_ByActivity(sub.ParentActivity.Id, idUser, idRole); } break; } if (permission.ViewOwnStat) { actions.Add(StandardActionType.ViewPersonalStatistics); } if (permission.ViewUserStat) { actions.Add(StandardActionType.ViewUserStatistics); } if (permission.ViewUserStat || permission.Create || permission.Update) { actions.Add(StandardActionType.ViewAdvancedStatistics); } if (permission.Create) { actions.Add(StandardActionType.Create); } if (permission.Create || permission.Update) { actions.Add(StandardActionType.Edit); } switch (destination.ServiceCode) { case CoreModuleRepository.UniqueID: actions = GetAllowedStandardActionForRepository(permission, actions, destination.ObjectLongID, idUser, idCommunity); break; } } // Boolean isMultimedia = (eventItemFile.File.RepositoryItemType != RepositoryItemType.FileStandard && eventItemFile.File.RepositoryItemType != RepositoryItemType.Folder && eventItemFile.File.RepositoryItemType != RepositoryItemType.None); //è multimediale e posso actions.Add(StandardActionType.EditMetadata) //actions.Add(StandardActionType.EditMetadata) // actions.Add(StandardActionType.Play); // actions.Add(StandardActionType.ViewPersonalStatistics); // actions.Add(StandardActionType.ViewAdvancedStatistics); return(actions); }
public static String Translate(string content, lm.Comol.Modules.EduPath.BusinessLogic.Service service, Path path, Int32 idUser, SubActivity subActivity) { String translation = content; if (path != null) { Int32 IdCRole = service.CommunityRoleId(path.Community.Id, idUser); ILookup <StatusStatistic, ActivityStatistic> statdict = null; DateTime?startEpDate = path.StartDate; if (startEpDate.HasValue) { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathStartedOn), ReplaceChars(startEpDate.Value.ToShortDateString())); } else { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathStartedOn), ""); } DateTime?endDate = service.GetEpEndDate(path, idUser); if (endDate.HasValue) { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathEndedOn), ReplaceChars(endDate.Value.ToShortDateString())); } else { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathEndedOn), ""); } //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.PathName))) translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathName), ReplaceChars(path.Name)); if (!String.IsNullOrEmpty(path.PathCode)) { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathCode), ReplaceChars(path.PathCode)); } else { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathCode), ""); } translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathId), ReplaceChars(path.Id.ToString())); //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.UnitCount))) // translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.UnitCount), path.UnitList.Where(u=> u.Deleted== BaseStatusDeleted.None)); if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.PathMinCompletion))) { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathMinCompletion), path.MinCompletion.ToString() + "%"); } //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.PathMinMark))) // translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathMinMark), path.MinCompletion.ToString()); Boolean timeBased = service.CheckEpType(path.EPType, EPType.Time); Int32 totalAct = -1; Int32 notStarted = -1; Int32 started = -1; Int32 completed = -1; Int32 completedAndPassed = -1; // ANCHE SE è AUTO devo verificare ?? //Boolean timeBased = service.CheckEpType(path.EPType, EPType.Time) && service.CheckEpType(path.EPType, EPType.Auto); if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.PathDuration)) && timeBased) { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathDuration), (path.Weight > 0) ? service.ConvertTimeFromLong(path.Weight) : "//"); } if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.UnitCount))) { short count = service.GetActiveUnitsCount(path.UnitList, idUser, IdCRole, true, false); translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.UnitCount), count.ToString()); } if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.ActivitiesCount))) { totalAct = service.GetActiveActivitiesCount(path.UnitList.SelectMany(x => x.ActivityList).ToList(), idUser, IdCRole, true, false); //foreach (var item in path.UnitList) //{ // count += service.GetActiveActivitiesCount(item.ActivityList , idUser, IdCRole, true, false); //} //totalAct = count; translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.ActivitiesCount), totalAct.ToString()); } if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.StartedActivities))) { //if (statdict == null) // statdict = service.ServiceStat.GetStatCount_ByUser(path.Id, idUser, DateTime.Now); //started = statdict[StatusStatistic.BrowsedStarted].Count(); started = service.ServiceStat.GetStatCount_ByUserAndStatus(path.Id, idUser, DateTime.Now, StatusStatistic.Started); translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.StartedActivities), started.ToString()); } if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.CompletedActivities))) { //if (statdict == null) // statdict = service.ServiceStat.GetStatCount_ByUser(path.Id, idUser, DateTime.Now); //completed = statdict[StatusStatistic.Started | StatusStatistic.Browsed | StatusStatistic.Completed ].Count(); //completed = statdict[StatusStatistic.Started | StatusStatistic.Browsed | StatusStatistic.CompletedPassed].Count(); completedAndPassed = service.ServiceStat.GetStatCount_ByUserAndStatus(path.Id, idUser, DateTime.Now, StatusStatistic.Completed); translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.CompletedActivities), completedAndPassed.ToString()); } //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.NotStartedActivities))) //{ // //if (statdict == null) // // statdict = service.ServiceStat.GetStatCount_ByUser(path.Id, idUser, DateTime.Now); // //if (totalAct == -1) // //{ // // totalAct = service.GetActiveActivitiesCount(path.UnitList.SelectMany(x => x.ActivityList).ToList(), idUser, IdCRole, true, false); // //} // //Int32 x = statdict[StatusStatistic.].Count(); // notStarted = totalAct - (started);//service.ServiceStat.GetStatCount_ByUserAndStatus(path.Id, idUser, DateTime.Now, StatusStatistic.None ,true ); // notStarted = (notStarted < 0) ? 0 : notStarted; // translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.NotStartedActivities), notStarted.ToString()); //} //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.CompletedOn))) //{ //(!subActivity.UsePathEndDateStatistics || !endDate.HasValue) || (subActivity.UsePathEndDateStatistics && endDate.HasValue && a.CompletedOn <= endDate.Value)); PathStatistic pathStatistic = null; if (!subActivity.UsePathEndDateStatistics || !endDate.HasValue) { pathStatistic = service.ServiceStat.GetPathStat(path.Id, idUser); } else if (subActivity.UsePathEndDateStatistics && endDate.HasValue) { pathStatistic = service.ServiceStat.GetPathStat(path.Id, idUser, endDate.Value); } if (pathStatistic != null) { //TODO:Check epAuto if (service.ServiceStat.CheckStatusStatistic(pathStatistic.Status, StatusStatistic.Completed) || service.ServiceStat.CheckStatusStatistic(pathStatistic.Status, StatusStatistic.CompletedPassed)) { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.CompletedOn), pathStatistic.CreatedOn.Value.ToShortDateString()); } else { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.CompletedOn), ""); } DateTime?compilationStartedOn = pathStatistic.StartDate; if (compilationStartedOn.HasValue) { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathStartCompilationOn), compilationStartedOn.Value.ToShortDateString()); } else { translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.PathStartCompilationOn), ""); } } //else //{ // translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.CompletedOn), "###"); //} //} } return(translation); }
public static String Translate(string content, lm.Comol.Core.DomainModel.iApplicationContext appContext, long idPath, Int32 idUser, SubActivity subActivity) { String translation = content; lm.Comol.Modules.EduPath.BusinessLogic.Service service = new lm.Comol.Modules.EduPath.BusinessLogic.Service(appContext); Path path = service.GetPath(idPath); if (path != null) { translation = Translate(translation, service, path, idUser, subActivity); } return(translation); }
public static String Translate(string content, lm.Comol.Core.DomainModel.iApplicationContext appContext, long idPath, Int32 idUser, SubActivity subActivity, List <dtoQuizInfo> items) { //return content; #region Setup lm.Comol.Modules.EduPath.BusinessLogic.Service service = new lm.Comol.Modules.EduPath.BusinessLogic.Service(appContext); Path path = service.GetPath(idPath); String translation = Translate(content, service, path, idUser, subActivity); DateTime?endDate = service.GetEpEndDate(path, idUser); #endregion if (items.Count > 0 && translation.Contains(OpenTag + "ep.Quiz")) { foreach (dtoQuizInfo quiz in items) { // DATE LE INFO RELATIVE AI QUIZ SISTEMARE l'OUTPUT INTANTO UN ESEMPIO PER VEDERE SE VA var query = quiz.Attempts.Where(a => (!subActivity.UsePathEndDateStatistics || !endDate.HasValue) || (subActivity.UsePathEndDateStatistics && endDate.HasValue && a.CompletedOn <= endDate.Value)); //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.QuizName))) // translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.QuizName), ReplaceChars(quiz.Name)); //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.QuizMinMark))) // translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.QuizMinMark), quiz.MinScore.ToString()); //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.QuizMaxMark))) // translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.QuizMaxMark), quiz.EvaluationScale.ToString()); //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.QuizMark))) // translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.QuizMark), (query.Any()) ? ((int)query.OrderByDescending(a=> a.CompletedOn).FirstOrDefault().RelativeScore).ToString() : ""); //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.QuizAttempts))) // translation = translation.Replace(GetPlaceHolder(EduPathPlaceHoldersType.QuizAttempts), query.Count().ToString()); //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.QuizQuestionsNumber))) //{ //} //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.QuizList))) //{ //} //if (content.Contains(GetPlaceHolder(EduPathPlaceHoldersType.QuizTable))) //{ //} } } return(translation); }
public static string SaveData(string data) { data = data.Replace("&", "&"); MemoryStream mem = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(data)); XPathDocument document; try { document = new XPathDocument(mem); } catch (Exception) { return("error"); } BenefitAdminDataContext bfAdmin = new BenefitAdminDataContext(); var allInSvr = from c in bfAdmin.Services select c; bfAdmin.Services.DeleteAllOnSubmit(allInSvr); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } var allInAct = from c in bfAdmin.Activities select c; bfAdmin.Activities.DeleteAllOnSubmit(allInAct); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } var allInSAct = from c in bfAdmin.SubActivities select c; bfAdmin.SubActivities.DeleteAllOnSubmit(allInSAct); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } var allInMat = from c in bfAdmin.Materials select c; bfAdmin.Materials.DeleteAllOnSubmit(allInMat); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } XPathNavigator navigator = document.CreateNavigator(); XPathNodeIterator allDocs = navigator.Select("DOCUMENTS/DOCUMENT"); while (allDocs.MoveNext()) { string title = allDocs.Current.GetAttribute("title", ""); if (title.Equals("Service")) { #region string col0 = "", col1 = "", col2 = "", col3 = "", col4 = "", col5 = ""; string col6 = "", col7 = "", col8 = "", col9 = "", col10 = ""; XPathNodeIterator countRowString = allDocs.Current.Select("METADATA/ROWS"); countRowString.MoveNext(); int countRow = Convert.ToInt32(countRowString.Current.Value); XPathNodeIterator rows = allDocs.Current.Select("DATA"); while (rows.MoveNext()) { for (int i = 1; i < countRow; i++) { XPathNodeIterator getCol0 = rows.Current.Select("R" + i + "/C0"); getCol0.MoveNext(); col0 = getCol0.Current.Value; XPathNodeIterator getCol1 = rows.Current.Select("R" + i + "/C1"); getCol1.MoveNext(); col1 = getCol1.Current.Value; XPathNodeIterator getCol2 = rows.Current.Select("R" + i + "/C2"); getCol2.MoveNext(); col2 = getCol2.Current.Value; XPathNodeIterator getCol3 = rows.Current.Select("R" + i + "/C3"); getCol3.MoveNext(); col3 = getCol3.Current.Value; XPathNodeIterator getCol4 = rows.Current.Select("R" + i + "/C4"); getCol4.MoveNext(); col4 = getCol4.Current.Value; XPathNodeIterator getCol5 = rows.Current.Select("R" + i + "/C5"); getCol5.MoveNext(); col5 = getCol5.Current.Value; XPathNodeIterator getCol6 = rows.Current.Select("R" + i + "/C6"); getCol6.MoveNext(); col6 = getCol6.Current.Value; XPathNodeIterator getCol7 = rows.Current.Select("R" + i + "/C7"); getCol7.MoveNext(); col7 = getCol7.Current.Value; XPathNodeIterator getCol8 = rows.Current.Select("R" + i + "/C8"); getCol8.MoveNext(); col8 = getCol8.Current.Value; XPathNodeIterator getCol9 = rows.Current.Select("R" + i + "/C9"); getCol9.MoveNext(); col9 = getCol9.Current.Value; XPathNodeIterator getCol10 = rows.Current.Select("R" + i + "/C10"); getCol10.MoveNext(); col10 = getCol10.Current.Value; //insert to DB if (!col0.Equals("")) { Service svr = new Service(); svr.SVCCode = col0; svr.SVCName = col1; svr.SVCDesc = col2; svr.HostCode = col3; svr.StaffRole = col4; svr.SVCType = col5; svr.SVCObjective = col6; svr.SVCSupport = col7; svr.SVCCoverage = col8; svr.SVCStart = col9; svr.SVCEnd = col10; bfAdmin.Services.InsertOnSubmit(svr); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } } } } #endregion } else if (title.Equals("Activity")) { #region string col0 = "", col1 = "", col2 = "", col3 = ""; XPathNodeIterator countRowString = allDocs.Current.Select("METADATA/ROWS"); countRowString.MoveNext(); int countRow = Convert.ToInt32(countRowString.Current.Value); XPathNodeIterator rows = allDocs.Current.Select("DATA"); while (rows.MoveNext()) { for (int i = 1; i < countRow; i++) { XPathNodeIterator getCol0 = rows.Current.Select("R" + i + "/C0"); getCol0.MoveNext(); col0 = getCol0.Current.Value; XPathNodeIterator getCol1 = rows.Current.Select("R" + i + "/C1"); getCol1.MoveNext(); col1 = getCol1.Current.Value; XPathNodeIterator getCol2 = rows.Current.Select("R" + i + "/C2"); getCol2.MoveNext(); col2 = getCol2.Current.Value; XPathNodeIterator getCol3 = rows.Current.Select("R" + i + "/C3"); getCol3.MoveNext(); col3 = getCol3.Current.Value; //insert to DB if (!col0.Equals("") && !col2.Equals("")) { Activity act = new Activity(); act.ACTCode = col0; act.ACTDesc = col1; act.SVCCode = col2; act.ICF_Code = col3; bfAdmin.Activities.InsertOnSubmit(act); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } } } } #endregion } else if (title.Equals("SubActivity")) { #region string col0 = "", col1 = "", col2 = ""; XPathNodeIterator countRowString = allDocs.Current.Select("METADATA/ROWS"); countRowString.MoveNext(); int countRow = Convert.ToInt32(countRowString.Current.Value); XPathNodeIterator rows = allDocs.Current.Select("DATA"); while (rows.MoveNext()) { for (int i = 1; i < countRow; i++) { XPathNodeIterator getCol0 = rows.Current.Select("R" + i + "/C0"); getCol0.MoveNext(); col0 = getCol0.Current.Value; XPathNodeIterator getCol1 = rows.Current.Select("R" + i + "/C1"); getCol1.MoveNext(); col1 = getCol1.Current.Value; XPathNodeIterator getCol2 = rows.Current.Select("R" + i + "/C2"); getCol2.MoveNext(); col2 = getCol2.Current.Value; //insert to DB if (!col0.Equals("") && !col2.Equals("")) { SubActivity sact = new SubActivity(); sact.SACTCode = col0; sact.SACTDesc = col1; sact.ACTCode = col2; bfAdmin.SubActivities.InsertOnSubmit(sact); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } } } } #endregion } else if (title.Equals("Material")) { #region string col0 = "", col1 = "", col2 = "", col3 = "", col4 = "", col5 = "", col6 = ""; XPathNodeIterator countRowString = allDocs.Current.Select("METADATA/ROWS"); countRowString.MoveNext(); int countRow = Convert.ToInt32(countRowString.Current.Value); XPathNodeIterator rows = allDocs.Current.Select("DATA"); while (rows.MoveNext()) { for (int i = 1; i < countRow; i++) { XPathNodeIterator getCol0 = rows.Current.Select("R" + i + "/C0"); getCol0.MoveNext(); col0 = getCol0.Current.Value; XPathNodeIterator getCol1 = rows.Current.Select("R" + i + "/C1"); getCol1.MoveNext(); col1 = getCol1.Current.Value; XPathNodeIterator getCol2 = rows.Current.Select("R" + i + "/C2"); getCol2.MoveNext(); col2 = getCol2.Current.Value; XPathNodeIterator getCol3 = rows.Current.Select("R" + i + "/C3"); getCol3.MoveNext(); col3 = getCol3.Current.Value; XPathNodeIterator getCol4 = rows.Current.Select("R" + i + "/C4"); getCol4.MoveNext(); col4 = getCol4.Current.Value; XPathNodeIterator getCol5 = rows.Current.Select("R" + i + "/C5"); getCol5.MoveNext(); col5 = getCol5.Current.Value; XPathNodeIterator getCol6 = rows.Current.Select("R" + i + "/C6"); getCol6.MoveNext(); col6 = getCol6.Current.Value; //insert to DB if (!col0.Equals("") && !col5.Equals("")) { Material mt = new Material(); mt.MaterialCode = col0; mt.MaterialDesc = col1; mt.Unit = col2; mt.EstimatedPrice = col3; mt.RealPrice = col4; mt.SVCCode = col5; mt.Note = col6; bfAdmin.Materials.InsertOnSubmit(mt); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } } } } #endregion } } return(null); }
private void excelToDB(DataTable data) { //clean DB #region if (RadioButtonList_type.SelectedIndex == 1) //selecte create new sheet { if (DropDownListTo.SelectedIndex == 0) { var allInSvr = from c in bfAdmin.Services select c; bfAdmin.Services.DeleteAllOnSubmit(allInSvr); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } } else if (DropDownListTo.SelectedIndex == 1) { var allInAct = from c in bfAdmin.Activities select c; bfAdmin.Activities.DeleteAllOnSubmit(allInAct); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } } else if (DropDownListTo.SelectedIndex == 2) { var allInSAct = from c in bfAdmin.SubActivities select c; bfAdmin.SubActivities.DeleteAllOnSubmit(allInSAct); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } } else { var allInMat = from c in bfAdmin.Materials select c; bfAdmin.Materials.DeleteAllOnSubmit(allInMat); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } } } #endregion if (DropDownListTo.SelectedIndex == 0) { int skip = 0; foreach (DataRow row in data.Rows) { if (row[0].ToString() != null && skip > 0) { Service svr = new Service(); try { svr.SVCCode = row[0].ToString(); svr.SVCName = row[1].ToString() == null ? "" : row[1].ToString(); svr.SVCDesc = row[2].ToString() == null ? "" : row[2].ToString(); svr.HostCode = row[3].ToString() == null ? "" : row[3].ToString(); svr.StaffRole = row[4].ToString() == null ? "" : row[4].ToString(); svr.SVCType = row[5].ToString() == null ? "" : row[5].ToString(); svr.SVCObjective = row[6].ToString() == null ? "" : row[6].ToString(); svr.SVCSupport = row[7].ToString() == null ? "" : row[7].ToString(); svr.SVCCoverage = row[8].ToString() == null ? "" : row[8].ToString(); svr.SVCStart = row[9].ToString() == null ? "" : row[9].ToString(); svr.SVCEnd = row[10].ToString() == null ? "" : row[10].ToString(); } catch { } var Svr = from c in bfAdmin.Services where c.SVCCode.ToString().Trim().Equals(row[0].ToString().Trim()) select c; if (Svr != null) { bfAdmin.Services.DeleteAllOnSubmit(Svr); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } } bfAdmin.Services.InsertOnSubmit(svr); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } } skip = 1; } } else if (DropDownListTo.SelectedIndex == 1) { int skip = 0; foreach (DataRow row in data.Rows) { if (row[0].ToString() != null && skip > 0) { Activity act = new Activity(); try { act.ACTCode = row[0].ToString(); act.ACTDesc = row[1].ToString() == null ? "" : row[1].ToString(); act.SVCCode = row[2].ToString() == null ? "" : row[2].ToString(); } catch { } var Act = from c in bfAdmin.Activities where c.ACTCode.ToString().Trim().Equals(row[0].ToString().Trim()) select c; bfAdmin.Activities.DeleteAllOnSubmit(Act); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } bfAdmin.Activities.InsertOnSubmit(act); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } } skip = 1; } } else if (DropDownListTo.SelectedIndex == 2) { int skip = 0; foreach (DataRow row in data.Rows) { if (row[0].ToString() != null && skip > 0) { SubActivity sact = new SubActivity(); try { sact.SACTCode = row[0].ToString(); sact.SACTDesc = row[1].ToString() == null ? "" : row[1].ToString(); sact.ACTCode = row[2].ToString() == null ? "" : row[2].ToString(); } catch { } var Sact = from c in bfAdmin.SubActivities where c.SACTCode.ToString().Trim().Equals(row[0].ToString().Trim()) select c; bfAdmin.SubActivities.DeleteAllOnSubmit(Sact); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } bfAdmin.SubActivities.InsertOnSubmit(sact); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } } skip = 1; } } else { int skip = 0; foreach (DataRow row in data.Rows) { if (row[0].ToString() != null && skip > 0) { Material mat = new Material(); try { mat.MaterialCode = row[0].ToString(); mat.MaterialDesc = row[1].ToString() == null ? "" : row[1].ToString(); mat.Unit = row[2].ToString() == null ? "" : row[2].ToString(); mat.EstimatedPrice = row[3].ToString() == null ? "" : row[3].ToString(); mat.RealPrice = row[4].ToString() == null ? "" : row[4].ToString(); mat.SVCCode = row[5].ToString() == null ? "" : row[5].ToString(); } catch { } var Mat = from c in bfAdmin.Materials where c.MaterialCode.ToString().Trim().Equals(row[0].ToString().Trim()) select c; bfAdmin.Materials.DeleteAllOnSubmit(Mat); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } bfAdmin.Materials.InsertOnSubmit(mat); try { bfAdmin.SubmitChanges(); } catch (Exception) { bfAdmin = new BenefitAdminDataContext(); } } skip = 1; } } //refresh page Response.Redirect(Request.RawUrl); }