linq C#通用数据库类 - ,&#34

📅 2026-11-30 👤 拼多多助力营销技巧 📂 拼多多助力网站 👁️ 225 次阅读

C#通用数据库类

最近在写一个c#的桌面应用,在网上查了半天,也没有合适的数据库访问类,于是自己动手写的一个,以下是关于该类的简单介绍 1、利用DbProviderFactory创建相应的conntion、command、transaction来实现相应的功能,含参数化查询,添加、更新、删除等功能 2、类默认为Sql server数据库,通过传入数据库文件路径,根据文件扩展名来确定数据库类型,用相应的SqlClientFactory.Instance,或OleDbFactory.Instance,创建dbFactory的实例,再用dbFactory的实例创建相应的conntion、command、transaction 3、在添加、更新时,通过控件的Tag保存表字段,根据控件的TabINdex的先后顺序返回对应的字段名和字段值 ,再用string.Join 实现自动创建相应的sql语句和参数化查询; 4、调用示例;grbWorklist是控件的容器,db.GetFieldNames(grbWorklist)获取表字段名的函数,db.GetFieldValues(grbWorklist)获取字段值函数。 dbFactory db=new dbFactory() int rows=db.InsertRow(“你的查询表”, db.GetFieldNames(grbWorklist), db.GetFieldValues(grbWorklist)); db.Dispose();

//C#通用数据库类` using System; using System.Data; using System.Data.Common; using System.Data.OleDb; using System.Data.SqlClient; using System.Drawing; using System.IO; using System.Linq; using System.Windows.Forms;

