Foxtable(狐表)用户栏目专家坐堂 → [求助]重复删除代码


  共有2729人关注过本帖树形打印复制链接

主题:[求助]重复删除代码

帅哥哟,离线,有人找我吗?
荟美绘姿
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:238 积分:1838 威望:0 精华:0 注册:2014/7/1 8:56:00
[求助]重复删除代码  发帖心情 Post By:2014/7/23 8:39:00 [只看该作者]

我要在下面的代码中再加上一个对另外一个表进行重复删除的代码,请指教该如何写,写在哪里?

 

谢谢!

 

If e.Form.Controls("TextBox1").Text = "" Then
    MessageBox.Show("编号不能为空")
    Return
End If

If e.Form.Controls("TextBox2").Text = "" Then
    MessageBox.Show("当事人名称不能为空")
    Return
End If

If e.Form.Controls("TextBox4").Text = "" Then
    MessageBox.Show("地址不能为空")
    Return
End If

If e.Form.Controls("TextBox5").Text = "" Then
    MessageBox.Show("联系电话不能为空")
    Return
End If

If e.Form.Controls("TextBox6").Text = "" Then
    MessageBox.Show("邮政编码不能为空")
    Return
End If

If e.Form.Controls("TextBox3").Text = "" Then
    MessageBox.Show("车牌号码不能为空")
    Return
End If

If e.Form.Controls("ComboBox1").Text = "" Then
    MessageBox.Show("车牌颜色不能为空")
    Return
End If

If e.Form.Controls("ComboBox2").Text = "" Then
    MessageBox.Show("案发地点不能为空")
    Return
End If

If e.Form.Controls("DateTimePicker1").Text = "" Then
    MessageBox.Show("案发时间不能为空")
    Return
End If

If e.Form.Controls("ComboBox3").Text = "" Then
    MessageBox.Show("违法行为不能为空")
    Return
End If

If e.Form.Controls("ComboBox4").Text = "" Then
    MessageBox.Show("案件状态不能为空")
    Return
End If

Tables("车辆违章表").current("编号")=e.Form.Controls("TextBox1").text
Tables("车辆违章表").current("单位基本情况_单位名称")=e.Form.Controls("TextBox2").text
Tables("车辆违章表").current("单位基本情况_地址")=e.Form.Controls("TextBox4").text
Tables("车辆违章表").current("单位基本情况_联系电话")=e.Form.Controls("TextBox5").text
Tables("车辆违章表").current("单位基本情况_邮政编码")=e.Form.Controls("TextBox6").text
Tables("车辆违章表").current("车辆基本情况_车牌号码")=e.Form.Controls("TextBox3").text
Tables("车辆违章表").current("车辆基本情况_车牌颜色")=e.Form.Controls("ComboBox1").text
Tables("车辆违章表").current("违章基本情况_违章地点")=e.Form.Controls("ComboBox2").text
Tables("车辆违章表").current("违章基本情况_违章时间")=e.Form.Controls("DateTimePicker1").text
Tables("车辆违章表").current("违章基本情况_违章行为")=e.Form.Controls("ComboBox3").text
Tables("车辆违章表").current("案件状态")=e.Form.Controls("ComboBox4").text
Tables("车辆违章表").Current.Save()
Tables("车辆违章表").Current.Locked = True

Tables("单位表").AddNew()
Tables("车辆表").AddNew()
Tables("单位表").current("单位名称")=e.Form.Controls("TextBox2").text
Tables("车辆表").current("单位名称")=e.Form.Controls("TextBox2").text
Tables("单位表").current("地址")=e.Form.Controls("TextBox4").text
Tables("单位表").current("联系电话")=e.Form.Controls("TextBox5").text
Tables("单位表").current("邮政编码")=e.Form.Controls("TextBox6").text
Tables("车辆表").current("车牌号码")=e.Form.Controls("TextBox3").text
Tables("车辆表").current("车牌颜色")=e.Form.Controls("ComboBox1").text
Dim i As Integer
For i  = DataTables("车辆表").DataRows.Count-1 To 0 Step -1
    Dim dr As DataRow = DataTables("车辆表").DataRows(i)
    Dim dr2 As DataRow = DataTables("车辆表").Find("车牌号码='" & dr("车牌号码") & "' and 车牌颜色='" & dr("车牌颜色") & "' and _Identify <> " & dr("_Identify"))
    If dr2 IsNot Nothing Then
        dr2.Delete
    End If
