public void GetData(string sidx, string sord, int?_page)
        {
            int          rows = Functions.GetGridNumberOfRows();
            int          numberOfPagesToShow = Functions.GetGridNumberOfPagesToShow();
            int          currentPage         = _page is null ? 1 : Convert.ToInt32(_page);
            int          startRowIndex       = ((currentPage * rows) - rows);
            int          totalRecords        = Couse.GetRecordCount();
            int          totalPages          = (int)Math.Ceiling((float)totalRecords / (float)rows);
            List <Couse> objCouseCol         = Couse.SelectSkipAndTake(rows, startRowIndex, sidx + " " + sord);

            // fields and titles
            string[,] fieldNames = new string[, ] {
                { "Couseid", "Couseid" },
                { "CouseName", "Couse Name" },
                { "CourseStartDate", "Course Start Date" },
                { "CourseEndDate", "Course End Date" },
                { "CouseFees", "Couse Fees" }
            };

            // assign properties
            CouseData            = objCouseCol;
            CouseFieldNames      = fieldNames;
            TotalPages           = totalPages;
            CurrentPage          = currentPage;
            FieldToSort          = String.IsNullOrEmpty(sidx) ? "Couseid" : sidx;
            FieldSortOrder       = String.IsNullOrEmpty(sord) ? "asc" : sord;
            FieldToSortWithOrder = String.IsNullOrEmpty(sidx) ? "Couseid" : (sidx + " " + sord).Trim();
            NumberOfPagesToShow  = numberOfPagesToShow;
            StartPage            = Functions.GetPagerStartPage(currentPage, numberOfPagesToShow, totalPages);
            EndPage = Functions.GetPagerEndPage(StartPage, currentPage, numberOfPagesToShow, totalPages);
        }
    /// <summary>
    /// Shows how to Select all records.  It also shows how to sort, bind, and loop through records.
    /// </summary>
    private void SelectAll()
    {
        // select all records
        List <Enquiry> objEnquiryCol = Enquiry.SelectAll();

        // Example 1:  you can optionally sort the collection in ascending order by your chosen field
        objEnquiryCol.Sort(Enquiry.ByCourseId);

        // Example 2:  to sort in descending order, add this line to the Sort code in Example 1
        objEnquiryCol.Reverse();

        // Example 3:  directly bind to a GridView - for ASP.NET Web Forms
        // GridView grid = new GridView();
        // grid.DataSource = objEnquiryCol;
        // grid.DataBind();

        // Example 4:  loop through all the Enquiry(s)
        foreach (Enquiry objEnquiry in objEnquiryCol)
        {
            int    enquiryId   = objEnquiry.EnquiryId;
            int    courseId    = objEnquiry.CourseId;
            string studentName = objEnquiry.StudentName;
            Int64  contactNo   = objEnquiry.ContactNo;
            string comments    = objEnquiry.Comments;

            // get the Enquiry related to EnquiryId.
            Enquiry objEnquiryRelatedToEnquiryId = Enquiry.SelectByPrimaryKey(enquiryId);

            // get the Couse related to CourseId.
            Couse objCouseRelatedToCourseId = objEnquiry.CourseIdNavigation;
        }
    }
Esempio n. 3
0
    /// <summary>
    /// The example below shows how to Select the Couseid and CouseName columns for use with a with a Drop Down List, Combo Box, Checked Box List, List View, List Box, etc
    /// </summary>
    private void SelectCouseDropDownListData()
    {
        List <Couse> objCouseCol = Couse.SelectCouseDropDownListData();

        // Example 1:  directly bind to a drop down list - for ASP.NET Web Forms
        // DropDownList ddl1 = new DropDownList();
        // ddl1.DataValueField = "Couseid";
        // ddl1.DataTextField = "CouseName";
        // ddl1.DataSource = objCouseCol;
        // ddl1.DataBind();

        // Example 2:  add each item through a loop - for ASP.NET Web Forms
        // DropDownList ddl2 = new DropDownList();

        // foreach (Couse objCouse in objCouseCol)
        // {
        //     ddl2.Items.Add(new ListItem(objCouse.CouseName, objCouse.Couseid.ToString()));
        // }

        // Example 3:  bind to a combo box.  for Windows Forms (WinForms)
        // ComboBox cbx1 = new ComboBox();

        // foreach (Couse objCouse in objCouseCol)
        // {
        //     cbx1.Items.Add(new ListItem(objCouse.CouseName, objCouse.Couseid.ToString()));
        // }
    }