namespace WinApp { //abstract public class dbFactory { private DbConnection connection; //数据库连结 private DbCommand command; //命令 private DbTransaction transaction; //事务 private DbProviderFactory dbfactory; //数据库提供程序工厂 private string ConnectionString; //数据库连结字串 private Providers Provider; public System.Collections.Generic.List ColumnTitle = new System.Collections.Generic.List(); public dbFactory(string filePath = “”) { string extension = Path.GetExtension(filePath);

switch (extension.ToLower())

{

case ".mdb":

Provider = Providers.OleDb;

this.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Jet OLEDB:Database Password=love1234love!@(;Data Source=" + filePath;

break;

case ".txt":

Provider = Providers.OleDb;

this.ConnectionString = $"Provider=Microsoft.Jet.OleDb.4.0;Data Source={Path.GetDirectoryName(filePath)};Extended Properties='text;HDR=YES;FMT=Delimited';";

break;

case ".csv":

Provider = Providers.OleDb;

this.ConnectionString = $"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={System.IO.Path.GetDirectoryName(filePath)};Extended Properties='text;HDR=Yes;FMT=Delimited(,)';";

break;

case ".xls":

case ".xlsx":

Provider = Providers.OleDb;

this.ConnectionString = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={filePath};Extended Properties='Excel 12.0;HDR=YES;IMEX=1';";

break;

case ".mdf":

case ".ldf":

Provider = Providers.SqlServer;

string sqlConnectionString = $"Data Source=(localdb)\\MSSQLLocalDB;AttachDbFilename={filePath};Integrated Security=True;";

break;

default:

Provider = Providers.SqlServer;

if (LoginInf.ConnTpye == "本地连结")//将大括号的值换成你的数据库配置

this.ConnectionString = $"Data Source={LoginInf.HostName};Initial Catalog={LoginInf.DatabaseName};User ID=sa;Password ={LoginInf.PassWord};Persist Security Info=True;";

else

this.ConnectionString = $"Server ={LoginInf.ServerIP}; Database ={ LoginInf.DatabaseName }; User ID = sa; Password ={ LoginInf.PassWord }; Persist Security Info = True;";

break;

}

switch (Provider)

{

case Providers.SqlServer:

dbfactory = SqlClientFactory.Instance;

break;

case Providers.OleDb:

dbfactory = OleDbFactory.Instance;

break;

}

connection = dbfactory.CreateConnection();

connection.ConnectionString = ConnectionString;

command = connection.CreateCommand();

BeginTransaction();

}

public void OpenConnection()

{

if (connection.State != System.Data.ConnectionState.Open)

{

connection.Open();

}

}

public void CloseConnection()

{

if (connection.State != System.Data.ConnectionState.Closed)

{

connection.Close();

}

}

public void BeginTransaction()

{

OpenConnection();

if (transaction == null)

{

transaction = connection.BeginTransaction();

command.Transaction = transaction;

}

}

public void CommitTransaction()

{

if (transaction != null)

{

transaction.Commit();

transaction = null;

}

}

public void RollbackTransaction()

{

if (transaction != null)

{

transaction.Rollback();

transaction = null;

}

}

//您可以使用以下的 C# 代码来查询未提交的事务并返回结果数据表:

public DataTable GetUncommittedTransactions(string connectionString)

{

using (SqlConnection connection = new SqlConnection(connectionString))

{

connection.Open();

SqlCommand command = connection.CreateCommand();

command.CommandText = "SELECT transaction_id, transaction_begin_time FROM sys.dm_tran_active_transactions WHERE transaction_state = 1";

SqlDataAdapter adapter = new SqlDataAdapter(command);

DataTable dataTable = new DataTable();

adapter.Fill(dataTable);

return dataTable;

}

}

public void SetColumsInf(DataTable dt)

{

ColumnTitle.Clear();

for (int i = 0; i < dt.Rows.Count; i++)

{

Columns Col = new Columns();

Col.Index = i;

Col.FieldName = dt.Rows[i]["ColName"].ToString();

Col.ParaName = "@" + dt.Rows[i]["ColName"].ToString();

Col.DbType = dt.Rows[i]["dbType"].ToString();

if (dt.Rows[i]["length"] != DBNull.Value)

Col.Width = Convert.ToDouble(dt.Rows[i]["length"]);

else

Col.Width = 0;

ColumnTitle.Add(Col);

}

}

//private string GetFieldValues(Control parentControl)

//{

// var fieldValues = parentControl.Controls.OfType()

// .Select(c => $"{c.Tag.ToString()} = '{c.Text}'")

// .ToList();

// return string.Join(",", fieldValues);

//}

// 将所有子控件的参数添加到 SqlCommand 中

private void AddParameters(SqlCommand command, Control parentControl)

{

foreach (var control in parentControl.Controls.OfType())

{

command.Parameters.AddWithValue($"@{control.Tag.ToString()}", control.Text);

}

}

public string[] GetColumn(string TableName)

{

connection.Open();

System.Text.StringBuilder str = new System.Text.StringBuilder();

str.Append("select a.TABLE_NAME as 表名,a.COLUMN_NAME as ColName,a.DATA_TYPE as dbType,a.CHARACTER_MAXIMUM_LENGTH length,");

str.Append("a.COLUMN_DEFAULT as 默认值, a.NUMERIC_SCALE as 小数位数,a.DATETIME_PRECISION as 日期精度,a.IS_NULLABLE as 允许Null,");

str.Append("a.NUMERIC_PRECISION as 字段精度,b.value as 说明 from information_schema.COLUMNS as a left join sys.extended_properties as b");

str.Append(" on a.TABLE_NAME = OBJECT_NAME(b.major_id) and a.ORDINAL_POSITION = b.minor_id where a.TABLE_NAME = '");

str.Append(TableName);

str.Append("'");

DbDataReader reader = ExecuteReader(str.ToString());

System.Collections.Generic.Listresults = new System.Collections.Generic.List();

DataTable dt = null;

dt.Load(reader);

SetColumsInf(dt);

while (reader.Read())

{

results.Add(reader["ColName"].ToString());

}

return results.ToArray();

}

public void AddParameter(string name, object value)

{

DbParameter parameter = command.CreateParameter();

parameter.ParameterName = name;

parameter.Value = value;

command.Parameters.Add(parameter);

}

public int ExecuteNonQuery(string query)

{

command.CommandText = query;

return command.ExecuteNonQuery();

}

public object ExecuteScalar(string query)

{

command.CommandText = query;

return command.ExecuteScalar();

}

public DbDataReader ExecuteReader(string query)

{

command.CommandText = query;

return command.ExecuteReader();

}

//保存图像到数据库

public void SaveImageToDatabase(string imagePath, string tableName, string idColumn, object KeyValue, string imageColumn)

{

Image image = null;

image=Image.FromFile(imagePath);

MemoryStream memoryStream = new MemoryStream();

image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);

byte[] imageData = memoryStream.ToArray();

memoryStream.Dispose();

string query = $"UPDATE {tableName} SET {imageColumn}=@ImageData WHERE {idColumn}=@Id";

command.CommandText = query;

command.Parameters.Clear();

AddParameter("@ImageData", imageData);

AddParameter("@Id", KeyValue);

command.ExecuteNonQuery();

}