Next
Tables("车辆表").Current.Save()
Tables("车辆表").Current.Locked = True
Tables("单位表").Current.Save()
Tables("单位表").Current.Locked = True


 回到顶部
帅哥哟,离线,有人找我吗?
荟美绘姿
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:238 积分:1838 威望:0 精华:0 注册:2014/7/1 8:56:00
  发帖心情 Post By:2014/7/23 8:46:00 [只看该作者]

我顶一下下,快快帮我一下,谢谢


 回到顶部
帅哥哟,离线,有人找我吗?
Bin
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:35433 积分:178524 威望:0 精华:3 注册:2013/3/30 16:36:00
  发帖心情 Post By:2014/7/23 8:52:00 [只看该作者]

For i  as integer = DataTables("车辆表").DataRows.Count-1 To 0 Step -1
    Dim dr As DataRow = DataTables("车辆表").DataRows(i)
    Dim dr2 As DataRow = DataTables("车辆表").Find("车牌号码='" & dr("车牌号码") & "' and 车牌颜色='" & dr("车牌颜色") & "' and _Identify <> " & dr("_Identify"))
    If dr2 IsNot Nothing Then
        dr2.Delete
    End If
Next

 回到顶部
帅哥哟,离线,有人找我吗?
荟美绘姿
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:238 积分:1838 威望:0 精华:0 注册:2014/7/1 8:56:00
  发帖心情 Post By:2014/7/23 8:56:00 [只看该作者]

请你帮我写完整一点,谢谢


 回到顶部
帅哥哟,离线,有人找我吗?
Bin
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:35433 积分:178524 威望:0 精华:3 注册:2013/3/30 16:36:00
  发帖心情 Post By:2014/7/23 8:59:00 [只看该作者]

就是完整的代码了啊  把你原来的替换成这个即可

你的处理方式没问题.

 回到顶部
帅哥哟,离线,有人找我吗?
荟美绘姿
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:238 积分:1838 威望:0 精华:0 注册:2014/7/1 8:56:00
  发帖心情 Post By:2014/7/23 9:01:00 [只看该作者]

If e.Form.Controls("TextBox1").Text = "" Then
    MessageBox.Show("编号不能为空")
    Return
End If

If e.Form.Controls("TextBox2").Text = "" Then
    MessageBox.Show("当事人名称不能为空")
    Return
End If

If e.Form.Controls("TextBox4").Text = "" Then
    MessageBox.Show("地址不能为空")
    Return
End If

If e.Form.Controls("TextBox5").Text = "" Then
    MessageBox.Show("联系电话不能为空")
    Return
End If

If e.Form.Controls("TextBox6").Text = "" Then
    MessageBox.Show("邮政编码不能为空")
    Return
End If

If e.Form.Controls("TextBox3").Text = "" Then
    MessageBox.Show("车牌号码不能为空")
    Return
End If

If e.Form.Controls("ComboBox1").Text = "" Then
    MessageBox.Show("车牌颜色不能为空")
    Return
End If

If e.Form.Controls("ComboBox2").Text = "" Then
    MessageBox.Show("案发地点不能为空")
    Return
End If

If e.Form.Controls("DateTimePicker1").Text = "" Then
    MessageBox.Show("案发时间不能为空")
    Return
End If

If e.Form.Controls("ComboBox3").Text = "" Then
    MessageBox.Show("违法行为不能为空")
    Return
End If

If e.Form.Controls("ComboBox4").Text = "" Then
    MessageBox.Show("案件状态不能为空")
    Return
End If