Esempio n. 4
0
    /// <summary>
    /// Shows how to get a specific number of sorted records, starting from an index, based on Search Parameters.  The number of records are also retrieved.
    /// </summary>
    private void SelectSkipAndTakeDynamicWhere()
    {
        int    startRetrievalFromRecordIndex = 0;
        int    numberOfRecordsToRetrieve     = 10;
        string sortBy = "Couseid";
        //string sortBy = "Couseid desc";

        // search parameters, everything is nullable, only items being searched for should be filled
        // note: fields with String type uses a LIKE search, everything else uses an exact match
        // also, every field you're searching for uses the AND operator
        // e.g. int? productID = 1; string productName = "ch";
        // will translate to: SELECT....WHERE productID = 1 AND productName LIKE '%ch%'
        int?     couseid         = null;
        string   couseName       = null;
        DateTime?courseStartDate = null;
        DateTime?courseEndDate   = null;
        Int64?   couseFees       = null;

        // 1. select a specific number of sorted records starting from the index you specify based on Search Parameters
        List <Couse> objCouseCol = Couse.SelectSkipAndTakeDynamicWhere(couseid, couseName, courseStartDate, courseEndDate, couseFees, numberOfRecordsToRetrieve, startRetrievalFromRecordIndex, sortBy);

        // to use objCouseCol please see the SelectAll() method examples
        // No need for Examples 1 and 2 because the Collection here is already sorted
        // Example 3:  directly bind to a GridView - for ASP.NET Web Forms
        // Example 4:  loop through all the Couse(s).  The example above will only loop for 10 items.
    }
Esempio n. 5
0
    /// <summary>
    /// Shows how to Select all records.  It also shows how to sort, bind, and loop through records.
    /// </summary>
    private void SelectAll()
    {
        // select all records
        List <Couse> objCouseCol = Couse.SelectAll();

        // Example 1:  you can optionally sort the collection in ascending order by your chosen field
        objCouseCol.Sort(Couse.ByCouseName);

        // Example 2:  to sort in descending order, add this line to the Sort code in Example 1
        objCouseCol.Reverse();

        // Example 3:  directly bind to a GridView - for ASP.NET Web Forms
        // GridView grid = new GridView();
        // grid.DataSource = objCouseCol;
        // grid.DataBind();

        // Example 4:  loop through all the Couse(s)
        foreach (Couse objCouse in objCouseCol)
        {
            int      couseid         = objCouse.Couseid;
            string   couseName       = objCouse.CouseName;
            DateTime courseStartDate = objCouse.CourseStartDate;
            DateTime courseEndDate   = objCouse.CourseEndDate;
            Int64    couseFees       = objCouse.CouseFees;
        }
    }
Esempio n. 6
0
        /// <summary>
        /// Handler, deletes a record.
        /// </summary>
        public IActionResult OnGetRemove(int id)
        {
            Couse Couse = Couse.SelectByPrimaryKey(id);

            Couse.Delete(id);
            return(new JsonResult(true));
        }
Esempio n. 7
0
        /// <summary>
        /// Handler, updates a record.
        /// </summary>
        public IActionResult OnGetUpdate(int id, string serializedData)
        {
            Couse objCouse = JsonConvert.DeserializeObject <Couse>(serializedData);

            CouseFunctions.AddOrEdit(objCouse, CrudOperation.Update, true);
            return(new JsonResult(true));
        }
