The main ASP.NET.4.5 MVC4.0 reborn: checkbox data storage

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Can be selected frame data storage



Controller

 1 public ActionResult SendInfo(SendInfo model, FormCollection fc, int[] GetSendInfo, int[] SetSendInfo)
 2         {
 3             int getsendinfoID = 0;
 4             int setsendinfoID = 0;
 5             foreach (int gsi in GetSendInfo)
 6             {
 7                 switch (gsi)
 8                 {
 9                     case 0: getsendinfoID = getsendinfoID + 1; break;
10                     case 1: getsendinfoID = getsendinfoID + 10; break;
11                     case 2: getsendinfoID = getsendinfoID + 100; break;
12                     case 3: getsendinfoID = getsendinfoID + 1000; break;
13                     case 4: getsendinfoID = getsendinfoID + 10000; break;
14                 }   
15             }
16 
17             foreach (int gsi in SetSendInfo)
18             {
19                 switch (gsi)
20                 {
21                     case 0: setsendinfoID = setsendinfoID + 1; break;
22                     case 1: setsendinfoID = setsendinfoID + 10; break;
23                     case 2: setsendinfoID = setsendinfoID + 100; break;
24                     case 3: setsendinfoID = setsendinfoID + 1000; break;
25                 }
26             }
27             model.SetSendInfo = setsendinfoID;
28             model.GetSendInfo = getsendinfoID;
29             model.State = 1;
30             model.CreateTime = DateTime.Now;
31             sendinforepository.SaveOrEditModel(model);
32             return RedirectToAction("ysqgk");
33         }

View

  1     <TABLE width=100% border="0" cellPadding=6 cellSpacing=1>
  2                                 <TBODY>
  3                                     <TR align=middle>
  4                                         <TD width="25%" height="30" class=maincol2_only_right
  5                                             style='border-top:none'>
  6                                             &nbsp;&nbsp;&nbsp;&nbsp;Whether the application for fee
  7                                         </TD>
  8                                         <TD class=maincol2_only_right noWrap width="33%">
  9                                             &nbsp;&nbsp;Specify and provide the required information (s)
 10                                             <SPAN class=star>*</SPAN>
 11                                         </TD>
 12                                         <TD class=maincol2_only_right2 width="33%">
 13                                             &nbsp;&nbsp;Method of obtaining information (s)
 14                                             <SPAN class=star>*</SPAN>
 15                                         </TD>
 16                                     </TR>
 17                                     <TR>
 18                                         <TD class=inputcol_only_right vAlign=top>
 19                                             <TABLE width="100%" cellPadding=3 cellSpacing=0 class=text-1>
 20                                                 <TBODY>
 21                                                     <TR>
 22                                                         <TD width=15>
 23                                                             <INPUT type=radio value="1" name="Expense"
 24                                                                 id="Expense">
 25                                                         </TD>
 26                                                         <TD class="left">
 27                                                             Apply. Please provide the relevant documentary proof
 28                                                         </TD>
 29                                                     </TR>
 30                                                     <TR>
 31                                                         <TD>
 32                                                             <INPUT type=radio CHECKED value="0" name="Expense"
 33                                                                 id="Radio2">
 34                                                         </TD>
 35                                                         <TD class="left">
 36                                                             No.
 37                                                         </TD>
 38                                                     </TR>                                                            
 39         
 40                                                 </TBODY>
 41                                             </TABLE>
 42                                         </TD>
 43                                         <TD class=inputcol_only_right vAlign=top>
 44                                             <TABLE class=text-1 cellSpacing=0 cellPadding=3 width="100%">
 45                                                 <TBODY>
 46                                                     <TR>
 47                                                         <TD width=15>
 48                                                         <input id="tgfs" name="tgfs" type="hidden" value="">
 49                                                             <INPUT  name="SetSendInfo" type="checkbox" value="0">
 50                                                         </TD>
 51                                                         <TD class="left">
 52                                                             The paper
 53                                                         </TD>
 54                                                     </TR>
 55                                                     <TR>
 56                                                         <TD>
 57                                                             <INPUT  name="SetSendInfo" type="checkbox" value="1">
 58                                                         </TD>
 59                                                         <TD class="left">
 60                                                             E-mail
 61                                                         </TD>
 62                                                     </TR>
 63                                                     <TR>
 64                                                         <TD>
 65                                                             <INPUT  name="SetSendInfo" type="checkbox" value="2">
 66                                                         </TD>
 67                                                         <TD class="left">
 68                                                             Optical disc
 69                                                         </TD>
 70                                                     </TR>
 71                                                     <TR>
 72                                                         <TD>
 73                                                             <INPUT  name="SetSendInfo" type="checkbox" value="3">
 74                                                         </TD>
 75                                                         <TD class="left">
 76                                                             Disk
 77                                                         </TD>
 78                                                     </TR>
 79                                                 </TBODY>
 80                                             </TABLE>
 81                                         </TD>
 82                                         <TD class=inputcol vAlign=top>
 83                                             <TABLE class=text-1 cellSpacing=0 cellPadding=3 width="100%">
 84                                                 <TBODY>
 85                                                     <TR>
 86                                                         <TD width=15>
 87                                                         
 88                                                             <INPUT type="checkbox" value="0" name="GetSendInfo">
 89                                                         </TD>
 90                                                         <TD class="left">
 91                                                             Mail
 92                                                         </TD>
 93                                                     </TR>
 94                                                     <TR>
 95                                                         <TD>
 96                                                             <INPUT type="checkbox" value="1" name="GetSendInfo">
 97                                                         </TD>
 98                                                         <TD class="left">
 99                                                             Express