Tables("车辆违章表").current("编号")=e.Form.Controls("TextBox1").text
Tables("车辆违章表").current("单位基本情况_单位名称")=e.Form.Controls("TextBox2").text
Tables("车辆违章表").current("单位基本情况_地址")=e.Form.Controls("TextBox4").text
Tables("车辆违章表").current("单位基本情况_联系电话")=e.Form.Controls("TextBox5").text
Tables("车辆违章表").current("单位基本情况_邮政编码")=e.Form.Controls("TextBox6").text
Tables("车辆违章表").current("车辆基本情况_车牌号码")=e.Form.Controls("TextBox3").text
Tables("车辆违章表").current("车辆基本情况_车牌颜色")=e.Form.Controls("ComboBox1").text
Tables("车辆违章表").current("违章基本情况_违章地点")=e.Form.Controls("ComboBox2").text
Tables("车辆违章表").current("违章基本情况_违章时间")=e.Form.Controls("DateTimePicker1").text
Tables("车辆违章表").current("违章基本情况_违章行为")=e.Form.Controls("ComboBox3").text
Tables("车辆违章表").current("案件状态")=e.Form.Controls("ComboBox4").text
Tables("车辆违章表").Current.Save()
Tables("车辆违章表").Current.Locked = True

Tables("单位表").AddNew()
Tables("车辆表").AddNew()
Tables("单位表").current("单位名称")=e.Form.Controls("TextBox2").text
Tables("车辆表").current("单位名称")=e.Form.Controls("TextBox2").text
Tables("单位表").current("地址")=e.Form.Controls("TextBox4").text
Tables("单位表").current("联系电话")=e.Form.Controls("TextBox5").text
Tables("单位表").current("邮政编码")=e.Form.Controls("TextBox6").text
Tables("车辆表").current("车牌号码")=e.Form.Controls("TextBox3").text
Tables("车辆表").current("车牌颜色")=e.Form.Controls("ComboBox1").text
Dim i As Integer
For i  = DataTables("车辆表").DataRows.Count-1 To 0 Step -1
    Dim dr As DataRow = DataTables("车辆表").DataRows(i)
    Dim dr2 As DataRow = DataTables("车辆表").Find("车牌号码='" & dr("车牌号码") & "' and 车牌颜色='" & dr("车牌颜色") & "' and _Identify <> " & dr("_Identify"))
    If dr2 IsNot Nothing Then
        dr2.Delete
    End If
Next
For i  = DataTables("单位表").DataRows.Count-1 To 0 Step -1
    Dim dr As DataRow = DataTables("单位表").DataRows(i)
    Dim dr2 As DataRow = DataTables("单位表").Find("单位名称='" & dr("单位名称") & "' and 地址='" & dr("地址") & "' and _Identify <> " & dr("_Identify"))
    If dr2 IsNot Nothing Then
        dr2.Delete
    End If
Next
Tables("车辆表").Current.Save()
Tables("车辆表").Current.Locked = True
Tables("单位表").Current.Save()

 

 

帮我看一下下,


Tables("单位表").Current.Locked = True


 回到顶部
帅哥哟,离线,有人找我吗?
Bin
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:35433 积分:178524 威望:0 精华:3 注册:2013/3/30 16:36:00
  发帖心情 Post By:2014/7/23 9:06:00 [只看该作者]

什么意思?不明白.请描述清楚,并且上例子.

 回到顶部
帅哥哟,离线,有人找我吗?
荟美绘姿
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:238 积分:1838 威望:0 精华:0 注册:2014/7/1 8:56:00
  发帖心情 Post By:2014/7/23 10:00:00 [只看该作者]

我这段代码是写在一个登记窗口的保存控件里的

当按下保存按钮时将相应的数据保存到"车辆违章表"、“单位表”和“车辆表”中,并保存了“车辆违章表”,接着对“单位表”和“车辆表”中的重复数据分别进行删除,最后保存锁定“单位表”和“车辆表”。

 

If e.Form.Controls("TextBox1").Text = "" Then
    MessageBox.Show("编号不能为空")
    Return
End If

If e.Form.Controls("TextBox2").Text = "" Then
    MessageBox.Show("当事人名称不能为空")
    Return
End If

If e.Form.Controls("TextBox4").Text = "" Then
    MessageBox.Show("地址不能为空")
    Return
End If

If e.Form.Controls("TextBox5").Text = "" Then
    MessageBox.Show("联系电话不能为空")
    Return
End If

If e.Form.Controls("TextBox6").Text = "" Then
    MessageBox.Show("邮政编码不能为空")
    Return
End If