//从数据库提取图像并在控件PictureBox上显示

public void LoadImageFromDatabase(int KeyValue, string tableName, string KeyColumn, string imageColumn, System.Windows.Forms.PictureBox pictureBox) 拼多多帮助力入口

{

string query = $"SELECT {imageColumn} FROM {tableName} WHERE {KeyColumn}=@Id";

command.CommandText = query;

command.Parameters.Clear();

AddParameter("@Id", KeyValue);

byte[] imageData = (byte[])command.ExecuteScalar();

if (imageData != null)

{

MemoryStream memoryStream = new MemoryStream(imageData);

Image image = Image.FromStream(memoryStream);

pictureBox.Image = image;

memoryStream.Dispose();

}

}

public DataTable ExecuteQuery(string query)

{

DbDataAdapter adapter = dbfactory.CreateDataAdapter();

command.CommandText = query;

command.CommandType = CommandType.Text;

adapter.SelectCommand = command;

DataTable dt = new DataTable();

try { adapter.Fill(dt); }

catch (Exception ex)

{

GetFunction.GetMessage(ex.Message);

}

finally

{

command.Parameters.Clear();

}

return dt;

}

public DataTable GetDataTable(string queysql)

{

var dt = new DataTable();

command.CommandText = queysql;

DbDataReader daReader = command.ExecuteReader();

dt.Load(daReader);

return dt;

}

// 利用Tag属性获取所有子控件的对应的字段名(在设计时将控件的Tag等于字段名,并设置TabIndex,以方便自动构建插入、更新的SQL语句)

//可以直接调用insertRow插入一条记录

public string[] GetFieldNames(Control parentControl)

{//使用 LINQ 对容器中的所有控件进行排序,并且排除了 Label 控件。

//你可以在 foreach 循环中遍历这些控件,以按照 TabIndex 的次序依次处理它们。

var controls = parentControl.Controls.Cast()

.OrderBy(c => c.TabIndex)

.Where(c => !(c is Label));

System.Collections.Generic.Listresults = new System.Collections.Generic.List();

foreach (Control control in controls)

{

if (control.Tag != null)

{

if (control is TextBox || control is ComboBox)

{

string fieldName = control.Tag.ToString();

results.Add(fieldName);

}

}

}

//fields = fields.TrimEnd(',');

return results.ToArray();

}

// 获取所有子控件的值

public string[] GetFieldValues(Control parentControl)

{

//使用 LINQ 对容器中的所有控件进行排序,并且排除了 Label 控件。

//你可以在 foreach 循环中遍历这些控件,以按照 TabIndex 的次序依次处理它们。

var controls = parentControl.Controls.Cast()

.OrderBy(c => c.TabIndex)

.Where(c => !(c is Label));

System.Collections.Generic.Listresults = new System.Collections.Generic.List();

foreach (Control control in controls)

{

if (control.Tag != null)

{

if (control is TextBox || control is ComboBox)

{

string fieldValue = control.Text;

results.Add(fieldValue);

}

}

}

return results.ToArray();

}

public int InsertRow(string tableName, string[] columnNames, object[] values)

{

string columns = string.Join(",", columnNames);

string parameters = string.Join(",", columnNames).Replace(",", ",@");

string query = $"INSERT INTO {tableName} ({columns}) VALUES (@{parameters})";

command.CommandText = query;

command.Parameters.Clear();

for (int i = 0; i < columnNames.Length; i++)

{

AddParameter($"@{columnNames[i]}", values[i]);

}

return command.ExecuteNonQuery();

}

public int DeleteRow(string tableName, string otherTableName, string primaryKeyColumnName, object primaryKeyValue)

{//这里只考虑一个表以tableName的主键为外键的情况,如有多表可以重载该函数,再用数组进行处理如

//public int DeleteRow(string tableName,string[] otherTableName, string primaryKeyColumnName, object[] primaryKeyValue)

if (IsForeignKeyExists(otherTableName, primaryKeyColumnName, primaryKeyValue))

{

throw new Exception("该记录有子项,无法删除");

return -1;

}

else

{

string query = $"DELETE FROM {tableName} WHERE {primaryKeyColumnName}=@Id";

command.CommandText = query;

command.Parameters.Clear();

AddParameter("@Id", primaryKeyValue);

return command.ExecuteNonQuery();

}

}

