c# - 为什么在c#中从.dll调用时表单不出现
问题描述
.dll 文件中的这个命名空间
这个.dll 来检查是否存在某些文件
以及如果文件存在。检查文件的内容
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CheckData
{
public class CheckFileContent : Form
{
public void Check(Form CreateFile)
{
try
{
// check file if exsits
if (!System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\" + "ConReq.HP"))
{
CreateFile = new Form();
CreateFile.ShowDialog();
}
else
{
//If file exists.Check the content of the file
string[] lines = File.ReadAllLines(AppDomain.CurrentDomain.BaseDirectory + @"\" + "ConReq.HP");
检查第一行内容是否为特定单词(DBname=)
if (lines[0].Substring(0, 7) != "DBname=")
{
CreateFile = new Form();
CreateFile.ShowDialog();
}
检查第一行是否包含特定单词(DBname =)
else if (lines[0].Substring(7, lines[0].Length - 7) == "")
{
CreateFile = new Form();
CreateFile.ShowDialog();
}
检查第一行内容是否为特定单词(server=)
else if (lines[1].Substring(0, 7) != "Server=")
{
CreateFile = new Form();
CreateFile.ShowDialog();
}
检查第一行是否包含特定的单词(server=)
else if (lines[1].Substring(7, lines[1].Length - 7) == "")
{
CreateFile = new Form();
CreateFile.ShowDialog();
}
检查第一行内容是否特定单词(数据源=)
else if (lines[2].Substring(0, 12) != "Data Source=")
{
CreateFile = new Form();
CreateFile.ShowDialog();
}
检查第一行是否包含特定单词(数据源=)
else if (lines[2].Substring(12, lines[2].Length - 12) == "")
{
CreateFile = new Form();
CreateFile.ShowDialog();
}
}
}
catch (Exception check_e)
{
MessageBox.Show(check_e.Message, check_e.Source, MessageBoxButtons.OK);
Application.Exit();
}
}
}
当在主窗体中调用 .dll 并调用方法来检查文件是否存在时
CheckFileContent cheek = new CheckFileContent();
cheek.Check(CheckFileCon.ActiveForm);
当文件不存在时,此表单调用以创建新文件 我想要这个
但这 就是我得到的
解决方案
推荐阅读
- cypress - 为什么我在柏树任务中收到此警告?
- amazon-web-services - AWS Lambda 请求/事件的最大负载大小?
- python - 如何在Python中计算2个元素之间的间隔
- ansible - 将变量传递给主机的 Ansible playbook:使用双引号
- python - 使用 ClientID 和密钥的 python 地理编码
- mysql - 将十六进制数据从 varchar 类型字段移动到 bigint 类型(mysql)
- python - 如何使用 json 文件使用 url lib
- php - Array - 从数组中选择子子 ID
- spring-security - Jhipster,防止用户更新其他用户创建的实体
- asp.net - 新创建的 Asp.net Web App 只能运行一次(在 VS2017 中)