Esempio n. 8
0
        /// <summary>
        /// Gets the list of data for use by the jqgrid plug-in
        /// </summary>
        public IActionResult OnGetGridData(string sidx, string sord, int _page, int rows, bool isforJqGrid = true)
        {
            int          totalRecords  = Couse.GetRecordCount();
            int          startRowIndex = ((_page * rows) - rows);
            List <Couse> objCouseCol   = Couse.SelectSkipAndTake(rows, startRowIndex, sidx + " " + sord);
            int          totalPages    = (int)Math.Ceiling((float)totalRecords / (float)rows);

            if (objCouseCol is null)
            {
                return(new JsonResult("{ total = 0, page = 0, records = 0, rows = null }"));
            }

            var jsonData = new
            {
                total = totalPages,
                _page,
                records = totalRecords,
                rows    = (
                    from objCouse in objCouseCol
                    select new
                {
                    id = objCouse.Couseid,
                    cell = new string[] {
                        objCouse.Couseid.ToString(),
                        objCouse.CouseName,
                        objCouse.CourseStartDate.ToString("d"),
                        objCouse.CourseEndDate.ToString("d"),
                        objCouse.CouseFees.ToString()
                    }
                }).ToArray()
            };

            return(new JsonResult(jsonData));
        }
Esempio n. 9
0
        /// <summary>
        /// Used when adding or updating a record.
        /// </summary>
        internal static void AddOrEdit(Couse model, CrudOperation operation, bool isForListInline = false)
        {
            Couse   objCouse;
            Couse   objCouseOld = new Couse();
            decimal id          = 0;

            if (operation == CrudOperation.Add)
            {
                objCouse = new Couse();
            }
            else
            {
                objCouse    = Couse.SelectByPrimaryKey(model.Couseid);
                objCouseOld = objCouse.ShallowCopy();
            }

            objCouse.Couseid         = model.Couseid;
            objCouse.CouseName       = model.CouseName;
            objCouse.CourseStartDate = model.CourseStartDate;
            objCouse.CourseEndDate   = model.CourseEndDate;
            objCouse.CouseFees       = model.CouseFees;

            if (operation == CrudOperation.Add)
            {
                id = objCouse.Insert();
            }
            else
            {
                objCouse.Update();
            }
        }
Esempio n. 10
0
    /// <summary>
    /// Shows how to Select all records sorted by column name in either ascending or descending order.
    /// </summary>
    private void SelectAllWithSortExpression()
    {
        // select all records sorted by Couseid in ascending order
        string sortBy = "Couseid"; // ascending order
        //string sortBy = "Couseid desc"; // descending order

        List <Couse> objCouseCol = Couse.SelectAll(sortBy);
    }
        public void LoadPage(int id, string returnUrl)
        {
            // select a record by primary key(s)
            StudentEnquiryAPI.BusinessObject.Couse objCouse = Couse.SelectByPrimaryKey(id);

            // assign values to this page's bound property
            Couse = objCouse;

            // assign the return url
            ReturnUrl = returnUrl;
        }
Esempio n. 12
0
        /// <summary>
        /// Updates a record
        /// </summary>
        internal static void Update(Couse objCouse)
        {
            StudentEnquiryDBContext context = new StudentEnquiryDBContext();
            Couse entCouse = context.Couse.Where(c => c.Couseid == objCouse.Couseid).FirstOrDefault();

            if (entCouse != null)
            {
                entCouse.CouseName       = objCouse.CouseName;
                entCouse.CourseStartDate = objCouse.CourseStartDate;
                entCouse.CourseEndDate   = objCouse.CourseEndDate;
                entCouse.CouseFees       = objCouse.CouseFees;

                context.SaveChanges();
            }
        }
