static void Main(string[] args) { SubProgram xp = new SubProgram(); xp.func(0); xp.funcA(); }
static void CalculateSums(SubProgram start) { while (start.ChildNodes.Exists(n => n.SumWeight == -1)) { CalculateSums(start.ChildNodes.First(n => n.SumWeight == -1)); } start.SumWeight = start.ChildNodes.Sum(n => n.SumWeight) + start.Weight; }
public ActionResult SaveAjax(SubProgram subProgram) { //id=0 means add operation, update operation otherwise bool isNew = subProgram.ID == 0; //validate data if (ModelState.IsValid) { try { //call repository function to save the data in database subprogramRepository.InsertOrUpdate(subProgram); subprogramRepository.Save(); //set status message if (isNew) { subProgram.SuccessMessage = "SubProgram has been added successfully"; } else { subProgram.SuccessMessage = "SubProgram has been updated successfully"; } } catch (CustomException ex) { subProgram.ErrorMessage = ex.UserDefinedMessage; } catch (Exception ex) { ExceptionManager.Manage(ex); subProgram.ErrorMessage = Constants.Messages.UnhandelledError; } } else { foreach (var modelStateValue in ViewData.ModelState.Values) { foreach (var error in modelStateValue.Errors) { subProgram.ErrorMessage = error.ErrorMessage; break; } if (subProgram.ErrorMessage.IsNotNullOrEmpty()) { break; } } } //return the status message in json if (subProgram.ErrorMessage.IsNotNullOrEmpty()) { return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, subProgram) })); } else { return(Json(new { success = true, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, subProgram) })); } }
public ActionResult Index([DataSourceRequest(Prefix = "Grid")] DataSourceRequest dsRequest) { if (!ViewBag.HasAccessToAdminModule) { WebHelper.CurrentSession.Content.ErrorMessage = "You are not eligible to do this action"; return(RedirectToAction(Constants.Actions.AccessDenied, Constants.Controllers.Home, new { Area = String.Empty })); } SubProgram subProgram = new SubProgram(); return(View(subProgram)); }
static void Main(string[] args) { var a = new Program(); a.PrinData(); SubProgram subProgram = new SubProgram(); subProgram.Star = "333"; SubProgram subProgram2 = new SubProgram(); }
static int GetCorrectWeight(SubProgram start) { var childs = start.ChildNodes; var correct = childs[0].SumWeight; if (childs[1].SumWeight != correct) { if (childs[2].SumWeight != correct) { correct = childs[1].SumWeight; } } return(correct); }
public ActionResult DeleteAjax(int id) { if (!ViewBag.HasAccessToAdminModule) { BaseModel baseModel = new BaseModel(); baseModel.ErrorMessage = "You are not eligible to do this action"; return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, baseModel) }, JsonRequestBehavior.AllowGet)); } //find the subProgram in database SubProgram subProgram = subprogramRepository.Find(id); if (subProgram == null) { //set error message if it does not exist in database subProgram = new SubProgram(); subProgram.ErrorMessage = "SubProgram not found"; } else { try { //delete subProgram from database subprogramRepository.Delete(subProgram); subprogramRepository.Save(); //set success message subProgram.SuccessMessage = "SubProgram has been deleted successfully"; } catch (CustomException ex) { subProgram.ErrorMessage = ex.UserDefinedMessage; } catch (Exception ex) { ExceptionManager.Manage(ex); subProgram.ErrorMessage = Constants.Messages.UnhandelledError; } } //return action status in json to display on a message bar if (subProgram.ErrorMessage.IsNotNullOrEmpty()) { return(Json(new { success = false, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, subProgram) })); } else { return(Json(new { success = true, data = this.RenderPartialViewToString(Constants.PartialViews.AlertSliding, subProgram) })); } }
static void BuildNodeTree(SubProgram start) { if (start.Children.Count > 0) { var childs = SubPrograms.Where(sp => start.Children.Contains(sp.Name)); start.ChildNodes = childs.ToList(); foreach (var childNode in childs) { childNode.Parent = start; BuildNodeTree(childNode); } } else { return; } }
public static ProgramDto AsDto(this SubProgram subProgram, Program program) { return(new ProgramDto { Category = program.Category, Description = subProgram.Description, Id = subProgram.Id, Leaders = subProgram.Leaders, Photo = subProgram.Photo, Sounds = subProgram.Sounds, AntenaId = program.AntenaId, ArticleLink = program.ArticleLink, IsActive = subProgram.IsActive, StartHour = subProgram.StartHour, StopHour = subProgram.StopHour, Title = subProgram.Title }); }
public ActionResult EditorAjax(int id) { SubProgram subProgram = null; if (id > 0) { //find an existing subProgram from database subProgram = subprogramRepository.Find(id); if (subProgram == null) { //throw an exception if id is provided but data does not exist in database return(new HttpStatusCodeResult(System.Net.HttpStatusCode.NotFound, "SubProgram not found")); } } else { //create a new instance if id is not provided subProgram = new SubProgram(); } //return the html of editor to display on popup return(Content(this.RenderPartialViewToString(Constants.PartialViews.CreateOrEdit, subProgram))); }
//SUBPROGRAM static void sqlite3VdbeChangeP4( Vdbe p, int addr, SubProgram pProgram, int n ) { union_p4 _p4 = new union_p4(); _p4.pProgram = pProgram; sqlite3VdbeChangeP4( p, addr, _p4, n ); }
/* ** Decrement the ref-count on the SubProgram structure passed as the ** second argument. If the ref-count reaches zero, free the structure. ** ** The array of VDBE opcodes stored as SubProgram.aOp is freed if ** either the ref-count reaches zero or parameter freeop is non-zero. ** ** Since the array of opcodes pointed to by SubProgram.aOp may directly ** or indirectly contain a reference to the SubProgram structure itself. ** By passing a non-zero freeop parameter, the caller may ensure that all ** SubProgram structures and their aOp arrays are freed, even when there ** are such circular references. */ static void sqlite3VdbeProgramDelete( sqlite3 db, SubProgram p, int freeop ) { if ( p != null ) { Debug.Assert( p.nRef > 0 ); if ( freeop != 0 || p.nRef == 1 ) { Op[] aOp = p.aOp; p.aOp = null; vdbeFreeOpArray( db, ref aOp, p.nOp ); p.nOp = 0; } p.nRef--; if ( p.nRef == 0 ) { p = null; sqlite3DbFree( db, ref p ); } } }
static SubProgram GetWrongNode(SubProgram start) { var correct = GetCorrectWeight(start); return(start.ChildNodes.SingleOrDefault(n => n.SumWeight != correct)); }
public void ChangeP4(int addr, string z, Action<object> notUsed1) { ChangeP4(addr, new P4_t { Z = z }, (int)P4T.DYNAMIC); } // STRING + Type public void ChangeP4(int addr, SubProgram program, int n) { ChangeP4(addr, new P4_t { Program = program }, n); } // SUBPROGRAM
/* ** Link the SubProgram object passed as the second argument into the linked ** list at Vdbe.pSubProgram. This list is used to delete all sub-program ** objects when the VM is no longer required. */ static void sqlite3VdbeLinkSubProgram( Vdbe pVdbe, SubProgram p ) { p.pNext = pVdbe.pProgram; pVdbe.pProgram = p; }
/* ** Create and populate a new TriggerPrg object with a sub-program ** implementing trigger pTrigger with ON CONFLICT policy orconf. */ static TriggerPrg codeRowTrigger( Parse pParse, /* Current parse context */ Trigger pTrigger, /* Trigger to code */ Table pTab, /* The table pTrigger is attached to */ int orconf /* ON CONFLICT policy to code trigger program with */ ) { Parse pTop = sqlite3ParseToplevel( pParse ); sqlite3 db = pParse.db; /* Database handle */ TriggerPrg pPrg; /* Value to return */ Expr pWhen = null; /* Duplicate of trigger WHEN expression */ Vdbe v; /* Temporary VM */ NameContext sNC; /* Name context for sub-vdbe */ SubProgram pProgram = null; /* Sub-vdbe for trigger program */ Parse pSubParse; /* Parse context for sub-vdbe */ int iEndTrigger = 0; /* Label to jump to if WHEN is false */ Debug.Assert( pTrigger.zName == null || pTab == tableOfTrigger( pTrigger ) ); Debug.Assert( pTop.pVdbe != null ); /* Allocate the TriggerPrg and SubProgram objects. To ensure that they ** are freed if an error occurs, link them into the Parse.pTriggerPrg ** list of the top-level Parse object sooner rather than later. */ pPrg = new TriggerPrg();// sqlite3DbMallocZero( db, sizeof( TriggerPrg ) ); //if ( null == pPrg ) return 0; pPrg.pNext = pTop.pTriggerPrg; pTop.pTriggerPrg = pPrg; pPrg.pProgram = pProgram = new SubProgram();// sqlite3DbMallocZero( db, sizeof( SubProgram ) ); //if( null==pProgram ) return 0; sqlite3VdbeLinkSubProgram( pTop.pVdbe, pProgram ); pPrg.pTrigger = pTrigger; pPrg.orconf = orconf; pPrg.aColmask[0] = 0xffffffff; pPrg.aColmask[1] = 0xffffffff; /* Allocate and populate a new Parse context to use for coding the ** trigger sub-program. */ pSubParse = new Parse();// sqlite3StackAllocZero( db, sizeof( Parse ) ); //if ( null == pSubParse ) return null; sNC = new NameContext();// memset( &sNC, 0, sizeof( sNC ) ); sNC.pParse = pSubParse; pSubParse.db = db; pSubParse.pTriggerTab = pTab; pSubParse.pToplevel = pTop; pSubParse.zAuthContext = pTrigger.zName; pSubParse.eTriggerOp = pTrigger.op; pSubParse.nQueryLoop = pParse.nQueryLoop; v = sqlite3GetVdbe( pSubParse ); if ( v != null ) { #if SQLITE_DEBUG VdbeComment( v, "Start: %s.%s (%s %s%s%s ON %s)", pTrigger.zName != null ? pTrigger.zName : "", onErrorText( orconf ), ( pTrigger.tr_tm == TRIGGER_BEFORE ? "BEFORE" : "AFTER" ), ( pTrigger.op == TK_UPDATE ? "UPDATE" : "" ), ( pTrigger.op == TK_INSERT ? "INSERT" : "" ), ( pTrigger.op == TK_DELETE ? "DELETE" : "" ), pTab.zName ); #endif #if !SQLITE_OMIT_TRACE sqlite3VdbeChangeP4( v, -1, sqlite3MPrintf( db, "-- TRIGGER %s", pTrigger.zName ), P4_DYNAMIC ); #endif /* If one was specified, code the WHEN clause. If it evaluates to false ** (or NULL) the sub-vdbe is immediately halted by jumping to the ** OP_Halt inserted at the end of the program. */ if ( pTrigger.pWhen != null ) { pWhen = sqlite3ExprDup( db, pTrigger.pWhen, 0 ); if ( SQLITE_OK == sqlite3ResolveExprNames( sNC, ref pWhen ) //&& db.mallocFailed==0 ) { iEndTrigger = sqlite3VdbeMakeLabel( v ); sqlite3ExprIfFalse( pSubParse, pWhen, iEndTrigger, SQLITE_JUMPIFNULL ); } sqlite3ExprDelete( db, ref pWhen ); } /* Code the trigger program into the sub-vdbe. */ codeTriggerProgram( pSubParse, pTrigger.step_list, orconf ); /* Insert an OP_Halt at the end of the sub-program. */ if ( iEndTrigger != 0 ) { sqlite3VdbeResolveLabel( v, iEndTrigger ); } sqlite3VdbeAddOp0( v, OP_Halt ); #if SQLITE_DEBUG VdbeComment( v, "End: %s.%s", pTrigger.zName, onErrorText( orconf ) ); #endif transferParseError( pParse, pSubParse ); //if( db.mallocFailed==0 ){ pProgram.aOp = sqlite3VdbeTakeOpArray( v, ref pProgram.nOp, ref pTop.nMaxArg ); //} pProgram.nMem = pSubParse.nMem; pProgram.nCsr = pSubParse.nTab; pProgram.token = pTrigger.GetHashCode(); pPrg.aColmask[0] = pSubParse.oldmask; pPrg.aColmask[1] = pSubParse.newmask; sqlite3VdbeDelete( ref v ); } Debug.Assert( null == pSubParse.pAinc && null == pSubParse.pZombieTab ); Debug.Assert( null == pSubParse.pTriggerPrg && 0 == pSubParse.nMaxArg ); //sqlite3StackFree(db, pSubParse); return pPrg; }
public void LinkSubProgram(SubProgram p) { p.Next = Programs; Programs = p; }