■◆我把这个问题放到这里,也希望有兴趣挑战的朋友看看◆■

YUDG 2005-03-11 09:21:47
这是我现在遇到而无法解决的问题,如有不懂.我继续给大家解释!
希望大家能给一个VB的解决方案,我用vb开发的.
此题解决和给出方案者,将给300分.如果本人分不够,重新开号放分.希望大家帮小弟一下.谢谢!
---------------------
虽然并不想这样做,可是实在没什么办法了.首先还是感谢大家.
---------------------
需求:
界面A,B.表tabA,tabC
表tabA与界面A连接.
界面A中一控件显示tabA中相应位置的内容.
点击界面A中"查看"按钮,将查看这个控件中的内容的全部信息,并在界面B中显示出来.
界面B中有添,删,修,存4个按钮

个人分析:
界面A中控件所显示的内容可能是tabA中隐藏列中的数据,但是经过转化,将转化后的数据显示在这个控件中.
例1:控件显示的内容是(1个鼻子+1个嘴+2个耳朵),那么tabA中隐藏位置上的数据是(1,2,3,3).1代表鼻子,2代表嘴,3代表耳朵.
但是控件中的内容中的数量并不是固定的(例2:1个鼻子+2个耳朵+2个眼睛+2个眉毛).那么tabA中隐藏位置上的数据就是(1,3,3,4,4,5,5),4代表眼睛,5代表眉毛.

界面B中显示的是这个控件中的内容的全部信息.并且界面B中,每条数据的控件的数量是一样,并且是随着界面A中控件中内容而改变的(如果是例2,那么在界面B中显示的控件组将为4行).
如例1时,将在界面B中的控件里显示:
[鼻子],[中],[重要],[损伤],[1]
[嘴] ,[下],[重要],[完好],[1]
[耳朵],[中],[重要],[修补],[2]

那么例2中显示的也差不多是这样.只不过又多了"眉毛"的描述.
----------------------
另外,在B中对内容进行操作时,界面A控件的内容也一定能做相应的修改.
例如:将例1中的鼻子删除掉,那么界面A控件中的内容应该是(1个嘴+1个耳朵)
----------------------
表tabC中存储的是这些数据(例如鼻子,嘴,眉毛等等),有其编号(编号唯一),并且各条记录没有重复.在界面B中只是显示了这些数据.并不是界面A中的控件每条信息都有一条数据.而是直接调用tabC中的数据.
例3,表tabC中的内容是
编号 名称 位置 状态 程度
1 鼻子 中 损伤 重要
2 嘴 下 完好 重要
3 耳朵 中 修补 重要
4 眼睛 上 完好 重要
5 眉毛 上 损伤 重要
........
N
(以上表只是例子)

请各位看看,给个解决方案和方法.
如能解答,必将重谢!
我的QQ号码是:30669235,如有兴趣,请联系(验证:csdn)
再次感谢!
...全文
123 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hamadou 2005-03-13
  • 打赏
  • 举报
回复
说明:
可能有些细节没有完全明白你的意思,不过我想大概的思路就应该是这样的。至于你说的在form2中,对tablec进行修改,新增或者删除,如果是删除,则可以直接使用sql语句进行删除tablea的内容,修改也是如此,因为tablea中相应的id已经传递过来了。如果是新增的话,我想,同样可以达到这个目的的。这些语句都很容易的。至于返回form1时,数据要刷新的问题 ,重新执行存储过程(把数据重新填充一下就ok了!)


呵呵,以前说过有时间来试试的,今天总算写点什么了。希望能对你有些帮助。
hqmmf 2005-03-13
  • 打赏
  • 举报
回复
up!
hamadou 2005-03-13
  • 打赏
  • 举报
回复
5.在form2中的实现(显示tablec内容)
Imports System.Data.SqlClient
Private m_id As Integer
Private m_sqlcon As SqlConnection
Public Property get_id() As Integer
Get
Return m_id
End Get
Set(ByVal Value As Integer)
m_id = Value
End Set
End Property

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
m_sqlcon = New SqlConnection("server=localhost;uid=sa;pwd=;database=jiang")
Dim str As String = "select distinct tablec.name ,tablec.pos,tablec.type,tablec.degree " & _
" from tablec, tablea where tablec.cid = tablea.cid and tablea.c=@id "
Dim cmd As New SqlCommand(str, m_sqlcon)
cmd.Parameters.Add("@id", SqlDbType.Int).Value = m_id
Dim sqldpr As New SqlDataAdapter(cmd)
Dim ds1 As New DataSet()
Try
m_sqlcon.Open()
sqldpr.Fill(ds1, "result")
Me.DataGrid1.DataSource = ds1.Tables(0)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
m_sqlcon.Close()
End Try

