You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
2.8 KiB
105 lines
2.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using Stone.Common;
|
|
using System.IO;
|
|
|
|
namespace Stone.WinModule.MyControl
|
|
{
|
|
public partial class MyFileEdit : UserControl
|
|
{
|
|
public string filecontent = "";
|
|
|
|
public MyFileEdit()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
[CategoryAttribute(""), DescriptionAttribute("文件类型(*.btw)|*.btw")]
|
|
public string Filter
|
|
{
|
|
get
|
|
{
|
|
return this.saveFileDialog1.Filter;
|
|
}
|
|
|
|
set
|
|
{
|
|
this.saveFileDialog1.Filter = value;
|
|
this.openFileDialog1.Filter = value;
|
|
}
|
|
}
|
|
|
|
private void btnSelect_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
|
|
{
|
|
byte[] buff = File.ReadAllBytes(this.openFileDialog1.FileName);
|
|
this.filecontent = Convert.ToBase64String(buff);
|
|
|
|
this.txtFileName.Text = this.openFileDialog1.SafeFileName;
|
|
|
|
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MyMessageBox.ShowErrorMessage(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if(this.txtFileName.Text.Trim() == "")
|
|
{
|
|
throw new Exception("当前没有文件");
|
|
}
|
|
|
|
this.saveFileDialog1.FileName = this.txtFileName.Text.Trim();
|
|
if (this.saveFileDialog1.ShowDialog() == DialogResult.OK)
|
|
{
|
|
byte[] buff = Convert.FromBase64String(this.filecontent);
|
|
|
|
File.WriteAllBytes(this.saveFileDialog1.FileName, buff);
|
|
|
|
MyMessageBox.ShowInfoMessage(this.saveFileDialog1.FileName + " 另存成功");
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MyMessageBox.ShowErrorMessage(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void btnDelete_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (this.txtFileName.Text.Trim() == "")
|
|
throw new Exception("当前没有可删除的文件");
|
|
|
|
if(MyMessageBox.ShowQuestion("是否要删除文件?"))
|
|
{
|
|
this.txtFileName.Text = "";
|
|
this.filecontent = "";
|
|
}
|
|
|
|
|
|
}catch(Exception ex)
|
|
{
|
|
MyMessageBox.ShowErrorMessage(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|