コード例 #1
0
ファイル: bill.aspx.cs プロジェクト: ZifengX/gBudget2
        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");
            }
        }
コード例 #2
0
ファイル: account.aspx.cs プロジェクト: ZifengX/gBudget2
        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");
            }
        }
コード例 #3
0
ファイル: category.aspx.cs プロジェクト: ZifengX/gBudget2
        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");
            }
        }
コード例 #4
0
ファイル: accounts.aspx.cs プロジェクト: ZifengX/gBudget2
        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();
        }
コード例 #5
0
ファイル: bills.aspx.cs プロジェクト: ZifengX/gBudget2
        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();
        }