Commit 35866dfb authored by 罗显健's avatar 罗显健

帮助文件移到独立文件夹

parent 6ceca42b
......@@ -50,7 +50,8 @@ namespace Tools.MyCommon
if (!this._db.ConnectionTest())
{
this._db = null;
throw new Exception($"数据库链接无效!\r\n链接:{link}");
// throw new Exception($"数据库链接无效!\r\n链接:{link}"); // 给提示即可,否则无法操作下去,即使想改链接。
MessageBox.Show($"数据库链接无效!\r\n链接:{link}");
}
}
/// <summary>
......
......@@ -71,7 +71,7 @@ namespace Tools.MyUtils
/// 提示框
/// </summary>
/// <param name="msg"></param>
public static void Tip(string msg, int width=0, int height=0)
public static void Tip(string msg, int width = 0, int height = 0)
{
new wMsgBox().Show(msg, width, height);
}
......@@ -81,7 +81,7 @@ namespace Tools.MyUtils
/// <param name="txtFileName"></param>
public static void ShowHelp(string txtFileName)
{
var helpFileName = $@"{Utils.ConfigPath}\{txtFileName}.txt";
var helpFileName = $@"{Utils.ConfigPath}\help\{txtFileName}.txt";
if (File.Exists(helpFileName))
{
using (var sr = new StreamReader(helpFileName))
......@@ -167,13 +167,15 @@ namespace Tools.MyUtils
public static DataRow GetNewRow(this DataTable dt)
{
var result = dt.NewRow();
//非空列默认赋值为0
//非空列默认赋值为0..
foreach (DataColumn c in dt.Columns)
{
if (c.AllowDBNull || c.AutoIncrement)
continue;
//非空列处理:主键列根据列类型生成;非主键列统一用0初始化
result[c.ColumnName] = dt.PrimaryKey.Contains(c) ? GetDefaultPrimaryKey(c) : "0";
// 非空主键可以自动赋值,其他列用0 未考虑数据类型会直接报错
result[c.ColumnName] = dt.PrimaryKey.Contains(c) ? GetDefaultPrimaryKey(c) : GetDefaultColumnValue(c);
result.EndEdit();
}
//当有筛选条件时,默认赋值筛选字段
......@@ -224,6 +226,42 @@ namespace Tools.MyUtils
return result;
}
private static object GetDefaultColumnValue(DataColumn c)
{
object result = "0";
var typeName = c.DataType.Name.ToLower();
if (typeName.Equals("int32") || typeName.Equals("int64"))
{
var obj = c.Table.Compute($"Max({c.ColumnName})", "1=1");
int.TryParse(obj?.ToString(), out int max);
result = (max + 1).ToString();
}
else if (typeName.Equals("guid"))
{
result = Guid.NewGuid().ToString();
}
else if (typeName.Equals("datetime"))
{
result = DateTime.Now;
}
else
{
result = $"{c.ColumnName}_{c.Table.Rows.Count}";
}
return result;
}
#endregion
#region (扩展)整型范围
......@@ -316,7 +354,7 @@ namespace Tools.MyUtils
{
return $"IF NOT EXISTS(SELECT 1 FROM sys.tables WHERE name = '{tableName}')\r\nBEGIN\r\nCREATE TABLE {tableName}\r\n(";
}
public static string GenSqlBody(DataTable dt,string tableName, string tableDescription, out List<string> descriptionList)
public static string GenSqlBody(DataTable dt, string tableName, string tableDescription, out List<string> descriptionList)
{
//描述信息
descriptionList = new List<string>();
......
......@@ -54,8 +54,13 @@ namespace Tools
try
{
var item = this.listView1.SelectedItems[0];
var w = Activator.CreateInstance(item.Tag as Type) as Form;
w?.ShowDialog();
var from = Activator.CreateInstance(item.Tag as Type) as Form;
if (from != null)
{
from.Text = item.Text;
from.ShowDialog();
from.Dispose();
}
}
catch (Exception ex)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment