You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kev/Drawer/UCDraw/LibTest/FrmDatabaseIO.cs

180 lines
5.9 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

///
/// 使用SqlSugar进行数据访问
/// 参考文档 https://www.donet5.com/Home/Doc
///
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WorkData;
using WorkData.Entity;
namespace LibTest
{
/// <summary>
/// 工区数据示例类.
/// </summary>
public partial class FrmDatabaseIO : Form
{
List<string> tableTypes = new List<string>();
/// <summary>
/// Initializes a new instance of the <see cref="FrmDatabaseIO"/> class.
/// </summary>
public FrmDatabaseIO()
{
InitializeComponent();
tableTypes.Add("井基础");
tableTypes.Add("井斜");
tableTypes.Add("测井曲线");
tableTypes.Add("孔隙度");
tableTypes.Add("砂岩厚度");
string strProjectFile = "C:\\temp\\20250330\\sys.db";
Config.ProjectPath = Path.GetDirectoryName(strProjectFile);
}
/// <summary>
/// Frms the database i o_ load.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private void FrmDatabaseIO_Load(object sender, EventArgs e)
{
TreeNode tnRoot = treeView1.Nodes[0];
tnRoot.Nodes.Clear();
foreach (string item in tableTypes)
{
TreeNode tnChild = tnRoot.Nodes.Add(item);
}
treeView1.ExpandAll();
}
/// <summary>
/// 打开工区事件.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private void btnOpenProject_Click(object sender, EventArgs e)
{
// 最近的工区列表
List<WorkspaceInfo> workList = WorkConfig.Data.WorkList;
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "*.kep|*.kep";
if (ofd.ShowDialog() != DialogResult.OK)
{
return;
}
string strProjectFile = ofd.FileName;
Config.ProjectPath = Path.GetDirectoryName(strProjectFile);
//Config.ProjectName = Path.GetFileNameWithoutExtension(strProjectFile);
try
{
treeView1.SelectedNode = treeView1.Nodes[0].Nodes[0];
}
catch (Exception ex)
{
MessageBox.Show($"数据库打开错误.\r\n{ex.Message}");
}
}
/// <summary>
/// 显示各数据表.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
if (e.Node == null)
{
return;
}
string strDataName = e.Node.Text;
switch (strDataName)
{
case "井基础":
List<WellBase> lstWellBase = DBHelp.Db.Queryable<WellBase>().ToList();
displayData(lstWellBase);
break;
case "井斜":
List<WellDeflection> lstWellDeflection = DBHelp.Db.Queryable<WellDeflection>().ToList();
displayData(lstWellDeflection);
break;
case "测井曲线":
List<WellCurveFile> lstWellCurve = DBHelp.Db.Queryable<WellCurveFile>().ToList();
displayData(lstWellCurve);
break;
case "孔隙度":
List<CcsjKxd> lstKxd = DBHelp.Db.Queryable<CcsjKxd>().ToList();
displayData(lstKxd);
break;
case "砂岩厚度":
List<CcsjSyhd> lstCcsjSyhd = DBHelp.Db.Queryable<CcsjSyhd>().ToList();
displayData(lstCcsjSyhd);
break;
default:
break;
}
this.dataGridView1.Tag = strDataName;
}
/// <summary>
/// 显示数据表.
/// </summary>
/// <param name="data">The data.</param>
/// <returns>A bool.</returns>
private bool displayData<T>(List<T> data)
{
this.dataGridView1.DataSource = null;
BindingList<T> bindlist = new BindingList<T>(data);
this.dataGridView1.DataSource = bindlist;
return true;
}
/// <summary>
/// 插入数据.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private void btnInsert_Click(object sender, EventArgs e)
{
string strDataName = $"{this.dataGridView1.Tag}";
if (string.IsNullOrEmpty(strDataName))
{
return;
}
switch (strDataName)
{
case "井基础":
/*
WellBase wellNew = new WellBase();
wellNew.JH = "井号1";
DBHelp.Db.Insertable(wellNew).ExecuteCommand();
*/
break;
case "井斜":
break;
default:
break;
}
}
/// <summary>
/// 更新数据.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The e.</param>
private void btnUpdate_Click(object sender, EventArgs e)
{
/*
WellBase wellUpdata = DBHelp.Db.Queryable< WellBase>().First();
wellUpdata.JH = "井号1";
DBHelp.Db.Updateable(wellUpdata).ExecuteCommand();
*/
}
}
}