小数典应用:小诗典

public partial class frmXSD : Form

{

SmallDataDict.SmallData ss=null;

public frmXSD()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

Init();

this.Text = SmallData.Title;

btnLogo.Image = Image.FromStream(new MemoryStream(SmallData.Image));

}

private void Init()

{

AppInfo api = AppInfo.Load("app.lic");

if (api == null)

{

frmSetMain f = new frmSetMain();

if (f.ShowDialog() == DialogResult.OK)

api = AppInfo.Load("app.lic");

}

if (api == null)

{

this.Close();

return;

}

SmallDataDict.SmallData.Init(api);

ss = new SmallDataDict.SmallData(api.Name);

cmbKey.Items.Clear();

cmbKey.Items.AddRange(ss.LoadSaveKeyList(true,new string\[\] { }));

}

Stopwatch t = new Stopwatch();

//写数据

private void btnIn_Click(object sender, EventArgs e)

{

if (cmbKey.Text == "" || txtIN.Text == "")

return;

t.Restart();

if (!ss.SetData(cmbKey.Text.ToString(), txtIN.Text, out string error))

{

MessageBox.Show(error, "IN", MessageBoxButtons.OK, MessageBoxIcon.Error);

}

else

{

if (cmbKey.SelectedIndex < 0)

cmbKey.Items.Add(cmbKey.Text);

MessageBox.Show(txtIN.Text+"\r\n耗时:"+t.ElapsedMilliseconds.ToString(), "IN", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

t.Stop();

}

//读数据

private void btnOut_Click(object sender, EventArgs e)

{

if (cmbKey.Text == "")

return;

t.Restart();

if (!ss.GetData(cmbKey.Text, out string value, out string error))

{

txtOut.Text = "";

MessageBox.Show(error, "OUT", MessageBoxButtons.OK, MessageBoxIcon.Error);

}

else

{

txtOut.Text = value;

MessageBox.Show(value+"\r\n耗时:" + t.ElapsedMilliseconds.ToString(), "OUT", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

t.Stop();

}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

if (cmbKey.Items.Count > 0 && ss!=null)

{

List<string> xx = ss.LoadSaveKeyList(true, new string\[\] { })?.ToList() ?? new List<string>();

xx.AddRange(cmbKey.Items.Cast<string>());

xx = xx.Distinct<string>().ToList();

ss.LoadSaveKeyList(false, xx.ToArray());

}

ss?.Dispose();

SmallData.Clear();

}

private void button1_Click(object sender, EventArgs e)

{

if(ss.DeleteData(null,out string error))

{

txtOut.Text = string.Empty;

MessageBox.Show("删除成功!","OUT", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

else

{

txtOut.Text = error;

MessageBox.Show(error, "OUT", MessageBoxButtons.OK, MessageBoxIcon.Error);

}

}

private void button2_Click(object sender, EventArgs e)

{

if(!ss.LoadSaveData(out string error))

{

MessageBox.Show(error, "OUT", MessageBoxButtons.OK, MessageBoxIcon.Error);

}

else

{

MessageBox.Show("保存成功!", "OUT", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}

private void button3_Click(object sender, EventArgs e)

{

if (!ss.LoadSaveData(out string error,false))

{

MessageBox.Show(error, "OUT", MessageBoxButtons.OK, MessageBoxIcon.Error);

}

else

{

MessageBox.Show("重置成功!", "OUT", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}

private void button4_Click(object sender, EventArgs e)

{

frmSetMain f=new frmSetMain();

if (f.ShowDialog() == DialogResult.OK)

{

Form1_Load(null, null);

}

}

private void btnLogo_Click(object sender, EventArgs e)

{

List<string> list = new List<string>();

list.Add("软件名称:"+SmallData.Title);

MessageBox.Show(string.Join("\r\n", list), "关于我们", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}

只要用同一个设置,到哪都能读到原来存进去的诗篇。改了又存。随时随地灵感而来,随时随地记录。

点击链接加入群聊【小数典】:https://qm.qq.com/q/uSmCtLJhHG

相关推荐
Qiuner1 小时前
Pico 重塑Agent时代人与数据交互方式
windows·docker·ai·架构
FL16238631292 小时前
Windows x64 系统安装 ChromeDriver
windows
Song_da_da_2 小时前
C#与VisionPro联合编程实战:机器视觉二次开发完整指南
开发语言·microsoft·c#
百事牛科技3 小时前
两种方法锁定 PDF,拒绝内容被随意篡改
windows·pdf
加号34 小时前
【C#】 Web API 自定义配置函数请求路径:从路由本质到灵活架构设计
开发语言·c#
happyprince7 小时前
11-Hugging Face Transformers 分布式与并行系统深度分析
分布式·c#·wpf
云樱梦海7 小时前
OpenClaw官方:OpenClaw Windows Node 实战(1.5K ★ 开源推荐)
windows·开源·github·openclaw
csdn_aspnet8 小时前
C# list集合 多属性排序
c#·list·linq·排序
加号39 小时前
【WPF】 基于 Canvas 读取并渲染 DXF 文件的技术指南
c#·wpf
深度学习04079 小时前
SVN 独立服务端部署与客户端使用指南(CentOS/Rocky 9.5 + Windows)
windows·svn