If e.Form.Controls("TextBox3").Text = "" Then
    MessageBox.Show("车牌号码不能为空")
    Return
End If

If e.Form.Controls("ComboBox1").Text = "" Then
    MessageBox.Show("车牌颜色不能为空")
    Return
End If

If e.Form.Controls("ComboBox2").Text = "" Then
    MessageBox.Show("案发地点不能为空")
    Return
End If

If e.Form.Controls("DateTimePicker1").Text = "" Then
    MessageBox.Show("案发时间不能为空")
    Return
End If

If e.Form.Controls("ComboBox3").Text = "" Then
    MessageBox.Show("违法行为不能为空")
    Return
End If

If e.Form.Controls("ComboBox4").Text = "" Then
    MessageBox.Show("案件状态不能为空")
    Return
End If

Tables("车辆违章表").current("编号")=e.Form.Controls("TextBox1").text
Tables("车辆违章表").current("单位基本情况_单位名称")=e.Form.Controls("TextBox2").text
Tables("车辆违章表").current("单位基本情况_地址")=e.Form.Controls("TextBox4").text
Tables("车辆违章表").current("单位基本情况_联系电话")=e.Form.Controls("TextBox5").text
Tables("车辆违章表").current("单位基本情况_邮政编码")=e.Form.Controls("TextBox6").text
Tables("车辆违章表").current("车辆基本情况_车牌号码")=e.Form.Controls("TextBox3").text
Tables("车辆违章表").current("车辆基本情况_车牌颜色")=e.Form.Controls("ComboBox1").text
Tables("车辆违章表").current("违章基本情况_违章地点")=e.Form.Controls("ComboBox2").text
Tables("车辆违章表").current("违章基本情况_违章时间")=e.Form.Controls("DateTimePicker1").text
Tables("车辆违章表").current("违章基本情况_违章行为")=e.Form.Controls("ComboBox3").text
Tables("车辆违章表").current("案件状态")=e.Form.Controls("ComboBox4").text
Tables("车辆违章表").Current.Save()
Tables("车辆违章表").Current.Locked = True

Tables("单位表").AddNew()
Tables("车辆表").AddNew()
Tables("单位表").current("单位名称")=e.Form.Controls("TextBox2").text
Tables("车辆表").current("单位名称")=e.Form.Controls("TextBox2").text
Tables("单位表").current("地址")=e.Form.Controls("TextBox4").text
Tables("单位表").current("联系电话")=e.Form.Controls("TextBox5").text
Tables("单位表").current("邮政编码")=e.Form.Controls("TextBox6").text
Tables("车辆表").current("车牌号码")=e.Form.Controls("TextBox3").text
Tables("车辆表").current("车牌颜色")=e.Form.Controls("ComboBox1").text
Dim i As Integer
For i  = DataTables("车辆表").DataRows.Count-1 To 0 Step -1
    Dim dr As DataRow = DataTables("车辆表").DataRows(i)
    Dim dr2 As DataRow = DataTables("车辆表").Find("车牌号码='" & dr("车牌号码") & "' and 车牌颜色='" & dr("车牌颜色") & "' and _Identify <> " & dr("_Identify"))
    If dr2 IsNot Nothing Then
        dr2.Delete
    End If
Next
For i  = DataTables("单位表").DataRows.Count-1 To 0 Step -1
    Dim dr As DataRow = DataTables("单位表").DataRows(i)
    Dim dr2 As DataRow = DataTables("单位表").Find("单位名称='" & dr("单位名称") & "' and 地址='" & dr("地址") & "' and _Identify <> " & dr("_Identify"))
    If dr2 IsNot Nothing Then
        dr2.Delete
    End If
Next
Tables("车辆表").Current.Save()
Tables("车辆表").Current.Locked = True
Tables("单位表").Current.Save()
Tables("单位表").Current.Locked = True

 

 

 


图片点击可在新窗口打开查看此主题相关图片如下:捕获.png
图片点击可在新窗口打开查看

 回到顶部
帅哥哟,离线,有人找我吗?
Bin
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:35433 积分:178524 威望:0 精华:3 注册:2013/3/30 16:36:00
  发帖心情 Post By:2014/7/23 10:09:00 [只看该作者]

上例子吧

 回到顶部