Esempio n. 13
0
    /// <summary>
    /// Shows how to get all records based on Search Parameters.
    /// </summary>
    private void SelectAllDynamicWhere()
    {
        // search parameters, everything is nullable, only items being searched for should be filled
        // note: fields with String type uses a LIKE search, everything else uses an exact match
        // also, every field you're searching for uses the AND operator
        // e.g. int? productID = 1; string productName = "ch";
        // will translate to: SELECT....WHERE productID = 1 AND productName LIKE '%ch%'
        int?     couseid         = null;
        string   couseName       = null;
        DateTime?courseStartDate = null;
        DateTime?courseEndDate   = null;
        Int64?   couseFees       = null;

        List <Couse> objCouseCol = Couse.SelectAllDynamicWhere(couseid, couseName, courseStartDate, courseEndDate, couseFees);
    }
Esempio n. 14
0
    /// <summary>
    /// Shows how to get a specific number of sorted records, starting from an index.  The total number of records are also retrieved when using the SelectSkipAndTake() method.
    /// For example, if there are 200 records take only 10 records (numberOfRecordsToRetrieve), starting from the first index (startRetrievalFromRecordIndex = 0)
    /// The example below uses some variables, here are their definitions:
    /// totalRecordCount - total number of records if you were to retrieve everything
    /// startRetrievalFromRecordIndex - the index to start taking records from. Zero (0) E.g. If you want to skip the first 20 records, then assign 19 here.
    /// numberOfRecordsToRetrieve - take n records starting from the startRetrievalFromRecordIndex
    /// sortBy - to sort in Ascending order by Field Name, just assign just the Field Name, do not pass 'asc'
    /// sortBy - to sort in Descending order by Field Name, use the Field Name, a space and the word 'desc'
    /// </summary>
    private void SelectSkipAndTake()
    {
        int    startRetrievalFromRecordIndex = 0;
        int    numberOfRecordsToRetrieve     = 10;
        string sortBy = "Couseid";
        //string sortBy = "Couseid desc";

        // 1. select a specific number of sorted records starting from the index you specify
        List <Couse> objCouseCol = Couse.SelectSkipAndTake(numberOfRecordsToRetrieve, startRetrievalFromRecordIndex, sortBy);

        // to use objCouseCol please see the SelectAll() method examples
        // No need for Examples 1 and 2 because the Collection here is already sorted
        // Example 2:  directly bind to a GridView - for ASP.NET Web Forms
        // Example 3:  loop through all the Couse(s).  The example above will only loop for 10 items.
    }
Esempio n. 15
0
    /// <summary>
    /// Shows how to Insert or Create a New Record
    /// </summary>
    private void Insert()
    {
        // first instantiate a new Couse
        Couse objCouse = new Couse();

        // assign values you want inserted
        objCouse.CouseName       = "abc";
        objCouse.CourseStartDate = DateTime.Now;
        objCouse.CourseEndDate   = DateTime.Now;
        objCouse.CouseFees       = 12;

        // finally, insert a new record
        // the insert method returns the newly created primary key
        int newlyCreatedPrimaryKey = objCouse.Insert();
    }
Esempio n. 16
0
        /// <summary>
        /// Inserts a record
        /// </summary>
        internal static int Insert(Couse objCouse)
        {
            StudentEnquiryDBContext context = new StudentEnquiryDBContext();
            Couse entCouse = new Couse();

            entCouse.CouseName       = objCouse.CouseName;
            entCouse.CourseStartDate = objCouse.CourseStartDate;
            entCouse.CourseEndDate   = objCouse.CourseEndDate;
            entCouse.CouseFees       = objCouse.CouseFees;

            context.Couse.Add(entCouse);
            context.SaveChanges();

            return(entCouse.Couseid);
        }