public int UpdateRowByKey(string tableName, string keyColumnName, string keyValue, string[] columnNames, object[] values)

{

System.Collections.Generic.ListupdateList = new System.Collections.Generic.List();

for (int i = 0; i < columnNames.Length; i++)

updateList.Add($"{columnNames[i]}=@{columnNames[i]}");

string updateSql = $"UPDATE {tableName} SET {string.Join(",", updateList)} WHERE {keyColumnName} = @key";

AddParameter($"@key", keyValue);

for (int i = 0; i < columnNames.Length; i++)

{

AddParameter($"@{columnNames[i]}", values[i]);

}

return ExecuteNonQuery(updateSql) ;

}

public void ExecuteStoredProcedure(string procedureName)

{

command.CommandType = CommandType.StoredProcedure;

command.CommandText = procedureName;

command.ExecuteNonQuery();

}

public bool HasForeignKey(string tableName, string KeycolumnName, object KeyValue)

{

command.CommandText = $"SELECT COUNT(*) FROM [{tableName}] WHERE [{KeycolumnName}] = @Id";

AddParameter("@Id", KeyValue);

var count = (int)command.ExecuteScalar();

return count > 0;

}

public DbCommand CreateCommand(string commandText, CommandType commandType = CommandType.Text)

{

var cmd = connection.CreateCommand();

cmd.CommandText = commandText;

cmd.CommandType = commandType;

OpenConnection();

return cmd;

}

///

/// 判断主键是否被其他表引用

///

///

///

///

///

public bool IsForeignKeyExists(string tableName, string ForeignKeyName, object ForeignKeyValue)

{

string sql = $"SELECT COUNT(*) AS RefCount FROM {tableName} WHERE {ForeignKeyName} = '{ForeignKeyValue}'";

return Convert.ToInt32(ExecuteScalar(sql)) > 0;

}

public void Dispose()

{

connection.Close();

connection.Dispose();

command.Dispose();

if (null != transaction)

{

transaction.Dispose();

}

}

}

public class Columns : System.Object

{

public int Index;

public string FieldName;

public string ParaName;

public string DbType;

public double Width;

public bool Visible;

public override string ToString()

{

return FieldName;

}

};

}

rkdown编辑器** 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。

新的改变

我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown编辑器功能,我们增加了如下几点新功能,帮助你用它写博客:

全新的界面设计 ,将会带来全新的写作体验;在创作中心设置你喜爱的代码高亮样式,Markdown 将代码片显示选择的高亮样式 进行展示;增加了 图片拖拽 功能,你可以将本地的图片直接拖拽到编辑区域直接展示;全新的 KaTeX数学公式 语法;增加了支持甘特图的mermaid语法1 功能;增加了 多屏幕编辑 Markdown文章功能;增加了 焦点写作模式、预览模式、简洁写作模式、左右区域同步滚轮设置 等功能,功能按钮位于编辑区域与预览区域中间;增加了 检查列表 功能。

功能快捷键

撤销:Ctrl/Command + Z 重做:Ctrl/Command + Y 加粗:Ctrl/Command + B 斜体:Ctrl/Command + I 标题:Ctrl/Command + Shift + H 无序列表:Ctrl/Command + Shift + U 有序列表:Ctrl/Command + Shift + O 检查列表:Ctrl/Command + Shift + C 插入代码:Ctrl/Command + Shift + K 插入链接:Ctrl/Command + Shift + L 插入图片:Ctrl/Command + Shift + G 查找:Ctrl/Command + F 替换:Ctrl/Command + G

合理的创建标题,有助于目录的生成

直接输入1次#,并按下space后,将生成1级标题。 输入2次#,并按下space后,将生成2级标题。 以此类推,我们支持6级标题。有助于使用TOC语法后生成一个完美的目录。

如何改变文本的样式

强调文本 强调文本

加粗文本 加粗文本

标记文本

删除文本

引用文本

H2O is是液体。

210 运算结果是 1024.

插入链接与图片

链接: link.

图片:

