65.9K
CodeProject 正在变化。 阅读更多。
Home

QASharp V1.3 [类似于 MSDE 数据库的查询分析器工具]

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.67/5 (14投票s)

2004年8月5日

CPOL

1分钟阅读

viewsIcon

129623

downloadIcon

2621

这个项目旨在提供一个类似于查询分析器的工具,可用于执行查询、创建表和执行所有其他常见的数据库活动。

Sample screenshot

Sample screenshot

引言

QASharp 是为那些使用 MSDE(Microsoft Desktop Engine)的人开发的。 这个项目旨在提供一个类似于查询分析器的工具,可用于执行查询、创建表和执行所有其他常见的数据库活动。

欢迎所有建议、疑虑和批评。

致谢

SqlDBHandler.cs 作者:http://www.aspenterprisemanager.com/

支持的功能

  • 创建新查询。
  • 保存现有查询。
  • 打开现有查询。
  • 执行查询。
  • 多个查询输出窗口。
  • 连接到不同的数据源。
  • 主要关键字的无闪烁语法高亮显示。
  • 在“帮助”菜单中添加了显示错误
  • 对象浏览器。
  • 数据/存储过程编辑功能。
  • 打印查询。

要进行的配置设置

为了使应用程序正常工作,请在app.config文件中进行以下更改,如下列键中所示

<?xml version="1.0" encoding="Windows-1252"?>
<configuration>
  <appSettings>
    <add key="server" value="(local)" /> 
    <add key ="database" value="master" />
    <add key="uid" value="sa"/>
    <add key="pwd" value=""/> 
  </appSettings>
</configuration>
密钥
服务器 要连接的服务器
数据库 要连接的初始数据库
Uid 用户 ID
密码 密码

用法

  • 选择一个数据库。
  • 通过单击“新建”创建一个新文档。
  • 键入查询(对于多个查询,在每个查询后添加一个“GO”关键字)。
  • 按“F5”执行查询,或单击工具栏上的“执行”图标。
  • 要选择不同的服务器
    • 单击“文件”->“连接”。 输入所需的参数,然后单击“连接”。

从 V1.2 到 V1.3 的主要代码更改

/// Syntax highlighting
private void rtbQueryPad_TextChanged(object sender, System.EventArgs e)
{
   /// Split the line into tokens.
   Regex r = new Regex("([ \\t{}();])");

   if (rtbQueryPad.Text.Trim() =="")
    return;

   /// Get current line

   int currentLine = rtbQueryPad.GetLineFromCharIndex(
    rtbQueryPad.GetCharIndexFromPosition(Cursor.Position));
   
   /// When large amount of text is copied, generates error
   
   try {
    string currentLineString = rtbQueryPad.Lines[currentLine];

    int startPos = 0;
    for (int i = 0; i < currentLine-1; i++)
    {
     startPos = startPos + rtbQueryPad.Lines[i].Length;
    }

    string [] tokens = r.Split(currentLineString);
    
    foreach (string token in tokens) 
      {
     if (token.Trim() != string.Empty) 
     {
      if (IsKeyWord(token))
       FindAndHighlight(token,Color.Blue,false,true,startPos);
      else
       FindAndHighlight(token,Color.Black,false,true,startPos);
     }
    }
   }
   catch (Exception ex)
   {
    Console.WriteLine(ex.Message);
   }
} 

private bool IsKeyWord(string input)
{
  for (int i = 0; i < keywords.Length; i++) 
  {
        if (input.Trim().ToLower() == keywords[i].ToLower())
    {
     return true;
    }
  }
  return false;
}