100                                                         </TD>
101                                                     </TR>
102                                                     <TR>
103                                                         <TD>
104                                                             <INPUT type="checkbox" value="2" name="GetSendInfo">
105                                                         </TD>
106                                                         <TD class="left">
107                                                             E-mail
108                                                         </TD>
109                                                     </TR>
110                                                     <TR>
111                                                         <TD>
112                                                             <INPUT type="checkbox" value="3" name="GetSendInfo">
113                                                         </TD>
114                                                         <TD class="left">
115                                                             Fax
116                                                         </TD>
117                                                     </TR>
118                                                     <TR>
119                                                         <TD>
120                                                             <INPUT type="checkbox" value="4" name="GetSendInfo">
121                                                         </TD>
122                                                         <TD class="left">
123                                                             To receive / read on the spot, copy
124                                                         </TD>
125                                                     </TR>
126                                                 </TBODY>
127                                             </TABLE>
128                                         </TD>
129                                     </TR>
130                                 </TBODY>
131                             </TABLE>

StringHelper

 1   public static string Setsendinfo(int Num)
 2         {
 3             string number = "";
 4             switch (Num)
 5             {
 6                 case 0:
 7                     number = "The paper";
 8                     break;
 9                 case 1:
10                     number = "E-mail";
11                     break;
12                 case 2:
13                     number = "Optical disc";
14                     break;
15                 case 3:
16                     number = "Disk";
17                     break;
18             }
19             return number.ToString();
20         }
21 
22 
23         public static string Getsendinfo(int Num)
24         {
25             string number = "";
26             switch (Num)
27             {
28                 case 0:
29                     number = "Mail";
30                     break;
31                 case 1:
32                     number = "Express";
33                     break;
34                 case 2:
35                     number = "E-mail";
36                     break;
37                 case 3:
38                     number = "Fax";
39                     break;
40                 case 4:
41                     number = "To receive / read on the spot, copy";
42                     break;
43             }
44             return number.ToString();
45         }

Detail

 1  <p>
 2                     <b>Specify how to provide the needed information: </b>
 3                     <%var setsendinfo = Model.SetSendInfo.ToString().PadLeft(4, '0');
 4 
 5                       char[] inca = setsendinfo.ToCharArray();
 6                       string strtempa = "-";
 7                       string strtempb = "";
 8                       string setstrtemp = "";
 9 
10                       for (int sn = 0; sn <inca.Length; sn++)
11                       {
12                           if (inca[sn].ToString() == "1")
13                           {
14                               strtempa = Soft.Helpers.StringHelper.Setsendinfo(sn);
15                           }
16                           else
17                           {
18                               strtempa = "-";
19                           }
20                           setstrtemp = setstrtemp + "-" + strtempa;
21                       }
22                           
23                         
24                     %>
25                     <%= Html.Encode(setstrtemp) %>
26                 </p>
27 
28                 <p>
29                     <b>The way to get information: </b>
30                     <%var getsendinfo = Model.GetSendInfo.ToString().PadLeft(4, '0');
31 
32                       char[] incb = setsendinfo.ToCharArray();
33                       string strtempc = "-";
34                       string strtempd = "";
35                       string getstrtemp = "";
36                       for (int sn = 0; sn <incb.Length; sn++)
37                       {
38                           if (incb[sn].ToString() == "1")
39                           {
40                               strtempc = Soft.Helpers.StringHelper.Getsendinfo(sn);
41                           }
42                           else
43                           {
44                               strtempc = "-";
45                           }
46                           getstrtemp = getstrtemp + "-" + strtempc;
47                       }
48 
49                     %>
50                     <%= Html.Encode(getstrtemp) %>
51                 </p>


Assuming the tick

The format of the specified way to provide required information: 0101

The way to get information: 10101

S: Check: 1, do not check: 0


Database to store

View mode

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Fannie at November 16, 2013 - 11:35 PM