protected void GetReports() { var currentUserID = User.Identity.GetUserId(); using (gBudget2Entities db = new gBudget2Entities()) { //query the datainfo table using EF and LINQ var Categories = from c in db.Categories where c.UserID == currentUserID select c; //bind the result to the gridview ddlCategoryReport.DataSource = Categories.ToList(); ddlCategoryReport.DataBind(); if (ddlCategoryReport.SelectedValue != "") { int selectedCategory = Convert.ToInt32(ddlCategoryReport.SelectedValue); //query the bills table using EF and LINQ var Datainfoes = from d in db.DataInfoes where d.CategoryID == selectedCategory && d.UserID == currentUserID select new { d.Date, d.Amount, d.Account.Account1, d.Mechant.Mechant1, d.Note, d.UserID }; grdCategoryReport.DataSource = Datainfoes.ToList(); grdCategoryReport.DataBind(); } } }
protected void GetBill() { var currentUserID = User.Identity.GetUserId(); //populate form with existing bill record Int32 DatainfoID = Convert.ToInt32(Request.QueryString["DatainfoID"]); //connect to db via EF using (gBudget2Entities db = new gBudget2Entities()) { //query the datainfo table using EF and LINQ var Categories = from c in db.Categories where c.UserID == currentUserID select c; //bind the result to the gridview ddlCategory.DataSource = Categories.ToList(); ddlCategory.DataBind(); var Accounts = from a in db.Accounts where a.UserID == currentUserID select a; ddlAccount.DataSource = Accounts.ToList(); ddlAccount.DataBind(); var Mechants = from m in db.Mechants where m.UserID == currentUserID select m; ddlMechant.DataSource = Mechants.ToList(); ddlMechant.DataBind(); //populate a datainfo instance with the datainfoID from the URL parameter DataInfo d = (from objD in db.DataInfoes where objD.DatainfoID == DatainfoID select objD).FirstOrDefault(); //map the datainfo properties to the form controls if we found a match if (d != null) { txtAmount.Text = Convert.ToString(d.Amount); ddlCategory.SelectedValue = Convert.ToString(d.CategoryID); ddlAccount.SelectedValue = Convert.ToString(d.AccountID); ddlMechant.SelectedValue = Convert.ToString(d.MechantID); txtNote.Text = d.Note; txtDate.Text = d.Date.ToString("yyyy-MM-dd"); } } }
protected void GetAccounts() { var currentUserID = User.Identity.GetUserId(); //connect to EF using (gBudget2Entities db = new gBudget2Entities()) { String SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString(); //query the accounts table using EF and LINQ var Accounts = from a in db.Accounts where a.UserID == currentUserID select a; //bind the result to the gridview grdAccounts.DataSource = Accounts.AsQueryable().OrderBy(SortString).ToList(); grdAccounts.DataBind(); } }
protected void btnSave_Click(object sender, EventArgs e) { var currentUserID = User.Identity.GetUserId(); //use EF to connect to SQL Server using (gBudget2Entities db = new gBudget2Entities()) { //use the datainfo model to save the new record DataInfo d = new DataInfo(); Int32 DatainfoID = 0; //check the querystring for an id so we can determine add / update if (Request.QueryString["DatainfoID"] != null) { //get the id from the url DatainfoID = Convert.ToInt32(Request.QueryString["DatainfoID"]); //get the current datainfo from EF d = (from objD in db.DataInfoes where objD.DatainfoID == DatainfoID select objD).FirstOrDefault(); } d.Amount = Convert.ToInt32(txtAmount.Text); d.CategoryID = Convert.ToInt32(ddlCategory.SelectedValue); d.AccountID = Convert.ToInt32(ddlAccount.SelectedValue); d.MechantID = Convert.ToInt32(ddlMechant.SelectedValue); d.Note = txtNote.Text; d.Date = Convert.ToDateTime(txtDate.Text); d.UserID = currentUserID; //call add only if we have no datainfo ID if (DatainfoID == 0) { db.DataInfoes.Add(d); } //run the update or insert db.SaveChanges(); //redirect to the updated students page Response.Redirect("bills.aspx"); } }
protected void GetAccount() { //populate form with existing account record Int32 AccountID = Convert.ToInt32(Request.QueryString["AccountID"]); //connect to db via EF using (gBudget2Entities db = new gBudget2Entities()) { //populate a account instance with the AccountID from the URL parameter Account a = (from objA in db.Accounts where objA.AccountID == AccountID select objA).FirstOrDefault(); //map the account properties to the form controls if we found a match if (a != null) { txtAccount.Text = a.Account1; } } }
protected void GetBills() { var currentUserID = User.Identity.GetUserId(); //connect to EF using (gBudget2Entities db = new gBudget2Entities()) { //query the bills table using EF and LINQ var Datainfoes = from d in db.DataInfoes where d.UserID == currentUserID select new { d.DatainfoID, d.Date, d.Amount, d.Category.Category1, d.Account.Account1, d.Mechant.Mechant1, d.Note, d.UserID }; //bind the result to the gridview, pass session String SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString(); grdBills.DataSource = Datainfoes.AsQueryable().OrderBy(SortString).ToList(); grdBills.DataBind(); } }
protected void GetCategory() { //populate form with existing category record Int32 CategoryID = Convert.ToInt32(Request.QueryString["CategoryID"]); //connect to db via EF using (gBudget2Entities db = new gBudget2Entities()) { //populate a category instance with the CategoryID from the URL parameter Category c = (from objC in db.Categories where objC.CategoryID == CategoryID select objC).FirstOrDefault(); //map the account properties to the form controls if we found a match if (c != null) { txtCategory.Text = c.Category1; } } }
protected void btnSave_Click(object sender, EventArgs e) { var currentUserID = User.Identity.GetUserId(); //use EF to connect to SQL Server using (gBudget2Entities db = new gBudget2Entities()) { //use the Account model to save the new record Account a = new Account(); Int32 AccountID = 0; //check the querystring for an id so we can determine add / update if (Request.QueryString["AccountID"] != null) { //get the id from the url AccountID = Convert.ToInt32(Request.QueryString["AccountID"]); //get the current account from EF a = (from objA in db.Accounts where objA.AccountID == AccountID select objA).FirstOrDefault(); } a.Account1 = txtAccount.Text; a.UserID = currentUserID; //call add only if we have no account ID if (AccountID == 0) { db.Accounts.Add(a); } //run the update or insert db.SaveChanges(); //redirect to the updated accounts page Response.Redirect("accounts.aspx"); } }
protected void btnSave_Click(object sender, EventArgs e) { var currentUserID = User.Identity.GetUserId(); //use EF to connect to SQL Server using (gBudget2Entities db = new gBudget2Entities()) { //use the category model to save the new record Category c = new Category(); Int32 CategoryID = 0; //check the querystring for an id so we can determine add / update if (Request.QueryString["CategoryID"] != null) { //get the id from the url CategoryID = Convert.ToInt32(Request.QueryString["CategoryID"]); //get the current category from EF c = (from objC in db.Categories where objC.CategoryID == CategoryID select objC).FirstOrDefault(); } c.Category1 = txtCategory.Text; c.UserID = currentUserID; //call add only if we have no category ID if (CategoryID == 0) { db.Categories.Add(c); } //run the update or insert db.SaveChanges(); //redirect to the updated accounts page Response.Redirect("categories.aspx"); } }
protected void grdAccounts_RowDeleting(object sender, GridViewDeleteEventArgs e) { //store which row was clicked Int32 selectedRow = e.RowIndex; //get the selected AccountID using the grid's Data Key collection Int32 AccountID = Convert.ToInt32(grdAccounts.DataKeys[selectedRow].Values["AccountID"]); //use EF to remove the selected account from the db using (gBudget2Entities db = new gBudget2Entities()) { Account a = (from objA in db.Accounts where objA.AccountID == AccountID select objA).FirstOrDefault(); //do the delete db.Accounts.Remove(a); db.SaveChanges(); } //refresh the grid GetAccounts(); }
protected void grdBills_RowDeleting(object sender, GridViewDeleteEventArgs e) { //store which row was clicked Int32 selectedRow = e.RowIndex; //get the selected datainfoid using the grid's Data Key collection Int32 DatainfoID = Convert.ToInt32(grdBills.DataKeys[selectedRow].Values["DatainfoID"]); //use EF to remove the selected bill from the db using (gBudget2Entities db = new gBudget2Entities()) { DataInfo d = (from objD in db.DataInfoes where objD.DatainfoID == DatainfoID select objD).FirstOrDefault(); //do the delete db.DataInfoes.Remove(d); db.SaveChanges(); } //refresh the grid GetBills(); }