質問編集履歴

1

追記しました

2018/09/16 05:12

投稿

sakuya
sakuya

スコア10

test CHANGED
File without changes
test CHANGED
@@ -22,8 +22,478 @@
22
22
 
23
23
 
24
24
 
25
- ![イメージ説明](abd77dcf714792ff7790631ab1b2f999.jpeg)
26
-
27
-
28
-
29
25
  まだ、実現可能か調査を行っている段階のため、ソースを記載できませんがよろしくお願いいたします。
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+ 追記させて頂きます。
36
+
37
+ SurferOnWwwさんのヒントから下記のコードを作成いたしました。
38
+
39
+
40
+
41
+ ```aspx
42
+
43
+ <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Create_Calendar.aspx.vb" Inherits="SimplyCheckTool.Create_Calendar" %>
44
+
45
+
46
+
47
+ <!DOCTYPE html>
48
+
49
+
50
+
51
+ <html xmlns="http://www.w3.org/1999/xhtml">
52
+
53
+ <head runat="server">
54
+
55
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
56
+
57
+ <title></title>
58
+
59
+ </head>
60
+
61
+ <body>
62
+
63
+ <form id="form1" runat="server">
64
+
65
+ <div>
66
+
67
+ <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
68
+
69
+ <asp:ListItem Value="1">1月</asp:ListItem>
70
+
71
+ <asp:ListItem Value="2">2月</asp:ListItem>
72
+
73
+ <asp:ListItem Value="3">3月</asp:ListItem>
74
+
75
+ <asp:ListItem Value="4">4月</asp:ListItem>
76
+
77
+ <asp:ListItem Value="5">5月</asp:ListItem>
78
+
79
+ <asp:ListItem Value="6">6月</asp:ListItem>
80
+
81
+ <asp:ListItem Value="7">7月</asp:ListItem>
82
+
83
+ <asp:ListItem Value="8">8月</asp:ListItem>
84
+
85
+ <asp:ListItem Value="9">9月</asp:ListItem>
86
+
87
+ <asp:ListItem Value="10">10月</asp:ListItem>
88
+
89
+ <asp:ListItem Value="11">11月</asp:ListItem>
90
+
91
+ <asp:ListItem Value="12">12月</asp:ListItem>
92
+
93
+ </asp:DropDownList>
94
+
95
+ <asp:DropDownList ID="DropDownList2" runat="server">
96
+
97
+ </asp:DropDownList>
98
+
99
+ <asp:Button ID="btn_planstop" runat="server" Text="PLANSTOP" />
100
+
101
+ <asp:Button ID="btn_pdf" runat="server" Link="\SimplyCheckTool\Account\CheckSheetDownLoadStart.ashx.vb" Text="PDF" />
102
+
103
+ </div>
104
+
105
+ <asp:GridView ID="GridView1" runat="server">
106
+
107
+ </asp:GridView>
108
+
109
+ </form>
110
+
111
+ </body>
112
+
113
+ </html>
114
+
115
+ ```
116
+
117
+ ```vb
118
+
119
+ '------------------------------------------------------------------'
120
+
121
+ '- ページ起動時処理 -'
122
+
123
+ '------------------------------------------------------------------'
124
+
125
+ Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
126
+
127
+ If Not IsPostBack Then
128
+
129
+ Dim dtNow As DateTime = Now
130
+
131
+ Dim iMonth As Integer = dtNow.Month
132
+
133
+ DropDownList1.SelectedIndex = iMonth - 1
134
+
135
+ End If
136
+
137
+
138
+
139
+ GridView1.DataSource = GetDataTable()
140
+
141
+ GridView1.DataBind()
142
+
143
+
144
+
145
+ '不要なヘッダーを非表示にする
146
+
147
+ For i = 1 To 93 - 31
148
+
149
+ GridView1.HeaderRow.Cells(i + 31).Visible = False
150
+
151
+ Next
152
+
153
+
154
+
155
+ End Sub
156
+
157
+ Public Function GetDataTable() As DataTable
158
+
159
+
160
+
161
+ Dim intMonth As Integer = DropDownList1.SelectedValue '選択した月
162
+
163
+ Dim intYear As Integer = dtToday.Year '今年の西暦
164
+
165
+ Dim stDay As String = intYear & "/" & intMonth & "/1" '対象年月の初日
166
+
167
+ Dim dtDay As Date = Date.Parse(stDay)
168
+
169
+ Dim dtTomm As Date
170
+
171
+ Dim intWeek As DayOfWeek = dtDay.DayOfWeek
172
+
173
+ Dim wktaskname As String = Nothing
174
+
175
+
176
+
177
+ Dtbl = SQLDS.Tables.Add("OutTbl")
178
+
179
+ Dim Col(94) As DataColumn
180
+
181
+ Col(0) = New DataColumn("task_name", Type.GetType("System.String")) '
182
+
183
+ Col(1) = New DataColumn("CB1", Type.GetType("System.Boolean")) '
184
+
185
+ Col(2) = New DataColumn("ST1", Type.GetType("System.String")) '
186
+
187
+ Col(3) = New DataColumn("ID1", Type.GetType("System.String")) '
188
+
189
+ '上記CB1・ST1・ID1を31日分作成しています。
190
+
191
+
192
+
193
+
194
+
195
+ For x = 1 To 93
196
+
197
+ Col(x).DefaultValue = True
198
+
199
+ x = x + 2
200
+
201
+ Next
202
+
203
+
204
+
205
+ Dtbl.Columns.AddRange(Col)
206
+
207
+
208
+
209
+ intWeek = dtDay.DayOfWeek
210
+
211
+ dtTomm = dtDay.AddMonths(1)
212
+
213
+
214
+
215
+ Dim isTable As Boolean = False
216
+
217
+ isTable = False
218
+
219
+ For i As Integer = 0 To SQLDS.Tables.Count - 1
220
+
221
+ If SQLDS.Tables(i).TableName = "tenken_H_tbl" Then
222
+
223
+ isTable = True
224
+
225
+ Exit For
226
+
227
+ End If
228
+
229
+ Next
230
+
231
+ If isTable Then
232
+
233
+ SQLDS.Tables("tenken_H_tbl").Clear()
234
+
235
+ End If
236
+
237
+ 'Dim cmd As SqlCommand
238
+
239
+ Dim str As String = ""
240
+
241
+ Dim dtO As DataTable = New DataTable
242
+
243
+ Dim Wide As ssWide = New ssWide()
244
+
245
+
246
+
247
+ str = String.Empty
248
+
249
+ str += String.Format("SELECT * ") + vbCrLf
250
+
251
+ str += String.Format("FROM View_tenken_H_file ") + vbCrLf
252
+
253
+ dtO = Wide.table_Read(str)
254
+
255
+
256
+
257
+ Dtbl.Clear()
258
+
259
+
260
+
261
+ '取得したデータから「装置名&点検名」「ステータス」を取得し設定
262
+
263
+ 'For Each HeaderRow In SQLDS.Tables("tenken_H_tbl").Rows
264
+
265
+ For Each HeaderRow In dtO.Rows
266
+
267
+ Dim dDay As DateTime = HeaderRow("実施開始日")
268
+
269
+ Dim iDay As Integer = dDay.Day
270
+
271
+ Select Case iDay
272
+
273
+ Case 2
274
+
275
+ iDay = 4
276
+
277
+ Case 3
278
+
279
+ iDay = 7
280
+
281
+ End Select
282
+
283
+ intWeek = HeaderRow("実施開始日").DayOfWeek
284
+
285
+ If HeaderRow("点検名") = wktaskname Then
286
+
287
+ DtblRow("task_name") = HeaderRow("装置名") & "_" & HeaderRow("点検名")
288
+
289
+ 'DtblRow(iDay) = HeaderRow("ステータス名")
290
+
291
+ DtblRow(iDay) = False
292
+
293
+ DtblRow(iDay + 1) = HeaderRow("ステータス名")
294
+
295
+ DtblRow(iDay + 2) = HeaderRow("点検ファイルNo")
296
+
297
+ Else
298
+
299
+ If wktaskname <> Nothing Then
300
+
301
+ Dtbl.Rows.Add(DtblRow)
302
+
303
+ End If
304
+
305
+ DtblRow = Dtbl.NewRow()
306
+
307
+ DtblRow("task_name") = HeaderRow("装置名") & "_" & HeaderRow("点検名")
308
+
309
+ 'DtblRow(iDay) = HeaderRow("ステータス名")
310
+
311
+ DtblRow(iDay) = False
312
+
313
+ DtblRow(iDay + 1) = HeaderRow("ステータス名")
314
+
315
+ DtblRow(iDay + 2) = HeaderRow("点検ファイルNo")
316
+
317
+ wktaskname = HeaderRow("点検名")
318
+
319
+ End If
320
+
321
+ Next
322
+
323
+ Dtbl.Rows.Add(DtblRow)
324
+
325
+
326
+
327
+ Dtbl.Columns(0).ColumnName = "点検名"
328
+
329
+
330
+
331
+ Dim stWeek(31) As String
332
+
333
+ Dim lastDay As Integer
334
+
335
+ Select Case intMonth
336
+
337
+ Case 1, 3, 5, 7, 8, 10, 12
338
+
339
+ lastDay = 31
340
+
341
+ Case 2
342
+
343
+ lastDay = 28
344
+
345
+ Case 2, 4, 6, 9, 11
346
+
347
+ lastDay = 30
348
+
349
+ End Select
350
+
351
+
352
+
353
+ Session("Dtbl") = Dtbl
354
+
355
+ Return Dtbl
356
+
357
+ End Function
358
+
359
+ '------------------------------------------------------------------'
360
+
361
+ '- カレンダー調整処理 -'
362
+
363
+ '------------------------------------------------------------------'
364
+
365
+ Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowDataBound
366
+
367
+ Dim span_length As Integer = 0
368
+
369
+ Dim cnt_loop As Integer = 31 * 3 '合計カラム数 = 31日分 × 1日3項目
370
+
371
+ Dim delete As Integer = 0
372
+
373
+ Dim stStatus As String
374
+
375
+ Dim stStatus2 As String
376
+
377
+
378
+
379
+ Dim tstStr As String
380
+
381
+ Dim result As Boolean
382
+
383
+
384
+
385
+ For idx = 1 To cnt_loop
386
+
387
+
388
+
389
+ If e.Row.RowIndex < 0 Then Return
390
+
391
+ Dim check As CheckBox = CType(e.Row.Cells(idx).Controls(0), CheckBox)
392
+
393
+ check.Enabled = True
394
+
395
+ stStatus = e.Row.Cells(idx).Text
396
+
397
+ stStatus2 = e.Row.Cells(idx + 1).Text
398
+
399
+ 'Dim c As Boolean = check.Checked.Equals(e.Row.Cells(idx))
400
+
401
+ 'ステータス名と検査ステータスNoのセルを非表示
402
+
403
+ e.Row.Cells(idx + 1).Visible = False
404
+
405
+ e.Row.Cells(idx + 2).Visible = False
406
+
407
+ 'セルを非表示にしてもセルの合計数が減るわけではないので、確認セルを2セル分とばす
408
+
409
+ idx = idx + 2
410
+
411
+
412
+
413
+ '残りのカラム数が次に確認するセル番号より少ない場合は処理を抜ける
414
+
415
+ If cnt_loop < idx + 3 Then
416
+
417
+ GoTo Finish
418
+
419
+ End If
420
+
421
+
422
+
423
+ Next
424
+
425
+ Finish:
426
+
427
+
428
+
429
+ For x = 1 To e.Row.Cells.Count - 2
430
+
431
+ 'e.Row.Cells(x) = True
432
+
433
+ 'x = x + 2
434
+
435
+ Next
436
+
437
+
438
+
439
+ End Sub
440
+
441
+
442
+
443
+ Protected Sub PlanStop(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles btn_planstop.Click
444
+
445
+ For idx = 1 To GridView1.Columns.Count
446
+
447
+ Dim check As CheckBox = CType(e.Row.Cells(idx).Controls(0), CheckBox)
448
+
449
+
450
+
451
+ If e.Row.Cells(idx).Text = True Then
452
+
453
+ e.Row.Cells(idx).BackColor = Drawing.Color.Gray
454
+
455
+ Else
456
+
457
+ e.Row.Cells(idx).BackColor = Drawing.Color.Empty
458
+
459
+ End If
460
+
461
+
462
+
463
+ idx = idx + 2
464
+
465
+ Next
466
+
467
+
468
+
469
+ End Sub
470
+
471
+ End Class
472
+
473
+ ```
474
+
475
+ 教えて頂いた、データーソースコントロールを利用して SQL Server からのデータ取得が難しかったため、無理やりチェックボックスを表示しているような状態です。
476
+
477
+ データテーブルにチェックボックス用のフィールド・チェックが付いている時に取得したいデータフィールド・GridViewに色付けするためのデータフィールドをそれぞれ31日分作成し、GridViewにバインドした後チェックボックス以外のフィールドは非表示にしています。
478
+
479
+ かなり無理やりなソースですので、いずれはさらに勉強して綺麗なソースに直したいとは考えています。
480
+
481
+ 今の私の能力ではこれが精一杯でした。
482
+
483
+ ただ、上記のソースで、各セルにチェックボックスを表示させることはできました。
484
+
485
+
486
+
487
+ 上記ソースで、どのチェックボックスにチェックが入っているかを取得することは可能なのでしょうか?
488
+
489
+ 正確に言うと、チェックボックスにチェックが入っているセルの右のセルの値が取得できるかがわかりません。
490
+
491
+
492
+
493
+ 全く分からないまま自分なりに出来る方法で見た目だけはなんとか作成しましたが、チェックボックスの位置を取得する所でかなり困っています。
494
+
495
+ 何とかヒントだけでも教えて頂けるとありがたいです。
496
+
497
+
498
+
499
+ よろしくお願いいたします。