Esempio n. 17
0
    /// <summary>
    /// Shows how to Update an existing record by Primary Key
    /// </summary>
    private void Update()
    {
        // first instantiate a new Couse
        Couse objCouse = new Couse();

        // assign the existing primary key(s)
        // of the record you want updated
        objCouse.Couseid = 12;

        // assign values you want updated
        objCouse.CouseName       = "abc";
        objCouse.CourseStartDate = DateTime.Now;
        objCouse.CourseEndDate   = DateTime.Now;
        objCouse.CouseFees       = 12;

        // finally, update an existing record
        objCouse.Update();
    }
Esempio n. 18
0
    /// <summary>
    /// Shows how to Select a record by Primary Key.  It also shows how to retrieve Lazily-loaded related Objects.  Related Objects are assigned for each Foreign Key.
    /// </summary>
    private void SelectByPrimaryKey()
    {
        int couseidSample = 12;

        // select a record by primary key(s)

        Couse objCouse = Couse.SelectByPrimaryKey(couseidSample);

        if (objCouse != null)
        {
            // if record is found, a record is returned
            int      couseid         = objCouse.Couseid;
            string   couseName       = objCouse.CouseName;
            DateTime courseStartDate = objCouse.CourseStartDate;
            DateTime courseEndDate   = objCouse.CourseEndDate;
            Int64    couseFees       = objCouse.CouseFees;
        }
    }
        private PageResult LoadPage(string returnUrl)
        {
            // create the model used by the partial page
            AddEditEnquiryPartialModel model = new AddEditEnquiryPartialModel();

            model.EnquiryDropDownListData = Enquiry.SelectEnquiryDropDownListData();
            model.CouseDropDownListData   = Couse.SelectCouseDropDownListData();
            model.Operation = CrudOperation.Add;
            model.ReturnUrl = returnUrl;

            // assign values to the model used by this page
            PartialModel = model;

            // assign the return url
            ReturnUrl = returnUrl;

            return(Page());
        }
        public PageResult LoadPage(int id, string returnUrl)
        {
            // select a record by primary key(s)
            StudentEnquiryAPI.BusinessObject.Couse objCouse = Couse.SelectByPrimaryKey(id);

            // create the model used by the partial page
            AddEditCousePartialModel model = new AddEditCousePartialModel();

            model.Operation = CrudOperation.Update;
            model.ReturnUrl = returnUrl;
            model.Couse     = objCouse;

            // assign values to the model used by this page
            PartialModel = model;

            // assign the return url
            ReturnUrl = returnUrl;

            return(Page());
        }
    /// <summary>
    /// Shows how to Select a record by Primary Key.  It also shows how to retrieve Lazily-loaded related Objects.  Related Objects are assigned for each Foreign Key.
    /// </summary>
    private void SelectByPrimaryKey()
    {
        int enquiryIdSample = 12;

        // select a record by primary key(s)

        Enquiry objEnquiry = Enquiry.SelectByPrimaryKey(enquiryIdSample);

        if (objEnquiry != null)
        {
            // if record is found, a record is returned
            int    enquiryId   = objEnquiry.EnquiryId;
            int    courseId    = objEnquiry.CourseId;
            string studentName = objEnquiry.StudentName;
            Int64  contactNo   = objEnquiry.ContactNo;
            string comments    = objEnquiry.Comments;

            // get the Enquiry related to EnquiryId.
            Enquiry objEnquiryRelatedToEnquiryId = Enquiry.SelectByPrimaryKey(enquiryId);

            // get the Couse related to CourseId.
            Couse objCouseRelatedToCourseId = objEnquiry.CourseIdNavigation;
        }
    }
        /// <summary>
        /// Gets the list of data for use by the jqgrid plug-in
        /// </summary>
        public IActionResult OnGetGridDataWithFilters(string sidx, string sord, int _page, int rows, string filters)
        {
            int?     couseid         = null;
            string   couseName       = String.Empty;
            DateTime?courseStartDate = null;
            DateTime?courseEndDate   = null;
            Int64?   couseFees       = null;

            if (!String.IsNullOrEmpty(filters))
            {
                // deserialize json and get values being searched
                var jsonResult = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(filters);

                foreach (var rule in jsonResult["rules"])
                {
                    if (rule["field"].Value.ToLower() == "couseid")
                    {
                        couseid = Convert.ToInt32(rule["data"].Value);
                    }

                    if (rule["field"].Value.ToLower() == "cousename")
                    {
                        couseName = rule["data"].Value;
                    }

                    if (rule["field"].Value.ToLower() == "coursestartdate")
                    {
                        courseStartDate = Convert.ToDateTime(rule["data"].Value);
                    }

                    if (rule["field"].Value.ToLower() == "courseenddate")
                    {
                        courseEndDate = Convert.ToDateTime(rule["data"].Value);
                    }

                    if (rule["field"].Value.ToLower() == "cousefees")
                    {
                        couseFees = Convert.ToInt64(rule["data"].Value);
                    }
                }

                // sometimes jqgrid assigns a -1 to numeric fields when no value is assigned
                // instead of assigning a null, we'll correct this here
                if (couseid == -1)
                {
                    couseid = null;
                }

                if (couseFees == -1)
                {
                    couseFees = null;
                }
            }

            int          totalRecords  = Couse.GetRecordCountDynamicWhere(couseid, couseName, courseStartDate, courseEndDate, couseFees);
            int          startRowIndex = ((_page * rows) - rows);
            List <Couse> objCouseCol   = Couse.SelectSkipAndTakeDynamicWhere(couseid, couseName, courseStartDate, courseEndDate, couseFees, rows, startRowIndex, sidx + " " + sord);
            int          totalPages    = (int)Math.Ceiling((float)totalRecords / (float)rows);

            if (objCouseCol is null)
            {
                return(new JsonResult("{ total = 0, page = 0, records = 0, rows = null }"));
            }

            var jsonData = new
            {
                total = totalPages,
                _page,
                records = totalRecords,
                rows    = (
                    from objCouse in objCouseCol
                    select new
                {
                    id = objCouse.Couseid,
                    cell = new string[] {
                        objCouse.Couseid.ToString(),
                        objCouse.CouseName,
                        objCouse.CourseStartDate.ToString("d"),
                        objCouse.CourseEndDate.ToString("d"),
                        objCouse.CouseFees.ToString()
                    }
                }).ToArray()
            };

            return(new JsonResult(jsonData));
        }
