Based on. NET platform of Windows programming Combat (VII.) The realization of statistical function of questionnaire (i)

Source: Internet
Author: User
Tags tostring

This article supporting source code

Disclaimer: This series of courses is designed for beginners to start the exercise, the purpose is to pass a complete questionnaire management system case to let the novice understand, deepen or familiar with the project development process and in. NET platform to use VS2005 and C # for Windows programming, in the course design, I try to avoid or do not discuss the underlying and performance optimization aspects of things, so the master can completely ignore this series of courses.

This lesson will lead you to the ability to add statistics, view statistics, consolidate statistics, and clear statistics about questionnaires.

First, design ideas

The design here is simpler, let's take a look at the design flowchart [as shown in Figure 7-1 below] and simply explain the process, and it may be easier for everyone to understand:

Figure 7-2 is a simple explanation: distribute the questionnaires and recycle them back, open the system has been entered in the questionnaire and a copy of the selected items in the system click on the selected, submitted, the system automatically each submitted questionnaires to accumulate statistics, and calculate the percentage, and then exported to Excel print it!

Second, the relevant principles to explain the following we will mainly look at the statistical accumulation of questionnaires and the implementation of the principle of merging statistics.

1. The realization of statistical summation of questionnaires first look at the following code:

Dboperate dboperate = new Dboperate ();//Instantiate a database action object to perform related database operations on the following data
/**////<summary>
Binding Questionnaire Data
</summary>
<param name= "Sid" > Incoming questionnaires id</param>
private void Binddata (string sid)
{
Query Questionnaire Information
String surveysql = "Select Survey_name,survey_sponsor,survey_outcount,survey_count,survey_titlecount,survey_ DateTime from Lj_survey Where id= "+ convert.toint32 (SID);"
DataTable SDT = dboperate. Getdatatable (Surveysql);
if (SDT). Rows.Count > 0)//If a questionnaire exists, do the following
{
Surveyname.text = SDT. Rows[0][0]. ToString ()//Get Questionnaire name
Sponsorlab.text = "Initiator:" + SDT. ROWS[0][1]. ToString ()//Get Initiator
String outcount = SDT. ROWS[0][2]. ToString ()///Get the number of distributions
String surveycount = SDT. ROWS[0][3]. ToString ()//Get statistics

if (Surveycount = = "0" && outcount!= "0")//If 0 are counted, N is issued
{
Reclaimlab.text = "Statistic rate:" + "0%";
}
else if (Surveycount = = "0" && Outcount = "0")//if there is no distribution and no statistics, that is 0
{
Reclaimlab.text = "Statistic rate:" + "0%";
}
else if (Surveycount!= "0" && Outcount = "0")//if not issued, but counted n
{
Reclaimlab.text = "Statistic rate:" + convert.toint32 (surveycount) + ". 0%";
}
Else
{//If n is sent, it also counts n copies.
Reclaimlab.text = "Statistic rate:" + String.Format ("{0:n2}", (Convert.todouble (Surveycount)/convert.todouble (OutCount) * 100)) + "%";
}

Outcountlab.text = "Issue questionnaire:" + Outcount + "part";
Incountlab.text = "Statistical questionnaire:" + Surveycount + "part";
Titlecountlab.text = "Common topic:" + SDT. ROWS[0][4]. ToString () + "DAO";//Get the number of topics
Sdatetlab.text = "Release time:" + convert.todatetime (SDT). ROWS[0][5]). Tolongdatestring ()//time to obtain payment