/// More functionality to be added later.
/// Code to print the query
protected void pdQuery_PrintPage (object sender, 
 System.Drawing.Printing.PrintPageEventArgs ev)
  {
   float linesPerPage = 0;
   float yPosition = 0;
   int count = 0;
   float leftMargin = ev.MarginBounds.Left;
   float topMargin = ev.MarginBounds.Top;
   string line = null;
   
   frmQueryWriter frmCurrentForm;
   frmCurrentForm = (frmQueryWriter)this.ActiveMdiChild;

   Font printFont = frmCurrentForm.rtbQueryPad.Font;
   SolidBrush myBrush = new SolidBrush(Color.Black);

   // Work out the number of lines per page, using the MarginBounds.
   linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);

   // Iterate over the string using the StringReader, printing each line.
   while(count < linesPerPage && ((line=myReader.ReadLine()) != null)) 
   {
    // calculate the next line position based on 
    // the height of the font according to the printing device
    yPosition = topMargin + (count * printFont.GetHeight(ev.Graphics));

    // draw the next line in the rich edit control
    
    ev.Graphics.DrawString(line, printFont, myBrush, 
     leftMargin, yPosition, new StringFormat());
    count++;
   }

   // If there are more lines, print another page.
   if(line != null)
    ev.HasMorePages = true;
   else
    ev.HasMorePages = false;

   myBrush.Dispose();
      
  }

从 V1.1 到 V1.2 的主要代码更改

// 使用更改的值更新表。

public void UpdateDT(DataTable dt)
{
   string sql;dt.TableName;                 
   try
   {
       if (m_conn.State == ConnectionState.Closed)
       {
           m_conn.Open ();
       }
       SqlDataAdapter da = new SqlDataAdapter(
        sql,m_conn.ConnectionString);
       string field="";
       string values="";
       string sql1 = "";
       foreach(DataRow dtr in  dt.Rows)
       { 
          if (dtr.RowState == DataRowState.Added)  
          {      
             sql1 = " insert into " + dt.TableName + " (";          
             field = "";                
             values = "";       
             foreach(DataColumn dc in dt.Columns)   
             {          
                if (dc.AutoIncrement == false)          
                {   
                    field += dc.ColumnName + ",";   
                    values +=  "'" +  dtr[dc.ColumnName] + "',";          
                }   
             }  
             field = field.Substring(0,field.Length-1);  
             values = values.Substring(0,values.Length-1); 
             sql1 += field  + ")" + "Values (" + values + ")" ;
          }
          else if (dtr.RowState == DataRowState.Modified)
          {
             sql1 = " update  " + dt.TableName + " set ";
             string stmt="";
             string where = " where ";

             foreach(DataColumn dc in dt.Columns)
             {
                field  = dc.ColumnName + " = ";
                values =  "'" +  
                 dtr[dc.ColumnName].ToString().Trim() + "' ";
                stmt += field +  values + ",";
                where += field + "'" +  
                dtr[dc.ColumnName,
                 DataRowVersion.Original].ToString().Trim() 
                     +   "' and " ;
             }

             stmt = stmt.Substring(0,stmt.Length-1);
             where = where.Substring(0,where.Length-5);
             sql1 += stmt + where;
          }

          else if (dtr.RowState == DataRowState.Deleted)
          {
             sql1 = " delete from " + dt.TableName ;
             string stmt="";
             string where = " where ";
             foreach(DataColumn dc in dt.Columns)
             {
                 field  = dc.ColumnName + " = ";
                 where += field + "'" +  
                 dtr[dc.ColumnName,DataRowVersion.Original].ToString().
                    Trim() + "' and " ;
             }
             where = where.Substring(0,where.Length-5);
             sql1 += stmt + where;
          }
          if (sql1.Trim() != string.Empty)
                ExecNonQuery(sql1);
      }

   }

   catch (Exception ex)
   {
       System.Diagnostics.Debug.WriteLine(ex.Message);
   }
}

修订历史

  • 2004 年 10 月 6 日
    • 在登录时添加了 Windows 集成安全性。
    • 改进了无闪烁的语法高亮显示。
    • 添加了对打印的支持。
    • 错误修复。
  • 2004 年 8 月 5 日
    • 对象浏览器。
    • 数据/存储过程编辑器。
    • 数据库树控件。
  • 1.1 2004 年 2 月 22 日
    • 多个查询输出窗口。
    • 语法高亮显示。
    • 连接到不同数据源的菜单选项。
  • © . All rights reserved.