/// <summary> /// 显示组图信息 /// </summary> /// <param name="gBean"></param> private void showBean(GroupBean gBean) { groupNameTxt.Text = gBean.GroupTitle; groupDescTxt.Text = gBean.GroupContent; groupRankComb.Text = gBean.GroupRank; groupKeyTxt.Text = gBean.GroupKeys; groupIdTxt.Text = gBean.GroupId; groupSrcNameLab.Text = gBean.GroupSrcName; descModeComb.Text = ""; saveBtn.Enabled = false; }
/// <summary> /// 保存txt文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void saveBtn_Click(object sender, EventArgs e) { GroupBean bean = new GroupBean(); bean.GroupContent = groupDescTxt.Text; bean.GroupKeys = groupKeyTxt.Text; bean.GroupPath = txtPath.Text; bean.GroupRank = groupRankComb.Text; bean.GroupTitle = groupNameTxt.Text; bean.GroupId = groupIdTxt.Text; bean.GroupSrcName = groupSrcNameLab.Text; saveGBean(bean); saveBtn.Enabled = false; statusLabel.Text = "保存成功。路径为:" + bean.GroupPath; }
/// <summary> /// 根据路径获取相应组图信息 /// </summary> /// <param name="path"></param> /// <returns></returns> private GroupBean getBean(string path) { statusLabel.Text = "选择txt路径为:" + path; GroupBean gBean = new GroupBean(); List <string> content = Util.readListTxt(path); gBean.GroupPath = path; string[] info = path.Split('\\'); string title = info[info.Length - 1]; gBean.GroupId = info[info.Length - 2]; //去除.txt gBean.GroupTitle = title.Substring(0, title.Length - 4); if (content.Count > 0) { string[] infos = content[0].Split('\t'); if (infos.Length == 2) { gBean.GroupRank = infos[0]; gBean.GroupContent = infos[1]; } else if (infos.Length == 1) { gBean.GroupRank = infos[0]; gBean.GroupContent = ""; } } if (content.Count > 1) { gBean.GroupKeys = content[1]; } else { gBean.GroupKeys = ""; } if (content.Count > 2) { gBean.GroupSrcName = content[2]; } txtPath.Text = path; return(gBean); }
/// <summary> /// 保存处理函数 /// </summary> /// <param name="bean"></param> private void saveGBean(GroupBean bean) { string content = bean.GroupRank + "\t" + bean.GroupContent + "\r\n" + bean.GroupKeys + "\r\n" + bean.GroupSrcName; if (!bean.GroupPath.EndsWith(bean.GroupTitle + ".txt")) { FileInfo file = new FileInfo(bean.GroupPath); string parent = file.DirectoryName; bean.GroupPath = parent + "\\" + bean.GroupTitle + ".txt"; parent = file.Directory.Name; groupTree.SelectedNode.Text = bean.GroupTitle + "(" + parent + ")"; file.Delete(); } if (bean.GroupPath != txtPath.Text) { FileInfo file = new FileInfo(txtPath.Text); if (file.Exists) { file.Delete(); } } Util.writeTxt(bean.GroupPath, content); txtPath.Text = bean.GroupPath; DirectoryInfo oldDire = new DirectoryInfo(bean.GroupPath).Parent; string newDire = oldDire.Parent.FullName + "\\" + bean.GroupId; if (oldDire.FullName != newDire) { oldDire.MoveTo(newDire); bean.GroupPath = newDire + "\\" + bean.GroupTitle + ".txt"; groupTree.SelectedNode.Text = bean.GroupTitle + "(" + oldDire.Name + ")"; } }
/// <summary> /// 保存处理函数 /// </summary> /// <param name="bean"></param> private void saveGBean(GroupBean bean) { string content = bean.GroupRank + "\t" + bean.GroupContent + "\r\n" + bean.GroupKeys + "\r\n" + bean.GroupSrcName; if (!bean.GroupPath.EndsWith(bean.GroupTitle + ".txt")) { FileInfo file = new FileInfo(bean.GroupPath); string parent = file.DirectoryName; bean.GroupPath = parent + "\\" + bean.GroupTitle + ".txt"; parent = file.Directory.Name; groupTree.SelectedNode.Text = bean.GroupTitle + "(" + parent + ")"; file.Delete(); } if (bean.GroupPath != txtPath.Text) { FileInfo file = new FileInfo(txtPath.Text); if (file.Exists) file.Delete(); } Util.writeTxt(bean.GroupPath, content); txtPath.Text = bean.GroupPath; DirectoryInfo oldDire = new DirectoryInfo(bean.GroupPath).Parent; string newDire = oldDire.Parent.FullName + "\\" + bean.GroupId; if (oldDire.FullName != newDire) { oldDire.MoveTo(newDire); bean.GroupPath = newDire + "\\" + bean.GroupTitle + ".txt"; groupTree.SelectedNode.Text = bean.GroupTitle + "(" + oldDire.Name + ")"; } }
/// <summary> /// 根据路径获取相应组图信息 /// </summary> /// <param name="path"></param> /// <returns></returns> private GroupBean getBean(string path) { statusLabel.Text = "选择txt路径为:" + path; GroupBean gBean = new GroupBean(); List<string> content = Util.readListTxt(path); gBean.GroupPath = path; string[] info = path.Split('\\'); string title = info[info.Length - 1]; gBean.GroupId = info[info.Length - 2]; //去除.txt gBean.GroupTitle = title.Substring(0, title.Length - 4); if (content.Count > 0) { string[] infos = content[0].Split('\t'); if (infos.Length == 2) { gBean.GroupRank = infos[0]; gBean.GroupContent = infos[1]; } else if (infos.Length == 1) { gBean.GroupRank = infos[0]; gBean.GroupContent = ""; } } if (content.Count > 1) { gBean.GroupKeys = content[1]; } else { gBean.GroupKeys = ""; } if (content.Count > 2) { gBean.GroupSrcName = content[2]; } txtPath.Text = path; return gBean; }