Query the topic information under this questionnaire
String titlesql = "Select Id,title_content,title_type from Lj_title Where title_sid=" + convert.toint32 (SID);
Titlesql + = "ORDER by title_order ASC";
DataTable TDT = dboperate. Getdatatable (Titlesql)//Get the topic data table
if (TDT. Rows.Count > 0)//If there is a problem with this questionnaire, do the following
{
DataTable rdt;//defines a datasheet that is used to store options for the corresponding topic
String resultsql = "";//SQL statement to hold the query's corresponding question option
String titype = "";//Topic type
int point = 0;//is used to set the position and height of the topic option
groupbox[] Tgroup = new GROUPBOX[TDT. rows.count];//defines an array of GroupBox controls that give you the option to store title headings and topics
for (int ti = 0; ti < TDT. Rows.Count; ti++)//Cycle each topic
{
Titype = TdT. ROWS[TI][2]. ToString ()//Get the type of the topic
Tgroup[ti] = new GroupBox (); Instantiate GroupBox, which holds the title of the topic and its corresponding options
Tgroup[ti]. AutoSize = true;
Tgroup[ti]. Font = new System.Drawing.Font ("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, (Byte) ( 134));
Tgroup[ti]. Width = svtitlefpanel.width-40;//Set the height of the topic
Tgroup[ti]. Cursor = cursors.hand;//Set cursor shape when mouse is put up
Tgroup[ti]. Text = (ti + 1). ToString () + "." + TDT. ROWS[TI][1]. ToString ()//Get the title of the topic
Query the contents of the option under this topic
Resultsql = "Select Id,result_content from Lj_result Where result_tid=" + Convert.ToInt32 (TDT. Rows[ti][0]. ToString ());
Rdt = Dboperate. Getdatatable (resultsql);//Get Option data table
if (Rdt. Rows.Count = = 0)////If no option exists, do the following
{
Label lb = new label ()//To Hold option contents
Lb. AutoSize = true;
Lb. Text = "no options";//SET options content
Lb. Location = new Point (10, 20);//Set the location of the option
Tgroup[ti]. Controls.Add (lb);//Add options to the corresponding topic
}
else//If there is an option, do the following
{
if (Titype = = "0")//Judgment topic type, 0 for single selection
{
radiobutton[] rdiobtn = new Radiobutton[rdt. rows.count];//defines a RadioButton array that holds all of the option contents
Point = 20;
for (int ri = 0; ri < Rdt. Rows.Count; ri++)//Cycle out all options under this topic
{
Rdiobtn[ri] = new RadioButton ()//instantiation of a RadioButton to hold a single option content
Rdiobtn[ri]. Location = new Point (points);//Set options where to store
Rdiobtn[ri]. Tag = Rdt. Rows[ri][0]. ToString ()//The option ID is set to the tag label of the option, which is used to distinguish between the options for statistics
Rdiobtn[ri]. Text = Rdt. ROWS[RI][1]. ToString ();//SET options display content
Rdiobtn[ri]. AutoSize = true;//Auto Set size
Point = point + 20;//height plus 20
}
Tgroup[ti]. Height = point;//Set the altitude of the topic
Tgroup[ti]. Tag = titype;//Sets the type of the topic to the tag tag of the GroupBox that holds the topic, which is used for statistical purposes.
Tgroup[ti]. Controls.AddRange (RDIOBTN)//Add all of these options to the topic
}
else//Multiple-select note similar to the above, no longer write more
{
checkbox[] Cbox = new Checkbox[rdt. Rows.Count];
Point = 20;
for (int ci = 0; ci < Rdt. Rows.Count; ci++)
{
CBOX[CI] = new CheckBox ();
CBOX[CI]. Location = new Point (point);
CBOX[CI]. Tag = Rdt. Rows[ci][0]. ToString ();
CBOX[CI]. Text = Rdt. ROWS[CI][1]. ToString ();
CBOX[CI]. AutoSize = true;
Point = Point + 20;
}
Tgroup[ti]. Height = point;
Tgroup[ti]. Tag = Titype;
Tgroup[ti]. Controls.AddRange (Cbox);
}
}
}

SvTitleFPanel.Controls.AddRange (Tgroup)//Add all the topics to the Svtitlefpanel and show them
}

}
Else
{//If no questionnaire exists, prompt
MessageBox.Show ("There is no this questionnaire, may have been deleted, please click on the [Refresh] button to refresh the list!") "," Operation Hint ", MessageBoxButtons.OK, MessageBoxIcon.Information);
This. Close ()//Closes the current window
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.