带尺寸的图片:

居中的图片:

居中并且带尺寸的图片:

当然,我们为了让用户更加便捷,我们增加了图片拖拽功能。

如何插入一段漂亮的代码片

去博客设置页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 代码片.

// An highlighted block

var foo = 'bar';

生成一个适合你的列表

项目

项目

项目

项目1项目2项目3

计划任务 完成任务

创建一个表格

一个简单的表格是这么创建的:

项目Value电脑$1600手机$12导管$1

设定内容居中、居左、居右

使用:---------:居中 使用:----------居左 使用----------:居右

第一列第二列第三列第一列文本居中第二列文本居右第三列文本居左

SmartyPants

SmartyPants将ASCII标点字符转换为“智能”印刷标点HTML实体。例如:

TYPEASCIIHTMLSingle backticks'Isn't this fun?'‘Isn’t this fun?’Quotes"Isn't this fun?"“Isn’t this fun?”Dashes-- is en-dash, --- is em-dash– is en-dash, — is em-dash

创建一个自定义列表

Markdown

Text-to-

HTML conversion tool

Authors

John

Luke

如何创建一个注脚

一个具有注脚的文本。2

注释也是必不可少的

Markdown将文本转换为 HTML。

KaTeX数学公式

您可以使用渲染LaTeX数学表达式 KaTeX:

Gamma公式展示

Γ

(

n

)

=

(

n

−

1

)

!

∀

n

∈

N

\Gamma(n) = (n-1)!\quad\forall n\in\mathbb N

Γ(n)=(n−1)!∀n∈N 是通过欧拉积分

Γ

(

z

)

=

∫

0

∞

t

z

−

1

e

−

t

d

t

.

\Gamma(z) = \int_0^\infty t^{z-1}e^{-t}dt\,.

Γ(z)=∫0∞​tz−1e−tdt.

你可以找到更多关于的信息 LaTeX 数学表达式here.

新的甘特图功能,丰富你的文章

