Answered by:
Monthly payments

Question
-
User-139952397 posted
Hello all,
I don't know if this is the right group, if it isn't I already appologize :)
I am writing a small web-application for a friend of mine and I aint a code-pro :) But I'll manage. There is just one thing I can't seem to get the right proces designed to accomplish.
The application is a members-administration program for a small fitness center.
He has about 200 members who pay him monthly, some automatic by bank and some transfer the money themselves. Now I want to make a kind of automatic proces for the people that pay him automaticly (trough Sepa). What I want to accomplish is the following:
- He opens a form from which he can select the current month (or perhaps it is already selected automatic)
- From the database all members wil be shown who didn't paid already and do have a automatic payment (the query isn't a problem)
- In the dataview (gridview of datalist) he selects the members he want to enter in the Sepa file for payment
- when the export has run succesfull there should be a marker set in a DB field that he can see they are already exported for payment
- Afterwards he enters (by hand) which payment succeeded and which didn't.
Can someone point me in the right direction? That will be much appreciated.
I use linq2sql if that is of any value knowing :)
Thanks in advance,
Peter
Thursday, September 13, 2018 7:53 PM
Answers
-
User-893317190 posted
Hi peterV,
If you want to select data according to datetime, I think I have written in my code.
dbContext.FitnessCenters.Where(c => c.isAuto && !c.isExported && c.selectDate.Month == DateTime.Now.Month && c.selectDate.Year == DateTime.Now.Year).ToList();
If you want to check whether the person has paid, do you have a column in your table to records whether the person has paid or not?
If you have , you could choose according to the column . If you don't have , I suggest you could add such a column to your table.
Best regards,
Ackerly Xu
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, September 17, 2018 1:23 AM
All replies
-
User-893317190 posted
Hi peterV,
You could use checkbox to let your friend choose and when he click the export button , you could choose the selected row , export these rows and save the result in database.
Below is my code.Please don't forget to add EnableEventValidation = "false" or the user can't export excel.
<%@ Page Language="C#" EnableEventValidation = "false" AutoEventWireup="true" CodeBehind="FitnessCenter.aspx.cs" Inherits="MyWebFormCases.gridView2.FitnessCenter" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server" DataKeyNames="id" AutoGenerateColumns="false"> <Columns> <asp:BoundField DataField="id" HeaderText="id" /> <asp:BoundField DataField="selectDate" HeaderText="date" /> <asp:CheckBoxField DataField="isAuto" HeaderText="isAuto" /> <asp:BoundField DataField="name" HeaderText="name" /> <asp:TemplateField HeaderText="isExported"> <ItemTemplate> <asp:CheckBox runat="server" ID="box" Checked='<%# Eval("isExported") %>'></asp:CheckBox> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:Button ID="Button1" runat="server" Text="Export" OnClick="Button1_Click" /> <asp:Button ID="Button2" runat="server" Text="Refresh" OnClick="Button2_Click" /> </form> </body>
Code behind. I use entity framework. It also uses linq. And you could choose other ways to export excel. For example , you could use EPPlus.
UserItemDb dbContext = new UserItemDb(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //select records in this month of this year (and other conditions) GridView1.DataSource= dbContext.FitnessCenters.Where(c => c.isAuto && !c.isExported && c.selectDate.Month == DateTime.Now.Month && c.selectDate.Year == DateTime.Now.Year).ToList(); GridView1.DataBind(); } } protected void Button1_Click(object sender, EventArgs e) { Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename="+DateTime.Now.ToString()+".xls"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); List<int> list = new List<int>(); foreach (GridViewRow row in GridView1.Rows) { if (row.RowType == DataControlRowType.DataRow) { //select the checked checkbox if ((row.FindControl("box") as CheckBox).Checked) { //record id of the row list.Add(Convert.ToInt32(row.Cells[0].Text)); int id= Convert.ToInt32(row.Cells[0].Text); //change the isExported to true dbContext.FitnessCenters.Where(c => c.id == id).First().isExported = true; } } } //save changes to database dbContext.SaveChanges(); // bind the selected row to the gridview to export them GridView1.DataSource = dbContext.FitnessCenters.Where(C => list.Contains(C.id)).ToList(); GridView1.DataBind(); GridView1.AllowPaging = false; for (int i = 0; i < GridView1.Rows.Count; i++) { GridViewRow row = GridView1.Rows[i]; row.Attributes.Add("class", "textmode"); } GridView1.RenderControl(hw); string style = @"<style> .textmode { mso-number-format:\@; } </style>"; Response.Write(style); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); } //don't forget this , or the user can't export public override void VerifyRenderingInServerForm(Control control) { } protected void Button2_Click(object sender, EventArgs e) { GridView1.DataSource = dbContext.FitnessCenters.Where(c => c.isAuto && !c.isExported && c.selectDate.Month == DateTime.Now.Month && c.selectDate.Year == DateTime.Now.Year).ToList(); GridView1.DataBind(); }
The result.
Best regards,
Ackerly Xu
Friday, September 14, 2018 6:35 AM -
User-139952397 posted
Hi Ackerly Xu,
Thank you very much for this example, much appreciated.
I got it working but ran into this challenge with linq.
Before I fill the table with the payments I want to do a check of there isn't already a payment for that person in the payments table (earlier import)
I can't seem to get it working with linq, do you have any idea?
- Select a month and year for the payment
- hit the button to inject the payments for the selected month into the table for that particular member
- a check runs on the payments table if it isn't already there, if so a message is shown, if not the injection takes place.
Thank you very much again,
Kind regards,
Peter
Saturday, September 15, 2018 6:09 PM -
User-893317190 posted
Hi peterV,
If you want to select data according to datetime, I think I have written in my code.
dbContext.FitnessCenters.Where(c => c.isAuto && !c.isExported && c.selectDate.Month == DateTime.Now.Month && c.selectDate.Year == DateTime.Now.Year).ToList();
If you want to check whether the person has paid, do you have a column in your table to records whether the person has paid or not?
If you have , you could choose according to the column . If you don't have , I suggest you could add such a column to your table.
Best regards,
Ackerly Xu
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, September 17, 2018 1:23 AM -
User-139952397 posted
Thank you very much, I got it working :)
Friday, September 21, 2018 7:25 PM