End Sub
hamadou 2005-03-13
  • 打赏
  • 举报
回复
4。在form1中的实现。
Imports System.Data.SqlClient
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cmd As New SqlCommand()
cmd.Connection = SqlCon
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "returntable"
Dim sqldpr As New SqlDataAdapter(cmd)
Dim ds1 As New DataSet()
Try
SqlCon.Open()
sqldpr.Fill(ds1, "test")
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
SqlCon.Close()
End Try


Me.DataGrid1.DataSource = ds1.Tables("test")
Dim style As New DataGridTableStyle()
Dim c1 As New DataGridTextBoxColumn()
Dim c2 As New DataGridTextBoxColumn()

style.MappingName = "test"
c1.HeaderText = "统一编号"
c2.HeaderText = "描述"

c1.Width = 65
c2.Width = 200
c1.MappingName = "id"
c2.MappingName = "descrip"

c1.ReadOnly = True
c2.ReadOnly = True
style.GridColumnStyles.Add(c1)
style.GridColumnStyles.Add(c2)

Me.DataGrid1.TableStyles.Add(style)
ds1.Tables("test").DefaultView.AllowNew = False

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim index As Integer = Me.DataGrid1.CurrentRowIndex
Dim id As Integer = Me.DataGrid1.Item(index, 0)
Dim newform As New Form2()
newform.get_id = id
newform.show()
End Sub
hamadou 2005-03-13
  • 打赏
  • 举报
回复
1。表结构:
tablea(id,cid,c)这里id是自增编号,cid对应tablec中的主键cid,c是代表分组的依据(我想应该有这个依据吧,或者它是个日期什么的,反正应该有这么一个分组条件的。)
tablec(cid,name,position,type,degree)这个意思就比较明显了。我们可以给tablec上建立触发器,关联tablec和tablea.
2。假定表内容tablea
id cid c
1 1 1
2 2 1
3 1 1
4 1 2
5 3 2
6 2 2
7 4 2
表tablec内容:
cid pos name type degree
1 中 鼻子 1 [重]
2 前 耳朵 2 [轻微]
3 左 眼睛 1 [中]
4 右 眉毛 1 [重]

3.建立存储过程,来从tablea中获得相关的描述信息。效果就是类似“1个鼻子,1个嘴,2个耳”

CREATE PROCEDURE returntable
AS
create table #linshi(id int not null primary key , descrip varchar(50) )
declare @id int ,@des varchar(50),@count int
declare @temp int
declare @text varchar(50)
set @temp =0
set @text =""
declare my_cusor cursor for select tablea.c ,tablec.name ,count(*) as sum from tablea,tablec where tablea.cid = tablec.cid group by tablea.c ,tablec.name order by tablea.c
open my_cusor
fetch next from my_cusor
into @id, @des,@count
while @@FETCH_STATUS = 0
begin
if @temp=0 or @temp = @id
begin
set @temp = @id
set @text =@text + convert(varchar,@count) + "个" + @des + ","
end
else
begin
if @temp <>@id
begin
set @text = left(@text,len(@text)-1)
--将组合好的记录插入临时表
insert #linshi values(@temp,@text)
set @temp=@id
set @text = convert(varchar, @count) + "个" + @des + ","
end
end
fetch next from my_cusor
into @id, @des,@count
end
set @text=left(@text,len(@text)-1)
insert #linshi values(@temp,@text) --将生成的最后一行插入
close my_cusor
deallocate my_cusor

select id,descrip from #linshi
GO

捏造的信仰 2005-03-12
  • 打赏
  • 举报
回复
觉得楼主的解决方式有某种原则上的问题,太乱了。
能不能不要一下子搞这么复杂的东西?可能问题本来不复杂硬是让楼主搞复杂了。
YUDG 2005-03-11
  • 打赏
  • 举报
回复
呵呵,希望您都看懂了.不懂得地方问我喔~~
hamadou 2005-03-11
  • 打赏
  • 举报
回复
好象不难啊!呵呵!有时间弄弄!
leisang 2005-03-11
  • 打赏
  • 举报
回复
寒~~
看了好几遍,没看懂楼主要表达的意思....

16,722

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