1、软件介绍
由于CANoe可能是多人合作,在没有使用gitee,我制作了一个快速合并工具,作为工具箱内容之一,在此基础上可以演变出DBC比对工具和专用软件的快速比对方案借鉴。
工具的目的不是为了替代其他工具,自己完成只是为了熟练掌握UI的使用和自己制定一些需求,完成相关的方案,主要就是为了优化工作 中繁琐的工作量,做一个借鉴。
2、软件UI
1、选择主程序,集成程序的主要负责人手里的软件
2、待合并程序,分配任务的人写的单个模块
3、主程序、待合并程序预览
4、程序内部文件预览,并且能够实现选择比对功能
5、选择需要合并的程序
6、开始合并程序
3、软件代码
#region 软件合并发布工具--目录与文档打开
private void InitListView()
{
this.listViewA.Columns.Add("Name", 200);
this.listViewA.Columns.Add("Type", 100);
this.listViewA.Columns.Add("Size", 100);
this.listViewA.CheckBoxes = true; // 启用复选框
this.listViewA.FullRowSelect = true; // 点击整行时选中
this.listViewB.Columns.Add("Name", 200);
this.listViewB.Columns.Add("Type", 100);
this.listViewB.Columns.Add("Size", 100);
this.listViewB.CheckBoxes = true;
this.listViewB.FullRowSelect = true;
this.listViewC.Columns.Add("Name", 200);
this.listViewC.Columns.Add("Type", 100);
this.listViewC.Columns.Add("Size", 100);
this.listViewC.CheckBoxes = true;
this.listViewC.FullRowSelect = true;
this.listViewC.Items.Clear();
this.listViewC.View = View.Details;
this.treeViewA.AfterSelect += new TreeViewEventHandler(this.TreeView_AfterSelect);
this.treeViewB.AfterSelect += new TreeViewEventHandler(this.TreeView_AfterSelect);
}
private string pathA, pathB;
private async void bt_Open_A_Click(object sender, EventArgs e)
{
pathA = textBox_A_Fliepath.Text = SelectFolder(textBox_A_Fliepath.Text);
if (pathA != null)
{
textBox_B_OutSoftwareName.Text = GetLastFolderName(textBox_A_Fliepath.Text);
await cANoeSoftwareMerge.PopulateTreeViewAsync(pathA, this.treeViewA, this.listViewA, this.listBoxLog);
}
}
private async void bt_Open_B_Click(object sender, EventArgs e)
{
pathB = textBox_B_Fliepath.Text = SelectFolder(textBox_B_Fliepath.Text);
if (pathB != null)
{
await cANoeSoftwareMerge.PopulateTreeViewAsync(pathB, this.treeViewB, this.listViewB, this.listBoxLog);
}
}
private void TreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
//if (e.Node.Tag != null)
//{
// string selectedDirectory = e.Node.Tag.ToString();
// if (sender == treeViewA)
// {
// cANoeSoftwareMerge.PopulateListView(selectedDirectory, listViewA, listBoxLog);
// selectedDirectory = cANoeSoftwareMerge.SelectNodeInTreeView(selectedDirectory, this.treeViewA, this.treeViewB);
// cANoeSoftwareMerge.PopulateListView(selectedDirectory, listViewB, listBoxLog);
// }
// else if (sender == treeViewB)
// {
// cANoeSoftwareMerge.PopulateListView(selectedDirectory, listViewB, listBoxLog);
// selectedDirectory = cANoeSoftwareMerge.SelectNodeInTreeView(selectedDirectory, this.treeViewB, this.treeViewA);
// cANoeSoftwareMerge.PopulateListView(selectedDirectory, listViewA, listBoxLog);
// }
//}
}
//双击获取同样文件夹名称的子内容
private void treeViewA_AfterSelect(object sender, TreeViewEventArgs e)
{
if (e.Node.Tag != null)
{
string selectedDirectory = e.Node.Tag.ToString();
cANoeSoftwareMerge.PopulateListView(selectedDirectory, listViewA, listBoxLog);
if (selectedDirectory == pathA)
{
cANoeSoftwareMerge.PopulateListView(pathB, listViewB, listBoxLog);
}
else
{
selectedDirectory = cANoeSoftwareMerge.SelectNodeInTreeView(selectedDirectory, this.treeViewA, this.treeViewB);
cANoeSoftwareMerge.PopulateListView(selectedDirectory, listViewB, listBoxLog);
}
}
}
private void treeViewB_AfterSelect(object sender, TreeViewEventArgs e)
{
if (e.Node.Tag != null)
{
string selectedDirectory = e.Node.Tag.ToString();
cANoeSoftwareMerge.PopulateListView(selectedDirectory, listViewB, listBoxLog);
if (selectedDirectory == pathB)
{
cANoeSoftwareMerge.PopulateListView(pathA, listViewA, listBoxLog);
}
else
{
selectedDirectory = cANoeSoftwareMerge.SelectNodeInTreeView(selectedDirectory, this.treeViewB, this.treeViewA);
cANoeSoftwareMerge.PopulateListView(selectedDirectory, listViewA, listBoxLog);
}
}
}
private void treeViewA_AfterExpand(object sender, TreeViewEventArgs e)
{
if (e.Node.Level == 0) // 根节点
{
// 同步展开treeViewB的根节点
// 判断treeViewB是否有根节点
if (treeViewB.Nodes.Count > 0)
{
// 直接展开treeViewB的根节点
treeViewB.Nodes[0].Expand();
}
else
{
listBoxLog.Items.Add("treeViewB没有根节点");
}
}
else
{
// 根据Node.Text展开treeViewB的节点
TreeNode correspondingNode = cANoeSoftwareMerge.FindNodeByFullPathAndText(treeViewB.Nodes, e.Node.FullPath, e.Node.Text);
if (correspondingNode != null)
{
correspondingNode.Expand();
}
else
{
listBoxLog.Items.Add($"无法找到对应的节点:{e.Node.Text}");
}
}
}
private void treeViewA_AfterCollapse(object sender, TreeViewEventArgs e)
{
if (e.Node.Level == 0) // 根节点
{
// 同步折叠treeViewB的根节点
// 判断treeViewB是否有根节点
if (treeViewB.Nodes.Count > 0)
{
// 直接展开treeViewB的根节点
treeViewB.Nodes[0].Collapse();
}
else
{
listBoxLog.Items.Add("treeViewB没有根节点");
}
}
else
{
// 根据Node.Text折叠treeViewB的节点
TreeNode correspondingNode = cANoeSoftwareMerge.FindNodeByFullPathAndText(treeViewB.Nodes, e.Node.FullPath, e.Node.Text);
if (correspondingNode != null)
{
correspondingNode.Collapse();
}
else
{
listBoxLog.Items.Add($"无法找到对应的节点:{e.Node.Text}");
}
}
}
private void treeViewB_AfterExpand(object sender, TreeViewEventArgs e)
{
}
private void treeViewB_AfterCollapse(object sender, TreeViewEventArgs e)
{
}
#endregion
#region 选择需要合并的程序,这里可以做成配置文件,就看具体的工作量了,再说
//选择需要合并的文件
private void listViewB_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (e.Clicks == 2) // 双击事件
{
// 检查是否有选中项
if (listViewB.SelectedItems.Count > 0)
{
// 获取选中项的索引和选中状态
int selectedIndex = listViewB.SelectedItems[0].Index;
bool isChecked = listViewB.SelectedItems[0].Checked;
// 调用 SelectListViewData 方法
bool result = cANoeSoftwareMerge.SelectListViewData(listViewB, selectedIndex, isChecked, listViewC, listBoxLog);
if (result)
{
// 执行成功的操作
}
else
{
// 执行失败的操作
}
}
}
// 选中内容,然后在listViewA的同样一行选中颜色蓝色
if (listViewB.SelectedItems.Count > 0)
{
ListViewItem selectedItem = listViewB.SelectedItems[0];
string selectedDirectory = selectedItem.Text.ToString();
cANoeSoftwareMerge.SelectNodeInListViewA(selectedDirectory, listViewA);
}
}
private void listViewA_MouseDoubleClick(object sender, MouseEventArgs e)
{
}
#endregion
#region 软件合并发布
private void bt_B_OutFile_Click(object sender, EventArgs e)
{
if (textBox_A_Fliepath.Text == "D:\\Work")
{
listBoxLog.Items.Clear();
listBoxLog.Items.Add("未选择文件");
return;
}
if (cANoeSoftwareMerge.CopyToAllFile(textBox_A_Fliepath.Text, textBox_B_OutPath.Text + textBox_B_OutSoftwareName.Text, listBoxLog))
{
listBoxLog.Items.Add("复制出来成功");
cANoeSoftwareMerge.FileToCopyPath(this.listViewC, textBox_B_Fliepath.Text, textBox_B_OutPath.Text + textBox_B_OutSoftwareName.Text, this.listBoxLog);
}
else
{
listBoxLog.Items.Add("复制出来失败");
}
}
#endregion
4、后记
完成这些小工具,完成设定好的目标,主要为了熟练完成需求--软件的目标,这个在制作测试软件和在利用其它平台工具中总结经验和提升自己的一些经验借鉴。