#mermaid-svg-yqCt2yhbuTNWyxEo {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-yqCt2yhbuTNWyxEo .error-icon{fill:#552222;}#mermaid-svg-yqCt2yhbuTNWyxEo .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-yqCt2yhbuTNWyxEo .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-yqCt2yhbuTNWyxEo .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-yqCt2yhbuTNWyxEo .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-yqCt2yhbuTNWyxEo .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-yqCt2yhbuTNWyxEo .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-yqCt2yhbuTNWyxEo .marker{fill:#333333;stroke:#333333;}#mermaid-svg-yqCt2yhbuTNWyxEo .marker.cross{stroke:#333333;}#mermaid-svg-yqCt2yhbuTNWyxEo svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-yqCt2yhbuTNWyxEo .mermaid-main-font{font-family:"trebuchet ms",verdana,arial,sans-serif;font-family:var(--mermaid-font-family);}#mermaid-svg-yqCt2yhbuTNWyxEo .exclude-range{fill:#eeeeee;}#mermaid-svg-yqCt2yhbuTNWyxEo .section{stroke:none;opacity:0.2;}#mermaid-svg-yqCt2yhbuTNWyxEo .section0{fill:rgba(102, 102, 255, 0.49);}#mermaid-svg-yqCt2yhbuTNWyxEo .section2{fill:#fff400;}#mermaid-svg-yqCt2yhbuTNWyxEo .section1,#mermaid-svg-yqCt2yhbuTNWyxEo .section3{fill:white;opacity:0.2;}#mermaid-svg-yqCt2yhbuTNWyxEo .sectionTitle0{fill:#333;}#mermaid-svg-yqCt2yhbuTNWyxEo .sectionTitle1{fill:#333;}#mermaid-svg-yqCt2yhbuTNWyxEo .sectionTitle2{fill:#333;}#mermaid-svg-yqCt2yhbuTNWyxEo .sectionTitle3{fill:#333;}#mermaid-svg-yqCt2yhbuTNWyxEo .sectionTitle{text-anchor:start;font-family:'trebuchet ms',verdana,arial,sans-serif;font-family:var(--mermaid-font-family);}#mermaid-svg-yqCt2yhbuTNWyxEo .grid .tick{stroke:lightgrey;opacity:0.8;shape-rendering:crispEdges;}#mermaid-svg-yqCt2yhbuTNWyxEo .grid .tick text{font-family:"trebuchet ms",verdana,arial,sans-serif;fill:#333;}#mermaid-svg-yqCt2yhbuTNWyxEo .grid path{stroke-width:0;}#mermaid-svg-yqCt2yhbuTNWyxEo .today{fill:none;stroke:red;stroke-width:2px;}#mermaid-svg-yqCt2yhbuTNWyxEo .task{stroke-width:2;}#mermaid-svg-yqCt2yhbuTNWyxEo .taskText{text-anchor:middle;font-family:'trebuchet ms',verdana,arial,sans-serif;font-family:var(--mermaid-font-family);}#mermaid-svg-yqCt2yhbuTNWyxEo .taskTextOutsideRight{fill:black;text-anchor:start;font-family:'trebuchet ms',verdana,arial,sans-serif;font-family:var(--mermaid-font-family);}#mermaid-svg-yqCt2yhbuTNWyxEo .taskTextOutsideLeft{fill:black;text-anchor:end;}#mermaid-svg-yqCt2yhbuTNWyxEo .task.clickable{cursor:pointer;}#mermaid-svg-yqCt2yhbuTNWyxEo .taskText.clickable{cursor:pointer;fill:#003163!important;font-weight:bold;}#mermaid-svg-yqCt2yhbuTNWyxEo .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163!important;font-weight:bold;}#mermaid-svg-yqCt2yhbuTNWyxEo .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163!important;font-weight:bold;}#mermaid-svg-yqCt2yhbuTNWyxEo .taskText0,#mermaid-svg-yqCt2yhbuTNWyxEo .taskText1,#mermaid-svg-yqCt2yhbuTNWyxEo .taskText2,#mermaid-svg-yqCt2yhbuTNWyxEo .taskText3{fill:white;}#mermaid-svg-yqCt2yhbuTNWyxEo .task0,#mermaid-svg-yqCt2yhbuTNWyxEo .task1,#mermaid-svg-yqCt2yhbuTNWyxEo .task2,#mermaid-svg-yqCt2yhbuTNWyxEo .task3{fill:#8a90dd;stroke:#534fbc;}#mermaid-svg-yqCt2yhbuTNWyxEo .taskTextOutside0,#mermaid-svg-yqCt2yhbuTNWyxEo .taskTextOutside2{fill:black;}#mermaid-svg-yqCt2yhbuTNWyxEo .taskTextOutside1,#mermaid-svg-yqCt2yhbuTNWyxEo .taskTextOutside3{fill:black;}#mermaid-svg-yqCt2yhbuTNWyxEo .active0,#mermaid-svg-yqCt2yhbuTNWyxEo .active1,#mermaid-svg-yqCt2yhbuTNWyxEo .active2,#mermaid-svg-yqCt2yhbuTNWyxEo .active3{fill:#bfc7ff;stroke:#534fbc;}#mermaid-svg-yqCt2yhbuTNWyxEo .activeText0,#mermaid-svg-yqCt2yhbuTNWyxEo .activeText1,#mermaid-svg-yqCt2yhbuTNWyxEo .activeText2,#mermaid-svg-yqCt2yhbuTNWyxEo .activeText3{fill:black!important;}#mermaid-svg-yqCt2yhbuTNWyxEo .done0,#mermaid-svg-yqCt2yhbuTNWyxEo .done1,#mermaid-svg-yqCt2yhbuTNWyxEo .done2,#mermaid-svg-yqCt2yhbuTNWyxEo .done3{stroke:grey;fill:lightgrey;stroke-width:2;}#mermaid-svg-yqCt2yhbuTNWyxEo .doneText0,#mermaid-svg-yqCt2yhbuTNWyxEo .doneText1,#mermaid-svg-yqCt2yhbuTNWyxEo .doneText2,#mermaid-svg-yqCt2yhbuTNWyxEo .doneText3{fill:black!important;}#mermaid-svg-yqCt2yhbuTNWyxEo .crit0,#mermaid-svg-yqCt2yhbuTNWyxEo .crit1,#mermaid-svg-yqCt2yhbuTNWyxEo .crit2,#mermaid-svg-yqCt2yhbuTNWyxEo .crit3{stroke:#ff8888;fill:red;stroke-width:2;}#mermaid-svg-yqCt2yhbuTNWyxEo .activeCrit0,#mermaid-svg-yqCt2yhbuTNWyxEo .activeCrit1,#mermaid-svg-yqCt2yhbuTNWyxEo .activeCrit2,#mermaid-svg-yqCt2yhbuTNWyxEo .activeCrit3{stroke:#ff8888;fill:#bfc7ff;stroke-width:2;}#mermaid-svg-yqCt2yhbuTNWyxEo .doneCrit0,#mermaid-svg-yqCt2yhbuTNWyxEo .doneCrit1,#mermaid-svg-yqCt2yhbuTNWyxEo .doneCrit2,#mermaid-svg-yqCt2yhbuTNWyxEo .doneCrit3{stroke:#ff8888;fill:lightgrey;stroke-width:2;cursor:pointer;shape-rendering:crispEdges;}#mermaid-svg-yqCt2yhbuTNWyxEo .milestone{transform:rotate(45deg) scale(0.8,0.8);}#mermaid-svg-yqCt2yhbuTNWyxEo .milestoneText{font-style:italic;}#mermaid-svg-yqCt2yhbuTNWyxEo .doneCritText0,#mermaid-svg-yqCt2yhbuTNWyxEo .doneCritText1,#mermaid-svg-yqCt2yhbuTNWyxEo .doneCritText2,#mermaid-svg-yqCt2yhbuTNWyxEo .doneCritText3{fill:black!important;}#mermaid-svg-yqCt2yhbuTNWyxEo .activeCritText0,#mermaid-svg-yqCt2yhbuTNWyxEo .activeCritText1,#mermaid-svg-yqCt2yhbuTNWyxEo .activeCritText2,#mermaid-svg-yqCt2yhbuTNWyxEo .activeCritText3{fill:black!important;}#mermaid-svg-yqCt2yhbuTNWyxEo .titleText{text-anchor:middle;font-size:18px;fill:#333;font-family:'trebuchet ms',verdana,arial,sans-serif;font-family:var(--mermaid-font-family);}#mermaid-svg-yqCt2yhbuTNWyxEo :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}

