C# Windows GUI Application. PROGRAM LANGUAGE: C# Here are the instructions I nee
ID: 3846267 • Letter: C
Question
C# Windows GUI Application.
PROGRAM LANGUAGE: C#
Here are the instructions I need help with this project as far as setting up the printpreview methods, and printing from an Array is something I haven't done before.
"Array of a structure. Create a project to analyze an income survey. The statistics for each home include an identification code, the number of members in the household, and the yearly income.
The Menus will include File, Reports, and Help. The File menu will contain Enter Data and Exit. As The data are entered, they should be assigned from the text boxes to the elements of a structure.
The reports for the project will be sent to the Print Preview Dialog. Each report should include a title, the programmer name, and the labels identifying the data.
Report 1: A report that displays the input data.
Report 2: A two-Coloumn report listing of the identification number, income for each household that exceeds the average income. The calculated average income should display at the top of the report.
Report 3: The percentage of households that have incomes below the poverty level.
Poverty Guidelines for 2008
Below is what my Form looks like and the Printpreview windows are what the outputs should look like.
Family Size Income 1 10210 2 13690 3 17170 4 20650 5 24130 6 27610 7 31090 8 34570 For each additional person add 3480 About Income Survey Income Survey Analysis an Income Survey Lists households that exceeds the average income Lists percentage of households below poverty level CloseExplanation / Answer
private void PopulateSurvey()
{
List<Question> questions = (from p in context.Questions
join q in context.SurveyQuestions on p.ID equals q.QuestionID
where q.SurveyID == surveyid
select p).ToList();
Table tbl = new Table();
tbl.Width = Unit.Percentage(100);
TableRow tr;
TableCell tc;
TextBox txt;
CheckBox cbk;
DropDownList ddl;
foreach (Question q in questions)
{
tr = new TableRow();
tc = new TableCell();
tc.Width = Unit.Percentage(25);
tc.Text = q.Text;
tc.Attributes.Add("id", q.ID.ToString());
tr.Cells.Add(tc);
tc = new TableCell();
if (q.QuestionType.ToLower() == "singlelinetextbox")
{
txt = new TextBox();
txt.ID = "txt_" + q.ID;
txt.Width = Unit.Percentage(40);
tc.Controls.Add(txt);
}
if (q.QuestionType.ToLower() == "multilinetextbox")
{
txt = new TextBox();
txt.ID = "txt_" + q.ID;
txt.TextMode = TextBoxMode.MultiLine;
txt.Width = Unit.Percentage(40);
tc.Controls.Add(txt);
}
if (q.QuestionType.ToLower() == "singleselect")
{
ddl = new DropDownList();
ddl.ID = "ddl_" + q.ID;
ddl.Width = Unit.Percentage(41);
if (!string.IsNullOrEmpty(q.Options))
{
string[] values = q.Options.Split(',');
foreach (string v in values)
ddl.Items.Add(v.Trim());
}
tc.Controls.Add(ddl);
}
tc.Width = Unit.Percentage(80);
tr.Cells.Add(tc);
tbl.Rows.Add(tr);
}
pnlSurvey.Controls.Add(tbl);
}
Below is the code to get response from the dynamic controls, after the submit button is clicked.
private List<Survey_Response> GetSurveyReponse()
{
List<Survey_Response> response = new List<Survey_Response>();
foreach (Control ctr in pnlSurvey.Controls)
{
if (ctr is Table)
{
Table tbl = ctr as Table;
foreach (TableRow tr in tbl.Rows)
{
Survey_Response sres = new Survey_Response();
sres.FilledBy = 2;
sres.SurveyID = surveyid;
sres.QuestionID = Convert.ToInt32(tr.Cells[0].Attributes["ID"]);
TableCell tc = tr.Cells[1];
foreach (Control ctrc in tc.Controls)
{
if (ctrc is TextBox)
{
sres.Response = (ctrc as TextBox).Text.Trim();
}
else if (ctrc is DropDownList)
{
sres.Response = (ctrc as DropDownList).SelectedValue;
}
else if (ctrc is CheckBox)
{
sres.Response = (ctrc as CheckBox).Checked.ToString();
}
}
response.Add(sres);
}
}
}
return response;
}
-------------------
Create new tables with the following script on this database
USE [SurveyApp]
GO
/****** Object: Table [dbo].[Roles] Script Date: 09/12/2012 15:46:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Roles](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](200) NOT NULL,
CONSTRAINT [PK_Roles] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object: Table [dbo].[Questions] Script Date: 09/12/2012 15:46:10 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Questions](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Text] [varchar](200) NOT NULL,
[QuestionType] [varchar](200) NOT NULL,
[Options] [varchar](2000) NOT NULL,
CONSTRAINT [PK_Questions] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object: Table [dbo].[Users] Script Date: 09/12/2012 15:46:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Users](
[ID] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [varchar](200) NOT NULL,
[LastName] [varchar](200) NULL,
[UserName] [varchar](200) NOT NULL,
[Password] [varchar](200) NOT NULL,
[Role] [int] NOT NULL,
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object: Table [dbo].[Surveys] Script Date: 09/12/2012 15:46:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Surveys](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Title] [varchar](200) NULL,
[Description] [varchar](200) NOT NULL,
[CreatedOn] [datetime] NOT NULL,
[ExpiresOn] [datetime] NULL,
[CreatedBy] [int] NOT NULL,
[Publish] [bit] NOT NULL,
CONSTRAINT [PK_Surveys] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object: Table [dbo].[SurveyResponse] Script Date: 09/12/2012 15:46:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[SurveyResponse](
[ID] [int] NOT NULL,
[SurveyID] [int] NOT NULL,
[QuestionID] [int] NOT NULL,
[Response] [varchar](200) NOT NULL,
[FilledBy] [int] NOT NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object: Table [dbo].[Survey_Questions] Script Date: 09/12/2012 15:46:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Survey_Questions](
[ID] [int] NOT NULL,
[SurveyID] [int] NOT NULL,
[QuestionID] [int] NOT NULL,
[OrderId] [int] NULL
) ON [PRIMARY]
GO
/****** Object: ForeignKey [FK_Survey_Questions_Questions] Script Date: 09/12/2012 15:46:11 ******/
ALTER TABLE [dbo].[Survey_Questions] WITH CHECK ADD CONSTRAINT [FK_Survey_Questions_Questions] FOREIGN KEY([QuestionID])
REFERENCES [dbo].[Questions] ([ID])
GO
ALTER TABLE [dbo].[Survey_Questions] CHECK CONSTRAINT [FK_Survey_Questions_Questions]
GO
/****** Object: ForeignKey [FK_Survey_Questions_Surveys] Script Date: 09/12/2012 15:46:11 ******/
ALTER TABLE [dbo].[Survey_Questions] WITH CHECK ADD CONSTRAINT [FK_Survey_Questions_Surveys] FOREIGN KEY([SurveyID])
REFERENCES [dbo].[Surveys] ([ID])
GO
ALTER TABLE [dbo].[Survey_Questions] CHECK CONSTRAINT [FK_Survey_Questions_Surveys]
GO
/****** Object: ForeignKey [FK_SurveyResponse_Questions] Script Date: 09/12/2012 15:46:11 ******/
ALTER TABLE [dbo].[SurveyResponse] WITH CHECK ADD CONSTRAINT [FK_SurveyResponse_Questions] FOREIGN KEY([QuestionID])
REFERENCES [dbo].[Questions] ([ID])
GO
ALTER TABLE [dbo].[SurveyResponse] CHECK CONSTRAINT [FK_SurveyResponse_Questions]
GO
/****** Object: ForeignKey [FK_SurveyResponse_Surveys] Script Date: 09/12/2012 15:46:11 ******/
ALTER TABLE [dbo].[SurveyResponse] WITH CHECK ADD CONSTRAINT [FK_SurveyResponse_Surveys] FOREIGN KEY([SurveyID])
REFERENCES [dbo].[Surveys] ([ID])
GO
ALTER TABLE [dbo].[SurveyResponse] CHECK CONSTRAINT [FK_SurveyResponse_Surveys]
GO
/****** Object: ForeignKey [FK_SurveyResponse_Users] Script Date: 09/12/2012 15:46:11 ******/
ALTER TABLE [dbo].[SurveyResponse] WITH CHECK ADD CONSTRAINT [FK_SurveyResponse_Users] FOREIGN KEY([FilledBy])
REFERENCES [dbo].[Users] ([ID])
GO
ALTER TABLE [dbo].[SurveyResponse] CHECK CONSTRAINT [FK_SurveyResponse_Users]
GO
/****** Object: ForeignKey [FK_Surveys_Users] Script Date: 09/12/2012 15:46:11 ******/
ALTER TABLE [dbo].[Surveys] WITH CHECK ADD CONSTRAINT [FK_Surveys_Users] FOREIGN KEY([CreatedBy])
REFERENCES [dbo].[Users] ([ID])
GO
ALTER TABLE [dbo].[Surveys] CHECK CONSTRAINT [FK_Surveys_Users]
GO
/****** Object: ForeignKey [FK_Users_Roles] Script Date: 09/12/2012 15:46:11 ******/
ALTER TABLE [dbo].[Users] WITH CHECK ADD CONSTRAINT [FK_Users_Roles] FOREIGN KEY([Role])
REFERENCES [dbo].[Roles] ([ID])
GO
ALTER TABLE [dbo].[Users] CHECK CONSTRAINT [FK_Users_Roles]
GO
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.