Esempio n. 23
0
 /// <summary>
 /// Shows how to Delete an existing record by Primary Key
 /// </summary>
 private void Delete()
 {
     // delete a record by primary key
     Couse.Delete(12);
 }
Esempio n. 24
0
 /// <summary>
 /// Shows how to get the total number of records
 /// </summary>
 private void GetRecordCount()
 {
     // get the total number of records in the Couse table
     int totalRecordCount = Couse.GetRecordCount();
 }
        /// <summary>
        /// Updates a record
        /// </summary>
        public void Update()
        {
            Couse objCouse = (Couse)this;

            CouseDataLayer.Update(objCouse);
        }
 /// <summary>
 /// Initial handler the razor page encounters.
 /// </summary>
 public void OnGet()
 {
     EnquiryDropDownListData = Enquiry.SelectEnquiryDropDownListData();
     CouseDropDownListData   = Couse.SelectCouseDropDownListData();
 }
 /// <summary>
 /// Sets data needed on page intialization.
 /// </summary>
 private void SetData()
 {
     Enquiry = new StudentEnquiryAPI.BusinessObject.Enquiry();
     EnquiryDropDownListData = Enquiry.SelectEnquiryDropDownListData();
     CouseDropDownListData   = Couse.SelectCouseDropDownListData();
 }
        /// <summary>
        /// Inserts a record
        /// </summary>
        public int Insert()
        {
            Couse objCouse = (Couse)this;

            return(CouseDataLayer.Insert(objCouse));
        }