2014-01-07

2014-01-09

2014-01-11

2014-01-13

2014-01-15

2014-01-17

2014-01-19

2014-01-21

已完成

进行中

计划一

计划二

现有任务

Adding GANTT diagram functionality to mermaid

关于 甘特图 语法,参考 这儿,

UML 图表

可以使用UML图表进行渲染。 Mermaid. 例如下面产生的一个序列图:

#mermaid-svg-KLVP4dg7M2idrW9I {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-KLVP4dg7M2idrW9I .error-icon{fill:#552222;}#mermaid-svg-KLVP4dg7M2idrW9I .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-KLVP4dg7M2idrW9I .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-KLVP4dg7M2idrW9I .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-KLVP4dg7M2idrW9I .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-KLVP4dg7M2idrW9I .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-KLVP4dg7M2idrW9I .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-KLVP4dg7M2idrW9I .marker{fill:#333333;stroke:#333333;}#mermaid-svg-KLVP4dg7M2idrW9I .marker.cross{stroke:#333333;}#mermaid-svg-KLVP4dg7M2idrW9I svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-KLVP4dg7M2idrW9I .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-KLVP4dg7M2idrW9I text.actor>tspan{fill:black;stroke:none;}#mermaid-svg-KLVP4dg7M2idrW9I .actor-line{stroke:grey;}#mermaid-svg-KLVP4dg7M2idrW9I .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-KLVP4dg7M2idrW9I .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-KLVP4dg7M2idrW9I #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-KLVP4dg7M2idrW9I .sequenceNumber{fill:white;}#mermaid-svg-KLVP4dg7M2idrW9I #sequencenumber{fill:#333;}#mermaid-svg-KLVP4dg7M2idrW9I #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-KLVP4dg7M2idrW9I .messageText{fill:#333;stroke:#333;}#mermaid-svg-KLVP4dg7M2idrW9I .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-KLVP4dg7M2idrW9I .labelText,#mermaid-svg-KLVP4dg7M2idrW9I .labelText>tspan{fill:black;stroke:none;}#mermaid-svg-KLVP4dg7M2idrW9I .loopText,#mermaid-svg-KLVP4dg7M2idrW9I .loopText>tspan{fill:black;stroke:none;}#mermaid-svg-KLVP4dg7M2idrW9I .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-KLVP4dg7M2idrW9I .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-KLVP4dg7M2idrW9I .noteText,#mermaid-svg-KLVP4dg7M2idrW9I .noteText>tspan{fill:black;stroke:none;}#mermaid-svg-KLVP4dg7M2idrW9I .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-KLVP4dg7M2idrW9I .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-KLVP4dg7M2idrW9I .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-KLVP4dg7M2idrW9I .actorPopupMenu{position:absolute;}#mermaid-svg-KLVP4dg7M2idrW9I .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4));}#mermaid-svg-KLVP4dg7M2idrW9I .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-KLVP4dg7M2idrW9I .actor-man circle,#mermaid-svg-KLVP4dg7M2idrW9I line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-KLVP4dg7M2idrW9I :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}

张三

李四

王五

你好!李四, 最近怎么样?

你最近怎么样,王五?

我很好,谢谢!

我很好,谢谢!

李四想了很长时间, 文字太长了

不适合放在一行.

打量着王五...

很好... 王五, 你怎么样?

张三

李四

王五

这将产生一个流程图。:

#mermaid-svg-FioZDwkfBVFdSPAh {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-FioZDwkfBVFdSPAh .error-icon{fill:#552222;}#mermaid-svg-FioZDwkfBVFdSPAh .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-FioZDwkfBVFdSPAh .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-FioZDwkfBVFdSPAh .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-FioZDwkfBVFdSPAh .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-FioZDwkfBVFdSPAh .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-FioZDwkfBVFdSPAh .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-FioZDwkfBVFdSPAh .marker{fill:#333333;stroke:#333333;}#mermaid-svg-FioZDwkfBVFdSPAh .marker.cross{stroke:#333333;}#mermaid-svg-FioZDwkfBVFdSPAh svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-FioZDwkfBVFdSPAh .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-FioZDwkfBVFdSPAh .cluster-label text{fill:#333;}#mermaid-svg-FioZDwkfBVFdSPAh .cluster-label span{color:#333;}#mermaid-svg-FioZDwkfBVFdSPAh .label text,#mermaid-svg-FioZDwkfBVFdSPAh span{fill:#333;color:#333;}#mermaid-svg-FioZDwkfBVFdSPAh .node rect,#mermaid-svg-FioZDwkfBVFdSPAh .node circle,#mermaid-svg-FioZDwkfBVFdSPAh .node ellipse,#mermaid-svg-FioZDwkfBVFdSPAh .node polygon,#mermaid-svg-FioZDwkfBVFdSPAh .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-FioZDwkfBVFdSPAh .node .label{text-align:center;}#mermaid-svg-FioZDwkfBVFdSPAh .node.clickable{cursor:pointer;}#mermaid-svg-FioZDwkfBVFdSPAh .arrowheadPath{fill:#333333;}#mermaid-svg-FioZDwkfBVFdSPAh .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-FioZDwkfBVFdSPAh .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-FioZDwkfBVFdSPAh .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-FioZDwkfBVFdSPAh .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-FioZDwkfBVFdSPAh .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-FioZDwkfBVFdSPAh .cluster text{fill:#333;}#mermaid-svg-FioZDwkfBVFdSPAh .cluster span{color:#333;}#mermaid-svg-FioZDwkfBVFdSPAh div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-FioZDwkfBVFdSPAh :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}

链接

长方形

圆

圆角长方形

菱形

关于 Mermaid 语法,参考 这儿,

FLowchart流程图

我们依旧会支持flowchart的流程图:

Created with Raphaël 2.3.0

开始

我的操作

确认?

结束

yes

no

关于 Flowchart流程图 语法,参考 这儿.

导出与导入

导出

如果你想尝试使用此编辑器, 你可以在此篇文章任意编辑。当你完成了一篇文章的写作, 在上方工具栏找到 文章导出 ,生成一个.md文件或者.html文件进行本地保存。

导入

如果你想加载一篇你写过的.md文件,在上方工具栏可以选择导入功能进行对应扩展名的文件导入, 继续你的创作。

mermaid语法说明 ↩︎ 注脚的解释 ↩︎

精彩文章

标签: 拼多多助力网站平台 赚钱项目 拼多多助力网 首码项目 手赚APP
拼多多助力营销技巧